Skip to content

Instantly share code, notes, and snippets.

View gnrfan's full-sized avatar

Antonio Ognio gnrfan

View GitHub Profile
@gnrfan
gnrfan / Populate circuits
Created June 5, 2012 23:44 — forked from PuercoPop/Populate circuits
small snippet to replicate circuits in development database
import random
from circuits.models import Circuit
from user_profile.models import UserProfile
circuits = Circuit.objects.all()
profiles = UserProfile.objects.all()
countdown = 100
while countdown > 0:
circuit = random.choice( circuits )
@gnrfan
gnrfan / change_admin_password.py
Created June 7, 2012 04:01
Change Django admin password to "admin"
from django.contrib.auth.models import User
user = User.objects.get(username='admin')
user.set_password("admin")
user.save()
@gnrfan
gnrfan / second_admin_django.py
Created June 7, 2012 09:16
Create another admin account in Django
from django.contrib.auth.models import User
another_admin = User(
username='admin2',
email='[email protected]',
is_superuser=True,
is_staff=True
)
another_admin.set_password('password')
@gnrfan
gnrfan / generate_salt.py
Created June 9, 2012 15:07
Generate salt for use when hashing passwords
from os import urandom
from base64 import b64encode
DEFAULT_SALT_LENGTH = 12
def generate_salt(length=DEFAULT_SALT_LENGTH):
salt = b64encode(urandom(length))
return salt
if __name__ == '__main__':
@gnrfan
gnrfan / password_hashing.py
Created June 10, 2012 03:50
Proper password hashing for web apps in Python
"""
Proper password hashing for storing in a web app.
You will need the "simple-pbkdf2" package from PyPi with either
"pip install simple-pbkdf2" or "easy_install simple-pbkdf2"
(c) 2012 - Antonio Ognio <[email protected]>
"""
from os import urandom
@gnrfan
gnrfan / gist:2925183
Created June 13, 2012 16:39
App-level configuration in Django
## app1/constants.py
MY_VAR = 100
## app1/settings.py
from django.conf import settings
from app1 import constants
MY_VAR = getattr(settings, 'MY_VAR', constants.MY_VAR)
@gnrfan
gnrfan / gnrfan-vimrc
Created August 18, 2012 21:42
VIM rc file by gnrfan
syntax on
set tabstop=2
set shiftwidth=2
set softtabstop=2
set smarttab
set expandtab
set nobackup
" auto indent
@gnrfan
gnrfan / models.py
Created September 10, 2012 16:12
An example of chained foreign keys using django-smart-selects from PyPi.
from django.conf import settings
from django.contrib.gis.db import models
from smart_selects.db_fields import ChainedForeignKey
from common.models import AuditableModel
from ubigeos import strings
class Department(models.Model):
"""
A peruvian department.
@gnrfan
gnrfan / gist:3752819
Created September 19, 2012 22:44
Por si necesitan tener letras y digitos a la mano para generar passwords aleatoriamente o cualquier otra cosa
>>> import string
>>> string.digits
'0123456789'
>>> string.hexdigits
'0123456789abcdefABCDEF'
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
@gnrfan
gnrfan / free-volume.sh
Created September 22, 2012 04:55
Bash script for killing all processes that are using a volume in Mac OS X
#!/bin/bash
# This script helps when you're getting this kind of error on a Mac:
#
# "The volume can’t be ejected because it’s currently in use."
#
# Just copy this script to /usr/bin/free-volume or somewhere else you
# want and then call it passing the path to the volume you want
# to free.
#
# Example: free-volume /Volumes/Iomega_HDD