很多公司都大量使用了python,其中有一些开发规范,code guidline, 通用组件,基础框架是可以共用的。
每个公司都自己搞一套, 太浪费人力,我想开一帖和大家讨论一下这些python基础设施的搭建。
原则是我们尽量不重新发明轮子,但开源组件这么多,也要有个挑选的过程和组合使用的过程,在这里讨论一下。
另一方面,有些开源组件虽然强大,但我们不能完全的驾驭它,或只使用其中很少的一部分,我们就可以考虑用python实现一个简单的轮子,可控性更强,最好不要超过300行代码。
// This code is public domain, share and enjoy. | |
window.ui = window.ui || {}; | |
/** @constructor */ | |
ui.ListView = function(element, collection) { | |
this.el = element; | |
this.cellHeight = 30; | |
this.collection = collection; |
// 大家写在评论中吧,代码高亮可以这样写: | |
// ```js | |
// your code | |
// ``` | |
// update: Fri Aug 31 08:39:21 | |
// copyright: https://gist.github.com/3549352 | |
// 加个性能测试:http://jsperf.com/get-dom-s-first-element | |
var util = {}; |
var arr = [1,2,3,4,5,6,7,8,9]; | |
arr.reduce(function(prev, cur, i, index){ | |
// 奇葩 | |
console.log(prev,cur,i,index, arr[--i] === prev) | |
}) | |
arr.reduce(function(prev, cur, i, index){ | |
// 正常 | |
console.log(prev,cur,i,index, arr[--i] === prev) |
Latest update 20-Oct-2012. me@jjperezaguinaga.com
Command Line Tools are required for Homebrew. Previously it was suggested to download Xcode 4, but since the new version doesn't ship the proper gcc compiler for rvm, the command line tools are a better option and then using homebrew to get the gcc compiler. If preferred, install Xcode 4, although this setup doesn't follow that set of instructions.
Really the nicest choice for a terminal on OSX right now, especially with Lion style full screen support.
捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg
:错误描述,比如:a is not definedurl
:出错脚本所在的urllineNumber
:出错脚本的行数本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
/** | |
* Override res.render to do any pre/post processing | |
*/ | |
app.use(function(req, res, next) { | |
var render = res.render; | |
res.render = function(view, options, fn) { | |
var self = this, | |
options = options || {}, | |
req = this.req, | |
app = req.app, |
- index.js | |
- package.json | |
- public/js/main.js | |
- public/index.html | |
- css/bootstrap-responsive.min.css | |
- css/flatly-bootstrap.min.css |
// Support routines for automatically reporting user timing for common analytics platforms | |
// Currently supports Google Analytics, Boomerang and SOASTA mPulse | |
// In the case of boomerang, you will need to map the event names you want reported | |
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable: | |
// rumMapping = {'aft': 'custom0'}; | |
(function() { | |
var wtt = function(n, t, b) { | |
t = Math.round(t); | |
if (t >= 0 && t < 3600000) { | |
// Google Analytics |
// List all files in a directory in Node.js recursively in a synchronous fashion | |
var walkSync = function(dir, filelist) { | |
var fs = fs || require('fs'), | |
files = fs.readdirSync(dir); | |
filelist = filelist || []; | |
files.forEach(function(file) { | |
if (fs.statSync(dir + file).isDirectory()) { | |
filelist = walkSync(dir + file + '/', filelist); | |
} | |
else { |