# 在node-webkit中使用sqlite3

Error: Cannot find module '/Users/voidmain/WorkSpace/NodeJS/node-webkit-sqlite3-windows-demo/node_modules/sqlite3/lib/binding/node-v11-darwin-ia32/node_sqlite3.node'


For some packages you may need to use node-pre-gyp (e.g. when you get the error “Undefined variable module_name in binding.gyp while trying to load binding.gyp”), which supports building for both node.js and node-webkit by using either node-gyp or nw-gyp.

# NSUserDefaults无法保存？

FML。。花了一上午调了一个bug。。

Also if you move the container while testing / debugging to the trash, the cfprefsd (see Activity Monitor) still keeps a link to the .plist. Empty the trash and force quit both cfprefsd (user and root).

youku地址：

## 我的思考

• 如果想要引发一场潮流的话，首先你要有勇气站出来，表达自己的观点
• 你的观点（产品）必须容易被其他人接受（所谓easy to follow）
• 作为最开始的leader，你需要尝试辅导最开始的几个follower，因为他们很重要（if the leader is the flint,the first follower is really the spark）
• 如果想要引领潮流，不要想着“你”到底有多重要，重要的是这场潮流（movement）

# How to Use New Android Animation API for Compat Fragment

## Why

Since honeycomb (API level 11), Google has introduced a new set of APIs to help developers build better app, including Fragment and property animation.

These new APIs are great, but they are not quite compatible with older devices, thus Google provided a support library to solve this problem.

While building my app, I’m trying to use the compat fragment to support as many devices as possible, meanwhile, I want to take advantage of new set of animation apis to create animation easier.

The FragmentTransaction class has a simple API named setCustomAnimations() to set the animation while switching fragments. But, sadly, when I tried to use the animator xml file (I mean, using property animation elements like <objectAnimator> in the animation xml) on Gingerbread emulator (with API level less than 11), the app simply crashed complaining it does not understand the objectAnimator sh*t, which means you have to give up on the new animation API with compat fragment.

No way!

And finally, I managed to find a way to get this work. Here’s what I’ve tried.

If you are urged to see a demo, please check the readme of this sample on github.

## Starting with a simple fragment

Since this is a experimental project, I don’t want to build some complex fragments, that’s why I decided to use RoundedColourFragment from ActionBarSherlock project.

The fragment is quite simple, it will generate a colored rounded rectangle as the view of the fragment, whose color can be specified as a argument of the constructor.

## Importing NineOldAndroids

In order to use the new animation api on older versions of android, I found of the NineOldAndroids project.

Even though I didn’t quite get its name (sad), the project is really awesome. It somehow managed to give the developer a way to use the new animation apis even on Android 1.0, amazing. It’s fun, but the only way is you cannot put them in XML files, still need to work out how to use the animation.

## Two parts of the animation

Not being able to use the animation in XML files, I have to write some code to make this happen. Here’s a methods I defined to trigger the new animation.

This is the first part of the animation, the old fragment fliped to disappear by changing the rotationY property from 0 to 90 degree. Once this animation is finished, I need to replace the old fragment with the new one by calling FragmentTransaction#replace method.

But we cannot simply let the new fragment appear and be there, it will be awkward. So, I’ve designed a callback that will be triggered once the new fragment’s view is ready, the code is listed below.

Once the view is created, I’ll kick off the second part of the animation, which changes the rotationY property from -90 degree to 0. Here’s the code.

And now, the animation is working perfectly.

## Show me the code

I’ve created a project on github, called FragmentCompatAnimator, make sure to check it out.

## Conclusion

It is always a good idea to use new APIs for better performance and use experience. But compatibilty is a tough problem. Thanks to all opensource framework contributors, it is and will be easier for us developers to take advantage of the new APIs but still be able to make it work on older devices.

# [更新-教程]如何在Mac上玩儿国服星际2（原生，非port版）

##更新

–原文–

### 准备工作

~~- 在Windows上下载一个星际2的客户端，用网易提供的绿色版就行。

