Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@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 / .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 / 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 / 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 / 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 / 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 / core.cljs
Last active July 2, 2016 07:36
Om/Secretary nested routing
(ns nested-routing.core
(:require-macros [om.core :as om]
[secretary.core :refer [defroute]])
(:require [om.dom :as dom]
[om.core :as om]
[secretary.core :as secretary]
[goog.events :as events]
[goog.history.EventType :as EventType])
(:import goog.History))
@scttnlsn
scttnlsn / core.cljs
Created July 1, 2015 17:58
Reagent/Secretary nested routing
(ns nested-routing.core
(:require [goog.events :as events]
[goog.history.EventType :as EventType]
[reagent.core :as reagent]
[reagent.ratom :refer-macros [reaction]]
[re-frame.core :refer [dispatch dispatch-sync register-handler register-sub subscribe]]
[secretary.core :as secretary :refer-macros [defroute]])
(:import goog.History))
(declare route-components
@scttnlsn
scttnlsn / lispy-react.js
Last active April 21, 2021 23:09
Lispy React components
import React from 'react';
import ReactDOM from 'react-dom';
function html([type, props, ...children]) {
return React.createElement(type, props, ...children.map((child) => {
if (Array.isArray(child)) {
return html(child);
} else {
return child;
}
@scttnlsn
scttnlsn / Makefile
Last active March 13, 2017 01:06
AVR Makefile
TARGET = example
MCU = atmega328p
PROG = avrisp
PORT = /dev/cu.*usb*
BAUD = 57600
F_CPU = 16000000
# Sources
LIBS = $(shell find lib/* -type d 2> /dev/null)
SRC = $(wildcard src/*.c) $(foreach LIB, $(LIBS), $(wildcard $(LIB)/*.c))