Skip to content

Instantly share code, notes, and snippets.

Avatar

stephan.com stephancom

View GitHub Profile
@stephancom
stephancom / footer.html.slim
Created Jul 1, 2014
footer trick for year
View footer.html.slim
@stephancom
stephancom / 5x5.rb
Created Jul 25, 2014
blacksmith gunpowdery
View 5x5.rb
#!/usr/bin/ruby
# (c) 2007 stephan.com
# 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(vnd.ms-excel vnd.ms-powerpoint 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 http://www.bram.us/2007/05/25/office-2007-mime-types-for-iis/
@stephancom
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'>
$(function(){
$('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
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'
end
group :test do
gem 'factory_girl_rails'
gem 'rspec'
end
@stephancom
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 => values.keys.map { |f| "#{f} (#{values[f]})"}.join('|'), :chtt =>'name of chart')
"http://chart.apis.google.com/chart?#{chart_params.to_query}"
end
@stephancom
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') {
new_stuff.insertBefore($(this))
} else if(target == 'after') {
new_stuff.insertAfter($(this))
} else {
new_stuff.appendTo(target)
View Gemfile
source "https://rubygems.org"
gem "devise", git: "git://github.com/plataformatec/devise.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://github.com/mongoid/mongoid.git", branch: "master"
gem "simple_form", "~> 3.0.0.beta1"
gem "rails", "4.0.0.beta1"
View creating-edgerails-app.sh
# 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
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 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 https://github.com/rails/rails.git
@stephancom
stephancom / Robots_spec.coffee
Last active Dec 16, 2015
TDD. Pending tests. Get cracking, bitches.
View Robots_spec.coffee
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.