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
" lambda λ | |
imap <C-j> <C-k>l* | |
" right arrow → | |
imap <C-l> <C-k>-> | |
" left arrow ← | |
imap <C-h> <C-k><- | |
" compose ∘ |
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
fn main(args: [str]) { | |
let args = vec::tail(args); | |
for vec::each(args) {|a| | |
io::println(respond(a)); | |
} | |
} | |
fn respond(s: str) -> str { |
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 Control.Monad | |
import Control.Monad.Random | |
data RPS = Rock | Paper | Scissors | |
deriving (Show, Eq, Read) | |
data Result = Win | Lose | Tie | |
deriving (Show, Eq) | |
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
Mixins.bq = {} | |
Mixins.bq.mouseOvers = (overElem, toggleElem) -> | |
return (v) -> | |
elem = (that) -> | |
if _.isString toggleElem then that.$(toggleElem) else toggleElem | |
v.on "mouseover #{ overElem }", -> elem(@).show() | |
v.on "mouseout #{ overElem }", -> elem(@).hide() | |
Mixins.bq.initTemplate = (name) -> | |
return (v) -> |
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
#=----------------------------------------------------------------------------=# | |
# Mixins.bq.collection | |
# factor out some view logic. This mixin does the common task of adding | |
# elements to a view when things are added to the collection | |
#=----------------------------------------------------------------------------=# | |
Mixins.bq.collection = (o={}) -> | |
throw "missing collection model view constructor" unless o.createView | |
unless o.tag | |
throw "missing o.tag, this is where the elements will be added to" | |
return (v) -> |
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
mapQ :: (MonadError M.Failure (PersistEntityBackend entity m), | |
PersistStore (PersistEntityBackend entity) m, | |
PersistEntity entity) | |
=> (Key (PersistEntityBackend entity) entity -> PersistEntityBackend entity m t) | |
-> [Key (PersistEntityBackend entity) entity] | |
-> PersistEntityBackend entity m [(Entity entity, t)] | |
mapQ f ids = forM ids $ \id' -> do | |
keyEnt <- get id' | |
xs <- f id' | |
case keyEnt of |
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 Data.CSV.Parser | |
import Control.Applicative | |
import GHC.Exts | |
import Control.Arrow | |
import Data.List (sortBy) | |
import Data.Function | |
type Parser a = FromCSV String a | |
data Class = Witch | DexInt | Templar | Ranger | Marauder | Duelist |
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
web :: IO () | |
web = scotty port $ do | |
post "/tracks" $ (parseBody :: ResponseM [Track]) >>= handleMany | |
post "/track" $ (parseBody :: ResponseM Track) >>= handleOne | |
post "/label" $ (parseBody :: ResponseM Label) >>= handleOne | |
-- post json >=> convert to persistent model >=> validate model >=> fix issues when possible >=> insert into database | |
-- responds with detailed error information from any part of the process | |
-- all refactored down to 1 line for each model with the help of typeclasses. It's beautiful ಥ_ಥ |
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
TrackView = | |
bQuery.view() | |
.set("tagName", "div") | |
.set("className", "track-row") | |
.init((opts={}) -> | |
@artists = new ArtistCollection { unassigned: no } | |
@on "editing:start", => @isEditing = yes | |
@on "editing:end", => @isEditing = no | |
) |
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
public static Maybe<object> GetProperty<T>(this T src, string prop) { | |
return from pi in typeof(T).GetProperty(prop).ToMaybe() | |
select pi.GetValue(src, null); | |
} | |
public static Maybe<IEnumerable<TResult>> GenericSelect<T, TResult>(this IEnumerable<T> ts, string property, Func<object, Maybe<TResult>> fn) { | |
var xs = | |
from t in ts | |
let prop = from x in t.GetProperty(property) | |
from y in fn(x) |