Skip to content

Instantly share code, notes, and snippets.

View mengzhuo's full-sized avatar

Meng Zhuo mengzhuo

View GitHub Profile
@mengzhuo
mengzhuo / WordsDetector.py
Created August 11, 2012 13:57 — forked from lastland/BeyesianAvg.py
尝试用这篇post: http://www.matrix67.com/blog/archives/5044 中的方法实现的一个自动中文抽词算法的Python程序
# -*- coding=utf-8 -*-
import feedparser
import re
import collections
import math
def info_entropy(words):
result = 0
total = sum([val for _, val in words.iteritems()])
for word, cnt in words.iteritems():
@mengzhuo
mengzhuo / Django paginator
Created January 2, 2013 01:22
My paginator
from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
def do_paginator( origin_list, page, max_item_per_page=MAX_ITEM_PER_PAGE):
"""
A paginator like doc says, but using default setting
in the views.py, I'd like to put it this way
do_paginator(list, request.GET.get('page'))
"""
try:
max_item_per_page = int(max_item_per_page)
@mengzhuo
mengzhuo / bigben.py
Last active December 17, 2015 07:39
# -*- coding: utf-8 -*-s
'''
File: bigben.py
Author: Meng Zhuo <[email protected]>
Description: 大笨钟
'''
import time
import logging
import threading
from datetime import datetime
@mengzhuo
mengzhuo / lazyobject
Created August 9, 2013 01:55
Lazy Object Of Python
# encoding: utf-8
__authors__ = (u"Meng Zhuo",)
class SimpleLazyObject(object):
"""Lazy Object impletement of Python
:func: init object or class
:returns: SimpleLazyObject
"""
@mengzhuo
mengzhuo / bug.py
Created October 23, 2013 16:11
Debug
# forms
# ...
AlbumUpdateForm = model_form(Album, db_session=Session,
exclude=[Album.create_at])
#views
# ....
if request.method == "PUT":
form = AlbumUpdateForm(request.form)
@mengzhuo
mengzhuo / toggle-touchpad
Created October 30, 2013 05:38
Toggle TouchPad on Linux with synclient, works/Tested on Ubuntu
#!/bin/sh
synclient TouchpadOff=$((`synclient -l | grep TouchpadOff | awk '{print $3}'`==0))
@mengzhuo
mengzhuo / Tornado-async-maker
Created December 30, 2013 06:01
How Tornado gen.Task making Sync into Async function?
from tornado import gen, ioloop
import urllib2
import re
tre = re.compile('\<title\>(?P<title>[^<]+)',re.IGNORECASE)
from pprint import pformat
@gen.coroutine
def sleep_bug(url):
print 'fetch:'+url
r = yield gen.Task(ioloop.IOLoop.current().add_callback)
print "callback "+ str(r)
getprop
[DEVICE_PROVISIONED]: [1]
[audio.legacy.postproc]: [true]
[bluetooth.isEnabled]: [true]
[dalvik.vm.heapconcurrentstart]: [2097152]
[dalvik.vm.heapidealfree]: [8388608]
[dalvik.vm.heapsize]: [128m]
[dalvik.vm.heapstartsize]: [5m]
[dalvik.vm.heaputilization]: [0.25]
[dalvik.vm.stack-trace-file]: [/data/anr/traces.txt]
@mengzhuo
mengzhuo / INSTALL.md
Created February 22, 2014 05:32 — forked from sztupy/INSTALL.md

rage-quit plugin for oh-my-zsh

based on rage-quit support for bash

HOW TO INSTALL

Put the files below inside ~/.oh-my-zsh/custom/plugins/fuck

Also chmod a+x the flip command.

@mengzhuo
mengzhuo / weakref.py
Last active January 10, 2022 00:24
weakref demo
import weakref
class ExpensiveObject(object):
def __init__(self, name):
self.name = name
def __del__(self):
print '(Deleting %s)' % self
obj = ExpensiveObject('Cake')
r = weakref.ref(obj)