Monday, November 12, 2012

Setting up multiple Firefox profiles in Ubuntu 12.04 and Windows 7

Introduction

One of the more underrated features of the Firefox Web Browser is the ability to set up different user profiles.

This feature comes quite a bit in handy when you have different people using the same computer, but don't require the overhead of setting up separate user accounts for each individual using it.

Setting up separate profiles allows multiple people to have Firefox configured the way they like it: with different bookmarks, saved passwords,  personal history, and so on.

Plenty of people like to keep their browsers signed in to the services they like for convenience (not having to keep signing back in), but when multiple people share a computer, signing people in and out all the time can be a hassle. Enter Profiles, unique "Firefox's" (so to speak) for each person. On my system, I have three profiles: One of myself, one for my better half, and one for guests which uses Firefox In-Private mode so their personal passwords, etc., are not tracked. You could even have different profiles for work and personal use, if you choose.

Firefox profiles are very easy to set up and manage, in today's post, I'll show you how to set them up on both Ubuntu 12.04 and Windows 7.

Ubuntu 12.04

I'll start off with a few assumptions here: You already have one Firefox profile set up and one short cut in your Unity Launcher (or other launcher of your choice). This is how Ubuntu comes by default, so it's not too crazy to assume this. If for some reason this isn't the case, you can easily install Firefox with the Ubuntu Software Center. Also, we'll assume that your secondary profiles (for other users), will also be accessed from the Unity launcher.

Creating new profiles

Before adding the new Firefox sessions to the Ubuntu browser, we'll have to set them up in Firefox first. First, launch a Terminal. Then, from the command line, run:

firefox -no-remote -ProfileManager

Most likely, you already have one profile named something like "Default". Feel free to keep this named Default, or rename it to your own name. Just remember whatever name you give it.

To make a new profile, click the "Create Profile" button:



Firefox will give you some data about profiles (pretty much what I summed up above), and then you can click "Next" and enter a name for the new profile. You can also change the directory the profile is stored, although most likely the default will be sufficient.

Create as many profiles as you desire, remembering the name for each. When you are done, close the Profile Manager.

Setting up different launchers for each Profile

There are actually two different ways you could go about this. You could just keep using your single Firefox launcher, but have it ask on launch what profile to use. To do this, from the Profile Manager, simply uncheck "Don't ask on startup". This will allow you to pick which profile you want each time you start.

But personally, I prefer to have a separate Unity launcher for each profile. This allows each person to access their own profile with just a single click. This is pretty each to set up, but also requires some more Terminal to work. Basically, we're going to change the default launcher to open one profile (your own for instance), then make new launchers for the other profiles.

From Terminal, navigate to:

/usr/share/applications

Here, you'll find all (or at least most) of the launchers used by Ubuntu and Unity, there should be one for Firefox called "firefox.desktop". Open it in your favourite text editor (with root access).

There is a lot of stuff in here, but you only have to make a very minor change or two. Look in the file for the lines beginning with "Exec=". This is the command which is executed when the launcher is run. For example:

Exec=firefox %u

To make it launch a specific profile, use the -P flag:


Exec=firefox -no-remote -P Jason %u

The "-no-remote" flag causes Firefox to launch it's own process rather than trying to connect to an existing process. This way, we can have different Firefox sessions with each profile open simultaneously. Make the change to all Exec lines in the file and save.

Pro-Tip: You might notice upon saving that the Firefox icon disappears from the Unity launcher. If it does, no sweat. Just open /usr/share/applications in Nautilus, find the "firefox.desktop" file, and drag it over to the Unity launcher. Keep Nautilus open since you'll need to do this for subsequent launchers.



To make a new launcher for another profile, just copy the firefox.desktop file to a different name, e.g. "profile2_firefox.desktop". Open it in a text editor and make the same changes to the "Exec" line. But don't save yet.

In order for Unity to isolate this launcher from the original, it's important that you also change the "Name=" line. For example, change:

Name=Firefox Web Browser

to something more personal like:

Name=Profile2_Firefox

Do this for all instances of "Name".

You can also change the icon easily too, so there aren't two Firefox icons in the Launcher. To do this, change the "Icon=" from:

Icon=firefox

To something else. One icon I like looks like a small picture of the planet:

Icon=/usr/share/icons/gnome/48x48/emblems/emblem-web.png

But feel free to poke around /usr/share/icons and find one you like better!

Finally, once you've saved the launcher, don't forget to to to /usr/share/applications on Nautilus and drag it over to the Unity launcher!

That's about it, just repeat the process for each profile you want. If you'd like a "Private" session to use (to avoid tracking passwords, etc), use the "-private" flag in your Exec line.

You can also keep using a "default" Firefox icon if you wish. This will cause the last profile to be launched which was launched with the ProfileManager. One might want to do this if you frequently launch links from other other applications (e.g. Thunderbird). In this case, just keep the default Firefox icon using the most frequently used profile (your own), but use alternate icons to launch other profiles.

Pro-Tip: I also set up a keyboard shortcut to launch the Guest Firefox session. To do this, just make a script (in the "Home", or "Home/Scripts" folder for example) with the following content:


firefox -P Guest -no-remote -private

Replace "Guest" with whatever you might have named the Guest profile. Save, then right click on the file and go to "Properties", then the "Permissions" tab. Check "Allow executing this file as a program":



