Skip to content

Instantly share code, notes, and snippets.

View robhurring's full-sized avatar
🍻
cheers

Rob Hurring robhurring

🍻
cheers
View GitHub Profile
@robhurring
robhurring / git-cleanup
Created June 24, 2014 19:47
Cleans up branches merged into "dev" from your local repo (except current branch, dev, and master)
#!/usr/bin/env sh
# IMPORTANT: exclude the current branch (*), master and dev branch. Add any other patterns here
# and do a --dry-run if you're unsure
to_prune=$(git branch --merged dev | grep -v '\*\|master\|dev')
function show_help {
echo Usage: $(basename $0)
echo " -n [--dry-run] Print branches that would be removed"
}
@robhurring
robhurring / db.rake
Last active August 29, 2015 13:58
Rake task to sync heroku database locally
namespace :db do
desc 'sync with prod database'
task :sync, :backup_id do |t, args|
dump_file = Rails.root.join('tmp', 'latest.dump')
db_configs = YAML.load_file(Rails.root.join('config', 'database.yml'))
db_config = db_configs[Rails.env]
commands = [
"heroku pgbackups:capture --expire",
"curl -o #{dump_file} \`heroku pgbackups:url #{args[:backup_id]}\`",
@robhurring
robhurring / base_form.rb
Last active August 29, 2015 13:57
Rails Form Models
# app/forms/base_form.rb
class BaseForm
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
@robhurring
robhurring / README.md
Last active December 20, 2015 04:49
Angular weather service using openweathermap.org -- not fully tested. (uses gist: https://gist.github.com/robhurring/6074128)
@robhurring
robhurring / README.md
Last active March 3, 2016 11:58
Angular geolocation wrapper service
@robhurring
robhurring / .slate
Last active December 15, 2015 16:09
Bootstrap-like grid "framework" for slate window manager.
# add this to your ~/.slate file
# source our grid
source ~/.slate.grid if_exists
# use the grid to position windows
alias left-half move 0;0 ${span-6};${row-12}
alias right-half move ${push-6};0 ${span-6};${row-12}
alias top-left-quarter move 0;0 ${span-6};${row-6}
alias top-right-quarter move ${push-6};0 ${span-6};${row-6}
@robhurring
robhurring / README.md
Last active January 30, 2020 19:00
Override devise's TokenAuthenticatable strategy to use Authorization headers

This will allow you to use devise's TokenAuthenticatable strategy while passing your :auth_token in using HTTP Authorization headers instead of params.

You can check it out using

curl -H "Authorization: Token token=XXXXXX, option=1" -vv http://railsapp.dev/api/v1/endpoint.json

It should properly authenticate using the token as well as set request.env['token.options'] to {"options" => "1"}.

@robhurring
robhurring / custom_field_names.rb
Created January 2, 2013 17:28
small concern that allows you to override the field names for validation messages
# small concern that allows you to override the field names for validation messages
#
# Example:
#
# # without concern
# class User < ActiveRecord::Base
# validates :name, presence: true
# end
# # => "Name can't be blank"
#
@robhurring
robhurring / events_dispatcher.coffee
Created October 22, 2012 20:48
Simple bind/trigger mixin for javascript object
# this: https://gist.github.com/464257 in coffeescript, without the global stuff...
class EventsDispatcher
callbacks: {}
bind: (event_name, callback) ->
@callbacks[event_name] ||= []
@callbacks[event_name].push callback
@
trigger: (event_name, data) ->
@robhurring
robhurring / .gitconfig
Created March 4, 2012 17:30
Git Branch Time
# add this to your ~/.gitconfig under the alias section to allow things like "git brt"
[alias]
brt = branch-time