Skip to content

Instantly share code, notes, and snippets.

View sstarr's full-sized avatar
🏠
Working from home

Simon Starr sstarr

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am sstarr on github.
  • I am sstarr (https://keybase.io/sstarr) on keybase.
  • I have a public key whose fingerprint is 0A09 E5BF 1F8E 14F7 B703 53A7 77A7 384A BBA0 C7AE

To claim this, I am signing this object:

class Profile < ActiveRecord::Base
# ...
def format_twitter_url
unless self.twitter_url.blank? || self.twitter_url[/^https?:\/\//]
if self.twitter_url[/twitter\.com/i]
self.twitter_url = 'http://' + self.twitter_url
else
self.twitter_url = "https://twitter.com/#{self.twitter_url.sub(/@/, '')}"
execute pathogen#infect()
syntax on
filetype plugin indent on
" 256 colours, please
set t_Co=256
" Dark twilight scheme
set background=dark
colorscheme twilight256
@sstarr
sstarr / wercker.yml
Created December 19, 2013 14:37
A Wercker config for Ruby on Rails, Elasticsearch, Postgres and Qt (for capybara-webkit).
box: wercker/ruby
services:
- wunki/elasticsearch@0.0.1
- wercker/postgresql
build:
steps:
# Taken from https://gist.github.com/pjvds/6008266
- script:
# - A `Thing` can be 1% - 100% green
# - This is represented on the front end with a doughnut chart
# - The doughnut chart can't be generated since it's in an email
# - To get around this, we have 25 static doughnut images in increments of 4%
# This code takes the percentage and returns the relevant image.
# I'm sure there must be a more sensible way of doing this than using the
# world's longest switch statement. Any ideas?
@sstarr
sstarr / gist:6995732
Created October 15, 2013 17:54
Generate a random hex colour value in Ruby. WARNING: May produce colours offensive to people with eyes.
colour = "##{((0..6).map{rand(256).chr}*'').unpack('H*')[0][0,6]}"
# => "#9ee5a3"
@sstarr
sstarr / gist:6817534
Last active December 24, 2015 15:09
Split a date range into week long arrays with appropriate padding at the beginning and end to ensure that the weeks always start on Monday.
@from_date = Date.parse("1/10/2013")
@to_date = Date.parse("31/10/2013")
date_range = [*@from_date..@to_date]
prepend = (date_range)[0].wday # 2
append = (date_range)[-1].wday # 4
weeks = (date_range).unshift(*2..prepend).push(*2..append).each_slice(7).to_a
# [
# [0] [
[
{
"keys": ["escape"],
"command": "alternative_autocomplete",
"context": [
{"key": "num_selections", "operator": "equal", "operand": 1},
{"key": "overlay_visible", "operator": "equal", "operand": false},
{"key": "panel_visible", "operator": "equal", "operand": false},
{"key": "has_prev_field", "operator": "equal", "operand": false},
{"key": "has_next_field", "operator": "equal", "operand": false},
@sstarr
sstarr / countries.rb
Created April 6, 2013 13:01
Danish country names
["Ækvatorialguinea", "Afghanistan", "Albanien", "Algeriet", "Amerikansk Samoa", "Andorra", "Angola", "Anguilla", "Antarktis",
"Antigua og Barbuda", "Argentina", "Armenien", "Aruba", "Aserbajdsjan", "Australien", "Bahamas", "Bahrain", "Bangladesh",
"Barbados", "Belarus", "Belgien", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnien-Hercegovina", "Botswana",
"Bouvetø", "Brasilien", "Brunei", "Bulgarien", "Burkina Faso", "Burundi", "Côte d'Ivoire", "Cambodja", "Cameroun", "Canada",
"Caymanøerne", "Chile", "Cocosøerne (Keelingøerne)", "Colombia", "Comorerne", "Congo", "Cookøerne", "Costa Rica", "Cuba",
"Cypern", "Danmark", "De Amerikanske Jomfruøer", "De Britiske Jomfruøer", "De Forenede Arabiske Emirater",
"De Franske Besiddelser i Det Sydlige Indiske Ocean", "De Mindre Amerikanske Oversøiske Øer", "De Nederlandske Antiller",
"Den Centralafrikanske Republik", "Den Dominikanske Republik", "Den Tidligere Jugoslaviske Republik Makedonien",
"Det Britiske Territorium i Det Indiske Ocean", "Det Forene
@sstarr
sstarr / gist:4563999
Created January 18, 2013 11:17
Rails helper to generate Twitter Bootstrap icons
# Generate Twitter Bootstrap icons with a minimum of fuss
# Use in views like so:
# icon('pencil') => content_tag(:i, '', class: 'icon-pencil')
# icon('trash', 'icon-white huge') => content_tag(:i, '', class: 'icon-trash icon-white huge')
def icon(style, extra_class = nil)
content_tag(:i, '', class: "icon-#{style}" + (extra_class ? " #{extra_class}" : ''))
end