Skip to content

Instantly share code, notes, and snippets.

View cansadadeserfeliz's full-sized avatar

Vera cansadadeserfeliz

  • Desparchado.co
  • Bogotá
View GitHub Profile
@cansadadeserfeliz
cansadadeserfeliz / gist:9671809
Last active August 29, 2015 13:57
Filter values list
>>> Airport.objects.filter(
iata_code='DME',
).values_list(
'iata_code',
'city__name',
'city__country__name',
)
[(u'DME', u'Moscow', u'Russia')]
@cansadadeserfeliz
cansadadeserfeliz / gist:9810462
Last active August 29, 2015 13:57
Django: add empty choice to СhoiceField for ModelForm
from django.db import models
class Project(models.Model):
name = models.CharField(max_length=140)
parent = models.ForeignKey('self', blank=True, null=True)
class ProjectForm(ModelForm):
def __init__(self, *args, **kwargs):
super(ProjectForm, self).__init__(*args, **kwargs)
ordered = []
@cansadadeserfeliz
cansadadeserfeliz / gist:9811875
Last active August 29, 2015 13:57
Python: get days, hours, minutes and seconds form timestamp
import datetime
duration = datetime.timedelta(seconds=1823723) # 21 days, 2:35:23
days, seconds = duration.days, duration.seconds # (21, 9323)
hours = seconds // 3600 # 2
minutes = (seconds % 3600) // 60 # 35
seconds = (seconds % 60) # 23
# Installation: https://help.ubuntu.com/community/PostgreSQL
# Creating a user: http://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist
# Set password: http://stackoverflow.com/a/7696398/914332
# make dump of existing database
$ pg_dump -O -U postgres database_name | gzip > /tmp/dump.sql.gz
# create dump without data
$ pg_dump test_db_development -s > /tmp/createdb.sql
@cansadadeserfeliz
cansadadeserfeliz / pipeline.py
Last active December 10, 2018 21:03
Django: python-social-auth configuration and pipeline to get users email, full name and save avatar for Facebook, Twitter, LinkedIn and Google http://blog.vero4ka.info/blog/2015/03/02/django-python-social-auth-configuration-and-pipeline-to-get-users-information/
def update_user_social_data(strategy, *args, **kwargs):
"""Set the name and avatar for a user only if is new.
"""
print 'update_user_social_data ::', strategy
if not kwargs['is_new']:
return
full_name = ''
backend = kwargs['backend']
@cansadadeserfeliz
cansadadeserfeliz / settings.py
Last active August 29, 2015 13:57
Python, Facebook, python-social-auth: get a list of Facebook friends with their name, location, profile picture and url to profile page
SOCIAL_AUTH_FACEBOOK_SCOPE = [
'email',
'user_friends',
'friends_location',
]
@cansadadeserfeliz
cansadadeserfeliz / gist:9923987
Last active August 29, 2015 13:57
Install Pillow or pyOpenSSL in MAC
export CPPFLAGS=-Qunused-arguments
export CFLAGS=-Qunused-arguments
brew install libjpeg
#pip install Pillow
#pip install pyOpenSSL
[user]
name = Vera
email = vera@example.com
[color]
ui = true
[alias]
st = status
ci = commit
last = log -1 HEAD
co = checkout
find . -name "*.pyc" -exec rm '{}' ';'
@cansadadeserfeliz
cansadadeserfeliz / gist:10378958
Created April 10, 2014 12:53
install lxml on mac
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
pip install lxml