Mastodon

Mysql tables – calculating size on disk.

Today I was getting ready to move an application at work over to a staging app that we set up at Heroku. Not wanting to absorb any extra charges for loading up a copy of the entire production database I figured I would empty out the tables that where taking up the most disk space. For that I had to query the information_schema table and add the size of the table to the size of the indexes. All the values are in bytes you have to do a little multiplication to get it displaying in something meaningful to a human like megabytes. Since this is a neat trick that I will likely end up using again I thought I would put it up here as well. Here is the query:

mysql> select table_name, round(((data_length + index_length) / (1024*1024)),2) as “size in megs” from information_schema.tables where table_schema = “myapp_development”;
+———————-+————–+
| table_name           | size in megs |
+———————-+————–+
| messages             |         0.11 |
| organisations        |         0.02 |
| rewards              |         0.02 |
| schema_migrations    |         0.02 |
| selections           |         0.02 |
| senders              |         0.02 |
| sessions             |         0.64 |
| summaries            |        15.52 |
| taggings             |         0.05 |
| tags                 |         0.02 |
| transactions         |         0.03 |
+———————-+————–+
11 rows in set (0.13 sec)

Change the where clause to look for the database you want or remove it completely to see all of them.

Connecting to a web server on a VirtualBox guest.

One of the things I did frequently when using VMware is connect from my host (usually Windows) to my guest (usually Linux). The fact that I don’t really remember how I set that up seems to indicate that it was pretty trivial or just worked “out of the box” (which is a funny thing to say about a VM). After happily using Virtualbox for a while now, the need to connect from host to guest has inevitably reared its head and I was a little surprised that there does not seem to be a straight forward way to do that. Turning as one usually does in such a situation, to Google, and since it was a bit of a fiddle I thought I would scrawl it down here.

The Windows version:

Open the Windows command line and navigate to

C:\Program Files\Sun\VirtualBox>

There are three commands that need to be issued. The command is a little daunting at first glance so here are the important parts:

“karmic” is the name I gave my VM when I created it.

“pcnet” refers to the PCNet virtual network card that I am using in my VM which you can select in your network settings. e1000 is also valid if thats what you’re using.

“railsdev” is the name that will be given to the port forwarding configuration that these commands set up.

The rest should be fairly self explanatory:

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/Protocol” TCP

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/GuestPort” 3000

C:\Program Files\Sun\VirtualBox>VBoxManage.exe setextradata “karmic” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/railsdev/HostPort” 3000

On *nix things are roughly the same, except that the default network card is the Intel Pro/1000 instead of the pcnet you can see above. Consequently you will need to do something like this:

vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/Protocol” TCP
vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/GuestPort” 80
vboxmanage setextradata “mavrick_server” “VBoxInternal/Devices/e1000/0/LUN#0/Config/rails/HostPort” 8080

You can see that here I am forwarding port 8080 on the host to port 80 on the guest and naming the forwarding configuration “rails”. Also notice the “e1000” that identifies the network card. Other things to note are that the quotes around the VM name (“mavrick_server” in the above example) MUST be there and they must be regular quotes not angled ones like  “ or ”. Angled quotes will be assumed to be part of the machine name and throw an error like this:

ERROR: Could not find a registered machine named ‘“webserver”’

Replace the quotes with proper ones and you should be good.

Happy forwarding!

Ditch VMware. Don’t look back.

After working in Ubuntu running in VMware for my Ruby on Rails development over the last few months I have come to the realization that VMware is really annoying.

First, I am tired of playing Russian roulette with their poorly chosen keyboard shortcuts. I have inadvertently rebooted the whole VM with a Control+R intended for the Firefox inside the VM more times than I care to admit. Much wailing and gnashing of teeth followed.

Equally poorly planned, but less damaging is their co-opting of the standard undo shortcut Control+Z. The fine folks at VMware decided to use that to suspend the VM which you will eventually discover after flipping between the VM and the host OS and then trying to undo something…

