Skip to content

Instantly share code, notes, and snippets.

View regiskuckaertz's full-sized avatar

Regis Kuckaertz regiskuckaertz

View GitHub Profile
package humbug
package codecs
sealed abstract class Type[T]
case object TyBool extends Type[Boolean]
case object TyByte extends Type[Byte]
case object TyDouble extends Type[Double]
case object TyI16 extends Type[Short]
case object TyI32 extends Type[Int]
case object TyI64 extends Type[Long]
@regiskuckaertz
regiskuckaertz / stripmargin.js
Created August 4, 2017 12:21
Scala's stripMargin
function stripMargin(sts, ...vals) {
let tts = sts[0];
if( vals.length ) {
tts = sts.reduce((s, i) => s + vals[i], '');
}
return tts.split('\n')
.map(s => s.trimLeft().startsWith('|')
? s.trimLeft().substr(1)
: s)
@regiskuckaertz
regiskuckaertz / copy.js
Created July 28, 2017 09:31
Object.prototype.copy
Object.defineProperty(
Object.prototype,
'copy',
{ value: function(spec) {
return Object.freeze(Object.assign({}, this, spec));
}
}
);
@regiskuckaertz
regiskuckaertz / dom-zipper.hs
Last active March 22, 2017 13:50
Zipper for a DOM-like tree data type
data Tree a = Leaf a | Node a [Tree]
type Crumb a = (a, [Tree a], [Tree a])
type Breadcrumbs a = [Crumb a]
type Zipper a = (Tree a, Breadcrumbs a)
goDown :: Zipper a -> Int -> Zipper a
goDown (Node el children, bs) n = let (head, nth:tail) = splitAt children n
in (nth, Crumb el head tail : bs)
@regiskuckaertz
regiskuckaertz / arrival.hs
Last active March 20, 2017 16:36
Template compiler in Haskell
--- We just read whatever comes from standard input and spit out its conversion result
main = interact louise
--- Our runner will just pipe the three components together:
louise :: String -> String
louise html = let result = parseHTML html >>= html2js >>= writeJS in
case result of
Right ok -> ok
Left nok -> "Error: " ++ nok