Skip to content

Instantly share code, notes, and snippets.

harold cooper hrldcpr

Block or report user

Report or block hrldcpr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hrldcpr
hrldcpr / concurrent_joystick.py
Last active Mar 9, 2019
read from a joystick device that blocks when held in the same direction, to control a character walking, using asyncio
View concurrent_joystick.py
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'
View ex-ramda.js
// 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' }
]
};
View ramda.js
// 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' }
]
};
View keybase.md

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 Jul 12, 2015
implementation of `itertools.tee()` using one linked list instead of n deques
View tee.py
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 Aug 29, 2015
combination of Reader and Maybe monads, using the ReaderT monad transformer
View ReadingT.hs
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 Jul 31, 2014
three different implementations of liftM
View liftM.hs
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 Aug 29, 2015
installing Docker on a Mac, such that `docker run -v ...` works for anything under /Users
View install_docker.md

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 Jul 28, 2014
simple example of Reader monad
View Reading.hs
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
@hrldcpr
hrldcpr / lazygreedy.md
Last active Aug 29, 2015
comparison of lazy and greedy regex performance
View lazygreedy.md

greedy - <img [^>]*>

python3 -m timeit -s 'import re; r = re.compile(r"<img [^>]*>")' \
'r.findall("<img src alt name etc> <img even more stuff forever dot com forward slash junk.html and stuff>")'

1000000 loops, best of 3: 0.72 usec per loop

lazy - <img .*?>

You can’t perform that action at this time.