Now, launch the HUD and type "keyboard". Open the Keyboard settings and go to "Shortcuts". Under "Custom Shortcuts" click the "+" button. Give it a name, and point the command to your script. Click Apply. To active the new short cut, click on where it says "Disabled", then hit the key combination you want to trigger it (for example CTRL-ALT-P). Now try hitting CTRL-ALT-P and you should see the private Guest profile launch.



Windows 7

The process in Windows 7 is quite similar, but seems to be less flexible then Ubuntu.

To open the ProfileManager in Windows 7, hit Win+R to open the Run menu. Then, type "firefox -no-remote -p" to open the Profile manager.

Create your Profiles exactly as described above.You can also un-check "Don't ask at start up" if you want to pick the profile to use every time.

Assuming to have your Firefox icon docked on the Start Bar (a.k.a. Task Bar), you can continue to just click on that icon, which will launch whatever the last profile started with the Profile Manager was. Unfortunately, I haven't figured out how to make the docked Firefox icon always start a specific profile (but if you know, please mention it in the comments).

You also also create shortcuts to launch other Firefox profiles. To do this, from the Desktop, Right-click and say "New->Shortcut". Use "Browse" to select the Firefox executable (you'll likely find it near C:\Program Files (x86)\Mozilla Firefox").

But before saving it, make the following change:

Before: "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -no-remote -P "Profile1"

Where "Profile1" is the name of an alternate profile.

You can make as many of these on the Desktop as you want, and even drag them into the Start Menu. Unfortunately, the Start Bar only seems to allow us to have a single icon, which launches whatever was last launched with the ProfileManager. I'm not sure why this is, but it's a limitation we'll have to live with for now (again, if you have any advice, please let us know).


Hopefully this is a feature of Firefox you'll find useful, I certainly do. Just one of the things that makes Firefox such a great browser!

One final tip: You can protect your saved passwords in Firefox by using a Master Password. This can come in handy in case your computer is ever stolen or its security otherwise compromised.





Sunday, June 24, 2012

A few Myth TV tips for Ubuntu 12.04

Good morning all!

I've been using MythTV 0.25 on Ubuntu 12.04 for a little over a month now, and while pleased overall, there were a few annoyances that caused me to scour the Interwebs for a solution. Things are working better now, so I wanted to share my tips for others out there!

1) Legacy Full Screen Support

If you are using Ubuntu with Unity, you may notice the MythTV interface doesn't completely go "full screen". That is, it's somewhat shadowed by the Unity bar and top bar.

To fix this, you'll need the CompizConfig Settings Manager. I don't think this is installed by default, so find it in the Ubuntu Software Center. Note that this is an advanced tool to mess with your settings, and while there is some pretty cool stuff in here, do be careful.

To get MythTV full screen over the Ubuntu panels, use "Legacy Full Screen" support.

1) Under CompizConfig Settings Manager, go to "Utility"
2) Go to "Work arounds"
3) Check "Legacy Full Screen" support.

After that, your MythTV should go properly full screen. Restart if necessary.

Reference: http://www.thegoss.com.au/content/ubuntu-1204-precise-pangolin-mythtv

2) Mythfilldatabase takes forever to run

(Note: These seems to have been fixed in a recent version of mythfilldatabase. A fresh MythTV install on Ubuntu 12.04 seems to no longer have this issue, but the instructions are still here for reference).

One bizarre thing I noticed is that mythfilldatabase never seems to end (actually, my girlfriend pointed out that hard drive was clicking loudly causing me to investigate and finding mythfilldatabase and mysql hogging the I/O. Hint: iotop is a cool program).

This is apparently due to a mythfilldatabase bug, and is fixed in the newest builds, but if you need a work around, here it is:

1) Set up a TMPFS for /tmp
Add the following to '/etc/fstab':

tmpfs   /tmp   tmpfs   nodev,nosuid    0 0

2) Change MYSQL configuration parameter:

Add the following to '/etc/mysql/conf.d/mythtv.cn':

default_storage_engine=MyISAM

Note: It's important to know that in step 1, you are actually switching your /tmp to a TMPFS file system. This means that any data written to /tmp is written to your RAM, and not to your hard disk as usual.

This can have both positive and negative consequences.

Using a tmpfs for /tmp can have some all around nice performance improvements since writing to RAM is far faster than writing to disc. Therefore, programs using /tmp will have their write operations quicker, therefore improving performance.

The downside is that the side of /tmp will be limited to the size of available RAM. This can be issue if /tmp ever becomes full, writes will fail. So, if you run into this issue, your programs may stop working.

If this becomes a recurring problem, you might need to revert your /tmp back to the HD and use the bug fixed version of mythfilldatabase. But, I've been using /tmp as a tmpfs for a good month now and have had no ill effects with moderate usage (I also have 6GB of RAM...just saying.)

Tip: Keep track of /tmp usage with the df command on the command line. Mine is currently only at 1% full.

References:
http://ubuntuforums.org/showthread.php?t=1991684
http://ubuntuforums.org/showpost.php?p=11918589&postcount=35

3) Mythweb PHP errors

I noticed some unusual errors in Mythweb. Simple functions like setting up recordings didn't seem to take, and there were some php error message along the top of some of the pages. This was a bit irritating to fix.

