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
@sstarr
sstarr / Gemfile
Created October 18, 2012 06:09
Trouble updating GoCardless gem
source 'http://rubygems.org'
gem 'rails', '3.1.8'
# Gems used only for assets
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem 'bourbon' # a comprehensive library of sass mixins (see https://github.com/thoughtbot/bourbon)
@sstarr
sstarr / cpr.rb
Created January 9, 2013 20:11
Randomly generate a valid Danish CPR number (personnummer) for someone born between 20 and 50 years ago.
# Based on the format described in this Wikipedia article: http://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
"#{(20.years.ago - (0..11000).to_a.sample.days).strftime('%d%m%y')}-1#{'%03d' % (0..999).to_a.sample}"
# Regular expression to validate a CPR number
/\b(0[1-9]|[12]\d|3[01])(0[1-9]|1[0-2])\d{2}-\d{4}\b/
@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
@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
[
{
"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 / 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] [
@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"
# - 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 / 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/[email protected]
- wercker/postgresql
build:
steps:
# Taken from https://gist.github.com/pjvds/6008266
- script:
execute pathogen#infect()
syntax on
filetype plugin indent on
" 256 colours, please
set t_Co=256
" Dark twilight scheme
set background=dark
colorscheme twilight256