Skip to content

Instantly share code, notes, and snippets.

View kxxoling's full-sized avatar
💉
💊💊💊

Kane Blueriver kxxoling

💉
💊💊💊
View GitHub Profile
@kxxoling
kxxoling / copythclipboard.js
Created October 31, 2013 07:48
JavaScript实现“复制到剪贴板”功能
copyToClipboard = function(txt) {
if(window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData(”Text”, txt);
} else if(navigator.userAgent.indexOf(”Opera”) != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege(”UniversalXPConnect”);
} catch (e) {
import sys
print 'Dive in'
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
print 'This message will be logged instead of displayed'
sys.stdout = saveout
fsock.close()
@kxxoling
kxxoling / CalculatePiWithMapReduce.py
Created April 22, 2014 03:43
以计算 Pi 为例介绍 Map/Reduce
#coding=utf-8
import random
import multiprocessing
from multiprocessing import Process
class MapReduce(object):
def __init__(self, map_func, reduce_func, workers_num=None):
self.map_func = map_func
from flask import Flask, request, jsonify, abort, make_response
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
tar -cv ORIG_FILE | docker exec -i 42web tar x -C TARGET_DIR
def replace_words(text, word_dic):
yo = re.compile('|'.join(map(re.escape, word_dic)))
def translate(mat):
return word_dic[mat.group(0)]
return yo.sub(translate, text)
body{
font-family: NotoSansHans-Light, AvenirNext-Regular, proxima-nova, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
font-family: Helvetica, Tahoma, Arial, STXihei, "华文细黑", "Microsoft YaHei", "微软雅黑", SimSun, "宋体", Heiti, "黑体", sans-serif;
}
class Pipe(object):
def __init__(self, func):
self.func = func
def __ror__(self, other):
def generator():
for obj in other:
if obj is not None:
yield self.func(obj)
return generator()
@kxxoling
kxxoling / grep ip log
Created February 26, 2015 10:58
grep top 20 ip
cat localhost.access_log* |awk '{print $1 " " substr($4,14,5)}'|sort -n|uniq -c|sort -nr|head -20
<a href="https://plus.google.com/hangouts/_?gid=gh-windrunner-info" style="text-decoration:none;">
<img src="https://ssl.gstatic.com/s2/oz/images/stars/hangout/1/gplus-hangout-24x100-normal.png"
alt="Start a Hangout"
style="border:0;width:100px;height:24px;"/>
</a>