Search Results

Search found 6 results on 1 pages for 'mykhal'.

Page 1/1 | 1 

  • Bit-shifting a file

    - by mykhal
    I wonder if there is an utility to read and print a (binary) file, shifted by some amount of bits (i mean, it should accept amounts, which are not divisible by 8). .. something like dd (and its skip option), but bit-wise, instead of byte-wise. (If you think that there is no such thing, and are going to implement it here, please use C.. i have my own bit-shifting thing for strings, written in Python, but it is surely relatively slow as hell)

    Read the article

  • Solaris kstat sdX disk nread counter value decreasing

    - by mykhal
    I get strange disk io nread (bytes read) counter values (from kstat) on Solaris. Example of collected nread value for sd6 disk collected in 30s interval (command kstat -n sd6): 768579416 768579416 768579416 768579416 768579416 768579416 768579416 768496080 768496080 768496080 768496080 768496080 768496080 768496080 768496080 768530896 768530896 768447560 768447560 768447560 One would suppose that the relative read bytes count can't be negative.. I wonder what can couse this situation and whether there is more reliable disk io data available. Some info about the system: machine:~ # uname -a SunOS machine 5.10 Generic_127112-11 i86pc i386 i86pc machine:~ # cat /etc/release Solaris 10 11/06 s10x_u3wos_10 X86 Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms. Assembled 14 November 2006

    Read the article

  • How to get HTTP status message in (py)curl?

    - by mykhal
    spending some time studying pycurl and libcurl documentation, i still can't find a (simple) way, how to get HTTP status message (reason-phrase) in pycurl. status code is easy: import pycurl import cStringIO curl = pycurl.Curl() buff = cStringIO.StringIO() curl.setopt(pycurl.URL, 'http://example.org') curl.setopt(pycurl.WRITEFUNCTION, buff.write) curl.perform() print "status code: %s" % curl.getinfo(pycurl.HTTP_CODE) # -> 200 # print "status message: %s" % ??? # -> "OK"

    Read the article

  • python histogram one-liner

    - by mykhal
    there are many ways, how to code histogram in Python. by histogram, i mean function, counting objects in an interable, resulting in the count table (i.e. dict). e.g.: >>> L = 'abracadabra' >>> histogram(L) {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r': 2} it can be written like this: def histogram(L): d = {} for x in L: if x in d: d[x] += 1 else: d[x] = 1 return d ..however, there are much less ways, how do this in a single expression. if we had "dict comprehensions" in python, we would write: >>> { x: L.count(x) for x in set(L) } but we don't have them, so we have to write: >>> dict([(x, L.count(x)) for x in set(L)]) however, this approach may yet be readable, but is not efficient - L is walked-through multiple times, so this won't work for single-life generators.. the function should iterate well also through gen(), where: def gen(): for x in L: yield x we can go with reduce (R.I.P.): >>> reduce(lambda d,x: dict(d, x=d.get(x,0)+1), L, {}) # wrong! oops, does not work, the key name is 'x', not x :( i ended with: >>> reduce(lambda d,x: dict(d.items() + [(x, d.get(x, 0)+1)]), L, {}) (in py3k, we would have to write list(d.items()) instead of d.items(), but it's hypothethical, since there is no reduce there) please beat me with a better one-liner, more readable! ;)

    Read the article

  • python VTE Terminal weirdness

    - by mykhal
    i'm trying to use the terminal from python VTE binding (python-vte from debian squeeze) as a virtual terminal emulator (just for ANSI/control chars text processing) in interactive python console, everything looks (almost) all right: >>> import vte >>> term = vte.Terminal() >>> term.feed("a\nb") >>> print repr(term.get_text(lambda *a: True).rstrip()) 'a\n b' however, launching this code (little modified) as python script, different result is yielded: $ python vte_wiredness_1.py '' strangely enough, pasting the code back into the (new) interactive python session also yields empty string: >>> import vte >>> term = vte.Terminal() >>> term.feed("a\nb") >>> print repr(term.get_text(lambda *a: True).rstrip()) '' >>> first thing caming on my mind was that the only difference between the two cases is the timing - there had to be some delay before get_text. unfortunately, preluding get_text with some seconds sleep did not help then i thought it has something to do with X window environment. but the results are the same pure linux console (with some warning on missing graphics). i wonder what causes such an unpredictable behavior (interactive console - pasted vs typed, and it's not the delay.. ant the interactive console has nothing to do with the vte terminal object.. i guess) can someone explain what is happening? is it possible to use the VTE Term such way? that the "b" letter in the output is preceded by the space, is another strangeness (all consecutive lines are preceded by more spaces.. looks like I have to send carriage return before the string.) (the lambda *a: True get_text method argument i'm using is a dummy callback, it's is some SlotSelectedCallback.. for its explanation i'd be grateful as well :) )

    Read the article

  • backspace character wiredness

    - by mykhal
    i wonder why backspace character in common linux terminals does not actually erase the characters, when printed (which normally works when typed).. this works as expected: $ echo -e "abc\b\b\bxyz" xyz (\b evaluates to backspace, can be inserted also as ctrl-v ctrl-h - rendered as ^H (0x08)) but when there are less characters after the backspaces, the strange behavior is revealed: $ echo -e "abc\b\b\bx" xbc is behaves like left arrow keys instead of backspace: $ echo -e "abc\e[D\e[D\e[Dx" xbc erase line back works normally: $ echo -e "abc\e[1Kx" x in fact, when i type ctrl-v <BS> in terminal, ^? (0x7f) is yielded instead of ^H, this is DEL ascii character, but ctrl-v <DEL> produces <ESC>[3~, but it is another story.. so can someone explain why printed backspace character does not erase the characters? (my environment it xterm linux and some other terminal emulators, $TERM == xterm, tried vt100, linux as well)

    Read the article

1