This file contains hidden or 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 wat(obj): | |
| ... sys.stdout.write("WAT") | |
| ... | |
| >>> sys.displayhook = wat | |
| >>> "I broke the REPL" | |
| WAT>>> |
This file contains hidden or 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 sys | |
| import os | |
| from pdb import Pdb | |
| banner = """Usage: | |
| %(command)s @<module>:<linenumber> ... <filename> <args> | |
| Use @<module>:<linenumber> to set one or multiple breakpoints. | |
| <module> may be an absolute path to a module file, or relative to sys.path. |
This file contains hidden or 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 Player | |
| def initialize | |
| @max_health = 20 | |
| @last_health = @max_health | |
| @taking_damage = false | |
| @directions = [:backward, :forward] | |
| @current_direction = :forward | |
| @reached_wall = false | |
| end | |
This file contains hidden or 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 unicodedata import normalize, category | |
| def unaccent(s): | |
| return unicode( | |
| filter( | |
| lambda c: category(c) != 'Mn', | |
| normalize('NFKD', s.decode('utf-8')) | |
| ) | |
| ).encode('utf-8') |
This file contains hidden or 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
| 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]; |
This file contains hidden or 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 NodeManager(models.Manager): | |
| def get_query_set(self): | |
| qs = super(NodeManager, self).get_query_set() | |
| return qs.select_related('category', 'child_class') |
This file contains hidden or 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 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 |
This file contains hidden or 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 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) |
This file contains hidden or 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 re | |
| YOUTUBE_REGEX = re.compile(r'"http://.+?(/v/|/watch\\?v=)(?P<videoId>[A-Za-z0-9_-]{11}).+?"') |
This file contains hidden or 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 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): |