Skip to content

Instantly share code, notes, and snippets.

View rochacbruno's full-sized avatar

Bruno Rocha rochacbruno

View GitHub Profile
def get(obj, attr, default=None):
"""
Fetch an attribute deeply nested on an object or dict, return `default` if not found
>>> class Foo: pass
>>> f = Foo()
>>> f.a = Foo()
>>> f.a.b = Foo()
>>> f.a.b.c = True
@steffanydev
steffanydev / EAD12.py
Last active April 30, 2020 15:25
Hotel Bom Descanso - Software para reserva de quartos
'''
Hotel Bom Descanso - Software para reserva de quartos
'''
quartos = {}
contiua_cadastro = "SIM"
while (contiua_cadastro.upper() == "SIM"):
quarto = input('Informe o número do quarto: ')
@rochacbruno
rochacbruno / dummy-web-server.py
Created April 25, 2020 17:14 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python (Updated for Python 3.7)
Usage:
./dummy-web-server.py -h
./dummy-web-server.py -l localhost -p 8000
Send a GET request:
@JacobCallahan
JacobCallahan / cache.py
Created February 14, 2020 15:07
poc for a new caching system
from collections import defaultdict
from functools import lru_cache
CACHE = Cache()
class Cache:
_free = defaultdict(lambda: defaultdict(list))
_active = defaultdict(lambda: defaultdict(list))
@ongun-kanat
ongun-kanat / 00-overrides.conf
Last active April 11, 2024 13:12
Make ~~cancer~~ emoji work on Linux
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<alias>
<family>Arial</family>
<prefer>
<family>Arial</family>
<family>Liberation Sans</family>
<family>sans-serif</family>
</prefer>
@niuware
niuware / django_stream_queryset_to_csv.md
Created October 18, 2019 03:41
How to stream a CSV file from a large QuerySet using Django's StreamingHttpResponse

Stream a CSV file from a QuerySet using StreamingHttpResponse

This is a sample on how to stream the results of a large QuerySet into a CSV file using Django StreamingHttpResponse class.

  1. Add the CSVStream class in your project, for example a writers.py file:
import csv
from django.http import StreamingHttpResponse
@rochacbruno
rochacbruno / download_images.sh
Created August 7, 2019 18:41
Download Multiple Sequential Images on Bash
# A web server having files named /file00001.jpg to /file00138.jpg
BASE_URL=https://xyzkonjdnfsdf.rackcdn.com/file00
for i in $(seq 001 138); do wget $BASE_URL$(printf "%.3d" "$i").jpg ; done
@Nasdin
Nasdin / image_to_grid_knitting_pattern.py
Last active October 28, 2019 01:41
Takes an image and converts it to a grid knitting pattern as an excel file with colors and labelled with numbers. Arguments are 1. image path 2. desired height of grid 3. excel output path
import sys
import cv2
import numpy as np
import xlsxwriter
if len(sys.argv) != 4:
print("That's not how it works")
sys.exit(404)
@rohanpm
rohanpm / remove-duplicate-test
Last active March 27, 2019 15:31
Improving remove_unit_duplicate_nevra performance
#!/usr/bin/env python
"""Benchmark script showing difference between current remove_unit_duplicate_nevra
and implementation with adjusted queries.
Logs for running this over real data:
2019-03-11 03:52:15,745 Testing queries for repo: rhel-7-server-release-e2e-test-1-rpms__x86_64
2019-03-11 03:52:15,752 Start improved for rhel-7-server-release-e2e-test-1-rpms__x86_64 (1584 units)
2019-03-11 03:52:15,755 End improved for rhel-7-server-release-e2e-test-1-rpms__x86_64
2019-03-11 03:52:15,755 Start original for rhel-7-server-release-e2e-test-1-rpms__x86_64 (1584 units)
import asyncio
import logging
import os
import signal
from aiohttp import web
log = logging.getLogger(__name__)