Skip to content

Instantly share code, notes, and snippets.


Percy Perez percyperez

View GitHub Profile
percyperez /
Created Aug 12, 2014
This script starts the virtual machine, ssh into the VM and then runs django's run server
cd ~/sandbox/git/moreau/devel/cms_dev/src/storyville
vagrant up
vagrant ssh -c 'cd ~/devel/cms_dev/src/storyville/medley/ && med rs'
percyperez / gist:034a2c2ca66603fcf67e
Created May 23, 2014
Get populated data from subdocument excluding specific fields
View gist:034a2c2ca66603fcf67e
var populate_data_from = 'trainers tags',
video_data = {
path: 'videos',
model: 'Video',
select: 'title description legacy_video videofiles.sources.10'
excludes = '-royalties';
* @return {object} A single collection with videos, tags and trainers
percyperez / collection.js
Created Apr 14, 2014
Promise chain using q and Mongoose models. Passing result from previous promise to another
View collection.js
// The route
var Q = require('q');
module.exports = function(app) {
var promise = require('./path/to/promise'),
promise.init(app);'someurl/add', function(req, res, next) {
Q.fcall(promise.createModel1, req.body)
percyperez /
Created Jun 4, 2013
Signal function to auto-create ApiKey objects when using tastypie ApiKeyAuthentication.
# Work around the ImportError: cannot import name create_api_key
# Issue
class User(AbstractUser):
@receiver(post_save, sender=User)
def create_user_api_key(sender, **kwargs):
percyperez / gist:5414079
Created Apr 18, 2013
Custom User Model with Django 1.5 due to "relation auth_user doesn't exist..." error using AbstractUser class
View gist:5414079
from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from .models import User # Your custom user model
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = User
percyperez / gist:4288072
Created Dec 14, 2012
Regular expression for validating time hh:mm am|pm
View gist:4288072
re = /(^(\d{1,2}):(\d{2})\s?(?:am|pm)?)$|^\d{1}(?:am|pm)$/i;
var reminder = (attributes.reminder || '').replace(/\./g, '').replace(/\s/g, '');
if (reminder !== '' && !reminder.match(re)) {
return "Enter valid time ie 3:30 pm or 5pm";
/* match result
12:00 pm
6 pm
percyperez / get_avatar_url
Created Jul 31, 2012
Get user avatar url from Twitter, FB via django-social-auth
View get_avatar_url
def get_avatar_url(request, backend, response, *args, **kwargs):
"""Pipeline to get user avatar from Twitter/FB via django-social-auth"""
avatar_url = ''
if isinstance(backend, FacebookBackend):
avatar_url = '' \
% response['id']
elif isinstance(backend, TwitterBackend):
avatar_url = response.get('profile_image_url', '')
request.session['avatar_url'] = avatar_url
percyperez / gist:1918232
Created Feb 26, 2012
Convert view for lazysignup with template_name
View gist:1918232
def convert(request, form_class=UserCreationForm,
return direct_to_template(request, template_name, {
You can’t perform that action at this time.