Samson's Blog

  • Home

  • About

  • Archives

Grid Archives 1.5.1

Posted on 2012-02-20 | Edited on 2018-11-29 | In PHP , Share , Technique , WordPress
Symbols count in article: 721 | Reading time ≈ 1 mins.

After such a long time, Grid Archives seems definitely need some love. Sorry my old friend, I was really..really busy. I mentioned I haven’t updated wordpress and plugins for quite a while before, now it’s not a problem anymore, cause I’ve bravely clicked that “Update Now” button (( with backup, of course :) )). It’s glad to see Grid Archives still works properly. So with some small minor style changes, Grid Archives 1.5.1 is released. I’m aware of that there’re still some issues to address. I will do address them… when I have some time. [ChangeLog]

  • minor css style changes
  • make the plugin compatible with wordpress 3.3

No big changes, but you can still verify it by navigating to the live demo page if you want.

Introducing SublimeTask (GTD)

Posted on 2012-02-15 | Edited on 2018-11-29 | In Share , Sublime Text 2 , Technique , TextMate , Tools , Vim
Symbols count in article: 3.5k | Reading time ≈ 6 mins.

[Overview] We already have Vim-Task, now we need one task plugin for Sublime Text 2. [Screenshot] As always, I’m a fan of the mac default font monaco, unfortunately it doesn’t support bold and italic: If you use font (e.g. Consolas) which support bold and italic and your current color scheme also support these highlighting, you can config the “scope” to display whatever style you want (see Customization section below). [Code Repository] github: https://github.com/samsonw/SublimeTask [Installation] I assume you have git installed, if not, you can download the latest source from Github Downloads then copy the whole directory into the Packages directory. The location of the “Packages” packages directory depends on the OS you’re using, below is a possible location that you may find your Packages directory:

  • OS X: [cc lang=”bash”]~/Library/Application Support/Sublime Text 2/Packages[/cc]
  • Linux: [cc lang=”bash”]~/.Sublime Text 2/Packages[/cc]
  • Windows: [cc lang=”bash”]%APPDATA%/Sublime Text 2/Packages[/cc]

We will take OS X for example for all the instructions below: [cc lang=”bash”] $ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/ $ git clone git@github.com:samsonw/SublimeTask.git [/cc] TODO: add this Package to sublime_package_control, so later we can install it directly in editor via package control. UPDATE: This package has already been accepted by sublime_package_control, now you can install it directly in the editor, the package name there is just called “Task”. [Shortcut Key & Key Binding] By default, I mapped Command+Ctr+Enter (OS X) and Ctrl+Shift+Enter (Windows, Linux) for toggling the task status, you can simply remap to what’s the most comfortable for you in your Default User keymap file ((Default (OSX).sublime-keymap, Default (Windows).sublime-keymap, Default (Linux).sublime-keymap)). OS X: [cc lang=”javascript”] [ { “keys”: [“super+ctrl+enter”], “command”: “task”} ] [/cc] Linux, Windows: [cc lang=”javascript”] [ { “keys”: [“ctrl+shift+enter”], “command”: “task”} ] [/cc] [Customization] To change the task display color, you need to edit a file called Task.tmLanguage bundled together with this SublimeTask package. [cc lang=”bash” nowrap=”false”] $ subl ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/SublimeTask/Task.tmLanguage [/cc] (you may need to enable sublime command line invocation to execute above command) [cc lang=”xml”] comment Completed Tasks match ^\s✓[^\[\]] name string [/cc] As you can see above, I use “string” scope for the Completed Tasks by default, which will be mapped to green in my color scheme file. If it doesn’t look good in your color scheme, you can simply customize it by changing “string” to something appropriate to your color scheme. You can find the scope name in your color scheme file. [File Format & Syntax] The Task grammar and commands by default apply to file todo.txt and files with extension .task, .tasks, .todo and .todolists. You can also customize this by editing SublimeTask/Task.tmLanguage: [cc lang=”xml”] fileTypes task tasks todo.txt todo todolists [/cc] All the formats and syntax is similar, quoted below for your references:

Headers end with a colon (“:”). Pending (uncompleted) tasks start with a hyphen (“-“). Completed tasks start with a checkmark (“✓”). Headers and tasks can be indented for grouping/hierarchy, as seen in the screenshot above.

[Bug & Feedback] Please report bugs and issues to github: https://github.com/samsonw/SublimeTask/issues, any feedback and suggestion is welcome.

Something Bad Happens

Posted on 2012-01-29 | Edited on 2018-11-29 | In Life
Symbols count in article: 236 | Reading time ≈ 1 mins.

code 500… especially for people who are so addicted to update.. like me the worse thing is right now I even tend to keep it just as is… cause if do, it may really cause “Something Bad Happens”… hehe, anyway, happy new year everyone :)

Busy Season

