Skip to content

Instantly share code, notes, and snippets.

View hansonkd's full-sized avatar

Kyle Hanson hansonkd

  • Statetrace
View GitHub Profile
Updating History for <<”some_user”>>
Users value: [{{<<”email”>>,riak_dt_lwwreg},<<”first@example.com”>>}]
Users history before update: []
Updating History for <<”some_user”>>
Users value: [{{<<”email”>>,riak_dt_lwwreg},<<”second@example.com”>>}]
Users history before update: [{{<<”num_commits”>>,riak_dt_emcntr},1},{{<<”all_emails”>>,riak_dt_orswot},[<<”first@example.com”>>]}]
% Update Counter
increment
decrement
{increment, 4}
{decrement, 9}
% Update Set
{add, <<"Value">>}
{add_all, [<<"Value">>]}
{remove, <<"Value">>}
{remove_all, <<"Value">>}
user = riak_client.bucket_type('app_objects').bucket('users').get("some_user")
user.registers['email'].assign("first@example.com")
user.store()
user.registers['email'].assign("second@example.com")
user.store()
-module(example_hook).
-export([postcommit/1]).
postcommit(RObj) ->
{ok, Client} = riak:local_client(),
ThisNode = atom_to_binary(node(), latin1),
UserKey = riak_object:key(RObj),
% The Users value from a riak_dt_map (Map)
$ 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}}
==> 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"}}}
{-# 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
@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
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',
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