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
# Naive slow implementation | |
def simple_fib(n) | |
return n if (0..1).include?(n) | |
simple_fib(n - 1) + simple_fib(n - 2) | |
end | |
# Recursive fast implementation | |
def rec_fib(n) | |
rec = -> (a, b, n) { n == 0 ? a : rec.call(b, a + b, n - 1) } | |
rec.call(0, 1, n) |
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 retrieve(path, hash) | |
remainder = hash.fetch(path.shift, nil) | |
remainder.is_a?(Hash) ? retrieve(path, remainder) : remainder | |
end | |
path = [:foo, :bar, :baz] | |
hash = { foo: { bar: { baz: 123 } } } | |
puts "path: #{path}" | |
puts "hash: #{hash}" |
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
# GemFile | |
gem 'state_machine' | |
# offerta.rb | |
scope :nuove, Offerta.where(:stato => "nuova") | |
STATI = %w(nuova inviata accettata rifiutata scaduta annullata) | |
state_machine :stato, :initial => :nuova do | |
before_transition any => :inviata do |offerta, transition| |
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
# app/views/sitemap/index.xml.builder | |
xml.instruct! | |
xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do | |
xml.url do | |
xml.loc root_url | |
xml.priority 1.0 | |
end | |
xml.url 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
require 'spec_helper' | |
describe CategoriesController do | |
describe "routing" do | |
it '/solutions to Category#index' do | |
path = categories_path | |
path.should == '/solutions' | |
{ :get => path }.should route_to( | |
:controller => 'categories', | |
:action => 'index' |
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 Order < ActiveRecord::Base | |
extend FriendlyId | |
belongs_to :customer | |
belongs_to :service | |
belongs_to :request_address, :foreign_key => "request_address_id", :class_name => "Address" | |
belongs_to :billing_address, :foreign_key => "billing_address_id", :class_name => "Address" | |
has_many :options, :through => :choices, :autosave => true | |
has_many :choices, :dependent => :destroy |
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
// Keeps the order recap box fixed on scroll, a la Apple Store | |
// http://jqueryfordesigners.com/fixed-floating-elements | |
$(function () { | |
var msie6 = $.browser == 'msie' && $.browser.version < 7; | |
if (!msie6 && $('#sidebar').length > 0 && false) { | |
var top = $('#logo').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0)), | |
order_recap_height = $('#sidebar').height(), | |
order_form_wrapper_height = $('#main-content').height(); |
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 ApplicationController < ActionController::Base | |
before_filter :set_locale | |
protect_from_forgery | |
def set_locale | |
logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}" | |
I18n.locale = current_user ? current_user.locale : (params[:locale] || extract_locale_from_accept_language_header || I18n.default_locale) | |
logger.debug "* Locale set to '#{I18n.locale}'" | |
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
require 'spec_helper' | |
describe Form do | |
context "ActiveRecord" do | |
it { should belong_to(:user) } | |
it { should have_many(:entries) } | |
it { should validate_presence_of(:mail_to_address) } | |
it { should validate_presence_of(:redirect_to_url) } | |
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
package net.primegap.authexample; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import org.apache.http.client.HttpResponseException; | |
import org.apache.http.client.ResponseHandler; | |
import org.apache.http.client.methods.HttpDelete; | |
import org.apache.http.client.methods.HttpPut; | |
import org.apache.http.impl.client.BasicResponseHandler; |
OlderNewer