Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / gist:7242691
Created October 31, 2013 00:31
print some code
enscript -E --color -wPostScript --toc -pfoo.ps *
@rgarcia
rgarcia / eat_bytes.sh
Last active December 27, 2015 04:59
memmon test
#!/usr/bin/env bash
# create a string of "a"s that is length $1
longstr=$(head -c $1 < /dev/zero | tr '\0' '\141')
sleep 1200
@rgarcia
rgarcia / main.coffee
Last active December 27, 2015 13:18
node: dangers of mixed objectMode
{Readable,Transform} = require 'stream'
crypto = require 'crypto'
report = (stream) ->
int = setInterval ->
console.log "#{stream.constructor.name}(#{stream._writableState?.length or ''} #{stream._readableState?.length or ''})"
, 1000
stream.on 'end', -> clearInterval int
# generates a bunch of bytes
@rgarcia
rgarcia / output.txt
Created November 6, 2013 07:03
string objectMode
{Readable,Transform} = require 'stream'
crypto = require 'crypto'
report = (stream) ->
int = setInterval ->
console.log "#{stream.constructor.name}(#{stream._writableState?.length or ''} #{stream._readableState?.length or ''})"
, 1000
stream.on 'end', -> clearInterval int
# generates a bunch of strings
@rgarcia
rgarcia / gist:7917826
Last active December 31, 2015 01:59
salt + docker
FROM salted
# /etc/hosts and /etc/hostname are read only. so change minion config
RUN HOSTNAME=`hostname` && sed "s/#id:/id: container-{{ name }}-$HOSTNAME/" -i /etc/salt/minion
ADD {{ salt_dir }} /srv/salt
ADD {{ pillar_dir }} /srv/pillar
RUN rm -f /etc/salt/minion_id
RUN salt-call --local state.highstate
@rgarcia
rgarcia / db_stats.go
Last active August 30, 2016 09:42
mongo db stats
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"os"
"strings"
"text/tabwriter"
@rgarcia
rgarcia / run.md
Last active August 29, 2015 13:57
node heap wtf
$ node --expose-gc server.js

in another terminal:

$ curl localhost:5001

output in first terminal shows that req.foo is still sitting in the heap: