Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I'm not my code.

Washington Botelho wbotelhos

💭
I'm not my code.
View GitHub Profile
View country-code-to-emoji-flag.rb
def country_code_to_flag(country_code)
code = country_code.to_s.upcase
return unless code =~ /\A[A-Z]{2}\z/
code.codepoints.map { |codepoint| (codepoint + 127_397).chr(Encoding::UTF_8) }.join
end
country_code_to_flag("BR")
# => "🇧🇷"
@wbotelhos
wbotelhos / routes.rb
Last active Dec 1, 2020
How to Set Session on Rails Request Spec
View routes.rb
# frozen_string_literal: true
Rails.application.routes.draw do
if Rails.env.test?
namespace :test do
resource :session, only: :create
end
end
end
@wbotelhos
wbotelhos / gpg-safe.sh
Created Sep 27, 2019
gpg: WARNING: unsafe permissions on homedir '~/.gnupg'
View gpg-safe.sh
sudo chown -R $USER ~/.gnupg
sudo chmod 700 ~/.gnupg
sudo chmod 600 ~/.gnupg/*
View populate_redis_with_large_data.sh
awk -F, 'NR > 1{ print "SET", $0, "true" }' large_data.csv | redis-cli -h redis.amazonaws.com -n 7 --pipe
@wbotelhos
wbotelhos / rails_schema_migration_cheat_sheet.md
Last active Jan 5, 2021
Rails Schema Migration Cheat Sheet
View rails_schema_migration_cheat_sheet.md

Migration

add_column :table_name, :column_name, :decimal, default: 0, precision: 15, scale: 10
add_column :table_name, :column_name, :jsonb, default: {}, null: false
add_column :table_name, :column_name, :string, array: true, default: []

add_foreign_key :table_name, :table_name
add_foreign_key :table_name, :table_name, column: :column_name, name: :index_table_name_on_column_name
View public_cookbook_on_supermarket.sh
knife cookbook site share 'chef-unicorn' 'Web Servers'
View rating_debug_queries.rb
total_count = "SELECT COUNT(DISTINCT resource_id) FROM reviews WHERE resource_type = 'Article' AND scopeable_type is NULL"
distinct_count = "SELECT COUNT(1) FROM reviews WHERE resource_type = 'Article' AND scopeable_type is NULL"
Review.find_by_sql("#{distinct_count}").as_json
Review.find_by_sql("#{total_count}").as_json
Review.find_by_sql("SELECT (CAST(0 AS DECIMAL(17, 14)) / 0) count_avg").as_json
View varnish-commands.md

Local

atom /usr/local/etc/varnish/default.vcl
ln -s /usr/local/sbin/varnishd /usr/local/bin/varnishd

Runs

View postgres-commands.md

Lib

apt-get -y install postgresql postgresql-contrib

List all Databases

\list
View how-to-build-a-debian-package.md
cd /tmp
mkdir nginx-pagespeed

mkdir -p ./etc
cp -rp    /etc/nginx ./etc

mkdir -p ./var/lib
cp -rp    /var/lib/nginx ./var/lib