Skip to content

Instantly share code, notes, and snippets.

View rgarcia's full-sized avatar

Rafael rgarcia

View GitHub Profile
@rgarcia
rgarcia / gist:7242691
Created October 31, 2013 00:31
print some code
enscript -E --color -wPostScript --toc -pfoo.ps *
@rgarcia
rgarcia / main.go
Last active December 22, 2015 20:59
pgp decrypt in go
package main
import (
gopgp "code.google.com/p/go.crypto/openpgp"
gopgperrors "code.google.com/p/go.crypto/openpgp/errors"
"fmt"
"io"
"os"
)
@rgarcia
rgarcia / json.go
Last active December 22, 2015 04:29
go data piping
package main
import (
"bufio"
"encoding/json"
"fmt"
"io"
"labix.org/v2/pipe"
"os"
)
@rgarcia
rgarcia / test.coffee
Last active December 20, 2015 17:38
node mem usage
# this will eat about 500MB of RAM
thecache = []
rnd_str = (length=30) ->
text = ""
possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
while text.length < length
text += possible.charAt(Math.floor(Math.random() * possible.length))
text
@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);
@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 / 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 / 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 / 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 / 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