Skip to content

Instantly share code, notes, and snippets.

@tj
tj / app.js
Created August 31, 2012 05:33
users online with redis
var express = require('express');
var redis = require('redis');
var db = redis.createClient();
var app = express();
// track users online (replace UA string with user id)
app.use(function(req, res, next){
var ua = req.headers['user-agent'];
@bhurlow
bhurlow / example.js
Last active October 13, 2015 20:07 — forked from jhs/example.js
My Node.js modules these days
// assets
// first installed modules
var util = require('util')
var assert = require('assert')
var whatever = require('whatever')
// then local
var foo = require('./foo')
var bar = require('./bar')
@mikeflynn
mikeflynn / etchosts.sh
Created December 13, 2012 19:04
An /etc/hosts manager bash script (v1.1) -- Added import and export commands!
#!/bin/bash
HOSTSFILE="/etc/hosts"
BAKFILE="$HOSTSFILE.bak"
DOMAINREGEX="^[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]+$"
IPREGEX="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
URLREGEX="^https?:\/\/[a-zA-Z0-9]{1}[a-zA-Z0-9\/\.\-]+$"
backup()
{
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 17, 2024 02:53
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@caged
caged / svg-to-png.js
Created January 27, 2013 18:11
Convert SVG's to PNGs. This works OK if the SVG's styles are inline. The SVG element must contain an xmlns attribute. Webkit also requires you specify a font size on `text` elements.
var svg = document.getElementById('graph'),
xml = new XMLSerializer().serializeToString(svg),
data = "data:image/svg+xml;base64," + btoa(xml),
img = new Image()
img.setAttribute('src', data)
document.body.appendChild(img)
@max-mapper
max-mapper / readme.md
Last active August 8, 2016 18:45
simple 4mb buffer proxy benchmarks

simple 4mb buffer proxy benchmarks

the goal: to do fast virtual host routing, e.g. to have a single process on a machine listening on port 80 and proxying data based on HTTP Host to other non-port-80 web processes on the same machine

many people use nginx for this because nginx is faster than node is currently for data-heavy applications (see below)

about these benchmarks

they use the JS proxies from https://github.com/substack/bouncy/tree/master/bench

@scttnlsn
scttnlsn / debounce.cljs
Created March 24, 2014 17:03
core.async debounce
(defn debounce [in ms]
(let [out (chan)]
(go-loop [last-val nil]
(let [val (if (nil? last-val) (<! in) last-val)
timer (timeout ms)
[new-val ch] (alts! [in timer])]
(condp = ch
timer (do (>! out val) (recur nil))
in (recur new-val))))
out))
@pyrtsa
pyrtsa / seqables_are_odd.clj
Created April 8, 2014 10:23
Seqables are odd in Clojure. Some functions auto-`seq`, some don't.
(empty? (d/datoms db :aevt :user/id))
;;=> false
(not-empty (d/datoms db :aevt :user/id))
;;=> #<db$datoms$reify__3265 datomic.db$datoms$reify__3265@7939b07>
(seq (d/datoms db :aevt :user/id))
;;=> (#Datum{:e 17592186046081 :a 70 :v "abc" :tx 13194139534976 :added true} ...)
(first (d/datoms db :aevt :user/id))
@staltz
staltz / introrx.md
Last active May 17, 2024 01:39
The introduction to Reactive Programming you've been missing
@yurrriq
yurrriq / flush_dns-mavericks.sh
Created June 24, 2014 20:43
Flush DNS Cache on Mac OS X 10.9.x
#!/bin/bash
dscacheutil -flushcache && sudo killall -HUP mDNSResponder