Skip to content

Instantly share code, notes, and snippets.

import collections
from typing import Counter, List, Set, Tuple
def subanagrams(letters: Counter[str], words: Set[str], min_len=4) -> List[Tuple[str, Counter[str]]]:
anagrams = []
for word in words:
if len(word) < min_len: continue
rest = letters.copy()
@hrldcpr
hrldcpr / concurrent_joystick.py
Last active March 9, 2019 23:15
read from a joystick device that blocks when held in the same direction, to control a character walking, using asyncio
import asyncio
import aiofiles # third party package, install from pip
# bytes outputted by the imaginary joystick device:
CENTER = b'x'
NORTH = b'n'
EAST = b'e'
SOUTH = b's'
@hrldcpr
hrldcpr / ex-ramda.js
Last active August 31, 2017 19:51
ex-exampda
// We have some state like:
const state1 = {
data: { some: 'stuff' },
people: ['blah', 'blah', 'blah'],
memberships: [
{ id: 1, roles: [], other: 'stuff' },
{ id: 2, roles: ['client'], more: 'junk' }
]
};
@hrldcpr
hrldcpr / ramda.js
Last active August 31, 2017 19:53
exampda
// We have some state like:
const state1 = {
data: { some: 'stuff' },
people: ['blah', 'blah', 'blah'],
memberships: [
{ id: 1, roles: [], other: 'stuff' },
{ id: 2, roles: ['client'], more: 'junk' }
]
};

Keybase proof

I hereby claim:

  • I am hrldcpr on github.
  • I am harold (https://keybase.io/harold) on keybase.
  • I have a public key ASAPWKbiomRFjYfOwBXs914vgEEbl3rgCRofGekEWGPzUQo

To claim this, I am signing this object:

@hrldcpr
hrldcpr / tee.py
Created July 12, 2015 22:08
implementation of `itertools.tee()` using one linked list instead of n deques
import collections
class LinkedList:
def __init__(self, value, tail=None):
self.value = value
self.tail = tail
def tee(iterable, n=2):
it = iter(iterable)
empty = LinkedList(None)
@hrldcpr
hrldcpr / ReadingT.hs
Last active August 29, 2015 14:04
combination of Reader and Maybe monads, using the ReaderT monad transformer
import Control.Monad.Reader
import Control.Monad.Trans
import Data.List
import Data.Maybe
import Text.Printf
type Environment = [(String, String)]
get :: String -> ReaderT Environment Maybe String
@hrldcpr
hrldcpr / liftM.hs
Created July 31, 2014 14:50
three different implementations of liftM
liftM f m = m >>= (return . f)
liftM f m = do
a <- m
return (f a)
-- which is just sugar for:
liftM f m =
m >>= \a ->
@hrldcpr
hrldcpr / install_docker.md
Last active August 29, 2015 14:04
installing Docker on a Mac, such that `docker run -v ...` works for anything under /Users

First, install VirtualBox. Then:

brew update
brew upgrade
brew install docker boot2docker

mkdir ~/.boot2docker
curl http://static.dockerfiles.io/boot2docker-v1.1.2-virtualbox-guest-additions-v4.3.12.iso \
> ~/.boot2docker/boot2docker.iso
@hrldcpr
hrldcpr / Reading.hs
Created July 28, 2014 16:23
simple example of Reader monad
import qualified Data.Maybe as Maybe
import qualified Control.Monad.Reader as Reader
type Environment = [(String, String)]
get :: String -> Environment -> String
get k env = Maybe.fromJust $ lookup k env