Skip to content

Instantly share code, notes, and snippets.

View onriv's full-sized avatar
🎯
Focusing

onriv onriv

🎯
Focusing
View GitHub Profile
@onriv
onriv / classconvert.py
Created July 26, 2014 09:32
python:文本处理:更换html类名
# -*- coding: utf-8 -*-
# 转换HTML类名
def lines(file):
for line in file: yield line
yield '\n'
def blocks(file):
'''
按照"块(空行分块)"读取文本
@onriv
onriv / cfunc.py
Created July 2, 2014 05:48
python:给函数添加使用次数记录:cfunc.py
# -*- coding: utf-8 -*-
class Cfunc(object):
"""Count function
"""
def __init__(self, func):
super(Cfunc, self).__init__()
self.count = 0
self.func = func
def f(self, *pargs, **kargs):
self.count += 1
@onriv
onriv / tie-tac-toe.js
Created June 27, 2014 17:30
JavaScript:tie-tac-toe:井字棋JS版本:tie-tac-toe.js
var a = document.getElementsByClassName("grid-cell");
var t = document.getElementsByClassName("tile-container")[0];
var old = document.getElementsByClassName("tile-new");
var msg = document.getElementsByClassName("game-message")[0];
var o = [], x = [];
var ot = true;
var player = 1;
for (var i = 8; i >= 0; x[i] = false, o[i--] = false);
for(var i = 0, len1 = a.length; i < len1; i++){
a[i].onclick = function () {
# update 2014-06-19 18:51
# Section Start: dropbox
108.160.166.62 dropbox.com
108.160.165.62 dropbox.com
205.251.196.138 dropbox.com
108.160.166.20 www.dropbox.com
108.160.167.204 www.dropbox.com
108.160.166.13 www.dropbox.com
108.160.165.147 www.dropbox.com
108.160.167.208 www.dropbox.com
@onriv
onriv / scope_test.py
Created June 18, 2014 09:23
python:test:测试:scope_test.py
# -*- coding: utf-8 -*-
def f1():
X = 88
def f2():
print X
return f2
action = f1()
action()
@onriv
onriv / tietactoe.py
Created June 12, 2014 09:11
python:计算机程序设计艺术:tietactoe.py
# -*- coding: utf-8 -*-
def tieTacToe(x, o):
L = [{0,1,2},{3,4,5},{6,7,8},
{0,3,6},{1,4,7},{2,5,8},
{0,4,8},{2,4,6}
]
moves = [not x[i] and not o[i] for i in xrange(9)]
wins = [False for i in xrange(9)]
blocks = [False for i in xrange(9)]
@onriv
onriv / ManageAttributesTest1.py
Created May 26, 2014 18:06
python:learning python:Managed Attributes:properties protocol:显式定义属性:ManageAttributesTest1.py
# -*- coding: utf-8 -*-
class Person():
def __init__(self, name):
self._name = name
self.originalName = name
def getName(self):
print('fetch...')
return self._name
# def setName(self, value):
@onriv
onriv / print_progress.py
Created May 26, 2014 11:41
python:util:print:打印进度条:print_progress.py
import sys
# Output example: [>>>>>>> ] 75%
# width defines bar width
# percent defines current percentage
def progress(width, percent):
print "%s %d%%\r" % (('%%-%ds' % width) % (width * percent / 100 * '>'), percent),
if percent >= 100:
print
@onriv
onriv / algorithm_x.py
Created May 26, 2014 08:42
python:精确覆盖问题:algorithm x:algorithm_x.py
# -*- coding: utf-8 -*-
"""
reference: [Algorithm X in 30 lines!](http://www.cs.mcgill.ca/~aassaf9/python/algorithm_x.html)
"""
def solve(X, Y, solution=[]):
''' for example:
X = {
1: {'A', 'B'},
2: {'E', 'F'},
3: {'D', 'E'},