Skip to content

Instantly share code, notes, and snippets.

@fjsj
fjsj / checklist-proposta-pybr.md
Last active June 15, 2018 17:27
Checklist para propostas de talks para Python Brasil

Checklist para propostas de talks para Python Brasil

Tema

  • Escolhi um tema relevante para a audiência. Imaginei quem estará na conferência e pensei: "sobre o que essas pessoas querem/precisam ouvir?"
  • Escolhi um tema enriquecedor, que trará um novo aprendizado para minha audiência
  • Escolhi um tema que já me sinto confortável em falar ou terei tempo suficiente para estudar para me sentir confortável
  • Escolhi um tema que é possível apresentar em 35 minutos
  • Escolhi um único tema e não um conjunto de temas pouco relacionados

Texto da proposta

@fjsj
fjsj / sorted_list_intersection.py
Created December 14, 2018 17:54
Python fast sorted list intersection
import bisect
def bisect_index(arr, start, end, x):
i = bisect.bisect_left(arr, x, lo=start, hi=end)
if i != end and arr[i] == x:
return i
return -1
def exponential_search(arr, start, x):
if x == arr[start]:
@fjsj
fjsj / speedtest.py
Created January 21, 2019 18:13
Python bloom filters performance test (based on pybloomfilter's own test)
#! /usr/bin/env python
import os
import tempfile
import time
import timeit
import pybloomfilter
tempfiles = []
fjsj:~/w/dedupe-3.8.1$ pyenv install 3.8.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.8.1.tar.xz...
-> https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz
Installing Python-3.8.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.8.1 to /Users/fjsj/.pyenv/versions/3.8.1
@fjsj
fjsj / infinite_monkey.py
Created October 13, 2021 18:22
Infinite Monkey in Python
import random
import sys
keyboard = "0123456789abcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ "
if __name__ == "__main__":
expected = " ".join(sys.argv[1:]).lower()
already_produced_set = set()
produced = ""
@fjsj
fjsj / log_time.py
Created December 9, 2021 23:07
Flexible Python context manager to log elapsed time
# Based on this: https://stackoverflow.com/a/62956469/145349
import logging
import time
from contextlib import contextmanager
@contextmanager
def log_time(logger, log_message="Took %.4f secs", log_level=logging.INFO):
start = time.perf_counter()
yield
elapsed = time.perf_counter() - start
SELECT
sum(idx_blks_read) as idx_read,
sum(idx_blks_hit) as idx_hit,
(sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit) as ratio
FROM
pg_statio_user_indexes;
@fjsj
fjsj / celery_settings.py
Last active March 24, 2024 10:44
Recommended Celery Django settings for reliability. For more details, check the DjangoCon 2023 talk "Mixing reliability with Celery for delicious async tasks" by Flávio Juvenal: https://youtu.be/VuONiF99Oqc
# Recommended Celery Django settings for reliability:
# (use `app.config_from_object('django.conf:settings', namespace='CELERY')`
# in proj/celery.py module)
from decouple import config # use python-decouple: https://github.com/HBNetwork/python-decouple
# Prefer RabbitMQ over Redis for Broker,
# mainly because RabbitMQ doesn't need visibility timeout. See:
# https://blog.daftcode.pl/working-with-asynchronous-celery-tasks-lessons-learned-32bb7495586b
# https://engineering.instawork.com/celery-eta-tasks-demystified-424b836e4e94