Skip to content

Instantly share code, notes, and snippets.

View danhigham's full-sized avatar

Dan Higham danhigham

View GitHub Profile
@danhigham
danhigham / ZIP-PDFdownloader.rb
Created January 15, 2011 15:03
Downloads files from a page if they are pdf or zip!
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'hpricot'
doc = Hpricot(open('http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2010-winter'))
(doc/"a").each do |x|
@danhigham
danhigham / scrape_it.rb
Created April 21, 2011 11:38
Hpricot script to extract sunrise and sunset dates from http://www.timeanddate.com/worldclock/astronomy.html
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'hpricot'
doc = Hpricot(open("http://www.timeanddate.com/worldclock/astronomy.html?n=136&month=12&year=2010&obj=sun&afl=-11&day=1"))
sunrise_rows = (doc/"table.spad tr")
@danhigham
danhigham / rubyconfvids.rb
Created May 22, 2011 08:03
Script to download all Scotland Ruby 2011 videos
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'hpricot'
dependencies = [:wget, :curl]
dependencies.each { |program| !`which #{program.to_s}`.empty? || STDERR.puts( "Requires #{program}") }
index_doc = Hpricot(open("http://confreaks.net/events/scotlandruby2011"))
$(document).ready ->
$("#fb-root").append "<script type=\"text/javascript\" src=\"#{document.location.protocol}//connect.facebook.net/en_GB/all.js\" async=\"true\"></script>"
window.fbAsyncInit = () ->
FB.init
appId: '172659579460514'
status: true
cookie: true
xfbml: true
class User
# attr :password
include DataMapper::Resource
property :id, Serial
property :name, String
property :email, String
property :password, String
@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
@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 / 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
#/**********************************************************\
#
# Auto-Generated Plugin Configuration file
# for Concept PM Communicator
#
#\**********************************************************/
set(PLUGIN_NAME "ConceptPMCommunicator")
set(PLUGIN_PREFIX "CPC")
set(COMPANY_NAME "TactusworksLtd")
@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