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
/** | |
* A simple preforking echo server in C. | |
* | |
* Building: | |
* | |
* $ gcc -Wall -o echo echo.c | |
* | |
* Usage: | |
* | |
* $ ./echo |
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
#!/usr/bin/env python | |
# | |
### patch socket and tornado | |
import gevent.monkey; gevent.monkey.patch_all() | |
import gtornado.monkey; gtornado.monkey.patch_all() | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.options |
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 time | |
from django.utils.http import http_date | |
AJAX_NEGATIVE_CHECK_EXPIRES = 60 # object is still available | |
AJAX_POSITIVE_CHECK_EXPIRES = 60*10 # if object is not available (or taken) | |
def check_ajax(request): | |
# do stuff here | |
timeout = AJAX_NEGATIVE_CHECK_EXPIRES if avail else AJAX_POSITIVE_CHECK_EXPIRES |
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
#!/usr/bin/env python | |
# Parses a .py file and look for for-else constructs | |
# Usage: find_forelse.py some_python_file.py | |
import sys | |
import ast | |
def check_file(filename): | |
with open(filename, "r") as f: |
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
# These are some commands to copy and paste into a manage.py shell session | |
# in order to find out what SQL queries are generated by a view | |
## turn on DEBUG so that ``connection.queries`` gets populated | |
from django.conf import settings | |
settings.DEBUG = True | |
from django.db import connection | |
## handy function for printing the queries |
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 django.http import QueryDict | |
class FakeRequest(object): | |
pass | |
request = FakeRequest() | |
request.GET = QueryDict('a=1&b=2') | |
request.META = {} | |
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
# This allows you to maintain your Django cache settings in Django 1.3 style i.e. settings.CACHE | |
# and convert it to the old settings.CACHE_BACKEND url so that you can run it under Django 1.2 or earlier | |
from django.core.exceptions import ImproperlyConfigured | |
CACHE_BACKEND_MAP = { | |
'django.core.cache.backends.db.DatabaseCache': 'db', | |
'django.core.cache.backends.dummy.DummyCache': 'dummy', |
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
VERSION="0.9.9" | |
BUILD="betable1" | |
set -e -x | |
# Keep track of the original working directory. | |
OLDESTPWD="$PWD" | |
# Work in a temporary directory. | |
cd "$(mktemp -d)" |
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
#!/bin/sh | |
# | |
# install-root-key.sh | |
# | |
# This script downloads the public key from the "cloud" environment. | |
if [ ! -d /root/.ssh ]; then | |
mkdir -p /root/.ssh | |
chmod 700 /root/.ssh | |
fi |
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
/* | |
* Copyright (c) 2013 by Wil Tan <[email protected]> | |
* | |
* Based on dump_dns.c from the dnscap <https://www.dns-oarc.net/tools/dnscap> | |
* originally written by Paul Vixie. | |
* | |
* Copyright (c) 2007 by Internet Systems Consortium, Inc. ("ISC") | |
* | |
* Permission to use, copy, modify, and/or distribute this software for any | |
* purpose with or without fee is hereby granted, provided that the above |
OlderNewer