Skip to content

Instantly share code, notes, and snippets.


Christian Plesner Hansen plesner

View GitHub Profile
plesner /
Last active Aug 29, 2015
Sh script for connecting to a machine while pinging it with a wake-on-lan package in the background every minute
set -e
# How often to send wake-on-lan pokes.
# Mac address of the machine to poke.
plesner / test.c
Last active Aug 29, 2015
Simple experiment with floating-point rounding modes in C
View test.c
#include <fenv.h>
#include <stdio.h>
#include <stdlib.h>
double do_the_thing(const char *mode) {
float b, v;
int i;
b = 0.01;
// Perform a lot of operations on b to accumulate rounding.
for (i = 0; i < 100000; i++)
plesner /
Created Mar 18, 2015
Utility for encoding files as qr-codes on paper.
# Utility for chopping a file into chunks of a certain number of lines and
# encoding each chunk as a qr code. For storing private keys on paper.
set -e

Keybase proof

I hereby claim:

  • I am plesner on github.
  • I am p5r ( on keybase.
  • I have a public key whose fingerprint is 6797 4944 0B13 F676 ACE2 2CAD B398 99E7 7971 5C1D

To claim this, I am signing this object:

plesner /
Last active Nov 26, 2015
Script for generating xorshift parameters for various set sizes
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
class Xorshift {
Xorshift(uint32_t x, uint32_t y, uint32_t z, uint32_t w)
: ox_(x), oy_(y), oz_(z), ow_(w)
, x_(x), y_(y), z_(z), w_(w) { }
plesner /
Created Aug 5, 2016
Leaky bucket rate limiter in pythong
def get_current_time_millis():
return int(time.time() * 1000)
# Rate limiter that issues permits at a certain rate but only allows a certain
# number of permits to accumulate regardless of how long you wait.
class LeakyBucket(object):
def __init__(self, permits_per_sec, max_accumulation):
self.millis_per_permit = 1000.0 / permits_per_sec
View departure_board.sql
, stop_times.departure_time_secs / 3600 AS departure_time_hours
, (stop_times.departure_time_secs / 60) - ((stop_times.departure_time_secs / 3600) * 60) AS departure_time_mins
, trips.trip_headsign
, routes.route_short_name
, calendars.monday
, calendars.tuesday
, calendars.wednesday
, calendars.thursday
plesner / polyenum.hs
Last active Feb 9, 2017
Polynomial range function in haskell
View polyenum.hs
-- Given a list of values, returns a list of the differences between
-- neighbouring pairs of values.
nextLevelDiffs (a:b:rest) = (b - a):(nextLevelDiffs (b:rest))
nextLevelDiffs _ = []
-- Given a list of values, returns a list of the differences such that the
-- first element is the 0-level differences, the second the 1-level and so
-- on.
nLevelDiffs [] = []
nLevelDiffs elms = elms:(nLevelDiffs (nextLevelDiffs elms))
plesner /
Created Apr 14, 2015
Command-line app indicator that shows syncing status
from gi.repository import AppIndicator3 as AppIndicator
from gi.repository import Gtk
import re
import signal
import sys
import threading
You can’t perform that action at this time.