Skip to content

Instantly share code, notes, and snippets.

@timblair
timblair / markdown.css
Created August 25, 2011 15:57
Simple Markdown CSS
/* Based on http://kevinburke.bitbucket.org/markdowncss/ */
body{
margin: 0 auto;
font-family: Georgia, Palatino, serif;
color: #444444;
line-height: 1;
max-width: 960px;
padding: 30px;
}
@timblair
timblair / tag_release
Created March 16, 2012 10:03
A helper script to manually tag a code release.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Please supply a commit SHA to tag."
exit 1
fi
git tag -af deployed $1 -m "Deployed to production." && git push origin tag deployed
@timblair
timblair / gist:2397242
Created April 16, 2012 09:26
Disqus error code
d652de5c2ad34f4eb0ac89709559309c$0291b4935aa804fdb72d9da9a96ed80c
@timblair
timblair / json-encoding.cfm
Created June 26, 2012 15:19
Test case for ColdFusion JSON serialisation/deserialisation
<cfsetting enablecfoutputonly="true">
<cfset variables.test_cases = {
raw_numeric = 123,
raw_float = 123.456,
zero_numeric = 000,
prefixed_numeric = 000123,
prefixed_float = 000123.456,
string_numeric = "123",
string_float = "123.456",
@timblair
timblair / JSON.cfc
Created July 17, 2012 10:38
JSON encoding wrapper to handle CF 9.0.2's failure at serialising strings comprised of all zeroes.
component {
public string function encode(required any data) {
var json = serializeJSON(arguments.data);
if (!find("00", json)) { return json; }
if (left(json, 2) == "00") { json = '"#json#"'; } // just a simple value
// value in a structure
if (find('":00', json)) { json = rereplace(json, '[^\\]":([0]+)', '":"\1"', "ALL"); }
// value in an array (beginning, end, middle)
if (find('[00', json)) { json = rereplace(json, '[^\\]?\[([0]+)', '["\1"', "ALL"); }
if (find('00]', json)) { json = rereplace(json, ',([0]+)\]', ',"\1"]', "ALL"); }
@timblair
timblair / ayb12.md
Created November 23, 2012 12:56
Notes from All Your Base 2012, 2012-11-23

AYB12

Alvin Richards: MongoDB

  • Trade-off: scale vs. functionality. MongoDB tries to have good functionality and good scalability.
  • Auto-sharding to maintain equilibrium between shards
  • Scalable datastore != scalable application: use of datastore may still be non-scalable (e.g. many queries across all shards)
  • Get low latency by ensuring shard data is always in memory: datastore
cd /tmp
brew update
brew upgrade ruby-build
rbenv install 2.0.0-p0
rbenv shell 2.0.0-p0
curl -fsSL curl.haxx.se/ca/cacert.pem -o "$(ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE')"
gem install bundler --pre # Successfully installed bundler-1.3.0.pre.8
gem install rails # Successfully installed rails-3.2.12
rails new test-app
cd test-app
@timblair
timblair / install.sh
Last active December 19, 2015 07:29
Quick setup of Bundler, rbenv and latest Ruby.
# Run with:
#
# curl -fsSL https://gist.github.com/timblair/5919255/raw | bash
$( which brew >/dev/null ) || ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew update
$( which rbenv >/dev/null) || brew install rbenv --HEAD
$( which ruby-build > /dev/null ) || brew install ruby-build --HEAD
brew upgrade ruby-build
@timblair
timblair / lemon-drizzle.md
Created August 19, 2013 08:42
Gluten-Free Lemon Drizzle Cake

Gluten-Free Lemon Drizzle Cake

This will make enough for a 2lb loaf tin. If you want something smaller, just use 2 medium eggs and halve the rest of the ingredients.

Sponge

  • 3 large eggs
  • 180g Gluten-free self-raising flour
  • 180g Caster sugar
  • 180g Unsalted softened butter
@timblair
timblair / number_converter.rb
Last active December 29, 2015 20:09
Counting from 1 to 1,000,000 in words. Actually caters for numbers up to 10^36-1 (using the short scale) if you really need to...
class NumberConverter
UNITS = [nil] + %w{ one two three four five six seven eight nine ten eleven
twelve thirteen fourteen fifteen sixteen seventeen eightteen nineteen }
TENS = %w{ twenty thirty forty fifty sixty seventy eighty ninety }
SCALE = %w{ hundred thousand } +
%w{ m b tr quadr quint sext sept oct non dec }.map { |i| i + "illion" }
# cache some lookups for a ~25% speed increase
@@cache ||= {}