• The Pragmatic Programmer

    For the last couple of weeks I’ve been slowly reading a book I recently got - “The Pragmatic Programmer, The: From Journeyman to Master” (Authors’ website).

    Get it on Amazon

    Andrew Hunt and David Thomas cover a lot of topics in this book, such as DRY principle (Do not Repeat Yourself), orthogonality, project management and many more. Challenges and exercises at the end of pretty much every single topic gets you thinking about your present code.

    Software Entropy

    This particular topic was a bit shocking. Software entropy is basically disorder in software, bad code, “rotten software” as they refer to it. As an example they talked about a research in why some buildings get damaged “beyond the owner’s desire to fix it”, while others stay pristine and clean. **“A broken window.” **“One broken window, left unrepaired for any substantial length of time, instills in theinhabitants of the building a sense of abandonment—a sense that the powers that be don’tcare about the building. So another window gets broken. People start littering. Graffitiappears. Serious structural damage begins.”

    When you think about it, they have a really good point. I can tell from my personal experience, that if you leave “broken windows” in software - bad design, poor code, more will appear in near future if they are not repaired.

    Programming by coincidence

    Many programmers have this problem, I sometimes find myself doing just that - programming by coincidence. Authors emphasize that you must know or must find out **WHY **it works in the first place, because when problems occur (and they will), you will not be able to deal with them. Not only that, but in my opinion it will make it harder for others to work with your code.

    Other topics

    Other topics include using Version Control Systems, importance of orthogonality and decoupling, plain text, code generators, project management, testing (important one!), code refactoring, automation, knowing your tools (!!!).

    Anything wrong?

    Only one thing that bothered me just a bit was that examples were only given in Java or C/C++ languages. But at the same time I understand that the example code is not that important, the point was to get the reader into a right mindset, pass a correct message. One way or another the code was not that hard to understand, since pretty much every single programming language is similar in some ways. So it’s not really a bad thing in my opinion.


    This book is by far one of the best books I’ve read on programming. In fact I found some similarities (in described practices) to an e-book “The best of edw519“ by a Hacker news Top contributor Ed Weissman. This should definitely be on every programmer’s to-read list. “The Pragmatic Programmer” really changed my mindset.

    “The Pragmatic Programmer” on The Pragmatic Bookshelf

    “The Pragmatic Programmer” on Amazon

    EDIT: If you want to find out more about the content, “The Pragmatic Programmer Quick Reference Guide” on Jeff Atwood’s website.

  • Launching "No Time To Explain" beta

    For the last couple of weeks I’ve been working with Alex and Tom from TinyBuildGames.com and helped them to launch private beta of a game they’re creating “No Time To Explain”. That was really lots of fun!

    The first challenge was to set up a forum for the community. Since it would be far too much work to write one, after some research we ended up with three candidates - phpBB, MyBB and SMF. We went with phpBB, since it has a big community support forum, lots and lots of (free) extensions and themes and it seems to be the oldest, thus (hopefully) the most secure.

    The game has social kick to it. You can build levels and share them easily through a level builder, which is built into the game. The best games are picked by the users through voting. Obviously that requires some sort of server to manage the data, so that was one of the challenges. Although we went with phpBB forum system, it still required some changes. And then I was surprised by phpBB. Even a simple password generator seemed to be quite elaborate. It wasn’t the old phpBB that was known to be riddled with bullet holes. I liked that.

    PhpBB was tightly coupled together, you can’t use certain things without using others, so you need to load the whole system. If you choose to do just that, tapping into phpBB itself was relatively easy, just with a few lines of code you can get access to pretty much all of the forum code:

    define('IN_PHPBB', true);
    $phpbb_root_path = 'path'; // Path to the forum from the script
    $phpEx = substr(strrchr(__FILE__, '.'), 1); // Extension, in case you use something different
    include($phpbb_root_path . 'common.' . $phpEx); // Main phpBB file

    To notify only certain people we didn’t want to mail each one by hand. And because each email is personalized and contains certain information, to minimize mistakes a program that does just that was a good idea. Some PHP sendmail handled that nicely.

    After the emails were sent it was just a waiting game. Personally I was curious to see how people will react. Very shortly feedback started coming in. I was surprised how eager people were to participate in NTTE’s development.

    And I must say that the levels the community created were really interesting and some very, even insanely difficult! In fact tinyBuildGames guys wrote about it here.

    It was really fun to work with Alex and Tom and help them. Thank you guys for the opportunity to participate and I wish best luck to you!

    I really recommend you to check them out. No Time To Explain!

  • My first Android Java application - AcceleroDroid

    It’s been almost a year since I got my first Android device (also it was the first Android powered phone ever released) - the HTC Dream (G1). I always wanted to write apps for Android, but never got to it, until today.

    Setting up and Hello world

    This part is easy and well documented. There are only a few things you need to do:

    1. Download the Android SDK and install it

    2. Download Eclipse

    3. Download and install Android development plugin for Eclipse

    4. Configure Eclipse to use Android SDK

    5. Update Android SDK configuration (download APIs and documentation)

    There’s an official guide to help you do this.

    It’s easy to create “Hello world” application, since every single new Android project does just that.

    Designing the UI

    It’s easy to do that too, because you need know next to none of programming. UI design is done in GUI, you just need to place items to their respective places. If you want to be uber hacker - you can always do this in pure XML or Java.

    The UI of main activity is stored in /res/layouts/main.xml and is written in XML.

    Functionality and the accelerometer

    I’m not a Java programmer (yet) and know only the basics of Java, thus I had to do some extensive googling on how to get the accelerometer to work, because either the code didn’t work, either it was too complicated. Eventually I found some sample code on developer.android.com in reference, customized it a bit and used it. I’ll add the code below.

    I was very surprised how sensitive the accelerometer was. It was able to measure down to 10^-6 (it might be even more precise). But I don’t need numbers that precise, so I rounded them to 10^-2.

    Another thing that I found interesting was that the values were constantly changing. Not by much (only by ±0.1 m/s^2). Even though the phone was placed on the table and nothing seemed to be moving. Could it be because of my PC near it?

    package com.tautvidas.accelerodroid;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.hardware.Sensor;
    import android.hardware.SensorManager;
    import android.hardware.SensorEvent;
    import android.hardware.SensorEventListener;
    import android.widget.EditText;
    import java.math.*;
    public class AcceleroDroid extends Activity implements SensorEventListener {
    private SensorManager mSensorManager;
    private Sensor mAccelerometer;
    protected EditText EditTextAxisX, EditTextAxisY, EditTextAxisZ;
    /*public AcceleroDroid() {
    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
    Log.d("DEBUGTAG", "Creating default view");
    EditTextAxisX = (EditText) findViewById(R.id.editTextXaxis);
    EditTextAxisY = (EditText) findViewById(R.id.editTextYaxis);
    EditTextAxisZ = (EditText) findViewById(R.id.editTextZaxis);
    mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    protected void onResume() {
    mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    Log.d("DEBUGTAG", "Started listening to the accelerometer");
    protected void onPause() {
    Log.d("DEBUGTAG", "Stopped listening to the accelerometer");
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    public void onSensorChanged(SensorEvent event) {
    EditTextAxisX.setText("" + Math.round(event.values[0] * 100.0) / 100.0);
    EditTextAxisY.setText("" + Math.round(event.values[1] * 100.0) / 100.0);
    EditTextAxisZ.setText("" + Math.round(event.values[2] * 100.0) / 100.0);


    This part was real fun. Using DDMS not only Eclipse got access to the app in a local Android Emulator, but also it was able to read Logcat logs from my phone, so any thrown exceptions or logs my app wrote appeared in Eclipse. I find it very cool.

    How the app interprets data from the accelerometer

    Well, take a look at the image on the right. I included the same image in the app itself.

    Currently there is no way of downloading this, sorry

  • Break helper 1.2 released

    I just released a new version of my Google Chrome extension Break Helper (it can be found here).


    I added two new features: one more time management rule - Pomodoro technique. Basically it lets you split your work in blocks. Work for 25 minutes and rest for 5 minutes. I think it’s the sweet spot, because from my own experience I know, that 20-20-20 rule’s break time (just 20 seconds) is too short for a proper rest and 50-10 rule’s break time (10 minutes) is just too much at a time. I often find myself not waiting until the end of the break and get back to work.

    Another feature I added is (optional) audio notifications. They are played when your break ends to let you know that it really ended. I think it’s quite useful, if you rest away from your workplace, stare away through the window or do something else. At first I tried to play sounds using HTML embed tag, but in Chrome’s notification it flickered a bit and I wasn’t able to fix that with CSS (even with hiding it). Then I switched it to** HTML5 audio** tag, which worked nicely.

    As for Javascript, I rewrote some functionality. Cleaned up some code, removed duplicated code and made it more reusable, improved my storage structure (now I store only 2 objects with multiple parameters, everything encoded in JSON, and before I had everything as a separate local storage array element). Reuse as much code as possible, because modifying something, that is used in a number of different places is very… painful.

    Problems and to do

    One issue that still persists is the design. I am not happy with it and I don’t think users like it, that’s why I plan to redesign it. The problem is I’m not good with design work, but oh well, it’s time for improvements.


    Now Break helper has 40 users, 14 weekly installs, 3 **ratings and is rated at **4 stars. I think it’s pretty good, since I’ve done nearly no promotion of it, just created a thread on one forum, which resulted in some users.

    I still have some plans how to improve the extension, like redesigning it. After that I’ll try to do some promotion. A month ago I saw a post on Lifehacker that featured a very similar website. I think I remember using it 20-20-20 rule. Any chances they saw my extension? And if the extension catches on, I hope to expand to other browsers (Opera, Firefox), maybe mobile niche (iOS, Android).

    If you have any suggestions or comments, please don’t hesitate to leave them below or contact me.

    Break helper on Chrome Web store

  • Disable Nvidia Optimus enabled graphics card

    New CPUs with Sandy bridge technology have integrated graphics processing units (APUs), which enables manufacturers to add another graphics card which is much more powerful and let the user switch between 2 graphics cards. One for battery preservation or both if you favor power.

    In Windows 7 environment Nvidia Optimus GPU switching works nicely - switch to Power saving mode to shut down the GPU, switch to High performance to enable both GPUs. However, I recently installed Ubuntu 10.10 and was disappointed to find out that Nvidia Optimus does not work on Linux and they don’t have any plans to support it on Linux (Nvidia officials actually wrote that on their support forums). Not only you can’t switch it or use it at all (yet), but there’s no easy way to disable it, so it consumes precious battery power even if you’re not using it. Well, you might be lucky, because some laptops may have a BIOS switch, but if you’re like me and not so lucky - BIOS won’t help here.

    And here comes the community to the rescue. Linux Hybrid Graphics is developed by the community, they are rapidly developing software for hybrid graphics cards support on Linux. At the moment of writing this post only a program to disable the NVIDIA graphics card is available. You can find the code here: http://github.com/mkottman/acpi_call

    You can install the program with these commands: git clone http://github.com/mkottman/acpi_call.git cd acpi_call make sudo insmod acpi_call.ko ./test_off.sh

    I tried it myself, it worked as a charm. My battery life increased more than twice!

    I hope it helps.