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
FLASK: | |
#!/usr/bin/env python | |
# A github post-receive hook handler, runs some shell command on each HTTP POST to PORT. | |
# github-listener.py PORT 'SOME SHELL COMMAND' | |
import sys | |
from subprocess import * | |
from flask import Flask |
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
------------------------------------------------------------------------------ | |
-- | Renders the child nodes only if the request comes from an authenticated | |
-- user. | |
ifLoggedIn :: Splice Application | |
ifLoggedIn = do | |
node <- getParamNode | |
res <- lift $ requireUser (return []) (return $ childNodes node) | |
return res | |
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
------------------------------------------------------------------------------ | |
-- | Runs the parameter node's children and returns the resulting node list. | |
-- By itself this function is a simple passthrough splice that makes the | |
-- spliced node disappear. In combination with locally bound splices, this | |
-- function makes it easier to pass the desired view into your splices. | |
runChildren :: Monad m => Splice m | |
runChildren = runNodeList . X.childNodes =<< getParamNode | |
------------------------------------------------------------------------------ |
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
#include <stdio.h> | |
#include <string.h> | |
struct node { | |
char c; | |
node * left; | |
node * right; | |
}; | |
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 OverloadedStrings #-} | |
module Main where | |
import Numeric | |
import Data.Bits | |
import Data.List | |
import Text.Blaze | |
import Text.Blaze.Html5 hiding (map) | |
import qualified Text.Blaze.Html5 as H | |
import qualified Text.Blaze.Html5.Attributes as A |
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
bindStrict :: Monad m => Splice m | |
bindStrict = do | |
node <- getParamNode | |
cs <- runChildren | |
maybe (return ()) (add cs) | |
(X.getAttribute bindAttr node) | |
return [] | |
where | |
add cs nm = modifyTS $ bindSplice nm $ do |
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 FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Snap.Snaplet.Internal.Lensed where | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.Trans | |
import Data.Lens.Lazy | |
import Data.Functor |
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
class Monad m => MonadSnapletState s m | m -> s where | |
getSnapletState :: m (Snaplet s) | |
putSnapletState :: (Snaplet s) -> m () | |
modifySnapletState :: (MonadSnapletState s m) => (Snaplet s -> Snaplet s) -> m () | |
modifySnapletState f = do | |
s <- getSnapletState | |
putSnapletState (f s) |
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 BangPatterns #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE RecordWildCards #-} | |
module Snap.Snaplet.Auth.Backends.MongoDB | |
( initMongoAuth | |
) where | |
------------------------------------------------------------------------------ | |
import Control.Arrow |
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
routes = [ ("login", with auth loginHandler) | |
, ("register", with auth registerHandler) | |
, ("logout", with auth logout >> redirect ".") | |
] | |
passParam paramName = maybe pass return =<< getParam paramName | |
loginHandler = do | |
username <- passParam "username" | |
password <- passParam "password" |