While the fact that switching between the guest and the host OS a few times makes their network connection crash and their seeming inability to make their shared folders work with Ubuntu in any sane way (hopefully fixed now…), both rank on my list of frustrations, the worst by far is the mouse.

I was hoping to get the mouse working better once the VMware tools were installed but that never ended up being the case. For whatever reason after the install I still had to explicitly click in the VM to get it to grab the mouse (or press Control+G… Don’t get me started…) and Control+ALT to release it. I suppose I might have been able to figure out some sort of fix for that had it really caused some acute aggravation, but for the most part it remained as a low level annoyance.

The acute aggravation came from the fact that VMware assumes that anytime you move your mouse anywhere near the top of the screen that you would like to jump out of the VM and access their menu.

Without fail this completely screws up the mouse and I have to try to click several times inside the VM to convince it to grab the mouse again.

Well I am pleased to tell you there is a fix for all of that. Virtualbox. No stupid shortcuts, is actually capable of running compiz-fusion, shared folders that actually work (sudo mount -t vboxsf sharename /mnt/share is all thats needed after you set up your share, exactly what a *nix user would expect), and a single key (the control button on the right side of the keyboard) that releases you from the VM. As a bonus it even seems faster than VMware. The best part is that you don’t have to go trawling on piratebay to get a copy, since it is open source and freely available from their website.

Ditch VMware. Don’t look back.

Holding the line

“On average, Office users spend more 1-on-1 time with Office than with their spouse”

This (unfortunately unsourced) gem comes from Jensen Harris’s presentation on the creation of the new “ribbon” based interface in Office 2007. While I think that quote probably says quite a bit about what is wrong with the world, it also tells you that how humans interact with computers is a very big deal. Ones relationship with the tools of their trade in any line of work is going to be necessarily intense and emotional. As software becomes more of a requirement than an option in most lines of work, companies like Microsoft and Apple spend staggering amounts of money studying people interacting with their software.  “Hundreds of millions” were supposedly spent on developing the new interface for Office 2007 according to Harris.

For all the fanfare, the ribbon is just the latest reshuffling of the same windows, icons, menus and folders that were developed at Xerox PARC in the early seventies. The problems in interface design today are largely to do with programs so rich with features that their menus are beginning to look like a rats nest of pop-ups, fly-outs, toolbars, menus, sub-menus and sub-sub-menus (and often sub- sub-sub-menus). Harris says that the research his team has done showed that users felt a loss of control and a loss of a sense of mastery.

I can’t help but wonder if some of these feelings are common to all GUI programs, not just Office. Most people seem to think of the Command Line Interface as the absence of an interface, and are terrified by the monochrome starkness and requirement that at least a few commands are known before the user can start. The first GUI based personal computers (Apple’s Lisa and Macintosh) were a rejection of the CLI and a way to open up computing to a wider audience.

“No command line interface was available on the Macintosh; you talked to it with the mouse, or not at all. This was a statement of sorts, a credential of revolutionary purity. It seemed that the designers of the Mac intended to sweep Command Line Interfaces into the dustbin of history.”    ~~ Neal Stephenson – In the Beginning was the Command Line

The problem was that to make these new GUI’s understandable to users the developers created the now ubiquitous “desktop metaphor”. Users would know what to do in this new virtual world because it would mirror aspects of the physical world. Everything in it would be presented to them as objects on a virtual desktop with folders to organize. However users don’t experience their desktops as a metaphor, for them they are real:

“Back in 1984, explanations of the original Mac interface to users who had never seen a GUI before inevitably included an explanation of icons that went something like this: “This icon represents your file on disk.” But to the surprise of many, users very quickly discarded any semblance of indirection. This icon is my file. My file is this icon. One is not a “representation of” or an “interface to” the other. Such relationships were foreign to most people, and constituted unnecessary mental baggage when there was a much more simple and direct connection to what they knew of reality.” ~~John Siracusa – About the Finder…

