Linux Author

August 24, 2009

Well if you didn’t know Linux is a open source operating system.  As a result updates and patches happen rather quickly (when compared to Windows and Mac at least).  But have you ever wondered just who updates Linux?  Well here is an article that should help clear things up and maybe even motivate you to even contribute.

Linux Kernel Development: Who Writes Linux (this is a pdf file).

Choosing the Right $PATH

August 23, 2009

Sorry for the long delay, but I have been busy with getting ready for school again and moving into my new apartment.

This is in some ways a continuation of my post Changing Modes.  As pointed out in one of the comments (thanks to Miorel) some people might wonder why you would have to type ./hello_world instead of just hello_world in order to execute the Perl script.  Well I though about this for a second and thought, “Well to run a script that isn’t one implemented by the OS you must place ./ before it.  This tells the OS that you are trying to execute a file.”  For example, if you want to run Firefox you just need to type firefox and not ./firefox.  If you are curious-and you should be-and enter ./firefox into the terminal you should get the following message, “bash: ./firefox: No such file or directory” (unless you for some reason have a file or directory called ./firefox, but why would you?).

Though that might answer might be good enough for some, I wanted to know why this was so, and if it was possible to change it so that you would only need to type hello_world (and not ./hello_world).  This is where $PATH comes into play.  I am going to try my best to explain this, and will also provide links to other sites for further reference.

To begin with here is a one line definition-which sadly isn’t mine, but gets the point across-of what the PATH variable is.

PATH is a list of directories where commands are looked for.

So when I type echo $PATH into the terminal I get the following:


Returning to our original example; if you were to type hello_world into the terminal. The OS would first look for a command (a file with the x bit set) with that name in /usr/local/sbin. If one is found it is run, if not it continues onto /usr/local/bin, and so on.

Now if we would like to only have to type hello_world, all we would have to do is add its directory to the PATH variable. Suppose that our script is in the directory /Mine. First I will show you the WRONG WAY to do this. Then two different correct ways (though I am not all that sure about which is better to use as of yet).

This is wrong because it will replace the original PATH variable with /Mine, and I am sure that you don’t want this.

Correct way #1: PATH=/Mine:$PATH
Correct way #2: PATH=$PATH:/Mine

As you can see, the first one will add /Mine to the beginning, and the seoncdd to the end of the PATH.

Here are two sites you can visit if you wish to learn more about the PATH variable. and

Pidgin Key Bindings

August 17, 2009

First, for those of you that don’t know what key bindings are.  Basically they are keyboard shortcuts.

Well Pidgin has one that I find rather annoying, it clears the scroll back history of a conversation.  The default key binding for this is <Control>l (the control and l key pressed together).  Now anyone that uses firefox and just about any other web browser knows that this allows you to edit the URL.  Naturally, I have Pidgin running I tend to also be using firefox.  So when I mistakenly think that firefox is the selected window and I want to change the URL I hit <Control>l.  Only to find that the Pidgin conversation window was selected.  This happened often enough for me to learn how to fix this.

The file that contains the key bindings for Pidgin are located at ~/.purple/accels.  All you have to do now is find the key binding that you want to change and change it to whatever you desire (or delete it if you so wish).  Time to introduce a new text editor (well new in the sense that I haven’t talked about it before on this blog), pico.  The format is just pico file, and the file’s contest will be displayed in the terminal. At this point you proceed as you would with any other text editor. Also there are additional commands at the bottom of the screen if you ever feel the urge to use them.

So let’s assume that you changed <Control>l to <Control>e, then saved the file.  Well this won’t work and here is why.  The line that you edited started with a ‘;‘ (semicolon), and GTK+ interprets this as a comment.  So your change has no effect.  Thus in addition to changing the key binding, you also need to remove the semicolon from the beginning of the line.

Facebook + Pidgin

August 16, 2009

Well I was having some issues with Pidgin earlier (still don’t think that they are all gone).  So I reinstalled it (with sudo apt-get install pidgin), since the main site only had the source (for Ubuntu) and I didn’t feel like building from source at the moment.

Well after installing I had to find the pidgin-facebook chat plugin.  This is provided through Google Code (just follow the link).  From here choose the .deb file to download.  Now installation is rather easy, just right click on the file and select “Open with GDebi Package Installer” and if all goes well you now should be able to connect to facebook-chat through Pidgin (after a restart).  If you don’t see this option then you need to get GDebi Package Installer, I don’t know how I got it so I won’t be much help but Google is your friend in this case.

