Skip to content

Instantly share code, notes, and snippets.

View alejandro's full-sized avatar

Alejandro Morales alejandro

  • Revls
  • Tegucigalpa, Honduras
View GitHub Profile
@isaacs
isaacs / comma-first-var.js
Created April 6, 2010 19:24
A better coding convention for lists and object literals in JavaScript
// See comments below.
// This code sample and justification brought to you by
// Isaac Z. Schlueter, aka isaacs
// standard style
var a = "ape",
b = "bat",
c = "cat",
d = "dog",
// attempts to get flash/session accessible in any template
// - this middleware function fails and keep producing 'Error: req.flash() requires sessions'
// - this middleware has been place *after* session middleware in the stack
app.use(function(req,res, next){
console.log("flash middleware")
res.locals({
session : req.session,
flash : req.flash()
});
});
@creationix
creationix / linux-node-joystick.js
Created January 28, 2012 21:49
Basic Linux Joystick support.
var FS = require('fs');
var EventEmitter = require('events').EventEmitter;
// http://www.mjmwired.net/kernel/Documentation/input/joystick-api.txt
function parse(buffer) {
var event = {
time: buffer.readUInt32LE(0),
number: buffer[7],
value: buffer.readInt16LE(4)
}
#include <Servo.h>
char messageBuffer[11];
int index = 0;
char cmd[3];
char pin[3];
char val[3];
char aux[4];
bool debug = false;
Servo servo;
@remy
remy / README.md
Created February 18, 2012 12:06
Waits for functions to complete before running complete

Unfinished and not tested beyond my own case.

Usage

var wait = new Wait();
wait.complete(function () {
  console.log('we are done - now report');
});
@twosixcode
twosixcode / gist:1988097
Created March 6, 2012 18:40
Make "Paste and Indent" the default paste in Sublime Text 2
// swap the keybindings for paste and paste_and_indent
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
@studgeek
studgeek / Heroku tracking branch.txt
Created March 8, 2012 16:55 — forked from seangeo/Heroku tracking branch.txt
Create a local tracking branch of your heroku/phpfog deployment
Create remote called heroku
> git remote add heroku git@heroku.com:YOURAPPNAME.git
create a local tracking branch called heroku
> git checkout -b heroku -t heroku/master
This will checkout the last revision you deployed to Heroku.
Now tell git to push the heroku branch to heroku/master
@TooTallNate
TooTallNate / bbs.js
Created March 16, 2012 22:42
Running a node.js REPL over `curl`
/**
* Requires node v0.7.7 or greater.
*
* To connect: $ curl -sSNT. localhost:8000
*/
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
@mikeal
mikeal / gist:2331127
Created April 7, 2012 18:22
safe .toJSON()
function getSafe (self, uuid) {
if (typeof self === 'object' || typeof self === 'function') var safe = {}
if (Array.isArray(self)) var safe = []
var recurse = []
Object.defineProperty(self, uuid, {})
var attrs = Object.keys(self).filter(function (i) {
if (i === uuid) return false
@pamelafox
pamelafox / util.js
Created April 13, 2012 17:44
JavaScript Utility Libraries (Scroll down!)
var ED = ED || {};
// Utility functions
ED.util = (function() {
// Data structure functions
function each(object, callback) {
if (object === null) return;