Skip to content

Instantly share code, notes, and snippets.

@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
@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):
{-# 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 / 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 / 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/"'
$ nix-shell -I . --pure --show-trace
error: while evaluating the attribute `nativeBuildInputs' of the derivation `client' at /home/ben/dev/ghcjs/oHm/examples/ohm-chat-client/default.nix:9:3:
cannot coerce a set to a string, at /home/ben/dev/ghcjs/oHm/examples/ohm-chat-client/default.nix:9:3
./dev-shell
[nix-shell:~/dev/hydra]$ ./configure $configureFlags --prefix=/opt/hydra
bash: ./configure: No such file or directory
[nix-shell:~/dev/hydra]$ ls
bootstrap configure.ac COPYING dev-shell doc hydra-module.nix INSTALL Makefile.am README.md release.nix src tests version
[nix-shell:~/dev/hydra]$ ./bootstrap
autoreconf: Entering directory `.'
@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