Skip to content

Instantly share code, notes, and snippets.

@boolpath
boolpath / the-little-learner.clj
Last active May 13, 2023 20:47
The Little Learner in Clojure (code in solid boxes only)
(ns books.little-series.little-learner.core)
;; p. 11
(def remainder
(fn [x y]
(cond
(< x y) x
:else (remainder (- x y) y))))
;; p. 14
@boolpath
boolpath / littleschemer.clj
Created October 19, 2021 20:27 — forked from gar3thjon3s/littleschemer.clj
Little schemer in clojure
(defn atom? [x]
(not (list? x)))
(def car first)
(def cdr next)
(def add1 inc)
(def sub1 dec)
(defn lat? [lst]
(every? atom? lst))
@boolpath
boolpath / form-2-component.cljs
Last active November 23, 2020 16:39
Let Over Hiccup
(defn form-2-component []
(let [content "Hello, world!"]
(fn [] [:div content])))
@boolpath
boolpath / hello-macros-tldr-defmacro-pass-args.clj
Last active October 30, 2020 03:02
hello-world-of-lisp-macros
(defmacro pass-args [code & args]
`(~@code ~@args))
> (macroexpand '(pass-args (+) 1 2 3))
(+ 1 2 3)
> (+)
0
> (pass-args (+) 1 2 3)
6
@boolpath
boolpath / hello-lisp-macros.md
Last active June 26, 2020 09:48
A "Hello, World!" of Lisp macros.

"Hello, Macros!"

A "Hello, World!" of Lisp macros

tl;dr

(defmacro pass-args (code &rest args)
  `(,@code ,@args))

> (macroexpand '(pass-args (format) t "Hello, World!"))
(FORMAT T "Hello, World!")
@boolpath
boolpath / test.rb
Last active August 29, 2015 14:06 — forked from avsej/test.rb
require 'rubygems'
require 'couchbase'
def transfer(source, destination, amount)
cb = Couchbase.bucket
# prepare transaction document
id = cb.incr("transaction:counter", :create => true)
trans_id = "transaction:#{id}"
cb.set(trans_id, {"source" => source, "destination" => destination,
@boolpath
boolpath / bogotajs_final
Created December 1, 2013 02:06
BogotaJS - Final
function fibonacci(n) {
var f = [1,1], j, p = f[0], s, i = n + 2;
for (j = 2; j < i; j++) {
s = f[j-1];
f.push(p + s);
p = s;
}
return f;
}
@boolpath
boolpath / gist:7727486
Created December 1, 2013 01:25
BogotaJS Ronda 2 - Jorge Zaccaro
function cifradoCesar(string) {
var a = [],
stringLength = string.length,
letter;
for (var i = 0; i < stringLength; i++) {
letter = string.charAt(i);
if (letter == ' ') {
a.push(' ');
} else if (letter == 'z') {
function maxZaks(array) {
var max = -Infinity;
for (var i = 0; i < array.length; i++) {
max = Math.max(array[i],max)
}
return max;
}