Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gorgi Kosev spion

:shipit:
View GitHub Profile
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)
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 June 7, 2012 02:43
i3wm "reorient v|h" command to change orientation of selected container. Don't forget to focus parent before running it.
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 June 9, 2012 15:22
Encodes / decodes a latlng object to 10 characters with 6 decimal (< 0.5 meter) precision
/**
* 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 June 21, 2012 11:14
JavaScript currying function
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 July 4, 2012 00:04
node.js scaling problem
/**
* 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 March 25, 2024 03:01
C++ versus V8 versus luajit versus C benchmark - (hash) tables

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 July 8, 2012 17:08
node.js infrared audio to binary
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 July 14, 2012 19:40
The lightblub problem - cost testing framework.
# 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 August 14, 2012 17:25
connectjs middleware dependencies solution proposal
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);
};