Caching prepared SQLite statements in iOS application

Many applications use Core data for iOS devices, others utilize frameworks like fmdb. But there are also people that write SQLite access from scratch. The comes the answer – how do you cache prepared statements (I will not discuss here why we cache prepared statements)?

Well – I have implemented 2 methods:

  • 1) Using C syntax to maintain array of sqlite_stmt*
  • 2) Using NSPointerArray* to store sqlite_stmt* that are prepared

First approach has it’s advantages in regards of using older SDKs (NSPointerArray is available from iOS 6.0+)

Second approach is more elegant, but as mentioned – only for newer versions.

Lets have some code:

Using C syntax

Code to prepare and cache statements:

This is pretty much everything. Of course don’t forget to release and finalize statements on db close.

In second approach – just instead of using (sqlite**) – replace with (NSPointerArray*):

Fetch and store statements:

Enjoy~

Migrating from SVN to GIT

Suppose you have a SVN repository and you would like to move to GIT – there might be many arguments around this. Well – here are some steps that I have tried to synthesise after many attempts and reading in internet. I am sure there are many approaches, but this one works for me straight forward.

The whole procedure consists of several steps:

  • Extracting users from SVN and creating a mapping file SVN_USER <-> GIT_USER
  • Cloning SVN repository into GIT repository
  • Migrating branches
  • Migrating tags
  • Creating new GIT detached repository and pushing all changes to it

Here are some assumptions:
You will work in one directory, where you will create


YOUR_GIT_REPO_DIR
NEW_GIT_REPO
svn-git-users-mapping.txt

YOUR_SVN_REPOSITORY_URL – is the URL that you use to checkout from SVN.

Lets start

Extracting users from SVN and creating a mapping file SVN_USER <-> GIT_USER

GIT needs to know how to map users from SVN to it’s format. Usually users in SVN are just usernames, where in GIT they are in format

So at the end we should produce a mapping file that looks like:

So execute the following command in your checkout svn repository, in order to create a file with the mapping svn-git-users-mapping.txt

Edit the produced file with correct User names and emails on the right side.

Cloning SVN repository into GIT repository

The following code executed in terminal will first create a directory, and clone svn into git repository in this directory, using svn-git-users-mapping.txt file for transforming users.

This script uses the standard SVN layout (trunk, branches, tags) – if you have a different structure – you can explicitly specify it, using parameters (-T trunk -b branches -t tags)

Migrating branches

Now is time to migrate branches – enter the created directory (YOUR_GIT_REPO_DIR) and execute the following script (this is a bash script, so if you use another shell, maybe you have to adjust it):

Similar process is used for the next point too:

Migrating tags

Now that we have fully migrated repository, if we want a detached one from SVN (currently the created repo is connected to svn and can be used that way, with commends git svn rebase --all – to fetch and rebase all changes from SVN, and git svn dcommit --interactive – to push changes from git local commits to remote SVN repo).

Next step:

Creating new GIT detached repository and pushing all changes to it

Now you are ready to use the newly created GIT repository, having all your history, branches and tags.

In next article I will try to share my experience of using SVN as central repository, and GIT as local versioning and client.

Here are some links that I used, while researching the best way to do the migration:

Converting a Subversion repository to Git

Stackoverflow: How to migrate SVN with history to a new Git repository?

Experimenting with Git at Slide (Part 1/3)

Tool to manage svn-externals with git

~Enjoy

When WordPress responds with 404 Error at wp-admin

Somethimes is can happen, that when you try to access your blog at
http://yourhost/youblog/wp-admin

you end with a page showing 404 Error and in the url we see that we have been forwarded to
http://yourhost/youblog/wp-login.php?…

If you trace the logs of the server, what you will find is something similar to:
client denied by server configuration: wp-login.php

If this is the case – so most probably the problem comes from .htaccess file in your blog.
When you open it you will have something like:

The problem comes from the third line – where “allow”-ed addresses to access login are registered. Check in the logs the IP address that you use to access wp-admin, or specify “All” if you want to be able to access admin from any place.

~Enjoy

How to speed up Android Emulator on uX system – UPDATED

If you are developing for Android, you probably have already abandoned the emulator that comes with Android SDK, and are testing and debugging on a real device. I cannot blame you – the emulator is awfully slow. Well I have good news for you – you can speed it up, if you are using uX system (Unix like – Linux, Mac OS X, BSD).
The trick is very simple – and I suppose some of you have already activated it – mount /tmp folder into memory. The reason why the emulator is much more faster – is that when the emulator is started, the image is expanded into /tmp folder – and all the communication goes through there. Normally it goes through DiskIO, and the trick is to do it through much faster channel – memory.

Here is the way to do it in Linux:

add the following line at the bottom:

This will mount your /tmp folder into memory.

Now you can type:

or restart the system. Enjoy the difference.

And here how it is done under Mac OS X (you can visit one article here – http://laclefyoshi.blogspot.de/2011/05/tmpfs-on-linux-and-mac.html):

this will give you something like /dev/rdisk2 – then use “2” in the following command instead of “X”:

This is something you should do every time you restart the system.

~Enjoy

When unlock icon does not work on MacOS X


I had encounter several times that when using MaxOS X Lion, when I try to unlock system preferences (usually for setting user access, privacy settings, etc) – the unlock icon does not respond – does nothing.

Well – google-ing all over – I found my solution. Just open terminal and type the following 2 commands:

Enjoy~