Posted on 2011-12-30 | Edited on 2018-11-29 | In Life
Symbols count in article: 117 | Reading time ≈ 1 mins.

See Nov and Dec of the archives page this year. This should give you a visual explanation of what I called “busy” :)

Sublime Text 2 Upgrade Problem

Posted on 2011-12-12 | Edited on 2018-11-29 | In Share , Technique , Tools
Symbols count in article: 1.5k | Reading time ≈ 2 mins.

搞了半天发现好还毕竟不是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: [cc lang=”bash”] 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 [/cc] 最为简单粗暴的方法是重装,鉴于我装的plugin/package有点多,且都做了各种配置,所以对此心有余悸,不过作为backup plan倒未尝不可。 另一种方法便是看error的trackback了,瞧,人家就是friendly,error分明是在complain读了一个bad zip file,那究竟那个坏小子藏在什么地方呢,root的package我知道,就是sublime的library目录(位于~/Library/Application Support/Sublime Text 2),但事实证明这个还真不好找,因为人家虽然是zip格式,但并不以.zip结尾…… 最后找了半个多小时,终于在Installed Packages目录下找到了元凶,貌似是一个codeIntel插件出了点问题,这可能跟我之前装完之后又手动build有关,anyway,干掉它先,毕竟我需要开起来工作先,完美的解决办法留给以后有空再慢慢找吧。 [cc lang=”bash”] mv SublimeCodeIntel.sublime-package /tmp [/cc]

Downgrade Rubygems

Posted on 2011-12-05 | Edited on 2018-11-29 | In Ruby , Ruby on Rails , Share , Technique
Symbols count in article: 564 | Reading time ≈ 1 mins.

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): [cc lang=”ruby”] gem update –system 1.4.2 [/cc] 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

Posted on 2011-11-24 | Edited on 2018-11-29 | In Share , Technique
Symbols count in article: 527 | Reading time ≈ 1 mins.

首先,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 ((我不是其sales……))解决了问题,它可以导入之前用tunnelblick创建的profile,所以可见tunnelblick这一领域还是相当那啥的,我看到其最新beta release就在上个月,所以tunnelblick重新work应该只是个时间问题,吧,呵呵。

Free Loop

Posted on 2011-11-24 | Edited on 2018-11-29 | In Life , Music , Share
Symbols count in article: 157 | Reading time ≈ 1 mins.

从今往后再在blog里面放音乐的话不出意外的外都会转向: music.samsonw.info 今天就开始生效,虽然目前还只能算是个workaround,but牛奶会有的,面包也会有的~ Free Loop - Daniel Powter http://music.samsonw.info/#free_loop

Update 62: 点下题

Posted on 2011-10-31 | Edited on 2018-11-29 | In Life , Share
Symbols count in article: 632 | Reading time ≈ 1 mins.

1. 公道自在人心在当前似乎只是一个公共信仰,如同很多的宗教信仰一样,这些都是有利于统治阶级(更modern一点的说法就是既得利益者)那啥的,依赖它们可能还不如依赖于上帝来的靠谱(当然上帝也是宗教信仰了……),当前上帝显然是在玩忽职守,“善有善报,恶有恶报”只是上帝一直未曾兑现的承诺罢了,上帝有许诺过这样的承诺吧? 2. 打印机就是个单线程应用程序,这就和用webrat跑起来的dev环境的rails app一副德性,不知道以前打印机(单台)厂商有没有考虑过实现并行的功能,应该可能也许大概根本不需要吧…… 3. 每天少上微博(无论哪种sns)10分钟,想想每天都在干啥干了些啥没干些啥应该干啥不应该干啥,比每天在那无止境无目的的刷着timeline要强无数倍;那么今天,你又刷了吗?(汗,我知道你刷了信用卡……) 4. 兴趣太广的坏处是显而易见的,我曾经并且已经深刻的感觉到了;但是眼下又有似乎不pick up就有太土太鳖太out的某个兴趣爱好等着我去重新或者崭新的拥有兴趣,不然后果可能是…… 哈哈,我不告诉你; 5. 这个bullet纯粹是为了点下题,当然这里要点下题的题目就是“点下题”,you get the idea……;话说我突然很喜欢“纯粹”这个词,因为我感觉它无论念起来还是看起来的时候都感觉那么纯粹,或许潜意识的影响太大了,以至于“纯粹”看起来就很纯粹,“恶心”看起来就很恶心,然后“麻烦”看起来就很麻烦? 6. 本人不善于傻笑,鉴定完毕。

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

Posted on 2011-10-28 | Edited on 2018-11-29 | In Node.js , Share , Technique
Symbols count in article: 3k | Reading time ≈ 5 mins.

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

创建Object / Array

逗号应放在行尾而不是行首,每一行放置简短的变量声明。只在你的解释器抱怨的时候才应该去给array的key上加上引号。 正确: [cc lang=”javascript”] var a = [‘hello’, ‘world’]; var b = { good: ‘code’, ‘is generally’: ‘pretty’, }; [/cc] 错误: [cc lang=”javascript”] var a = [ ‘hello’, ‘world’ ]; var b = {“good”: ‘code’ , is generally: ‘pretty’ }; [/cc]

等号操作符

编程不是仅仅记住那些愚蠢的规则。比如我们应该使用三个等号的相等操作符,因为它会有我们意料之中的行为。 正确: [cc lang=”javascript”] var a = 0; if (a === ‘’) { console.log(‘winning’); } [/cc] 错误: [cc lang=”javascript”] var a = 0; if (a == ‘’) { console.log(‘losing’); } [/cc]

原型扩展

不要扩展任何对象的prototype原型,特别是native的对象。如果你不遵守这条准则,地狱里面某个特殊的地方正在等着你。 正确: [cc lang=”javascript”] var a = []; if (!a.length) { console.log(‘winning’); } [/cc] 错误: [cc lang=”javascript”] Array.prototype.empty = function() { return !this.length; } var a = []; if (a.empty()) { console.log(‘losing’); } [/cc]

条件判断

任何只要不是没用的条件判断都应该被赋予一个有意义具有描述性的变量名: 正确: [cc lang=”javascript”] var isAuthorized = (user.isAdmin() || user.isModerator()); if (isAuthorized) { console.log(‘winning’); } [/cc] 错误: [cc lang=”javascript”] if (user.isAdmin() || user.isModerator()) { console.log(‘losing’); } [/cc]

函数长度

函数尽量保持简短。一个好的函数应该能够完整的放到一张幻灯片里面,且能让一个大会议室的最后一排观众可以轻松舒适的阅读到。所以不要指望他们都有很好的视力,你应该限制你的每个函数都在10行左右。

Return语句

为了避免if语句的深层次嵌套,函数内部尽量越早return越好。 正确: [cc lang=”javascript”] function isPercentage(val) { if (val < 0) { return false; } if (val > 100) { return false; } return true; } [/cc] 错误: [cc lang=”javascript”] function isPercentage(val) { if (val >= 0) { if (val < 100) { return true; } else { return false; } } else { return false; } } [/cc] 就这个例子来说,我们还可以更加简化: [cc lang=”javascript”] function isPercentage(val) { var isInRange = (val >= 0 && val <= 100); return isInRange; } [/cc]

命名闭包

可以给你的闭包取个名字。这意味着你很关心它们,且会产生更好的堆栈跟踪(stack trace)。 正确: [cc lang=”javascript”] req.on(‘end’, function onEnd() { console.log(‘winning’); }); [/cc] 错误: [cc lang=”javascript”] req.on(‘end’, function() { console.log(‘losing’); }); [/cc]

嵌套闭包

使用闭包,但不要嵌套它们。否则你的代码会变的一团糟。 正确: [cc lang=”javascript”] setTimeout(function() { client.connect(afterConnect); }, 1000); function afterConnect() { console.log(‘winning’); } [/cc] 错误: [cc lang=”javascript”] setTimeout(function() { client.connect(function() { console.log(‘losing’); }); }, 1000); [/cc]

回调(Callbacks)

由于node意味着到处都是非阻塞I/O,函数通常都会使用回调函数来返回结果。node核心开发小组的惯例是保留回调函数的第一个参数,以用来存储可能存在的error对象。 你应该在你自己的回调函数里使用相同的方法。

Object.freeze, Object.preventExtensions, Object.seal, with, eval

这些都是些疯狂的东西,你很有可能永远不需要它们。远离它们。

Getters and setters

不要使用setters,它们会产生远比它能解决的麻烦多的多的麻烦。 可以在不产生副作用的时候使用getters,比如给你的集合类提供一个length属性。

EventEmitters

Node.js自带了一个简单的EventEmitter类,它可以从’event’模块里面进行include: [cc lang=”javascript”] var EventEmitter = require(‘events’).EventEmitter; [/cc] 在创建复杂的类的时候,继承这个EventEmitter类来用来产生事件是很常见的做法。这基本上就是一个简单的观察者模式的实现。 不过,我强烈建议你不要在你自己的类里面监听它自己所发出的事件。让一个对象监听它自己是很不自然的。它经常还会以你不希望的形式将你的实现细节暴露出来,同时让你的代码更难看懂。

继承 / 面向对象编程

继承和面向对象编程它们本身各自都是主题。如果你对这个流行的编程模型有兴趣,请阅读我的面向对象编程指南。

1…91011…35
Samson Wu

Samson Wu

天与弗取,反受其咎;时至不行,反受其殃

347 posts
148 categories
140 tags
GitHub
Creative Commons
Links
  • Portfolio
  • Resume
© 2007 – 2018 Samson Wu | 309k | 8:35
0%