This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
: <<'END_COMMENT' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Ryan McGeary : http://github.com/rmm5t | |
# License: MIT : https://rmm5t.mit-license.org/ | |
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}" | |
end | |
def load_seed_data(klass, records) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Ryan McGeary : http://github.com/rmm5t | |
# License: MIT : https://rmm5t.mit-license.org/ | |
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}])); | |
}); |
Fast/efficient approach:
-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
-> 1.3197s
Slow/naïve approach:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'time' | |
n = 1_000_000 | |
t = Time.new.utc | |
Benchmark.bmbm do |x| | |
x.report("unix epoch") { n.times { t.to_i.to_s } } | |
x.report("iso 8601 ") { n.times { t.iso8601 } } | |
end |
I hereby claim:
- I am rmm5t on github.
- I am rmm5t (https://keybase.io/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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | |
"Whatever." | |
end |