Skip to content

Instantly share code, notes, and snippets.

@rgarcia
rgarcia / lolla.py
Last active September 25, 2015 09:47
script to tell us when the lollapalooza front page changes, so that we can get in on ticket deals quickly
#!/usr/bin/python
# script to tell us when the lollapalooza front page has changed, presumably to get ticket deals
import urllib2
import time
import md5
import smtplib
import random
from email.mime.text import MIMEText
def factorial_sumofdigits(n):
val = 1
for i in xrange(1,n+1):
val *= i
return sum([int(c) for c in str(val)])
for i in xrange(1,10000):
f = factorial_sumofdigits(i)
print i, f
if f == 8001:
@rgarcia
rgarcia / index.html
Created February 18, 2012 05:05
backbone + d3
<!DOCTYPE html>
<html>
<body>
<svg width="100%" height="100%"viewBox="0 0 50 50"></svg>
</body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script type="text/javascript">
@rgarcia
rgarcia / test.coffee
Created April 30, 2012 21:33
weird mongoose behavior
step = require 'step'
mongoose = require 'mongoose'
Schema = mongoose.Schema
schemas = {}
schemas.Foobar = new Schema
name : { type: String, trim: true, required: true, unique: true }
connection = mongoose.createConnection 'mongodb://127.0.0.1:27017/sandbox'
models = {}
@rgarcia
rgarcia / repro.coffee
Created April 30, 2012 21:49
working example
mongoose = require 'mongoose'
Schema = mongoose.Schema
schemas = {}
schemas.Foobar = new Schema
name : { type: String, trim: true, required: true, unique: true }
connection = mongoose.createConnection 'mongodb://127.0.0.1:27017/sandbox'
models = {}
models.Foobar = connection.model 'Foobar', schemas.Foobar
@rgarcia
rgarcia / proxy.coffee
Created November 21, 2012 21:13
node tcp proxy
net = require 'net'
assert = require 'assert'
settings =
# listen on this port
proxy_server:
host: 'localhost'
port: 4731
# and proxy this guy
@rgarcia
rgarcia / domains.coffee
Created December 22, 2012 05:41
playing with Node.js domains
domain = require 'domain'
bad = (msg, cb) ->
if (r = Math.random()) < 0.33
cb null, msg
else if r < 0.66
cb new Error('error via callback')
else
throw new Error('error via exception')
@rgarcia
rgarcia / output.txt
Last active December 11, 2015 22:28
node streams v2
CSVP <Buffer 61 2c 62 2c 63 2c 64 0a 31 2c 32 2c 33 2c 34 0a 35 2c 36 2c 37 2c 38 0a>
DUMP { a: '1', b: '2', c: '3', d: '4' }
@rgarcia
rgarcia / underscore.stream.coffee
Last active December 11, 2015 23:58
more streams2
_ = require 'underscore'
stream = require 'stream'
fs = require 'fs'
csv = require 'csv'
# apply() for constructors
construct = (constructor, args) ->
F = -> constructor.apply this, args
F.prototype = constructor.prototype
new F
@rgarcia
rgarcia / domain-errors.js
Created June 28, 2013 18:04
useful domain error handling example from nodeconf
var util = require("util");
var domain = require("domain");
var express = require("express");
var defaultErrHandler = express.errorHandler();
module.exports = function totallyUseless(error, req, res, next) {
console.error("in error handler", error.stack)
if (domain.active) {
domain.active.emit("error", error);