Skip to content

Instantly share code, notes, and snippets.

@wting
wting / gfm.rb
Created January 9, 2013 00:11 — forked from mojombo/gfm.rb
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end
@wting
wting / .gitignore
Last active December 10, 2015 17:08
autojump-git PKGBUILD
*.tar.xz
pkg/
src/
@wting
wting / .jhbuildrc
Created May 14, 2012 22:39
JHBuild - Epiphany
# -*- mode: python -*-
# -*- coding: utf-8 -*-
# edit this file to match your settings and copy it to ~/.jhbuildrc
# if you have a GNOME git account, uncomment this line
# repos['git.gnome.org'] = 'ssh://user@git.gnome.org/git/'
# what module set should be used. The default can be found in
# jhbuild/defaults.jhbuildrc, but can be any file in the modulesets directory
import XMonad
main = xmonad defaultConfig
{ modMask = mod4Mask -- Use Super instead of Alt
, terminal = "urxvt"
-- more changes
}
@wting
wting / uri.js
Created May 7, 2012 19:31 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@wting
wting / gist:2495828
Created April 26, 2012 04:29
codejam: alien language
#!/usr/bin/env python2
import re
_, lines, cases = map(int,raw_input().split())
words = []
for _ in xrange(lines):
words.append(raw_input())
for c in xrange(cases):
@wting
wting / tree.md
Created April 25, 2012 23:36 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@wting
wting / prime.py
Created April 24, 2012 05:07
misc. prime number related functions
#!/usr/bin/env python
import pudb
import random
# infinite prime number generator
def gen_prime():
tbl = dict()
i = 2
while True:
@wting
wting / wait_do.sh
Last active August 29, 2015 14:02
Watch a file or directory for changes and run a command in response. For example: wait_do src/ ./run_tests.py
#!/usr/bin/bash
wait_do() {
if [[ `uname` == 'Darwin' ]]; then
if ! command -v fswatch &>/dev/null; then
echo "fswatch not found!"
return
fi
fswatch . ${@}
else
@wting
wting / nevergonnagiveyouup.sh
Last active August 29, 2015 14:02
Runs a command continuously (e.g. rsync) until it succeeds (0 exit code).
#!/usr/bin/bash
nevergonnagiveyouup() {
false
while [ $? -ne 0 ]; do
${@}
if [ $? -ne 0 ]; then
echo "[$(\date +%Y.%m.%d_%H%M)] FAIL: trying again in 60 seconds..."
sleep 60