Skip to content

Instantly share code, notes, and snippets.

View seanstickle's full-sized avatar

Seán Stickle seanstickle

View GitHub Profile
#!/usr/bin/env ruby
require "rubygems"
require "hpricot"
require "open-uri"
url = "http://feeds.feedburner.com/Rubyconf2008-Confreaks"
(Hpricot(open url)/:enclosure).map {|x| x.attributes["url"]}.uniq.each do |vid|
File.exist?(vid.split("/").last) ? next : `wget #{vid}`
def create
@ticket = Ticket.new(params[:ticket])
flash[:notice] = "Ticket created."
redirect_to(@ticket)
end
def validate
errors.add("No such category") unless self.category
end
controller:
def show
begin
asset = Attachment.find(params[:id]).asset
render :text => "#{asset.path} #{asset.content_type} #{asset.original_filename}"
rescue
session_redirect
end
# Trace is a model in vendor/plugins/mylogger/lib/app/models/trace.rb
# vendor/plugins/mylogger/lib/mylogger.rb
#...
module MyLoggerImpl
def self.trace(controller_instance)
puts 'Tracing'
%h1 New document
%table
%tr
%th
%th
%th
- @documents.each do |document|
%tr
%th= link_to 'Show', document
@seanstickle
seanstickle / README.md
Created February 11, 2012 17:19 — forked from netmute/README.md
Game of Life

Game of Life

An implementation of Conway's Game of Life in 140 characters of Ruby.

Author

Created by Simon Ernst (@sier).

@seanstickle
seanstickle / hack.sh
Created March 31, 2012 14:44 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@seanstickle
seanstickle / black.scm
Created April 8, 2012 07:54 — forked from ecounysis/black.scm
Black-Scholes Option Pricing Model in Scheme
(define new-pi 3.1415926)
(define days-in-year 365)
(define (sqrt-t days-to-expiration)
(sqrt (/ days-to-expiration days-in-year)))
(define (normal-dist zz)
(if (= zz 0) 0.5
[let ((p 0.2316419) (b1 0.31938153) (b2 -0.356563782)
#!/bin/env ruby
def broken
people = Hash.new([])
people['a'] = [1]
people['b'] = [2]
p people
end
broken
# all upcoming events for a client
def future_events_all_accounts
self.accounts.map{ |account|
account.events.in_future(account.now).where(:client_id => self.id)
}.uniq.sort_by{ |a| a.start_time }
end
# all past events for a client
def past_events_all_accounts
self.accounts.map{ |account|