Skip to content

Instantly share code, notes, and snippets.

@lrvick
lrvick / spectrum.ino
Created September 6, 2012 02:14
Arduino sketch to convert output from a MSGEQ7 graphic equalizer display filter to RGB values that are fed to BlinkM tricolor LED modules for music visualization
#include "Wire.h"
#include "BlinkM_funcs.h"
#define blinkm_addr 0x00
#define blinkm1_addr 0x09
#define blinkm2_addr 0x10
int spectrumReset=5;
int spectrumStrobe=4;
int spectrumAnalog=0; //0 for left channel, 1 for right.
@lrvick
lrvick / pi_gpio_fuzz.sh
Created August 16, 2012 10:24
Send 1hz pulse to all Raspberry Pi GPIO pins for testing, using bash
#!/bin/bash
pins=( 4 25 24 23 22 21 18 17 )
for pin in "${pins[@]}"; do
echo $pin > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio${pin}/direction
sleep 0.1
done
@lrvick
lrvick / StyleGuide.md
Created July 16, 2012 23:19
Lance's Code Style Guide
@lrvick
lrvick / timelapse.py
Created July 15, 2012 02:01
Simple script to run a timelapse on a canon camera from a raspberry pi with an attached HD44780 display
from hd44780 import HD44780
import ctypes
from time import sleep
class CameraFilePath(ctypes.Structure):
_fields_ = [('name', (ctypes.c_char * 128)),
('folder', (ctypes.c_char * 1024))]
gp = ctypes.CDLL('libgphoto2.so.2')
@lrvick
lrvick / q3lcd.py
Created July 7, 2012 11:35
Quake3 logger for the raspberry pi that outputs to an attached HD44780 LCD using my library for it
from hd44780 import HD44780
from os import stat
from time import sleep
lcd = HD44780()
lcd.message(" Quake3 Logger\nCommence killing...")
logfile_name = 'game.log'
@lrvick
lrvick / init.sh
Created May 8, 2012 03:00
Chrooted Arch Linux environment setup script for Android
USER='lrvick'
cd /data/local/arch
if ! mountpoint -q dev; then
mount -t proc /proc proc
mount -o bind /dev dev
mount -o bind /dev/pts dev/pts
fi
@lrvick
lrvick / github_flask.py
Created April 26, 2012 06:47
Github API access with Flask and rauth
from flask import Flask, request, redirect, url_for
from rauth.service import OAuth1Service, OAuth2Service
github = OAuth2Service(
name='github',
consumer_key='GITHUB_CONSUMER_KEY',
consumer_secret='GITHUB_CONSUMER_SECRET',
access_token_url='https://github.com/login/oauth/access_token',
authorize_url='https://github.com/login/oauth/authorize',
)
@lrvick
lrvick / baez.js
Created March 29, 2012 11:16
Naive Bayes sentiment classifer attempt in javascript
var baez = (function(){
var stopwords = ['i','in','and','to','are','the','but','my','they','those','them','you','a']
function tokenize(sample){
var tokens = []
sample.split(' ').forEach(function(token){
if (baez.stopwords.indexOf(token) & /^[a-zA-Z0-9]+$/.test(token)){
@lrvick
lrvick / loadtest.py
Created March 27, 2012 07:31
Simple 1000 thread web server load test using eventlet
import eventlet
from eventlet.green import urllib2
def request():
urllib2.urlopen("http://yourtarget.com").read()
print "%s request sent"
pool = eventlet.GreenPool(size=1000)
while True:
@lrvick
lrvick / bitcolor.js
Created March 18, 2012 20:02
Javascript functions for doing fast binary/hex/RGB color conversions using bitwise operations.
// convert 0..255 R,G,B values to binary string
RGBToBin = function(r,g,b){
var bin = r << 16 | g << 8 | b;
return (function(h){
return new Array(25-h.length).join("0")+h
})(bin.toString(2))
}
// convert 0..255 R,G,B values to a hexidecimal color string
RGBToHex = function(r,g,b){