SMS Backup and Restore on Meego

Recently I’ve got a N9 to play with. The boring thing is I cannot restore my old SMSs. So I wrote a small utility to backup and restore.

The repo is located at GitHub. The deb file can also be downloaded there.

Notice To compile from source code, follow the intruction on Harmattan Platform SDK to build the environment, and run

apt-get install libcommhistory-dev

to have libcommhistory headers. (Thanks Philipp Zabel for helping me on that)

Update Growl framework for MacDroidNotifier

Android Notifier sends the notifications to computers. Here’s the article on lifehacker.

I’m using Mac, so I installed MacDroidNotifier from the project home. But as I installed Growl 1.3.2, without backward compatibility. So I updated Growl framework for MacDroidNotifier.

The project home is on GitHub, and MacDroidNotifier can be downloaded here. It’s tested on Mac OS X Lion 10.7.2.

Compile lbn for Lua 5.1.4

Lua is powerful. It’s so small that some “advanced” features require 3rd party libraries.

I want to operate high precision integer, which Lua doesn’t provide.

I got lbn at http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/. lbn requires openssl only.

Download and unarchive it.

Edit Makefile to have correct environment vars, LUA, LUAINC, LUALIB, LUABIN. I installed Lua by homebrew, so the path is

LUA= /usr/local/Cellar/lua/5.1.4
LUAINC= $(LUA)/include
LUALIB= $(LUA)/lib
LUABIN= $(LUA)/bin

If Lua is compiled by selves, use

LUA= /path/to/lua-5.1.4
LUAINC= $(LUA)/src
LUALIB= $(LUA)/src
LUABIN= $(LUA)/src

But, I got the error

Undefined symbols for architecture x86_64:
"_luaL_newmetatable", referenced from:
  _luaopen_bn in lbn.o
"_lua_setfield", referenced from:
  _luaopen_bn in lbn.o
"_luaL_register", referenced from:
  _luaopen_bn in lbn.o
…

But the Lua library is already compiled by x86_64

$ file liblua.5.1.4.dylib
liblua.5.1.4.dylib: Mach-O 64-bit dynamically linked shared library x86_64

The problem is the library is not used during compilation. (LUALIB is not used anywhere)

The solution is changing these lines in Makefile

$T: $(OBJS)
$(MAKESO) -o $@ $(OBJS) -lcrypto

to

$T: $(OBJS)
$(MAKESO) -o $@ $(OBJS) -lcrypto -L$(LUALIB) -llua

And it just works.

Notice: It works in Lua 5.1.4 now, and it should work in Lua 5.2, but some effort need to be made. (Lua 5.2 deprecated some API as I see)

Use OpenVPN on Galaxy Nexus

I recently got a Galaxy Nexus to play with. What I hate is Android doesn’t provide native proxy support, or OpenVPN support, because I’m in China.

First step: Root the device

I followed the instruction on GalaxyNexusRoot.com.

Next: Install openvpn

  • Install OpenVPN Installer on Android Market. Run the application and install openvpn and ifconfig and route to /system/xbin.
  • This step is important: making ifconfig and route in /system/xbin/bb, because openvpn will execute /system/xbin/bb/ifconfig to create tun0 interface, otherwise, the device will connect to the server without an interface to send packets.

    • Install SSHDroid on Android Market. SSH to the device and run

      mkdir /system/xbin/bb
      ln -s /system/xbin/ifconfig /system/xbin/bb/
      ln -s /system/xbin/route /system/xbin/bb/
      
    • If it says “Read-only file system”. Run the following command first to make it read/write, and then run the above commands.

      mount -o remount,rw -t ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/system /system
      

      Update: A simplified version:

      mount -o remount,rw /system
    • Later, you can choose to make to readonly again by

      mount -o remount,ro -t ext4 /dev/block/platform/omap/omap_hsmmc.0/by-name/system /system
      

      Update: A simplified version:

      mount -o remount,ro /system

Run it

Now it’ll be fine to run OpenVPN by OpenVPN Settings. Just copy OpenVPN configuration files into /mnt/sdcard/openvpn and run it in OpenVPN Settings.

The problem I met

Update: OpenVPN Installer 0.2.4 fixed the problem by providing the option with openvpn using /system/xbin/ifconfig and /system/xbin/route

At the beginning, I tried to connect using OpenVPN Settings but failed, but from logs by adb mixed with system logs, I couldn’t find useful information. I didn’t find the tun.ko on the device, and I searched and viewed a ton of pages and found nothing.

Though from TUN.ko Installer I saw Tun module is loaded, and Path to tun.ko is not found!, I thought there was some problem with the software that showing inconsistent information. I gave a last try to DroidVPN, and I succeeded to connect!

Before that, I even downloaded the source and was ready to compile tun.ko myself. The lesson is to try every possible way, a problem can be caused by any possible reason.

Tunnelblick’s network change monitor

Tunnelblick is the OpenVPN client under Mac OS X.

It’s easy to use, but I’ve got some special requirement for that: I want to have my own DNS settings and need Tunnelblick’s network settings change monitor. However, currently, it only works with default name server setting.

So I read part of the source code to find the possibility to do some hack.

All the setting interfaces are related to SettingsSheetWindowController.m, which interacts with the UI, and saves the values in global gTbDefaults. VPNConnection.m is the one who parses the configurations and passes them to openvpnstart. Almost all configurations can be found in method argumentsForOpenvpnstartForNow: in VPNConnection.m, surely including the one I’m tracking: “doNotRestoreOnDnsReset”.

openvpnstart is another executable to actually run openvpn, also up and down scripts. The up script will start leasewatch if necessary, i.e. “Monitor network settings” is checked in Tunnelblick settings. Leasewatch is the daemon monitoring network changes, and it’s run by launchd.

