Skip to content

Instantly share code, notes, and snippets.

View mdigital's full-sized avatar

Robin Marshall mdigital

View GitHub Profile
@mdigital
mdigital / gist:1094836
Created July 20, 2011 12:01 — forked from paulirish/gist:366184
html5 geolocation with fallback.
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
;(function(geolocation){
if (geolocation) return;
var cache;
@mdigital
mdigital / pwm.py
Created February 27, 2012 03:32 — forked from arthurnn/pwm.py
beaglebone PWM
from mmap import mmap
import struct
MMAP_OFFSET = 0x44c00000 # base address of registers
MMAP_SIZE = 0x48ffffff-MMAP_OFFSET # size of the register memory space
CM_PER_BASE = 0x44e00000 - MMAP_OFFSET
CM_PER_EPWMSS1_CLKCTRL = CM_PER_BASE + 0xcc
CM_PER_EPWMSS0_CLKCTRL = CM_PER_BASE + 0xd4
CM_PER_EPWMSS2_CLKCTRL = CM_PER_BASE + 0xd8
@mdigital
mdigital / tarsnap-install.sh
Created April 18, 2012 02:40
Debian / Ubuntu Tarsnap installation
#!/bin/sh
# Installs tarsnap client on Debian and Ubuntu
#
# You'll need to setup an account at
# http://www.tarsnap.com
# and load it with some funds
#
# Make sure you run this as root
#
@mdigital
mdigital / .bash_profile
Created May 31, 2012 21:25
.bash_profile function to name your terminal windows
function st {
title=$1;
echo -e "\033];${title}\007";
}
@mdigital
mdigital / .bashrc
Created May 31, 2012 21:33 — forked from henrik/.bashrc
Git branch and dirty state in Bash prompt.
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
@mdigital
mdigital / JsonPExampleinBackbone.js
Created June 7, 2012 02:21 — forked from denisos/JsonPExampleinBackbone.js
Backbone.js model calling jsonp
// backbone.js continues to impress, I needed to get data from a jsonp api
// I really wanted to do this the "right" backbone.js way and create a model and call fetch.
// But the default backbone synch is not jsonp
// Turns out you can override a synch on a per model basis (thanks stackoverflow)
// whats nice is backbone.js continue to work as expected with the override
// here's a snippet (some changes to protect our privacy). An improvement could be to create a jsonp model class which MyModel inherits
// the synch function is most important below, that's what tells backbone it's jsonp
MyModel = Backbone.Model.extend({
@mdigital
mdigital / to_haml.rb
Created June 7, 2012 22:41 — forked from johnnyicon/to_haml.rb
Convert all html.erb files to html.haml while preserving git history
# Adapted the script listed in the following link to maintain git history
# Original Script: http://snippets.dzone.com/posts/show/5449
# Usage:
# 1) Copy the file to the root of your Rails app
# 2) Run the script (i.e., ruby to_haml.rb app/views)
class ToHaml
def initialize(path)
@path = path
end
@mdigital
mdigital / gist:2907430
Last active October 6, 2015 00:57
.bash_profile including set_title and git prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ [\1$(parse_git_dirty)]/"
}
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
@mdigital
mdigital / gist:2998640
Created June 26, 2012 20:18
Google Analytics Outbound Link Tracking in CoffeeScript
$('a[href^="http"]').on 'click', (e) ->
e.preventDefault
_gaq.push(['_trackEvent', 'Outbound', 'click', this.href])
callback = -> window.location = arguments[0]
setTimeout callback, 200, this.href
@mdigital
mdigital / jquery.hint.js
Created June 27, 2013 09:53
Placeholder polyfill that support's password fields - based on Remy Sharp's jquery plugin
jQuery.fn.hint = function (blurClass) {
if (!blurClass) {
blurClass = 'blur';
}
return this.each(function () {
// get jQuery version of 'this'
var $input = jQuery(this),
// capture the rest of the variable to allow for reuse