Skip to content

Instantly share code, notes, and snippets.

@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 / StyleGuide.md
Created July 16, 2012 23:19
Lance's Code Style Guide
@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 / 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.
async.waterfall [
(cb) ->
if user?.id
models.execute User, 'find', user.id, (err,user) ->
cb null, err, userModel
else
cb null, null, null
(err, userModel, cb) ->
@lrvick
lrvick / controllers.js
Last active December 14, 2015 19:09
Websocket AngularJS controller/services pattern
app.controller( 'AppCtrl', function ($scope, socket) {
socket.onopen(
function(){
console.log('Socket is connected :D')
}
)
socket.onclose(
function(){
console.log('Socket is disconnected :(')
}
@lrvick
lrvick / fetch.js
Created May 2, 2013 15:08
Angular socket data caching/retrieval pattern check service for cached data else check local storage for data (optional) else make socket request for data (optional) then create listener for data from socket save obtained data to service save obtained data to localStorage (optional)
/**
* ## Fetch Data
*
* @param {String} key Data source to request
* @param {Boolean} use_storage set/get from localStorage
* @param {Object} request JSON formatted request for server
*
* @return {Object} a $q.defer().promise for the data requested
*
*/
@lrvick
lrvick / .bowerrc
Created June 18, 2013 18:32
grunt-bower-task failing testcase Fails to copy modules from a Git repository with no bower package file.
{
"directory": "app/lib"
}
@lrvick
lrvick / angular-logging.js
Last active February 3, 2021 04:26
AngularJS - Global logging override module. Enables you to write custom hooks to intercept, display, manipulate or re-transfer $log logs as you see fit. Also allows one to easily globally disable logs application wide, useful for production.
/**
* # Global logging module
*
* This is a global set of hooks that catch all $log messages sent out by the
* application. Currently they are simply passed off directly to console.log
* but this could be updated later to allow them to be stored locally, sent to
* a server etc.
*/
angular.module('ngLogging', [])
@lrvick
lrvick / sort.js
Created October 17, 2013 20:18
Comparison of integer sorting algorithms in JavaScript
function jsSort(items){
var steps = 0
items.sort(function(a,b){
steps = steps+1
return a-b
})
return [items,steps]
}