Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
-- | This module contains convenience functions for helping render
-- Heist templates from Snap.
module Snap.Heist where
------------------------------------------------------------------------------
import Control.Applicative
{-# LANGUAGE OverloadedStrings #-}
module Splices.MongoDB where
import Prelude
import qualified Prelude as P
import Control.Monad
import Control.Monad.Trans
import Data.Maybe (fromJust)
@mightybyte
mightybyte / local.js
Created January 3, 2011 06:34
Javascript for digestive-functors massInput
inputHidden = flip inputRead "Error reading hidden" $ \id' inp ->
createFormHtml $ \cfg -> applyClasses' [htmlInputClasses] cfg $
H.input ! A.type_ "hidden"
! A.name (H.stringValue $ show id')
! A.id (H.stringValue $ show id')
! A.value (H.stringValue $ fromMaybe "" inp)
massInputHtml s d = mapView (fmap addControls) $ massInput inputHidden s d
where
addControls form = do
@mightybyte
mightybyte / MassInputDemo.hs
Created January 4, 2011 03:15
Full massInput example
-- This code uses the convenience code I added to digestive-functors-blaze.
-- http://bit.ly/hjGRXl
{-# LANGUAGE OverloadedStrings, TypeSynonymInstances,
NoMonomorphismRestriction #-}
import Control.Applicative
import Data.String
import Snap.Types
import Snap.Http.Server (httpServe, defaultConfig)
@mightybyte
mightybyte / Instances.hs
Created January 5, 2011 00:30
Working on HasFormlet type class
{-# LANGUAGE TypeSynonymInstances #-}
module Text.Digestive.Blaze.Instances where
import Data.Maybe
import Text.Digestive.Blaze.Html5 (inputText, inputCheckBox, inputTextRead)
import Text.Digestive.Forms (FormInput)
import Text.Digestive.Types (Form)
class HasFormlet a where
formlet :: (Monad m, Functor m, FormInput i f) => e -> Maybe a -> Form m i e v a
@mightybyte
mightybyte / passdepth.patch
Created January 19, 2011 14:32
Passes a depth to addItem
diff --git a/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs b/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
index 88b5510..4d647af 100644
--- a/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
+++ b/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
@@ -41,6 +41,7 @@ import Text.Digestive.Forms (FormInput (..))
import qualified Text.Digestive.Forms as Forms
import qualified Text.Digestive.Common as Common
import Text.Digestive.Forms.Html
+import Text.Digestive.Result
import Text.Digestive.Transform
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
@mightybyte
mightybyte / gist:866161
Created March 11, 2011 16:44
Useful Heist Splices
------------------------------------------------------------------------------
-- | 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
@mightybyte
mightybyte / gist:871084
Created March 15, 2011 17:25
mapBind variations
------------------------------------------------------------------------------
-- | 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
------------------------------------------------------------------------------
@mightybyte
mightybyte / gist:873828
Created March 17, 2011 04:19
iterative inorder tree traversal
#include <stdio.h>
#include <string.h>
struct node {
char c;
node * left;
node * right;
};