Skip to content

Instantly share code, notes, and snippets.

View jqr's full-sized avatar

Elijah Miller jqr

View GitHub Profile
require 'activesupport'
{:one => 1, :two => 2}.slice(:one) #=> {:one=>1}
class Account < ActiveRecord::Base
has_many :users
belongs_to :first_user, :class_name => 'User'
accepts_nested_attributes_for :first_user
end
class AccountsController < ApplicationController
def new
# Watches a value change over time showing you current value and rate of
# change.
#
# rate { Time.now.to_i }
# # 1243457076 (0.999/sec)
# # 1243457077 (0.999/sec)
# # 1243457078 (0.999/sec)
def rate(options = {})
clear = `clear`
defaults = {
module Breadcrumb
def breadcrumbs
if parent
parent.breadcrumbs << self
else
[self]
end
end
end
require 'rubygems'
require 'httparty'
zip_code = 46220
theater_list = HTTParty.get("http://new.api.movies.yahoo.com/v2/listTheatersByPostalCode?pcode=#{zip_code}&count=20&yprop=msapi")
theater_list['TheaterList']['Theater'].each do |theater|
puts "=== " + theater['Name'] + " " + "=" * 50
theater['MovieList']['Movie'].each do |movie|
puts " " + movie['movie:Title']
puts " " + movie['Shows']['Time'].collect { |t| Time.parse(t).strftime('%I:%M') }.join(', ')
class A
def initialize
puts "A initialized"
end
end
class B < A
alias :original_initialize :initialize
def initialize
<script type="text/python">
def pyFunc():
window.alert("hi, i'm python")
</script>
<script type="text/ruby">
def rubyFunc
pyFunc
end
</script>
<script>
@jqr
jqr / heroku.rake
Created April 24, 2009 13:24
Automatically Generate the Heroku gems manifest from gem dependencies
namespace :heroku do
desc "Generate the Heroku gems manifest from gem dependencies"
task :gems do
RAILS_ENV='production'
Rake::Task[:environment].invoke
list = Rails.configuration.gems.collect do |g|
command, *options = g.send(:install_command)
options.join(" ") + "\n"
end
irb(main):001:0> thing
NameError: undefined local variable or method `thing' for main:Object
from (irb):1
irb(main):002:0> defined? thing
=> nil
irb(main):003:0> thing = thing
=> nil
irb(main):004:0> thing
=> nil
irb(main):005:0> defined? thing
# Given I have the following projects:
# | short_description |
# | Feed Dante |
# | Walk my dogs |
Given /^I have the following projects:$/ do |table|
table.hashes.each do |project_hash|
@current_user.projects.create!(project_hash)
end
end