Skip to content

Instantly share code, notes, and snippets.

View hcarvalhoalves's full-sized avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
Internal Server Error: /v1/cinema/
Traceback (most recent call last):
File "/Users/hcalves/.virtualenvs/claquete/lib/python2.7/site-packages/tastypie/resources.py", line 192, in wrapper
response = callback(request, *args, **kwargs)
File "/Users/hcalves/.virtualenvs/claquete/lib/python2.7/site-packages/tastypie/resources.py", line 397, in dispatch_list
return self.dispatch('list', request, **kwargs)
File "/Users/hcalves/.virtualenvs/claquete/lib/python2.7/site-packages/tastypie/resources.py", line 427, in dispatch
response = method(request, **kwargs)
File "/Users/hcalves/.virtualenvs/claquete/lib/python2.7/site-packages/tastypie/resources.py", line 1029, in get_list
objects = self.obj_get_list(request=request, **self.remove_api_resource_names(kwargs))
@hcarvalhoalves
hcarvalhoalves / gist:2244820
Created March 29, 2012 23:16
No such table on ./manage.py testserver with :memory: database
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.4
Python Version: 2.7.1
Installed Applications:
('django.contrib.auth',
@hcarvalhoalves
hcarvalhoalves / nginx_status_codes.rb
Created May 1, 2012 17:58 — forked from mipearson/nginx_status_codes.rb
Very simple munin plugin to graph nginx HTTP error codes
#!/usr/bin/env ruby
CODES = {
'400' => 'Bad Request',
'401' => 'Unauthorized',
'403' => 'Forbidden',
'404' => 'Not Found',
'405' => 'Method Not Allowed',
'406' => 'Not Acceptable',
'408' => 'Request Timeout',
@hcarvalhoalves
hcarvalhoalves / postgresql_fields.py
Created August 21, 2012 20:47
Django field for PostgreSQL array
from django.db import models
class IntegerArrayField(models.Field):
__metaclass__ = models.SubfieldBase
def db_type(self, *args, **kwargs):
return "integer[]"
def get_prep_value(self, value):
@hcarvalhoalves
hcarvalhoalves / youtube_regex.py
Created August 30, 2012 00:19
Regex to extract YouTube video ids
import re
YOUTUBE_REGEX = re.compile(r'"http://.+?(/v/|/watch\\?v=)(?P<videoId>[A-Za-z0-9_-]{11}).+?"')
from django.views.generic.list import ListView
from django.conf.urls.defaults import patterns, url
from models import Movie
class MovieListView(ListView):
paginate_by = 50
def get(self, request, *args, **kwargs):
self.filter = MovieFilterSet(data=request.GET, queryset=self.queryset)
@hcarvalhoalves
hcarvalhoalves / storages.py
Created November 7, 2012 22:44
File storage for development server
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage
from django.utils.encoding import filepath_to_uri
from django.utils.log import getLogger
from django.conf import settings
from urllib2 import urlopen, HTTPError
from urlparse import urljoin
class NodeManager(models.Manager):
def get_query_set(self):
qs = super(NodeManager, self).get_query_set()
return qs.select_related('category', 'child_class')
var a = [20, 10, 5, 1];
// Everyday array
a.sort();
// [1, 10, 20, 5]... WTF?
a == [1, 10, 20, 5];
// false
a === [1, 10, 20, 5];
from unicodedata import normalize, category
def unaccent(s):
return unicode(
filter(
lambda c: category(c) != 'Mn',
normalize('NFKD', s.decode('utf-8'))
)
).encode('utf-8')