Skip to content

Instantly share code, notes, and snippets.

Avatar

John Bachir jjb

View GitHub Profile
View dns.rb
#!/usr/bin/ruby
# save in ~/bin/dns and chmod 755
unless ARGV[0]
print `networksetup -getdnsservers Wi-Fi`
exit
end
servers = case ARGV[0]
View Safely setting NOT NULL on a column in Postgres 12+.md

This recipe is a work in progress and has never been run as-is.

  • timeouts are in ms
  • lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
  • statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
View How to deal with ruby and postgres segmentation fault on MacOS when using macports or homebrew.md

Here's something I spent a long time debugging, so I'm making this gist to help others find the solution when searching.

Summary

postgres 12 on MacOS will cause crashes when forking. The solution is to do one of these two things:

  • add gssencmode: "disable" to database.yml
  • if using homebrew: uninstall postgres, update homebrew, reinstall postgres

Here's some discussion:

View gist:d65bc10bb55fed7e4cafb07be035c10a
test results for https://github.com/puma/puma/pull/2228
run 1 - nothing
273.3 MB
27.4 MB
27.3 MB
27.3 MB
27.3 MB
27.3 MB
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 << Thread.new 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
# 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
You can’t perform that action at this time.