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
@rg3915
rg3915 / convert_string_types.py
Last active February 21, 2024 18:45 — forked from dunossauro/convert_string_types.py
Conversão de strings em tipos válidos do Python usando ast literal_eval by @dunossauro - python ast
from ast import literal_eval
def convert_to_type(input_data):
try:
return literal_eval(input_data)
except (ValueError, SyntaxError):
return input_data
@rg3915
rg3915 / views.py
Created August 23, 2018 00:48 — forked from robsonsilv4/views.py
Django override get_form on CreateView
class MyModelAdd(CreateView):
model = MyModel
def get_form(self):
type_form = self.request.GET.get('type')
if type_form == 'pf':
self.form_class = PFForm
else:
self.form_class = PJForm
return super(MyModelAdd, self).get_form()
@rg3915
rg3915 / data_table.js
Last active August 9, 2018 19:45 — forked from olivx/data_table.js
search date data-table
// Bootstrap datepicker
$('.input-daterange input').each(function() {
$(this).datepicker('clearDates');
});
// Set up your table
table = $('#my-table').DataTable({
paging: false,
info: false
});
@rg3915
rg3915 / teste_bulk_update.py
Created August 1, 2018 01:34 — forked from luzfcb/teste_bulk_update.py
Django bulk_update
# 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:
@rg3915
rg3915 / methods.py
Created May 25, 2018 21:27 — forked from dunossauro/methods.py
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
@rg3915
rg3915 / Dockerfile
Last active July 25, 2020 09:12 — forked from olivx/docker_basic.md
Guia definitivo de Docker
ARG PYTHON_VERSION='3.8'
# set base image (host OS)
FROM python:3.8
ENV PYTHONUNBUFFERED 1
# set the working directory in the container
WORKDIR /code
@rg3915
rg3915 / filter_jquery_element.js
Last active January 31, 2019 10:09 — forked from olivx/filter_jquery_element.js
Filter elements with jQuery - Search (dataTable)
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();
}
});
}
@rg3915
rg3915 / var-let-const.md
Last active April 4, 2017 23:25 — forked from vinicius73/var-let-const.md
var, let e const no JavaScript

var,let, const

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

var abc = 25
// ...
// ...
var abc = 99
@rg3915
rg3915 / Django + Ajax dynamic forms .py
Created March 23, 2017 18:14 — forked from goldhand/Django + Ajax dynamic forms .py
Django form with Ajax. A simple Task model that can be updated using a CBV with an AJAX mixin. The view sends post data with ajax then updates the view with a callback to a DetailView with a json mixin.There is an abstract CBV, AjaxableResponseMixin, based on the example form django docs, that is subclassed in the TaskUpdateView CBV. TaskUpdateV…
#models.py
class Task(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
def __unicode__(self):
return self.title
@rg3915
rg3915 / gist:21b547711d65c8fae432f11104748ef2
Created August 23, 2016 16:42 — forked from edmondburnett/gist:40e7db34416fdc734846
Push-to-Deploy, Python edition - git post-receive hook script
#!/usr/bin/env python
# post-receive hook for git-based deployments
# https://edmondburnett.com/post/python-push-to-deploy
import sys
import os
from subprocess import call
# configuration
deploy_to_path = '/path/to/deploy/directory/'