Skip to content

Instantly share code, notes, and snippets.

View davidchambers's full-sized avatar

David Chambers davidchambers

View GitHub Profile
@davidchambers
davidchambers / open_in_hashify.rb
Created May 15, 2011 23:10 — forked from adrusi/open_in_hashify.rb
TextMate command to open a markdown document in hashify.me
#!/usr/bin/env ruby
require "base64"
message = "HG: Enter commit message. Lines beginning with 'HG:' are removed."
data = STDIN.read
data.gsub!(/^HG: .+\n/, '') if data.include? message
%x[open http://hashify.me/#{Base64.encode64(data).gsub(/\n/, '')}]
=begin
+-[ COMMAND SETTINGS ]------------+
<?xml version="1.0" encoding="UTF-8"?>
<seestyle>
<mode id="SEEMode.Javascript">
<style id="_Default"
color="#657b83" font-style="normal" font-weight="normal" background-color="#fdf6e3" />
<style id="/Javascript/Keywords"
color="#859900" font-style="normal" font-weight="normal" />
<style id="/Javascript/this"
color="#586e75" font-style="normal" font-weight="normal" />
<style id="/Javascript/Numbers"
@davidchambers
davidchambers / nginx.conf
Created July 12, 2011 16:37
Hashify nginx config
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
@davidchambers
davidchambers / hashify
Created October 13, 2011 06:29
Command line utility for publishing documents on hashify.me (and docco.hashify.me!)
#!/usr/bin/env ruby
# Publish documents on the internets!
# -----------------------------------
# Copyright (c) 2011, David Chambers.
# * * * * * * * * * * * * * * * * * *
require 'base64'
require 'net/http'
@davidchambers
davidchambers / to_hash.coffee
Created April 1, 2012 06:02
Dictionary comprehensions in CoffeeScript
to_hash = (pairs) ->
hash = {}
hash[key] = value for [key, value] in pairs
hash
# usage:
to_hash ([n, n * n] for n in [0..5]) # {0:0, 1:1, 2:4, 3:9, 4:16, 5:25}
escapeRegExpChars = (string) ->
# Copied from https://github.com/slevithan/XRegExp.
string.replace /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'
deconstructRegExp = (regexp) ->
/// ^/(.+)[/]([gimy]*)$ ///.exec regexp
# Create a pattern like the one provided, but with a start of string
# anchor:
#
Action
------------------------------------
Release Publish Configure
Project name on GitHub on npm Travis CI
------------------------------------------------------------
airwaves (*) (*) (*)
an.hour.ago (*) (*) (*)
Base64.js (*) (*) (*)
CANON (*) (*) (*)
doctest (*) (*) ( )
@davidchambers
davidchambers / symlink
Created June 14, 2012 20:37
I get the arguments to `ln -s` round the wrong way at least half the time. This simple script makes this relatively common operation easy to get right.
@davidchambers
davidchambers / languages.coffee
Created July 1, 2012 20:58
Attach language codes to request object
(req, res) ->
# Attach language codes to request object.
h = req.headers['accept-language']
req.languages = h and (/[^\s;-]+/.exec(l)[0] for l in h.split ',') or []
@davidchambers
davidchambers / paths.coffee
Created September 18, 2012 03:33
Problem: Determine all the paths for a given node.
# Problem: Determine all the paths for a given node.
#
# A
# / \
# / \
# B C
# / \ \
# / \ \
# C D D
# \