Skip to content

Instantly share code, notes, and snippets.

View richardolsson's full-sized avatar

Richard Olsson richardolsson

View GitHub Profile
@richardolsson
richardolsson / up.sh
Created March 16, 2015 08:04
up.sh - Simplified Docker Compose replacement
#!/bin/sh
build_if_not_exists() {
# Param $1: name of image
# Param $2: path to build context
images=`docker images |grep -e ^$1[[:space:]]`
if [ -z "$images" ]; then
echo building $1
docker build -t $1 $2
else
@richardolsson
richardolsson / gist:be16453fb9e6f1fa3528
Created December 2, 2014 09:26
Falcon routing tree prototype
class RouteNode(object):
def __init__(self, segment, responder=None):
self._children = []
self.segment = segment
self.responder = responder
def traverse(self, segments, index=0, seg_count=None):
if seg_count is None:
seg_count = len(segments)
@richardolsson
richardolsson / calcRiksdagSeats.js
Created June 17, 2013 08:37
Javascript to calculate seats in the Swedish parliament, The Riksdag, based on total number of votes and the results (percentage of votes) for an arbitrary number of parties.
/**
* Calculate number of seats in the Swedish parliament for an arbitrary number
* of parties, from the total number of votes and each party's result as a
* percentage of the total vote. Return an array containing the parties' respective
* number of seats.
*
* The seats are distributed using a "Modified Sainte-Laguë method" algorithm where
* the first divisor is 1.4.
*
* In short, each party is given a "comparison value" based on the total number
@richardolsson
richardolsson / Basic_Stereo.as
Created August 7, 2012 10:31
Simple example of how to use new Away3D stereoscopic rendering
// This example uses the stereoscopic rendering feature of Away3D that
// has not yet been merged into any of the main branches. At the time
// of writing this, the below code requires the "stereofeature" branch
// of Away3D.
//
// The running demo can be found here:
// https://dl.dropbox.com/u/1560087/away3d/stereo/Basic_Stereo.html
//
// Note that this feature may or may not make it into main Away3D.
//