Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@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)]
### 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 / 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
@scttnlsn
scttnlsn / README.md
Created March 10, 2018 21:00
Enable USB mass storage on Raspberry Pi Zero

Create new filesystem:

sudo dd if=/dev/zero of=/usb.bin bs=512 count=51200
sudo mkdosfs /usb.bin
  • Add dwc2 to /etc/modules-load.d/modules.conf
  • Add dtoverlay=dwc2 to /boot/config.txt
  • reboot
@scttnlsn
scttnlsn / mqtt_relay.py
Created January 18, 2018 16:12
ESP8266 + MQTT relay
import machine
import network
import ubinascii
from umqtt.simple import MQTTClient
SSID = ''
PASSWORD = ''
BROKER = ''
TOPIC = ''
@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))
@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 / 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 / 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))