All posts in Technique

Sublime Text 2 Upgrade Problem

搞了半天发现好还毕竟不是sublime本身的错,要不就完全毁了这几个星期来对之的美好印象了……

btw,sublime text 2着实是个相当promising的editor,各位看官有闲情雅致且有信心记住更多的key shortcuts的话不妨一试(其实也没有多少啦),鄙人highly recommended(路人甲:你算哪跟葱……;我:……),除了其License价格不菲之外(比textmate多1刀),其余很多feature都可圈可点,好消息是beta版可以免费使用,就是时不时会有dialog跳出来提醒抑或是恶心一下你,呵呵。

废话有点多,不过鉴于某些同学口味比较重比较独特只喜欢看本人的废话部分,所以现在我基本把重要的事情都放在废话部分讲……

anyway,本次遇到的问题是sublime无法启动,报出以下颇为technical的error dialog,然后便quit,想必是目前用此editor的大多还是developer居多,所以报这种样式的error通常会被认为更为friendly:

Unable to run package setup:

Traceback (most recent call last):
File "./PackageSetup.py", line 155, in upgrade
upgradePackage(pkg, pristinedir, datadir, backupdir)
File "./PackageSetup.py", line 148, in upgradePackage
os.path.join(backupdir, base), inhibitOverwrite)
File "./PackageSetup.py", line 31, in upgradeArchive
newar = zipfile.ZipFile(src)
File ".\zipfile.py", line 696, in __init__
File ".\zipfile.py", line 716, in _GetContents
File ".\zipfile.py", line 728, in _RealGetContents
zipfile.BadZipfile: File is not a zip file

Continue reading →

Downgrade Rubygems

First let’s list 2 truths here:

  • Rails 2.3.5 will fail with RubyGems 1.5.0 +
  • Rails 2.3.11 will fail with RubyGems 1.7.0 +

So what if you want to deploy or run an application which unfortunately still or initially written in rails 2, given the situation that latest RVM default install rubygems version 1.8.11?

It turns out to be not so painful, cause it’s as simple as just issue one command (take 1.4.2 for example):

gem update --system 1.4.2

Just like the China highway train, sometimes what you need to do is just to stop moving so fast.

Setup VPN on RAM Host VPS

首先,ramhost采用的是openvz而不是像linode一样的xen,所以pptpd是不stable且不被official所支持的:

https://forum.ramhost.us/bbs/viewtopic.php?id=343

遂改用openvpn,你也没有啥损失,这里有official的documentation,买了ramhost service的同学相信都能很好的阅读e文,我就不啰嗦了~

https://forum.ramhost.us/bbs/viewtopic.php?id=4

至于openvpn的client,mac上有个叫tunnelblick的工具,我用它来create了一个connection profile,可惜最后没有运行成功,可能是stable version有点outdated的缘故,最后我用了一个叫viscosity的client i解决了问题,它可以导入之前用tunnelblick创建的profile,所以可见tunnelblick这一领域还是相当那啥的,我看到其最新beta release就在上个月,所以tunnelblick重新work应该只是个时间问题,吧,呵呵。

[Footnotes]
  1. 我不是其sales…… []

Felix’s Node.js Style Guide (Part 2)

接上篇:Felix’s Node.js Style Guide (Part 1)

创建Object / Array

逗号应放在行尾而不是行首,每一行放置简短的变量声明。只在你的解释器抱怨的时候才应该去给array的key上加上引号。

正确:

var a = ['hello', 'world'];
var b = {
  good: 'code',
  'is generally': 'pretty',
};

错误:

var a = [
  'hello', 'world'
];
var b = {"good": 'code'
        , is generally: 'pretty'
        };

Continue reading →

Felix’s Node.js Style Guide (Part 1)

本文为译文,翻译自原文 http://nodeguide.com/style.html

标题咱就不翻了吧,说实话guide这个词还真不好翻,不能显得很高深又不能显得很for dummy的样子,索性就不翻了……

本guide应该较上篇略有意思,作者泰国海滩度假的时候写出来的东西想来也不会多么干巴巴(海滩不是到处都是水吗……),当然本文所涉及的编程风格之类的选择应该完全是作者自己的opinion,不代表我台观点。

============================== 我是分割线 ==============================

本文不是node.js应用程序所应该遵循风格的官方文档。本guide只是试图带给你一整套instructions,虽说本人有点固执己见,但这套东西确实能让你创建美观且统一的软件。

