This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _add_log_level_upper(logger, method_name, event_dict): | |
if method_name == "warn": | |
method_name = "warning" | |
event_dict["level"] = method_name.upper() | |
return event_dict | |
level_styles = structlog.dev.ConsoleRenderer.get_default_level_styles() | |
for k, v in list(level_styles.items()): | |
level_styles[k.upper()] = v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extended python -m http.serve with --username and --password parameters for | |
# basic auth, based on https://gist.github.com/fxsjy/5465353 | |
from functools import partial | |
from http.server import SimpleHTTPRequestHandler, test | |
import base64 | |
import os | |
class AuthHTTPRequestHandler(SimpleHTTPRequestHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from functools import lru_cache, wraps | |
def lru_cache_timeout(timeout_seconds: int): | |
def decorator(f): | |
@lru_cache(maxsize=None) | |
def f_cache_id(f_cache_id, *args, **kwds): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://codekata.com/kata/kata09-back-to-the-checkout/ implemenation using python3 with type-hints and mypy | |
from collections import defaultdict | |
from typing import NamedTuple, Dict, List | |
import unittest | |
class Product(NamedTuple): | |
price: int | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var Model = {} | |
Model.make = function(model_name) { | |
var model = {} | |
model.getByID = function(id, fn) { | |
JSONP.getByID(model_name, id, fn); | |
} | |
model.list = function(params, fn){ | |
// NOTE: brasiltotal | |
params.exclude__codigonoticia__exact = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HotelResource(ModelResource): | |
fields = ("pk", "name", "precos", ) | |
model = Hotel | |
def precos(self, instance): | |
return Preco.objects.filter(quarto__hotel=instance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HotelResource(ModelResource): | |
fields = ("pk", "name", "precos", ) | |
model = Hotel | |
def precos(self, instance): | |
return Preco.objects.filter(quarto__hotel=instance) |