Skip to content

Instantly share code, notes, and snippets.

@rknuu
rknuu / simple-composition.hs
Last active August 29, 2015 14:14
Why Haskell is cool
-- Taken from https://www.youtube.com/watch?v=6KkF5-_erns#t=1154
-- Original code taken from https://github.com/haskelllive/haskelllive/blob/episode-1/Chess.hs
module Chess where
-- This call reads in a string grid of a chessboard with each row separated by a newline
-- and returns an encoded board where each position could be Nothing or an encoded piece
-- type (returned from readSquare).
--
readBoard :: String -> Maybe Board
@rknuu
rknuu / jsoniq-regexp-crazy.xq
Last active August 29, 2015 14:21
seriously complicated regular expression in XQuery
(: taken from http://markmail.org/message/5p3uespuxk4ew7fa :)
let $regexp := '(\{)|(\})|(\[)|(\])|(:)|(,)|(true)|(false)|(null)|(\s+)|("([^"\\]|\\"|\\\\|\\/|\\b|\\f|\\n|\\r|\\t|\\u[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9])*")|(-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?)'
return
let $json := '{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
# Taken from @chancancode https://speakerdeck.com/chancancode/turbo-rails-in-rust
>> require "canada"
=> true
>> " ".blank_eh?
=> true
>> "hi".blank_eh?
=> false
@rknuu
rknuu / factorial-table.jl
Created February 10, 2016 02:57
Julia is awesome...
# Julia is fully unicode aware and if you use your variable and function
# names just right, you can express your anger like no other language.
⋰┛ಠДಠ┛⋱彡┻━┻(n) = n < 2 ? n : ⋰┛ಠДಠ┛⋱彡┻━┻(n - 1) + ⋰┛ಠДಠ┛⋱彡┻━┻(n - 2)
@elapsed ⋰┛ಠДಠ┛⋱彡┻━┻(25) # 0.00266