Skip to content

Instantly share code, notes, and snippets.

View bohde's full-sized avatar

Rowan Bohde bohde

View GitHub Profile
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.IO.Class (liftIO)
import PureMVar
asyncGreet :: (MonadIO m) => MVarT m String
asyncGreet = do
v <- newMVar
fork $ do
let greeting = "Hello world"
liftIO $ putStrLn greeting
LogEntry Nothing (Variable (Fresh 0)) []
LogEntry Nothing (Spawn 0) []
LogEntry (Just 0) (Variable (Write 0)) [BlockedOn Nothing 0]
LogEntry (Just 0) (Variable (Read 0)) []
LogEntry (Just 0) Halt [BlockedOn Nothing 0]
Failures:
1) blocking program should not block
predicate failed on: Nothing (after 3 tests):
nothing
Randomized with seed 308638565
Finished in 0.0305 seconds
2 examples, 1 failure
program :: MVarM ()
program = do
chan <- newSkipChan :: MVarM (SkipChan Int)
fork $ void $ getSkipChan chan
mapM_ (putSkipChan chan) [0..10]
-- "new mvar"
-- "new mvar"
-- "write to mvar"
-- "fork"
@bohde
bohde / mvar.hs
Created April 25, 2015 14:44
Minimal Pure MVar
{-# LANGUAGE ExistentialQuantification #-}
import Control.Monad.Free
data MVar a = Empty | Val a
data MVarOps next = forall a. New (MVar a -> next)
| forall a. Put (MVar a) a next
| forall a. Take (MVar a) (a -> next)
-- GHC won't derive this for us :(
@bohde
bohde / foo.hs
Created February 15, 2015 03:47
module Foo where
import Control.Applicative
import Data.Set (Set)
import Data.Map (Map)
import qualified Data.Map as M
import qualified Data.Set as S
get :: String -> IO (Maybe String)
get = undefined
@bohde
bohde / Main.purs.hs
Created March 15, 2014 23:46
Use websockets with Control.Reactive in Purescript
module Main where
import Control.Monad.Eff
import Control.Reactive
import Debug.Trace
import Prelude
foreign import websocket
"function websocket(url) {\
\ return function(outgoing) {\
from django.test import TestCase
from models import App
from my_api import api
class ResourceUriTestCase(TestCase):
urls = 'path.to.api.urls'
def test_uri_uses_the_uuid(self):
uuid = new_uuid()
@bohde
bohde / resources.py
Created October 4, 2012 04:24
Tastypie helpers for view reuse.
class MyResource(ModelResource):
def model_to_data(self, model, request=None):
bundle = self.build_bundle(obj=model, request=request)
return self.full_dehydrate(bundle).data
def resource_for_request(resource_name, filters, request):
resource = v1_dns_api.canonical_resource_for(resource_name)
objects = resource.get_object_list(request).filter(filters)
return (resource.model_to_data(model, request) for model in objects)
@bohde
bohde / if_modified.py
Created September 28, 2012 13:25
An Example ModelResource using If-Modified Headers
from time import mktime
from django.utils.http import http_date, parse_http_date_safe
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpNotModified
class IfModifiedResource(ModelResource):
def cached_obj_get(self, request=None, **kwargs):
bundle = super(IfModifiedResource, self).cached_obj_get(request, **kwargs)