This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Xlib.display | |
from Xlib import X, Xcursorfont | |
def XSelectWindow(dpy): | |
screen = dpy.screen() | |
root = screen.root | |
gc = root.create_gc(background=screen.black_pixel, foreground=screen.white_pixel, function=X.GXinvert, subwindow_mode=X.IncludeInferiors) | |
font = dpy.open_font('cursor') | |
cursor = font.create_glyph_cursor(font, Xcursorfont.crosshair, Xcursorfont.crosshair+1, (65535, 65535, 65535), (0, 0, 0)) | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Really useful in some situations, but you can see how often it's actually been used, since cmp() doesn't even exist anymore... | |
sign = lambda v: cmp(v, 0) | |
clamp = lambda v, minv, maxv: min(max(v, minv), maxv) | |
# These are a bit of a misnomers, since below/above suggests lt/gt, while these are le/ge | |
clamp_below = lambda v, maxv: min(v, maxv) | |
clamp_above = lambda v, minv: max(v, minv) | |
div_ceil = lambda dividend, divisor: (dividend - 1) // divisor + 1 | |
# Just for symmetry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def rtlsdr2numpy(datafilename, tempfilename): | |
real = np.memmap(datafilename, mode='r', dtype='uint8') | |
temp = np.memmap(tempfilename, mode='w+', dtype='float64', shape=real.shape) | |
temp[:] = real | |
temp /= 127.5 | |
temp -= 1 | |
return temp.view('complex128') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def float2str(val): | |
val, sci, exp = str(val).partition('e') | |
if not sci: | |
return val | |
sign = '' | |
if val[0] in '-': | |
sign = '-' | |
val = val[1:] | |
assert val.count('.') == 1 and val[1] == '.' and val[0] != '0' |