Skip to content

Instantly share code, notes, and snippets.

@baojie
baojie / rc.lua
Last active December 21, 2015 16:49
awesome config, with dmenu support, save as ~/.config/awesome/rc.lua
-- Standard awesome library
require("awful")
require("awful.autofocus")
require("awful.rules")
-- Theme handling library
require("beautiful")
-- Notification library
require("naughty")
-- Load Debian menu entries
import pycosat
cnf = [[1, -5, 4], [-1, 5, 3, 4], [-3, -4]]
#(x or not x5 or x4) and (not x1 or x5 or x3 or x4) and (not x3 or not x4)
# list a solution
pycosat.solve(cnf)
# OUT: [1, -2, -3, -4, 5]
# x1 = x5 = True, x2 = x3 = x4 = False
import basehash
base62 = basehash.base62()
encoded = base62.encode(2013)
decoded = base62.decode('WT')
print encoded, decoded
# OUT: WT 2013
hashed = base62.hash(2013, 8)
unhashed = base62.unhash('6LhOma5b')
print hashed, unhashed
# OUT: 6LhOma5b 2013
@baojie
baojie / result.txt
Last active December 21, 2015 02:09
sh python lib performance
$ time ./tailme.sh
./tailme.sh 0.01s user 0.00s system 12% cpu 0.093 total
$ time python ./tailme.py
0.28s user 0.21s system 35% cpu 1.372 total
$ time python ./tailme.envoy.py
0.09s user 0.06s system 44% cpu 0.330 total
$ time python tailme.sarge.py
@baojie
baojie / cass.py
Created August 12, 2013 23:20
pycassa hello world. cassandra
import pycassa
pool = pycassa.ConnectionPool('Foo')
cf = pycassa.ColumnFamily(pool, 'Yaya')
cf.insert('foo', {'column1': 'val1'})
# OUT: 1376349520115333L
cf.get('foo')
# OUT: OrderedDict([('column1', 'val1')])
cf.insert('foo', {'column1': 'val2'})
# OUT: 1376349532964277L
cf.get('foo')
from batbelt.parallel import worker
@worker()
def test(mot):
print "in %s" % mot
return mot
process = test.start()
for x in range(10):
# Initialize Site object
import mwclient
site = mwclient.Site('commons.wikimedia.org')
site.login(username, password) # Optional
# Edit page
page = site.Pages['Commons:Sandbox']
text = page.edit()
print 'Text in sandbox:', text.encode('utf-8')
page.save(text + u'\nExtra data', summary = 'Test edit')
This file has been truncated, but you can view the full file.
{"contributors": null, "truncated": false, "text": "RT @_pius: Put #indieweb into MBA terms and call it a low-end disruption of current standards. Enterprise IT will race to adopt it. #osfw3c", "in_reply_to_status_id": null, "id": 366197162410909697, "favorite_count": 0, "source": "web", "retweeted": false, "coordinates": null, "entities": {"symbols": [], "user_mentions": [{"id": 12920742, "indices": [3, 9], "id_str": "12920742", "screen_name": "_pius", "name": "Pius"}], "hashtags": [{"indices": [15, 24], "text": "indieweb"}, {"indices": [132, 139], "text": "osfw3c"}], "urls": []}, "in_reply_to_screen_name": null, "in_reply_to_user_id": null, "retweet_count": 3, "id_str": "366197162410909697", "favorited": false, "retweeted_status": {"contributors": null, "truncated": false, "text": "Put #indieweb into MBA terms and call it a low-end disruption of current standards. Enterprise IT will race to adopt it. #osfw3c", "in_reply_to_status_id": null, "id": 365564200224964609, "favorite_count": 2, "source": "<a href=\
Navigating the current page:
? show the help dialog for a list of all available keys
h scroll left
j scroll down
k scroll up
l scroll right
gg scroll to top of the page
G scroll to bottom of the page
@baojie
baojie / githubpy.py
Last active December 20, 2015 21:39
from github import GitHub
gh = GitHub(username='loginname', password='your-password')
gh = GitHub()
u = gh.users('michaelliao').get()
u.name
# OUT: u'Michael Liao'
gh.repos('michaelliao')('githubpy').issues \
.get(state='open', assignee='michaelliao')
# OUT: []
gh.repos('michaelliao')('githubpy').issues \