Skip to content

Instantly share code, notes, and snippets.

View camilonova's full-sized avatar

Camilo Nova camilonova

View GitHub Profile
from django import template
from django.http import Http404
from django.conf import settings
register = template.Library()
DEFAULT_SORT_UP = getattr(settings, 'DEFAULT_SORT_UP' , '↑')
DEFAULT_SORT_DOWN = getattr(settings, 'DEFAULT_SORT_DOWN' , '↓')
INVALID_FIELD_RAISES_404 = getattr(settings,
'SORTING_INVALID_FIELD_RAISES_404' , False)
@camilonova
camilonova / .profile
Created January 28, 2012 16:16
OSX Lion .profile file
# Virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Color
export TERM=xterm-color
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Bash completion
@camilonova
camilonova / models.py
Created February 8, 2012 13:05
Comment tree model
class Comment(models.Model):
"""
Representa los comentarios a los posts del blog
"""
post = models.ForeignKey(
'blog.Post',
)
user = models.ForeignKey(
'auth.User',
)
@camilonova
camilonova / .bash_profile
Last active November 20, 2015 16:00
Bash profile osx lion
# Locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Homebrew
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"
# Brew autocomplete
source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
@camilonova
camilonova / settings.py
Created June 25, 2012 20:36
Default logging for django 1.4
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'console': {
@camilonova
camilonova / migrate.py
Last active December 16, 2015 14:19
Migrate files from FileSystem to other storage
import os
from django.core.files import File
from .models import MediaFile
for ff_local in os.listdir('app/media/uploads/files'):
if MediaFile.objects.filter(file_uploaded__contains=ff_local):
mf = MediaFile.objects.filter(file_uploaded__contains=ff_local)[0]
f = File(open('app/media/uploads/files/'+ff_local, 'r'))
mf.file_uploaded.save(ff_local, f)
@camilonova
camilonova / update_requirements.sh
Created May 10, 2013 18:40
Update requirements if they have changed
#!/bin/bash
# This script will update the requirements only if the file has changed
# Author: AxiaCore S.A.S. http://axiacore.com
FILE=.requirements_timestamp
if [ ! -f $FILE ] || [ ! `stat --format="%Y" requirements.txt` -eq $(cat $FILE) ];
then
echo "Updating requirements..."
pip install -U -r requirements.txt
#!/bin/bash
# This script create a report for jenkins violations plugin
# Author: AxiaCore S.A.S. http://axiacore.com
echo "Generating cloc report..."
mkdir -p reports
cloc --by-file --exclude-dir=static,migrations,libs,vendor,reports --exclude-ext=min.js,min.css --exclude-lang=make --quiet --csv "`pwd`/" | egrep -v 'Counting|language' | awk -F, '{ if ($1 == "Bourne Again Shell") {language="shell"} else if ($1 == "Bourne Shell") {language="shell"} else { language=tolower($1) } n=split($2, basedir, "/"); folder=basedir[n-1]; print $5"\t"language"\t"folder"\t"$2 }' > reports/cloc.report
echo "Done"
@camilonova
camilonova / jshint_report.sh
Last active December 17, 2015 05:19
Generate a jshint report for jenkins violations plugin
#!/bin/bash
# This script create a report for jenkins violations plugin
# Make sure you have a .jshintignore file to exclude paths from the report
# Author: AxiaCore S.A.S. http://axiacore.com
echo "Generating jshint report..."
mkdir -p reports
jshint --reporter=jslint app/media/js/ | sed -E 's?<file name="(.*)\?">?<file name="'"`pwd`"'/\1">?' > reports/jshint.xml
echo "Done"
@camilonova
camilonova / views.py
Created June 26, 2013 18:50
redactor S3 integration
@staff_member_required
def generate_s3_auth_link(request):
"""Genera una url de autenticación para subir imagenes a amazon S3.
Utilizada en el admin por el editor de texto redactor.
"""
file_path = 'inlines/%s' % request.GET['name']
headers = {
'Content-Type': request.GET['type'],
'x-amz-acl': 'public-read'
}