Skip to content

Instantly share code, notes, and snippets.

View plesner's full-sized avatar

Christian Plesner Hansen plesner

View GitHub Profile
, 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 /
Created August 5, 2016 10:28
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
plesner /
Last active November 26, 2015 10:28
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) { }

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 /
Created April 14, 2015 08:41
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
plesner /
Created March 18, 2015 12:25
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
plesner / test.c
Last active August 29, 2015 14:09
Simple experiment with floating-point rounding modes in 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 / polyenum.hs
Last active February 9, 2017 02:55
Polynomial range function in haskell
-- 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 /
Last active August 29, 2015 14:06
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.