Skip to content

Instantly share code, notes, and snippets.

View olivx's full-sized avatar

Thiago Oliveira olivx

  • Tivit
  • Sao Paulo
View GitHub Profile
@olivx
olivx / configurar_pyenv.md
Created September 9, 2021 15:51 — forked from luzfcb/configurar_pyenv.md
instalar pyenv no ubuntu

baseado no meu outro tutorial https://gist.github.com/luzfcb/1a7f64adf5d12c2d357d0b4319fe9dcd

Use o pyenv https://github.com/pyenv/pyenv para baixar, instalar e gerenciar múltiplas versões do INTERPRETADOR Python na sua maquina.

Primeiro instale as dependências:

Linux (Ubuntu):

Abra um terminal, apertando o atalho CRTL + ALT + T ou digite aperte a tecla do windows e digite terminal, ou clique com o botão direito na tela, e escolha a opção "Abrir Terminal" (somente para Ubuntu 15.10 ou superior, para 14.04 é necessário instalar o pacote nautilus-open-terminal e reiniciar)

@olivx
olivx / audit_mixin.py
Created August 31, 2021 19:14 — forked from metaperl/audit_mixin.py
generic audit log for SQLAlchemy models, inspired by https://gist.github.com/ngse/c20058116b8044c65d3fbceda3fdf423
# Inspired by the flask-specific https://gist.github.com/ngse/c20058116b8044c65d3fbceda3fdf423
# This is generic and should work with any web framework and even command-line.
# Implement by using AuditableMixin in your model class declarations
# Usage for the [Reahl web app framework](http://reahl.org) below:
# ---------------------------------------------------------------
# import lib.audit_mixin
#!/bin/bash
echo Intalling linux esentials...
sudo apt-get update -y
sudo apt-get install -y gcc \
gconf2 \
make \
linux-headers-$(uname -r) \
build-essential \
apt-transport-https \
ca-certificates \
@olivx
olivx / avatar.js
Created August 11, 2020 13:57
change avatar, crop file with Django and ajax and pillow .
$("#change-image-button").click(function(event){
$("#id_avatar").click()
})
// open file and get result
$(".avatar-img").on("change", "#id_avatar", function(event){
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$("#crop-image").attr("src", e.target.result);
@olivx
olivx / resize-thumbnail.py
Last active August 11, 2020 13:58
Django resize thumbnail on save image
from io import BytesIO
from os.path import splitext
from uuid import uuid4
from PIL import Image
def genereic_entity_upload_to(instance, filename):
_, filename_ext = splitext(filename)
return f"{instance.__class__.__name__}/{instance.entity.pk}/{uuid4()}.{filename_ext}".lower()
@olivx
olivx / js-scroll.js
Last active August 11, 2020 13:58
make simple scroll function with vanilla js
<script type="text/javascript">
function slide(src,nome){
document.getElementById(nome).removeAttribute('style');
document.getElementById(nome).setAttribute('style','background-image:url('+src+')');
}
function next (id,project) {
var width=document.getElementById(project).offsetWidth;
var container = document.getElementById(id);
sideScroll(container,'right',18,width,10);
@olivx
olivx / models.py
Last active August 11, 2020 13:59
Custom User Django
from django.db.models import (Model, EmailField, BooleanField, DateTimeField)
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager, PermissionsMixin
class UserManager(BaseUserManager):
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
user = self.model(email=email, **extra_fields)
DATA_LISTENER_ENDPOINT: "127.0.0.1"
ESP_DATA_LISTENER_PORT: 1167
endpoints:
- localhost:8080/alert
- localhost:8081/alert
severity_levels:
- { "5": "critical" }
@olivx
olivx / tcpdump
Last active November 5, 2021 20:10
Incluir regras de firewall:
iptables -t nat -A PREROUTING -p udp --dport <31001> -i ens3 -j DNAT --to <ip-destino>:<porta-destino> <- ip:port
Listar regras de firewall:
iptables -t nat -nL --lin
@olivx
olivx / Pipfile
Last active August 11, 2020 14:00
python json logger
python-json-logger = "*"