Rather than repeat everything I did, I'll just point you to the official ticket:
http://code.mythtv.org/trac/ticket/10142

I just manually clicked on the individual *.patch files and applied the changes by hand. There's probably a better way to do it, but that worked for me. Hope you find it useful.

4) A new Remove_Commercials script

My first attempt to use my old remove_commercials script failed miserably. Not surprising, since some of the command line parameters changed between versions. But, there's an updated one you can use here:

http://www.mythtv.org/wiki/Script_-_RemoveCommercials 

The script didn't quite work out of the box for me. A few tweaks I made:

1) Replacing all of the usages of $START with "$START"
2) Adding --user=mythtv --password=PASSWORD (where PASSWORD is your mysql password, from the mythbackend settings) to the mysql command
3) You might also get better results if you use -f on mythcommflag instead of --chanid and --starttime, but if they work for you then great.

I'm still playing with the commercial cut script a bit, so I may make some more updates, but hopefully that'll give you something to start with.




One issue I still have is the display mythfrontend runs on. I haven't yet been able to control what display it opens on from the command line as setting $DISPLAY has no effect. But I'll keep trying!

If you have any of your own tips, let us know. Take care, and have a great day!

Sunday, June 3, 2012

Configuring LIRC for HVR-1600 in Ubuntu 12.04




As promised, here is the recipe I followed to get LIRC working for my Hauppauge HVR1600 card on Ubuntu 12.04. This includes both the IR Receiver and the IR Blaster. This may work for other Hauppauge cards as well. The hard work was all done by others, for Ubuntu 10.04, this just serves as an updated reference for Ubuntu 12.04. As usual, this info is provided with NO warranty of any kind, so use at your own risk! It's assumed you have basic knowledge of Linux/LIRC/Scripts/etc.

The secret to the HVR1600 is the lirc_zilog kernel module. Once this kernel module is loaded and LIRC is configured, the HVR1600's IR capabilities should work.

Step One: Install LIRC

Step one is easy, just install standard LIRC! You can install it from the Ubuntu Software Center, or, install (or build) it from the command line if you are so inclined. The LIRC version that was installed for me was 0.9.0.

Step Two: Install lirc_zilog

(Note: you might already have lirc_zilog installed, see below).

This part is a bit tricky. The "proper" way to do it would be to install the lirc-modules-source package, apply the lirc_zilog patch, then reconfigure the package to build the kernel modules. The Ubuntu 10.04 recipe for this is here.

However, it does not yet appear that the lirc-modules-source package is available for Ubuntu 12.04. If it were, you would likely have to make some changes to the patch file to get it building under 12.04 (you might find some hints here).

