Skip to content

Instantly share code, notes, and snippets.

View marcotc's full-sized avatar

Marco Costa marcotc

View GitHub Profile
@marcotc
marcotc / test.ipynb
Last active January 10, 2017 04:05
Test
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@marcotc
marcotc / fix-ruby-readline.sh
Created January 11, 2017 22:14
Fix ruby readline version mismatch on MacOS with homebrew
brew update && brew upgrade
for i in `rbenv versions --bare|xargs`; do rbenv install -f $i && RBENV_VERSION=$i gem pristine --all; done
@marcotc
marcotc / sidekiq_retry_time.csv
Created February 14, 2017 18:16
Sidekiq retry exponential backoff formula times
Retry count Retry Time Total Cumulative Time Total Cumulative Days
0 0:00:00 0:00:00 0.0
1 0:00:16 0:00:16 0.0
2 0:00:31 0:00:47 0.0
3 0:01:36 0:02:23 0.0
4 0:04:31 0:06:54 0.0
5 0:10:40 0:17:34 0.0
6 0:21:51 0:39:25 0.0
7 0:40:16 1:19:41 0.1
8 1:08:31 2:28:12 0.1
@marcotc
marcotc / FastClicker.ico
Last active April 10, 2017 01:58
Fast Mouse Clicker icon
@marcotc
marcotc / tf2items.weapons.txt
Last active April 30, 2017 05:57
tf2items.weapons.txt
"custom_weapons_v3"
{
// For reference: "1" "280 ; 2" // Change projectile to rocket
"*"
{
// Demoman
"308" // Loch-n-load
{
"1" "280 ; 2"
"2" "3 ; 0.75"
@marcotc
marcotc / current_queries.sql
Last active September 25, 2017 16:53
Retrieve and kill current Postgres queries
SELECT pid, age(query_start, clock_timestamp()), state, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' and state = 'active' ORDER BY age(query_start, clock_timestamp());
--select pg_cancel_backend(123456);-- Kill by PID
@marcotc
marcotc / clear_ar_cache.rb
Created October 3, 2017 20:52
Clear ActiveRecord cache
ActiveRecord::Base.connection.query_cache.clear
@marcotc
marcotc / find_new_tfsa_limit.rb
Created December 6, 2017 20:51
Finds latest TFSA limit published by CRA
require 'wombat'
require 'date'
data = Wombat.crawl do
base_url "https://www.canada.ca"
path "/en/revenue-agency/services/tax/individuals/frequently-asked-questions-individuals/adjustment-personal-income-tax-benefit-amounts.html"
limit xpath: "/html/body/main/div[1]/div[2]/div/table/tbody/tr[45]/td[2]"
year css: ".active > th:nth-child(2)"
end
@marcotc
marcotc / ar_current_queries.rb
Last active February 7, 2018 17:02
Find long running queries (an kill them if you wish)
ActiveRecord::Base.connection.exec_query("SELECT pid, age(query_start, clock_timestamp()), state, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' and state = 'active' ORDER BY age(query_start, clock_timestamp())")
#ActiveRecord::Base.connection.exec_query("select pg_cancel_backend(123456)") # Kill by PID
@marcotc
marcotc / ar_list_index.rb
Created June 18, 2018 21:35
List Postgres indexes with ActiveRecord
ActiveRecord::Base.connection.exec_query("SELECT t.tablename, indexname, c.reltuples AS num_rows, pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size, pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size, CASE WHEN indisunique THEN 'Y' ELSE 'N' END AS UNIQUE, idx_scan AS number_of_scans, idx_tup_read AS tuples_read, idx_tup_fetch AS tuples_fetched FROM pg_tables t LEFT OUTER JOIN pg_class c ON t.tablename=c.relname LEFT OUTER JOIN ( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x JOIN pg_class c ON c.oid = x.indrelid JOIN pg_class ipg ON ipg.oid = x.indexrelid JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid ) AS foo ON t.tablename = foo.ctablename WHERE t.schemaname='public' ORDER BY 1,2;")