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
@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 / 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 / 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 / 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
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
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;
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)
hi guys. I have a factory that returns a resource like this:
return $resource('/api/:key.json', {key: '@key'}, {
'delete': { method: 'DELETE' }
});
when I do:
Key.delete(pair, function (response) {
console.log(response);
;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
@thiagofm
thiagofm / gist:7109133
Created October 22, 2013 22:14
gauss.sc
object gauss {
def gauss = {
def sum(f: Int => Int, a: Int, b: Int): Int = {
if (a > b) 0
else f(a) + sum(f, a+1, b)
}
sum(x => x, 1, 100)
} //> gauss: => Int
gauss //> res0: Int = 5050