Skip to content

Instantly share code, notes, and snippets.

View anjianshi's full-sized avatar

安坚实 anjianshi

View GitHub Profile
@anjianshi
anjianshi / tornado_with_peewee-async.py
Last active November 25, 2019 05:11
Use peewee-async with Tornado
import tornado.gen
import tornado.web
from tornado.platform.asyncio import AsyncIOMainLoop
from tornado.options import define, options, parse_command_line
import peewee
import asyncio
import peewee_async
import logging
@anjianshi
anjianshi / linkPushState.js
Last active August 29, 2015 14:15
在用户点击 <a> 标签时,进行 pushState 操作 (通过 history.js)
//灵感来自: https://gist.github.com/tbranyen/1142129
$(document).on("click", "a", function(event) {
// 如果一个链接的协议、域名、端口都和当前页面相同,则将其视为应用内的跳转链接,通过 pushState 进行处理;
// 否则作为普通外部链接,交由浏览器处理。
// 不过当用户按下 Ctrl 等控制键时,因为涉及到浏览器原生的在新标签/页面打开链接的操作,一切链接都交由浏览器处理。
var keyPressed = event.ctrlKey || event.shiftKey || event.altKey || event.metaKey || event.which === 2;
var isSameSite = this.protocol === location.protocol && this.hostname === location.hostname &&
this.port === location.port;
if(!keyPressed && isSameSite) {
@anjianshi
anjianshi / .Xresources
Last active August 29, 2015 14:14
Ubuntu 14.10 Xterm config
! 把这个文件放到用户文件夹下
xterm*faceName: Source Code Pro:style=Regular
! support chinese
xterm*faceNameDoublesize: Droid Sans Fallback:style=Regular
xterm*faceSize: 11
xterm*vt100.geometry: 80x23
xterm*loginshell: true
! support 256color
@anjianshi
anjianshi / install-mysql-python.py
Created October 25, 2014 08:22
Help you compile and install mysql-python on Windows
# -*- coding: utf-8 -*-
"""
Install mysql-python on Windows using pip was difficult.
This script can help you done the task.
Requirements:
Python 2.7
pip (setuptools >= 6.0, use `pip install -U setuptools` to upgrade)
VCForPython27 (http://www.microsoft.com/en-us/download/details.aspx?id=44266 used to compile mysql-python)
function normal() {
var color1, color1box, color2, color2box;
var boxes = document.querySelectorAll('#box > span'), boxLen = boxes.length;
for(var i = 0; i < boxLen; i++) {
var box = boxes[i], color = box.style.backgroundColor;
if(i == 0) {
color1 = color;
color1box = box;
value = 1
fn = ->
`var value` # 通过这句强制创建一个局部变量
value = 2
@anjianshi
anjianshi / db_helper.py
Created January 13, 2014 06:06
python MySQLdb helper
# -*- coding: utf-8 -*-
import MySQLdb
def get_db(database, user="root", passwd=None, charset='utf8'):
return MySQLdb.connect(host="localhost", user=user, passwd=passwd, db=database, charset=charset)
def execute(db, sql):
cur = db.cursor()
ChildCtrl = function($scope) {
$scope.validate = function() {
//...
}
$scope.edit = function(item) {
parentValidateFn = $scope.$parent.validate;
$scope.$parent.validate = $scope.validate(); // 覆盖父类的方法
$scope.$parent.edit(item);
$scope.$parent.validate = parentValidateFn;