Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@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))
@scttnlsn
scttnlsn / example.js
Last active December 30, 2015 23:39
CSP with JavaScript (ES6 only)
// node --harmony example.js
var go = require('./go');
var even = go.channel();
var odd = go.channel();
go(function* () {
for (var i = 0; i < 10; i += 2) {
yield even.put(i);
@scttnlsn
scttnlsn / example.html
Last active December 17, 2015 16:39
Flight-inspired mixin composition
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>
<script src="http://backbonejs.org/backbone.js"></script>
<script src="wings.js"></script>
<script>
@scttnlsn
scttnlsn / queue.go
Last active July 5, 2023 14:30
Queue server in Go
package main
import (
"bufio"
"flag"
"fmt"
"net"
"strconv"
"strings"
"time"
@scttnlsn
scttnlsn / .bashrc
Last active December 16, 2015 22:39
Redis launch agent
alias redis-start="launchctl start io.redis.redis-server"
alias redis-stop="launchctl stop io.redis.redis-server"
alias redis-status="launchctl list | grep io.redis.redis-server"
@scttnlsn
scttnlsn / env.js
Created January 31, 2013 17:55
RequireJS plugin to conditionally load modules based on environment
// Include { env: 'development' } in your RequireJS config
// When building (with r.js) set the value to 'production' or just omit it entirely
//
// Assuming the following directory structure:
// - config/
// - development.js
// - production.js
//
// Load the appropriate file based on the current env:
//
@scttnlsn
scttnlsn / README.md
Created August 21, 2012 16:13
Git as a key/value store

git-store

$ git init mystore
$ cd mystore

$ git store set foo "this is foo"
$ git store get foo
this is foo
@scttnlsn
scttnlsn / README.md
Created July 30, 2012 22:16
Pub/sub with MongoDB and Node.js

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@scttnlsn
scttnlsn / coffeescript-ifer.sublime-snippet
Created June 11, 2012 16:56
ST2 Snippet: if (err) return callback(err)
<snippet>
<content><![CDATA[return ${1:callback} ${2:err} if ${2:err}?]]></content>
<tabTrigger>ifer</tabTrigger>
<scope>source.coffee</scope>
<description>ifer</description>
</snippet>
@scttnlsn
scttnlsn / server.js
Created May 18, 2012 17:46
Serving thumbnails on-the-fly with Nettle and Express
var express = require('express');
var im = require('imagemagick');
var nettle = require('nettle');
var app = express.createServer();
var store = nettle.store({ url: 'mongodb://localhost:27017/mydb' });
// Create Nettle processor to resize image
var createProcessor = function(width) {
store.processor(width, function(buffer, callback) {