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 / accounts_controller.rb
Created October 30, 2013 01:27
Playing with a way of setting UI-specific default values in forms.
class AccountsController < ApplicationController
include Authenticated
before_action :populate_default_attributes, only: %i(new)
expose :customer
expose :accounts, ancestor: :customer
expose :account
# def new omitted, thanks to DecentExposure...
# suffers the obvious problem that Time.now is evaluated at load, not on-call...
def prior_to(issue_date = Time.now)
where("issue_date < ?", issue_date).order(:issue_date).reverse_order
end
@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
# 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
module HostnameHelper
def using_hostname(hostname)
old_host = Capybara.default_host
Capybara.default_host = "http://#{hostname}"
yield
Capybara.default_host = old_host
end
end
@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
arr = [:a, :b, :c]
obj = :d
[*arr] # => [:a, :b, :c]
[*obj] # => [:d]
@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"
@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: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