lazy load google map

google map一般这样调用,引入的google的js文件,然后它内部会在引入其它js,网络条件不好的时候,会阻塞住浏览器 <script type="text/javascript" src="http://map.google.cn/maps/api/js?sensor=false"></script> <script> var draw_map = function(){ //.…. }; draw_map(); </script> 所以最好是用异步的方式,在需要的时候再载入地图的js文件,等地图所需js文件载入完毕后再调用自己的draw_map函数,google的api支持callback。 ...

August 14, 2012 · notsobad

非法url的http响应

两个现象 正常的http请求: wang@nb:/tmp$ nc 20.0.8.5 80 GET /abc HTTP/1.0 HTTP/1.1 404 NOT FOUND Server: nginx/1.0.6 Date: Fri, 10 Aug 2012 04:19:29 GMT Content-Type: text/html; charset=utf-8 Connection: close Vary: Accept-Language, Cookie Content-Language: zh-cn Set-Cookie: sessionid=981f6af6103261f552fe5a1ce4b5a90d; Path=/ <!DOCTYPE html> …… 如果请求的url不以/开头: wang@nb:/tmp$ nc 20.0.8.5 80 GET abc HTTP/1.0 <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/1.0.6</center> </body> </html> 注意响应部分没有http头部。 如果用httplib来发一个这样的请求,会注意到响应码居然是200,这应该是httplib发现没有响应头,自己补的状态码。 ...

August 10, 2012 · notsobad

工作5年

2012.7月,我已经工作5年了。五年前我完全不知道以后会是什么样子,现在我也完全不知道5年后会是怎样。 2010.5月,在我工作快3年的时候,我离开了第一个公司,加入现在的公司。 2007.7月,毕业了,来到北京,第一次开始挣钱,第一次银行卡上有超过3位数的钱 ...

July 16, 2012 · notsobad

扔掉50件东西

来北京5年了,2007年背着包到北京,到现在已经搬了五六次家,东西越来越多,有很多东西,从来没有用过,却一直被我搬来搬去。 前些天看到个说法,叫扔掉50件东西,我想实践一下。 票据,各种发票、收据,我也不知道为什么会一直留着 旧杂志 大学时代的旧书 穿过小于5次的衣服 坏掉的电器,一个台灯,两个旧手机 …… 待续 ...

July 5, 2012 · notsobad

使用scrapy

最近项目中用到了scrapy,所以研究了一下,发现很好用,主要把时间花在内容的提取规则上即可,剩下的全部交给scrapy搞定。 写了几个网站的爬取规则,包括6个图片网站,7个笑话网站,每个网站需要编写的代码50行以内,所以对于内容采集来说scrapy非常好用。 ...

June 25, 2012 · notsobad

urllib模拟登录

今天用一个urllib2、cookielib来模拟登陆,并希望能维持会话,及认证后的cookie可以保存下来,后续请求直接使用这个cookie,用cookielib折腾了好久,坑爹的是cookie可以保存,但是一直不能在请求中带上。 最后的解决办法。。不用cookielib,自己写个文件保存cookie,下次请求时自己读文件、自己发header。。。。 ...

March 30, 2012 · notsobad

web培训

培训的简单提纲 Bootstrap Grid 网格,标准布局:940px,分为16个格, 用于实现多列布局 layout 布局 Typography 标题、列表、code、pre、label等元素的样式 Tables 各种表格样式 Forms 表单 Navigation 导航栏、tabs、面包屑导航、分页 alert & errors 告警、提示信息 Popovers 弹出层提示 Tooltips 对title的提示优化 underscore 借鉴了一些函数式变成的思想,_.each, _.map, _.reduce, ...

March 23, 2012 · notsobad

Create a chrome extension

google chrome screen capture的网页截图思路 pages.js加入content_scripts,各个tab都可以调用,background.html是入口。 background.html调用标准的tabs.captureVisiableTab来绘制可见区域,在回调函数中,将图片写入canvas,同时向该tab发送scroll_next消息,该消息由pages.js处理,网页滚动一屏,翻页完成后,重新调用tabs.captureVisiableTab来,图片追加写入canvas。 ...

March 19, 2012 · notsobad

开始用gentoo

Gentoo常用的命令 #同步portage eix-sync / emerge --sync #安装某个软件包,自动处理依赖关系 emerge -av package #安装某个软件包,忽略任何依赖关系 emerge -Ov1 package #更新整个系统,自动处理所有的依赖关系 emerge -auvDN world #处理系统更新后由于某个动态库更新导致需要更新的软件 revdep-rebuild #处理python升级后部分python包的更新 python-updater #字体优化 emerge -av layman layman -L layman -f -a lcd-filtering 参考: http://blog.xtao.me/2011/11/gentoo%E5%AD%97%E4%BD%93%E4%BC%98%E5%8C%96/ http://gitorious.org/lcd-filtering/pages/Install ...

March 19, 2012 · notsobad

SICP python version

今天在hn上看到个资料,用python来讲SICP。 引述里面的一句话: The fundamental equation of computers is: computer = powerful + stupid Computers are very powerful, looking at volumes of data very quickly. Computers can perform billions of operations per second, where each operation is pretty simple. Computers are also shockingly stupid and fragile. The operations that they can do are extremely rigid, simple, and mechanical. The computer lacks anything like real insight .. it’s nothing like the HAL 9000 from the movies. If nothing else, you should not be intimidated by the computer as if it’s some sort of brain. It’s very mechanical underneath it all. Programming is about a person using their real insight to build something useful, constructed out of these teeny, simple little operations that the computer can do. ...

March 18, 2012 · notsobad