Skip to content

Instantly share code, notes, and snippets.

def archive
dates = Post.date_counts(3).sort{|a,b| b <=> a}
@links = dates.map do |elem|
year, month = elem[0].split(/\//)
{:string => DateTime.strptime(elem[0], "%Y/%m").strftime("%B %Y"), :year => year, :month => month}
@links = @links[]
end
render
end
class Post < ActiveRecord::Base
has_many :comments
end
class PostController < ApplicationController
def show
@post = Post.find(param[id])
{ :checklist =>
{ :id => checklist.id,
:title => checklist.title,
:items => checklist.items
}
}.to_json
it "should return error 401 with bad key" do
get :list, :api_key => "My name is ryan and I'm a big jerkface who goes to Montreal and brags about how awesome the restaurants are"
response.status.should == "401"
end
@eqdw
eqdw / hotswap.rb
Created January 4, 2011 21:29
Proof of Concept of Erlang-style hot-swapping in Ruby
$CALLBACK = nil
$i = 0
class HotCode
def self.dispatcher(&block)
while(42)
sleep(0.25)
block.call
if($CALLBACK != block)
activity_file_1 = ActivityFile.create!( :title => "ActivityFile 1", :date_issued => Date.parse( "2009-02-02" ), :size => 10, :content_type => "text/pdf", :filename => "temp1.pdf", :facility => facility )
activity_file_2 = ActivityFile.create!( :title => "ActivityFile 2", :date_issued => Date.parse( "2009-01-12" ), :size => 10, :content_type => "text/pdf", :filename => "temp1.pdf", :facility => facility )
activity_file_3 = ActivityFile.create!( :title => "ActivityFile 3", :date_issued => Date.parse( "2009-03-24" ), :size => 10, :content_type => "text/pdf", :filename => "temp1.pdf", :facility => facility )
activity_file_4 = ActivityFile.create!( :title => "ActivityFile 4", :date_issued => Date.parse( "2009-02-24" ), :size => 10, :content_type => "text/pdf", :filename => "temp1.pdf", :facility => facility )
activity_file_5 = ActivityFile.create!( :title => "ActivityFile 4", :date_issued => Date.parse( "2009-02-23" ), :size => 10, :content_type => "text/pdf", :filename => "temp1.pdf", :fac
(function(){
var inner_private_var;
window.set_ipv = function(){
ipv = "herpaderp";
}
@eqdw
eqdw / wip_gcal.rb
Created January 23, 2011 19:16
[WIP] GData Calendar Scraping
require 'gdata'
require 'json' #parsing
cal = GData::Client::Calendar.new
cal.source = "innovatis_gdata_test"
cal.clientlogin("[email protected]", "YOUR_PASSWORD")
#now authenticated
#pull list of calendars which the currently logged in user can access. in json
feed = cal.get("https://www.google.com/calendar/feeds/default/allcalendars/full?alt=jsonc")
## DOES THIS MAKE SENSE / IS VALID
class Foo < ActiveRecord::Base
has_many :bar
has_many :baz, :through => :bar
end
class Bar < ActiveRecord::Base
belongs_to :baz
end