As a shortcut, I found a complied version of lirc_zilog that appears to be 12.04 compatible here. There is a *.deb file for both i386 and 64-bit version (disclaimer: I can't vouch for the security of this site of the files). I find it strange that these files appear in this package but aren't actually in Ubuntu by default - but I'm sure there is an answer to that (if you know, feel free to share).

Download the version applicable to you and open the *.deb file with the Archive Manager (not the Ubuntu Software Center, which it opens with by default).

Find the lirc_zilog.ko file in the archive here: /lib/modules/3.2.0-24-generic/kernel/drivers/staging/media/lirc/

Extract it, and copy it to the following location in your system:
/lib/modules/3.2.0-24-generic/updates/dkms/lirc_zilog.ko

To load the module: sudo modprobe lirc_zilog

If all was successful, you shouldn't get any errors. At this point, you should be able to do lsmod | grep -i lirc_zilog and see:

lirc_dev               19204  1 lirc_zilog

Pro-Tip: To have lirc_zilog automatically inserted into the kernel on boot, add it to /etc/modules

Pro-Tip:  You might already have lirc_zilog installed. As an easy check, in a Terminal, go to /lib/modules and run find . -name "lirc_zilog*. If it finds lirc_zilog, already, you shouldn't have to copy one from another source. However, you'll still have to modprobe lirc_zilog to get it loaded and add it to /etc/modules to have it run boot.


Step Three: Install the HVR1600 IR Firmware files

I believe this can be found here, and a few other locations on the web.

This file needs to be copied here: /lib/firmware


Step Four: Configuration Files

You need to modify the following two files:

/etc/lirc/hardware.conf
/etc/lirc/lircd.conf


First, we modify hardware.conf to get lirc_zilog to be loaded. Add or modify the following lines (if necessary):

REMOTE_MODULES="lirc_dev lirc_zilog"
REMOTE_DEVICE="/dev/lirc0"
START_LIRCD="true"
LOAD_MODULES="true"

As for lircd.conf, again, a working one for my card was found here. I believe you can even put the relevant parts in its own file and use an include directive if you'd like.

Step Five: Take a deep breath

You're almost there! At this point, the following two things should work:

From a terminal, run "irw". Point your HVR1600 at the IR Receiver and press some buttons! If irw is working correctly, you should see some response, like:

$ irw
00000000000017a5 00 OK Hauppauge_350
0000000000001795 00 Down Hauppauge_350
0000000000001794 00 Up Hauppauge_350

This means your IR Receiver is working.

To test the IR Blaster, use the irsend command. At this point, it doesn't matter what code set you use, you just want to get the light to blink. For example:

$ irsend SEND_ONCE blaster 0_130_KEY_0

Note that the name "blaster" was the name chosen in "lircd.conf" from above....if you used another name insert it there.

Step Six: Final configuration

If the IR Blaster and Receiver are responsive, you're pretty much golden. All that remains is a bit of extra configuration.

To get the IR Receiver to do "cool" things (e.g. work MythTV and/or launch applications), you want to configure a ".lircrc" file. This should be in your Home directory.

Each command to be sent to a specific application has an entry that looks like this:

begin
prog = mythtv
button = LEFT
repeat = 3
config = Left
end

Each starts with "begin" and ends with "end".

button = The button on the remote which will cause the command
prog = The program to send the command too.
config = The command to send to the program
repeat = What to do when a key is repeated. 0 ignores repeats. A positive value (n) sends the command to the program every "nth" times.

Obviously, you need a lot of commands to get various buttons working. To get you started, here is a .lircrc file very similar to the one I use.

Pro-Tip: To get a remote button to start a program, instead of just being interpreted by one, set "prog" to irexec and "config" to the command line-method of starting the program. Remember that irexec must be running in the background for this to work, so you can set it up as an Ubuntu start-up application.

For the receiver, you need to figure out what code set the device you are sending commands to uses. One again, a script is already developed for this. This will send the Power command to the device. Once you see it respond, you've found the right code set. For example, in the command I have above, the code set being used was 0_130 code set.

You'll most often be using this to change the channel, but you can do other things as well. You can find some example change_channel scripts here. Don't forget that in order for MythTV change the channel, you need to configure the backend to post to the script.

At this point you should be in good shape, but you might require some additional modifications to get things "quite right" (geeks are never happy, are we?)

My only concern is that some point along the line, a Linux kernel change will cause lirc_zilog to stop working. But I'll cross that bridge when I come to it...either by getting it building from source or finding it compiled elsewhere. I hope you found this guide helpful.

References and special thanks!
http://wilsonet.com/?p=40
http://www.blushingpenguin.com/mark/blog/?p=24
http://www.bsntech.com/bsntech-blog-mainmenu-321/computers-mainmenu-281/1762-getting-your-hauppauge-hvr-1600-remote-control-to-work-in-ubuntu-1004-lucid.html
http://pkgs.org/download/linux-image-3.2.0-24-generic










Tuesday, May 29, 2012

Ubuntu 12.04: The Good. The Bad. The (Not So?) Ugly.

Hello friends!

I recently upgraded by home PC from Ubuntu 10.04 to Ubuntu 12.04. I decided to make a hardware change as well, specifically, upgrading my primary hard drive from a 320GB SATA to a 2TB SATA.

Now, I didn't actually "upgrade" the 10.04 to Ubuntu 12.04 in place, I installed a fresh copy of Ubuntu 12.04 on the 2TB drive and manually migrated my programs, settings and files over to the new system. I personally like to start with fresh installs when possible, and given all the custom modifications I had made to my system, I feared an upgrade would cause more problems then it was worth (if you've had a different experience, let us know).

I didn't take the choice of upgrading to Ubuntu 12.04 lightly. I knew I would have to upgrade 10.04 sooner or later, only having a year 10.04 support left, and didn't want to let it go until the last minute. Having heard a lot of dislike between versions 10.10, 11.04, and 11.10 (the Unity UI for example), I seriously considered switching to another distribution such as Linux Mint.

In the end, I decided to give Ubuntu 12.04 a try. From looking at the screen shots and reading the design philosophy, I decided Unity was worth a try. Even if I didn't like it, I knew I could always install another desktop on top, like classic GNOME, Cinnamon, or GNOME 3, without having to switch distros.

So far, I'm happy with what I see, and think I'll be sticking around with Ubuntu, at least for now. The future is always open though!

The Good


Off the bat, a lot of 12.04, including the GUI, impressed me. Install and format process was very fast, even on the 2TB drive. I haven't tried setting up a dual boot system (Linux only) but that has been extremely easy since at least 9.10 so assuming it's been kept up to date with newer versions of other OS's, I don't imagine much of an issue.

Nvidia Binary Drivers


Nvidia Binary Drivers were detected and installed out of the box, no configuration needed. This gave me access to 3D acceleration and advanced multi-display configuration - a must have for a HTPC. I did use the Hardware Drivers option to upgrade to the "bleeding edge" drivers, though rather this was necessary or not, I'm not sure.

HDMI Audio Support


Remember this post? Thanks to an updated ALSA, HDMI Audio worked out of the box too. They also fixed the under-enumeration problem present in 10.04. I immediately had a (single) HDMI audio option in the Sound Devices that I could select and move back and forth seemlessly, no fuss. Success!

New MythTV & HVR1600 support


Since one of the main purposes of the my machine is to use as a HTPC and DVR, I installed MythTV straight from the repositories, and no issues setting up my card. Just don't forget to add you cx18.conf file to /etc/modprobe.d :)

Webcam Support

In 10.04 I was never quite able to get my Webcam and my HVR1600 working together. In 12.04, they seem to both work happily, though I haven't tried unplugging the webcam yet (that may still cause some issues to be aware of)

Improved Third Party Software

Firefox and Thunderbird are installed by default. Maybe you don't like them, but I do. Skype works fairly well and is easily installable. The Ubuntu Software Center is really nice, so far I haven't had any need to use another package manager (though I may need to at some point).

