Skip to content

Instantly share code, notes, and snippets.

@hrldcpr
hrldcpr / lazygreedy.md
Last active August 29, 2015 14:04
comparison of lazy and greedy regex performance

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 - ``

@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
@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 / 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 / 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 / evernote-crontab
Created December 15, 2012 18:27
crontab to make Evernote for Mac sync every minute. to edit your crontab, open Terminal and run `EDITOR=nano crontab -e`
* * * * * osascript -e 'if application "Evernote" is running then tell application "Evernote" to synchronize'
@hrldcpr
hrldcpr / gist:4429798
Last active December 10, 2015 11:48
example of trying to use svg in meteor
<head>
<title>Leaderboard</title>
</head>
<body>
<div id="outer">
{{> leaderboard}}
</div>
</body>
for (var v = 0; v < 2*N; v++) {
for (var u = -N; u < N; u++) {
var w = getCube(u, v);
if (w > 0 && w < tick) { // there's a cube and it's not one we just created
setCube(u, v, 0); // remove it
if (u < N && v > 0) {
if (Math.random() < 0.5) // 50% of the time
setCube(u + 1, v - 1, tick); // directly above
if (Math.random() < 0.25) // 25% of the time
setCube(u + 1, v - 2, tick); // above-left
@hrldcpr
hrldcpr / iwish.hs
Last active December 12, 2015 12:39
dedup [] = []
dedup (x:xs) = dedup' x xs
where
dedup' x [] = [x]
dedup' x (x:xs) = dedup' x xs
dedup' y (x:xs) = y : dedup' x xs

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: