Skip to content

Instantly share code, notes, and snippets.

Jacob Burenstam buren

Block or report user

Report or block buren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@buren
buren / gist:6961940
Last active Jun 1, 2017
Custom database for rails branch
View gist:6961940

Custom database for Rails branch

(Below is an example with MySQL)

Customize config/database.yml to handle multiple databases.

<%
  # How to setup a custom database for a branch
  branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
  suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : "_development"
@buren
buren / zsh-git-prompt
Last active Aug 29, 2015
zsh-git-prompt
View zsh-git-prompt
# Shameless steal from http://askubuntu.com/a/85111
# git branch in zsh-prompt
echo '
autoload -Uz vcs_info
precmd () { vcs_info }
setopt prompt_subst
PS1="\$vcs_info_msg_0_$PS1"' >> ~/.zshrc
@buren
buren / RetryableCall.rb
Created Apr 16, 2014
Retry given block until response is not nil or max_retries is reached
View RetryableCall.rb
class RetryableCall
DEFAULT_OPTIONS = {
sleep: 0.5,
max_retries: 5
}
def self.perform options = {}, &block
new(options).perform(&block)
end
View keybase.md

Keybase proof

I hereby claim:

  • I am buren on github.
  • I am buren (https://keybase.io/buren) on keybase.
  • I have a public key whose fingerprint is EBA4 FF7D C0DF C205 02B8 9A24 C85F B75E 410E 4CC4

To claim this, I am signing this object:

@buren
buren / Singelton.java
Created May 7, 2014
Simple Java Singelton Example
View Singelton.java
package utils;
import java.net.URL;
public class Enduro {
private static Enduro ourInstance = new Enduro();
public static Enduro getInstance() {
return ourInstance;
}
@buren
buren / response_follow_redirect.rb
Last active Aug 8, 2016
Get response given an URL and follow redirects
View response_follow_redirect.rb
require 'uri'
require 'net/http'
require 'openssl'
MAX_ATTEMPTS = 2
# Get response given an URL and follow redirects
def self.url_response(uri)
found = false
url = URI.parse(uri)
@buren
buren / gem_console.rb
Created Oct 5, 2014
Put this in the Gem's Rakefile.
View gem_console.rb
# https://gist.github.com/buren-trialbee/f51c6d37ea96618bcc49
task :console do
require 'irb'
require 'irb/completion'
require 'my_gem'
ARGV.clear
IRB.start
end
@buren
buren / meta_ruby.rb
Created Oct 22, 2014
Simple Ruby meta programming example
View meta_ruby.rb
class Meta
def self.make_method(meth_name)
define_method meth_name do |adjective|
puts "#{meth_name} is a #{adjective} method name"
end
end
def method_missing(meth, *args, &block)
puts "Method #{meth} is not defined on this class"
self.class.make_method(meth)
@buren
buren / rails_web_console_param.rb
Last active Feb 13, 2016
Attach a rails web console to any page by adding ?web_console=
View rails_web_console_param.rb
# config/initializers/web_console.rb
WebConsoleBeforeAction = ->(controller) do
controller.console if controller.params[:web_console]
end
ApplicationController.before_action(WebConsoleBeforeAction) if defined?(WebConsole) && Rails.env.development?
# NOTE:
# For security reasons only do this in development.
@buren
buren / rails_strong_parameters_refactor.rb
Last active Apr 10, 2017
A simple pattern to refactor permitted params for Rails with StrongParameters included.
View rails_strong_parameters_refactor.rb
# Rails StrongParameters refactor
#
# Inspired by Ryan Bates's Screencast #371
# http://railscasts.com/episodes/371-strong-parameters
#
# A simple pattern to refactor permitted params for Rails with StrongParameters.
# app/models/author.rb
class Author < ActiveRecord::Base
validates_presence_of :name, :birth_date
You can’t perform that action at this time.