The Bad


USB3.0


I never got USB3.0 working reliably on 10.04, and 12.04 doesn't seem to have improved much. Although the Linux kernel officially supports USB3.0, I'm guessing the there is something amiss with the drivers for my specific chipset (the 3.0 ports are build into the motherboard). I am certain the ports, cords and external hard drive are all USB3.0, but I've never gotten any more then a sustained 60 MB/sec (480Mb/sec, USB2.0) transfer speeds when connected to the USB3.0 ports. Worse, I get sporadic "unmounting" of the USB drive when connected over 3.0, and cannot remount without restarting the computer. I realize this is likely the fault of a driver, or missing kernel module (and less Ubuntu), but it's still irritating. Hopefully I can figure out the bottle neck and start getting reliable USB 3.0 support.

Flash

So basically, YouTube videos have a blueish tint. Yep, you heard me right. Apparently, this is a bug in Flash,  but since Adobe has officially discontinued Flash for Linux, with 11.2 being the last version, it is unlikely the bug will be fixed. Now, there are workarounds, the easiest being to disable hardware acceleration,  but come on, something like this shouldn't be necessary as now I have to drive my CPU hotter. 

Another bizarre issue with Flash if you are using dual desktops: Full screen sometimes only appears on your *primary* display, even if the originating window was on the second. Now, I didn't have this problem with YouTube (full screen was on the correct display), but I did have this problem with sites that used their own custom player based on Flash, such as video from the sites of TV Networks. I found a work around for this using gDevilspie (see this thread). But this only addressed the *position* of the window, *not* the size. so unless the two displays were running at the resolution, the full screen was cropped and I could only see the top-left portion. My only work around of this (for now) is to run both displays at the same resolution. 

Hopefully with Flash for Linux discontinued, Canonical (or someone out there) will do the right thing and take over the reigns of support Flash going into the future. Even if you wish Flash would just die, pretending it's already dead is not the solution to a good user experience.

LIRC

LIRC is a great program, unless your card just happens to not be supported. This isn't LIRC's fault, it tries its best, but for legal reasons there are certain remote they just can't support. Getting LIRC to work for my HVR1600 card was a *huge* pain on 10.04, requiring me to build a custom kernel module. I did eventually get it, but if memory serves, it took several months.

Unfortunately, my card *still* isn't supported in the newest version of LIRC with 12.04. Likely, it never will. On 10.04, I was able to build the kernel module thanks to the lirc-modules-source package and a very nice Fedora user, but it wasn't fun. Unfortunately, it appears lirc-modules-source is not available for 12.04! So until it is, I can't update the patch for 12.04, nor build my kernel module or use my IR Blaster/Receiver.

UPDATE!  I *have* gotten LIRC for my HVR1600 card working on 12.04! Without too much difficulty. I happened across a pre-complied version of the necessary module, lirc_zilog, here inside of a DEB file (32 and 64-bit versions available). I'll post a more comprehensive tutorial as soon as I have a spare moment :).

The (Not So?) Ugly

Unity

Hey, I like it. Been using it for a few weeks now and I find it pretty fluid and easy to use. The HUD feature is very cool. Now, now, I know what you are thinking...that damn Unity bar is glued to the left side!!! While I agree that, in principle, this was a poor choice on the part of the Unity developers, you have to remember that Unity is just one desktop environment. You aren't forced to use it, and there are even forks out there (or could fire one up yourself) to get it on the bottom if it's really important to you. Or use an alternative like Cairo dock, or another desktop environment. So it's not really a reason to abandon the distribution altogether, at least IMHO. And if you give it try, you might just like it too. While I do hope they add an supported option to move it in the future, for now I can deal.

X-Session Weirdness

In Ubuntu 10.04, I ran GNOME on two separate X-sessions, one of the PC display, and one of the TV display. I liked this better then running a single display on both, since applications seemed to handle it better (e.g. full screen Flash), even though it meant you couldn't move windows between displays (no biggie to me).

When I enabled dual X-sessions (with the Nvidia-config tool) in 12.04, I was very confused. On one display was the normal Ubuntu desktop, but on the other was just a pure white background with a "X" for a cursor. Obviously 12.04/Unity wasn't designed to handle dual X-sessions this way.

So, I flipped over to Twinview, to see if I could configure that the way I wanted. To my vast surprise, I found two separate desktops (complete with Launcher and top menu bar) just as if I was using dual X-sessions! But now, I had the ability to move windows between desktops. Pretty cool, considering I had been expecting something similar to way Windows handles extended displays, just making a blank window space on the other monitor, but no separate task bar.

So it seems like they tried to take the best of dual X-sessions and the best of Twinview (extended desktop) and munge them together (as a new form of Twinview). And honestly, it works pretty well, except for two problems I've found so far:

1) The "Flash" full screen issue I mentioned above
2) Applications don't quite "understand" it.

What I mean by #2 is that I'm used to being able to launch an X program on either GUI from the command line simply by setting the "DISPLAY" environment variable. Well, in 12.04 no such luck, the DISPLAY environment variable has the same value (0) regardless of what display you are on. So now, launching applications based on the X-session is a little trickier than it used to be - not a good thing. For the most part, applications do work correctly if you launch them on the correct display, but I haven't yet figured out how to launch an application on a specific display from the command line. Unfortunately, MythTV was one of the applications that didn't quite behave, it was showing up on the primary display regardless of what display I launched it from. No good - I need Myth on my secondary (TV) display. Thankfully I found an option in the MythTV appearance settings which allowed me to choose between display "0" and "1". Setting to 1 put it on the TV display....just as if I had set the environment variable. So there is some support similar to the old methods, but it appears to be application specific.

But sometimes (like when I'm running mythbackend), I *do* want it on the primary display. I used to have separate scripts that I could run for which display I wanted to appear on...but even trying to use the "--display" option on the mythfrontend command line, it goes to whatever display I set it to in the options. So, I have a workaround for now (setting the display option in the settings), but this is irritating...having a way to move it on the command line would be much preferred.

It's only been a few weeks, but so far I like what I see in 12.04 and find it a worthy successor to 10.04 (I usually skip non-LTS versions...due to the work involved with upgrading). So I'll be sticking with Ubuntu for now, and hope others out there enjoy it as well.

Have a great day!

Saturday, May 12, 2012

The Art of Computer Programming


Greetings all!

Have you ever heard that computer programming (and by extension, Software Engineering) is an act/profession that doesn't require any imagination or creativity?

I certainly have, but such comments tend to be made by people with no knowledge or experience in the field, so their ignorance can be (at least partially) forgiven.

But as such, it prompted me to write an article about why this is untrue; software development does indeed require imagination and creativity, in fact, quite a lot of it!

It's not too difficult to see how such an option might evolve among the common populace, if you look at the "stereotypical" view of a software developer in society, you'll find a person (often male), wearing a white collared shirt sitting in dull, grey-looking cubical typing on a dull black computer with meaningless lines of white (or green if you are really lucky) text on the screen. How could someone in such a boring-looking world possibly have any sense of creativity?

If you examine software developers in real life, you actually find a much different perspective. But I digress, this article isn't really about the people, it's about the work itself. There is another common misconception about programming: that it is completely formulamatic, and that programmers just go through the motions dicated from a book or a superior and somehow miraculously end up with a perfectly working program. Nothing could be further from the truth.

Imagination can be defined in serveral ways, but to me, it typically refers to the ability to create images or sensory input in one's mind. For example, I can picture what a peanut butter sandwich looks like, without my eyes actually seeing in. I can recall what it smells like, what it tastes like and what it feels like to hold. I can ever hear what I sound like while chewing it.

But this is only the memory aspect of imagination. There is a whole other layer of imagination on top of it, namely, the ability to create things that you have never  actually experienced.

For example, I have never been to the Eiffel tower, but I can imagine standing on top of it. I have never been in space, but I can imagine floating in midair.

Our imagination can dream up things we've never thought of before, like the plot of a novel or a "Eureka" moment in a discovery. These ideas use building blocks to create something completely new. This also leads into creativity, typically the creation of something new, where "new" depends on the domain of what's being created.

Returning to the theme of developing software, there are many aspects of which require imagination and creativity, for example:

1) Imagining the finished project from high level sketch. The idea for the a piece of software typically comes form one of two places: a) Your brain; b) Someone else's brain. If you come up with an idea for a piece of software (perhaps because it's something you need, but doesn't exist yet), then you clearly exercised creativity. But even if you are developing the idea for some else, you still need to exercise your imagination and creativity. For example, in both cases you exercised imagination to envision the new software even though you've never actually seen it.

Descriptions of software to be developed tend to start as extremely abstract...just a setence or paragraph on what the software needs to do without any idea of how it is going to be done. It is up to the developer to figure out how to get there, by imagining the finished project. The developer might even come up with new things the software should or needs to do that the client never even thought of. Software gets very complicated very fast. For example, there can be many programs (not just one) involved, and communication between them, as well as documentation and many rounds of testing. Sometimes, it even takes creative methods to get the client to tell you what they need in their software, since often, they aren't sure themselves!

2) Building a cohesive whole from primitive building blocks. Computers have evolved over the years from lights blinking on a box to complex machines capable of displaying millions of pixels or performaing trillions of operations per second. It is extremely rare that any piece of software developed today is built entirely "from scratch". If software always needed to be developed from completely scratch, we'd still be using boxes with blinking lights and flipping switches to represent binary input. Over the years, software developers have add layers of "encapsulation" onto the basic circuitry inside a computer. Primitative building blocks that allow us to make the computer do something useful, for example, moving a piece of data from memory block to another, or turning a specific pixel a specific color.

When you go to develop a piece of software, you need to carefully understand the requirements, and then figure out how to combine the primitive operations available to form a cohesive whole. And sometimes you don't have the building blocks you need, so you have to find them or create them, using even more primitive operations.

Software is all about layers and building from smaller blocks. It's like when you were a child playing with your first batch of Legos. In the box, they are just thousands of individual blocks, useless by themselves. But when you combine them with imagination and creativity, you can combine those blocks in an astronomical number of ways to form something completely different. Building software is much the same, and without imagination, you wouldn't be able to combine them together to create something useful, nor keep track of the building blocks the software requires which can easily number into the millions.

