This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
fomafst="$1" | |
inverted=$(tempfile) | |
cat <<EOF | foma -p | |
read regex @"$fomafst"; | |
invert net | |
save stack $inverted | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cat <<EOF | ssh -CX cube python | |
from nltk.tree import Tree | |
Tree('''$(pbpaste)''').draw() | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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())] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Teri accepted {verb} hated pharmacology": { | |
"affirmed": true, | |
"asked": false, | |
"suggested": true, | |
"intimated": false, | |
"predicted": true, | |
"justified": false, | |
"denied": true, | |
"confabulated": true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |