Skip to content

Instantly share code, notes, and snippets.

View luzfcb's full-sized avatar

Fábio C. Barrionuevo da Luz luzfcb

View GitHub Profile
@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@rg3915
rg3915 / print.js
Last active June 28, 2018 21:06
Print on HTML with JS e imprimindo gráfico ChartJS
<script>
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;

essas batalhas sobre linguagens de programação sao frequententes, mas muitos ignoram que tudo vira instruções que a máquina é capaz de executar então, no inicio, a programação era complicada, com fios (isso falando de computadores modernos, da época da segunda guerra depois, com o desenvolvimento das memórias, viu-se a vantagem de tornar a programação flexivel e armazena-la na memoria (agora abundante) os computadores e os programas começaram a crescer entao eles programavam apenas em código de máquina, instruções que eram codificadas para cada processador depois veio a ideia de agrupar instrucoes semelhantes em menemonicos aparece o assembly uma instrucao em assembly pode gerar varias instrucoes de maquina diferente mov Registrador, memoria mov memoria, Registrador

@alexcasalboni
alexcasalboni / aws-lambda-static-type-checker.md
Last active May 22, 2023 07:31
AWS Lambda Static Type Checker Example (Python3)

How to use Python3 Type Hints in AWS Lambda

TL;DR

Static Type Checkers help you find simple (but subtle) bugs in your Python code. Check out lambda_types.py and incrementally improve your code base and development/debugging experience with type hints.

Your Lambda Function code will go from this:

@pydanny
pydanny / django_local_settings.py
Last active December 12, 2018 12:31
running local unverified SSL on Django and Flask (don't do this in production!!!)
from .common import * # noqa
DEBUG = True
INSTALLED_APPS += ('django_extensions',)
# Snip all the other stuff
@danilobellini
danilobellini / kruskal.py
Last active October 30, 2021 13:42
Kruskal's algorithm
"""
Kruskal's algorithm
Pure Python implementation by Danilo J. S. Bellini
"""
import pytest
def kruskal_sets(graph):
nodes = frozenset.union(*graph)
@hackebrot
hackebrot / README.md
Last active July 6, 2017 20:28
Python class setup

Run pytest and show prints:

$ pytest -v -s
test_helloworld.py::TestHello::test_python [TestHello.setUpClass] PASSED
test_helloworld.py::TestHello::test_world PASSED
test_helloworld.py::TestHey::test_world [TestHey.setup_class] PASSED
@judy2k
judy2k / auto_args.py
Created April 18, 2017 13:48
Save constructor arguments on self without writing self.x = x etc...
from inspect import signature
def auto_args(f):
sig = signature(f) # Get a signature object for the target:
def replacement(self, *args, **kwargs):
# Parse the provided arguments using the target's signature:
bound_args = sig.bind(self, *args, **kwargs)
# Save away the arguments on `self`:
for k, v in bound_args.arguments.items():
if k != 'self':
@craigvantonder
craigvantonder / flush-dns.sh
Last active February 3, 2021 04:42
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart
@c0psrul3
c0psrul3 / graphite-api.wsgi
Last active August 21, 2017 17:53
Graphite-api config and uWSGI start (for use with Grafana)
[uwsgi]
processes = 2
http-socket = localhost:8001
uid = 165
gid = 165
module = graphite_api.app:app
daemonize2 = /var/log/uwsgi-graphiteapi.log
env = GRAPHITE_API_CONFIG=/usr/local/etc/graphite-api.yaml