Skip to content

Instantly share code, notes, and snippets.

View gist:2585933
lst = []
while (true):
lst.push(float(S.readline()))
if (lst.length == 60):
avg = reduce(lambda (s, x): s = s + x, lst) / lst.length
lst = []
postToServer(avg)
View gist:2586074
import sys
import urllib2
import json
lst = []
while (True):
lst.append(float(S.readline()));
if (len(lst) == 60):
avg = sum(lst) / len(lst)
@spion
spion / i3wm-reorient-vh.patch
Created Jun 7, 2012
i3wm "reorient v|h" command to change orientation of selected container. Don't forget to focus parent before running it.
View i3wm-reorient-vh.patch
diff --git a/i3.config b/i3.config
index 1a457fc..bf85f02 100644
--- a/i3.config
+++ b/i3.config
@@ -54,6 +54,13 @@ bindsym Mod1+h split h
# split in vertical orientation
bindsym Mod1+v split v
+# change to horizontal orientation
+bindsym Mod1+Shift+h reorient h
@spion
spion / latLngCoder.js
Created Jun 9, 2012
Encodes / decodes a latlng object to 10 characters with 6 decimal (< 0.5 meter) precision
View latLngCoder.js
/**
* Encode/decode latlng
*/
var latLngCoder = (function(map) {
map = map ? map : "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
var self = {};
var encodenum = function(num, len) {
enc = [];
while (num > 0) {
enc.unshift(map[num % map.length]);
@spion
spion / jscurry.js
Created Jun 21, 2012
JavaScript currying function
View jscurry.js
function curry(fn, args, len) {
var fnStr = fn.toString(),
argStart = fnStr.indexOf('(') + 1; argnames = fnStr.substr(argStart, fnStr.indexOf(')') - argStart).split(/[ ,]+/);
len = len?len:argnames.length
return function() {
var a = [], i = 0;
for (var k = 0; k < len; ++k)
if (args.hasOwnProperty(k))
a.push(args[k])
@spion
spion / node-scale.js
Created Jul 4, 2012
node.js scaling problem
View node-scale.js
/**
* Module dependencies.
*/
var async = require('async');
var cluster = require('cluster');
var http = require('http');
var url = require('url');
@spion
spion / a-warning.md
Last active Sep 18, 2020
C++ versus V8 versus luajit versus C benchmark - (hash) tables
View a-warning.md

Warning

This benchmark has been misleading for a while. It was originally made to demonstrate how JIT compilers can do all sorts of crazy stuff to your code - especially LuaJIT - and was meant to be a starting point of discussion about what exactly LuaJIT does and how.

As a result, its not indicative of what its performance may be on more realistic data. Differences can be expected because

  1. the text will not consist of hard-coded constants
@spion
spion / infraredaudio2binary.js
Created Jul 8, 2012
node.js infrared audio to binary
View infraredaudio2binary.js
var spawn = require('child_process').spawn,
info = spawn('file', [ process.argv[2] ]);
var infos = [];
info.stdout.setEncoding('utf8');
info.stdout.on('data', function(buf) { infos.push(buf); });
@spion
spion / costtest.py
Created Jul 14, 2012
The lightblub problem - cost testing framework.
View costtest.py
# Original problem:
# If you have 20 lightbulbs which break at certain height
# and a 100 floor bulding, how will you find the maximum
# height at which the lightbulbs can withstand the fall?
# Modified problem:
# For a given cost of climbing one floor (climbCost),
# descending one floor (descentCost) and breaking a
# lightbulb (breakCost), find the optimal algorithm
# that determines the maximum floor
@spion
spion / connect-list.js
Created Aug 14, 2012
connectjs middleware dependencies solution proposal
View connect-list.js
module.exports = function () {
var list = arguments;
return function (req, res, realNext) {
var id = -1;
var innerNext = function (err) {
var nextFn = ++id < list.length - 1 ? innerNext : realNext,
mw = list[id];
if (err) mw(err, req, res, nextFn);
else mw(req, res, nextFn);
};
You can’t perform that action at this time.