Archive

Archive for November, 2009

Android: Get String From Resource By Name

November 29th, 2009 niels No comments

Usually the string resources in your Android application are being referred to by a unique ID. But sometimes you will want to recover a string by its key, e. g. when you build the key of the string at the run time of your application (“Battery_Health_2″ or “Battery_Health_3″). You can do that like this:

private String getStringResourceByName(String aString)
{
  String packageName = "com.coliena.myapp";
  int resId = getResources().getIdentifier(aString, "string", packageName);
  return getString(resId);
}

Check this link if you need to recover in image resource by its name.
More information about string resources is available in the Android Developer Documentation.

Tags: ,

Using WinMerge with git on Windows 7

November 28th, 2009 niels No comments

Though git is not my primary source code management tool, I use it whenever I work on complex code that I don’t want to commit yet. Or just to keep track of my local scripts.
And using “git difftool”, it is pretty simple to use third party tools like WinMerge for graphical diffs:

  1. Create a wrapper script (e.g. git-diff-wrapper.sh) and put it anywhere in your Windows path (%PATH%):
    #!/bin/sh
    "C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$1" "$2" | cat
  2. Update your .gitconfig to run this script whenever “git difftool” is invoked:
    # … more config …
    [diff]
    tool = winmerge
    [difftool "winmerge"]
    cmd = git-diff-wrapper.sh "$LOCAL" "$REMOTE"
    # … more config …

That’s it, no restart required ;)

Tags: ,

How To Restore A SQL Server Database via SQLCMD

November 11th, 2009 niels No comments

Run this with SQLCMD to restore a SQL Server database:

RESTORE DATABASE MyDatabase
FROM DISK = 'd:\backup\MyDatabase.bak'

It’s that simple.
Thanks to Michael Otey @ SQL Server Magazine.

Tags: