Skip to content

Instantly share code, notes, and snippets.

Christian Plesner Hansen plesner

Block or report user

Report or block plesner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@plesner
plesner / mosh-mini.sh
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
View mosh-mini.sh
#!/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 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
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
plesner / paper-backup.sh
Created Mar 18, 2015
Utility for encoding files as qr-codes on paper.
View paper-backup.sh
#!/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 Apr 14, 2015
Command-line app indicator that shows syncing status
View sync-indicator.py
#!/usr/bin/python
from gi.repository import AppIndicator3 as AppIndicator
from gi.repository import Gtk
import re
import signal
import sys
import threading
View keybase.md

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 Nov 26, 2015
Script for generating xorshift parameters for various set sizes
View xorshift.cc
#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 Aug 5, 2016
Leaky bucket rate limiter in pythong
View leaky_bucket.py
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
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
You can’t perform that action at this time.