Skip to content

Instantly share code, notes, and snippets.

View hansonkd's full-sized avatar

Kyle Hanson hansonkd

  • Statetrace
View GitHub Profile
@hansonkd
hansonkd / gist:3422759
Created August 22, 2012 06:06
Fay JSON
{-# LANGUAGE NoImplicitPrelude #-}
module Console where
import Language.Fay.FFI
import Language.Fay.Prelude
data MyData = MyData { xVar :: Int, yVar :: Int }
myData :: MyData
{-# LANGUAGE NoImplicitPrelude #-}
module Console where
import Language.Fay.FFI
import Language.Fay.Prelude
data MyData = MyData { xVar :: Int, yVar :: Int }
instance Foreign MyData
@hansonkd
hansonkd / gist:3458272
Created August 25, 2012 01:07
Snap OpenId persistent state example
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
------------------------------------------------------------------------------
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Exception (SomeException, try)
import Control.Arrow (second)
import qualified Data.Text as T
import System.IO
module SnapApp.Processing (sanatizeSourceString) where
import GHC
import Outputable
import HsDecls
import Data.List
import Data.Maybe
import Control.Monad (unless)
import Text.Regex.Posix
from flask import Flask
from flask.ext.security import RoleMixin, UserMixin, MongoEngineUserDatastore, Security
from flask.ext.mongoengine import MongoEngine
from werkzeug.local import LocalProxy
app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = dict(
db='flask_security_test',
host='localhost',
@hansonkd
hansonkd / gist:6259695
Created August 18, 2013 03:01
IxSet filter by key
-- | Returns the subset of an index whose key when run against the provided
-- function returns True.
filterByKey :: (Indexable a, Typeable a, Ord a, Typeable k)
=> (k -> Bool) -> IxSet a -> IxSet a
filterByKey func ixset@(IxSet indexes) = collect indexes
where
collect [] = [] -- FIXME: should be an error
collect (Ix index _:is) = maybe (collect is) f $ cast index
where
f index'' = insertList (concatMap Set.elems [ val | (key, val) <- (Map.toList index''), (func key)]) empty
{-# LANGUAGE OverloadedStrings, DeriveGeneric, TypeOperators #-}
import qualified Data.Text as T
import Database.MongoDB
import Control.Monad.Trans (liftIO, MonadIO)
import Control.Monad
import Control.Monad (forM_)
import qualified Data.Bson as B
import Data.Bson.Generic
==> riak_api (get-deps)
Pulling riak_pb from {git,"git://github.com/basho/riak_pb.git",
{tag,"2.0.0.16"}}
Cloning into 'riak_pb'...
ERROR: Dependency dir /riak-build/deps/riak_pb failed application validation with reason:
{version_mismatch,{"/riak-build/deps/riak_pb/src/riak_pb.app.src",
{expected,"2.0.0.16"},
{has,"2.0.0.15-15-gd10c567"}}}
$ curl http://localhost:8098/buckets/test/props
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"test","notfound_ok":true,"old_vclock":86400,"postcommit":[{"mod":"riak_DNE","fun":"postcommit_send_DNE"}],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","small_vclock":50,"w":"quorum","young_vclock":20}}