This file contains 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
(load "[email protected]:carpentry-org/sockets@master") | |
(load "[email protected]:carpentry-org/http@master") | |
(load "https://veitheller.de/git/carpentry/[email protected]") | |
(defn read-all [sock s] | |
(let [read (Socket.read sock)] | |
(if (= &read "") | |
(Response.parse &s) | |
(let [acc (String.concat &[s read])] |
This file contains 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
; as an introduction, we tried to do string capitalization by hand, | |
; using as many different interesting idioms as possible | |
(defn capitalize-char [c] | |
(if (Char.lower-case? c) | |
(=> c | |
(to-int) | |
(- 32) | |
(from-int)) | |
c)) |
This file contains 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
(defndynamic derive-special-internal2 [comb f ms] | |
(if (= (length ms) 0) | |
'(zero) | |
(if (= (length ms) 1) | |
(f (caar ms)) | |
(list comb | |
(f (caar ms)) | |
(derive-special-internal2 comb f (cdr ms)))))) | |
(defndynamic derive-special-internal [comb f a] |
This file contains 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
#include <string.h> | |
#include <stdlib.h> | |
#include <core.h> | |
static const char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | |
String b64(String* osrc) { | |
String src = *osrc; | |
int len = strlen(src); | |
char *pos; |
This file contains 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
(system-include "../bench.h") | |
(register get-time-elapsed (Fn [] Double)) | |
(defn min [a] | |
(let [m (Double.copy (Array.nth a 0))] | |
(do | |
(for [i 1 (Array.count a)] | |
(let [el (Double.copy (Array.nth a i))] | |
(if (Double.< el m) |
This file contains 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
; Sneak this in somewhere | |
(defmacro = [& args] (apply (rand-nth [identical? not=]) args)) |
This file contains 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
Array.prototype.next = function(i) { | |
return this[++i % this.length]; | |
} | |
Array.prototype.previous = function(i) { | |
return i === 0 ? this[this.length - 1] : this[--i % this.length]; | |
} |
This file contains 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
;; Solution to: | |
;; How many different ways can we make change of $ 1.00, given half-dollars, quarters, dimes, nickels, and pennies? | |
;; More generally, can we write a procedure to compute the number of ways to change any given amount of money? | |
;; | |
;; Example usage for $1.00: (count-change 100) => 292 | |
;; This computation takes around 0.6 secs on my machine in zepto. | |
(define (count-change amount) | |
(cc amount 5)) |
This file contains 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
(define (templating template values) | |
(hash:keys-reduce (lambda (template k) (string:substitute template (++ "{{" k "}}") (values k))) template values)) |
This file contains 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
function templating(template, values) { | |
for(var k in values) { | |
template = template.replace('{{' + k.toString() + '}}', values[k].toString()); | |
} | |
return template; | |
} |
NewerOlder