Skip to content

Instantly share code, notes, and snippets.

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 / 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;
@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 / 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 / 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 / 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;
};
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 / libao.conf
Created October 17, 2013 13:51
ogg123 and alsa dmix
default_driver=alsa
dev=default
@alepez
alepez / redmine_identifier_update.sql
Created July 24, 2013 16:03
Redmine: change project identifier with sql query.
UPDATE projects SET identifier = 'new_identifier' WHERE identifier = 'current_identifier';
@alepez
alepez / 24xx_i2c_address.rb
Last active December 20, 2015 03:19
Calculate 24xx eeprom addresses relationship with A0-A1-A2
8.times { |i| p "0x#{(0x50 + i).to_s(16)} => A0: #{(i & 0x1) == 1 ? "HIGH" : "LOW "}, A1: #{((i & 0x2) >> 1) == 1 ? "HIGH" : "LOW "}, A2: #{((i & 0x4) >> 2) == 1 ? "HIGH" : "LOW "}" }
# "0x50 => A0: LOW , A1: LOW , A2: LOW "
# "0x51 => A0: HIGH, A1: LOW , A2: LOW "
# "0x52 => A0: LOW , A1: HIGH, A2: LOW "
# "0x53 => A0: HIGH, A1: HIGH, A2: LOW "
# "0x54 => A0: LOW , A1: LOW , A2: HIGH"
# "0x55 => A0: HIGH, A1: LOW , A2: HIGH"
# "0x56 => A0: LOW , A1: HIGH, A2: HIGH"
# "0x57 => A0: HIGH, A1: HIGH, A2: HIGH"