Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@arthuralvim
arthuralvim / postgres_queries_and_commands.sql
Created September 8, 2020 12:46 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@arthuralvim
arthuralvim / ipdb-jupyter.py
Last active August 19, 2020 13:22
ipdb-jupyter
IPython.core.debugger.Pdb.set_trace()
# DeprecationWarning: `Tracer` is deprecated since version 5.1, directly use `IPython.core.debugger.Pdb.set_trace()`
from IPython.core.debugger import Tracer; Tracer()()
@arthuralvim
arthuralvim / email-to-spreadsheet.gs
Created August 12, 2020 14:09
Google Apps Script para enviar dados de email do Gmail para o Google Spreadsheets.
function count_emails() {
var max = 500;
var offset = 0;
var emails = [];
while (true) {
var threads = GmailApp.search("in:anywhere", offset, max);
emails = searchThreads.concat(threads);
if (threads.length < max) {
@arthuralvim
arthuralvim / GetGmailEmails.gs
Created August 12, 2020 13:22 — forked from moayadhani/GetGmailEmails.gs
Get Gmail Emails By Assigned Label
var ui = SpreadsheetApp.getUi();
function onOpen(e){
ui.createMenu("Gmail Manager").addItem("Get Emails by Label", "getGmailEmails").addToUi();
}
function getGmailEmails(){
var input = ui.prompt('Label Name', 'Enter the label name that is assigned to your emails:', Browser.Buttons.OK_CANCEL);
@arthuralvim
arthuralvim / pizza.py
Created July 12, 2020 22:55
Máquina escolha minha pizza, por favor.
import random
from collections import Counter
random.seed(3)
pizzas = ['caipira', 'portuguesa', 'pepperoni', '4 queijos']
print(Counter([random.sample(pizzas, 1)[0] for r in range(1000)]))
@arthuralvim
arthuralvim / logout.js
Created June 5, 2020 11:47
HTTP AUTH LOGOUT
// paste it in your console and change the url to your needs.
function logout(to_url) {
var out = window.location.href.replace(/:\/\//, '://log:out@');
jQuery.get(out).error(function() {
window.location = to_url;
});
}
@arthuralvim
arthuralvim / basic_math_utils.py
Last active April 21, 2020 23:22
Basic Math Utils
from math import gcd
from functools import reduce
# or
# def gcd(a, b):
# """Return greatest common divisor using Euclid's Algorithm."""
# while b:
# a, b = b, a % b
# return a
@arthuralvim
arthuralvim / postgres_table_row_count.sql
Created April 9, 2020 18:01
SQL to count rows in all PostgreSQL tables.
# credits for -> https://www.sisense.com/blog/exact-row-counts-for-every-database-table/
CREATE OR REPLACE FUNCTION
count_rows(schema text, tablename text) RETURNS integer
AS
$BODY$
DECLARE
result integer;
query varchar;
BEGIN
@arthuralvim
arthuralvim / screen.md
Last active March 24, 2020 11:48
GNU Screen Commands

Screen Commands

On the command prompt, type screen. Run the desired program. Use the key sequence ctrl-a + ctrl-d to detach from the screen session. Reattach to the screen session by typing screen -r.

List running screen sessions

$ screen -list

or

@arthuralvim
arthuralvim / aws_create_site.yml
Created February 19, 2020 13:00 — forked from ruzickap/aws_create_site.yml
Ansible playbook which creates instances and tag volumes
---
- name: Create Instance in AWS
hosts: localhost
connection: local
gather_facts: false
vars:
aws_access_key: "xxxxxx"
aws_secret_key: "xxxxxx"
security_token: "xxxxxx"