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
| ;; 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) | |
| %) |
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
| (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 |
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
| (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 ] |
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
| (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 |
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
| 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 |
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
| 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; |
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 '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) |
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
| 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); |
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
| ;; 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)) |
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
| 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 |