This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SignalModel(models.Model): | |
"""A Model mixin class that lets you put your signal handler methods back into your Model class.""" | |
@classmethod | |
def _sig_pre_delete(cls, instance, *args, **kwargs): | |
"""dispatch the pre_delete method to a regular instance method. """ | |
return instance.sig_pre_delete(*args, **kwargs) | |
@classmethod | |
def _sig_post_delete(cls, instance, *args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(N): | |
# 1. convert number to binary | |
# N > 0 | |
# 2. figure out binary period. | |
# P > 0 | |
# P <= Q/2 | |
# Loop through all values of P until you find one. | |
words = set() | |
binStr = bin(N)[2:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $(canvas) - is the canvas element we want to export | |
# svgfix - https://code.google.com/p/svgfix/ | |
svg = svgfix($(canvas).html()) | |
buffer = document.createElement('canvas'); | |
buffer.width = width | |
buffer.height = height | |
# canvg - https://code.google.com/p/canvg/ | |
canvg(buffer, svg) | |
window.setTimeout -> | |
# Give some time for the canvas to be "drawn" so we can export it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from httplib import HTTPResponse | |
import json | |
import logging | |
import urllib2 | |
from django.conf import settings | |
from django.http import HttpResponse | |
import oauth2 | |
from rest_framework.exceptions import PermissionDenied | |
from rest_framework.filters import SearchFilter, OrderingFilter, DjangoFilterBackend | |
from rest_framework.views import APIView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GETAPIFacebookTokenAuthenticationResource(ModelResource): | |
""" | |
Authenticates the user via facebook and returns an APIToken for them. | |
""" | |
class Meta(object): | |
queryset = ApiKey.objects.all() | |
resource_name = 'authenticate' | |
fields = ['user', 'key'] | |
allowed_methods = ['get'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Stuff | |
*/ | |
body { | |
font-family: helvetica; | |
font-size: 12px; | |
line-height: 28px; | |
} | |
#top { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import logging | |
from django.core.cache import cache | |
from django.utils.datetime_safe import datetime | |
LOGGER = logging.getLogger(__name__) | |
class RateLimit(object): | |
''' | |
Naive rate limiting helper class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.core.mail import EmailMessage, EmailMultiAlternatives | |
from django.template import Context, TemplateDoesNotExist | |
from django.template.loader import get_template | |
from django.utils.html import strip_tags | |
import re | |
from os.path import commonprefix | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What will the below code print out? | |
"use strict"; | |
var asimsVar = 3; | |
asimVar = 1; | |
console.log(asimVar); |
OlderNewer