The plist used by launchd includes a key called WatchPaths. Leasewatch uses that to get notified to do any changes, and the old values are saved in system configurations accessed by scutil.

Fine, I think it works, but too complicated, though I now cannot get a smarter way yet. And I still need read more to find a way to have customized DNS settings monitored for changes.

[Alfred Extensions] Sleep Display

Alfred Powerpack allows users to use extensions. And I do need a shortcut to sleep my displays. That’s how it comes from.

A simple extension to sleep display quickly. It’s a wrapper of a binary file.
The code to generate the binary is from Command to Sleep Display OSX

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
 
/* Returns 0 on success and 1 on failure. */
int display_sleep(void)
{
    io_registry_entry_t reg = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
    if (reg) {
                IORegistryEntrySetCFProperty(reg, CFSTR("IORequestIdle"), kCFBooleanTrue);
                IOObjectRelease(reg);
        } else {
                return 1;
        }
        return 0;
}

At the beginning, I cannot run the binary inside the extension directory, but my home or my previous session’s directory. And that’s because I didn’t check the “Silent” option, which makes the default startup directory is the extension’s.

Well, it’s easy to use: just type the keyword, and hit Enter.
What I hope is Alfred 1.0 to support Global Hotkeys for extensions.

Oh, forgot to say, Download it here.

PS, PadLock is another app doing the same thing costing $2.99. The other feature of the app is to give you the buffer to cancel the lock operation, useful also.

Install postgis on Mac Lion

Updated to Lion recently, I need install postgis with MacPort.
Postgis depends on geos, which I failed to install with the error

:info:build Undefined symbols for architecture x86_64:
:info:build   "__ZNSt8auto_ptrIN4geos4geom8EnvelopeEEcvSt12auto_ptr_refIT_EIS2_EEv", referenced from:
:info:build       virtual thunk to geos::geom::GeometryCollection::computeEnvelopeInternal() constin GeometryCollection.o
:info:build   "std::auto_ptr::auto_ptr(std::auto_ptr_ref)", referenced from:
:info:build       virtual thunk to geos::geom::GeometryCollection::computeEnvelopeInternal() constin GeometryCollection.o
:info:build ld: symbol(s) not found for architecture x86_64
:info:build collect2: ld returned 1 exit status

It’s said to have been fixed in https://trac.macports.org/ticket/30309, but still failing at latest macport. And the temporary solution mentioned in the ticket doesn’t work either.

sudo port install geos configure.cc=gcc-4.2 configure.cxx=g++-4.2

I got the imperfect way. That is to install geos by non-macport way.

  • Download GEOS framework for Snow Leopard/Lion from http://www.kyngchaos.com/software:frameworks#geos, and install it.
  • Install proj

    sudo port install proj
  • Download postgis source code from http://postgis.refractions.net/download/
  • Unarchive and install with

    ./configure --prefix=/opt/local --with-geosconfig=/Library/Frameworks/GEOS.framework/unix/bin/geos-config --with-projdir=/opt/local
    make
    sudo make install
    
  • Notes on Postgresql 9.0 High Performance (1)

    Regarding the hardware, there are 3 parts basically: CPU, Memory and Disk.

    For CPU:
    There are two choices: Faster cores or more cores. It depends on the application. Postgresql runs queries by processes, so if the application need single complicated queries, faster cores should be the one, and if the application does the small update quite frequently, like real-time games, more cores can help more.

    For Memory:
    It doesn’t worth upgrading memory if: 1) the database is small enough that it can already be totally read into memory. 2) the tables are much bigger that it’s better to enhance CPU and disk. However, reading part of frequently accessed data into memory will be helpful.

    For Disk:
    SSD is a bit small, the others are a bit slow. Need to consider much, including different disk type (SATA, SAS), RAID, disk write caches, etc, to choose disk(s). Well, I don’t care about that much, leave it now.

    VPS Review: prgmr

    I like the statement in their homepage: We don’t assume you are stupid.

    I needn’t to pay for unnecessary management, which I could do almost by myself. And seems prgmr is the best unmanaged VPS from the reviews. Yes, it’s cheap, only $12/month for 512M, while others (semi-managed or managed) at least $20, like famous Linode, and even more expensive by some Chinese VPS providers.
    I purchased on Saturday, but could not find a payment link until Monday. I have to say the user interface is not friendly at all. Anyway, I paid on Monday and got the server set up in a few hours.

    I set up VPN, nginx, php and the blog here, and until now it runs smoothly.
    The network was quite unstable in the first few days from China, and I even tried to find a refund way. It’s OK for me now, however, though still a bit slow here.
    No down time yet.

    It’s a half a month review. So if you want a stable, cheap, unmanaged VPS, and you can suffer a bit the slow network from China, give it a try.

    Adium message time style change

    I’m using Adium now. But the problem is when I enlarge the font of messages in “Messages” tab of Preferences, the font of time doesn’t change accordingly. So I’ve got big enough message text, and half size time text. That’s really uneasy to get used with.

    Common sense, that it’s hard to expect the developer to deal with your requirement in high priority, they always get more important things to do. I have to help myself.

    Luckily, it’s controlled by a css file. As my Adium is installed in /Application, and I’m using “yMous” style, the css file is located as

    /Applications/Adium.app/Contents/Resources/
    Message Styles/yMous.AdiumMessageStyle/Contents/Resources/Styles/Base.css

    There is a “font-size: 0.5em” in a .x-time, change that to 1em, and restart Adium, and everything looks beautiful!

    Update: It’s boring to change it every time when Adium updates, so I moved it to ~/Library/Application Support/Adium 2.0/Message Styles, and changed its name to yMous-big.AdiumMessageStyle, and changed the Info.plist accordingly. Open the new folder in Finder or “open”, “new” message style installed