- 博客(198)
- 收藏
- 关注
转载 WYSIWYG
from flask import Flaskfrom flask.ext.sqlalchemy import SQLAlchemy from flask.ext import admin, wtffrom flask.ext.admin.contrib import sqlamodel app = Flask(__name__)app.config['SECRET_KEY'] =
2015-02-14 22:36:43
840
原创 postgres插入默认值 如果select查询不到默认值
CREATE OR REPLACE FUNCTION get_user(test integer) RETURNS SETOF test AS $BODY$DECLARE r record;BEGIN FOR r IN SELECT * FROM test LOOP RETURN NEXT r; END LOOP; if not found then
2015-02-05 23:03:24
2262
原创 psycopg2.ProgrammingError: execute cannot be used while an asynchronous query is underway
psycopg2.ProgrammingError: execute cannot be used while an asynchronous query is underwayTemporary solution - close connection, if error happened in it. For it, let's create class inspired
2015-02-05 10:27:50
4522
原创 blog to share
http://momjian.us/main/writings/pgsql/hw_performance/https://github.com/gevent/gevent/blob/master/examples/psycopg2_pool.pyhttp://jorgenmodin.net/index_html/process-safe-connection-pool-for-psycop
2015-02-03 16:22:43
777
转载 python descriptor override
.4.2.3 Invoking DescriptorsIn general, a descriptor is an object attribute with ``binding behavior'', one whose attribute access has been overridden by methods in the descriptor protocol: __get__(),
2014-09-11 16:43:38
811
原创 python 描述符 类方法 闭包
# -*- coding:utf-8 -*- #class FunWrap(object): u"""包装一个函数""" def __init__(self, func): self.func = func def __get__(self, obj, typ = None): return szhinstancemethod(typ, obj, self) def _
2014-09-10 22:41:43
706
转载 Node.js
Node.js采用了Google Chrome浏览器的V8引擎,性能很好,同时还提供了很多系统级的API,如文件操作、网络编程等。浏览器端的Javascript代码在运行时会受到各种安全性的限制,对客户系统的操作有限。相比之下,Node.js则是一个全面的后台运行时,为Javascript提供了其他语言能够实现的许多功能。Node.js采用事件驱动、异步编程,为网络服务而设计事件驱动这个词并不陌生
2014-05-10 09:45:36
920
转载 RequireJS
RequireJS入门(一)RequireJS由James Burke创建,他也是AMD规范的创始人。 RequireJS会让你以不同于往常的方式去写JavaScript。你将不再使用script标签在HTML中引入JS文件,以及不用通过script标签顺序去管理依赖关系。 当然也不会有阻塞(blocking)的情况发生。好,以一个简单示例开始。 新建一个目录,
2014-05-04 14:56:16
610
转载 Flask
@app.route('/login', methods=['GET', 'POST'])def login(): if request.method == 'POST': do_the_login() else: show_the_login_form()
2014-05-03 10:46:13
608
转载 深入理解 AngularJS 的 Scope
JavaScript 的原型繼承就是奇葩。之前在 V2EX 上看到討論說,不會 OOP 的 JavaScript 的程序員就是野生程序員。看來我是屬於野生的。一、遇到的問題問題發生在使用 AngularJS 嵌套 Controller 的時候。因為每個 Controller 都有它對應的 Scope(相當於作用域、控制範圍),所以 Controller 的嵌套,
2014-05-02 20:52:55
769
转载 Ruby类方法 实例方法
ruby的类方法与实例方法类方法也叫静态方法,通过类名来调用的方法。实例方法,必须要new一个实例出来才能用。class Foo def self.bar puts 'class method' end def baz puts 'instance method' endendFoo.bar #class method#Foo.baz #报
2014-05-02 11:27:20
2208
转载 ruby 多继承 mixin include exclude require load
首先定义一个Module:module Foo def bar puts "foo"; endend然后我们把这个模块混入到对象中去:class Demo include Fooend 如上编码后,模块中的实例方法就会被混入到对象中:d=Demo.newd.bar会输出foo字样。下面我们重新定义一下D
2014-05-02 11:25:07
742
转载 OAuth2.0协议 第三方登录 授权
帮你深入理解OAuth2.0协议oAuth2.0OAuth2.0OpenAuthorizationWeb安全协议开放授权1. 引言如果你开车去酒店赴宴,你经常会苦于找不到停车位而耽误很多时间。是否有好办法可以避免这个问题呢?有的,听说有一些豪车的车主就不担心这个问题。豪车一般配备两种钥匙:主钥匙和泊车钥匙。当你到酒店后,只需要将泊车钥匙交给服务生,停车的事情就由服务
2014-05-02 09:46:12
1447
转载 javascript settimeout setinterval Javascript高性能动画与页面渲染
Javascript高性能动画与页面渲染
2014-05-02 09:14:24
660
转载 js BDD Test framework jasmine
http://evanhahn.com/how-do-i-jasmine/http://jasmine.github.io/2.0/introduction.html
2014-05-01 21:24:44
631
转载 平衡二叉树
旋转 节点再怎么失衡都逃不过4种情况,下面我们一一来看一下。① 左左情况(左子树的左边节点)我们看到,在向树中追加“节点1”的时候,根据定义我们知道这样会导致了“节点3"失衡,满足“左左情况“,可以这样想,把这棵树比作齿轮,我们在“节点5”处把齿轮往下拉一个位置,也就变成了后面这样“平衡”的形式,如果用动画解释就最好理解了。 1
2014-04-27 19:16:12
604
转载 python func defaults args are evaluated only once,(in definition time)
In [7]: def r(): ...: return random.randint(1,100) ...:In [12]: def d(a, b=r()): ....: print b,'-------------' ....:In [13]: d(9)75 -------------In [14]: d(9)75 -------------
2014-04-26 11:20:02
652
转载 python list存储的是reference id
ids of integer constants are not guaranteed to be equal, and indeed, for integers as large as 257, they aren't. (try id(257) == id(258 - 1)) Everything in python is stored as reference.
2014-04-26 10:45:32
1051
原创 python 闭包
def a(): l=[] def set_l(): l.append(1) def get_l(): print l return set_l, get_ls,g = a()In [4]: g()[]In [5]: s()In [6]: s()In [7]: g()
2014-04-26 10:24:48
521
转载 python实现二叉树
class _Tree(object): def __init__(self, value, nodeClass): self.value = nodeClass(value) self.leftNode = None self.rightNode = None def setLeftNode(self, node):
2014-04-25 16:13:54
577
转载 JavaScript事件冒泡
JavaScript的事件确实会带着这个属性。当程序捕获一个事件的时候,它会知道这个事件来自于页面上哪个元素。修改上面的程序,使用事件委托来处理点击事件。当最顶层捕获点击事件时,查看事件来源于哪一层,然后只将那一层涂色。再次点击每一层,查看实际效果。只有当前点击的正方形变色了,其他的都毫无反应。(点击这里查看demo)jQuery('#d1').click(function(e){
2014-04-21 18:51:49
530
转载 匹配汉字英文字符
正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度2012-12-07 18:23 7639人阅读 评论(0) 收藏 举报匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00-\u9fa5_a-zA-Z0-9]+$同时判断输入长度:[\u4e00
2014-04-16 20:35:21
786
转载 redis sort 使用外部key排序
>>> conn.rpush('sort-input', 23, 15, 110, 7) #A4 #A>>> conn.sort('sort-input') #B['
2014-04-06 21:45:48
1272
转载 redis python操作 string integer
打开Python解释器:>>> import redis>>> r = redis.Redis(host='localhost', port=6379, db=0) #如果设置了密码,就加上password=密码>>> r.set('foo', 'bar') #或者写成 r['foo'] = 'bar'True>>> r.get('foo') 'bar'
2014-04-06 20:57:03
534
转载 markdown use
图片很明显地,要在纯文字应用中设计一个「自然」的语法来插入图片是有一定难度的。Markdown 使用一种和链接很相似的语法来标记图片,同样也允许两种样式: 行内式和参考式。行内式的图片语法看起来像是:
2014-04-04 23:23:19
574
转载 ruby pass by reference
Q1: What happens when you assign a new variable str to a value of 'foo'?str = 'foo'str.object_id # => 2000A: A label called str is created that points at the object 'foo', which for the state
2014-04-04 01:14:18
612
转载 ruby安装
运行:sudo apt-get install rubysudo apt-get update ruby安装完成后,运行:ruby -v,提示当前安装的版本是1.8书上提到了irb是一个很好用的ruby交互环境,而且在开发过程中要不断查阅文档,于是就使用: sudo apt-get install irb sudo apt-g
2014-04-02 21:18:45
505
转载 python yield send
def psychologist(): print 'Please tell me your problems' while True: answer = (yield) if answer is not None: if answer.endswith('?'): print ("Don't ask yourself too much questions") el
2014-03-31 10:47:54
668
转载 python dict reg key
Dictionary lookup with regular expression as keyI just remembered that I was meant to post that thing here, too. Problem is the following: you want to retrieve all values of a python dictionary
2014-03-30 00:06:50
737
转载 python wraps decorator
frominspectimportgetmembers, getargspecfromfunctoolsimportwraps defwraps_decorator(f): @wraps(f) defwraps_wrapper(*args,**kwargs): returnf(*args,**kwargs) returnwraps_wra
2014-03-29 23:38:14
959
转载 socket SO_REUSEADDR
SO_REUSEADDR可以用在以下四种情况下。 (摘自《Unix网络编程》卷一,即UNPv1) 1、当有一个有相同本地地址和端口的socket1处于TIME_WAIT状态时,而你启动的程序的socket2要占用该地址和端口,你的程序就要用到该选项。 2、SO_REUSEADDR允许同一port上启动同一服务器的多个实例(多个进程)。但每个实例绑定的IP地址是
2014-03-29 20:46:18
658
原创 pitfall while if condition in python non zero
python 中 if while 条件语句 条件是不为零
2014-03-27 17:54:05
444
转载 python copy * shallow
需要在程序中使用二维数组,网上找到一种这样的用法:123456#创建一个宽度为3,高度为4的数组#[[0,0,0],# [0,0,0],# [0,0,0],# [0,0,0]]myList= [[0]* 3]* 4
2014-03-27 00:24:12
493
原创 python +=
In [25]: a=[]In [26]: b=[]In [27]: id(a)Out[27]: 51344568In [29]: a+=bIn [31]: id(a) ## id 没变, a +=不会创建新listOut[31]: 51344568In [32]: a=a+b
2014-03-25 23:27:28
478
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人