Computer use in GUI environments is exploratory, tasks are completed by hunting down menu items and unearthing option dialogs, navigating an environment, like a rat navigating a maze for a piece of cheese, that, for them, might as well be real. The reward at the end of the process might be empowering, but the path to the reward is not.

Command line interfaces offer a very different experience for the user. In many cases users can accomplish the same task but the experience of the path to that end result is very different. The CLI sets up a different kind of relationship with the user, one that also echoes the users real world experience; a master/slave relationship. Because of this, working at the command line is empowering: you issue a command, the computer does it. If I type “aptitude install firefox”, aptitude (The program Ubuntu uses to add and remove programs) installs Firefox. Commands like “su” and “sudo” only reinforce the perception of the machines subservience, allowing you to override even its objections. It’s a very different feeling than fishing through a folder tree trying to find “setup.exe” so you can double click on it and then click “next” a half dozen times.

Words like “power” and “control” tend to come up a fair bit in where the command line is discussed, but although there are plenty of good things to say about GUI’s those are not the first things that spring to mind when describing your feelings about using one. Though there are some that dismiss use of the command line as a major usability roadblock, hopefully as the use of GNU/Linux based systems grows, more people will recognise that it is an efficient and empowering way to get things done. When that happens even normal people will find XKCD funny…

VMware tools and shared folders in Unbuntu 9.04 Jaunty

The latest version of Ubuntu does indeed have some sexy new features, new notifications, eucalyptus cloud support. All around a pretty awesome release. In what I will kindly call a fit of nievete, I decided to upgrade the my VM that I have been using for web development. Although the upgrade from 8.10 to 9.04 went smoothly, the reinstall of VMware tools failed leaving me without any shared folders. So after a little profanity and a lot of googling I thought I would share what got my shared folders back up and running.

First you will want to make sure that you have the headers and other stuff so VMware tools has what it needs to compile everything:

sudo apt-get install linux-headers-`uname -r` build-essential

If you are not running VMware 6.5.2 you will likely be asked where your header files are. 6.5.2 added “experimental” support for Jaunty so it already knows where to look. I was running the server version so my headers were in/lib/modules/2.6.28-11-server/build/include.

If you are running the desktop version you can probably find them here: /lib/modules/2.6.28-11/build/include

What is the location of the directory of C header files that match your running
kernel? [/lib/modules/2.6.28-11-server/build/include]

The first time I tried to install VMware tools, two of the modules failed. I upgraded to version 6.5.2 build 156735 and tried it again and that time only the HGFS module failed with the following error:

