Are You The Best Developer In The World?

HumbleThere is a lot to be said for being humble. As individuals we tend to admire those who are humble, the self-effacing celebrity, the quiet monk, these are the kinds of people we look up to. We are all taught as kids that being humble is a good thing and we must all aspire to it. As a society, however we don’t really reward humbleness. Recognition doesn’t come to those who quietly work hard, recognition comes to those who apply for it and can then prove their greatness. The software development world is no different, we aspire to work with stars (it’s human nature), we want to associate with those we consider great. Nobody wants to work with quiet Joe Programmer, possibly because noone knows how awesome young Joe really is. Yes, it’s a bit of a dilemma.

So should you, as a developer, maintain a humble attitude or is self promotion the way to go? Let me ask you a question. Have you ever thought that you were the best developer in the world? Perhaps after pulling an all-nighter to finish working on your latest, greatest idea, or maybe after solving that weird bug that the whole team has been trying to figure out for the last three days. You know the feeling you get, that quiet satisfaction, that inner glow after you realize that you may have just found it, and while basking in that glow you might just entertain a though:

“Man, I have some 1337 (that’s ‘elite’ for those who don’t know) skillzzz!”,

but of course as soon as you think that you realize how completely ludicrous that sounds. And then, to compensate, you shrug off the praises of your co-workers and feel a little embarrassed to be getting so much attention,

“It was a team effort”,

you say, I am just your average Joe Programmer; no big deal.

While humbleness is admirable, I am a big believer in balance in all things. I am perhaps not the humblest person in the world (yeah, I can hear those who know me laughing out loud :)), but I try to be aware of that part of my nature and keep it in check, but at the same time I am careful not to let it go too far the other way. I am well aware that I am not the greatest developer in the world. I’ve known and worked with plenty of people who were better, but that doesn’t mean that I don’t value the skills that I do have. And that’s the crux of it, no matter what societal pressures or your own nature might tell you, there is nothing wrong with having a healthy sense of self-worth.

You need to walk the middle ground. There is no doubt that any non-trivial software project these days will be a team effort and there is nothing wrong with giving credit to the whole team for the successes that the project might have. But, at the same time, you need to remember that you and every other individual are part of that team. If you, or someone else, does something great then there is nothing wrong with acknowledging it. Learn to give and take praise graciously, it is a very useful skill to have. Don’t devalue your own work, when others acknowledge it, by discounting the efforts you put into it. Being humble is easy, it comes naturally to most of us, and being a self-promoter works (after all, if you put yourself out there enough, someone is bound to trip over you at the very least :)). But, there is no need to jump to either extreme, find a healthy balance, you will be mentally and emotionally better off for it.

Don’t get me wrong though, you still need to keep your feet planted firmly on the ground. Remember that Socrates quote – “_I know nothing except the fact of my ignorance_” – well, that doesn’t mean that you actually know nothing (and it is also not nonsense, regardless of whether you have an IQ of 268 or not). What it does mean, is that no matter how much you know, you need to always be aware that there is a lot more to learn, and that’s one of the things that will keep you grounded (firmly in the middle). Acknowledge your successes and always keep learning and improving yourself, and next time you ask yourself:

“Do I absolutely rock at this software development gig or what?”,

examine all the facts and make an honest assessment, rather than dismissing the question as arrogant, or giving yourself a pat on the back for no reason.

Image by echiner1

Different Types Of Encoding Schemes – A Primer

As a software developer and especially as a web developer you likely see/use different types of encoding every day. I know I come across all sorts of different encodings all the time. However since encoding is never really a central concept, it is often glossed over and it can sometimes be confusing which encoding is which and when each one is relevant. Well, to put the confusion to bed once and for all, here is a quick primer on the different types of encoding schemes you’re likely to come across and when each one is relevant.

HTML Encoding

Html encoding is mainly used to represent various characters so that they can be safely used within an HTML document (as the name might suggest). As you know there are various characters that are part of the HTML markup itself (such as <, > etc.). To use these within the document as content you need to HTML encode them. There are two ways to HTML encode characters.

  1. HTML encoding defines several entities to represent characters that can be part of the markup e.g.:

    ” - "
    ‘ - '
    > - >
    < - <
    & - &

  2. You can also HTML encode any character using its ASCII code by prefixing it with &# and then using the ASCII decimal value, or prefixing it with &#x and using the ASCII hex value e.g.:

    ’ - '
    < - <
    > - >
    ‘ - "

So, any time you need to encode characters within an html document itself, those are the ways to do it. This one is sometimes confused with URL encoding which is somewhat different.

URL Encoding

