Skip to content

Instantly share code, notes, and snippets.

building itsy bitsy parts of the internet

Ryan McGeary rmm5t

building itsy bitsy parts of the internet
View GitHub Profile
rmm5t /
Last active Feb 1, 2019
Add wheel group to sudoers on macOS
# Add current user to wheel group
sudo dseditgroup -o edit -a $USER -t user wheel
# Add wheel to sudoers
sudo su -
cd /etc
chmod 660 sudoers
vi /etc/sudoers
rmm5t / date_time_formats.rb
Last active Feb 1, 2019
Example of config/initializers/date_time_formats.rb
View date_time_formats.rb
Time::DATE_FORMATS[:long_date] = Date::DATE_FORMATS[:long_date] = "%b %e, %Y"
Time::DATE_FORMATS[:day] = Date::DATE_FORMATS[:day] = "%a, %e %b %Y"
Time::DATE_FORMATS[:local_time] = Date::DATE_FORMATS[:local_time] = "%I:%M%P %Z"
Time::DATE_FORMATS[:human] = Date::DATE_FORMATS[:human] = lambda { |t| t.strftime("%b %e, %Y %I:%M%P").sub(/0(\d):/, '\1:') } # Oct 2, 2011 5:57pm
Time::DATE_FORMATS[:rfc822] = "%e %b %Y" # Already in Date::DATE_FORMATS
rmm5t / seeds.rb
Last active Feb 1, 2019
Example of idempotent seeds:
View seeds.rb
# Author: Ryan McGeary :
# License: MIT :
def restart_sequence(klass)
seq = [klass.table_name, "id", "seq"].join("_")
next_id = klass.maximum(:id) + 1
klass.connection.execute "ALTER SEQUENCE #{seq} RESTART #{next_id}"
def load_seed_data(klass, records)
View pg_searchable.rb
# Author: Ryan McGeary :
# License: MIT :
# TL;DR: A poor-man's full-text search.
# This module employs a mechanism by which we can easily add left outer joins
# to queries (typically for full-text-like searches that need to dig into
# specific associations).
# One way to do this is to just use ActiveRecord's `eager_load` as part of a
rmm5t / promisify-node4.js
Created Aug 15, 2017
Node.js "promisify" implementations
View promisify-node4.js
const promisify = (fn) => {
return function () {
const args = Array.from(arguments);
return new Promise(function (resolve, reject) {
fn.apply(undefined, args.concat([function (error, data) {
if (error) return reject(error);
if (data === undefined) return resolve();
return resolve(data);
rmm5t /
Last active Feb 19, 2021
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id =")
   -> 1.3197s

Slow/naïve approach:

View iso8601_benchmark.rb
require 'benchmark'
require 'time'
n = 1_000_000
t =
Benchmark.bmbm do |x|"unix epoch") { n.times { t.to_i.to_s } }"iso 8601 ") { n.times { t.iso8601 } }

Keybase proof

I hereby claim:

  • I am rmm5t on github.
  • I am rmm5t ( on keybase.
  • I have a public key whose fingerprint is 79DA 34B8 A2E7 3C96 E0CC 5BB2 005A C77D 7CBF 3EAF

To claim this, I am signing this object:

View bob.rb
class Bob
def respond_to(input)
@input = input.strip
return "Fine. Be that way!" if silence?
return "Whoa, chill out!" if shouting?
return "Sure." if question?