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 / new_order.py
Last active May 16, 2018 01:04
Renumerando uma lista
# Dada a lista
lista = [1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 6, 6, 9, 9, 9]
# como eu chego na lista
nova_lista = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 5]
questions_order = (1, 2, 4, 6, 8, 9)
@rg3915
rg3915 / import_export_xlsx.py
Created May 17, 2018 19:42
Import Export Python to XLSX example
import xlrd
import xlwt
def salvar_xlsx(lista):
''' Exportar dados em XLSX '''
result = lista
# response = HttpResponse(content_type='application/ms-excel')
date_ = timezone.now().strftime('%y%m%d%H%M%S')
filename = "/tmp/example_{}.xlsx".format(date_)
# response['Content-Disposition'] = 'attachment; filename=%s' % filename
@rg3915
rg3915 / git_annotations.md
Last active February 2, 2021 23:49
Git Tutorial Git Annotations
@rg3915
rg3915 / display_on_change.js
Created May 23, 2018 20:56
Display JS CSS on change
document.getElementById('get_select').addEventListener('change', function () {
var style = this.value == 0 ? 'none' : 'block';
document.getElementById('my_div').style.display = style;
});
@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 / bulk_create.md
Last active December 15, 2021 18:49
Exemplo de uso do bulk_create no Django. Incluindo escrita e leitura de CSV.

Exemplo de uso do bulk_create no Django

Projeto Django

pip install django names

Crie um projeto Django e gere a migração. Usaremos somente o model User.

@rg3915
rg3915 / ref_data.vue
Created June 19, 2018 02:37
VueJS ref and data example
<div id="app">
<span data-pk='42' ref="mySpan">Meu span maneirasso</span>
<h2>
{{textMySpan}}
</h2>
</div>
new Vue({
el: "#app",
@rg3915
rg3915 / forms.py
Created June 29, 2018 21:19
ChoiceField customizado no forms.
candidate = Candidate.objects.select_related('user')
candidate = candidate.values_list('stage_status__order', flat=True)
candidate = candidate.distinct().order_by('stage_status__order')
qs_choices = [('', _('Todos'))] + [(id, id) for id in candidate]
stage_status = forms.ChoiceField(
choices=qs_choices,
widget=forms.Select(
attrs={'class': 'form-control'}
)
@rg3915
rg3915 / forms.py
Last active March 1, 2023 11:28
Passando User no forms. usuário logado usuario form usuario logado - form kwargs
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user', None)
super(MyForm, self).__init__(*args, **kwargs)
if user.is_authenticated:
my_field = MyModel.objects.filter(user=user)
# ...
self.fields['bar'].choices = qs_choices