Skip to content

Instantly share code, notes, and snippets.

@thoslin
thoslin / douban_zufang.py
Created October 21, 2015 03:19
pyspider douban group
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2015-10-21 10:27:30
# Project: douban_zufang
import re
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
@thoslin
thoslin / statsd.output
Created May 9, 2014 07:06
statsd output
{ counters:
{ 'statsd.bad_lines_seen': 3,
'statsd.packets_received': 17,
'window.performance.navigation.redirectCount': 0,
'window.performance.navigation.type.navigate': 1 },
timers:
{ 'view.listing.views.list_view.GET': [ 1993 ],
'view.listing.views.GET': [ 1993 ],
'view.GET': [ 1993 ],
'window.performance.timing.domComplete': [ 7273 ],
<?php
/**
* A simple PHP web scraper
* >> php -f scraper.php
*/
//echo "Hello World!";
/**
* Fire a get request
@thoslin
thoslin / my_workaround.html
Created January 10, 2014 10:36
Asynchronously load openx
<html>
<head>
<script type="text/javascript">
var adQueue = [];
var OA_show = function(position, output) {
// queue the function call and create a place holder
adQueue.push([position, output]);
document.write("<div id='_"+position+"'></div>");
}
</script>
@thoslin
thoslin / old_view.py
Last active January 2, 2016 16:19
Use celery to refactor a time consuming view.
def export(request, **kwargs):
qs = get_queryset(**kwargs)
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=foo.csv'
writer = csv.writer(response, dialect=csv.excel)
for i in qs:
writer.writerow([i.foo, i.bar, i.baz, ...])
@thoslin
thoslin / base62.py
Created October 30, 2013 06:26
Python implementation for generating Tiny URL- and bit.ly-like URLs
#!/usr/bin/env python
_alphabet = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"
_base = len(_alphabet)
def encode(n):
"""
Encode a number using the alphabet above
@thoslin
thoslin / add_post_render_callback.py
Created July 24, 2013 02:02
add_post_render_callback
if timeout:
cache_key = learn_cache_key(request, response, timeout, self.key_prefix, cache=self.cache)
# Ensure the template is literally rendered. Cause if you are using TemplateResponse. The rendering doesn't happen
# Until it reach the bottom of response middleware
# Actually it happens in django wsgi handler which lives at django/core/handlers/base.py
if hasattr(response, 'render') and callable(response.render):
response.add_post_render_callback(
lambda r: self.cache.set(cache_key, r, timeout)
)
else:
@thoslin
thoslin / gist:4711791
Last active December 12, 2015 04:08
Setting up Vagrant
export VENV=$VIRTUAL_ENV
mkdir $VENV/packages && cd $VENV/packages
curl -O http://oligarchy.co.uk/xapian/1.2.8/xapian-core-1.2.8.tar.gz
curl -O http://oligarchy.co.uk/xapian/1.2.8/xapian-bindings-1.2.8.tar.gz
tar xzvf xapian-core-1.2.8.tar.gz
tar xzvf xapian-bindings-1.2.8.tar.gz
cd $VENV/packages/xapian-core-1.2.8
@thoslin
thoslin / settings.py
Created May 16, 2012 01:39
django-markitup settings
# django-markitup settings
# The MARKITUP_FILTER setting defines how markup is transformed into HTML on your site.
# This setting is only required if you are using MarkupField or MarkItUp! AJAX preview.
MARKITUP_FILTER = ('markdown.markdown', {'safe_mode': False, 'enable_attributes': True})
# MarkItUp! allows the toolbar button-set to be customized in a Javascript settings file.
MARKITUP_SET = 'markitup/sets/markdown'
# MarkItUp! skins can be specified in a similar manner.