When dealing with URLs, they can only contain printable ASCII characters (these are characters with ASCII codes between decimal 32 and 126, i.e. hex 0x20 – 0x7E). However, some characters within this range may have special meanings within the URL or within the HTTP protocol. URL encoding comes into play when we have either some characters with special meaning in the URL or want to have characters outside the printable range. To URL encode a character we simply prefix its hex value with a % e.g.:

% - %25
space - %20
tab - %09
= - %3D

Note that as part of the URL encoding scheme you can also represent a space using +. This is often confused with Unicode encoding due to the fact that both begin with %, however Unicode encoding is a little bit more involved.

Unicode Encoding

Unicode encoding can be used to encode a character from any language or writing system in the world. Unicode encoding encompasses several encoding schemes.

  1. 16 bit Unicode encoding is somewhat similar to URL encoding (which is why they can sometimes be confused). To encode a character in 16 bit Unicode, you start with %u and then append the code point, of the Unicode character that you want to encode. A code point is basically just a 4 digit hexadecimal number that maps to a particular character that you’re trying to represent according to the Unicode standard (as you can imagine there are a LOT of these, have a look) e.g.:

    @ - %u0040
    ∞ (infinity)- %u221E

  2. UTF-8 is another type of Unicode encoding that uses one or more bytes to represent each character. When we need to UTF-8 encode characters for transmission over HTTP, we simply prefix each byte of the UTF-8 representation with a %. You can look up the UTF-8 representations for various characters by following the same link as above.

    ± (plus minus) - %c2%b1
    © (copyright) - %c2%a9

As you can imagine there is much, much more that could be said about Unicode, but this is only a quick primer so I’ll leave it up to you to discover more for yourself.

Base64 Encoding

This one is fun and always useful to know about. Base64 is used to represent binary data using only printable characters. Usually it is used in basic HTTP authentication to encode user credentials, it is also used to encode e-mail attachments for transmission over SMPT. In addition Base64 encoding is sometimes used to transmit binary data inside cookies and other parameters, as well as often simply being used to make various data unreadable (or less easily readable) to prevent easy tampering.

Base64 looks at data in blocks of 3 bytes which is 24 bits. These 24 bits are then divided into 4 chunks of 6 bits each, and each of those chucks is then converted to its corresponding base64 value. Since it deals with 6 bit chunks there are 64 possible characters each chunk can map to (hence the name). If the end of the string that is being encoded contains less than 3 characters (which means we can make 4 base64 characters), then we make as many base64 characters as we can and pad the rest with = characters. You can have a look at the base 64 alphabet here as well as many other places. Lets have a look at a quick example.

If we want to convert the word ‘cake’ to base 64, we simply convert each of the characters to it’s ASCII decimal value and then get the binary value of each decimal value. In our case:

cake =  01100011011000010110101101100101

We now need to break up our binary string into chucks of 6 bits each, and since every 3 characters must make 4 base64 characters, we can pad with 0’s if we don’t have enough:

011000 110110 000101 101011 011001 010000 000000 000000

We now convert each one of the 6 bit binary values into it’s corresponding character, and in the case of an all zero value we use the padding character (=). In our case we get:

Y2FrZQ==

Which is the base64 encoded value of the word ‘cake’.

Base64 encoding is usually pretty easy to spot as it looks fairly distinctive especially when it contains padding characters (=) on the end of the string.

Hex Encoding

This one is easy, sort-of :). Basically with hex encoding, we simply use the hex value of every character to represent a collection of characters. So if we wanted to represent the word ‘hello’ it would be:

68656C6C6F

Pretty straight forward right? Well, it is only simple when we’re encoding printable ASCII characters (I mentioned those above). As soon as we need to encode international characters of some sort, it becomes more complicated as we have to go back to Unicode. I wouldn’t worry too much about this one, you’re a lot less likely to encounter it in your day-to-day web development and you now know what it might be if you see a bunch hex numbers stuck together.

Hopefully this was helpful and you can refer to this – as a starting point – any time you have some encoding issues; to sort out any confusion. If you think there are other encoding schemes (relevant to our day to day lives as software developers) I should have mentioned, feel free to let me know in the comments.

Installing And Using SQLite With Ruby On Windows

SQLite is a great little embeddable database engine that’s meant to be self-contained, easy to use and not require configuration. However when I tried to use it in my Ruby code I found that it wasn’t that straight forward getting everything to work, especially if you’re using Ruby on windows. The information on the old WWW was rather sparse. I worked it out eventually, so in the interests of being a helpful web denizen I thought I’d share.

What To Download And Where To Put It

First thing first, before we involve Ruby directly lets download set up everything we need. You need to download two things from the SQLite website (well strictly speaking you only actually NEED one, but we’ll download both since the other one is useful):

  • sqlitedll-3_6_16.zip – you can think of this one as actually being the SQLite database that you will install on your machine
  • sqlite-3_6_16.zip – this one is a command line utility that can be used to administer a SQLite database

Both of those files are located on the downloads page – http://www.sqlite.org/download.html, under the ‘Precompiled Binaries For Windows’ section.

Once you unzip both of those you will have several files, the important ones are:

  • sqlite3.dll – this is the actual database
  • sqlite3.exe – this is the command line utility

You need to take the DLL and put it somewhere, where Ruby would look for libraries when you execute a script, some possible locations would be, your windows system folder or the bin folder of your Ruby installation (Note: as reader Luis Lavena noted in the comments below, the ruby installation bin folder is by far the best place to put the DLL). On my machine it was:

1
2
3
C:\ruby1.8\bin
C:\WINDOWS\system
C:\WINDOWS\system32

You can also put the command line utility in any of those places as well, but you don’t have to as you can use that one from anywhere (if you do put it in another location make sure that location is in the PATH environment variable otherwise you will have to specify the full path to it every time you want to use it).

You’re now ready to install the SQLite Ruby interface gem. You will need to do the following:

1
gem install sqlite3-ruby

After it completes you will have a gem similar to the following in your gem repository, in my case:

1
C:\ruby1.8\lib\ruby\gems\1.8\gems\sqlite3-ruby-1.2.5-x86-mswin32

You’re now ready to work with SQLite in your Ruby application. Note that you need to install the ‘_sqlite3-ruby_’ gem and not the ‘_sqlite-ruby_’ one, as that is the old one.

If you did not install the DLL correctly you might get an error similar to the following when you try to run your ruby script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
C:/ruby1.8/lib/ruby/1.8/dl/import.rb:29:in `initialize': unknown error (RuntimeError)
        from C:/ruby1.8/lib/ruby/1.8/dl/import.rb:29:in `dlopen'
        from C:/ruby1.8/lib/ruby/1.8/dl/import.rb:29:in `dlload'
        from C:/ruby1.8/lib/ruby/1.8/dl/import.rb:27:in `each'
        from C:/ruby1.8/lib/ruby/1.8/dl/import.rb:27:in `dlload'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/api.rb:31
        from C:/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from C:/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/driver/dl/driver.rb:1
        from C:/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from C:/ruby1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb:619:in `load_driver'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb:617:in `each'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb:617:in `load_driver'
        from C:/ruby1.8/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5-x86-mswin32/lib/sqlite3/database.rb:72:in `initialize'
        from D:/ruby-projects/search-engine/search-engine/lib/search-engine-main.rb:21:in `new'
        from D:/ruby-projects/search-engine/search-engine/lib/search-engine-main.rb:21

This is because the SQLite ruby interface is trying to use a deprecated driver (it’s called DL and it is buggy and doesn’t work) because it can’t find the native one, you need to make sure you put the DLL in the appropriate spot mentioned above. Also note that putting the DLL in the same directory as the script you’re executing does not work and produces a different error possibly because it has a dependency on MSVCRT.DLL.

How To Use SQLite With Ruby

We can now write some ruby code to test that everything is working, as well as learn to use SQLite a little bit.

```ruby require ‘sqlite3’ database = SQLite3::Database.new( “new.database” )

database.execute( “create table sample_table (id INTEGER PRIMARY KEY, sample_text TEXT, sample_number NUMERIC);” )

database.execute( “insert into sample_table (sample_text,sample_number) values (‘Sample Text1’, 123)“) database.execute( “insert into sample_table (sample_text,sample_number) values (‘Sample Text2’, 456)“)

rows = database.execute( “select * from sample_table” )

p rows```

Running this code will create a new file called ‘new.database’ in the same folder where you ran the script. This is the sqlite database you’ve just created (sqlite stores data as files). To execute any SQL code using sqlite, you simply call the ‘execute’ method on your database instance and provide it some SQL code as a string. This is what we did to create a table and to insert two rows into it. Our little script produces the following output:

1
[["1", "Sample Text1", "123.0"], ["2", "Sample Text2", "456.0"]]

Which shows that we can get the two rows that we inserted back from the database.

If you attempt to re-run this script, it will simply pick up the database file since the file persists past the execution of the script. Incidentally the script would fail a second time since the table ‘sample_table’ already exists in the database.

You now have the basics down, from here the going is a little easier. You can look at the following resources:

SQLite/Ruby FAQ – all the different ways to use sqlite from a Ruby script

SQLite Documentation – self explanatory

Supported SQL Syntax – self explanatory

SQLite Datatypes – how datatypes work in SQLite 3

Enjoy!