Skip to content

Instantly share code, notes, and snippets.

View nz's full-sized avatar

Nick Zadrozny nz

View GitHub Profile
@nz
nz / gist:8852934
Created February 6, 2014 21:35
Rails Concern to create a bunch of downcased getter methods
module Downcaseable
extend ActiveSupport::Concern
module ClassMethods
def downcase_field(*names)
Array(names).flatten.each do
class_eval %Q(
def #{name}_eval
send(:#{name}).try(:downcase)
end
)
@nz
nz / keybase.md
Created March 13, 2014 17:47
keybase.md

Keybase proof

I hereby claim:

  • I am nz on github.
  • I am nz (https://keybase.io/nz) on keybase.
  • I have a public key whose fingerprint is 9B6A A415 178D EE9F A265 B3E9 DF54 6078 26E3 B167

To claim this, I am signing this object:

@nz
nz / irbrc-rails-env.rb
Created May 29, 2014 17:56
My ~/.irbrc with the Rails app name and environment. A useful bit of paranoia to help prevent operator errors.
if defined?(Rails) && Rails.env
reset = "\e[0m"
color = case Rails.env
when 'development', 'test'
"\e[36m" # cyan
else
"\e[31m" # magenta
end
ES_URL = urlparse(os.environ.get('BONSAI_URL') or 'http://127.0.0.1:9200/')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': ES_URL.scheme + '://' + ES_URL.hostname + ':80',
'INDEX_NAME': 'haystack',
},
}
@nz
nz / git-helper-functions.sh
Created October 30, 2008 05:52
Some shell functions I use to help me effortlessly do clean rebasing and pushing in git.
function rebase {
if [[ $1 == "" ]]; then master='master'; else master=$1; fi
branch=`git branch | grep \* | awk '{print $2}'` &&
git checkout $master && git pull && git rebase $master $branch
}
function push {
if [[ $1 == "" ]]; then master='master'; else master=$1; fi
branch=`git branch | grep \* | awk '{print $2}'` &&
rebase $master && git checkout $master && git merge $branch && git push &&
# 0. Do all your work in a local branch, preferably named loosely for the feature you're working on.
git checkout -b work
# 1. Make sure all your changes are committed.
git commit -m "changes to a local branch"
# 2. Update the master branch, pulling down the latest code from the rest of the team
git checkout master
git pull
@nz
nz / autotest.rb
Created October 29, 2008 16:46
My autotest config file. With colored Growl support for Test::Unit and RSpec. Save in ~/.autotest
require 'autotest/redgreen'
Autotest.send(:alias_method, :real_make_test_cmd, :make_test_cmd)
Autotest.send(:define_method, :make_test_cmd) do |*args|
real_make_test_cmd(*args).sub('test/unit', %[rubygems -e "require 'redgreen'"])
end
Autotest.add_hook :initialize do |autotest|
autotest.add_exception(/^\.\/vendor/)
autotest.add_exception(/\.svn/)
// The search query for this was my address here in Bremerton. This is the result.
{"places":
{"place":
[{ "woeid":2368481,
"placeTypeName":"Town",
"placeTypeName attrs":{"code":7},
"name":"Bremerton",
"country":"United States",
"country attrs":{"type":"Country","code":"US"},
"admin1":"Washington",
class GatheringPlan < ActiveRecord::Base
belongs_to :roov
belongs_to :gathering_idea
has_many :participations, :class_name => "GatheringPlanParticipation"
has_many :participants, :through => :participations, :source => :user
has_many :votes, :class_name => "GatheringPlanVote"
has_many :suggestions, :through => :votes, :source => :suggestion
end
[4294967295,4294967295].to_yaml
#=> "--- \n- 4294967295\n- 4294967295\n"
[4294967295,4294967295].to_yaml.size
#=> 31
[4294967295,4294967295].to_json
#=> "[4294967295,4294967295]"
[4294967295,4294967295].to_json.size
#=> 23