Skip to content

Instantly share code, notes, and snippets.

View rosterloh's full-sized avatar

Richard Osterloh rosterloh

View GitHub Profile
@rosterloh
rosterloh / bb-python-gpio-test.py
Created March 7, 2012 10:11 — forked from mrichardson23/bb-python-gpio-test.py
BeagleBone GPIO with Python Test
#!/usr/bin/python
import time
# Open up the pins and set mode in/out
# TODO: Error handling
outPin = file("/sys/class/gpio/export", "w")
outPin.write("%d" % (38))
outPin.close()
outPin = file("/sys/class/gpio/gpio38/direction", "w")
@rosterloh
rosterloh / gist:8195325
Created December 31, 2013 11:06
Node.js Asynch options from Nettuts
// Taken from: http://net.tutsplus.com/tutorials/javascript-ajax/managing-the-asynchronous-nature-of-node-js/
// STANDARD
app.get('/login', function (req, res) {
sql.query('SELECT 1 FROM users WHERE name = ?;', [ req.param('username') ], function (error, rows) {
if (error) {
res.writeHead(500);
return res.end();
}
if (rows.length < 1) {
@rosterloh
rosterloh / template.c
Created January 11, 2014 20:00
C source file templates from beningo.com
/*******************************************************************************
* Title : System Initialization
* Filename : sys_init.c
* Author : JWB
* Origin Date : 04/23/2012
* Version : 1.0.0
* Compiler : Microchip C30 v3.30c
* Target : PIC24FJ64GB004
* Notes : None
*******************************************************************************/
@rosterloh
rosterloh / debounce.c
Created April 6, 2014 20:18
Simple input debouncing
#define CHECK_MSEC 5 // Read hardware every 5 msec
#define PRESS_MSEC 10 // Stable time before registering pressed
#define RELEASE_MSEC 100 // Stable time before registering released
// This function reads the key state from the hardware.
extern bool_t RawKeyPressed();
// This holds the debounced state of the key.
bool_t DebouncedKeyPress = false;
// Service routine called every CHECK_MSEC to
// debounce both edges
void DebounceSwitch1(bool_t *Key_changed, bool_t *Key_pressed)
@rosterloh
rosterloh / ga_error.js
Created April 14, 2014 08:30
Track Errors with Google Analytics
// Track basic JavaScript errors
window.addEventListener('error', function(e) {
_gaq.push([
'_trackEvent',
'JavaScript Error',
e.message,
e.filename + ': ' + e.lineno,
true
]);
});
@rosterloh
rosterloh / angular-socket-io.js
Created April 24, 2014 09:20
Custom factory for AngularJS Socket.io service
factory('socket', ['$rootScope', 'io', function($rootScope, io) {
var socket = io.connect(),
events = {},
that = {};
var addCallback = function(name, callback) {
var event = events[name],
wrappedCallback = wrapCallback(callback);
if (!event) {
@rosterloh
rosterloh / socket.js
Created May 2, 2014 13:00
The world's most basic socket.io AngularJS factory
appServices.factory('socket', function ($rootScope) {
var socket = io.connect('http://localhost:3000');
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
#!/usr/bin/perl
######################################################################
#
# File : split_bootimg.pl
# Author(s) : William Enck <enck@cse.psu.edu>
# Description : Split appart an Android boot image created
# with mkbootimg. The format can be found in
# android-src/system/core/mkbootimg/bootimg.h
#
# Thanks to alansj on xda-developers.com for
@rosterloh
rosterloh / getopts.sh
Created June 2, 2014 16:07
An example of how to use bash getopts
#!/bin/bash
######################################################################
#This is an example of using getopts in Bash. It also contains some
#other bits of code I find useful.
#Author: Linerd
#Website: http://tuxtweaks.com/
#Copyright 2014
#License: Creative Commons Attribution-ShareAlike 4.0
#http://creativecommons.org/licenses/by-sa/4.0/legalcode
@rosterloh
rosterloh / androidVersion.java
Created June 19, 2014 12:55
Gist for checking device android version
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
AlertDialog.Builder dialog = new AlertDialog.Builder(BlueBand.this);
dialog.setTitle("Error");
dialog.setMessage("Support Android 4.3 or above only.");
dialog.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.exit(0);