Skip to content

Instantly share code, notes, and snippets.

@jcromartie
jcromartie / navbar.rb
Last active December 14, 2015 15:38
Convert one super-sized (ideally iPad landscape @2x) image into the slew of images required to implement a non-repeating nav bar background at all sizes and resolutions for iOS.
#!/usr/bin/env ruby
# Takes one Retina iPad landscape nav bar image, and creates all of
# the requisite sizes for use on each device and orientation. Crops
# part of the image for iPhone portrait size.
#
# This is ONLY necessary for non-repeating or non-resizable (i.e. with
# cap insets) nav bar images. This program is an illustration of why
# you should discourage your designers from doing this.
#
@jcromartie
jcromartie / spark.rb
Created November 15, 2011 13:37
Sparklines in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }
(ns trie.core
(:refer-clojure :exclude (merge contains?))
(:use clojure.test))
;; some generic trie (prefix tree) functions
(def box list)
(defn trie
"Returns trie for single seq s"
(ns markov
(use clojure.test))
;; ---------- basic markov chain utils and API ----------
(defn n-grams
"Partition seq s into all sequential groups of n items"
[n s]
(partition n 1 (repeat nil) s))
@jcromartie
jcromartie / gsd.sh
Created May 4, 2011 15:40
Elegant Bash-based Get-Shit-Done script
#!/usr/bin/env bash
# edit this list, or set GSD_SITES to add your custom sites
SITES="$GSD_SITES reddit.com forums.somethingawful.com somethingawful.com digg.com break.com news.ycombinator.com infoq.com bebo.com twitter.com facebook.com blip.com youtube.com vimeo.com delicious.com flickr.com friendster.com hi5.com linkedin.com livejournal.com meetup.com myspace.com plurk.com stickam.com stumbleupon.com yelp.com slashdot.com"
HOSTFILE="/etc/hosts"
if [ ! -w $HOSTFILE ]
then
echo "cannot write to $HOSTFILE, try running with sudo"