Skip to content

Instantly share code, notes, and snippets.

View danhigham's full-sized avatar

Dan Higham danhigham

View GitHub Profile
@danhigham
danhigham / Gemfile
Created October 17, 2012 14:05
Example of how to use the vmc library to do an automatic mysql backup of a named service
source :rubygems
source "http://rubygems.org"
gem 'vmc', '0.3.18'
gem 'caldecott', '>=0.0.5'
@danhigham
danhigham / hello.rb
Created August 6, 2012 17:55
Serving images
require 'sinatra'
get '/hi' do
"<html><head></head><body><img src=\"/images/javelin-2012-hp.jpg\" /></body></html>"
end
get %r{/images/(.+)} do |c|
File.read(c)
end
@danhigham
danhigham / mp4convert.rb
Created April 1, 2012 16:30
Ruby script to convert .m4a files to mp3 (install lame and faad2 via homebrew first)
#!/usr/bin/ruby
require 'rubygems'
require 'mp4info'
path = ARGV[0]
Dir.foreach(path) do |file|
file_path = File.join path, file
@danhigham
danhigham / gist:1599924
Created January 12, 2012 11:13
Download Progress
# download zip file
source = open(feed_url,
:content_length_proc => lambda { |t|
start = Time.now
if t && 0 < t
content_length = t / 100
end
},
:progress_proc => lambda { |s|
@danhigham
danhigham / serialize_form.coffee
Created August 17, 2011 20:45
Serializes form elements in to a javascript object
$ = jQuery
$.extend $.fn,
serializeObject: () ->
e = $(this)
a = e.serializeArray()
o = {}
$.each a, ->
if o[this.name] != undefined
#/**********************************************************\
#
# Auto-Generated Plugin Configuration file
# for Concept PM Communicator
#
#\**********************************************************/
set(PLUGIN_NAME "ConceptPMCommunicator")
set(PLUGIN_PREFIX "CPC")
set(COMPANY_NAME "TactusworksLtd")
@danhigham
danhigham / dm-redis-test.rb
Created July 20, 2011 05:55
RSpec test cases for enums with dm-redis-adapter
#!/usr/bin/ruby
require 'rubygems'
require 'datamapper'
require 'rspec'
class Book
include DataMapper::Resource
property :id, Serial
@danhigham
danhigham / fork.rb
Created July 8, 2011 19:19
Forking a process and getting it's pid
#!/usr/bin/ruby
pid = Process.fork do
exec 'ls -al'
end
puts "pid is #{pid}"
Process.detach pid
@danhigham
danhigham / application.coffee
Created June 23, 2011 10:00
CoffeeScript and Handlebars
window.template_manager = new TemplateManager()
configuration = {}
template_manager.load_template "tabs", "/templates/_tabitems.handlebars", ->
markup = template_manager.transform "tabs", configuration
class User
# attr :password
include DataMapper::Resource
property :id, Serial
property :name, String
property :email, String
property :password, String