Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / libao.conf
Created October 17, 2013 13:51
ogg123 and alsa dmix
default_driver=alsa
dev=default
var gpio = require("pi-gpio");
gpio.open(11, "input", function(err) { if (err) { console.log(err); }});
setInterval( function() { gpio.read(11, function(err, value) { console.log("value:", value); }); }, 1000);
@alepez
alepez / classical_vs_prototypal.js
Created November 4, 2013 14:19
node.js profiling memory classical vs prototypal
var memwatch = require('memwatch');
var classical = function() {
var Apple = function(options) {
var self = this;
var color = options.color;
var getColor = function() {
return color;
};
@alepez
alepez / omx.js
Last active December 27, 2015 11:49
var spawn = require('child_process').spawn;
var util = require('util');
var commands = {
'pause' : 'p',
'quit' : 'q',
'play' : '.', // TODO: check
'forward' : "$'\\x1b\\x5b\\x43'", // TODO: check
'backward' : "$'\\x1b\\x5b\\x44'" // TODO: check
};
@alepez
alepez / launch_detached.js
Last active December 27, 2015 11:59
Launch a detached process of node running 'app.js' in the same directory of this script.
#!/usr/bin/env node
var spawn = require('child_process').spawn;
var path = require('path');
var nodeBin = process.execPath;
var appjs = path.resolve(__dirname, 'app.js');
var options = { detached: true, stdio: 'ignore', cwd: __dirname };
var child = spawn(nodeBin, [appjs], options);
child.unref();
@alepez
alepez / EventEmitter_Object_create.js
Created November 6, 2013 13:38
inherit EventEmitter Crockford's way
var EventEmitter = require('events').EventEmitter;
var a = Object.create(EventEmitter.prototype);
a.on('x', function() { console.log("x!"); });
a.emit("x");
@alepez
alepez / express-recursive-routing.js
Last active December 28, 2015 04:59
express recursive routing with namespace
var fs = require('fs');
var path = require('path');
var walk = function(dir, done) {
var results = {};
fs.readdir(dir, function(err, list) {
if (err) {
return done(err);
}
var i = 0;
To make the black pixels transparent and keeps the white pixels as they are, run this command:
convert source.png -alpha copy -fx '#fff' result.png
@alepez
alepez / vertical_blur.glsl.rb
Created January 21, 2014 10:37
glsl shader generator for vertical blur with weights from Pascal Triangle
#!/usr/bin/env ruby
## first parameter is the row number from pascal triangle
def triangle(n)
ret = []
(0..n).each{|r|
lst=[1]
term=1
k=1
ffmpeg: skip frames
-vf select="gte(n\, 5)"