Skip to content

Instantly share code, notes, and snippets.

import re
# Some mobile browsers which look like desktop browsers.
RE_MOBILE = re.compile(r"(iphone|ipod|blackberry|android|palm|windows\s+ce)", re.I)
RE_DESKTOP = re.compile(r"(windows|linux|os\s+[x9]|solaris|bsd)", re.I)
RE_BOT = re.compile(r"(spider|crawl|slurp|bot)")
def is_desktop(user_agent):
"""
#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
usage=$(
cat <<EOF
$0 [OPTIONS] start/stop
-s set speed default 256Kbit/s
-p set port default 3000
-d set delay default 350ms
@akaihola
akaihola / .gitignore
Last active June 1, 2023 12:30
streaming-json-encoder
*.pyc
/bin
/include
/lib
@bitrut
bitrut / last_commit.py
Created December 18, 2011 20:13
Get timestamp of the last commit in git repository
#!/usr/bin/python
import subprocess
import re
from optparse import OptionParser
def git_version():
p = subprocess.Popen(["git", "log" , '-1', '--date=iso'], stdout=subprocess.PIPE)
out, err = p.communicate()
m = re.search('\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}', out)
@nrabinowitz
nrabinowitz / fitProjection.js
Created February 7, 2012 00:46
D3 function for fitting a projection to geodata
function fitProjection(projection, data, box, center) {
// get the bounding box for the data - might be more efficient approaches
var left = Infinity,
bottom = -Infinity,
right = -Infinity,
top = Infinity;
// reset projection
projection
.scale(1)
.translate([0, 0]);
@rufuspollock
rufuspollock / ckan-datastore.py
Created March 1, 2012 15:39
CKAN DataStore client
#!/usr/bin/env python
import urlparse
import mimetypes
import os
import ConfigParser
import urllib2
import json
import csv
import time
@techtonik
techtonik / caller_name.py
Created March 21, 2012 19:29
Python - inspect - Get full caller name (package.module.function)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.
@karmi
karmi / .gitignore
Created April 12, 2012 10:18
Life Expectancy Choropleth Map
.DS_Store
@hekyou
hekyou / app.py
Created July 17, 2012 06:55
gevent+websocket+ginkgo+Flask
import os
from ginkgo import Service
from ginkgo.async.gevent import WSGIServer
from geventwebsocket.handler import WebSocketHandler
from flask import Flask, render_template
class WebSocket(Service):
def __init__(self):
self.add_service(WSGIServer(('127.0.0.1', 8001), self.handle,
handler_class=WebSocketHandler))
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: