Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dominictarr's full-sized avatar

Dominic Tarr dominictarr

View GitHub Profile
@dominictarr
dominictarr / stats_parse.rb
Created December 2, 2010 00:27
parse the monthy stats from awstats.***.tld
#! ruby
require "eregex"
@patterns = Hash.new
@keys = []
def path(dir, group=nil)
if (dir.is_a? String) then
dir = Regexp.escape(dir)
@dominictarr
dominictarr / hello_mongoose.js
Created December 13, 2010 07:51
hello_mongoose.js
var mongoose = require('mongoose').Mongoose
mongoose.model('User', { properties: ['name'] })
var db = mongoose.connect('mongodb://localhost/db');
db.addListener('error',function (error){
throw error
})
@dominictarr
dominictarr / globals.this-js
Created December 19, 2010 11:42
module where globals === this
console.log("GLOBALS!")
var assert = require('assert')
this.hello = 'sdgfasdgaghasdg'
assert.ok(global === this,'expected global === this')
assert.equal(this.hello , hello)
y = 'MVOISMDFOVISR'
assert.equal(this.y , 'MVOISMDFOVISR')
@dominictarr
dominictarr / module.main.js
Created February 2, 2011 10:06
module.main bug in node-v0.3.7
console.log("process.version = " + process.version )
console.log("module = ")
console.log(module)
console.log("process.mainModule = ")
console.log(process.mainModule)
console.log("require.main = ")
console.log(require.main)
@dominictarr
dominictarr / mixin2.js
Created February 6, 2011 00:26
adding assert functions to current module without breaking anything!
var assert = require('assert')
var s = 'var assert = require(\'assert\')\n'
for(var i in assert){
s += (ok.toString().replace(/ok/g,i)) + '\n'
}
function ok (){
assert.ok.apply(null,arguments)
}
@dominictarr
dominictarr / crash-minimal.js
Created March 3, 2011 08:09
minimal TypeErrors when it doesn't know what to do with a field.
// run with the following command: node test-node.js
var minimal = require("../minimal-node");
var $m = minimal.template("<html><head><title></title><body><p id='content'></p></body></html>");
$m({
title: "some title",
unknown: "not in template"
});
var http = require('http'),
fs = require('fs'), // to load html/js templates
window = require("jsdom").jsdom().createWindow(), // DOM/BOM
jQuery = require('jquery'), // for selectors
$p = require('pure').$p//FIX
templates = {};
http.createServer(function (req, res) {
@dominictarr
dominictarr / couch_proxy.js
Created March 4, 2011 07:29
proxy couchdb so that browser side js can query it.
var connect = require('connect')
, httpProxy = require('http-proxy')
//when a host:port/couch request comes in, remove /couch from url and proxy to host:5984
function couch (req,res,next){
console.log(req.url)
req.url = req.url.replace(/^\/couch/,'') || '/'
console.log(req.url)
@dominictarr
dominictarr / http-proxy-close.node.js
Created March 6, 2011 11:53
http-proxy does not properly close, and leaves node running.
var http = require('http'),
httpProxy = require('http-proxy'),
request = require('request')
// Create your proxy server
var proxied =
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
@dominictarr
dominictarr / git-commit-prefixes
Created May 23, 2011 23:02 — forked from Marak/git-commit-prefixes
Short list of Git commit prefixes used at Nodejitsu
[api]: New apis / changes to apis
[test]: Update test/* files
[dist]: Changes to submodules, version bumps, updates to package.json
[minor]: Small changes
[doc]: Updates to documentation
[ux]: Updates to UX
[fix]: Bug fixes
[bin]: Update binary scripts associated with the project
[merge]: Resolved git merge from upstream or otherwise
[refactor]: Refactor of existing code with no external API changes