Archive for August, 2007

Firefox: Web Page Printing Problems

Monday, August 27th, 2007

I had a page recently that would just not print properly in Firefox, even though IE 6 and 7 were printing it correctly. When I went to print-preview FF would tell me that there are 3-4 pages of content to be printed. However once you send the page to the printer, only a single sheet of paper would come out, with some overlapped text on the bottom. It took me a while to figure out what was happening. It turns out that FF doesn’t like absolute positioning. In my CSS I had something like:

#sidebar {
	position: absolute;
	width: 200px;
}
 
#content {
	margin-left: 200px;
	float: left;
}

The content was a big div that essentially held all the text that was to be printed. In my print.css style sheet I decided to hide the sidebar like this:

#sidebar {
	display: none;
	visibility: hidden;
}

Apparently this was not enough. I tweaked the CCS for a little bit and came up with the following solution:

#sidebar {
	position: static;
	display: none;
	visibility: hidden;
}
 
#content {
	position: static;
}

For some reason, when I only specified static positioning for the sidebar, it would still print everything on a single page. So if you are getting similar problem, explicitly define all the elements you want to print as having a static positioning. Absolute positioning of even a single element will mess up printing for all the other non-top-level elements on the page for some reason.

Random Sunday Mix

Sunday, August 26th, 2007

Here is some more craziness for the random Sunday mix:

  • Evil Monkeys Raep Kenyan Villagers - best story evar. Apparently a horde of super monkeys is sexually abusing Kenyan villagers, and stealing their food. I don’t care if it’s true, because it is awesome! Evil Raep Monkeys FTW!
  • Communist China outlaws reincarnation - ah, the bizarre absurdities of a communist regime. Remember kids - living in a communist country is like playing Paranoia - just more real, and you don’t get to create a new character when you die.
  • There is a gaping hole in my universe - scientists discover a gaping hole devoid of all matter or anti-matter. What is in there? No one knows. My guess is that someone divided by zero, or measured the exact weight of the Higgs boson over there.
  • Baloon Tower Defense - (flash game) combines the best parts of the ballon game and tower defense!
  • Paint-ball Game - (flash game) paint lines to lead the ball to the target
  • Dots Game - (flash game) same game as this, but done in flash.

Enjoy!

Superbad

Saturday, August 25th, 2007

It’s Saturday, so it means it’s time for a review! This time it’s not anime though so don’t run away. mrgreen

Superbad

Funniest movie of the summer

I went to see Superbad with high expectations. It was highly recommended, highly rated, and everyone was raving about it for like a week now. This is usually a recipe for disappointment, as few movies ever live up to the hype that surrounds them. But it wasn’t. Surprisingly Superbad was as funny as everyone was making it to be. So let me join the chorus of voices saying: if you haven’t seen the movie yet, go see it today. You are missing out.

Superbad

This is one of these movies that you probably should see twice or three times because you are laughing so hard missing half of the lines. A lot of the humor in this movie is delivered via the snappy, witty profanity filled dialog. It is reminiscent of the “40 Year Old Virgin” style irreverent banter but more filthy, absurd and overflowing with clever, and very graphic and often innovative one liners, and expressions. All the actors deliver these lines with impeccable timing.

Superbad

Michael Crea - of the Arrested Development fame (and most recognizable of the 3 protagonists) is funny, but he was almost upstaged by his co-stars Jonah Hill and Christopher Mintz-Plasse. Crea is essentially playing his old character, George Michael again but this time less quirky, and more normal in a way. He is funniest when playing a straight man to Hills’s irreverent, sex obsessed, filthy mouthed performance. Mintz-Plasse on the other hand, generates pure awesomeness when paired up with the misfit cops played by Seth Rogen and Bill Hader. In fact, McLovin is now an internet meme. Or so I’ve heard at least.

McLovin

Don’t think this movie is just a gag reel, or a stream of loosely connected dialog based skits. The plot, while not very complicated is tightly scripted and delivers a lot of situational comedy as well. The story essentially follows the characters of Crea, Hill and Mintz-Plasse - high school geeks, who try to get to buy booze and get to the only house party they were ever invited too - and possibly their only chance to get laid before college. Unfortunately at every step something goes wrong - and they end up having series of misadventures leading them to weird and unexpected places. Sounds familiar? Yes, this is an old and tried setup - but in Superbad it was executed flawlessly.

Superbad

How do you describe the humor of this movie? I think writers Seth Rogen and Evan Goldberg are making their own unique brand here. Take the general theme and topic matter from the first American Pie, throw in some dorky awkwardness of Napoleon Dynamite caliber, mix it with the 40 Year old Virgin style of delivery and a lot of original humor and you get Superbad.

Superbad

