Skip to content

Instantly share code, notes, and snippets.

View fbidu's full-sized avatar
💭
I may be slow to respond.

Felipe Rodrigues fbidu

💭
I may be slow to respond.
View GitHub Profile
@fbidu
fbidu / read_only_wrapper.py
Created February 22, 2023 10:57
simple snippet for a read-only wrapper around a base class
class User:
"""
User class
It has some methods and properties to simulate the functions
of a regular class.
"""
def __init__(self, first_name, last_name, email, password):
self.first_name = first_name
self.last_name = last_name
"""
Data are bits
Numbers can be written as bits
Therefore, any data can be written as a number
Here is a small playground
"""
def text_to_int(filename):
@fbidu
fbidu / primes.py
Created November 24, 2019 14:20
A simple iterator that generates all the prime numbers
"""
primes provide a very simple iterator that's able
to generate all the prime numbers!
This is for teaching purposes only.
"""
class Primes:
"""
@fbidu
fbidu / dados.csv
Last active October 22, 2019 17:21
Dados de exemplo para um exercício de CSV com Python
326.75 39.9 39.92 3.69
333.05 49.75 49.76 3.91
338.45 59.85 59.72 4.09
340.95 64.9 64.86 4.17
343.25 69.81 69.9 4.25
345.35 74.84 74.78 4.31
347.45 79.85 79.93 4.38
class CacheState(Enum):
"""
Enum to diferentiate caches hits and misses for boolean values.
It was created to store OAuth2 token validity in cache. In that
scenario, a cache miss prompts an API call to check the token,
while a cache hit with a False value does not.
VALID and INVALID are bool compatible.
>>> bool(CacheState.INVALID)
@fbidu
fbidu / python-bootstrap.md
Last active May 3, 2019 14:19
A simple shell script that bootstraps a basic Python project

Bootstrapping a Python project

Just give me the script!

From inside a new folder run:

pipenv --three
pipenv install --dev --pre pylint black pytest
touch README.md
mkdir tests
@fbidu
fbidu / export.md
Last active April 26, 2023 19:04
Exports an AWS ECS Task Definition environment variables to a docker run command
  1. Install jq
  2. Run:
aws ecs describe-task-definition \
	--task-definition <task_arn> \
	--query "taskDefinition.containerDefinitions[0].environment[]" |
	jq -r '.[] | "-e \(.name)=\"\(.value)\" \\"'
@fbidu
fbidu / draft.py
Created August 19, 2018 12:19
A rough draft for a more pythonic AWS client
import boto3
class Cluster:
"""
Class to handle an ECS Cluster
"""
def __init__(self, name, boto3_session):
assert type(boto3_session) == boto3.session.Session, "Please, provide an boto3 Session as argument!"
self.name = name
self.boto3_session = boto3_session
@fbidu
fbidu / sra_demo.py
Created October 15, 2017 21:08
Rascunho de script para obter IDs de sequencias de DNA/RNA (NGS) armazenadas no SRA (https://trace.ncbi.nlm.nih.gov/Traces/sra/) com base em busca via Entrez
from xml.dom import minidom # Ou qualquer parser XML que você preferir
from Bio import Entrez
def search_sra(query, email='seu@email.com'):
"""
Retorna um handler de busca para o SRA
"""
Entrez.email = email
handle = Entrez.esearch(db='sra',
sort='relevance',
0x26fc5049bC81986BB3703af70BBe1ef4babb07E1