Skip to content

Instantly share code, notes, and snippets.

View plesner's full-sized avatar

Christian Plesner Hansen plesner

View GitHub Profile
@plesner
plesner / mosh-mini.sh
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
#!/bin/sh
set -e
# How often to send wake-on-lan pokes.
POKE_INTERVAL_SECS=60
# Mac address of the machine to poke.
MAC_ADDR=00:25:4b:a0:65:9c
@plesner
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
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
plesner / paper-backup.sh
Created March 18, 2015 12:25
Utility for encoding files as qr-codes on paper.
#!/bin/sh
# 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
KEYIN=$1
OUTFMT=key-%i.png
CHUNKSIZE=12
@plesner
plesner / sync-indicator.py
Created April 14, 2015 08:41
Command-line app indicator that shows syncing status
#!/usr/bin/python
from gi.repository import AppIndicator3 as AppIndicator
from gi.repository import Gtk
import re
import signal
import sys
import threading

Keybase proof

I hereby claim:

  • I am plesner on github.
  • I am p5r (https://keybase.io/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
plesner / xorshift.cc
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 {
public:
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
plesner / leaky_bucket.py
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
SELECT
stops.stop_name
, 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