CC [M]  /tmp/vmware-config3/vmhgfs-only/page.o
/tmp/vmware-config3/vmhgfs-only/page.c: In function âHgfsDoWriteBeginâ:
/tmp/vmware-config3/vmhgfs-only/page.c:763: warning: ISO C90 forbids mixed declarations and code
/tmp/vmware-config3/vmhgfs-only/page.c: In function âHgfsWriteBeginâ:
/tmp/vmware-config3/vmhgfs-only/page.c:867: error: implicit declaration of function â__grab_cache_pageâ
/tmp/vmware-config3/vmhgfs-only/page.c:867: warning: assignment makes pointer from integer without a cast
make[2]: *** [/tmp/vmware-config3/vmhgfs-only/page.o] Error 1
make[1]: *** [_module_/tmp/vmware-config3/vmhgfs-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.28-11-server’
make: *** [vmhgfs.ko] Error 2
make: Leaving directory `/tmp/vmware-config3/vmhgfs-only’
Unable to build the vmhgfs module.

Fortunately some googling turned up this clever fellow who tells you how to fix the problematic line of code. I did it and am happy to report that it works. Just to make everybody’s lives a little easier I thought I would make the patched code available to save people some time and bother.  You can see the link to it in the code below. So without further ado, here is what you need to do to fix the HGFS. You will need the vmware-tools-distrib folder. I had it laying around from my previous install attempts.

mike@ubuntu:~$ cd vmware-tools-distrib/lib/modules/source/

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ rm vmhgfs.tar
rm: remove write-protected regular file `vmhgfs.tar’? y

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ wget http://www.dexterchief.com/vmhgfs.tar
–2009-05-03 00:18:25–  http://www.dexterchief.com/vmhgfs.tar
Resolving http://www.dexterchief.com… 67.205.50.232
Connecting to http://www.dexterchief.com|67.205.50.232|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 901120 (880K) [application/x-tar]
Saving to: `vmhgfs.tar’

100%[======================================>] 901,120      176K/s   in 5.8s

2009-05-03 00:18:32 (152 KB/s) – `vmhgfs.tar’ saved [901120/901120]

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ ls -al vmhgfs.tar
-rw-r–r– 1 mike mike 901120 2009-05-02 23:26 vmhgfs.tar

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ chmod 444 vmhgfs.tar

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ ls -al vmhgfs.tar
-r–r–r– 1 mike mike 901120 2009-05-02 23:26 vmhgfs.tar

Now that the permissions are set correctly just rerun the install script:

mike@ubuntu:~/vmware-tools-distrib/lib/modules/source$ sudo ./vmware-install.pl

I hope that ends up being useful for somebody.

All I want from Facebook…

The way Facebook looks at its users is that each one is a source of news. A friend request in Facebook-land is really a bi-directional subscription to each others news feeds. This is a cool way to look at the world and the result is a news feed for each of the users that only includes items that users have explicitly opted-into receiving. The other side effect is that the company is now worth 15 Billion dollars.

Sadly the Facebook applications seem to be able to ride roughshod over that opt-in philosophy and send events to users news feeds even when that user does not have the application installed. As a result my news feed now looks like this:

So and so got another likeness match. Are you like me?

This HOTorNOT user wants to meet so and so! What do you think of him? Click here so you can meet HOTTIES too ;)

Somebody scored points for Somebody-else in TV Show Trivia. Somebody just scored 120 points for Somebody-else’s team. Somebody-else’s team now has 17770 points and is a Ace. Play TV Trivia >>

Someone has received a new FunWall post!
Click here to see Someone’s photo!

So and so’s Zombie Mogul regulated on Somebody’s Ancient Vampire! Victory dances ensued. Huzzah!

My news feed is supposed to be the heart of Facebook and totally relevant to me as a user. If I was interested in receiving Vampire/Pirate/Zombie/Werewolf notifications from my friends I would have installed the application. In fact I specifically avoided installing the application because I hate them. Having my feed hijacked by applications I don’t even have installed is pretty bothersome. I know what I will be hoping for, for Christmas…

Facebook Application Sliders

Haunted by Flash 7

For some reason my version of Firefox seems to be haunted by the ghost of Flash 7. I have installed Flash 9 several times now but today when I tried to watch a video on http://www.expertvillage.com I saw nothing but a black square. Thinking it was loading I gave it a few seconds and when nothing had changed a right click confirmed my worst fears as the text “about flash player 7” appeared at the bottom of the menu.

What does it want with me? Is it trying to tell me something?

A little googleing revealed that /home/username/.mozilla/plugins is not the only place that Firefox looks for plugins. It also keeps them in /usr/lib/firefox/plugins/

After terminating the flashplayer.xpt and libflashplayer.so files that were resident in that folder and copying in new ones freshly extracted from the tar.gz file on adobe’s site I can finally watch videos again. I think I finally exorcised the beast.

Flash 7 begone! The power of root compels you!

Ubuntu ♥’s the Nikon Coolpix S6

Nikon’s Coolpix S6 camera sure seems to have a lot going for it; WIFI, HUGE screen, nice colour and image quality and a really nice size. The only real strike against is shutter lag which means that there is a noticeable delay between pushing the button and capturing the image. This can be a real drag for capturing “the moment” in sports related situations. That said, it is still a great camera and I am still actively considering buying one.

The big question I wanted answered before I reach for my wallet is; does it work with Ubuntu?

