Skip to content

Instantly share code, notes, and snippets.

#/bin/env python
#-*- coding:utf-8 -*-
from bottle import *
@get('/t2p')
def text_form():
return '''
<form method="POST">
<input type="text" name="text" />
<input type="submit" name="Submit" />
</form>
@syshack
syshack / t2p-sae.py
Created May 18, 2012 09:23
text2png for sae demo
from bottle import *
import sae.storage as sst
from StringIO import StringIO
import sae
app = Bottle()
debug(True)
@app.get('/t2p')
def text_form():
return '''
<form method="POST">
@syshack
syshack / edit_task.tpl
Created May 21, 2012 07:26
a todo demo in sae
p>编辑 ID 为 {{no}} 的任务</p>
<form action="/edit/{{no}}" method="GET">
<input type="text" name="task" value="{{old[0]}}" size="100" maxlength="100" />
<select name="status">
<option value="1">开启</option>
<option value="0">关闭</option>
</select>
<br />
<input type="submit" name="save" value="save" />
</form>
@syshack
syshack / FomationCheck.py
Created May 23, 2012 03:11
check fomation
#!/usr/bin/env python
import web
import simplejson as sj
def FomationCheck():
db=web.database(dbn='mysql', host='',db='shdb1', user='', pw='')
jsons = list(db.query("SELECT json FROM Formation"))
for json in jsons:
jsonData=json.json.encode('utf-8')
jsonVar=sj.loads(jsonData)
playerId=jsonVar['playerId']
@syshack
syshack / threadpool.py
Created June 18, 2012 02:27
python线程池
# -*- coding: UTF-8 -*-
"""Easy to use object-oriented thread pool framework.
A thread pool is an object that maintains a pool of worker threads to perform
time consuming operations in parallel. It assigns jobs to the threads
by putting them in a work request queue, where they are picked up by the
next available thread. This then performs the requested operation in the
background and puts the results in another queue.
@syshack
syshack / sshcmd.py
Created June 29, 2012 05:57
sshcmd
import paramiko as ssh
port=22
username='xxx'
passwd='xxx'
def SshCmd(cmd):
s=ssh.SSHClient()
s.set_missing_host_key_policy(ssh.AutoAddPolicy())
s.connect(host,port,username,passwd)
stdin,stdout,stderror =s.exec_command(cmd)
print stdout.read()
@syshack
syshack / view.py
Created July 5, 2012 12:49
flask_admin_db_view
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.orm import subqueryload
from sqlalchemy.sql.expression import desc
from sqlalchemy import or_
from wtforms.ext.sqlalchemy.orm import model_form
from flask import flash
from flask.ext.admin.babel import gettext
from flask.ext.admin.form import BaseForm
@syshack
syshack / dbbake.sh
Created July 18, 2012 02:50
mysql bak
#!/usr/bin/env bash
#dbbake.sh
#author:syshack
#date:2011.9.10
#数据库
DBName=mysql
#用户名
DBUser=root
#数据库密码
DBPasswd=
@syshack
syshack / logparse.py
Created July 31, 2012 06:47
v1 纹身日志
#!/usr/bin/env python
'''logfomat:2012-07-19 13:50:39,playerId:68719476740,operFlow:1,operType:0,indentify:ws:shanbiP110,sampleId:ws:shanbiP1,Level:1,Exp:
0,Num:1'''
import re
import time
Time="2012-07-31 12:43:40"
time_str=time.mktime(time.strptime(Time,"%Y-%m-%d %H:%M:%S"))
def grep(file,exp):
fd=open(file,'r')
#!/usr/bin/env python
'''logfomat:2012-07-19 13:50:39,playerId:68719476740,operFlow:1,operType:0,indentify:ws:shanbiP110,sampleId:ws:shanbiP1,Level:1,Exp:
0,Num:1'''
import re
import time
Time="2012-07-31 12:43:40"
time_str=time.mktime(time.strptime(Time,"%Y-%m-%d %H:%M:%S"))
def grep(file,exp):
fd=open(file,'r')