Skip to content

Instantly share code, notes, and snippets.

Benjamin Fleischer bf4

View GitHub Profile
bf4 / clock
Created Apr 3, 2019
Script to run only in the specified minute range
View clock
#!/usr/bin/env bash
# Created by Benjamin Fleischer 2019
# Distributed under the MIT license
# Usage:
# MINUTE_RANGES="0...10 30...40" ./clock echo 'we done it'
# DEBUG=true MINUTE_RANGES="0...10 30...40" ./clock echo 'we done it'
main() {
local ranges
bf4 /
Created Jul 8, 2014
invalid %-encoding error in application for malformed uri
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 /
Last active Nov 26, 2018
a polymorphic many-to-many association in Rails

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

class Title < ActiveRecord::Base
  has_many :countries, :through => :item_countries, :as => :locatable
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 "[/\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 / 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
# 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 / 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 / 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-'
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
bf4 / errors.html.erb
Last active Feb 18, 2018
Rails Router
View errors.html.erb
<% if Rails.env.development? || %>
More verbose errors
<% end %>
You can’t perform that action at this time.