Skip to content

Instantly share code, notes, and snippets.

@sli
sli / MongoProvider.cs
Created August 27, 2015 02:05
A quick and dirty example data provider using MongoDB.
/* This is an example implementation of a Mongo database driver built
* on the native C# driver. It acts as a singleton.
*
* Note that this is _not_ in any way a production-ready driver and is
* not meant to be used in the real world. It's simply example code
* that accesses a Mongo server and queries for data.
*/
using System;
using System.Collections.Generic;
@sli
sli / ParkingSensor.ino
Last active August 29, 2015 14:00
A simple parking sensor using the Arduino.
// Minimum distance before activating the warning light (in inches)
const int distanceMin = 6;
// Stop light blink interval
const int interval = 100;
// Pin setup
const int pinGo = 7;
const int pinStop = 8;
const int pingSig = 2;
@sli
sli / playlists.py
Last active August 29, 2015 14:09
Miniature playlist-parsing library.
''' Playlists
Quick and simple M3U and PLS playlist parser. Returns a list of media
elements.
'''
import configparser
def parse(contents):
if contents.split('\n', 1)[0] == '[playlist]':
@sli
sli / edge_detection.py
Last active August 29, 2015 14:14
Raspberry Pi Buttons + LEDs
import RPi.GPIO as GPIO
def led_callback(pin):
mode = GPIO.input(pin)
GPIO.output(led, mode)
if __name__ == '__main__':
led = 22
button = 18
@sli
sli / histo.py
Last active August 29, 2015 14:15
Manual histogram with Pillow.
import sys
import os
import math
from PIL import Image, ImageDraw
if len(sys.argv) > 1:
f = sys.argv[1]
else:
print('Usage: python histo.py <image filename>')
sys.exit(1)
@sli
sli / smallduino.c
Last active August 29, 2015 14:16
A subset of the Arduino library.
#include <avr/io.h>
#include <util/delay.h>
#define delay(x) _delay_ms(x)
#define delayMicroseconds(x) _delay_us(x)
static void pinMode(int pin, int setting) {
if (pin >= 0 && pin <= 7) {
if (setting > 0) { // Set to OUTPUT
DDRD |= (1<<pin);
@sli
sli / retrogame.c
Created April 1, 2015 22:12
Retrogame for arcade shit.
/*
ADAFRUIT RETROGAME UTILITY: remaps buttons on Raspberry Pi GPIO header
to virtual USB keyboard presses. Great for classic game emulators!
Retrogame is interrupt-driven and efficient (usually under 0.3% CPU use)
and debounces inputs for glitch-free gaming.
Connect one side of button(s) to GND pin (there are several on the GPIO
header, but see later notes) and the other side to GPIO pin of interest.
Internal pullups are used; no resistors required. Avoid pins 8 and 10;
these are configured as a serial port by default on most systems (this
@sli
sli / games
Last active August 29, 2015 14:18
games.sh
#!/bin/bash
NES='fceu'
PS3='Choose a game: '
options=("Cave Story" "Legend of Zelda" "Zelda II: The Adventure of Link" "Super Dodge Ball" "Excitebike" "Super Mario Bros." "Super Mario Bros. 2" "Super Mario Bros. 3" "Mega Man" "Kirby's Adventure" "pokemans" "Quit")
select opt in "${options[@]}"
do
@sli
sli / rplstack.py
Last active August 29, 2015 14:18
Pythonic RPL for some reason.
class RPLStack:
def __init__(self):
self._s = []
def ENTER(self, *n):
for i in n:
if isinstance(i, (int, float)):
self._s.append(i)
def DEPTH(self):
@sli
sli / mental.py
Last active August 29, 2015 14:26
A mental math trick implemented in Python
a = 567
b = 174
r = 0
p = 0
while a > 0:
d = (a % 10) * 10**p
r += b * d
a //= 10
p += 1