Skip to content

Instantly share code, notes, and snippets.

View ctavan's full-sized avatar

Christoph Tavan ctavan

View GitHub Profile
@ctavan
ctavan / gist:1106547
Created July 26, 2011 11:38
Pass arrays to node-mysql's client.format()
var ids = [291, 9123, 218];
client.query(
'SELECT * FROM campaigns WHERE campaign_id IN (?)',
[ ids ],
function selectCb(err, results, fields) {
if (err) {
console.log(err);
throw err;
}
console.log(results);
@ctavan
ctavan / spawn.js
Created September 2, 2011 16:19
Spawning a childprocess in node.js
var spawn = require('child_process').spawn;
var proc = spawn('/path/to/executable', ['param1', 'param2', 'param3']);
var self = {
_stdoutBuf: '',
_stderrBuf: ''
};
proc.stdout.on('data', function(data) {
@ctavan
ctavan / averages
Created November 19, 2011 18:08
Benchmark results for node-uuid, see https://github.com/broofa/node-uuid/wiki/Benchmark
version node_uuid_v1_string node_uuid_v1_buf node_uuid_v4_string node_uuid_v4_buf libuuid_v4_string libuuid_v4_binary uuidjs_v1_string uuidjs_v4_string 140byte_es_v4
0.4.12 880183 729465 1.24115e+06 826444 246295 265074 217654 371096 184442
0.5.10 1.48504e+06 1.22108e+06 231354 186444 190173 213507 343986 492219 197463
0.6.0 1446553 1.11238e+06 227864 185221 167569 178823 358566 558284 205497
0.6.3 1.44182e+06 1.09582e+06 227247 182816 191369 207347 357010 550478 207418
@ctavan
ctavan / jshin-config.js
Created April 12, 2012 08:23
jshint config
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : false, // Standard browser globals e.g. `window`, `document`.
"node" : true,
@ctavan
ctavan / install_graylog.sh
Created July 12, 2012 10:09
Install mongodb, elasticsearch, graylog2, logstash on Ubuntu 12.04
#!/bin/bash
# WARNING: Don't use this in production since all passwords are kept at their default.
# mongodb
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo -e "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen\n" > /etc/apt/sources.list.d/mongodb-10gen.list
apt-get update
apt-get install -y mongodb-10gen
@ctavan
ctavan / clone
Created July 20, 2012 09:11
Cloning harddisks over the network using dd and nc
# clone harddisk from one machine to harddisk on another machine over the network
# on the target:
nc -l -p 7000 | gunzip | dd of=/dev/sda &
# on the source:
dd if=/dev/sda | gzip | nc <TARGET_IP> 7000 -q 10 &
# progress (on the source):
# get pid
@ctavan
ctavan / gist:3149813
Created July 20, 2012 09:19
Forward port 80 traffic to different host
TARGET=192.168.2.10
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination $TARGET:80
iptables -t nat -A POSTROUTING -j MASQUERADE
@ctavan
ctavan / chart_Shape__attrimage.patch
Created August 15, 2012 06:28
Patch against Ext-JS 4.0.2a
--- Shape_orig.js 2011-09-01 16:54:43.000000000 +0200
+++ Shape.js 2011-09-01 18:44:39.000000000 +0200
@@ -24,6 +24,17 @@
/* End Definitions */
+ image: function (surface, opts) {
+ return surface.add(Ext.applyIf({
+ type: 'image',
+ x: opts.x - opts.radius,
@ctavan
ctavan / gist:3800152
Created September 28, 2012 14:21
Convert list of strings to valid JSON array for loading in node.js
cat list.txt | sed 's/\(.*\)/"\1",/;1s/^/[/;$s/.$/]/' > list.json
@ctavan
ctavan / Makefile
Created September 29, 2012 12:54
Make targets for linting javascript code (node.js)
JSFILES = $(shell find lib test -name "*.js")
jshint: force
jshint $$JSFILES --config test/share/jshint.conf
gjslint: force
gjslint --debug_indentation --nojsdoc --unix_mode \
-e test/fixtures -r lib -r test
check: jshint gjslint