Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Osterloh rosterloh

View GitHub Profile
@rosterloh
rosterloh / bb-python-gpio-test.py
Created Mar 7, 2012 — forked from mrichardson23/bb-python-gpio-test.py
BeagleBone GPIO with Python Test
View bb-python-gpio-test.py
#!/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 Dec 31, 2013
Node.js Asynch options from Nettuts
View gist:8195325
// 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 Jan 11, 2014
C source file templates from beningo.com
View template.c
/*******************************************************************************
* 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 Apr 6, 2014
Simple input debouncing
View debounce.c
#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 Apr 14, 2014
Track Errors with Google Analytics
View ga_error.js
// 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 Apr 24, 2014
Custom factory for AngularJS Socket.io service
View angular-socket-io.js
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
The world's most basic socket.io AngularJS factory
View socket.js
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);
});
});
View split_bootimg.pl
#!/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 Jun 2, 2014
An example of how to use bash getopts
View getopts.sh
#!/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 Jun 19, 2014
Gist for checking device android version
View androidVersion.java
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);