Skip to content

Instantly share code, notes, and snippets.

@sli
sli / partial.hy
Created July 19, 2016 22:39
Figuring out Lisp by implementing partials in hy.
(defn partial [f arg &rest args1]
(defn p [&rest args2]
(apply f (+ (list* arg (list args1)) (list args2)))))
(defn add [a &rest b]
(+ a (reduce + b)))
(def add10 (partial add 10))
(print (add10 15 20))
@sli
sli / composer.py
Last active July 1, 2016 00:46
Function composition and chaining in Python.
def chain(*args):
result = args[0]
for func in args[1:]:
result = func(result)
return result
def compose(*funcs):
cfuncs = []
for func in funcs:
if hasattr(func, '__call__'):
@sli
sli / bclock.htm
Last active June 25, 2016 03:51
A shitty binary clock.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Binary Clock</title>
<style>
/*body { background-color: #a2d5d5; }
table { border-collapse: collapse; border-width: 1px; }
td { border: 1px solid black; }*/
#h td { background-color: #f6bbca; }
@sli
sli / readadc.py
Last active June 15, 2016 16:24
Read from an ADC channel on a Raspberry Pi. Shamelessly lifted from Adafruit.
import RPi.GPIO as GPIO
def readadc(adcnum, clockpin=18, mosipin=23, misopin=24, cspin=25):
if adcnum > 7 or adcnum < 0:
return -1
GPIO.output(cspin, True)
GPIO.output(clockpin, False) # start clock low
GPIO.output(cspin, False) # bring CS low
@sli
sli / ips.py
Last active January 9, 2024 22:41
Python IPS patcher.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# IPS Patcher
# Copyright (©) itari 2014
# Do whatever you want with this, I don't care. :D
#
# Modified by sli to work on the command line and with
# Python 3. Who even uses Tkinter anymore?
@sli
sli / SamuraiArduino.ino
Last active May 19, 2016 22:32
Samurai Arduino - A reaction game for the Arduino that plays like Samurai Kirby. Uses two buttons and an RGB LED.
volatile int state = 0; // current state in the FSM
volatile int activePlayer; // this game's winner or loser
const int redPin = 3;
const int greenPin = 4;
const int bluePin = 5;
const int p1_button = 6;
const int p2_button = 7;
@sli
sli / dragonballgo.py
Last active May 12, 2016 17:39
DragonBallGo.co API
import re
import requests
import urllib.parse
from bs4 import BeautifulSoup
url_base = 'http://dragonballgo.co/series/'
episode_base = 'http://dragonballgo.co/lib/picasa.php'
post_re = re.compile('data: (.*?)')
@sli
sli / pi-node.md
Last active March 17, 2016 21:23
Pi Node

Pi Node

  • Touchscreen interface
  • Sensors
  • Sensor-based games
  • Texting/chat
  • Imaging (cheapest camera)
  • Live sensor data display
@sli
sli / sensor-network.md
Last active March 17, 2016 21:22
Sensor Network notes

sensed

  • First generation of the protocol, uses SocketIO and JSON for communication
  • sensed listens for data requests and responds accordingly
  • This method allows for managing of network resources and requesting data from specific sensors
  • senselog client round-robin requests data from each connected node, inserting the data into a Mongo database
  • senselog is a client reference implementation, sensed doesn't care about the client's purpose

lidard

  • Second generation of the protocol, uses UDP and msgpack for communication
  • msgpack is JSON-like, but is a binary format and results in much smaller packets
@sli
sli / PiCade.md
Last active March 10, 2016 23:28
Notes on the PiCade