This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'activesupport' | |
{:one => 1, :two => 2}.slice(:one) #=> {:one=>1} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Breadcrumb | |
def breadcrumbs | |
if parent | |
parent.breadcrumbs << self | |
else | |
[self] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(', ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
def initialize | |
puts "A initialized" | |
end | |
end | |
class B < A | |
alias :original_initialize :initialize | |
def initialize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/python"> | |
def pyFunc(): | |
window.alert("hi, i'm python") | |
</script> | |
<script type="text/ruby"> | |
def rubyFunc | |
pyFunc | |
end | |
</script> | |
<script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |