Skip to content

Instantly share code, notes, and snippets.

@jstimpfle
jstimpfle / .xsession
Created April 30, 2016 00:53
xinput commands to configure trackpoint scrolling
# activate middle click + trackpoint scrolling
xinput set-prop 'TPPS/2 IBM TrackPoint' 'Evdev Wheel Emulation' 1
xinput set-prop 'TPPS/2 IBM TrackPoint' 'Evdev Wheel Emulation Button' 2
xinput set-prop 'TPPS/2 IBM TrackPoint' 'Evdev Wheel Emulation Timeout' 220
# horizontal scrolling
xinput set-prop "TPPS/2 IBM TrackPoint" "Evdev Wheel Emulation Axes" 6 7 4 5
@jstimpfle
jstimpfle / countInversions.c
Last active June 19, 2016 15:29
Count inversions of integers read from standard input. Basic C
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void *xrealloc(void *p, size_t sz)
{
p = realloc(p, sz);
if (p == NULL) {
fprintf(stderr, "OOM!\n");
-- Applicative instance where we have NOT (ap = (<*>))
-- is this valid?
data ParFallible e a = Fail e | Success a
instance Functor (ParFallible e) where
fmap _ (Fail e) = Fail e
fmap f (Success a) = Succes (f a)
instance Monoid e => Applicative (ParFallible e) where
-- some custom atomic datatype, defined in Atom.hs
newtype Atom = Atom ByteString deriving (Ord)
-- another custom datatype
newtype DbInt = DbInt Word64 deriving (Ord)
-- and so on.
-- DbIndex.hs
-- an index doesn't know of all the possible datatypes we might want to use.
-- So we can't use a sum type (Expression Problem), but need these datatypes wrapped in an existential type.
data Cell where
/* benchmark for testing function call overhead of function pointer
* integer lexem parsing, vs inlined integer lexem parsing
*/
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BUFSIZE ((size_t)(1024*1024*1024))
@jstimpfle
jstimpfle / htmltagsreplace.py
Last active April 19, 2017 18:05
Replace magic HTML tags with the result of python calls.
"""Replace magic HTML tags with the result of function calls.
For now, only self-closing tags (<TAGNAME .../>) are supported. This is for
simplicity and also because otherwise we'd have to decide how to check for
proper nesting and to handle body arguments (lazy or strict call order, ... ?)
We don't even try to parse valid HTML here. We're just looking for
the next occurrence of "<TAGNAME" for any given TAGNAME.
This is easy to implement and better for performance.
#!/usr/bin/python3
# This is useful for editing multi-line C macros
import sys
lines = [line.rstrip(' \\\n').rstrip() for line in sys.stdin]
maxlen = max(len(line) for line in lines)
for line in lines:
print(line + ' '*(2 + maxlen - len(line)) + '\\')
-- Stateful closure in Haskell
import Data.IORef
makeCounter :: IO (Int -> IO Int)
makeCounter = do
state <- newIORef 0
return $ \i -> do
modifyIORef state (+i)
readIORef state
@jstimpfle
jstimpfle / test.ps
Created June 3, 2017 16:27
dabbling in postscript
1 setlinewidth
% move somewhere near the center of an A4/letter page
100 500 moveto
% string -> (Write the string)
/logstring
{
(%stdout) (w) file
exch writestring
} def
@jstimpfle
jstimpfle / htmltemplates.py
Last active June 12, 2017 16:15
Poor man's POWERFUL html templating system for python
import sys
class Element:
def __init__(self, name, **attributes):
self.name = name
self.attributes = attributes
self.childs = []
def setAttribute(self, key, val):