Author Archives: janos

Using custom fonts on Android

The default fonts you can choose from when developing for Android are not very interesting. Normally they are OK for my simple purposes, but for once I wanted something a little bit prettier for my new app, Happy Moments.

I found this tutorial very useful for using custom fonts on Android:

http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/

And I found some pretty nice fonts on this site suitable for the concept of my app:

http://www.fontsquirrel.com/fonts/list/category/Handwritten

Here’s the gist:

Step 1: Find a nice font and put it in your assets/ folder

Step 2: Set the custom font in code (which is the only way to do it), like this:

TextView message = (TextView) findViewById(R.id.message); 
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
message.setTypeface(font);

And voila, the result in the app itself:

Fixing system date out of sync in Debian

I started using my old-ish Debian server again and realized the system date is off by 20 minutes…

The solution is to install ntpdate, which automatically synchronizes the clock at certain system events, for example when the network interface comes up.

To force synchronizing now, you can run ntpdate manually, but you must specify the NTP servers to use as reference on the command line, otherwise it will give you an error like this:

14 May 06:53:06 ntpdate[6505]: no servers can be used, exiting

An easier way is to run ntpdate-debian without arguments, which will use the NTP servers configured in /etc/default/ntpdate, which is a Debian-specific setup.

Viewing old revisions in the web browser interface of Subversion

If Apache is configured to browse a Subversion repository, its files and directories are shown as of the latest version by default, for example:

http://svn.apache.org/repos/asf/subversion/trunk/

If you want to browse the content of older revisions, there is a non-trivial way by inserting /!svn/bc/REVNO between the base URL of the repository and the path component of the target directory inside the repository, for example you can browse the contents as of revision 1234123 like this:

http://svn.apache.org/repos/asf/!svn/bc/1234123/subversion/trunk/

Practical tips & tricks in the Linux shell

I put together this simple presentation about a few simple but very effective practical tips that should make you lightning fast on the command line. I use these literally every minute I spend in the shell. All the tips should work in Linux, UNIX, BSD and similar.

  • I used many tips from Zach Holman’s blog to “design” the slides.
  • I created the presentation using Google Docs, but it was not really a great experience:
    • The dotted green line you see under headings is not intentional, it appears only after exporting to PDF. I don’t know why. I would prefer it without the line as shown correctly in Google’s viewer, but I want to use Speaker Deck as it is not blocked at my workplace and has a better WordPress plugin.
    • The JavaScript seems to go crazy in the presentation editor. The longer I use it, the heavier it gets, until I do a clean fresh reload.
  • I used the Speaker Deck Embed plugin to embed the presentation here. Oh and Speaker Deck is really awesome.

Hacking contest on a Live CD

A Linux Live CD that should be interesting, educational, and highly entertaining for any self-respecting programmer: a security challenge with 6 levels based on the online contest created by Stripe in early 2012.

The CD contains a very light Linux system (based on Tiny Core), the ISO image is less than 30 megabytes. You can download it from here:
https://sourceforge.net/projects/ctfomatic/files/

The easiest way to use the Live CD is with a software like VirtualBox: create a virtual machine with no hard disk and 256MB memory and point the CD device to the ISO file and that’s it, start the VM! The Live CD uses US qwerty keyboard by default, you can change that by passing a boot parameter at the boot prompt, for example:

boot: kmap=azerty/fr

Alternatively you can use the shortcuts frjp or hu for French, Japanese or Hungarian keymap, respectively.

When the system starts you are logged in as user level00. You will be presented with a hint that should help you gain access to the password of user level01. Your mission, should you choose to accept it, is to find and exploit the vulnerabilities presented at each increasingly difficult level, advancing forward until you reach level06 (and celebrate!)

By completing this challenge you will become a better programmer:

  • You will increase your awareness of the importance of security, and probably write more secure, more robust code in the future.
  • You will improve your skill of finding problems and weaknesses, which is the critical first step in optimization tasks.
  • You will have a wonderful time, and come out enlightened!

