Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE DeriveDataTypeable #-}
module Main where
{-
Example FRP/zeromq app.
The idea is that messages come into a zeromq socket in the form "id state". The state is of each id is tracked until it's complete.
-}
import Control.Monad
@commandodev
commandodev / stargate_process_example.py
Created October 3, 2011 14:44
Stargate example app
import eventlet
from eventlet import wsgi
from paste.httpserver import serve
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config
from stargate import WebSocketAwareResource, WebSocketView, is_websocket
import simplejson as json
host = "127.0.0.1"
@commandodev
commandodev / Automata.hs
Created November 14, 2011 12:00 — forked from petermarks/Automata.hs
Automata
module Automata where
import Prelude hiding (map, head, foldl, take)
import qualified Prelude as P
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as C
import Data.ByteString.Internal (c2w)
import qualified Data.Map as M
import Data.List (sort)
import Data.Tuple
{-
One process starts the master process
Other start do-nothing process
master distributes the work among the other processes
-}
module Main where
import Remote
import Control.Monad
{-# LANGUAGE NoMonomorphismRestriction #-}
module Data.Pcap.Source (
sourcePcap
, parsePcap
) where
import Control.Monad.IO.Class
import qualified Data.ByteString as BS
import Data.Conduit
import qualified Data.Conduit.List as CL
import Data.DateTime
@commandodev
commandodev / FRP.hs
Created October 2, 2012 15:05
Fay Arrows problem
-- Arrow definitions
arr = arrC
first = firstC
second = secondC
(<<<) :: Coroutine b o -> Coroutine i b -> Coroutine i o
cof <<< cog = Coroutine $ \i ->
let (x, cog') = runC cog i
(y, cof') = runC cof x
in (y, cof' <<< cog')
@commandodev
commandodev / git aliases
Last active December 25, 2015 20:59
Nicer git branches
alias gbr='for k in `git branch|sed "s/^..//"`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t\\t"$k";done | sort -r | sed -e "s/\(^.*\):[0-9]\{2\} +\?[0-9]\{4\} /\1 /" -e "s/minutes/mins/"'
alias gbra='for k in `git branch -a|sed "s/^..//"`;do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t\\t"$k";done | sort -r | sed -e "s/\(^.*\):[0-9]\{2\} +\?[0-9]\{4\} /\1 /" -e "s/minutes/mins/"'
@commandodev
commandodev / k vs *
Last active September 20, 2017 14:56
insert
:: (KnownSymbol k, Typeable i, ChannelType k api ~ i)
=> Proxy api -> Proxy k -> f i -> RouteMap f routes -> RouteMap f ((k :> i) ': routes)
insert _ pKey i = Routes . Map.insert k (I i) . unRoutes
where
k = (symbolVal pKey) ^. packed
type family Chan (chan :: *) :: * where
Chan (chan :> a) = a
@commandodev
commandodev / rest_traversal.py
Last active September 11, 2018 20:03
Rest traversal in pyramid. With a small example of usage.
from pyramid.view import view_config
from sqlalchemy.ext.associationproxy import AssociationProxy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, object_mapper, ColumnProperty, SynonymProperty
Session = scoped_session(sessionmaker())
class _PrettyPrintBase(object):
"""Base mixin for all of our declarative tables
@commandodev
commandodev / req_req.py
Created June 26, 2012 10:04
Handling REQ/REP syncronization in eventlet
from eventlet.pools import Pool
from eventlet.timeout import Timeout
class SocketPool(Pool):
"""A pool of sockets connected to a component
If a socket times out in use, simply close if before handing it back to the
pool and it will be discarded and a replacement inserted into the pool."""
def __init__(self, address, **kwargs):