Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
@dnch
dnch / gist:1643764
Created January 19, 2012 23:42
Ode To The Splat Operator
def test_exclusions(str)
exclusions = ['a', /^I-/]
case str
when *exclusions then
"Excluded"
else
"Accepted"
end
end
@dnch
dnch / derp.js
Created July 17, 2012 02:12
Uh...
(function() {
$(function() {
return $('a[data-toggle="tab"]').on('shown', function(e) {
var persistentTabs;
persistentTabs = localStorage.getObject("persistentTabs") || {};
persistentTabs[location.pathname] = e.target.hash;
return localStorage.setObject("persistentTabs", persistentTabs);
});
});
@dnch
dnch / gist:3393069
Created August 19, 2012 07:09
NOPE NOPE NOPE
#!/usr/bin/env ruby -wKU
str = "Herp"
case str
when "Herp"
when "Derp"
puts "This will never, ever work the way you want it to. Ruby ain't PHP."
end
@dnch
dnch / gist:3935667
Created October 23, 2012 00:01
My ZSH theme
ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_CLEAN=" %F{46}±"
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{196}±"
function codeape_prompt {
# set up the biggest possible middle padding we'd need
(( spare_width = ${COLUMNS} ))
prompt=" "
@dnch
dnch / gist:3944389
Created October 24, 2012 06:30
.zshrc
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set to the name theme to load.
# Look in ~/.oh-my-zsh/themes/
export ZSH_THEME="codeape"
# Set to this to use case-sensitive completion
# export CASE_SENSITIVE="true"
arr = [:a, :b, :c]
obj = :d
[*arr] # => [:a, :b, :c]
[*obj] # => [:d]
@dnch
dnch / gist:5062136
Created March 1, 2013 02:51
uh, wtf?
> gem install rails --version=4.0.0.beta1 --verbose
HEAD http://rubygems.org/prerelease_specs.4.8.gz
302 Moved Temporarily
HEAD http://production.s3.rubygems.org/prerelease_specs.4.8.gz
304 Not Modified
HEAD http://rubygems.org/specs.4.8.gz
302 Moved Temporarily
HEAD http://production.s3.rubygems.org/specs.4.8.gz
304 Not Modified
GET http://rubygems.org/quick/Marshal.4.8/rdoc-3.12.2.gemspec.rz
module HostnameHelper
def using_hostname(hostname)
old_host = Capybara.default_host
Capybara.default_host = "http://#{hostname}"
yield
Capybara.default_host = old_host
end
end
# app/models/foo.rb
# Keep in mind, this doesn't even factor in TimeZones.
class Foo
# Including this line gives your model two virtual
# attributes - `date` and `time` - which you can use as
# methods in your form_for / f.text_field calls, etc
attr_writer :date, :time
# returns the date component of starts_at, to ensure
@dnch
dnch / gist:5546857
Last active December 17, 2015 03:58
Guardfile + Required Gems
logger level: :warn
rspec_opts = {
zeus: true,
binstubs: true,
all_on_start: false,
cli: "--order rand:$RANDOM"
}
guard :rspec, rspec_opts do