Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@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 / 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 / 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 / chat.rs
Created November 15, 2019 20:26
Rust chat server
use std::collections::hash_map::{Entry, HashMap};
use std::io::{self, BufRead, BufReader, Write};
use std::net::{TcpListener, TcpStream, ToSocketAddrs};
use std::sync::{
Arc,
mpsc::{self, Sender, Receiver},
};
use std::thread::{self};
#[derive(Debug)]
@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 / 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 / gateway.py
Last active April 16, 2020 21:49
Raspberry Pi RFM69 to MQTT gateway
# pip install spidev RPI.GPIO
# git clone https://github.com/etrombly/RFM69.git
#
# 19 MOSI
# 21 MISO
# 23 SCK
# 22 DI00
# 24 NSS
import time
### Keybase proof
I hereby claim:
* I am scttnlsn on github.
* I am scttnlsn (https://keybase.io/scttnlsn) on keybase.
* I have a public key ASB9vyD2EVSPOPFZSG40S9RvkY9urio90LlnLsBacf9Z5go
To claim this, I am signing this object:
@scttnlsn
scttnlsn / migrations.sql
Created April 4, 2019 20:12
Pure SQL migrations
--------------------------------------------------
--- SETUP
--------------------------------------------------
\set ON_ERROR_STOP true
CREATE TABLE IF NOT EXISTS migrations (
name CHAR VARYING PRIMARY KEY,
timestamp TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now()
);
@scttnlsn
scttnlsn / app.rb
Created October 18, 2011 13:59
Sinatra/Mongoid RESTful resource
require 'mongoid'
require 'sinatra'
require_relative 'resource'
class Example
include Mongoid::Document
field :name
field :created, :type => DateTime