• 在Mac上下载台湾（美国应该也行，我没测试过）服务器的Mac客户端。在Mac上进行安装，注意，不用全部更新完成，更新至绿色可执行状态即可。
• 下载Support.dmgSC_II_apps&toolsCN[2.0.6.25180].dmg两个文件，注意，不要用浏览器打开，用迅雷直接下载URL。~~

### 开始替换

~~以上内容全部下载完成后就要开始操作了：
1.把国服绿色版压缩包解压。
2.把Support.dmg和apps&tools.dmg里面的内容复制到解压路径下，必要时替换对应内容。
3.把Mac上台湾客户端下的StarCraft IIStarCraft II EditorStarCraft II Public TestVersions的内容复制&替换到解压路径下。
4.启动游戏，这个时候游戏的客户端可能会一直停在初始化阶段，可以从菜单中选择修复客户端，然后静静的等着它完成更新。
5.更新结束后，点击执行，这时候发现，客户端的右边多了中国特色的几行字，恭喜你，成功了！
~~

# What I have learned from terminal-notifier

The terminal-notifier is a cute command-line tool written by alloy that sends User Notifications for OS X systems running 10.8 or later.

There’s not so much code down there, but still I’ve learned a lot, and here’s what I’ve got:

### Architecture Overview

There are two major parts in this project. To deliver NSUserNotification or respond to user click event, we need a Cocoa App even though there will never be a display window or something. According to the builder, it is currently packaged as an application bundle, because NSUserNotification does not work from a ‘Foundation tool’.

To provide a easier way to install and use terminal-notifier, the project also provides a ruby gem, whose source is located at Ruby/ folder of the project.

As for the communication, I’ve managed to draw a small graph below:

The ruby gem is in charge of providing a command-line interface. Once the arguments are collected, it will call the Cocoa App’s bin file with extra arguments. By then, the Cocoa App will read the arguments and deliver the notification to user.

That’s quite straight-forward, yet the result is amazingly powerful. Let me tell you the technique details I’ve learned below.

### Lesson #1 - Are we running this app on OS X 10.8 or later?

Easy, but you need to know two commands, namely uname and sw_vers. You can refer to man to see what exactly they are doing, briefly, uname tells the name of the operating system, which is Darwin for OS X, and sw_vers returns the version info for OS X.

And here’s the code from terminal-notifier:

This is ruby code, and it’s easy to understand I believe.

### Lession #2 - Don’t forget some useful variables

Just a quick flash back, $0 refers to the name of current running script, $: is the same as $LOAD_PATH and $? is the status code of the last process terminated. For a detailed list, please refer this article.

### Lession #3 - NSUserDefaults will help you with the command-line arguments

Parsing command-line arguments is not an unusual job, there are surely a lot of ways to do this in all programming languages. As I’m new to Cocoa Programming, I DID NOT know that one can read command-line arguments using NSUserDefaults. Imagine how I felt lost while reading the following code:

Who the heck fills the standardUserDefaults for us with the command-line arguments? It’s impossible.

But, indeed, it is possible. I’ve found this article that explains the defaults domain and their precedence. As it turns out, it is the NSArgumentDomain that does the heavy-lift job of parsing the arguments and store them into the standardUserDefaults. Note that this is quite a good way, espically overriding the system wide defaults with command line arguments. It is a way of hacking something, I guess.

### Lession \$4 - Easier API with objectForKeyedSubscript:

What if you want to grab some object using [] operator, by that I mean instead of retrieving object like dict[@"key"] rather than [dict objectForKey: @"key"]. And again, it’s simple, just implement the objectForKeyedSubscript: method for the class or add category with some predefined classes. Here’s the example from terminal-notifier:

With this code snippet, we add the power of subscription to NSUserDefaults, and it’s fun to use.

### Conclusion

I’ve learned the 4 major lessons from terminal-notifier, but there are many other lessions I’ve not mentioned. And to write better code, we should all read more f**king code.