3) Visualizaling what the ones and zeros actually mean. It can be hard to imagine to the novice user, but even today, at the heart of computing is nothing more then the manipulation of binary data, that is, ones and zeros (binary digits, or bits). And yet, when you look at your screen, you see text, buttons, pictures, even videos. And yet, it's ALL just ones and zeros. When a programmer is creating a piece of software, they continually have to imagine what that data, the ones and zeros, actually represents. Now, there are building blocks to help, some of the most primitive operations the computer provides are used to interpret once piece of binary data as another, for example, turning a group of bits into the letter 'A', or the number 65, or the color of a pixel. But you can't lose track of what it is underneith, and to visualize ones and zeros forming a picture of a beautiful sunset certainly requires imagination. 

4) Solving problems in creative ways. Solving a problem or problems with software usually requires solving a bunch of smaller problems, then combining the solutions of the smaller problems together to solve the big problems. Each smaller problem is usually solved with a concise sequence of logical statements often mathematical in origin. The same task can usually be done in many different ways, using different sequences of logical statements.


Navigating a logical sequence of statements is rarely trivial, whether you are writing it or reading it. At each stage, you have to clearly imagine what that statement means (sometimes in terms of the ones and zeros in the computer, sometimes visually like boxes and pipes) and keep it in your minds eye for hundreds or thosands more logical statements you are writing to make it make sense.

The ability to break the large problem up into smaller problems takes a lot of creativity, and solutions to the smaller problems themselves are often far from obvious.

5) Development of user interfaces. Programmers rarely write programs which just do a single thing, all the time. Most software is capable of performing many different tasks, and requires input from a user, which can be entered an enormous number of ways. So not only do programmers have to write the software to perform a funtion, they need to envision a way to let the user tell the software what to do.

A lot of software today provides a Graphical User Interface (GUI, pronounced 'gooey'). Creating a good GUI is a subject of much discussion, and can be considered an art form all on its own. The operating system you are using now (likely, though perhaps not) includes a GUI, as does the web browser you are reading this page on. It took a lot of time and creativity on the part of the devlopers to figure out how to make the GUI work well and be usable. And even then it's difficult, because a devloper will tend to write a GUI that a developer wants to use...but often that isn't sufficient for the non-devloper. As such, they have to imagine what it's like to be an average user, and create the GUI for them, not themselves. Stepping outside of yourself like that is not easy, and requires a lot of imagination. Even software which provides a non-GUI interface, like a text-only interface (yes, they still exist) needs to think about the user, and figure out a good way to describe all of the functions and operations of the software through text only.

6) Breaking software. You might be suprised to learn that an important job of a software developer is actually trying to figure out how to break the software, let alone figuing out how to write it. All professional developers want their software to be completely bug free, but in reality, that goal isn't achievable. Still, as perfectionists, we strieve to make our software the absolute best that it can be, and one possible metric by which to measure that is bugs. Bugs (and sometimes new "features") typically happen because the user does something with the software that the developer didn't ancipiate, and so the software does something unexpected.

In fact, software development companies have entire departements dedicated to testing and trying to break software, sometimes these departments are even bigger than the developent department. And they are effectively programmers themselves, just doing a different kind of programming. One job is to write their own programs, specifically for the purpose of testing the product program. If the software is supposed to do things "A","B" and "C", then they write a program to exercise A, B and C in different ways, then check that the software preforms as expected.

But, it's also their job to imagine ways to use the software in unexpected ways, and see how the software reacts. Such a task requires you to create inputs entirely from your imagination, and sometimes to break the software you need to get pretty creative, depending on how well the original developer considered the possible inputs. For the programmer, tracking down bugs and figuring out methods to fix them while maintaining the integrity of the software is a strong exercise in creativity and imagination.

7) Documentation and help files. Software is useless unless you have a good way to tell the user how to use it. Developers also need to write extensive documentation on the software themselves so they can use it as reference material when updating and changing the software.

A GUI can only hold so much information, so most software typically has a Help section. The Help section describes all of the software in greater detail, so that the user can understand it at a more basic level in order to decide how to perform tasks. Writing this documentation requires you to imagine how the software will work, and what it looks like, especially since the person writing it might not have developed it. It's also important to organize how the Help appears so that it is accessible to the user.

The documentation of the software can number into the thousands of pages and also needs to be well organized. Having creative ways to store and reference this documentation so it can be recalled by the developers when needed is critical. Trust me, you don't want the developer of a nuclear power plant's software writing code without a clear picture in his or her head of what it's going to do!

8) Considering the pace at which technology changes, and anticipanting future needs. Technology moves very, very rapidly. As such, professional software is almost never just a |one-off" peice of work which is never touched again. Software evolves over time, and when programming, you can't just consider what the software needs to do today, you need to anticipate what it's going to need to do tomorrow, the next day and the day after that. Some software systems survive for decades after their original developement. If the original developers of the software hadn't had any imagination or creativity, they wouldn't have been able to build the software to evolve, and have to be constantly replacing the software. But, in reality, developers build software to evolve, to live and to grow.

Even this list is hardly exlusive, a professional programmer could probably add a few more ways on top of the ones listed on how programming requires creativity. Just because we might (emphesis on the might) not be able to paint a masterpeice or decorate a house hardly means that we lack imagination and creativity, it just means that we express it in different ways.

