Skip to content

Instantly share code, notes, and snippets.

View cmdelatorre's full-sized avatar
:octocat:
Litox

Carlos de la Torre cmdelatorre

:octocat:
Litox
View GitHub Profile
@cmdelatorre
cmdelatorre / id3.py
Last active February 22, 2018 16:03
Desicion tree classifier (ID3) algortihm
"""
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 / Backbone.django_csrf.sync.coffee
Created August 25, 2015 14:09
Integrate Backbone with Django: Add CSRF Token to Backbone Ajax calls
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')
# 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 / export.py
Last active August 29, 2015 14:04
Synthetic example of 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