Skip to content

Instantly share code, notes, and snippets.

Avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
View gist:2209659
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 Mar 29, 2012
No such table on ./manage.py testserver with :memory: database
View gist:2244820
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 — forked from mipearson/nginx_status_codes.rb
Very simple munin plugin to graph nginx HTTP error codes
View nginx_status_codes.rb
#!/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 Aug 21, 2012
Django field for PostgreSQL array
View postgresql_fields.py
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 Aug 30, 2012
Regex to extract YouTube video ids
View youtube_regex.py
import re
YOUTUBE_REGEX = re.compile(r'"http://.+?(/v/|/watch\\?v=)(?P<videoId>[A-Za-z0-9_-]{11}).+?"')
View gist:3796643
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 Nov 7, 2012
File storage for development server
View storages.py
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
View gist:4158296
class NodeManager(models.Manager):
def get_query_set(self):
qs = super(NodeManager, self).get_query_set()
return qs.select_related('category', 'child_class')
View i_hate.js
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];
View gist:5223105
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')