When I tried this method I got a message about missing something called libjson-glib-1.0-0 .  So I went looking for it, only to find that Ubuntu doesn’t provide it for me.  In the end, I had to get this package through Debian (which I hear isn’t all that different from Ubuntu, under the hood at least, follow the previous link to the download page).  After installing this everything else was a breeze.

This really took longer than it should have, but oh well.  I tried other Pidgin like programs in the short time in between reinstalling, but didn’t find one that I thought measured up.

Change Mode

August 16, 2009

So you have written your first program in Perl and it probably looks something like this


# We will call the program hello_world
print “Hello world\n”

Now you try to run it with the command ./hello_world, only to find that it won’t run.  Well the reason is obvious, well to experienced users anyway.  The problem is that your program doesn’t have permission to be executed.  Instead you first need to run chmod u+x hello_world, then ./hello_world will run as expected.
The function of the chmod command is to change the mode of a files.  The modes are permissions and special modes.  I will only touch on permissions in this post.  The format for this command is as follows

chmod [references] [operator] [modes] file1...

references: who you want to apply the changes to
operator: how the changes are to be made
modes: which changes are to be made

The references are; u, o, g, and a u is the owner of the file.  g is users who are members of the file’s group.  o is outsider, members who are not specified by either u or g.  Finally a is all, this is equivalent to uog.

The operators are; +, , and =.  As can be expected you use + to add permissions and to remove them.  The = is a little harder to explain but is made perfectly clear with an example (which is later in this post).

The modes are; r, w, x.  They stand for read, write, and executable respectively.

Well now I suppose you would like to see some examples of this in use.  For all these examples we will assume that hello_world has the following initial modes: -rwxr-xr-x, this means that the owner (the first grouping of rwx) has the ability to read, write, and execute.  However, group members (the second grouping) and outsiders (the last grouping) can only read and execute

Example 1: Make it so that the owner only has executable permission.  After using the following command, the file’s modes will look like —xr-xr-x

chmod u=x hello_world

Example 2: Make is so that the owner can only read and execute.  After using the following command, the file’s modes will look like -r-xr-xr-x

chmod u-w hello_world

Example 3: Make it so that group users and outsiders  can read and write only. While not affecting the owner’s permissions.  After using the following command the file’s modes will look like -rwxrw-rw-

chmod og=rw hello_world

Example 4: Make it so that no one has execute ability.  The file’s modes will look like -rw-r–r– after using the following command.

chmod a-x hello_world

Example 5: Make is so that people that aren’t group members or the owner have write permission.  The file’s modes will look like -rwxr-xrwx after using the following command.

chmod o+w hello_world

So that wasn’t too bad, and hopefully you noticed how the = operator works.  Finally, it is worth mentioning that in order to see a file’s modes you only need to use ls -l file.  For more information on chmod check out this Wikipedia entry, and for examples follow this link.

See My Coffee: A C and Java tale

August 13, 2009

Anyone with half a brain can tell you that (pick one: C/C++ or Java) is vastly superior to (pick the other). The only problem is that I don’t know all that much about Java. So instead of doing the obvious thing and talking about how “C/C++ is better than Java”, I am going to talk about a few aspects of C++ that annoy the hell out of me.

Fist off why would you have a ‘long‘ data type if it is not required to be any bigger than a regular ‘int‘?  All that is specified is that both int and long must be at least 32bits. Thus if you want to get a 64bit integer you have to use ‘long long‘ (or __int64 if you are using Microsoft Visual C++).  This should really be addressed, and hopefully sometime soon. Though I suppose there are more pressing issues.

Second, I don’t know about you but no one ever told me why you it is poor C++ programming to include a class function’s definition inside the class.  It wasn’t until I was reading Thinking in C++ Vol.1 that it was made clear.  When you do this, the compiler will inline your function.  This means that everywhere you use it the compiler will reproduce the written code, instead of making a function call.  Sure, for small functions this is alright, but for larger ones it can add to code bloat, thus possibly resulting in a slower program.  The “standard” for determining if a function is small is, “does it take up more than one line of code?” If so then don’t inline.

Why are struct and classes the same?  The only difference is that the members of a class default to private, while those of a struct default to public.  Oh well, until they change this I will continue to use struct and then specify private/protected/friend when needed.

Finally, the STL is not quite as vast as the Java API.  But that can be attributed to what the languages were designed for, so I suppose I can live with this “fault”.

In the /dev/null Zone

August 13, 2009

