Skip to content

Instantly share code, notes, and snippets.

View wbotelhos's full-sized avatar
💭
I'm not my code.

Washington Botelho wbotelhos

💭
I'm not my code.
View GitHub Profile
@wbotelhos
wbotelhos / convert_sass_to_scss.sh
Created March 17, 2022 01:20
Convert SASS to SCSS
#!/bin/bash
convert() {
file=$1
target=${file//.sass/.scss}
paths_with_file=$(echo $file | tr '/' "\n" | wc -l | tr -d ' ')
paths_number=$(($paths_with_file - 4)) # app assets stylesheets ... filename.sass
@wbotelhos
wbotelhos / mysql-ld-library-not-found-for-lzstd.sh
Last active October 20, 2021 20:29
Mac ARM64 M1 - MySQL Error "ld: library not found for -lzstd"
gem install mysql2 -- --with-mysql-lib=$(brew --prefix)/Cellar/mysql/5.7.35/lib/ --with-mysql-dir=$(brew --prefix)/Cellar/mysql/5.7.35/ --with-mysql-config=$(brew --prefix)/Cellar/mysql/5.7.35/bin/mysql_config --with-mysql-include=$(brew --prefix)/Cellar/mysql/5.7.35/include/
@wbotelhos
wbotelhos / country-code-to-emoji-flag.rb
Created February 12, 2021 12:41
Country Code to Emoji Flag
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 June 2, 2023 14:03
How to Set Session on Rails Request Spec
# 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 September 27, 2019 19:00
gpg: WARNING: unsafe permissions on homedir '~/.gnupg'
sudo chown -R $USER ~/.gnupg
sudo chmod 700 ~/.gnupg
sudo chmod 600 ~/.gnupg/*
@wbotelhos
wbotelhos / populate_redis_with_large_data.sh
Created April 8, 2019 16:29
Populate Redis With Large Data
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 January 5, 2021 18:22
Rails Schema Migration Cheat Sheet

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
@wbotelhos
wbotelhos / public_cookbook_on_supermarket.sh
Created March 1, 2018 04:06
Public Cookbook on Supermarket
knife cookbook site share 'chef-unicorn' 'Web Servers'
@wbotelhos
wbotelhos / rating_debug_queries.rb
Created February 8, 2018 20:10
Rating Debug Queries
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
@wbotelhos
wbotelhos / varnish-commands.md
Created January 31, 2018 14:56
Varnish Commands

Local

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

Runs