Skip to content

Instantly share code, notes, and snippets.

Carlos de la Torre cmdelatorre

View GitHub Profile
View viewsets.py
# Based on http://stackoverflow.com/a/22922156/1161156
class MultiSerializerViewSetMixin(object):
def get_serializer_class(self):
"""
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
class MyViewSet(MultiSerializerViewSetMixin, ViewSet):
serializer_class = MyDefaultSerializer
@cmdelatorre
cmdelatorre / Backbone.django_csrf.sync.coffee
Created Aug 25, 2015
Integrate Backbone with Django: Add CSRF Token to Backbone Ajax calls
View Backbone.django_csrf.sync.coffee
oldSync = Backbone.sync
Backbone.sync = (method, model, options) ->
csrfSafeMethod = (method) ->
# these HTTP methods do not require CSRF protection
/^(GET|HEAD|OPTIONS|TRACE)$/.test method
options.beforeSend = (xhr, settings) ->
if !csrfSafeMethod(settings.type) and !@crossDomain
xhr.setRequestHeader 'X-CSRFToken', $.cookie('csrftoken')
@cmdelatorre
cmdelatorre / id3.py
Last active Feb 22, 2018
Desicion tree classifier (ID3) algortihm
View id3.py
"""
http://en.wikipedia.org/wiki/ID3_algorithm
http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm
"""
from collections import namedtuple, Counter, defaultdict
from math import log2
@cmdelatorre
cmdelatorre / export.py
Last active Aug 29, 2015
Synthetic example of export.py
View export.py
# # Example of a model in your legacy app:
#
# class OldNotes(models.Model):
# title = models.CharField(max_length=256)
# text = models.TextField()
#
# # Example of a model in one of your new apps, awesomeapp:
#
# HEADER_LEN = 256
You can’t perform that action at this time.