Skip to content

Instantly share code, notes, and snippets.

@larsr
larsr / shmem.py
Created September 23, 2014 16:32
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):
@larsr
larsr / mupl.py
Last active August 29, 2015 14:09
A python implementation of the MUPL language
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']
import urllib2 as u
import BeautifulSoup as bs
url='https://www.fourmilab.ch/cgi-bin/Hotbits?nbytes=128&fmt=hex&npass=1&lpass=8&pwtype=3'
print bs.BeautifulSoup(u.urlopen(url).read()).body.pre.text
(* Coq proof that "less than" is well-founded *)
Require Le.
Lemma well_founded_lt : well_founded lt.
Proof.
intro a.
induction a;
constructor;
intros y H.
#!/usr/bin/env python
# Plot a graph of Data which is comming in on the fly
# uses pylab
# Author: Norbert Feurle
# Date: 12.1.2012
# License: if you get any profit from this then please share it with me
import pylab
from pylab import *
xAchse=pylab.arange(0,100,1)
# Lars.Rasmusson@gmail.com, 2015-03-03
# Using llvmlite from https://github.com/numba/llvmlite branch llvm3.6
# and llvm from http://llvm.org/git/llvm.git branch release_36
# and clang from http://llvm.org/git/clang.git branch release_36
# (when building llvmlite, I had to remove -flto in ffi/Makefile.linux
# because I was lazy and ld-gold was not setup correctly on my machine)
from llvmlite import binding as llvm
from llvmlite.llvmpy import core as llvmpy
# -*- coding: utf-8 -*-
"""
John McCarthy, who discovered Lisp, attributes this puzzle to Hans Freudenthal:
We pick two numbers a and b, so that 99 ≥ a ≥ b ≥ 2.
We tell Mr. P. the product a × b and Mr. S. the sum a + b.
Then Mr. S. and Mr. P. engage in the following dialog:
Mr. P.: I don’t know the numbers.
import os
def headerconstant(includefiles,name):
w,r = w,r=os.popen2("rm -f prog; gcc -x c -o prog -")
includes="\n".join(["#include <%s>"%x for x in includefiles])
s = ("""\
#include <stdio.h>
%s
int main() {
printf("%%ld", (long)%s);
@larsr
larsr / z3-sudoku.py
Last active September 23, 2015 12:53
game = """
. . . . . . 9 . .
7 . . 9 . . . 3 .
. . . . 3 . 1 . 7
. . . . . . . . .
4 . 3 1 . . 2 5 .
. . 6 . . . . . .
@larsr
larsr / tspi.py
Created April 13, 2012 13:57
Calling Trousers TSS stack from Python
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):