Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / app.js
Created May 27, 2011 16:11
Embedding another application with Express
var express = require('express')
var app = express.createServer()
// Configuration
app.configure(function() {
this.set('views', __dirname + '/views')
.set('view engine', 'jade')
.use(express.static(__dirname + '/public'))
.set('view options', {title: 'Express'})
@naholyr
naholyr / class.php
Created June 6, 2011 08:29
PHP Sadness... Callbacks as arguments
<?php
class c {
public $f;
public function __construct() {
$this->f = function() { echo 'coucou'; };
}
}
// Note: "public $f = function() {...}" is a syntax error...
@naholyr
naholyr / gist:1048660
Created June 27, 2011 10:45
Quick 'n dirty Bash completion for "pman"
We couldn’t find that file to show.
@naholyr
naholyr / update-sublime-text.sh
Created September 6, 2011 15:27
Install or update Sublime Text from web site
#!/bin/bash
# Requirements: sed, grep, curl, pkill
# User configuration
LOCAL_INSTALL="/usr/lib/sublime-text-2" # Must be user-writable
REPO="dev" # "dev" for dev releases, or "2" for beta releases
TARGET_BUILD="Linux 32 bit" # can be one of "Windows", "Windows 64 bit", "OS X", "Linux 32 bit", "Linux 64 bit"
# Check if sublime text is running
@naholyr
naholyr / binlog-tailer.js
Created October 11, 2011 21:29 — forked from laverdet/binlog-tailer.js
MySQL binlog tailer
"use strict";
this.MysqlBinlogTailer = MysqlBinlogTailer;
var EventEmitter = require('events').EventEmitter;
var fs = require('fs');
var path = require('path');
/**
* Tails a Mysql binlog and emits an event for every query executed.
*/
@naholyr
naholyr / command.sh
Created January 5, 2012 23:10
Failed continuous replication with CouchDB
curl -H 'Content-Type: application/json' -X POST http://localhost:5984/_replicate -d ' {"source": "http://isaacs.iriscouch.com/registry", "target": "npmregistry", "create_target": true, "continuous": true} '
@naholyr
naholyr / auth.js
Created January 10, 2012 06:22
[snippet] implement "remember me" with BrowserId
// https://github.com/mozilla/browserid/wiki/Advanced-BrowserID-Features
function login () {
function gotAssertion (assertion) {
if (assertion) {
// User chose not to log in, or an error occurred
} else {
// Ajax call to server to check email
}
}
@naholyr
naholyr / backend.js
Created January 23, 2012 18:28
GeoChatHTML5
var io = require('socket.io').listen(8123);
io.sockets.on('connection', function (socket) {
socket.on('username', function (username) {
this.set('username', username, function () {
socket.broadcast.emit('newcomer', username);
socket.emit('ready', username);
});
});
@naholyr
naholyr / gist:1682312
Created January 26, 2012 11:21 — forked from mhawksey/TAGSStats.R
Read edge list from TAGS Spreadsheet calculate SNA data and POST back
library(igraph)
library(reshape)
library(plyr)
require(RJSONIO)
require(RCurl)
# Google Spreadsheet key (must be published to the web)
key='0AqGkLMU9sHmLdGNYZDVyTWl1ZmtNbmFzWGlpUkt1Tmc'
# Sheet gid name
gid=105
@naholyr
naholyr / svn-branch.sh
Created February 1, 2012 15:51
Branching with SVN
# Retrieve repository URL
function svn-url() {
LANG=en_US svn info "$1" | grep '^URL *:' | sed 's/^URL *: //'
}
# Branching
function svn-branch() {
if [ ! -d .svn ]; then return 1; fi
if svn-url | grep '/trunk' &> /dev/null; then
echo trunk