Skip to content

Instantly share code, notes, and snippets.

View theleoborges's full-sized avatar

Leonardo Borges theleoborges

View GitHub Profile
(setq hs-show-all-p t)
(defun hs-mode-toggle-show-all ()
(interactive)
(if hs-show-all-p
(hs-hide-all)
(hs-show-all))
(setq hs-show-all-p (not hs-show-all-p)))
(global-set-key (kbd "C-.") 'hs-toggle-hiding)
(global-set-key (kbd "C-c C-.") 'hs-mode-toggle-show-all)
(async
(let [a (await (async-task-a))
b (await (async-task-b))
c (await (async-task-c (* a b)))]
(+ a b c)))
;; whish is equivalent to:
(async
(let [a (await (async-task-a))
@theleoborges
theleoborges / sequence.scala
Last active August 29, 2015 14:04
sequence, type lambdas and sequenceU
case class Error(reason: String)
val eithers: List[\/[Error, String]] = List(\/-("Ok"), -\/(Error("notOk")))
eithers.sequence
// error: could not find implicit value for parameter ev: scalaz.Leibniz.===[scalaz.\/[Error,String],G[B]]
eithers.sequence[({type λ[α] = \/[Error, α]})#λ, String]
// scalaz.\/[Error,List[String]] = -\/(Error(notOk))
eithers.sequenceU
@theleoborges
theleoborges / gist:a26c1566f14ff6304bf0
Last active March 7, 2019 23:03
20 intermediate haskell exercises
-- From: http://tonymorris.github.io/blog/20-intermediate-haskell-exercises/
-- which seems to be offline now
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
-- Relative Difficulty: 1
instance Fluffy [] where
furry = error "todo"

Keybase proof

I hereby claim:

  • I am leonardoborges on github.
  • I am leonardoborges (https://keybase.io/leonardoborges) on keybase.
  • I have a public key whose fingerprint is CD7B F319 99AE 74FF 4D3B 86CD B71B 49D1 0F1B F2EE

To claim this, I am signing this object:

@theleoborges
theleoborges / monads.clj
Last active August 29, 2015 13:56
Monads in Clojure talk
;; Slides at: http://www.slideshare.net/borgesleonardo/monads-in-clojure
;; The list Monad
(def list-m {
:return (fn [v] (list v))
:bind (fn [mv f]
(mapcat f mv))
})
(defn combinations []
;; This is short but in case of a failure, it's harder to pinpoint which bit is wrong.
(is (= (balance tree)
[:red
[:black
[:black nil "a" nil]
"x"
[:black nil "b" nil]]
"y"
[:black
(require '[clojure.core.async :as async :refer :all])
(defn fake-search [kind]
(fn [query]
(Thread/sleep (int (* (java.lang.Math/random) 1000)))
(str kind " result for " query)))
(def web (fake-search "Web"))
(def image (fake-search "Image"))
(def video (fake-search "Video"))
@theleoborges
theleoborges / func_fizzbuzz.rb
Last active December 17, 2015 20:28
Functional Fizz Buzz in Ruby 2.0
threes = ["", "", "fizz"].cycle.lazy
fives = ["", "", "", "", "buzz"].cycle.lazy
(1..Float::INFINITY).lazy.zip(threes, fives).map{|n,f,b|
if f.empty? && b.empty?
return n
elsif f.empty?
return b
else
return [f,b].join
@theleoborges
theleoborges / robot.js
Created December 3, 2012 03:28
MassiveDestructionMachine
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.rotateCannon(90);