This file contains 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
package main | |
import ( | |
"fmt" | |
"net/http" | |
"time" | |
) | |
/* | |
* Converts a function that return a channel |
This file contains 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
make_resourceful do | |
actions :all | |
before :show do | |
@articles = current_object.articles | |
end | |
before :index do | |
@books = AmazonService::get('0QZ1AAT31TZ9RNVANY82', 'hackruby-20', 'ruby programming') unless read_fragment(:fragment => 'books') | |
@videos = YoutubeService::get('E45845C8A1F5726D', 3) unless read_fragment(:fragment => 'videos') |
This file contains 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 "config/environment" | |
require "faker" | |
module Faker | |
class Lorem | |
Words = %w(am is are was when done here get could can have has smart cool I my we they he it she them Ruby on rails merb jruby web2.0 1.9 mashups advent 2008 tools linux apache Zed Shaw David quoted Gems plugins routes passive aggressive real world code refactor simple testing rspec behavior driven benchmark profile use server client service impressive number generator rake make done ) | |
end | |
end | |
namespace :posts do |
This file contains 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
#check if at least one child has content - i.e. given a list of booleans, at least one is true? | |
inject(false) { |one_child_has_content, child| one_child_has_content || child.has_content? } | |
#check if all the constraints are true - i.e. given a list of booleans, all of them are true? | |
@constraints.inject(true) { |accepted, constraint| accepted && constraint.check(result) } |
This file contains 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
#!/usr/bin/ruby | |
class Integer | |
def days; hours * 24; end | |
def hours; minutes * 60; end | |
def minutes; seconds * 60; end | |
def seconds; self; end | |
end | |
def snapshot(name) |
This file contains 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
def tap | |
yield self | |
self | |
end unless Object.respond_to?(:tap) | |
# Yout could use unless/if to conditionally run a method |
This file contains 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 logged in as "(.*)"$/ do |name| | |
business = Business.make(:subdomain => "test") | |
@current_user = User.make(:email => "#{name}@example.com", | |
:password => "qaz123", | |
:password_confirmation => "qaz123", | |
:business => business) | |
visit "/login" | |
fill_in "Email", :with => "#{name}@example.com" | |
fill_in "Password", :with => "qaz123" |
This file contains 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 Student < ActiveRecord::Base | |
has_many :rating | |
has_many :books, :through => :ratings | |
end | |
class Book < ActiveRecord::Base | |
has_many :ratings | |
has_many :students, :through => :ratings | |
end | |
This file contains 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
#without :ujs option | |
link_to_function("Greeting", "alert('Hello world!')") | |
# <a href="#" onclick="alert('Hello world!'); return false;">Greeting</a> | |
#with :ujs and :id option | |
link_to_function("Greeting", "alert('Hello world!')", :id => "greeting_link", :ujs => true) | |
# <a href="#" id="greeting_link">Greeting</a> | |
# <script type="text/javascript"> | |
# //assuming users JS framework of choice is jQuery | |
# $(\"#greeting_link\").click( function(){ alert('Hello world!'); return false } ); |
This file contains 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
link_to_function("Show me more", nil, :id => "more_link") do |page| | |
page[:details].visual_effect :toggle_blind | |
page[:more_link].replace_html "Show me less" | |
end |
OlderNewer