Skip to content

Instantly share code, notes, and snippets.

View marceloleiva's full-sized avatar

Marcelo Leiva marceloleiva

View GitHub Profile
@marceloleiva
marceloleiva / bootstrap-tables2.css
Created November 20, 2015 18:06 — forked from shayh/bootstrap-tables2.css
bootstrap3 django-tables2 based on this gist https://gist.github.com/dyve/5458209 I created a template that works wtih https://github.com/dyve/django-bootstrap3 make sure you have 'django.core.context_processors.request' in your TEMPLATE_CONTEXT_PROCESSORS
.table-container th.asc:after {
content: '\0000a0\0025b2';
}
.table-container th.desc:after {
content: '\0000a0\0025bc';
}
.pagination {
text-align: center;
}
@marceloleiva
marceloleiva / forms.py
Created December 10, 2015 22:37 — forked from neara/forms.py
Django Class Based Views and Inline Formset Example
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from models import Sponsor, Sponsorship
class SponsorForm(ModelForm):
class Meta:
model = Sponsor
package com.example.twitter;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
function validaRut(campo){
if ( campo.length == 0 ){ return false; }
if ( campo.length < 8 ){ return false; }
campo = campo.replace('-','')
campo = campo.replace(/\./g,'')
var suma = 0;
var caracteres = "1234567890kK";
var contador = 0;
@marceloleiva
marceloleiva / django_reversion.md
Created July 12, 2016 17:39 — forked from goutham2027/django_reversion.md
using django reversion
pip install django-reversion

Add reversion to INSTALLED_APPS

INSTALLED_APPS = [
...
...
...
@marceloleiva
marceloleiva / determinar_encoding.py
Last active September 30, 2016 13:56
Determinar encoding
import chardet
def determinar_encoding(input_file='despachos.csv'):
file = open(input_file, 'rb').read()
encoding = chardet.detect(file)
if encoding:
return encoding['encoding']
return None
@marceloleiva
marceloleiva / Buscar texto con re.py
Created October 17, 2016 18:43
Buscar texto con re created by marceloleiva - https://repl.it/Dy6x/1
import re
texto = 'Supermercado (1,10,5)'
busqueda_coordenada = re.search(r'(.+)(\(.{5,}\))', texto)
print(busqueda_coordenada.groups())
if busqueda_coordenada:
if len(busqueda_coordenada.groups()) >= 2:
texto = busqueda_coordenada.group(1).strip()
coordenada = re.sub('[()]', '', busqueda_coordenada.group(2)).split(',')
@marceloleiva
marceloleiva / letsencrypt_2017.md
Created June 6, 2017 14:51 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@marceloleiva
marceloleiva / django_model_graph.sh
Created April 3, 2018 21:06 — forked from perrygeo/django_model_graph.sh
Generate UML diagram of django app models
apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in settings.py
python manage.py graph_models trees -o test.png
@marceloleiva
marceloleiva / page.py
Created July 21, 2018 23:01 — forked from rturowicz/page.py
django - intermediate admin page
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']