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
# Example usage... | |
from admin_util import ImprovedModelForm | |
class DialogAdmin(ImprovedModelForm): | |
raw_id_fields = ("forum", "user", ...) # "forum" and "user" are ForeignKeys | |
... |
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 atexit | |
import subprocess | |
from django.core.management.commands.runserver import BaseRunserverCommand | |
from django.core.servers.basehttp import AdminMediaHandler | |
from django.conf import settings | |
# Patch runserver to run the sass and coffeesscript compilers automatically | |
class Command(BaseRunserverCommand): | |
active_processes = [] |
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 KeyToNumMapper(object): | |
counter = 0 | |
mapper_key_int = {} | |
mapper_int_key = {} | |
def __init__(self, initial): | |
map(self.add_key, initial) | |
def add_key(self, key): | |
if key in self.mapper_key_int: |
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 -*- | |
from django.core.management.base import BaseCommand | |
from django.contrib.auth.models import User | |
from emailuser.models import UserProfile | |
from socialdata.models import SocialData | |
class Command(BaseCommand): | |
def _has_relations(self, related_objects, user, whitelist=(User, UserProfile, SocialData)): | |
for related in related_objects: | |
model = related.model |
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 hashlib | |
from random import random | |
from multiprocessing import Process, Array | |
from ctypes import c_char | |
CPU_CORES = 4 | |
def new_candidate(prev_hash, seed): | |
return prev_hash[:32] + seed |
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 -*- | |
from lxml.html import fromstring | |
import os | |
import csv | |
import requests | |
def _get_payload_for_code(code): | |
parameters = { | |
"i_%s_3" % code: "on", | |
"visaAG": "on", |
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 Object: | |
attributes = ["myattr", | |
"anotherattr", | |
"attr1", | |
"someattr", | |
"attr5"] | |
code = "def __init__(self" | |
for att in attributes: | |
code = code + ", " + att + " = None" | |
code = code + "):\n" |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
html, body { height: 100%; } | |
body { font-size: 4em; color: rgba(0,0,0,0.1); } | |
body.noscroll { | |
overflow: hidden; | |
} |
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
/* | |
DOCUMENTATION: | |
This script can be embedded on any page with Kundo Chat, and will change the contents | |
of an element on the page, depending on if the customer can start a new chat or not. | |
To change what's shown, change CHAT_AVAILABLE_HTML and CHAT_UNAVAILABLE_HTML to | |
anything you want. To add a button that starts the chat, add a call to | |
window.$kundo_chat.start_chat() |
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 gensim.models import TfidfModel | |
from gensim.corpora import Dictionary | |
class MyCorpus: | |
def __init__(self, documents): | |
self.documents = documents | |
self.dictionary = Dictionary(documents) | |
def __iter__(self): |
OlderNewer