Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🗽
✊ Fist in the air in the land of hypocrisy

Charlie Robbins indexzero

🗽
✊ Fist in the air in the land of hypocrisy
View GitHub Profile
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@csanz
csanz / slideshow.js
Created April 24, 2012 19:27
intro to node.js slide show app written in node.js
var color = require('colors');
var stdin = process.openStdin()
, slides = {
1: "\tNode.js" +
"\n\n\t\tJavascript running on the server" +
"\n\n\t\tWritten in C++ (POSIX)" +
"\n\n\t\tWraps V8 JS VM (Google/Chrome)"
, 2: "\tOthers / Evented I/O" +
"\n\n\t\t > Reactor Pattern" +
"\n\n\t\t > EventMachine(Ruby) / Twisted (Python)" +

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.

@PatrickHeneise
PatrickHeneise / gist:2132062
Created March 20, 2012 06:38
passport.js with flatiron.js, union and director
var flatiron = require('flatiron')
, connect = require('connect')
, path = require('path')
, fs = require('fs')
, plates = require('plates')
, director = require('director')
, util = require('util')
, keys = require('./auth_keys')
, passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy
@heapwolf
heapwolf / DTraceBuiltins.md
Created February 24, 2012 14:26
Builtins for the DTrace D-Language
Type Name Description
int64_t arg0, ..., arg9 The first ten input arguments to a probe represented as raw 64-bit integers. If fewer than ten arguments are passed to the current probe, the remaining variables return zero.
array args[] The typed arguments to the current probe, if any. The args[] array is accessed using an integer index, but each element is deined to be the type corresponding to the given probe argument. For example, if args[] is referenced by a read(2)system call probe, args[0] is of type int, args[1] is of type void *, and args[2] is of type size_t.
uintptr_t caller The program counter location of the current thread just before entering the current probe.
chipid_t chip The CPU chip identiier for the current physical chip.
processorid_t cpu The CPU identiier for the current CPU.
cpuinfo_t *curcpu The CPU information for the current CPU.
lwpsinfo_t *curlwpsinfo The lightweight process (LWP) state of the LWP a
@jed
jed / api.js
Created February 13, 2012 14:32
using uglify to turn javascript functions into DynamoDB query language
// just a quick brainstorm for my dynamo API: https://github.com/jed/dynamo
// is it worth it to use uglify-js to parse functions into ASTs, to be transformed into dynamo's non-standard query language?
// the good:
// - no need to learn new API, just use javascript to query
// - API ends up resembling well-known .map and .filter style
// - would be entirely optional, compiling into specifiable query objects
// the bad:
@Gozala
Gozala / example.js
Created January 29, 2012 03:46
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
/*
Pascal's triangle
0 001
1 001 001
2 001 002 001
3 001 003 003 001
4 001 004 006 004 001
5 001 005 010 010 005 001
6 001 006 015 020 015 006 001
@weavenet
weavenet / gist:1524092
Created December 27, 2011 15:50
Quick github repo backup script
#!/bin/bash
# Script to backup git repo to S3
# Set bucket, dir, password and account to use for the backup. I keep mine in local env vars
# These are set by localrc which lives on an encrypted home directory and is executed by my bashrc
bucket=$GITHUB_BACKUP_BUCKET
dir=$GITHUB_BACKUP_DIR
password=$GITHUB_BACKUP_PASSWORD
account=$GITHUB_ACCOUNT
/**
* The Article domain object, this can be completely custom or
* part of some ORM. It doesn't really matter. It's an object you
* can call methods on. As long as you return some compatible
* promise-like thing to the data/render cycle
*/
var util = require('util')
, Q = require('q') // https://github.com/kriskowal/q
, db = require('./data-layer')
, Domain = require('./domain');