twtplus updated for Ubiquity 0.5+
twtplus.ubiq.js
My friend Ryan and I just launched our team site Icecodez, which is dedicated to our iPhone apps development. The FIRST app by Icecodez just got out this week. Check out IceMetro Shahghai Subway Map Lite (itunes link). It’s an interactive map for Shanghai subway. And it’s free! Isn’t that ice cool?
*Corrected yajl include path. Updated info about adding YAJL static lib to project for deploying on device
MGTwitterEngine is a great Objective-C library for the Twitter API. Did you know the famous Twitterrific for iPhone (iTunes link) is built with MGTwitterEngine plus YAJL? You probably know that from the now famous YAJL error Twitterrific presented you when the Twitapocalypse hit the world, right?
But setting up MGTwitterEngine and YAJL for iPhone development turned out to be more difficult than I thought, due to the lack of documentation, and my lack of extensive experience with iPhone and Mac development. Anyway, after some hacking around, I finally got the two boys to play together and work with my next cool iPhone project. The following is how I did it and I think it might be useful to someone else wrestling with the same problem out there.
First, get the latest YAJL code and get it compiled.
git clone git://github.com/lloyd/yajl
If you don’t have cmake on your Mac yet, get it via MacPorts. (The cmake version from Fink is too old to compile YAJL. I’ve tried it.)
sudo port install cmake
Now compile YAJL
cd yajl sudo ./configure && make install
Now you should have “yajl-1.0.6″ under the “build” folder. And the build process should have copied the binaries to /usr/local/lib/ and /usr/local/include/yajl respectively.
Get the latest code from the SVN repo.
svn checkout http://svn.cocoasourcecode.com/MGTwitterEngine
Add everything from the MGTwitterEngine directory starting with ”MGTwitter”, and also the NSString+UUID and NSData+Base64 category files, to the Xcode project. Choose to copy the files to the project.
MGTwitterEngine doesn’t support Twitter’s search and trends API without YAJL, because these APIs only return JSON data. So obviously we need to tell MGTwitterEngine we have YAJL and please give us the support search and trends APIs, in addition to requesting JSON data for other Twitter API calls.
In MGTwitterEngineGlobalHeader.h
#define YAJL_AVAILABLE 1
Now add the required frameworks to the Xcode project.
Locate “/usr/local/lib/libyajl.dylib”, drag and drop it onto “Frameworks” in the Groups & Files pane in Xcode. Don’t choose to copy the files.
**BEGIN UPDATE**
Compiling YAJL from the source using the shipped makefile will produce the dynamic library binary files (yajl*.dylib) under /usr/local/lib. Although adding these files to the frameworks gets the project to compile and run on the simulator, this won’t work on a device since only static libraries are allowed on devices for third party frameworks.
Compiling the static library from the source code requires a bit more work but I found someone has already done that with more good stuff like an Obj-C wrapper for YAJL. So we can now simply grab this compiled YAJL static library for iPhone, exand it, then add the file “libYAJLIPhone.a” to the Frameworks.
**END UPDATE**
Then also add “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib/libxml2.dylib” to Frameworks.
Next, open Project Info, locate the Build page, and look for the “Header Search Paths” property. Add the following two paths to the search paths property.
/usr/local/include/yajl $SDKROOT/usr/include/libxml2
*Although it seems LibXML is not required, I did get compilation errors if LibXML is not in the Frameworks.
It appears that MGTwitterEngine is still written against a previous version of YAJL (supposedly a pre-1.0 version). So if at this stage you go ahead and build the project, you will see two errors from MGTwitterEngine.
error: too few arguments to function 'yajl_alloc' error: too few arguments to function 'yajl_free_error'
It looks like the latest version of YAJL has changed its signatures of the functions “yajl_alloc” and “yajl_free_error”. So let’s hack the corresponding code in MGTwitterYAJLParser.m to work around the build errors. Find the calls to these two functions and change the code as follows.
... _handle = yajl_alloc(&callbacks, &cfg, nil, self); ... yajl_free_error(nil, errorMessage); ...
Now you can hit Build and the project should build successfully. Next, you should take a look at AppController.h and AppController.m which come with MGTwitterEngine and see how to use it. It’s pretty easy to use once you get past the compilation problems. Now we have a fully functional and nicely built Twitter library ready to be used for any iPhone project! Also, if you have any suggestion or any better way to get the stuff to work please let me know.
If you want to take advantage of the new APIs from iPhone SDK 3.0 while keeping compatibility with pre-3.0 devices, using the following conditional compilation flag is a good solution.
#ifdef __IPHONE_3_0 //3.0 #else //pre 3.0 #endif
I needed to install cmemcache on a Gentoo box in order to enable Django to work with memcached. But when I tried to compile the cmemcache code, I got such error messages:
‘CmemcacheObject’ has no member named ‘mc_ctxt’
I’m surprised Google didn’t give me many answers. But I came across this post which was very useful. So in the end, here’s how I got cmemcache compiled and installed on Gentoo.
cd ~/code sudo emerge libmemcache wget http://gijsbert.org/downloads/cmemcache/libmemcache-1.4.0.rc2.patch wget http://gijsbert.org/downloads/cmemcache/cmemcache-0.95.tar.bz2 # the patch was made using a folder called reference mkdir reference cd reference tar xjvf ../libmemcache-1.4.0.rc2.tar.bz2 cd .. patch -p0 < libmemcache-1.4.0.rc2.patch cd reference/libmemcache-1.4.0.rc2 ./configure && make sudo make install cd ../../ tar xjvf cmemcache-0.95.tar.bz2 cd cmemcache-0.95 sudo python setup.py install
一直在思考这个问题,如何定义伟大的产品,怎么样才能做出伟大的产品。这个星期某天又折腾了一把Quicksilver,注意到了About窗内的老子语录,真有茅塞顿开的感觉。这不就是最好的对伟大产品哲学的概括吗?!难怪Quicksilver能达到这种境界。
为无为 事无事 味无味 大小多少 报怨以德 圆难于其易 为大于其细 天下难事 必作于易 天下大事 必作于细
我想,要做伟大的软件产品,参照这两条足矣。要是几千年前有电脑,老子就一定是古代的Steve Jobs了。遂发至Twitter与友共勉。
和Xcode打了几个月的交道,总结一下我最常用也是最喜欢的几个快捷键。总的来说Xcode快捷键并不是非常丰富灵活,但熟悉了下面为数不多的几个快捷键以后工作效率马上可以提高不少。
外加一句,深感XCode一定要用All-In-One单窗口的Layout才好用。
iPhone OS 3.0 beta发布后马上下载过来体验了一把,把自己的iPod Touch刷了3.0版firmware,也升级了XCode 3.1.3。这次大版本更新带来了非常多的新特性,iPhone离一台完美的手持设备已经非常非常近了。初步体验下来,3.0版OS的潜力还是要靠app来挖掘,系统的本来面目还没有特别大的区别,众多新特性需要有软件的支持才能用得到。普通用户一上手就能看到的改进主要是spotlight搜索,拷贝粘贴,还有开放的蓝牙(但是默认状态是什么蓝牙服务都没有的)。后台Push,in-app支付,turn-by-turn GPS等等重要特性都要等到众多新版应用出现以后才能体现出强大来。先上几张touch上的截图吧。
Mozilla Ubiquity is not only a wonderful command engine and launcher. It can also be used to do stuff what Greasemonkey is good at, manipulating page DOM dynamically, by utilizing the “pageLoad_” function hook. To demonstrate this case I’ve quickly migrated the recently popular Twitter search on Google monkey script onto Ubiquity. You can get the Ubiq version of Twitter+Google search from here.
I retained the original DOM building code, but replaced the Ajax call with a JQuery one along with a couple hacks explained below to get it working from Ubiquity.
First, while Greasemonkey has built-in mechanism for filtering page URLs for selective script invocation, you have to do that on your own with Ubiquity. Look at the first few lines in the Ubiq command for the regex job to filter out Google search addresses.
var href = doc.location.href;
var q = (/^https?:\/\/(?:www\.)?google\..*\/.*[&?]q=([^&]*)(?:&|$)/(href)||0)[1];
Secondly, before publishing the script, you have to put such a line of comment in the script in order for Ubiquity to consider it an installable command and trigger the install bar at the top of the page. (Kudos to satyr for pointing out this hack)
//function cmd_
In similar ways, most of the Greasemonkey scripts can be migrated to Ubiquity.
Earlier this year I spent some time to write the “twtplus” command for Ubiquity, the intriguing Quicksilver-like plugin for Firefox. I’ve been tweaking it intermittently and now I’m gonna put together a little handy reference for it. Twtplus has the following features:
Most of the features are pretty straightforward. Take a look at the following screenshot. Notice the grey hints after the “twtplus” command when you type and you’ll be fine.
In order to get multi-account posting working, there are a couple things I’d like to mention. First, due to the way the browser works, if you have a logged in session for Twitter, the browser will ALWAYS post your tweet as the currently logged in user, regardless of the one you specifies with the “as” modifier keyword. Thus the solution is to avoid being logged in via the Twitter web interface, or when the stock “twitter” command prompts you a login dailog. If you visit twitter.com and find that you’ve already logged in, log out explicitly.
Secondly, twtplus looks for your stored usernames and passwords for Twitter in your Firefox password manager, for the login authentication to Twitter and provide multiple account autocompletion suggestions. So you need to store your Twitter accounts with Firefox if you haven’t already. This is also a more secure and convenient way than the stock “twitter” command since you don’t need to input your twitter login from time to time.
Update: Here’s an awesome screencast from @neo4zion