View 1-array.js
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 = ordered + indexed + duplicate values | |
// a.k.a. List | |
const arr = [1, 2, 3] | |
// size | |
arr.length //=> 3 | |
// random-access | |
arr[1] // 2 |
View 2-declarative.js
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
// Imperative: 'what' + 'how' | |
const makes1 = [] | |
for (let i = 0; i < cars.length; i += 1) { | |
makes1.push(cars[i].make) | |
} | |
// Declarative: only 'what' | |
const makes2 = cars.map((car) => car.make) |
View 1-function.js
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
// Producer | |
const range = (min, max, acc = []) => { | |
if (max < min) throw new Error('not supported!') | |
if (min >= max) return acc | |
return range(min + 1, max, acc.concat(min)) | |
} | |
// Consumer | |
const lt100 = range(0, 100) | |
//=> [1, 2, 3, 4, ..., 97, 98, 99] |
View 1.js
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
// Interface of a primitive variable: its name and type | |
const DEFAULT_DB_HOST = 'localhost' | |
// Interface of a container variable: its name, types and structures | |
const config = { | |
user: 'readuser', | |
pass: '******', | |
db: 'test-env', | |
} |
View git.js
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
// blob = file contents, identified by hash | |
const blobs = { | |
'73d8a': 'import x from "y"; console.log("some file contents")', | |
'9c6bd': 'D8 A1 31 0F ...', | |
'547d4': '# Readme\nThis is documentation', | |
'a0302': '# Readme\nThis is some updated documentation', | |
} | |
// tree = references to blobs and trees, identified by hash | |
const trees = { |
View unit-testing.js
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
/** | |
* Returns a list of numbers from `min` (inclusive) to `max` (exclusive). | |
*/ | |
const range = (min, max, acc = []) => { | |
if (max < min) throw new Error('not supported!') | |
if (min >= max) return acc | |
return range(min + 1, max, acc.concat(min)) | |
} | |
/** |
View log.py
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
import json | |
from datetime import datetime, timezone | |
LEVELS = { | |
"emergency": 7, | |
"alert": 6, | |
"critical": 5, | |
"error": 4, | |
"warning": 3, | |
"notice": 2, |
View http-easy.rkt
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
#lang racket/base | |
(require | |
net/http-easy) | |
(define (base-url path) | |
(string-append "https://httpbin.org" path)) | |
; request: GET | |
; response: plain string body |
View 1-web-server.rkt
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
#lang racket/base | |
(provide | |
server-start) | |
(require | |
markdown | |
net/url | |
web-server/http | |
web-server/servlet-env |
View 0-syntax.rkt
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
#lang racket/base | |
(require (for-syntax racket/base)) | |
; Reading Quotes | |
; see: https://docs.racket-lang.org/reference/reader.html | |
; ' quote #' syntax | |
; ` quasiquote #` quasisyntax | |
; , unquote #, unsyntax | |
; ,@ unquote-splicing #,@ unsyntax-splicing |
NewerOlder