Skip to content

Instantly share code, notes, and snippets.

View don's full-sized avatar

Don Coleman don

View GitHub Profile
# parse the duration of a FLV file from the metadata
def duration(file_name)
return -1 unless FileTest.exist?(file_name)
metadata = File.open(file_name, 'rb') do |file|
file.read(400) # bytes
end
offset = metadata =~ /duration/
@don
don / force_ssl.rb
Created February 17, 2011 16:40
Rack Middleware to force all http requests to https
# Rack Middleware to force all http requests to https
# Alternately you could do this with an Apache or Nginx rewrite
#
# Install this middleware in conf/environments/production.rb
# config.middleware.use "ForceSSL"
#
# You can optionally set the host name for the redirect
# config.middleware.use "ForceSSL", "example.com"
#
class ForceSSL
@don
don / .zshrc
Last active November 20, 2020 18:24
Show git branch in bash prompt
# get git branch info using old bash function
# the zsh way to do this is vsc_info
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# add git branch version to prompt
setopt PROMPT_SUBST
PROMPT='%n@%m %1~$(parse_git_branch) %# '
@don
don / 1.app.js
Created January 21, 2012 00:17
Code samples for Sencha Touch Blog post
Ext.application({
launch: function() {
// define our app here
}
});
@don
don / .gitignore
Created February 11, 2012 19:48
Git Ignore for Windows Phone Projects
*.bak
thumbs.db
App_Data/
bin/
obj/
Bin/
_ReSharper.*/
tmp/
@don
don / HelloNDEFWorld.ino
Created January 15, 2013 03:10
Write hello world NDEF message. Cheat by hardcoding bytes.
//
// Write "Hello, world!" in a plain text NDEF message
// Tag must be a Mifare Classic with a 4 byte ID
// Tested with Samsung TecTile
//
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#define IRQ (2)
#define RESET (3) // Not connected by default on the NFC Shield
@don
don / phoengap-nfc-issue-80.js
Last active December 17, 2015 03:29
phonegap-nfc - write a message to unformatted tags, read text message from NDEF tags
// handle unformatted tags
nfc.addNdefFormatableListener(
function (nfcEvent) {
// NDEF message with one record
var message = [
ndef.textRecord("hello, world")
];
nfc.write(
@don
don / 01_install.sh
Last active December 17, 2015 10:48
Code for NFC slides - Maker Faire Bay Area 2013
cd ~/Documents/Arduino/libraries
git clone git@github.com:adafruit/Adafruit_NFCShield_I2C.git
git clone git@github.com:don/Ndef.git
@don
don / 0_connect.ino
Last active December 17, 2015 12:09
var macAddress = "00:00:AA:BB:CC:DD";
var connected = function() {
// connected, do something
};
var disconnected = funtion(error) {
// disconnected
};
bluetoothSerial.connect(macAddress, connected, disconnected);
@don
don / Arduino_NFC_LED_Demo
Last active December 17, 2015 23:39
Arduino NFC Demo from Maker Faire Bay Area 2013 http://don.github.io/slides/2013-05-18-arduino-nfc
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#include <NfcAdapter.h>
NfcAdapter nfc = NfcAdapter();
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)