Skip to content

Instantly share code, notes, and snippets.

View luiscberrocal's full-sized avatar
👽
Happy since I left the circus...

Luis Carlos Berrocal luiscberrocal

👽
Happy since I left the circus...
View GitHub Profile
@luiscberrocal
luiscberrocal / Openpyxl read file
Created August 1, 2018 18:58
Shell to read Excel sheet using OpenPyxl
def convert(self, filename, sheet_name='Sheet1'):
wb = load_workbook(filename=filename, data_only=True)
sheet = wb[sheet_name]
row_num = 1
for row in sheet.rows:
if row_num != 1:
try:
status = row[self.columns['original_name']].value
@luiscberrocal
luiscberrocal / pagination_snippet.html
Created July 8, 2018 14:09
Django Pagination Snippet Bootstap 4
<nav aria-label="Page navigation example">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a href="?page={{ page_obj.previous_page_number }}&order_by={{ order_by }}&direction={{ direction }}"
class="page-link">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
@luiscberrocal
luiscberrocal / crudviews
Last active October 25, 2018 21:55
Django Crud Views
class $MODEL$ListView(LoginRequiredMixin, ListView):
model = $MODEL$
context_object_name = '$context_object$_list'
def get_queryset(self):
return $MODEL$.objects.all()
class $MODEL$UpdateView(LoginRequiredMixin, UpdateView):
model = $MODEL$
context_object_name = '$context_object$'
@luiscberrocal
luiscberrocal / modelform
Created November 26, 2015 18:25
Django Model Form
class $MODEL$Form(ModelForm):
class Meta:
model = $MODEL$
fields = ['', ]
@luiscberrocal
luiscberrocal / Bootstrap 3 Model Form
Created November 26, 2015 18:23
Bootstrap 3 Model Django Form
{% extends "base.html" %}
{% load staticfiles bootstrap3 i18n %}
{% block extra_css %}
{{ form.media }}
{% endblock extra_css %}
{% block page_title %}
$PAGE_TITLE
{% endblock page_title %}
{% block content %}
@echo off
SET VIRTUAL_ENVIRONMENT_FOLDER=C:\python_environments
SET PYCHARM_PROJECT_FOLDER=%USERPROFILE%\PyCharmProjects
SET PYTHON_PROJECT=%~1
SET PROJECT_ENVIRONMENT=%VIRTUAL_ENVIRONMENT_FOLDER%\%PYTHON_PROJECT%_env
cd %VIRTUAL_ENVIRONMENT_FOLDER%
REM echo %PYCHARM_PROJECT_FOLDER%
echo %PROJECT_ENVIRONMENT%
C:\Python34\python.exe C:\Python34\Lib\site-packages\virtualenv.py --no-site-packages %PROJECT_ENVIRONMENT%
@luiscberrocal
luiscberrocal / django_project_setup.sh
Created August 9, 2015 19:49
Bash script to create a Django project and a virtual environment for Python3
#!/bin/bash -e
VIRTUAL_ENVIRONMENT_FOLDER=~/virtual_environments
PYCHARM_PROJECT_FOLDER=~/PycharmProjects/
cd $VIRTUAL_ENVIRONMENT_FOLDER;
/usr/local/Cellar/python3/3.4.1_1/bin/python3 /usr/local/lib/python3.4/site-packages/virtualenv.py --no-site-packages $1_env;
source $VIRTUAL_ENVIRONMENT_FOLDER/$1_env/bin/activate
########## LOGGING CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
@luiscberrocal
luiscberrocal / pydev_templates.xml
Created August 1, 2012 15:03
Python editor templates
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<templates>
<template autoinsert="true" context="org.python.pydev.editor.templates.python" deleted="false" description="csv reader" enabled="true" name="vib_csv_reader">csv_filename= r''&#13;
csvreader = csv.reader(open(csv_filename, 'rb'), delimiter=',', quotechar='|')&#13;
rc = 1&#13;
for row in csvreader:&#13;
if rc != 1:&#13;
regexp = re.compile('[\s\(\)\[\]/{}.,]+')&#13;
clean_value = regexp.sub('', row[6]).strip()&#13;
rc += 1</template>
@luiscberrocal
luiscberrocal / encryptor.py
Created July 17, 2012 19:07
Encrypto using pycrypt
import os, base64
from Crypto.Cipher import AES
import hashlib
class Encryptor(object):
# the block size for the cipher object; must be 16, 24, or 32 for AES
block_size = 32
padding = '{'
def __init__(self, secret):
self.secret = hashlib.sha256(secret).digest()