Skip to content

Instantly share code, notes, and snippets.

Benjamin Fleischer bf4

View GitHub Profile
@bf4
bf4 / comment.md
Created Jul 8, 2014
invalid %-encoding error in application for malformed uri
View comment.md
@bf4
bf4 / Gemfile
Created Jul 2, 2013
Rails lograge and logstash request logging
View Gemfile
gem 'lograge' # more readable logs
gem 'logstash-event' # for logstash json format
gem 'mono_logger' # threadsafe logging
@bf4
bf4 / polymorphic_many_to_many_in_rails.md
Last active Nov 26, 2018
a polymorphic many-to-many association in Rails
View polymorphic_many_to_many_in_rails.md

This was my solution for a polymorphic many-to-many association

class ItemCountry < ActiveRecord::Base
  belongs_to :locatable, :polymorphic => true
  belongs_to :country
  # fields are :locatable_id, :locatable_type, :country_id
end

class Title < ActiveRecord::Base
  has_many :countries, :through => :item_countries, :as => :locatable
@bf4
bf4 / bin-squash_migrations
Created Nov 12, 2015
Squash Rails migrations in this one easy step
View bin-squash_migrations
#!/usr/bin/env bash
git ls-files db/migrate/*.rb | sort | tail -1 | \
ruby -e "schema_version=STDIN.read[/\d+/]; init_schema=%(db/migrate/#{schema_version}_init_schema.rb);
%x(git rm -f db/migrate/*.rb;
mkdir db/migrate;
git mv db/schema.rb #{init_schema};
rake db:migrate;
git add db/schema.rb; git commit -m 'Squashed migrations')"
@bf4
bf4 / rails32_http_patch_support.rb
Last active Jun 4, 2018
HTTP PATCH support in Rails 3.2
View rails32_http_patch_support.rb
# Rails 3.2 support for HTTP PATCH.
fail "Remove this patch" if Rails::VERSION::MAJOR > 3
# see http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/
# https://github.com/rails/rails/pull/505
# Be very conservative not to monkey-patch any methods until
# the relevant files are loaded.
ActiveSupport.on_load(:action_controller) do
ActionDispatch::Request.instance_eval do
# Is this a PATCH request?
@bf4
bf4 / interview_questions.txt
Last active May 28, 2018
Interview questions
View interview_questions.txt
Good Interview Questions
"Give Him/Her the opportunity to impress you, and maybe even give you a revelation"
Ask open-ended questions, see
---> attitudes about the topic
---> how s/he thinks
---> what s/he's been thinking about lately
Q: Compare Ruby to another language.
@bf4
bf4 / jdbc_sample.rb
Created Apr 18, 2018 — forked from rwjblue/jdbc_sample.rb
Convert JDBC ResultSet into Ruby Hash with JRuby
View jdbc_sample.rb
require './lib/adsjdbc-10.10.0.28.jar'
java_import java.sql.Driver
java_import java.sql.DriverManager
java_import 'com.extendedsystems.jdbc.advantage.ADSDriver'
class AdsAdapter
def initialize(connect_string)
@connect_string = connect_string
end
@bf4
bf4 / errors.html.erb
Last active Feb 18, 2018
Rails Router
View errors.html.erb
<% if Rails.env.development? || Subdomain.new.internal_ip_user?(request) %>
More verbose errors
<% end %>
@bf4
bf4 / Gemfile
Last active Nov 11, 2017
Download my destroyallsoftware videos
View Gemfile
# A sample Gemfile
source "https://rubygems.org"
gem 'mechanize'
You can’t perform that action at this time.