Skip to content

Instantly share code, notes, and snippets.

Avatar
🧙‍♂️
On sabbatical

Thiago F Macedo thiagof

🧙‍♂️
On sabbatical
View GitHub Profile
@thiagof
thiagof / printer.py
Created Jun 24, 2020
Python Epson Printer on Windows
View printer.py
import os, sys
import win32print
import StringIO
printer_name = win32print.GetDefaultPrinter()
hPrinter = win32print.OpenPrinter(printer_name)
def prn_txt(text):
if sys.version_info >= (3,):
@thiagof
thiagof / Dockerfile
Created May 4, 2020
Docker X11 Forwarding
View Dockerfile
FROM debian:jessie
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y x11-apps
@thiagof
thiagof / balancing.py
Last active Mar 4, 2020
Python Brackets Balancing Excercise
View balancing.py
class UnbalancedBlockException(Exception):
pass
'''Representation of a brackets block and a node in the tree'''
class Block(object):
def __init__(self, char, parent):
self.initiator = char
self.children = []
self.parent = parent
# attach to the parent block
@thiagof
thiagof / app.py
Created Mar 2, 2020
Flask Ensure Domain (redirect) Middleware
View app.py
import flask
import middleware
app = flask.create_app(os.path.dirname(__file__))
app.wsgi_app = middleware.EnsureDomainMiddleWare(app.wsgi_app)
@thiagof
thiagof / lambda_deploy.yml
Created Feb 18, 2020
Github Actions and Lambda Deployment (CD)
View lambda_deploy.yml
on:
push:
branches:
- master
paths:
- '**.py'
- '.github/workflows/lambda_deploy.yml'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@thiagof
thiagof / Job.php
Created Nov 6, 2019
Laravel Queue Instrumentation Trait
View Job.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Log;
@thiagof
thiagof / dumm.md
Created Jun 26, 2019
Design Responsive e Mobile-first
View dumm.md

Design Responsivo

O conceito de design responsivo, originalmente cunhado pela Ethan Marcote em 2010, descreve uma técnica na qual o design de um site é ajustado automaticamente com base no tamanho das telas dos usuários.

Dica rápida: você pode determinar se um site é ou não responsivo ao ampliar ou reduzir manualmente a janela do navegador.

Exemplos de Responsividade:

@thiagof
thiagof / helpers.py
Last active Mar 24, 2019
Normalize nested Json into Flat dict structure
View helpers.py
def json_flat(item, nest=''):
new = {}
for k,v in item.iteritems():
key = '%s_%s' % (nest, k) if nest else k
if isinstance(v, dict):
new.update(json_flat(v, k))
else:
new[key] = v
return new
@thiagof
thiagof / Dockerrun.aws.json
Created Feb 6, 2019
AWS ECS / Beanstalk Docker syslog LogDriver
View Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "1",
"dnsServers": [ "8.8.8.8" ],
"Volumes": [
{
"HostDirectory": "/var/app/current",
"ContainerDirectory": "/usr/src/app"
},
{
"HostDirectory": "/tmp",
@thiagof
thiagof / express-middleware.js
Last active Feb 5, 2019
Nodejs measure execution time
View express-middleware.js
async function logRouteExecTime(req, res, next) {
const startTime = process.hrtime();
res.once('finish', () => {
const endTime = parseHrtimeToSeconds(process.hrtime(startTime));
const payload = {
server_method: req.method,
server_url: `${req.baseUrl}${req.route ? req.route.path : ''}`,
server_params: req.params,
server_time: endTime,