Skip to content

Instantly share code, notes, and snippets.

@victorono
victorono / decorators.py
Last active December 28, 2015 14:59
Show page 404 for register not found django
def not_found(method):
def wrap(*args, **kwargs):
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
try:
return method(*args, **kwargs)
except ObjectDoesNotExist, ex:
raise Http404(ex.message)
@victorono
victorono / unicode.py
Last active August 1, 2020 21:58
Eliminar tildes string python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unicodedata
def elimina_tildes(cadena):
s = ''.join((c for c in unicodedata.normalize('NFD',unicode(cadena)) if unicodedata.category(c) != 'Mn'))
return s.decode()
string_acentos = 'café'.decode('utf-8')
@victorono
victorono / attributes.js
Created November 25, 2013 01:58
All attributes element jQuery
(function(old) {
$.fn.attr = function() {
if(arguments.length === 0) {
if(this.length === 0) {
return null;
}
var obj = {};
$.each(this[0].attributes, function() {
if(this.specified) {
@victorono
victorono / entities.py
Created November 28, 2013 14:38
unescape html
import HTMLParser
h = HTMLParser.HTMLParser()
s = h.unescape('© 2010')
print s
@victorono
victorono / cache_user.py
Created December 2, 2013 15:44
cache by user django
from django.views.decorators.cache import cache_page
from functools import wraps
from django.utils.decorators import available_attrs
def cache_on_auth(timeout):
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
return cache_page(timeout, key_prefix="_auth_%s_" % request.user.is_authenticated())(view_func)(request, *args, **kwargs)
return _wrapped_view
@victorono
victorono / password.py
Created December 9, 2013 18:56
Random password python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from string import digits
from string import letters
def _pw(length=10):
s = ''
for i in range(length):
@victorono
victorono / git_group.txt
Created December 11, 2013 21:34
repository git with permission group
sudo groupadd developers
adduser username
usermod -a -G developers username
mkdir repository.git
cd !$
git --bare init
touch readme.md
@victorono
victorono / python_275.sh
Created December 11, 2013 23:01
Python 2.7.5 CentOS 6
sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python27.repo >> /etc/yum.repos.d/scl.repo'
sudo yum install python27
scl -l
python27
scl enable python27 bash
python -V
@victorono
victorono / upgrade_python.sh
Created December 15, 2013 23:26
Upgrade python OS X 10.9 with brew
### Makes you owner of /usr/local
$ sudo chown -R `whoami` /usr/local
### Force uninstalls failed python
$ brew uninstall -f python
### Clear the brew cache
$ rm -rf `brew --cache`
### Cleanup - cleans up old homebrew files
@victorono
victorono / mysql_python.sh
Created December 15, 2013 23:38
Install mysql and mysql-python os x
# first install mysql
brew install mysql
# second export path mysql
PATH="$PATH:/usr/local/Cellar/mysql/5.6.15/bin/"
# finally install mysql-python
sudo pip install mysql-python --upgrade