Skip to content

Instantly share code, notes, and snippets.

View rlorca's full-sized avatar

Rodrigo Lorca rlorca

  • Lausanne, Switzerland
View GitHub Profile
@rlorca
rlorca / first.hs
Created August 22, 2014 14:51
Hello world in haskell
add a b = a + b
turboDrop n xs = if n <= 0 || null xs
then xs
else turboDrop (n -1)(tail xs)
fu = print "abc"
data Phones = Iphone | Htc_one
@rlorca
rlorca / Protocol
Last active August 29, 2015 13:56
* General form
Command (parameters*)\n
* General errors
ERR_INVALID_SEQUENCE 2
ERR_INVALID_COMMAND 4
* Commands
JOIN
Resp: OK [GO | WAIT] GAME_NUMBER
@rlorca
rlorca / gist:6931332
Created October 11, 2013 08:15
Push!
66a4a70f a087d7cf b6a22bf7 f9614ee8 16cfa25e 17e4c020 67dbbc01 ce6d52e7
@rlorca
rlorca / gist:6810754
Created October 3, 2013 14:27
Push token
<6d619398 75fd80e6 d7d57bc0 1bd852cd a8e17371 947c9d43 c9245ca2 c7cf46cc>
@rlorca
rlorca / spider.go
Last active December 17, 2015 22:19
package main
import ("fmt"
"net/http")
type Endpoint struct {
address string
code int
}
@rlorca
rlorca / gist:2996732
Created June 26, 2012 16:07
Coroutines in Lua
function foo ()
return coroutine.yield("ho ho ho")
end
co = coroutine.create(function (a)
return foo() * a
end)
print("intermediate result", coroutine.resume(co, 3))
print("final result", coroutine.resume(co, 7))
(testing +
[1] [1] "single result is noop"
[1 2] [3] "two values are added"
[1 2 3] [6] "three values are added"
[] [0] "no values, zero")
;idea from the book onlisp, pag 30
(defn rev [nums]
(let [f (fn [coll res]
(if (empty? coll)
res
(recur (drop-last coll) (conj res (last coll)))))]
(f nums [])))
;exercise from http://programmingpraxis.com/2010/10/08/zellers-congruence/
;formula from http://en.wikipedia.org/wiki/Zeller%27s_congruence
(defn month-id [month]
(+ 3
(mod (+ month 9) 12)))
(defn year-of-century [year]
(mod year 100))
(let ((counter 0))
(defun new-id ()
(incf counter))
(defun reset-id ()
(setq counter 0)))