本guide假设你只针对node.js。如果你的代码需要在浏览器或者其它环境里面运行,请勇敢的忽略其中一些部分。

另外请注意node.js和围绕node的其它很多package都有其自身略显不同的风格,所以如果你对那些项目感兴趣,请遵守他们那边的规则。(别到时被砍……译者注)
Continue reading →

Felix的Node.js初学者入门指南

本文为译文,翻译自原文 http://nodeguide.com/beginner.html

网上有很多关于node.js的资料,但鉴于其快速的开发进度,初学者可能会很难找到比较好且最新的入门资料。本文就是在力求提供这份资料,并且力求时刻和最新的node.js稳定版本保持同步。

本guide已经针对node 0.4.x的最新改动做过更新,node 0.4.x也是当前node的稳定分支。

学习JavaScript

本guide假设你已经对JavaScript有所熟悉。如果你不是很熟悉,你可以去读读:Marijn Haverbeke写的Eloquent JavaScript,它可以在网上免费阅读。
Continue reading →

SQL调优和SQL优化

本文为译文i,翻译自原文 http://beginner-sql-tutorial.com/sql-query-tuning.htm

sql语句可以用来从数据库取回数据。不同的sql查询语句有时可以得到相同的返回结果。如果考虑执行效率的话,选择使用最佳的查询语句至关重要,所以我们需要根据需求来优化sql查询。下面是一些我们平时经常使用的查询语句,以及如何优化它们以达到更好的执行效率。

SQL调优/SQL优化技巧:

1) 如果在SELECT语句里面用具体的column名而不是’*',sql查询会更快。

例如,查询语句写成:

SELECT id, first_name, last_name, age, subject FROM student_details;

比写成下面这样快:

SELECT * FROM student_details;

Continue reading →

[Footnotes]
  1. 翻译的主要目的在于强化记忆和加深理解 []

Python NameError: name ‘readline’ is not defined

Python 2.6.×已经装了有一定时日了,已经完全不知道python的世界都更新到什么境界了;标题这个issue在我更新到Lion之前就已经存在了,所以这不能算是Lion里才introduce的issue,这个还是得有一句说一句;

之前我在Snow Leopard一直没有找到fix的办法,当然主要的原因还在于我也没有那么急切的想fix它,至少对于一个几个月都基本不碰python的家伙而言,它的急迫性显然没有解决starcraft2破解版一联机就自动更新不能玩这个issue来的高,xd:)

BTW, 我只玩战役模式,Blizzard及其各路partner已经完全将starcraft2的对战模式变成网游,虽然我很想支持暴雪买正版,但是网游的各种消耗对我来说是无法容忍的.

貌似又有跑题的趋势…… anyway……

这个issue就是下面这样的,注意倒数第二行:

~ ➔ python
Python 2.6.6 (r266:84292, Sep 13 2010, 20:53:06)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Module readline not available.
Traceback (most recent call last):
  File "/Users/samson/.pythonrc", line 22, in <module>
    readline.read_history_file(historyPath)
NameError: name 'readline' is not defined
>>>

Continue reading →

Lion Ready?

装了Lion将近3周,新的fancy的feature不少 i,当然各种大的小的宏观的细节的问题也不少;这儿我就不列了,还真是不一而足呢;

现在大家都在讨论,说种种迹象表明,mac os x的未来便是慢慢向ios靠拢,逐步统一两系统的用户体验和程序开发;列位,先别讨论未来了,我比较现实,谁先把10.7.1给我整出来吧……

[Footnotes]
  1. fancy的另外一种解释就是中看不中用…… []

Grid Archives 1.5.0

Grid Archives 1.4.0 introduced a new display style called “compact”, which only supports year expand at that time.

Although this function will effectively reduce the length of the whole archive page if there are many years of articles, it still presents as a very long list page if there are many articles/posts in each year. To address this issue, 1.5.0 introduce a new month list view in “compact” mode.

It will be shown by default if “compact” mode is enabled, but you can always turn it off if you like. The month date format is also highly customizable.

[ChangeLog]

  • added month list view in ‘compact’ mode, the page will smoothly scroll to that month if clicked
  • added an option to hide the month list, thus disable the scroll capability
  • added an option to customize the date display format for month list

See Archives of The Year for a live demo.