May 2013
7 posts
1 tag
get rid of example.com for Django's default site
Suppose you have the following model: class MyModel(models.Model): def get_absolute_url(self, *args, **kwargs): return '/show/%s' % self.pk The “View on site” button on admin will always take you to example.com, which is bullshit. Even if you override it with ABSOLUTE_URL_OVERRIDES in settings.py. The solution is to fuck Django’s default Site in your...
May 14th
1 tag
比奥数题还脑残的Python题
下边的问题是在CPython interactive shell 里按顺序执行的,请在 下划线处 ____ 填上答案。 >>> x = [1, 2, 3] >>> for number in x: ... number += 1 ... >>> print x __________________ >>> print 1 == True __________________ >>> print 0 == False __________________ >>> print 2 == True __________________ >>> item = 'x' >>> print item == "y" or...
May 13th
微软到底出了什么问题
最近HN上有个关于Linux 3.1内核tickless新特性的讨论,然后一位微软员工,自称来自NT内核组,发个帖子抱怨微软: See, component owners are generally openly hostile to outside patches: if you’re a dev, accepting an outside patch makes your lead angry (due to the need to maintain this patch and to justify in in shiproom the unplanned design change), makes test angry (because test is on the hook for making sure the change doesn’t...
May 10th
1 note
3 tags
n-body 舞蹈
看到这个demo:n-Body Choreographies v. 0.9 js写的太看了。赞一个。 其中很多模型我觉得比较好理解啊: 比如: D(10,8/3) 这个可以看成两个质心互绕,其中每个质心就是5个球体。。。 D(10,5/2) 这个可以看成2个质心一个收缩一个膨胀 D(8,9/4) 也类似2个质心。。。 很多看似复杂的轨道把 trajectory 关了就发现简单规律了。人脑的模式识别真是个神奇的东西~~~~~~~~~~~~~~ 让我想起了几天前fallark发的那个分解质因数的javascript 都是超赞的东西~ via
May 8th
2 tags
一个NP-complete问题
Steiner tree problem 好酷!的解法!中间的点叫做 费马点 via
May 3rd
2 notes
3 tags
PonyORM - python的新一代黑魔法级别ORM
简单的例子,来自官网 python的查询代码: select(c for c in Customer if sum(c.orders.price) > 1000) 通过PonyORM翻译成SQL: SELECT "c"."id" FROM "Customer" "c" LEFT JOIN "Order" "order-1" ON "c"."id" = "order-1"."customer" GROUP BY "c"."id" HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000 以前觉得peewee的查询语法很clever,比Django那种丑爆的 price__gt=1000 好出一条街。那么PonyORM就超出其他python ORM一条银河系了。 ...
May 3rd
3 notes
1 tag
关于码畜的定义
码农的定义就不用说了。 码畜的定义: > If you answer to managers and build CRUD apps to support their careers rather than your own, then you’re not a professional. 如果你的职业生涯就是给你的上级写CRUD应用。那么你就是码畜。 via
May 3rd
1 note
April 2013
18 posts
1 tag
ITU这个2b,让人不吐槽不舒服。
话说E.164这个标准还是挺重要的。电话国家区号。比如中国是 +86 好吧。我们去看下官网: http://www.itu.int/itudoc/itu-t/ob-lists/icc/e164_763.html 卧槽,哪里可以下载??????? 查看源码——有pdf和doc下载。。。。。但是页面上没有???? 用F12开发者工具一看,卧槽,尼玛居然需要水平滚动,下载icon在页面最右边!!!!!!!body的水平width是1910px!!!!!!我了个大艹!!!!!! 尼玛水平滚动也就算了,footer文字为毛position根据窗口固定? 好了。下载pdf ,一打开: 尼玛逼的,怎么搞技术的都这么脑残,不懂 natural sort 呢? 后来发现为啥不用natural sort了。这尼玛坑爹的国家区号是变长的。 ...
Apr 23rd
2 tags
传说中Kinect/OpenCV做的咪咪跟踪算法。
SPY居然冒了一句excellent。。。视频叫 suprise buttseks。。。 via
Apr 22nd
1 tag
365icl.com 的通讯
ipaddr=118.123.8.95 port=8000 ipaddr_auxiliary=125.64.16.139 port_auxiliary=8000 分析协议是件蛋痛的事情。 国产软件是多么不靠谱。。。。自带一个MapInfo MapX的地图组件,搞得客户端飞JB大。。。。
Apr 20th
2 tags
对于通讯的一些感受
今天地震,然后家里就断网了,就无聊听电台。然后就听了下350MHz - 370MHz。一开始以为是跳频,后来发现是多频道时断时续而已。一些感受: 我觉得普通JC是最苦逼的职业。基本就是被总台呼来唤去的民工。半个小时处理的事情基本就是解决停车纠纷啊,菜市场打架啊,银行卡被盗刷500元啊之类的鸡毛蒜皮事。真心蛋痛啊我日。 模拟信号语音交流感觉在“微信”时代真的落后了。 我们需要一个更加原子化、更加 IP 化的交流通讯方式。总台可以PUSH任务到人员,人员可以update情况,这一切需要一个更加优良的 UX 设计。我观察到比如一个很苦逼的事情就是手台里说手机号码。。这个在21世纪是很尴尬的。从市民报告,到总台分配,到解决,都应该数字化。 前几天看到reddit众在互相通气Boston...
Apr 20th
1 note
1 tag
Re: python标准库貌似没有实现链表?
发信人: draculalord ( 嗯?), 信区: Python 标 题: 也谈链表及其他Re: python标准库貌似没有实现链表? 发信站: 水木社区 (Mon Mar 21 18:49:46 2011), 转信 实际上刚开始学习一些高级语言的时候我也有同样的疑问,而且即使有链表对应物的语言,链表常常也很少被实际使用。 如果是在国外听数据结构的课,老师一般会警告你这只是一个理论概念,实际应用应该实际考察,在通常情况下链表不是一个很好的结构。 通常链表会作为一个很好的反例,告诉大家脱离实际硬件环境来谈论所谓算法复杂度是没有任何意义的。 这是因为,链表已经不适合当今的计算机硬件发展。当今的计算机硬件对内存是否连续更为敏感,而链表恰恰会破坏这种顺序读取。 由于locality很差所以常常造成page fault和cache miss...
Apr 18th
2 tags
Boston爆炸后偷衣服
via
Apr 15th
1 tag
新闻是个坏东西
News misleads News is irrelevant News has no explanatory power > The more “news factoids” you digest, the less of the big picture you will understand. If more information leads to higher economic success, we’d expect journalists to be at the top of the pyramid. That’s not the case. News is toxic to your body News increases cognitive errors News inhibits thinking ...
Apr 14th
1 tag
听水车们讲大数据在国内的发展
发信人: Nineteen (..), 信区: Database 标 题: Re: cassandra集群的去中心拓扑真是帅啊 发信站: 水木社区 (Sat Mar 9 10:03:09 2013), 站内 就像@immars提到的,开源项目们在一两年后开发出来的东西比论文原型在性能上差了一个层次,其实不仅仅是性能,其他方面差得会更多。 然后其他公司一看,不错,有东西能应付应付需求,接着就开始大用特用,坚持个一两年,东西尽管被改个面目全非,但仅限于补丁摞补丁,在外围小刀,想深入大改?门都没有,老板们会说了,先满足业务需求。最常听到的说法是:tmd我们都要死了,你丫还想花那么长时间大改? 团队规模在“快死了”的状态中不断成长,成长的另一个原因是层出不穷的运维事件和用户“永远都没办法满足的需求”,话语权也变得越来越重。 ...
Apr 10th
1 note
1 tag
Google Street View Hyperlapse
via
Apr 10th
2 tags
跟 @igrigorik 大神学前端
reddit上看到的 ppt在这里 做点笔记: 现代浏览器可以通过 performance.timing 看到载入和渲染时间记录。 Chrome的pagespeed插件和audit工具很有用 在线pagespeed 分析 critical path 其实 @igrigorik 大神的博客和github有不少好东西!
Apr 10th
1 note
1 tag
1915年,北京 盆糕 【老照片】
国内把切糕的英语翻译说成 Xinjiang glutinous rice cake, nut cake,不如这个1915年照片名字起的好:Cake Of Millet & Jujubes。感觉盆糕和切糕差不多? From Flickr via reddit
Apr 8th
1 note
2 tags
如何艹渣度的烂广告,但是保留贴吧登陆/发回帖功能
Chrome里打开: chrome://settings/contentExceptions#cookies Chrome的通配符语法真是 奇葩!
Apr 8th
2 tags
reddit砖家说:共产主义是NP-complete问题,所以不可能实现,除非
除非P=NP Economics is interesting because it is fundamentally the attempt to solve not just lots of problems, but a single GIGANTIC problem: the “resource scarcity” problem. Basically, we are trying to split up all the resources in such a way as to maximize the overall utility of those resources to each agent. How does this relate to the question at hand? Well, As a computer...
Apr 8th
2 tags
Khaleesi你肿么了!
盯这个照片5秒钟才反应出来这是谁。。。。 via
Apr 8th
1 tag
施华洛世奇元素 vs 施华洛世奇
施华洛世奇(Swarovski)实际上有两种含义,很多情况下这两种含义容易被混同。首先他是世界首屈一指的水晶制造商和水晶奢侈品生产商,两百年来,施华洛世奇一直独享和水晶切割有关的所有技术,并以此作为最高色商业秘密。由于其垄断地位和巨大名声,施华洛世奇在很多情况下已经成为水晶的代名词。而第二种含义,则是所谓的施华洛世奇元素(Swarovski Elements),实际上,这代表的是这种产品制造中使用到人造水晶,而这很可能和真正的施华洛世奇毫无关系。 又想起了 美素丽儿 美素佳儿,康师傅,康帅傅 了。 我日真坑爹。
Apr 8th
4 tags
Valve把source engine移植到linux的动机是——兲朝XP用户太多了
via
Apr 4th
3 tags
Google Spreadsheet API pitfalls
Don’t use OAuth 2 for “Google Apps for Business”, coz admin may set share option to “limit to xxx domain only”, thus your poor nigga API account like “30000000000@developer.gserviceaccount.com” won’t work. Google Spreadsheets’ CSV output format is terrible shit. Never bother touch it. It does not handle line breaks nor escapes like sane...
Apr 2nd
1 tag
OS X Mountain Lion 修改 openssh sshd_config 配置
OS X的蛋痛特性是 “launched` 。如果你需要修改sshd的监听端口,那么 编辑 /System/Library/LaunchDaemons/ssh.plist <key>Listeners</key> <dict> <key>SockServiceName</key> <string>ssh-alt</string> </dict> 然后在/etc/services里定义: ssh-alt 12345/tcp # ssh-alt 然后重启sshd服务: sudo launchctl uload...
Apr 2nd
March 2013
12 posts
3 tags
HAProxy like zero-copy in Python with memoryview
开篇帖子侃一下HAProxy这个神器有什么神器之处。 写过proxy的人都会写类似的语句: localstream.write(upstream.read(1024)) upstream.write(localstream.read(1024)) 其中1024为业界良心艹榴网的chunk或者一个buffer size。这样的操作在各种router, proxy, firewall 里太常见了。 那么HAProxy有什么特别的地方呢?秘密就是,上游socket的接受buffer和本地socket的发送buffer为同一块内存。也就是说,上游socket数据来了,本地socket自动发送这一块buffer的数据。效率真是高爆了。这块buffer数据还可以用内核调用splice() 和 tee() 来达到分流和分离信号的目的。 btw sendfile()...
Mar 26th
1 note
2 tags
GOOG 的生态系统已经完了。欢迎来到私家花园
两个事情需要喷一下: G+团队的官方博客:http://gplusproject.appspot.com/new-apps-iphone-android 这是个什么jb飞机玩意?为啥不用blogger? 看这个关于代码测试的google官方博客 http://googletesting.blogspot.sg/2013/03/testing-on-toilet-testing-state-vs.html 用它妈这么多javascript特效干嘛?关键是——禁用了js之后,页面就一片空白了。 欢迎来到后web 2.0时代——没有首页,没有订阅,没有js就神马都不显示的web app时代。
Mar 25th
1 tag
day -1
day -3 observed performance downgrade when x-linking sites day -2 frustrated at tcp blackout day -1 punched the hole and see the light day 0 productivity.
Mar 21st
1 tag
RIP Google Reader
It was fun while it lasted. FUCK GOOG
Mar 13th
1 tag
Unix Socket 点滴[转载]
【Unix Socket 点滴 1】使用unix socket时,把路径名的第一个字节设为null byte(\x00),这样就不会产生实际的文件,使用起了比较方便,也不用纠结选哪个路径,随便一个字符串就行了。netstat的时候会发现,第一个字节变成了蜗牛符号 【Unix Socket 点滴 2】unix socket的DGRAM模式可以传输大数据块,而UDP单个包最大65507字节。 【Unix Socket 点滴 3】unix socket可以发送文件句柄。特别是大数据量交互的时候可以放在tmpfs共享内存,只把文件句柄发送过去,这样可以做到0-copy。 【Unix Socket 点滴 4】unix socket可以校验对端的uid和pid,这在某些场合下是一种可依赖的鉴权手段。 【Unix Socket 点滴 5】uninx...
Mar 12th
1 note
4 tags
Web服这个屎盆子不够装了——记inetd的现代版Mozilla Circus
今天瞄了下Mozilla Circus这个项目,黑有意思。 简单的说,目前Web服务器基本模型都是一个总瓢把子Nginx,后边一大堆苦力worker进程。比如Python世界的Gunicorn是这个样子的粗暴简单: worker基本都是日出而耕,日落而息。(顺便一喷,Supervisord这些都弱爆了。djb大牛的runit才是王道) 要做到聪明的运维,和可小可大硬又黑的HA scaling,就需要一个高级一点的worker进程管理器于是——哐当当,Mozilla的Circus闪亮登场! 中文介绍在这里Mongrel2&Circul = web栈的完全控制 我觉得这项目很不错,至少有了Web Console码农不用再去砸400多元的机械键盘去 kill -HUP和 cat pidfile 啪啪啪了 ...
Mar 11th
2 notes
3 tags
yes, wsgi is such pain in the ass
found this gem While it is indeed now possible to utilize greenlets to convert multiple function calls into yields in a generator, it’s still something you would not do. In general JSON via HTTP or zeromq is so much cooler and more flexible than WSGI could ever be. Gevent is much better
Mar 7th
2 tags
tf2上最尽职尽责的医生了吧。。。
坚持不懈在悬崖上依然勇于奉献无私给奶的好奶爸!在最后关键60秒获得了关键胜利!
Mar 6th
1 note
2 tags
Benefits of class-based views
suppose you have url like this: /api/<method> In function based view it’s like: def myview(req, method=''): if method=='callA': return "" elif method=='callB': return "" else: return "" The problem is you can’t enumerate every callA and callB. But for class based view it’s trivial to write more elegant code like: class myview(ViewRouter): ...
Mar 5th
1 tag
再刷第三方ROM就剁手!
今天刷了下第三方ROM,我擦,搜狗的两个渣app删不掉,用RE浏览器删掉了。。。 结果。。。尼玛android的默认浏览器选项给屏蔽了。启动默认首页,弄死都是作者lishuo0427的JB烂博客 找到了个办法刷回官方包了。坑爹啊。我草!
Mar 5th
1 tag
Python 3.3很多激动人心的新特性啊
最近粗浅把玩了一下libev,感受颇深 首先是瞻仰了libuv python binding - pyuv 作者 @saghul 的博客 特别是这个slides很是学习了点东西 里边还提到,Twisted, Tornade和Gevent都有其对应libuv实现了。猛啊。 其中一个重要的东西,就是 Python 3.3里边的PEP-3156,和其参考实现Tulip,基于Pyuv的也有个实现叫Rose。 可以大胆估计,PEP 3156是以后最重要的Python标准接口之一了。其重要性超过PEP 333 WSGI libuv和 Boost.ASIO的比较看这里: libuv Boost Event Loop: yes Asio Threadpool:...
Mar 3rd
2 tags
客厅android的一些感受
com.yinyuetai.ui 这个JB设计居然只能竖屏。我擦。com.tencent.qqmusic 居然也是强制竖屏。在1080p电视上感谢这两款软件治好了我多年的颈椎病。 com.tencent.qqmusicpad 还是很赞的。 最讨厌android软件锁区 在v2ex上 看到HiHex这个只能电视团队,现在觉得如果要搞大屏交互还是很有搞头的。 对于交互我的一些粗浅看法: 传统键盘只是高速输入设备 鼠标是放大型的绝对精确定位设备,屏幕上的光标是实现了一种代入感,单个hot spot touchscreen是一种拟物的创新。多指就是多个hot spot 客厅大屏交互,这个交互必须是相对的。而且没有hot spot,只有dynamic area。 也就是说,桌面或者home...
Mar 3rd
February 2013
13 posts
1 tag
Return twice in a python function
1.py: def foo(): try: return 'foo' finally: return 'bar' print foo() 2.py def foo(): try: return 'foo' finally: print 'bar' print foo() The result is shocking… $ python 1.py bar $ python 2.py bar foo I think this particular behavior is well abused in WSGI two cents: return does not actually leave the function immediately a function without return statement...
Feb 28th
1 tag
pypy 10年黑历史——精彩回顾
摘录一下: 2007年欧盟觉得pypy这货是典型的烂尾钓鱼工程于是就停止拨款了。 尝试过RPython -> Javascript。失败告终 至少4次用LLVM。全部失败。 2次尝试写了个Rpython版的ctypes,叫rctypes,均失败。 JIT引擎写过3个版本,第四个个版本才成功 第一个成功C编译版本的pypy直接segfault了——本来应该unsigned int写成了signed int 在当年的欧盟砖家评审会上,Pypy画了一个惊天地泣鬼神的大饼——几乎包含了所有编程语言最新最酷的特性。后来这些累赘在一次sprint中被砍掉70%精简了30%代码量 from pypy blog via reddit, HN
Feb 28th
2 tags
tg的蛋蛋伍中心被人爆菊花了。。。
我是不是out了现在才知道。。。 来源: https://twitter.com/uponsnow/status/305585519822254080/photo/1 截图: 碉堡了!!!!!!!!
Feb 25th
2 tags
电池技术的进步 == 人类世界的终结
从 HN 上看到这个视频 看到这个评论 One reason they don’t already have cameras built in is a combination of power requirements 突然想到,一个由思轴组成的飞行swarm网络,如果每个节点都自带摄像头输入的话,网络可以p2p通信,那么这个swarm的战术能力比士兵组成的战术分队强大多少倍啊。。。。。 看来得加紧研制大功率激光近防武器了。这种小虫子势不可挡啊。
Feb 21st
2 tags
这次apt1报告里tg最sb的地方。。。
看到这个报道 简单的说,由于twitter facebook被封了,PLA需要翻墙。用什么翻墙最方便呢? 当然是黑下来的肉鸡最方便。
Feb 20th
3 tags
Install bjoern on Gentoo
VPS内存小,连uWSGI这种都玩不起,只能玩玩bjoern这个神器了。Bottle.py支持的WSGI容器还真多啊! curl -O http://python-distribute.org/distribute_setup.py sudo python distribute_setup.py curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py sudo python get-pip.py sudo emerge libev CFLAGS=-I/usr/include/libev sudo pip install bjoern 灌了个水的哟。。。
Feb 19th
2 tags
dynamic app routing for Bottle.py based on...
Problem: I want ONE bottle project to display different pages for: http://foo.est.im http://bar.est.im These should be separate Bottle apps. There’s an ugly hack from the official maillist, I think I can make it better. The secret is to create a customized WSGI app: from fnmatch import fnmatch from bottle import Bottle, default_app, run foo = Bottle() foo.hostnames =...
Feb 18th
2 tags
Google Apps Script生成动态网页碉堡了。
Google Docs自己搞了一套类似Google App Engine的体系,只不过服务器端语言是Javascript,运行环境是 云JS——Google Apps Script https://developers.google.com/apps-script/html_service 看了下文档,类似php的语法,在html里嵌入js,然后服务器渲染得到一个网页。 <table> <? var data = getData(); for (var i = 0; i < data.length; ++i) { ?> <tr> <? for (var j = 0; j < data[i].length; ++j) { ?> <td><?=...
Feb 15th
1 tag
理论数学PhD被黑出翔了。
via [1]http://www.reddit.com/r/math/comments/18i7zx/which_one_is_most_different_from_the_others/), 2
Feb 15th
1 note
1 tag
Cloud Atlas 观后
Freedom. The fatuous jingle of our civilization But only those deprived of it have the barest inkling of what it really is
Feb 8th
2 tags
Is Discourse going to be next Wordpress?
I discovered Discourse on HN and played with it all day. So far it looks promising. freshing and distinctive UI high profile blogger promotes it. haz all the basic forum functions community based moderation deadly easy distribution and (promising) install methods. something I think yet to improve Does the system converge? The “branching” topic feature seems very creative, but...
Feb 6th
2 tags
火控雷达意味着什么
形象生动 > Military ships and planes do not “lock onto other vessels all the time”. Not with targeting radar, and not in international waters - doing so is proscribed under international law as an act of aggression. It is the high-tech equivalent of sticking a gun in someone’s face and cocking the hammer via
Feb 6th
January 2013
16 posts
2 tags
Google Suggest spell checker
请求: POST https://www.googleapis.com/rpc HTTP/1.1 Host: www.googleapis.com Connection: keep-alive Content-Length: 159 Content-Type: application/json {"method":"spelling.check","apiVersion":"v1","params": {"text":"cchrome","language":"en","originCountry":"USA", "key":"AIzaSyCLlKc60a3z7lo8deV-hAyDU7rHYgL4HZg"}} 返回: HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Cache-Control:...
Jan 31st