Skip to content

Instantly share code, notes, and snippets.

>>> english = set(open('/usr/share/dict/words').read().splitlines())
>>> left_hand = 'qwertasdfgzxcvb'
>>> words_typeable_by_left_hand = [w for w in english if all(c in left_hand for c in w)]
>>> print max(words_typeable_by_left_hand,key = lambda w: len(w))
reverberates
@stesh
stesh / gist:5522364
Last active December 17, 2015 00:39
An Error transformer monad
class Monad m => MonadError e m | m -> e where
catchError :: e -> m a
throwError :: m a -> (e -> m a) -> m a
data ErrorT e m a = ErrorT {
runErrorT :: m (Either e a)
}
instance MonadTrans (ErrorT e m) where
lift m = ErrorT $ do
@stesh
stesh / gist:5456884
Created April 25, 2013 01:31
The State transformer monad
-- State transformer monad --
--
-- 1. Typeclass MonadState, declaring stateful operations
-- 2. A datatype to work with
-- 3. An implementation of Monad
-- 4. An implementation of MonadTrans
-- 5. An implementation of MonadState
-- 6. The State Monad for free, by transforming Identity
class (Monad m) => MonadState s m | m -> s where
type Stream a = MVar (Item a)
data Item a = Item a (Stream a)
data Channel a = Channel (MVar (Stream a)) (MVar (Stream a))
newChannel :: IO (Channel a)
newChannel = do
hole <- newEmptyMVar
readVar <- newMVar hole
writeVar <- newMVar hole
return $ Channel readVar writeVar
#!/bin/sh
fomafst="$1"
inverted=$(tempfile)
cat <<EOF | foma -p
read regex @"$fomafst";
invert net
save stack $inverted
EOF
#!/bin/sh
cat <<EOF | ssh -CX cube python
from nltk.tree import Tree
Tree('''$(pbpaste)''').draw()
EOF
#!/usr/bin/python
words = open('/usr/share/dict/words').read().splitlines()
sort = lambda s:''.join(sorted(s))
anagrams = {sort(w):[] for w in words}
for word in words:
anagrams[sort(word)].append(word)
while True:
print anagrams[sort(raw_input())]
{
"Teri accepted {verb} hated pharmacology": {
"affirmed": true,
"asked": false,
"suggested": true,
"intimated": false,
"predicted": true,
"justified": false,
"denied": true,
"confabulated": true,
#!/usr/bin/python
verbs = ['accepted', 'accused', 'admitted', 'affirmed', 'agreed', 'allowed',
'ascertained', 'asked', 'asserted', 'averred', 'believed', 'bet', 'conceded',
'confabulated', 'conessed', 'confirmed', 'considered', 'denied', 'desired',
'disagreed', 'discussed', 'disliked', 'disproved', 'doubted', 'entailed',
'established', 'explored', 'forgot', 'hated', 'heard', 'hid', 'hoped',
'imagined', 'indicated', 'inquired', 'intimiated', 'justified', 'knew', 'liked',
'mentioned', 'noted', 'noticed', 'opined', 'persuaded', 'predicted', 'proved',
'queried', 'refuted', 'registered', 'regretted', 'remembered', 'said', 'saw',
#!/bin/sh
cd "$HOME/tmp"
ln -s $$ lock || exit 1
TMPDOT="$HOME/tmp/tmp.dot.$$.$RANDOM"
OUTPNG="/srv/webspace/stesh/intersocs.svg"
IRCLINKS="$HOME/bin/irclinks"
[ -x $IRCLINKS ] || exit 1