Skip to content

Instantly share code, notes, and snippets.

View daltonmatos's full-sized avatar
🎉

Dalton Barreto daltonmatos

🎉
View GitHub Profile
@daltonmatos
daltonmatos / gist:7ef74c9e6de52dfa7dbde1003137de8c
Created February 19, 2024 17:16
Terraform recreate google_notebooks_instance
TF_LOG=DEBUG t plan
2024-02-16T14:35:44.883-0300 [INFO] Terraform version: 1.7.3
2024-02-16T14:35:44.884-0300 [DEBUG] using github.com/hashicorp/go-tfe v1.41.0
2024-02-16T14:35:44.884-0300 [DEBUG] using github.com/hashicorp/hcl/v2 v2.19.1
2024-02-16T14:35:44.884-0300 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2024-02-16T14:35:44.884-0300 [DEBUG] using github.com/zclconf/go-cty v1.14.1
2024-02-16T14:35:44.884-0300 [INFO] Go runtime version: go1.21.5
2024-02-16T14:35:44.884-0300 [INFO] CLI args: []string{"terraform", "plan"}
2024-02-16T14:35:44.884-0300 [DEBUG] Attempting to open CLI config file: /home/***/.terraformrc
2024-02-16T14:35:44.884-0300 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
@daltonmatos
daltonmatos / handler-ignoring-some-path-params.py
Last active April 25, 2021 18:13
Asyncworker: Recebendo parametros do Path do Request através de typehints
from aiohttp import web
from asyncworker import App
from asyncworker.http.types import PathParam
app = App()
@app.http.get(["/path/{_bool}/{string}/{number}/{_float}"])
async def user_books(_bool: PathParam[bool], string: PathParam[str]):
@daltonmatos
daltonmatos / asyncworker-app-handler-recebe-user-resource.py
Last active January 4, 2020 02:01
Blog Post: Asyncworker: Handler HTTP recebendo mais do que Request
from aiohttp.web import Request, json_response
from pydantic import BaseModel
from asyncworker import App, RouteTypes
from asyncworker.routes import call_http_handler
app = App()
class UserResource(BaseModel):
@daltonmatos
daltonmatos / dynamic-sig-call.py
Created January 4, 2020 01:30
Blog post: Chamando funções Python com assinatura dinâmica Baseada em Typehint
import asyncio
from typing import Dict, Type, Any, Callable, get_type_hints, Coroutine, TypeVar
T = TypeVar("T")
types_registry: Dict[Type, Any] = dict()
async def call_func(
f: Callable[..., Coroutine[Any, Any, T]], registry: Dict[Type, Any]
) -> T:
@daltonmatos
daltonmatos / logger.py
Created January 20, 2013 23:29
Dynamic logging.getLogget(__name__) implementation
class LoggerProxy(object):
def _setup_logger(self, logger):
console = logging.StreamHandler()
logger.addHandler(console)
logger.setLevel(logging.INFO)
logger._configured = True
@daltonmatos
daltonmatos / mocktrue.py
Created August 7, 2012 02:36
Hack to mock the python True object
import mock
class AlmostAlwaysTrue(object):
def __init__(self, total_iterations=1):
self.total_iterations = total_iterations
self.current_iteration = 0
def __nonzero__(self):
if self.current_iteration < self.total_iterations:
@daltonmatos
daltonmatos / download.py
Created July 27, 2012 01:49
Simple download function with progress bar
# Requires clint (https://github.com/kennethreitz/clint) from the develop branch, because of the expected_size argument.
def download(url, to_file, chunk_size=8192):
r = requests.get(url)
size = int(r.headers['Content-Length'])
expected_size = size / chunk_size
with open(to_file, 'w') as f:
for chunk in progress.bar(r.iter_content(chunk_size=chunk_size), expected_size=expected_size):
@daltonmatos
daltonmatos / count.py
Created April 8, 2012 00:09
Count words
import sys
users = {}
for line in sys.stdin:
username = line.strip('\n')
if username not in users:
users[username] = 1
else:
@daltonmatos
daltonmatos / deco.py
Created March 29, 2012 02:48
A Simple decorator idea for django views
#!/usr/bin/env python
def requires_apikey(f):
def wrap(req, *args, **kwargs):
print "Searching fot an API Key inside {0}...".format(req)
return f(req, *args, **kwargs)
return wrap
@daltonmatos
daltonmatos / hacknrio.rst
Created September 4, 2011 23:13
Descrição da minha submissão de palestra para o Hack in Rio 2011

Título

Rodando sua aplicação Django em um ambiente distribuído com wsgid e mongrel2

Descrição da Palestra

Nessa palestra você conhecerá duas novas ferramentas que facilitarão o deploy de suas aplicações Django em um abiente distribuído.