Skip to content

Instantly share code, notes, and snippets.

Avatar stephancom

View GitHub Profile
stephancom / footer.html.slim
Created Jul 1, 2014
footer trick for year
View footer.html.slim
stephancom / 5x5.rb
Created Jul 25, 2014
blacksmith gunpowdery
View 5x5.rb
# (c) 2007
# A program to impress Grace
# Finds five words of five letters using all unique letters
Goodwords = []
CompareMatrix = {}
# returns true if any letters are shared between two strings
def has_common_letters?(a, b)
View mime_types_incl_office_2007.rb
# I realize this declaration looks kind of crazy, but I find it
# way more readable and DRY than a straight list would be
# optionally add octet-stream to this list - evaluate security risk of any before doing so
CONTENT_TYPES = %w(gif jpg jpe jpeg pjpeg bmp png pdf x-png tiff).map { |st| "image/#{st}"} +
%w( msword pdf).map { |st| "application/#{st}"} +
[ "text/plain" ] +
# Don't blame me, blame Microsoft - this is for Office 2007.
# It makes a lot of MIME types that we shouldn't actually make,
# but that seems pretty harmless.
# original list from
stephancom / unobtrusive_rollover.js
Created Jun 4, 2011
unobtrusive rollover coffeescript vs original
View unobtrusive_rollover.js
// purpose of script is to handle rollovers unobtrusively, e.g.
// <img src='original.png' data-rollover='rolled.png'>
$('img[data-rollover]').live('mouseover', function(){
if($(this).data('rollover-original') == null) {
$(this).data('rollover-original', $(this).attr('src'))
$(this).attr('src', $(this).data('rollover'))
}).live('mouseout', function(){
stephancom / Gemfile
Created Jul 28, 2011
Example of problem with rspec 2 + rails 3.1 + ruby 1.9.2 + factory_girl
View Gemfile
gem 'rails', '3.1.0.rc4'
group :development, :test do
gem 'rspec-rails', '~> 2.6.1'
group :test do
gem 'factory_girl_rails'
gem 'rspec'
stephancom / GooglePie.rb
Created Dec 19, 2011
Simple code to generate a Google Charts pie chart url
View GooglePie.rb
# values is expected to be hash whose keys are the names of the pie segments
def chart_url(values, size = '300x125')
colors = %w(FF9900 324C8E ff0000 FF69B4 1E90FF 9ACD32 DAA520 40E0D0)
basic_chart = {:chs => size, :cht => 'p3', :chco => colors.join('|')}
chart_params = basic_chart.merge( :chd => 't:'+values.values.join(','),
:chdl => { |f| "#{f} (#{values[f]})"}.join('|'), :chtt =>'name of chart')
stephancom / generic_fields.js
Created Jan 3, 2012
Generic Repeatable Fields
View generic_fields.js
$('a[data-add-nested]').live('click', function(){
var regexp = new RegExp($(this).data('add-nested-replace'), "g")
target = $(this).data('add-nested-target')
new_stuff = $($(this).data('add-nested').replace(regexp, (new Date).getTime())).hide()
if(!target || target == 'before') {
} else if(target == 'after') {
} else {
View Gemfile
source ""
gem "devise", git: "git://", branch: "rails4"
gem "devise-i18n", "~> 0.6.5"
gem "jbuilder", "~> 1.0.1"
gem "jquery-rails"
gem "haml", "~> 4.0.1"
gem "mongoid", git: "git://", branch: "master"
gem "simple_form", "~> 3.0.0.beta1"
gem "rails", "4.0.0.beta1"
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone
stephancom /
Last active Dec 16, 2015
TDD. Pending tests. Get cracking, bitches.
describe "A robot", ->
it "may not injure a human being or, through inaction, allow a human being to come to harm."
it "must obey the orders given to it by human beings, except where such orders would conflict with the First Law."
it "must protect its own existence as long as such protection does not conflict with the First or Second Laws."
You can’t perform that action at this time.