Skip to content

Instantly share code, notes, and snippets.

@ysimonson
ysimonson / gist:1313774
Created October 25, 2011 18:37
Telephone words in Haskell
import Data.Char
telephoneWords :: String -> [String]
telephoneWords [] = [[]]
telephoneWords (digit : digits) =
[letter : rest
| letter <- digitToLetters digit, rest <- telephoneWords digits]
@ysimonson
ysimonson / gist:3173269
Created July 24, 2012 23:10
ZMQ bug (failing script)
var util = require("util"),
zmq = require("zmq"),
events = require("events");
function Socket(zmqSocket) {
var self = this;
self._zmqSocket = zmqSocket;
self._zmqSocket.on("error", function(error) {
self.emit("error", error);
@ysimonson
ysimonson / gist:3173276
Created July 24, 2012 23:11
ZMQ bug (working script)
var zmq = require("zmq");
var socket = zmq.socket("xrep");
socket.bindSync("ipc:///tmp/zmq-issue");
socket.on("message", function(envelope, _, name) {
socket.send([envelope, new Buffer(0), "Hello, " + name.toString()]);
});
@ysimonson
ysimonson / gist:4401171
Created December 28, 2012 19:38
Sudoku puzzle generator created in Haskell
import System.Random
import Data.Set (Set, unions, fromList, member)
import Data.Map (Map, singleton, elems, (!), insert)
import Debug.Trace (trace)
main :: IO ()
main = do
rng <- newStdGen
layout <- return (createRandomLayout rng 0.1)
putStr (stringifyLayout layout)
@ysimonson
ysimonson / gist:5877284
Last active February 22, 2016 19:56
LinkedIn OAuth2 authentication over tornado
from tornado import auth, httpclient, httputil, escape
import urllib.request
import urllib.parse
import urllib.error
import functools
REQUEST_TIMEOUT = 20.0
class LinkedInMixin(auth.OAuth2Mixin):
@ysimonson
ysimonson / gist:6795714
Created October 2, 2013 15:38
Search for all files that have foobar using silver searcher, and open them in sublime
ag foobar --files-with-matches | while read filename; do subl $filename; done
@ysimonson
ysimonson / gist:7120798
Last active February 18, 2016 20:24
Tornado decorator to make an endpoint prerenderable for search engine crawlers
# This has been turned into a full-fledged repo:
# https://github.com/dailymuse/torender
@ysimonson
ysimonson / rust_try_replacer.py
Created January 5, 2017 04:16
Replaces all instances of try! in a rust codebase with the ? operator. I used this because I can't use rustfmt.
import os
import re
import sys
TRY_PATTERN = re.compile(r"try!\(")
def replace_try(contents):
match = TRY_PATTERN.search(contents)
if match:
@ysimonson
ysimonson / wheel.html
Created February 18, 2017 20:06
Twirling Color Wheel
<html>
<body style="text-align: center">
<img id="img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtoAAALaCAYAAAAP7vQzAAGx+0lEQVR42uydd5xdVdn9175TEyChgwoi0kvovSm9CoReRak2quCL5RVff4Ki0kQRFAUEAkS69N577yVUEZAOaZNp+/dHCpM75+z9tH3unWQ/n4+Sueecfc6dhMz3LtZeyyFPnjx58pBnl82B9g4A/TO//oPd0bbuWpgLXZgLHnMBmHPa/+aAx9wA5gUwEsBIeMwJYC7ATT3HYxgw43+d8OgA0AagDR5tAGoAWgA4eACAn/YE/fDoA9ANoAdANzymAOgCMBnAJHhMAjARwHh4Px7AZ9P+9zE8PgIwAcAE+Gn/BMYDGI8OTLjjAeCv/6r7BtSAyZOBK+7OfxaabQ455BCceeaZ+RuRJ08Tjcvfgjx58uQBRs4FrL0qgN5pfzk64OBdMOfcc2ME+jACwIjWGuZdf1Us1NKK+dCP+QA3zzSAng/9mKsOljsBdALoANA+DZA/n9DXnHM51w4+1gdgyrT/dcHPAPSp//T4EA4fTYPyDwH/IRw+6OnGf+97Gp/1+WnQXsOnH3yE3r9dN2DtFuC+p4AJk/OfrQzaefJk0M6TJ0+eWXra2oBtNvz86y8sgM4DdsX86MN8AOabbyQWW3x5fAl9+ALgvgDgS+jDvNPU5+nK81QE9TGodY2DaZNzffhcB6Ad3cBMKvg7qOEdAG+j37+DFrw57gW888kEfATgAzh8dNbVwPufTr2+vw+47iGgrz//2cygnSdPBu08efLkGRKz1GLAKisB6AE2Xgsj1lsHC6MLC3d24CvLjMJXAXwZcF+Gx5fRi5HANCV6uraLIrh09rAMlw7Eg2t5G2gPrTn9eDv6UcN4eHwK4H204HUA/wb8G+jHy8+/gHe6u/EuOvDuHQ+j/95nAbQCjzwHvPZu/r
@ysimonson
ysimonson / mixed_tabs_spaces.py
Created April 20, 2017 00:39
Search for mixed tabs/spaces in files
#!/usr/bin/env python3
# Uses python3. Example: `python3 mixed_tabs_spaces.py '**/*.py'`
import glob
import sys
def has_mixed_tabs_spaces(f):
has_spaces = False
has_tabs = False