If you have read the comment from my post On my first Script, it was suggested that I use nohup firefox >& /dev/null & to solve my infinite loop problem.  Well I read up on the parts of this command and it seems that it should work (I have yet to try it, but should get around to it this weekend).  So it’s time to break it down for those of you who have never seen anything like this before.

Firstly, nohup allows a program to continue to run in the background even if the user logs out (or the terminal is closed).  However, this can cause ‘hanging’.  From what I understand this happens when your program produces some kind of output (standard or error) and you try to close the terminal (or log out I suppose).  But you are unable to because the system is still “working”.  Say you have a program called count which counts to 1,000,000,000.  Needless to say this will take a while and you would want to do other things while waiting for it to finish.  So you run nohup count, but you forget that count prints the numbers to standard output (the screen). Thus when you try to close the terminal you are unable to do so (whoops).

This is where /dev/null comes to the rescue (well partially, but we will get to that later).  /dev/null is basically a file that you can write to but not read, and anything written to it is automatically discarded (aka deleted or destroyed). Thus you could enter nohup count > /dev/null, so now all your numbers will be written to /dev/null and not the screen.

Now this is where things get a little “complicated”, but bear with me.  There are 3 differnet standard I/O streams.  STDIN (used for input, usually the keyboard), STDOUT (standard output to the screen), and STDERR (standard error).  By default the streams are numberd 0, 1, 2 repectively.  So the command 2>&1 will redirect standard error to standard output.  How is this useful at all you ask. Well here’s how.  nohup count > /dev/null 2>&1. The first part as you already know will redirect our output to /dev/null, but the second part makes sure that if there is any standard error that it will be redirected to standard output which is being directed to /dev/null (also knowns as the black hole).  Thus, we can finally let count run and be able to close the terminal with no worries.

I know this might have been a little lengthy, but it is a lot to cover.  I am sure there are things that I left out but the basics are there.

This is What Linux Sounds Like

August 11, 2009

So what good is a system that has Amarok (if you don’t know what this is and you use Ubuntu/Kubuntu, stop now and check out the link) but doesn’t play sounds?  I’ll let you come to your own conclusions on that.  For me the answer is “pointless and rather annoying”.  A few days ago I had my first issues with my sound card.  Basically I would not be able to play songs on Amarok while watching a video on a site (read: YouTube).  It turns out that I was trying to route all of my sound through PulseAudio.

No clue why it only started causing problems a few days ago and not any time before.  Here is my ad-hoc solution.  System>Preferences>Sound.  Then in this menu change have ALSA manage the sound events and PulseAudio control the sound playback for videos and music. Everything else is set to Autodetect.  You’re almost done.  Now you just need to open up Amarok and go to Settings>Configure Amarok>Engine.  In this menu use the Xine Engine for your Sound System, for the Output Plugin select PulseAudio. “Problem solved”.

In addition to solving the above problem it also allowed me to preview music files with a mouse over.  Some people complain about this feature, but I really like it. Saves me the time of opening an actual media player.

I honestly spent about two hours searching around Google and the Ubuntu forums trying to find a solution to this.  However, nothing seemed to work; or my system was already configured as they recommended.  Don’t take this the wrong way, I LOVE the Ubuntu forums. In fact they have helped me solve most of my problems, such as getting my computer to not freeze up when I insert and SD card, but that’s a whole differnt story.

Well I am now somewhat more interested in learning more about PulseAudio and Xine, so I will probably spend some time reading those Wikipeia pages I linked at the beginning.  They should be a good place to start.  Maybe I will be able to find a better solution to suggest.  Who knows, maybe this is just a 64-bit problem, but I really doubt that.

Space Usage

August 4, 2009

Not too much is new in Linux world.  Still mostly working on SPOJ problems and browsing the internet.  So nothing all that exciting yet.

However, I did manage to learn how to use the mount command.  The general format is

mount [source] [destination]

Here is an example:  mount /dev/sda1 /media/disk The colors are so that you can easily follow which is the destination and which is the source.  I probably should mention at this time that I am running Ubuntu from an external HD (otherwise I run Vista) so if I ever want to access any of the files on my internal HD I must first mount it.

Well that wasn’t too hard.  Though if you don’t want to bother with this Ubuntu does have a graphical way to do this.  Just go to Places and the drive you want to mount should be in the drop down list.  Personally I never knew the source of my internal HD until I ran df -h.  This displaces the space used by each available disk (internal, external, etc.).  The -h flag tells the system to display the information in amounts humans can more easily understand (kB, MB, GB, and so on).