Skip to content

Instantly share code, notes, and snippets.

View nertzy's full-sized avatar
🤪

Grant Hutchins nertzy

🤪
View GitHub Profile
gem "texticle", :git => "http://github.com/tenderlove/texticle.git"
@nertzy
nertzy / case_statement_builder.rb
Created November 5, 2010 19:30
Quick way to build a case statement in SQL using ActiveRecord
module CaseStatementBuilder
class << self
delegate :connection, :to => ActiveRecord::Base
def build(lhs, values_hash, default_value)
when_expressions = values_hash.sort.map do |rhs, value|
"WHEN #{lhs} = #{connection.quote(rhs)} THEN #{connection.quote(value)}"
end.join(" ")
"CASE #{when_expressions} ELSE #{connection.quote(default_value)} END"
>> def foo; __method__; end
=> nil
>> foo
=> :foo
>> alias bar foo
=> nil
>> bar
=> :foo
>> method(:bar)
=> #<Method: Object#bar>
@nertzy
nertzy / hash_test.rb
Created June 28, 2012 00:06
Faster stringify_keys and symbolize_keys
require_relative "lib/active_support/core_ext/hash/keys"
require "benchmark"
[1, 10, 100, 1_000, 10_000, 100_000, 1_000_000].each do |count|
puts
puts '*' * 80
puts "Hash with #{count} entries"
puts
strings = (1..count).map(&:to_s)
@nertzy
nertzy / README
Created December 9, 2012 22:32 — forked from symposion/README
Convert OS X Keychain exported entries into logins for 1Password import
These two files should help you to import passwords from mac OS X keychains to 1password.
Assumptions:
1) You have some experience with scripting/are a power-user. These scripts worked for me
but they haven't been extensively tested and if they don't work, you're on your own!
Please read this whole document before starting this process. If any of it seems
incomprehensible/frightening/over your head please do not use these scripts. You will
probably do something Very Bad and I wouldn't want that.
2) You have ruby 1.9.2 installed on your machine. This comes as standard with Lion, previous
versions of OS X may have earlier versions of ruby, which *may* work, but then again, they
@nertzy
nertzy / gist:5286543
Last active December 15, 2015 16:08
git diff config/initializers/simple_form.rb
diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index 553961b..e3f8d09 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -1,83 +1,126 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
- # Components used by the form builder to generate a complete input. You can remove
- # any of them, change the order, or even add your own components to the stack.
- # config.components = [ :placeholder, :label_input, :hint, :error ]
@nertzy
nertzy / show-remote-branches.sh
Last active December 28, 2015 10:39
Show remote git branches, how old they are, and who made the last commit
origin/staging 22 hours ago Grant Hutchins and Rick Reilly
origin/restrict_to_reports 2 days ago Grant Hutchins and Rick Reilly
origin/master 3 days ago Grant Hutchins
origin/HEAD 3 days ago Grant Hutchins
staging/master 3 days ago Grant Hutchins
origin/provide_feedback_pagination 7 days ago Dave Goddard
origin/provide_feedback 8 days ago Dave Goddard and Paul Meskers
origin/provide_feedback_check_manager 8 days ago Dave Goddard
origin/reply_to_emails 8 days ago Dave Goddard and Paul Meskers
origin/experimental-js 2 weeks ago Brent Wheeldon and Nigel Pepper
@nertzy
nertzy / Gemfile
Created December 12, 2014 20:31
Rails bug
source "https://rubygems.org"
gem "activerecord", github: "rails"
gem "sqlite3"
± gh |master ✓| → bundle --verbose
HTTP GET https://rails-assets.org/api/v1/dependencies
――― ERROR REPORT TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――
- What did you do?
- What did you expect to happen?
- What happened instead?
Error details
Java::JavaLang::RuntimeException: Could not generate DH keypair
@nertzy
nertzy / callgrind_profiler.rb
Last active August 29, 2015 14:20
CallgrindProfiler
require 'jruby/profiler'
require 'jruby/profiler/callgrind_printer'
module CallgrindProfiler
def callgrind
unless JRuby.runtime.instance_config.is_profiling?
STDERR.puts 'Profiling not enabled, re-run with `ruby --profile.api`'
return
end