Skip to content

Instantly share code, notes, and snippets.

View clvrobj's full-sized avatar

Chi Zhang clvrobj

  • Singapore, Singapore
View GitHub Profile
@clvrobj
clvrobj / .emacs
Created October 11, 2012 06:49
.emacs
(cond
((= 23 emacs-major-version)
(if (file-exists-p "~/.emacs.d/emacs23.el")
(load-file "~/.emacs.d/emacs23.el")))
((= 24 emacs-major-version)
(if (file-exists-p "~/.emacs.d/emacs24.el")
(load-file "~/.emacs.d/emacs24.el")))
)
@clvrobj
clvrobj / gist:3795035
Created September 27, 2012 16:43
Check and add "# -*- coding: utf-8 -*-"
(defun add-py-header ()
"check and add # -*- coding: utf-8 -*-"
(interactive)
(let ((pyheader "# -*- coding: utf-8 -*-"))
(if (not (equal pyheader (buffer-substring-no-properties 1 (1+ (length pyheader)))))
(progn (goto-char 1)
(insert (concat pyheader "\n\n"))))))
# -*- coding: utf-8 -*-
import sys
import os
import fnmatch
def Walk(root='.', recurse=True, pattern='*'):
"""
Generator for walking a directory tree.
Starts at specified root folder, returning files
that match our pattern. Optionally will also
#-*- coding:utf-8 -*-
from optparse import OptionParser
from pyapns import configure, provision, notify, feedback
def send_notify(host, app, cert, token, string, is_feedback):
print 'Sending...\nhost: %s\napp: %s\ndevice: %s\nstring: %s' % (host, app, token, string)
configure({'HOST': host})
if cert:
provision(app, open(cert).read(), 'sandbox')
notify(app, token, {'aps':{'alert': string}})
#ab -r -n 10000 http://127.0.0.1:8880/hello/world
#You have to run Sentry at 127.0.0.1:8000 and replace the following DSN.
from bottle import route, run
@route('/hello/:name')
def index(name='World'):
from raven import Client
client = Client('http://5a77e2293b2e441188dcd03180e47e6d:[email protected]:8000/2')
client.captureMessage('hello world!')
@clvrobj
clvrobj / gist:2290640
Created April 3, 2012 09:26 — forked from disinfeqt/gist:2286703
YYETS Copy
(function(){
var output = '';
for(var i = 0,array = document.querySelectorAll('.hover.filebox')[0].querySelectorAll('li'); i<array.length-1; i++){
if(array[i].querySelector('input').checked && array[i].querySelector('a').href.length > 0 && array[i].querySelector('a').href.match('-----') === null){
output += array[i].querySelector('a').href + '\n';
}
}
copy(output);
})();
@clvrobj
clvrobj / yyets.com.js
Created April 3, 2012 09:19
人人影视yyets.com下载页面添加一个显示选中的下载链接的窗口,方便非ie使用 (dotjs required)
var exposeEd2kCon = $('<input class="button" type="button" value="显示选中链接" style="background-color:#C30604; color:#FFFFFF"/>').click(
function () {
var output = '';
for(var i = 0,array = document.querySelectorAll('.hover.filebox')[0].querySelectorAll('li'); i<array.length-1; i++){
if(array[i].querySelector('input').checked && array[i].querySelector('a').href.length > 0 && array[i].querySelector('a').href.match('-----') === null){
output += array[i].querySelector('a').href + '\n';
}
}
if (!$('#ed2kexpwin').length) {
$('body').append('<div id="ed2kexpwin" style="width:656px;height:168px;left:30px;bottom:0;position:fixed;overflow:scroll;visibility:visible;background-color:#fff;text-align:left;"><textarea rows="8" cols="90"></textarea></div>');
@clvrobj
clvrobj / douban oauth, post miniblog.
Created March 8, 2012 01:45
post miniblog, douban oauth with ruby sinatra
require 'sinatra'
require 'oauth'
API_KEY = ''
API_SECRET = ''
token = ''
secret = ''
post '/miniblog' do
content = params[:content]
r1 = {'a': {'q': 1, 'w': 2}, 'b': {'q': 3, 'w': 4}}
r2 = {'a': {'q': 5, 'w': 7}, 'b': {'q': 8, 'w': 2}}
# ret = {'a': {'q': 6, 'w': 9}, 'b': {'q': 11, 'w': 6}}
def iter_dict(x, y):
if not isinstance(x, dict):
return map(lambda x: sum(x), zip(x, y))
if isinstance(x.values()[0], dict):
return dict(zip(x.keys(), map(lambda x:iter_dict(x[0], x[1]), zip(x.values(), y.values()))))
return dict(zip(x.keys(), iter_dict(x.values(), y.values())))
@clvrobj
clvrobj / contentscript.js
Created February 8, 2012 03:21
Shame on this script, from a chrome extension (nnancliccjabjjmipbpjkfbijifaainp)
if (!pluginnetwork) var pluginnetwork = {};
var failcount = 0;
pluginnetwork.contentscript = function () {
return {
isMarketingEnabled: function () {
if (pluginnetwork.pluginStorage.getItem(pluginnetwork.GLOBALS.PLUGIN_NAMESPACE + '.marketing') == "false") {
return false;
} else {
return true;
}