This file contains hidden or 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 qualified Data.ByteString as B | |
main :: IO () | |
main = do | |
td <- newTemplateDirectory' "templates" emptyTemplateState | |
quickServer $ templateHandler td defaultReloadHandler $ \ts -> | |
route [ ("echo/:s", echoHandler) | |
] <|> | |
templateServe ts <|> | |
dir "static" (fileServe ".") |
This file contains hidden or 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 TypeFamilies, QuasiQuotes, TemplateHaskell #-} | |
import Yesod | |
data Echo = Echo | |
mkYesod "Echo" [$parseRoutes| | |
/echo/#String EchoR GET | |
|] | |
instance Yesod Echo where approot _ = "" | |
getEchoR s | |
| length s == 4 = permissionDenied "Forbidden: 4 letter word" | |
| otherwise = return $ RepPlain $ toContent s |
This file contains hidden or 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
get ["echo", word] | |
| length word == 4 = body "4 letter word" >> status 403 | |
| otherwise = body word |
This file contains hidden or 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
-- is there a GHC language extension that would | |
-- let me break up function definitions like this: | |
f1 some_pattern = expression1 | |
f2 some_other_pattern = expression2 | |
f1 yet_another_pattern = expression3 | |
f2 another_pattern = expression4 | |
--instead of having to group them together like this: |
This file contains hidden or 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
sayHello "spanish" = "hola" | |
sayHello "english" = "hi" | |
sayGoodBye "spanish" = "hasta la vista" | |
sayGoodBye "english" = "laterz" |
This file contains hidden or 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
sayHello "spanish" = "hola" | |
sayGoodBye "spanish" = "hasta la vista" | |
sayHello "english" = "hi" | |
sayGoodBye "english" = "laterz" |
This file contains hidden or 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
-- blog posts admin actions | |
get ["admin", "posts"] = do .... | |
post ["admin", "posts"] = do .... | |
put ["admin", "posts", id] = do .... | |
delete ["admin", "posts", id] = do .... | |
-- blog frontend | |
get ["posts"] = do .... | |
get ["posts", year, month, day] = do .... | |
get ["posts", year, month, day, id] = do .... |
This file contains hidden or 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
app = require('express').createServer() | |
app.get( | |
'/', | |
(req, res) -> | |
res.send('hello express in coffeescript!') | |
) | |
app.listen(3000) |
This file contains hidden or 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
HomeController = | |
index: -> $('#main').text 'Welcome!' | |
routes = -> @get '#/', HomeController.index | |
app = $.sammy routes | |
$ -> app.run() |
This file contains hidden or 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
db.events.save({name: "event1", start_date: "2010/01/01", end_date: "2010/09/01"}) | |
db.events.save({name: "event2", start_date: "2010/01/01", end_date: "2010/09/30"}) | |
db.events.find({start_date: {'$lte': "2010/09/10"}, end_date: {'$gt': "2010/09/10"}}) |