I truly think that this is the new cult summer high school teen movie. Superbad is the new American Pie - as filthy, irreverent and goofy, and equally as funny. And possibly even hitting closer to home, because while the characters of American Pie were all moderately popular and liked, the protagonists of Superbad are all miserable dorks. And let’s face it - most of us were probably friends with a “McLovin” rather than with a “Stiffler” back in high school.

My rating: 5.0 stars
*****

Seriously, go see that movie! I haven’t LOL’d so hard in ages.

Biggest Regex In The Word

Friday, August 24th, 2007

There are two common pattern matching problems that appear simple on the surface, but are very complex if you think about them. These are matching emails and URI’s in free form text. Everyone wrote a URL or an email validation script at one point or another. And I’m willing to bet that 90% of these validation scripts out there are just plain wrong.

The URI matching problem was definitively solved sometime in 1999 by a perl script that generated the ultimate regex to catch all legal URI’s as specified in RFC’s. What is the end result?

Here it is in all of it’s unholy, unreadable glory: the 7.4Kb regex of doom. It appears that you need exactly 7579 characters to pattern match every possible legal url out there. Or possibly even more because this one doesn’t actually account for https:// addresses. And you thought this was an easy issue that could be solved by a one liner. Shame on you!

In all fairness, how often do we really need the regex of doom though? In most cases (not all mind you) something as simple as “give me all strings that start with http:// and are delimited by spaces on both sides” will work almost as well, and probably much faster.

Let’s face it. Who wants to have something like that sitting in their codebase? You can’t read it, you can’t verify that it works via code inspection, and generating the regex from scratch using the perl script included on the linked page, is probably the only way you can maintain it. Trying to modify it by hand is just asking for a one way trip to Painsville, NJ (that’s the fabled fictional town that invated brain pain if you didn’t know).

via GDR

Mount Remote Drives on KDE Startup With a Zenity Dialog

Thursday, August 23rd, 2007

I use Kubuntu on my laptop. I noticed that wherever I go, I usually end up mounting some windows shares or remote drives. I have 5 or 6 entries in fstab but I don’t have them auto mounting at startup. Why? Because it’s a laptop. Sometimes I use it at home, sometimes I use it at school, and sometimes I use it at work. And depending on where I am at the moment different drives need to be mounted.

Most of the time these shares will get mounted as I access them with KDE apps (thank you kio slaves!) but some of my perl scripts require this or that share to be mounted to run. And I habitually forget to mount stuff every morning, and don’t realize it until some cron job starts spewing errors. So I wrote myself a simple script that will prompt me to mount my drives at startup. I used zenity to create a nice looking GUI dialog:

#!/bin/bash
 
l=$(cat ~/.mountme | xargs)
input=$(zenity --list --checklist --column "Mount" --column "FS" $l --separator=" ")
 
retval=$?
 
case $retval in
	0)
		array=($input)
		for i in ${array[@]}; do mount $i; done
		;;
	1)
		exit;;
esac

The scrupt makes some assumptions. First one is that you have file called .mountme in your home directory. This file should contain annotated list of all the filesy stems you want to show up in your dialog box. Mine looks like this:

TRUE //dc01/Public
TRUE //dc01/Private/maciak
FALSE //dc02/Share
FALSE //elrond/Share
FALSE //eoran/Shared
FALSE //grendel/Share

Each line should consist of two words. First word should be a TRUE/FALSE statement. Each line annotated with TRUE will show up as pre-checked in the zenity dialog. Lines annotated with FALSE will be un-checked.

The second word on the line should be the actual path to the remote file system you want to mount, as it appears in your fstab. Each line has to have a corresponding fstab entry. Finally, watch out for spaces in the paths - they will break stuff.

The script will read in this file, flatten it out using xargs and pass it to zenity as one of the arguments. It will produce a dialog like this:

Zenity Mount Script

The output of zenity will be a space separated lists of paths to be mounted. I plugged it into array and then use a loop to mount each of them in succession.

The only thing left was to make this dialog appear every time I log into KDE. To do this you have to create a small .desktop file in your ~/.kde/Autostart/ directory. I called mine remotemount.desktop:

[Desktop Entry]
Exec=~/bin/remotemount
Name=RemoteMount
Type=Application
X-KDE-StartupNotify=false
X-KDE-autostart-phase=2

The Exec line is the important one. It specifies the path to your script. I have it in ~/bin. The two X-KDE-autostart-phase variable tells KDE to wait until everything else loads before launching this app. It doesn’t really make sense to have this dialog pop-up before for example my Kmail and assorted apps like Kgpg and etc…

Is this a perfect solution? Of course not, but it works. Why don’t I parse the fstab directly? I could but it would mean more scripting. I like to keep things simple.