Skip to content

Instantly share code, notes, and snippets.

For bundler I did the following on Catalina
$ brew install [email protected]
$ bundle config build.libv8 --with-system-v8
$ bundle config build.therubyracer --with-v8-dir=$(brew --prefix [email protected])
$ bundle install
@phund
phund / rbenv-howto.md
Created December 27, 2019 14:13 — forked from samukasmk/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

def cal_retry_time(retry_count)
time = 0
(1..retry_count).each do |rc|
time += ((rc ** 4) + 15 + (rand(30) * (rc + 1)))
end
p "time: #{time}s => #{time.to_f/3600}h => #{time.to_f/3600/24}day(s)"
end
cal_retry_time(10)
@phund
phund / config.yml
Last active March 19, 2019 09:29
Run lighthouse on a domain
defaults: &defaults
URL: https://example.com
development:
<<: *defaults
test:
<<: *defaults
staging:
@phund
phund / postgres-cheatsheet.md
Created March 1, 2019 02:47 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@phund
phund / gist:cf5e0a9561cbd7ecc55a66b21b967152
Last active July 8, 2019 09:59
Rake task check syntax in a Rails app.
namespace :syntax do
desc 'Checks the syntax of ERB files'
task :erb do
require 'action_view'
puts "Start check ERB files: "
errors = []
Dir['app/views/**/*.erb'].each do |file|
template = File.read(file)
@phund
phund / ab.sh
Created September 21, 2018 10:32 — forked from hassansin/ab.sh
Apache Bench Ajax POST
ab \
-n 1000 \
-c 20 \
-s 30 \
-p post-data.txt \
-T 'application/x-www-form-urlencoded; charset=UTF-8' \
-v 3 \
-H "X-Requested-With: XMLHttpRequest" \
-H "X-Ajax-Referer: http://example.com" \
-H "Accept-Encoding: gzip, deflate" \
@phund
phund / .rvmrc
Created August 27, 2018 06:30 — forked from danielnc/Gemfile
Ruby-based Benchmark of MessagePack vs. JSON vs. Yajl vs. Protobuffers vs. MultiJson vs. Marshal vs. YAML vs. BSON
rvm --create 1.9.3@benchmarks
@phund
phund / pgsql-query-json-array.sql
Created July 19, 2018 10:22 — forked from clarkdave/pgsql-query-json-array.sql
(PostgreSQL) Query something in a JSON array in a WHERE clause
-- when you have a record which looks like this
--
-- id: 5,
-- properties: {
-- ages: [20, 30]
-- }
--
-- it is a bit of a pain if you need to query based on the contents of the "ages" array inside the JSON object "properties"
-- because PG currently lacks easy to use operators to work with JSON arrays
@phund
phund / benchmark.rb
Created July 19, 2018 08:29 — forked from hakanensari/benchmark.rb
PostgreSQL update strategies in and around Rails
require 'active_record'
require 'activerecord-import'
require 'benchmark'
require 'pg'
include ActiveRecord
Base.establish_connection adapter: 'postgresql',
encoding: 'unicode',
pool: 5,