Skip to content

Instantly share code, notes, and snippets.

arthuralvim /
Created Feb 25, 2021 — forked from kissgyorgy/
Python: py.test fixture for SQLAlchemy test in a transaction, create tables only once!
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from myapp.models import BaseModel
import pytest
def engine():
return create_engine("postgresql://localhost/test_database")
arthuralvim /
Created Feb 2, 2021 — forked from ursuad/
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/ --zookeeper localhost:2181 --list

Describe a topic

bin/ --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/ --zookeeper localhost:2181 --alter --topic mytopic --config

... wait a minute ...

View postgres_queries_and_commands.sql
-- 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 /
Created Aug 12, 2020
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 ="in:anywhere", offset, max);
emails = searchThreads.concat(threads);
if (threads.length < max) {
arthuralvim /
Created Aug 12, 2020 — forked from MoayadAbuRmilah/
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 /
Created Jul 12, 2020
Máquina escolha minha pizza, por favor.
import random
from collections import Counter
pizzas = ['caipira', 'portuguesa', 'pepperoni', '4 queijos']
print(Counter([random.sample(pizzas, 1)[0] for r in range(1000)]))
# DeprecationWarning: `Tracer` is deprecated since version 5.1, directly use `IPython.core.debugger.Pdb.set_trace()`
from IPython.core.debugger import Tracer; Tracer()()
View logout.js
// 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;
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 / postgres_table_row_count.sql
Created Apr 9, 2020
SQL to count rows in all PostgreSQL tables.
View postgres_table_row_count.sql
# credits for ->
count_rows(schema text, tablename text) RETURNS integer
result integer;
query varchar;