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 ctypes | |
class Tspi: | |
def __init__(self): | |
self.hContext = ctypes.c_uint32(0) | |
self.tspi = ctypes.CDLL('libtspi.so.1') | |
e = self.tspi.Tspi_Context_Create(ctypes.pointer(self.hContext)) | |
assert e==0,'Error: %x' % e | |
def err(self,e): |
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
SEP=03248902398402398402390239402 | |
awk < $0 '/^'$SEP'/{f=substr($0,length("'$SEP'")+2);} f && !/^'$SEP'/{print $0 > f}'; exit $? | |
03248902398402398402390239402-file_one.txt | |
this is | |
file one | |
03248902398402398402390239402-file_two.txt | |
and this | |
is file | |
number two |
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
/dts-v1/; | |
/ { | |
description = "Chrome OS kernel image with one or more FDT blobs"; | |
#address-cells = <1>; | |
images { | |
kernel@1 { | |
data = /incbin/("/home/larsr/build/arch/arm/boot/zImage"); | |
type = "kernel_noload"; |
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 quicksort(l): | |
work = [(0,len(l)-1)] | |
while work: | |
(left,right) = work.pop() | |
if right < left: | |
continue | |
i_piv = left | |
piv = l[i_piv] | |
l0,r0 = left, right | |
while left<right: |
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
# sudoku-starter-kit, lars.rasmusson@gmail.com, 2013-04-30 | |
game = '.8...6...|32.9.47..|.4...7.6.|93..1....|......8.9|8..2.....|...4..17.|.7...89..|..4......' | |
def rc(r,c): return (r-1)*9+(c-1) | |
def init_sud(sud): | |
v=[] | |
for c in sud: | |
if c in "123456789": v.append([int(c)]) | |
elif c in ".": v.append(range(1,10)) | |
assert(len(v)==81) | |
return v |
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 BeautifulSoup | |
import urllib2 | |
def word(w): | |
return BeautifulSoup.BeautifulSoup(urllib2.urlopen("http://thesaurus.com/browse/"+w).read()) | |
def synonym(w): | |
w = word(w) | |
return w.find('table', {"class":'the_content'}).find('td',text=lambda t:'Synonym' in t).parent.parent.text |
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
# compute the square root of x | |
def sqr(x): | |
prec = 1 | |
z = 2 | |
while z < x: | |
prec = prec + 1 | |
z = z * 4 | |
# Here x <= (2**prec)**2 | |
a = 0 |
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
moves = """ | |
1 14 76 | |
2 15 77 | |
3 16 78 | |
4 17 74 | |
5 18 75 | |
6 19 71 | |
7 20 72 | |
8 21 73 | |
9 22 69 |
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 mmap | |
import posix_ipc | |
import os | |
import sys | |
def create_shared_mem(sm_name, size): | |
sm = posix_ipc.SharedMemory(sm_name, flags=posix_ipc.O_CREX, size=size) | |
return mmap.mmap(sm.fd, sm.size) | |
def open_shared_mem(sm_name): |
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
class term(object): | |
def __init__(self,**args): | |
for k in self.vals: | |
self.__setattr__(k,args[k]) | |
def __str__(self): | |
return self.__class__.__name__+"("+(", ".join([k+'='+str(self.__getattribute__(k)) for k in self.vals]))+")" | |
class const(term): vals = ['val'] | |
class add(term): vals = ['e1', 'e2'] | |
class let(term): vals = ['name','exp', 'body'] |
OlderNewer