Skip to content

Instantly share code, notes, and snippets.

arthuralvim /
Created Feb 21, 2019
Example of python queues and multithreading.
import queue
import threading
num_worker_threads = 1
def do_work(item):
arthuralvim /
Created Aug 19, 2015
Convert .csv to Django fixtures.
# -*- coding: utf-8 -*-
# requirements
# pip install unipath
# pip install python-decouple
from os.path import join
from unipath import Path
from decouple import config
import csv
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 21, 2014
A template tag to check if an user belongs to a specific group.
from django import template
from django.contrib.auth.models import Group
register = template.Library()
def has_group(user, group_name):
group = Group.objects.get(name=group_name)
return True if group in user.groups.all() else False
# DeprecationWarning: `Tracer` is deprecated since version 5.1, directly use `IPython.core.debugger.Pdb.set_trace()`
from IPython.core.debugger import Tracer; Tracer()()
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)]))