Skip to content

Instantly share code, notes, and snippets.

John Bachir jjb

Block or report user

Report or block jjb

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
View check the syntax in a tree of files.rb
lines = `find . -name '*.rb'`.split("\n")
problems = []
lines.each_slice(100) do |slice|
threads = []
slice.each do |l|
threads << do
result = `ruby -c #{l}`
if "Syntax OK" == result.strip
print "."
View how to instrument graphql ruby with scout.rb
class GraphqlController < ApplicationController
def create
ScoutApm::Transaction.rename("Graphql/" + params["_json"].first["operationName"])
View delete all branches on a github page.js
buttons = document.getElementsByClassName("js-branch-delete-target text-red");
for(var i = 0; i < buttons.length; i++)
jjb / concat.rb
Last active Mar 8, 2019
Ruby String Interpolation vs. Concatenation performance benchmark
View concat.rb
t =
a = []
10_000_000.times do
a << "a" + " " + "b"
puts - t.to_f
View rails 5.0 vs 5.1 default primary key in

5.0, no id specified

class SerialIdTest < ActiveRecord::Migration[5.0]
  def change
    create_table "test" do |t|
      t.integer "foo_id"
      t.string "foo_role"
View how to make a handy dandy alert

alert shell function

I keep mine in .zshrc. It could probably also be a standalone script named "alert" with chmod 755 (i think?) in ~/bin

# examples:
#   git push heroku master ; alert
#   bundle install ; alert
function alert {
  if (( $? == 0 )) then
View 🗳 How to get the vote out for Democrats 🗳.md
jjb /
Created Feb 4, 2018
Active Record Connection Management in Rails 5.1 or lower
jjb /
Created Jan 18, 2018
Sleep in coffeescript
sleep = (ms)->
date = new Date()
break if (new Date())-date > ms
# from
# as foretold in a million passionate comments by programmers 'round the world,
# using this in business logic in javascript is a bad idea. but it sometimes comes in
# handy when trying to experiment with something in dev (like if you want to simulate
# a timeout)
jjb /
Last active Jan 12, 2018
How to access the list of all timezones which are recognized by Rails

Time.find_zone! uses these two methods to look up strings:

  • ActiveSupport::TimeZone[time_zone]
  • TZInfo::Timezone.get(time_zone)

The lists they reference are these:

  • (150)
  • TZInfo::Timezone.all_identifiers (606)
You can’t perform that action at this time.