Skip to content

Instantly share code, notes, and snippets.

View indexzero's full-sized avatar
🌎
Always bet on Open Source

Charlie Robbins indexzero

🌎
Always bet on Open Source
View GitHub Profile
@indexzero
indexzero / SS.js
Created September 26, 2011 19:19
Comments in SugarSkull
(function(window, undefined) {
var dloc = document.location;
function regifyString(str) {
if(~str.indexOf('*')) {
str = str.replace(/\*/g, '([_\.\(\)!\\ %@&a-zA-Z0-9-]+)');
}
if(~str.indexOf(':')) {
str = str.replace(/:.*?\/|:.*?$/g, '([a-zA-Z0-9-]+)/');
@indexzero
indexzero / load-all-routes.js
Created October 4, 2011 13:20
Simple example of loading routes from multiple modules in node.js
var fs = require('fs'),
path = require('path'),
journey = require('journey');
exports.loadAllRoutes = function () {
var router = new (journey.Router)({
strict: false,
strictUrls: false,
api: 'basic'
@indexzero
indexzero / jshint.json
Created October 4, 2011 23:48
JSHint settings used @nodejitsu
{
"passfail": false,
"maxerr": 100,
"browser": true,
"node": true,
"rhino": false,
"couch": true,
"wsh": true,
"jquery": true,
@indexzero
indexzero / no-comma-first.js
Created October 4, 2011 23:59
JUST SAY NO TO COMMA FIRST
var fs = require('fs'),
path = require('path'),
colors = require('colors'),
argv = require('optimist').argv;
fs.readFile(path.join(__dirname, argv._[0]), function (err, data) {
var lines = data.toString().split('\n');
for (var i = 0; i < lines.length; i++) {
@indexzero
indexzero / rethrow-fail.js
Created October 6, 2011 04:19
An example of bad `uncaughtException` handling in node.js
process.on('uncaughtException', function (err) {
throw err;
});
process.on('uncaughtException', function (err) {
//
// This console.dir is never hit.
//
console.dir(err);
process.exit(1);
@indexzero
indexzero / start-and-monitor-with-forever.js
Created October 9, 2011 00:59
A simple hook to restart a process if it is hung (i.e. non-responsive)
var forever = require('forever'),
request = require('request');
function checkIsHung (monitor) {
//
// Do something to check if your process is hung
// e.g. Make an http request
//
request({ uri: 'http://yourapp.com' }, function (err, res, body) {
if (err) {
@indexzero
indexzero / app.in
Created October 25, 2011 16:49 — forked from tj/ast.js
Declarative JS
with application
set env to production
set view engine to jade
get /user/tj
send "hello"
delete /user/tj
send "no can do!"
// Here is a proposal for minimalist JavaScript classes, humbly offered.
// There are (at least) two different directions in which classes can be steered.
// If we go for a wholly new semantics and implementation, then fancier classical
// inheritance can be supported with parallel prototype chains for true inheritance
// of properties at both the class and instance level.
// If however, we keep current JavaScript prototype semantics, and add a form that
// can desugar to ES3, things must necessarily stay simpler. This is the direction
// I'm assuming here.
@indexzero
indexzero / opensource-guidelines.md
Created November 9, 2011 01:54
The least amount of guidelines possible to maintain 150+ open source node.js modules

Guidelines for Open Source at Nodejitsu

README.md Outline

  • Header
    • Brief description (should match package.json)
  • Example (if applicable)
  • Motivation (if applicable)
  • API Documentation: This will likely vary considerably from library to library.
  • Installation
var cursor = dbclient.collection('example', _).find(_);
var count = cursor.count(_);
for(var obj = cursor.nextObject(_), oi = 0; obj; obj =
cursor.nextObject(_), oi++) {
/**
* do something with every obj here
* suppose for this example it needs total count and offset (oi).
*/
});