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
//-- If you understand closures - you know why this will always return true | |
function f(value) { | |
return (function (copy) { | |
return copy === value; | |
}(value)); | |
} |
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
// Orignal ------------------------------------------------------------ | |
var isFancy = true; | |
var fancy = document.querySelector("#commentsbtn"); | |
fancy.addEventListener("click", function(e){ | |
if (isFancy) { | |
document.body.classList.remove("fancy-comments"); | |
isFancy = false; | |
} | |
else { |
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
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI #-} | |
import Reflex.Dom | |
import Data.Monoid | |
import GHCJS.Types | |
import GHCJS.Foreign | |
import GHCJS.DOM.Element | |
import GHCJS.DOM.Types | |
import Control.Monad.IO.Class | |
newtype LeafletMap = LeafletMap { unLeafletMap :: JSRef LeafletMap } |
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
//-- Sum -------------------------------------------------------------- | |
let | |
identity = 0, | |
mappend = (x,y) => x + y, // + | |
concatSum = | |
xs => xs.reduce(mappend, identity) | |
concatSum([1,2,3,4,5]) // => 15 | |
//-- Product ---------------------------------------------------------- |
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
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import Prelude hiding (succ) | |
newtype Fix f = Fix (f (Fix f)) | |
deriving instance (Show (f (Fix f))) => Show (Fix f) |
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
-- old ---------------------------------------------------------------- | |
mkGraphMeta (start,end) (aggregated,timeSeriesWithColor) = | |
(aggregated,) $ fromMaybe (Nothing,[]) $ case second unTimeSeries <$> (timeSeriesWithColor :: [(String,TimeSeries)]) of | |
[] -> Nothing | |
xss -> do | |
minMax@(vMin,vMax) <- getMinMax $ snd <$> (xss :: [(String,[(UTCTime,Double)])]) | |
let | |
tw = end `diffUTCTime` start | |
fx = fromIntegral pWidth / tw | |
ph = fromIntegral pHeight |
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
Postgres Cheat Sheet | |
Source: Postgresql Documentation | |
### shell commands | |
creatuser <user> | |
deletesuer <user> | |
createdb -O <user> -E utf8 -T <template> <db_name> | |
dropdb <db_name> |
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
{-# LANGUAGE TupleSections #-} | |
import Control.Lens | |
data Expr | |
= Var String | |
| App Expr Expr | |
| Lam String Expr | |
deriving Show |
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
const | |
whenDivisibleBy = (x, t, f) => n => (n % x == 0 ? t : f), | |
fizz = whenDivisibleBy(3, 'Fizz', ''), | |
buzz = whenDivisibleBy(5, 'Buzz', ''), | |
fizzBuzz = n => fizz(n) + buzz(n) || String(n); | |
//Array(...Array(100)).map((_,x) => fizzBuzz(x+1)) |