The answer:

Ubuntu Importing Photos from Coolpix S6

It seems to think the model is an S2 but everything works perfectly. Ubuntu detects it automatically and imports without a hitch.

Binary MADNESS Part II

My professor for this course was pretty hardcore. Being an old school Bulgarian mathematician he was all about making us understand how computers work with numbers, and doing it with a paper and pencil. Since there is surprisingly little about doing this that can be found on the internets, and it is kind of neat, here is how to do it.

Manually converting to binary:

13/2 = 6 remainder = 1
6/2 = 3 remainder = 0
3/2 = 1 remainder = 1
1/2 = 0 remainder = 1

The result of the conversion is reading the remainders from bottom to top: 1101 = 13

Manually converting fractional numbers to binary:

This is a little different. You multiply by two and if it makes 1 you remove the one and continue without it. The results of the conversion are all the ones and zeros that you have been putting off to the side this time read from top to bottom. It does get a little weird as you will see, because converting things like 0.5 or 0.625 hit 0 and ends very quickly:

0.5 X 2 = 1.0 | 1
0.0 X 2 = 0.0 | 0

0.5 is 0.10 in binary

0.625 X 2 = 1.25 | 1
0.25 X 2 = 0.5 | 0
0.5 X 2 = 1.0 | 1
0.0 X 2 = 0.0 | 0

0.625 = 0.101 in binary

Converting something like 0.8 will never hit 0 and must be stopped at some arbitrary point so the computer does not get stuck in an infinite loop:

0.8 X 2 = 1.6 | 1
0.6 X 2 = 1.2 | 1
0.2 X 2 = 0.4 | 0
0.4 X 2 = 0.8 | 0
0.8 X 2 = 1.6 | 1
0.6 X 2 = 1.2 | 1
0.2 X 2 = 0.4 | 0
0.4 X 2 = 0.8 | 0
0.8 X 2 = 1.6 | 1
0.6 X 2 = 1.2 | 1
0.2 X 2 = 0.4 | 0
0.4 X 2 = 0.8 | 0

That kind truncating of values gives mathematicians Tourette’s, because it effectively means that computers are incapable of generating a (mathematically) correct answer to any question. But if you know what you are doing you can generate an answer that is correct enough for whatever you are doing.

Binary MADNESS Part I

Ok so this is more so I don’t forget it, than because I think anyone will read it or care. But on the off chance you care about this kind of thing, here is what I learned about binary:

The position of the number indicates a multipul of the base of the number system (2) the same as what we have in the human base 10 number system.
So a 1 in the ones column gives us 1: 0001
And a one in the twos column would give us two: 0010
A one in both the ones and twos column gives us three: 0011
And the columns double in value as they move left. So 0100 is four, and 1000 is eight and adding a fifth column will give us sixteen and so on.

Adding:

Adding binary numbers is pretty simple.
0+0=0
0+1=1
1+1 = 0 and carry 1 to the next column.
1+1+ a carry of one = 1 and a carry of one.

So:

0111 (aka 7)
+0111
——–
1110 (aka 14)

Subtraction:

Ok this is a little weird. Computers don’t subtract. Well they do, but they do it by adding a negative to a positive. To create the negative number, called a twos compliment, you need to flip all the bits (change all the ones to zeros and vice versa) and then add one. It sounds simple but I screw it up pretty consistently, so I was very happy to find an idiot resistant method of finding a twos compliment just in time for my final exam:

Working from right to left, ignore any zeros and find the first one. Keep it the way it is flip all the other bits like so:

0111 (aka 7)
1001 (the twos compliment of 7)

so:

1110 (aka 14)
+1001 (plus the twos compliment of 7)
——-
0111 (equals 7!)

Technically it equals 10111 but computers can only work with so many bits at a time (the newest can now do 64 bits at a time, older ones just 32). In this case we are working with 4 bit numbers so any carrys from the addition will just be dropped. So the 1 on the far left will be chopped off leaving us with the 0111.