Skip to content

Instantly share code, notes, and snippets.

// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
@chrishamant
chrishamant / lurker-list.js
Created March 28, 2011 13:29
quick and dirty command line tools I use to grep out projects 'I know I saved somewhere'
#!/usr/bin/env node
var rest = require('restler');
rest.get('http://github.com/api/v2/json/repos/watched/{username}').on('complete', function(data) {
data.repositories.forEach(function(repo){
console.log(repo.owner + "/"+ repo.name + " , " + repo.description + " , " + repo.language);
});
});
@chrishamant
chrishamant / twitter-searcher.js
Created March 28, 2011 13:45
quick and dirty script to search twitter streaming api
var sys= require('sys');
var OAuth= require('oauth').OAuth;
var TwitterNode = require('twitter-node').TwitterNode;
var consumer_key = "-";
var consume_secret = "-";
var access_token = "-";
var access_token_secret = "-";
//var oa= new OAuth("https://api.twitter.com/oauth/request_token","https://api.twitter.com/oauth/access_token", consumer_key, consume_secret, "1.0A", "http://localhost:3000/oauth/callback", "HMAC-SHA1");
@chrishamant
chrishamant / imagescraper.coffee
Created April 5, 2011 17:29
use node to scrape and save some images from a url
#!/usr/bin/env coffee
sys = require 'sys'
fs = require 'fs'
http = require 'http'
tovisit = []
imgcount = 0
getImage= (url)->
@chrishamant
chrishamant / Bootstrap.coffee
Created April 28, 2011 07:30
Simple asyncscript loader
#analytics stuff
_gaq = [['_setAccount','UA-XX-1'],['_trackPageview']]
d = window.document
l = d.location
scripts = [
'//google-analytics.com/ga.js',
'//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
'//' + l.host + '/js/site.js'
]
@chrishamant
chrishamant / Bootstrap.coffee
Created April 28, 2011 17:53
comparison of generated coffeescript code
#analytics stuff
_gaq = [['_setAccount','UA-18606719-1'],['_trackPageview']]
d = window.document
l = d.location
scripts = [
'google-analytics.com/ga.js',
'ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
l.host + '/js/site.js'
]
@chrishamant
chrishamant / example.js
Created May 2, 2011 00:55
Sample of discrepancy between mongo db parsers
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var Connection = require('mongodb').Connection;
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;
var nativeparser = new Db('testing', new Server(host, port, {}), {native_parser:true});
var jsparser = new Db('testing', new Server(host, port, {}));
var Foo = function(){
this.foo = "foo";
@chrishamant
chrishamant / hookpuller.py
Created May 2, 2011 23:47 — forked from JakeWharton/hookpuller.py
Takes a GitHub service hook POST and automatically updates the associated repo.
#!/usr/bin/env python
'''
Takes a GitHub service hook POST and automatically updates the associated repo.
'''
__license__ = '''
Copyright 2009 Jake Wharton
hookpuller is free software: you can redistribute it and/or modify
@chrishamant
chrishamant / extend.coffee
Created May 3, 2011 20:54
ecmascript snippet to copy properties to another object
Object.defineProperty(Object.prototype, "extend",
enumerable: false
value: (from)->
props = Object.getOwnPropertyNames(from)
dest = this
props.forEach((name)->
if (name in dest)
destination = Object.getOwnPropertyDescriptor(from, name)
Object.defineProperty(dest, name, destination)
return this;
@chrishamant
chrishamant / fixtures.js
Created May 4, 2011 04:37
some code to seed a database with fixtures
var sys = require("sys");
var fs = require('fs');
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSONNative;
var _ = require('nimble');
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;