Skip to content

Instantly share code, notes, and snippets.

Wil Tan wil

Block or report user

Report or block wil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
pip install networkx distance pattern
In Flipboard's article[1], they kindly divulge their interpretation
of the summarization technique called LexRank[2].
wil /
Last active Dec 20, 2015 — forked from mnot/
HTTP Link header parsing routines originally adapted from [Mark Nottingham's gist]( This version adds a `parse_link_value_by_rel` convenience function to address a common use case.
wil / libresolv_query.c
Created Aug 2, 2013
Demonstrates how to send a DNS query and parse response in C using libresolv.
View libresolv_query.c
* Copyright (c) 2013 by Wil Tan <>
* Based on dump_dns.c from the 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
wil /
Created Jul 10, 2013
downloads the public key from the "cloud" environment
# This script downloads the public key from the "cloud" environment.
if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
set -e -x
# Keep track of the original working directory.
# Work in a temporary directory.
cd "$(mktemp -d)"
wil /
Created Oct 8, 2012
Django 1.3 CACHE_BACKEND settings backward compatibility
# 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
'django.core.cache.backends.db.DatabaseCache': 'db',
'django.core.cache.backends.dummy.DummyCache': 'dummy',
wil / fake_django_request
Created Jan 3, 2012
Fake django request useful for calling a view function
View fake_django_request
from django.http import QueryDict
class FakeRequest(object):
request = FakeRequest()
request.GET = QueryDict('a=1&b=2')
request.META = {}
wil /
Created Jan 3, 2012
Django Production SQL Debugging in the shell
# These are some commands to copy and paste into a 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
wil /
Created Oct 24, 2011
Look for the for/else construct in python code
#!/usr/bin/env python
# Parses a .py file and look for for-else constructs
# Usage:
import sys
import ast
def check_file(filename):
with open(filename, "r") as f:
wil / gist:347596
Created Mar 29, 2010
Django Setting Expires Header in XHR Response
View gist:347596
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
You can’t perform that action at this time.