How to set up a fast emulator for Android on Linux?
This article describes how to setup a new emulator which allows to install apps which use Google Play Services.
Recently, Android 4.3 (API level 18) has been published. As former releases it contains system images for ARM and Intel Atom (x86). When creating an emulator via the Android Virtual Device Manager one can choose to target either the “plain” API level or include Google APIs. The “plain” configuration can benefit from both hardware acceleration options (ARM and Intel Atom). Running such a virtual device is quite comfortable as it behaves similar to a hardware device. The Google API targets however do not allow to use Intel Atom architecture.
Android button states understood
After a lot of research, trial and error I finally understood how I can specify four different button states via XML. The important detail is that you need to add both state parameters in every item. In the following example those are android:state_checked
and android:state_pressed
which can be combined to four different states.
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- finger is on while button is up --> <item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/ic_btn_medium_grey"/> <!-- finger is gone, button is up, default --> <item android:state_checked="false" android:state_pressed="false" android:drawable="@drawable/ic_btn_light_grey"/> <!-- finger is gone, button is down --> <item android:state_checked="true" android:state_pressed="false" android:drawable="@drawable/ic_btn_dark_grey"/> <!-- finger is on while button is down --> <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/ic_btn_deep_dark_grey"/> </selector>
If you are unsure why you want to have four states for a single button just imagine the button can stay in its checked state.
Git: How to copy a range of commits from one branch to another?
Sometimes it is useful to copy a series of commit to another branch. This post describes how to do this using git rebase
. Two example illustrate different scenarios which should help to understand the command arguments in generell.
Example 1: The commit P, Q, R which are contained in branch feature should be copied to branch master. The commits should be appended to commit M.
The first command git rebase --onto M O R
copies the commits P, Q, R to the branch master. They won’t be visible if you check the visual graph in gitk. This is because there is no branch reference that points to one of the three commits. To update the branch master run the second command git rebase HEAD master
which moves up the HEAD to commit R.
How to fix Eclipse colors for autocompletion and tooltips
Sadly Eclipse ships with a broken color theme when it comes to autocompletion and tooltips. I cannot tell if the problem is limited to Ubuntu Precise, however, it is worth getting fixed immediately. The following screenshots illustrate the broken color settings in both situations. The tooltip window shows up with a black background color and blue links.
When autocompletion popup appears the first suggestions is not readable at all.
So, here is what you need to do to fix the colors. Read the rest of this entry »
How to manually install TeX Live 2012
Some days ago, at July 8, TeX Live 2012 has been released. In the meantime, I also updated to Ubuntu 12.04. (Precise) but I did not find the time to install TeX Live. I am happy to report that there is nothing new to learn regarding the installation. You can straight follow the very same instructions I posted earlier for TeX Live 2011. Have fun.
Update: I noticed that TeX Live 2012 has been made available via apt-get. I recommend testing it out (I haven’t done so yet).
Search and replace across multiple directories
Today, I tried to find a convenient way to unify the spelling of a word used in various text files spread across multiple directories. Of course vim has a solution to this. In my case all files are of type *.txt. The term I want to search for is “re-use” which should be replaced by “reuse“. Here is what I did:
- Open vim while loading all relevant files recursively as a argument list the editor.
vim **/*.txt
- Start recording a macro in register “a”. Type
qa
- Enter the substitution command to search and replace a specific character pattern
:%s/re\-use/reuse/ge
- Change to the next file in the argument list. Type
:wnext
- Stop recording the macro in register “a”. Press
q
- Playback the macro 999-times by entering.
999@a
The posts “Vim 101: Search and Replace on Multiple Files” and “Vim. How to replace a word (string) in several files.” guided me. Please have a look there for further information.
Colored Diffs add-on for Thunderbird
Reading todays post-hook emails with the latest diffs of some project the thought rushed to my head that it would be nice to have the diffs displayed in color. Since I am using Thunderbird as my email client I found a great add-on named “Colored Diff”.
Although, the add-on seems to be outdated to work with the latest Thunderbird version (which is 10.0 right now) there is an easy way to install the add-on while the automatic installer refuses to do so. Here is what you can do to make the installation work.
- Download the colored diffs *.xpi file
- Open the archive with an archive manager of your choice
- Edit the contained install.rdf with a text editor of your choice
- Change the maxVersion parameter to be equal or greater then the current version of Thunderbird
Before:<em:maxVersion>3.1.*</em:maxVersion>
After:<em:maxVersion>13.1.*</em:maxVersion>
- Save the changes and store them back into the archive
- Install the add-on
Do not forget to check out the preferences after you installed the add-on. You can choose 4 different types to display the diffs and customize the colors as well.
If you feel interested to enhance the add-on you can do so. The “Colored diffs” project is hosted on Google Code open for people to participate.
Amend files to a git commit without changing the commit message
Quiet often there is the need to add files to the recent commit. This can be done with 2 simple commands.
git add file git commit --amend
In case you do not wand to change the commit message there is the new option --no-edit
for git commit introduced in git 1.7.9. The git release notes describe how the --no-edit
option can be used.
“
git commit --amend
” learned “--no-edit
” option to say that the
user is amending the tree being recorded, without updating the
commit log message.
git commit --amend --no-edit
Of course, I added an alias for the new option to my global git configuration.
ci = commit cm = commit -m ca = commit --amend cn = commit --amend --no-edit
Reset the author of a git commit
Once in a while one forgets to configure the user name and email address for git when initializing or cloning a new git repository. So do I. But git would not be git if it does not have an answer to that problem. Here is what git prints out when you commit without previously configuring the user credentials.
$ git cm 'Initial import.'; [master (root-commit) 0396c37] Initial import. Committer: User User@Machine.(none); Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name ''Your Name'' git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 file
Well done git!
Custom NSLog for Xcode 4
This post describes how you can to setup a custom NSLog snippet in Xcode 4. By default, this custom NSLog prints the class and method name of the position it is inserted.
Please follow these steps to add the code snippet to the scripts in Xcode 4.
- Copy and paste the following code into your editor. Anywhere.
NSLog(@"%@ %@", self.className, NSStringFromSelector(_cmd)); /* DEBUG LOG */
- Open up the code snippets library which sits in the utility pane on the right side. Look for the curly braces {}.
- Highlight the above mentioned code – click and hold the mouse over the text (for a short while) – drag them into the code snippet library.
- Afterwards you can edit the snippet and add a title, summary and a completion shortcut. I used the following settings:
Title: Custom NSLog (Class & method name) Summary: NSLog prints the class and method name Platform: All Language: Objective-C Completion Shortcut: NSLog Completion Scopes: All
You are welcome to comment and post your custom code snippets!
This article is inspired by the post “Easy Doxygen code snippets for Xcode 4” by Chris Powell.