Skip to content

Instantly share code, notes, and snippets.

View chenglou's full-sized avatar
💫

Cheng Lou chenglou

💫
View GitHub Profile
@chenglou
chenglou / smallestTemplateEngineEver.coffee
Created June 20, 2013 02:21
It actually works perfectly, can you believe it? Inspired by coffeekup.
# 21 lines, gutter at 80, for a fully functional coffeescript templater.
global.compiledHTML = ''
makeTagFunc = (tagName, isSelfClosing) ->
(args...) ->
selfEndingTag = if isSelfClosing then ' /' else ''
attrs = args.filter((i) -> typeof i is 'object').reduce(((i, j) ->
i + ("#{key}='#{val}'" for key, val of j).join ' '), '')
inner = args.filter((i) ->
typeof i != 'function' and typeof i != 'object').map((i) -> i).join ' '
global.compiledHTML += "<#{(tagName + ' ' + attrs).trim()}#{selfEndingTag}>"
@chenglou
chenglou / fibPrimeGenerators.js
Last active February 18, 2022 04:14
JavaScript generators: fibonacci, natural numbers and sieve of Erasthosthenes for primes.
/* Infinite stream of numbers!
Format: `[number, suspendedStream]` where suspendedStream is really just a
function that, upon calling, returns another `[number, suspendedStream]`.
*/
function head(a) {
return a[0];
}
function tail(a) {