Skip to content

Instantly share code, notes, and snippets.

View thiagofm's full-sized avatar
🐢
Slowly coming back to OSS

Thiago Massa thiagofm

🐢
Slowly coming back to OSS
View GitHub Profile
require 'test_helper'
shared_examples_for 'An Adapter' do
describe '#read' do
before do
@adapter.write(@key = 'whiskey', @value = "Jameson's")
end
it 'reads a given key' do
@adapter.read(@key).must_equal(@value)
filter(_, [], List) -> List;
filter(F, [H|T], List) ->
case F(T) of
true -> filter(F, [T], [H|List]);
false -> filter(F, [T], List)
end.
%% why can't I do this way?
filter(_, [], List) -> List;
allowed_params = [:name, :stats, :xpto]
params = {
name: 'Blabla',
stats: '123'
}
def update(allowed_params, params)
# validate if params are allowed
params.each do |param|
raise 'Bad Request' unless allowed_params.include? params
@thiagofm
thiagofm / 2.clj
Created October 9, 2012 23:01
2.clj
(ns problem2.core)
(defn fib-rec
[ list-fib n ]
(if
(< (last list-fib) 4000000)
(fib-rec (conj list-fib (reduce + (take-last 2 list-fib))) (- n 1)) list-fib)
)
(defn fib
@thiagofm
thiagofm / fib2.clj
Created October 9, 2012 22:40
fib clojure 2
(defn fib-rec
[ list-fib n ]
(if
(not= n 2)
(fib-rec (conj list-fib (reduce + (take-last 2 list-fib))) (- n 1)) list-fib)
)
(defn fib
[ n ]
@thiagofm
thiagofm / fib.clj
Created October 9, 2012 21:49
fib clojure
(defn fib-list
[actual-n next-n iterations-left full-list]
(if
(not= iterations-left 0)
(fib-list (reduce + [actual-n next-n]) actual-n (- iterations-left 1) (conj full-list (reduce + [actual-n next-n]) ))
full-list
)
)
(defn -main
@thiagofm
thiagofm / gist:3861668
Created October 9, 2012 21:48 — forked from timmc/fact.swear.clj
Factorial in Clojure without using alphanumeric characters
;; It all started here: http://clojure-log.n01se.net/date/2011-04-06.html#19:04
(#((% (+(*))) %) ;; call arg 1 with all args
[;; data
(+ (*)(*)(*)(*)(*)(*)(*))
;; main fn -- simulate 'if' with map lookup and closures
#(({(+) (% (+(*)(*)))} ;; if zero return 'then' clause
(% (+)) ;; dispatch on first arg
(% (+(*)(*)(*)))) ;; call 'else' clause (n not found in map)
%)
@thiagofm
thiagofm / PriceCalculator_spec.rb
Created September 13, 2012 14:28
PriceCalculator_spec.rb
require 'spec_helper'
describe FaleMais::PriceCalculator do
context "#object" do
it "should be a subclass of Object" do
Object.constants.should include(:FaleMais)
end
it "should be instantiable" do
FaleMais::PriceCalculator.new.should be_an_instance_of FaleMais::PriceCalculator
@thiagofm
thiagofm / calculate_price_steps.rb
Created September 13, 2012 14:17
calculate_price_steps.rb
Given /^I'm on the landing page$/ do
visit '/'
end
When /^I select my plan, source, destination and time$/ do
#@options = { :plan => '120', :source => '018', :destination => '011', :time => '200' }
fill_in 'tempo', :with => '200'
select '120', :from => 'plano'
select '018', :from => 'origem'
select '011', :from => 'destino'
# antes:
<!--MENU-->
<nav class="menu">
<ul>
<li>
<% if params[:action].eql? 'sobre' %>
<%= link_to 'Sobre', help_sobre_url, :class => 'on' %>
<% else %>
<%= link_to 'Sobre', help_sobre_url %>