I hope that this blog post has been enlightening to you, and encourage you to consider all the imagination, creativity, and hard work into the software you use everyday. Today, the world runs on software, and that's unlikely to change any time soon. Considering all of this, why one would think  programming doesn't require imagination and creativty, especially when it's something they've never experienced, is beyond me. Or at least, beyond this particular blog post :)

Take care, and have a great day!

Monday, April 16, 2012

Useful tools for Matrix/Linear Algebra

Five years ago, around this time, I was busily studying for my Linear Algebra final.

Personally, I found both Linear Algebra and Matrix Algebra to be enjoyable, if sometimes difficult, topics. There also seemed to be overlap with my primary vocation (along with Discrete Math), Computer Science, then some of the other math classes I took.

The applications to both of these fields are wide-spread, for example Matrix multiplication is heavily used in the area of 3D-graphics programming (see here and here). Ever played an FPS like Doom or Half-life 2? Many of these games utilize the multiplications of matrices to transform objects in three-dimension objects along an axis, to stretch it, or translate it along an axis. In fact, many GPU's are basically processors designed explicitly for the purpose of working on matricies, and popular programming API's such as OpenGL are designed to make programming with matricies easier.

In Linear Algebra, I was pretty facinated with Vector Spaces, and more generically, the idea of mathematical spaces, elaborate models describing concepts by combining base axioms. Two years later, I found that many of the fundamentals I'd learned in Linear Algebra had surprising applications in Artificial Intelligence (e.g. Neural networks and Feature Space).

I used several tools to help me along with the study of these topics, including two web pages that I wanted to share.

One of the biggest things that was drilled into my head during Matrix Algebra was Gaussian Elimination, or Guass-Jordan elimination. I don't think I'll ever forget the algorithm (although my professor did eventually convinced me that LU-factorization was the preferred method, Gaussian still holds a special place in my heart =P). While learning it using the various Elementary-Row operations, however, I constantly made small arithmatic errors. Ever since I was a child, even if I fully understood a mathematical concept, these errors often annoyed me as I was too busy focusing on the big picture. Anyway, the following tool below allows you to type in a matrix and each row operation one-at-a-time so that you can check your work for errors. It even allows you to fully reduce a reducable matrix so that you can see if your final result is correct:

Matrix Calcuations with Elementary Row-Operations
http://people.hofstra.edu/stefan_waner/RealWorld/tutorialsf1/scriptpivot2.html

The second tool is also very useful. It allows you to input a matrix and perform several calcuations on it such as finding it's inverse, multiplying it with another, or finding the determinant. Again, I mostly used these tools to help me error check my work when I knew my method was correct but had small arithmetic errors.

Matrix operation tool:
http://interactive-mathvision.com/mck/LinearAlgebra/JPaisMatrixMult04/classes/JPaisMatrixMult04.html


For anyone out there studying these topics, either for Computer Science, Matematics, or just pure fun, I hope you find these links useful.

Have a good day!

Sunday, January 22, 2012

Skype webcam tip on Ubuntu 10.04

Happy Sunday!

I was messing around with Skype on Ubuntu this morning and realized my webcam didn't produce any video for Skype! I did a little research and got it working and wanted to share the tip.

Note that my webcam *did* work with the "cheese" application. If yours does not, you may need to do some additional research.

The issue seems to be that my webcam is only supported on V4L2 (That's Video-For-Linux-Two), not V4L (Video-For-Linux). Apparently Skype by default only supports V4L.

I found this out with the gstreamer-properties utility (use the video tab).

But, it turns out there is a shared library you can preload with skype which will allow it to use this webcam.

For testing purposes, we're going to run skype from the command line, so fire up a terminal!

You can run skype with the "skype" command, no strange magic there.

To load a separate shared library, we use the "LD_PRELOAD" environment variable.

(Warning: Background ahead)

Linux executables make use of something called dynamically linked libraries. These are often called shared objects or "SO"'s. Not all of the code the executable uses is in the executable itself, for code reuse, we can put it in common libraries that multiple applications share.

When the application is build, it usually specifies what shared libraries it wants to use. When the application is run, the OS will know what libraries to provide it (try it yourself, the "ldd" tools shows you the shared libraries, e.g. ldd /usr/bin/skype).

When the OS goes to look for the shared libraries, it looks in the default location. But, you can over-rule this if you want to using the "LD_PRELOAD" environement variable.

(Background done)

So, to make skype use the webcam, we're going to modify how it's run. Instead of just running the skype command, try this:

32-bit Ubuntu: env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
64-bit Ubuntu: env LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype

After that, go into the Skype webcam settings and give it a test! Hopefully you'll see your picture. You can also try making a few calls and seeing if it's handled properly.

If it works for you, make it a permanent change by right clicking on the Ubuntu-menu and saying "Edit menu". Find the skype entry, and modify the "Command" (under Properties") to have the environment preload variable set.

After that, run Skype from the menu as usual and hopefully your video works!

To be fair, it's still not the best picture in the world. The lighting goes from dark to washed out periodically and fellow Skypers have told me my video is choppy (even when theirs is smooth on my end). Not sure if there's anything I can do about this on my end yet (the web cam was pretty cheap). Here's hoping you get better picture.

Best of luck!

References:

https://wiki.ubuntu.com/SkypeWebCams
http://ubuntuforums.org/archive/index.php/t-914952.html