Skip to content

Instantly share code, notes, and snippets.

View vinta's full-sized avatar
🩸
爛命一條

Vinta Chen vinta

🩸
爛命一條
View GitHub Profile
@Miserlou
Miserlou / middleware.py
Created September 6, 2012 01:47
Django Profiler
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
import sys
import os
import re
import hotshot, hotshot.stats
import tempfile
import StringIO
@lalabear
lalabear / gist:3315650
Created August 10, 2012 17:02 — forked from anonymous/gist:3311403
如何使用迅雷抓美劇
@jboner
jboner / latency.txt
Last active May 6, 2025 10:17
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@crizCraig
crizCraig / gist:2816295
Created May 27, 2012 22:52
Download images from Google Image search using Python
import json
import os
import time
import requests
from PIL import Image
from StringIO import StringIO
from requests.exceptions import ConnectionError
def go(query, path):
"""Download full size images from Google image search.
@vmihailenco
vmihailenco / tastypie_logging.py
Created April 14, 2012 08:29
Logging mixin for Django tastypie
class LoggingMixin(object):
def dispatch(self, request_type, request, **kwargs):
logger.debug(
'%s %s %s' %
(request.method, request.get_full_path(), request.raw_post_data))
try:
response = super(LoggingMixin, self).dispatch(
request_type, request, **kwargs)
except (BadRequest, fields.ApiFieldError), e:
@reorx
reorx / encoding_converter.py
Created April 4, 2012 05:21
char detect & convert
#!/usr/bin/python
# -*- coding: utf-8 -*-
import chardet
BROTHER_ENCODINGS = [
('GB2312', 'GBK', 'GB18030'),
]
@anderser
anderser / api.py
Created March 26, 2012 14:31
Cached tastypie model resource
class CachedModelResource(ModelResource):
def create_response(self, *args, **kwargs):
resp = super(CachedModelResource, self).create_response(*args, **kwargs)
resp['Cache-Control'] = "max-age=600"
return resp
@hrldcpr
hrldcpr / tree.md
Last active January 6, 2025 22:43
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@bohde
bohde / tags.py
Created January 30, 2012 03:25
Using django-taggit with django-tastypie
from tastypie.fields import ListField
class TaggedResource(ModelResource):
tags = ListField()
class Meta:
queryset = Model.objects.all()
def build_filters(self, filters=None):
if filters is None: