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 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
# https://github.com/my-company/my-project/branches/stale?page=7
buttons = document.getElementsByClassName("js-branch-delete-target text-red");
for(var i = 0; i < buttons.length; i++)
buttons[i].click();
@jjb
jjb / concat.rb
Last active Mar 8, 2019
Ruby String Interpolation vs. Concatenation performance benchmark
View concat.rb
t = Time.now
a = []
10_000_000.times do
a << "a" + " " + "b"
end
puts Time.now.to_f - t.to_f
View rails 5.0 vs 5.1 default primary key in postgres.md

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"
    end
  end
View how to make a handy dandy alert thingy.md

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
jjb / file.md
Created Feb 4, 2018
Active Record Connection Management in Rails 5.1 or lower
View file.md
@jjb
jjb / sleep.coffee
Created Jan 18, 2018
Sleep in coffeescript
View sleep.coffee
sleep = (ms)->
date = new Date()
loop
break if (new Date())-date > ms
# from https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
# 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
jjb / rails-timezones.md
Last active Jan 12, 2018
How to access the list of all timezones which are recognized by Rails
View rails-timezones.md

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:

  • ActiveSupport::TimeZone.all.map(&:tzinfo).map(&:canonical_identifier) (150)
  • TZInfo::Timezone.all_identifiers (606)
@jjb
jjb / config.ru
Created Oct 17, 2017
How to log file descriptor count in a rails or rack application
View config.ru
require_relative 'config/environment'
class FileDescriptorLogger
def initialize(app)
@app = app
end
def call(env)
if 1000==rand(1001)
unclosed_files = 0
You can’t perform that action at this time.