Skip to content

Instantly share code, notes, and snippets.

View rg3915's full-sized avatar
🏠
Working from home

Regis Santos rg3915

🏠
Working from home
View GitHub Profile
@luzfcb
luzfcb / installing_pyenv_on_ubuntu_based_distros.md
Last active May 2, 2024 17:51
Quick install pyenv and Python

Tested only on Ubuntu 22.04, KDE Neon User Edition (based on Ubuntu 22.04) and OSX Mojave or higher.

will probably work on other newer versions, with no changes, or with few changes in non-python dependencies (apt-get packages)

NOTE: Don't create a .sh file and run it all at once. It may will not work. Copy, paste, and execute each command below manually. :-)

Ubuntu

# DO NOT RUN THIS AS A ROOT USER
@dunossauro
dunossauro / methods.py
Last active May 26, 2018 00:01
Exemplo de como funcionam os decoradores de classe para o @rg3915
"""
Respondendo a questões feitas no grupo da live de Python.
"""
class Teste:
bananas_cls = 5 # Variável de classe
def __init__(self):
"""Método que inicia a instância."""
self.bananas_self = 10 # Variável de instância
# https://github.com/aykut/django-bulk-update
from django_bulk_update.helper import bulk_update
from minhaapp.models import MeuModelo
queryset_meumodelo = MeuModelo.objects.all()
# limpa os dados
for meumodelo_obj in queryset_meumodelo:
function filter(element, selector) {
var value = $(element).val().toUpperCase();
$(selector +" li").each(function () {
if ($(this).text().toUpperCase().indexOf(value)> -1) {
$(this).show();
} else {
$(this).hide();
}
});
}
@olivx
olivx / docker_basic.md
Last active November 1, 2018 02:26
basico docker

Manual Docker LinuxTip

instalação

curl -fsSL https://get.docker.com/ | sh

primieiro docker container

sudo docker run hello-world

visualizar o container em execução

sudo docker ps

@fleepgeek
fleepgeek / apps.py
Last active February 17, 2024 13:46
A Django Middleware to prevent multiple sessions for the same user. It automatically logs out the previous session and replaces it with the new session.
from django.apps import AppConfig
class ForumConfig(AppConfig):
name = 'forum'
# This function is the only new thing in this file
# it just imports the signal file when the app is ready
def ready(self):
import your_app_name.signals
@vinidmpereira
vinidmpereira / example_current_user.py
Last active May 21, 2019 18:57
get_current_user middleware.
"""
This should be a separate file, i usually install it on the maind django project folder.
"""
from threading import local
from django.utils.deprecation import MiddlewareMixin
_user = local()
@vinicius73
vinicius73 / var-let-const.md
Last active September 30, 2019 13:52
var, let e const no JavaScript

var, let e const

Em JavaScript há uma comportamento chamado hoisting. O uso de var trazia algumas pegadinhas, como por exemplo, declarar a mesma variavel 2x usando var

var abc = 25
// ...
// ...
var abc = 99
@twidi
twidi / drf_utils.py
Created December 21, 2016 14:34
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
import PyPDF2
import shutil
import sys
from pathlib import Path
def list_files(directory, pattern='*.pdf'):
""" Get name of all pdf files on directory """
return sorted(Path(directory).glob(pattern))