Skip to content

Instantly share code, notes, and snippets.

@scttnlsn
scttnlsn / chat.rs
Created Nov 15, 2019
Rust chat server
View chat.rs
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)]
View gist:b4d245743b12a8ddf60816eebed705e3
### 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 Apr 4, 2019
Pure SQL migrations
View migrations.sql
--------------------------------------------------
--- 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 Apr 16, 2020
Raspberry Pi RFM69 to MQTT gateway
View gateway.py
# 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 Mar 10, 2018
Enable USB mass storage on Raspberry Pi Zero
View README.md

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 Jan 18, 2018
ESP8266 + MQTT relay
View mqtt_relay.py
import machine
import network
import ubinascii
from umqtt.simple import MQTTClient
SSID = ''
PASSWORD = ''
BROKER = ''
TOPIC = ''
@scttnlsn
scttnlsn / Makefile
Last active Mar 13, 2017
AVR Makefile
View 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 Apr 21, 2021
Lispy React components
View lispy-react.js
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 Jul 1, 2015
Reagent/Secretary nested routing
View core.cljs
(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 Jul 2, 2016
Om/Secretary nested routing
View core.cljs
(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))