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
View summarize.py
#!/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
wil / link_header.py
Last active Dec 20, 2015 — forked from mnot/link_header.py
HTTP Link header parsing routines originally adapted from [Mark Nottingham's gist](https://gist.github.com/mnot/210535) This version adds a `parse_link_value_by_rel` convenience function to address a common use case.
View link_header.py
@wil
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 <wil@cloudregistry.net>
*
* 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
@wil
wil / install-root-key.sh
Created Jul 10, 2013
downloads the public key from the "cloud" environment
View install-root-key.sh
#!/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
View graphite-deb.sh
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)"
@wil
wil / convert_cache_setting.py
Created Oct 8, 2012
Django 1.3 CACHE_BACKEND settings backward compatibility
View convert_cache_setting.py
# 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',
@wil
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):
pass
request = FakeRequest()
request.GET = QueryDict('a=1&b=2')
request.META = {}
@wil
wil / django_sql_debug.py
Created Jan 3, 2012
Django Production SQL Debugging in the manage.py shell
View django_sql_debug.py
# 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
@wil
wil / find_forelse.py
Created Oct 24, 2011
Look for the for/else construct in python code
View find_forelse.py
#!/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:
@wil
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
timeout = AJAX_NEGATIVE_CHECK_EXPIRES if avail else AJAX_POSITIVE_CHECK_EXPIRES
You can’t perform that action at this time.