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 / gist:100740
Last active January 15, 2023 23:24
simple XMPP message
require 'rubygems'
require 'xmpp4r-simple'
jabber = Jabber::Simple.new(username+'@gmail.com',password)
puts "Connected."
jabber.deliver("l***@gmail.com", "Hello..!")
@rlorca
rlorca / oban.clj
Created October 1, 2010 16:16
Oban numbers
; from http://programmingpraxis.com/2010/10/01/oban-numbers/
(ns oban)
(def base [nil nil "three" nil "five" "six" "seven" "eight" "nine"])
(def dec ["twenty" "thirty" "fifty" nil "sixty" "seventy" "eigthy" "ninety"])
(def teens ["ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen" "eighteen" "nineteen"])
(let ((counter 0))
(defun new-id ()
(incf counter))
(defun reset-id ()
(setq counter 0)))
;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))
;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 [])))
(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")
@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))
@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:6810754
Created October 3, 2013 14:27
Push token
<6d619398 75fd80e6 d7d57bc0 1bd852cd a8e17371 947c9d43 c9245ca2 c7cf46cc>
@rlorca
rlorca / gist:6931332
Created October 11, 2013 08:15
Push!
66a4a70f a087d7cf b6a22bf7 f9614ee8 16cfa25e 17e4c020 67dbbc01 ce6d52e7