The source code of the scripts used to build this CD is available on GitHub:
https://github.com/janosgyerik/ctf-o-matic

Have fun!

Gource is a cool VCS visualization tool

Gource is a really cool open-source software to visualize the revision history of your projects, whether you’re using Git, Bazaar, Mercurial or Subversion.

https://code.google.com/p/gource/

The project website has many cool example screenshots generated from the repositories of famous projects such as the Linux kernel or Git.

Here’s what some of my projects look like in gource:

1. Revision history of Bash One-Liners:

2. Revision history of the RecipeNotes App:

To generate these videos I used the following commands on Mac OS X:

gource --file-idle-time 0 --seconds-per-day .3 -640x480 -o gource.ppm
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gource.ppm -vcodec libvpx -b 10000K gource.webm

Cloning a remote Subversion repository using Git through a proxy server

To clone a remote Subversion repository using Git through a proxy server, edit the ~/.subversion/servers file appropriately:

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
# http-proxy-host = defaultproxy.whatever.com
# http-proxy-port = 7000
# http-proxy-username = defaultusername
# http-proxy-password = defaultpassword

Note that even in Windows, the correct path is actually ~/.subversion/servers when using git-svn, even though this is NOT the normal configuration directory for the native svn.exe. For example in Windows 7 svn.exe typically uses the path C:\Users\YOURUSER\AppData\Roaming\Subversion.

This was quite confusing to me at first, because after I got svn checkout working well by editing C:\Users\YOURUSER\AppData\Roaming\Subversion\servers I was surprised to find that git clone svn still had the proxy issue.

In case you were wondering, the http_proxy and https_proxy environment variables are ignored by both Git and Subversion.

Computer and IT Quiz

Recently I started contributing to this fun Computer and IT Quiz app on Android:

Android app on Google Play

Mike Heyworth created the original app, I contributed mocks and elements for the new design, which Mike incorporated in the latest version of the app released just a few days ago. If you are in IT, do try it out, challenge yourself, test your skills, and just have fun with it!

If you like this FREE app please do buy the PRO version and support us!

More usability and design improvements will be coming soon (1-2 months), so stay tuned!

 

Setting default device in R in Mac OS X

On Mac OS X, for some reason the default device for displaying plots is Quartz. This can be inconvenient, since for example the savePlot function works only with X11 devices with Cairo support.

To change the default device, I created ~/.Rprofile like this:

setHook(packageEvent("grDevices", "onLoad"),
    function(...) grDevices::X11.options(type='cairo'))
options(device='x11')

The setHook creates a hook so that when the grDevices module is loaded, it sets the default type of X11 devices to cairo.

The second line sets the default device to X11.

Both of these lines are necessary, otherwise the default device would either not be X11, or it would not be the correct X11 type.

Subversion does not remember or update my password

I had this strange issue the other day. My account password has recently changed, and for each Subversion repository linked to that account I had to re-enter my password. Normally it is enough to re-enter once per repository: Subversion updates the corresponding authentication setting file so that I don’t need to enter it again. But for some repositories it kept asking for it…

After some digging around, I realized that my user did not have write access to the file that sores the password. That is easy to fix once you know what to look for, and if you know which file it is. However that can be tricky if like me you don’t know how Subversion organizes its settings files…

In Windows 7 (using the Git shell) you can find your Subversion setting files that you don’t have write access to like this:

find /c/Users/YOURUSER/AppData/Roaming/Subversion ! -perm -200 -type f

This can be useful to confirm your suspicion about filesystem permission issues. If you don’t care about all that, you can just add write permission to yourself on all files indiscriminately with:

chmod -R u+w /c/Users/YOURUSER/AppData/Roaming/Subversion

How did it happen that my write permission has disappeared on some of the files? I haven’t the foggiest idea…