Archive for September, 2007

new posts popup

September 15th, 2007

This is a feature I've wanted to have for a long time, but until now I didn't know how to realize it. I wanted to have some kind of a notification area for new events on the blog, so that a returning visitor could immediately see what has changed since the last visit. And I definitely didn't want it on the sidebar, it had to be above the fold.

So the concept was in the back of my head for months, but I couldn't figure out how to make it look good. Then I came up with the idea of making it a popup window. Not a browser window, of course, just a layer that would show if there had been new events. Otherwise it wouldn't show up. Yes, that sounds like something. So with some digging and research, a bit of hacking and lots of debugging, here is the final result.

new_posts_overlay_ss.png

The window conveys quite a lot of information. It lists the three posts last to be published (or commented on). This way you have new posts and new comments in the same place. In the screenshot, the top entry is a post made recently. The bottom two are older posts that have received new comments.

In terms of appearance, I wanted to make the window active only if the user is using it, so on page load it is made partially transparent, onMouseOver it becomes more opaque, and onMouseOut it becomes more transparent again.

For a demo.. you have this blog. After 15 minutes of inactivity your session will expire and the window will go away. To bring it back delete your cookies from this domain (or use a different browser) and it reappears. The session is handled entirely with cookies, so for visitors who don't accept cookies, the window will always appear as if this were their first visit.

Compatibility

The opacity property is new in CSS3 and isn't uniformly supported (yet). I've tested the plugin with the following browsers.

  • Firefox 1.0.1, 2.0.0.6
  • Opera 8.0, 9.23
  • Safari 3.0.3
  • IE 5.0, 6.0, 7.0
  • Konqueror 3.5.7 (opacity support is rumored to be on the way)
  • Netscape 6.0.1, 7.0, 8.0.2, 9.0b3

In addition, there's a rather pesky layout bug in IE <7.0 that causes the height of the window (which is floating above the other content) to be added to the top of the page. If you fix it, please send a patch. :)

Also, I tried very hard to make sure it only consumes one query, which unfortunately made it very complicated. If you rewrite it in simpler terms, send a patch. :)

Required MySQL version: 4.1+
How to use

Download, unzip, install, append the css to your styles. :cap:

UPDATE: Added Netscape.

UPDATE2: MySQL compatibility.

sshfs: easy to access remote ssh locations

September 13th, 2007

If you're a heavy ssh user, you already know about scp and rsync+ssh, but even that gets tedious when you're using the same remote location a lot.

A solution to this is KDE's fish:// kioslave, which lets you browse the remote path in konqueror much like you do any other. The drawback is that it's not an actual filesystem, so if you open a video, you'll have to wait before konqueror copies the whole file to a temporary local path before it will open it. (The same goes for smb:// samba shares, and probably all kioslaves.)

I've been using fish:// a lot, but lately it's become very flaky on me, and I don't know why, because the terse error messages don't explain anything. But I also miss how it's less convenient than nfs, which *is* a real filesystem (albeit one that is a pita to configure properly).

But there is another option. (Oh who am I kidding? This is linux, there are probably hundreds of options. :D ) If you have a remote location you need to access a lot, you could try sshfs. As the name implies, the protocol is still ssh (so the traffic is encrypted), but the interface is that of a filesystem. And it's based on fuse (the user level filesystem layer), so no messing with the kernel necessary.

Here's what you do

emerge sshfs-fuse
echo "fuse" >> /etc/modules.autoload.d/kernel-2.6
modprobe fuse

That should make sure the fuse module is loaded on boot. Now to mount and unmount a remote path:

sshfs host:/path /mount/point
fusermount -u /mount/point

Or, to make it even easier.. save this in /usr/local/bin.

MOUNT_POINT=/mount/point
HOST=host
MOUNT_PATH=/path/on/host

if [ ! -d $MOUNT_POINT ]; then
	echo "mount point $MOUNT_POINT missing"; exit 1
fi

if mount | grep $MOUNT_POINT; then
	echo "umounting..."
	fusermount -u $MOUNT_POINT
else
	echo "mounting..."
	sshfs -C -o transform_symlinks -o Cipher="blowfish" $HOST:$MOUNT_PATH $MOUNT_POINT
fi

tv shopping is here to stay

September 12th, 2007

I used to watch a lot of tv when I was a kid. One thing that was very common was for stations (cable stations especially) to broadcast tv shopping in the off hours. I recall TV3 did this a lot, they called it "teleshop" I think.

What strikes me is that not only has this home shopping gig not worn out yet, it hasn't even changed at all from the early 90s. And that's a bit unusual, because so many practices have been forced to evolve or become deprecated. But this tv shopping has survived. Why is this? Do they actually sell those products? Hard to believe, isn't it? I've never bought anything. In fact the very "exclusivity" of the products, how you "can't buy them in any store" raises a serious credibility issue with me.

And the funny thing is they still sell the same things! In the 80s/90s there was a well established stereotype, at least in Norway, about vacuum cleaner salesmen who would come to your house and try to demonstrate the product for you. This was a solid reference for jokes and humor programs. A bit I've seen many times is a person answering the door and before the caller has a chance to say what they want you say "no, I don't want a vacuum cleaner" and slam the door.

And yes, in the 90s they sold vacuum cleaners on tv. This is how it would go. First of all, the studio looks like one of those kitchens they used to give away for prizes in game shows. It's clean, it's very big, no dishes or kitchen ware in sight. There are two hosts. One is the product expert, who is going to demonstrate the product. The other is, usually a woman, the person who is going to exclaim amazement at every detail. They start off with a side-by-side comparison of the product on sale with some other "typical" product. So they make a mess on the floor, and the "expert" tells the woman to clean it up . She tries, and, of course, fails. Then the expert uses *his* product and it goes very well. She's very impressed. Then he starts enumerating the virtues of the better vacuum cleaner, to her wide eyed disbelief.

After that's done, he launches into a sales presentation. This is how much it costs, but we're giving everyone the special discount (which is perpetual) and so you will only pay this much. Plus shipping. And we're giving you these bonus items just because we're nice. And if you order within 10 days you'll get a complimentary cheaper-product-also-sold-on-tv. You can't beat that deal.

Then comes the black and white sequence. A woman (a different one) is shown vacuuming and she's holding a hand to her back, which means her back hurts. She's also doing a poor job of cleaning, as she misses spots here and there. This is you. It's shown in black and white to tell you that what you're doing is arcane and obsolete. And silly. Seriously, wisen up and buy this product. And now comes a repeat of the sales pitch again, without any people this time, just filming the vacuum cleaner, all the extensions you can put on it, and the special price. And the bonus gifts. And finally the list of countries and telephone numbers to call.

And if you turn on the tv today in the off hours, you'll see very same thing. The same kind of studio, the same people, the same lines, the same sequence of scenes. It's like archival footage. And they *still* sell vacuum cleaners. Now they've abandoned vacuum cleaners in the traditional sense, so they sell mops and things that clean with steam and what have you, but it's the same thing.

But how much can a vacuum cleaner really do for you? It makes cleaning easier, but it won't make you happy, will it? I like the products that make you a better person. Like pills that give you more energy, and dietary products, and skin care. It only takes a clever person to make a better mop, but it takes a doctor to examine and approve a chemical that's going to be sold to the public. If you're a doctor you can be the star on tv shopping. They bring you out, you get applause and admiration. Then you have to explain how the lotion works and why it's so fantastic. Be careful to inject some pseudo scientific terms to sound like a credible scientist. And you have to wear a white lab coat and a stethoscope, like you just came off duty at work, because who in their right mind would believe a real doctor would come on a program like this?

head on collision with a bicycle

September 11th, 2007

I had a rather unfortunate happening today. I was leaving the supermarket, which is on this narrow, but busy street (too narrow for its needs, as the case often is here). I had reclaimed my bicycle from the over crowded bike stand and I was about to get on it. I had a loaf of bread in my left hand which wouldn't fit in my backpack, so my movements were a bit impaired.

Now this street is only wide enough to allow one motor vehicle to drive, so if there is a car coming in the opposite direction, you have to basically look for a space to squeeze in so you can pass each other. And there's normally quite a few cars on the street. On both sides you have these concrete poles every 2m to draw out a narrow sidewalk for pedestrians (but which is level with the street).

As I was making my way out, there was a van parked right up against the bike stand, which blocked my view in the direction I was going. On this street that's quite common. So just as I mount my bike and push off, I see around the van and there are two bikers coming at me at 3m away. Oops. I was too far out to pull back in behind the van, and it was too late to speed off as well, so basically I was stuck. Terrible timing. A woman rode the first bike, probably 40ish, the other biker was a bit behind. She hit the brakes and stopped just so her front tyre lightly bumped into my front wheel. An inexcusable traffic blunder on my part.

She came to a full stop, I was relieved. The other bike just behind her also stopped. I look up at her. She gives me a stern, but somewhat understanding glance. Says nothing. I say "sorry" and take off. This is the way people are here. Calm. Patient. They've figured out that getting mad doesn't do you any good. I forced her to come to a complete stop. Very annoying. But ultimately harmless, and nothing to get all riled up over.

But these are the kinds of blind spots we have. On my bike I maneuver just fine. Two minutes after the incident I caused a kid a bit of mild panic when he thought I was making a turn just in front of him and he was going straight. Of course I could see I would make my turn well before he could crash into me, so there was no risk. But these are the things we don't think about. On the bike, fine. But while getting on the bike with a heavy backpack and one hand not fully available, reaction time increases.

recover lost stuff from memory

September 10th, 2007

This has happened to you before. I'm painstakingly typing a long email on gmail and I'm not sure that I should send it yet, cause it feels like I'm forgetting to mention something. So I want to save it as a draft so I can finish it later. Somehow I hit Discard instead. :doh: Gmail flashes the notice your message has been discarded, but I don't usually read those messages, so I navigate away from the page, and *just* as I click the link the meaning of the message dawns on me. Shit. Now it's too late to undo the action. Son of a. :fero: :wallbang:

Okay, relax, perhaps all is not lost. A couple of weeks ago I went over how you can find stuff on disk by searching the raw data. The same *can* be done with memory. See, just because my message is gone and gmail doesn't display it anymore doesn't mean it's not still possibly somewhere in memory. It just isn't being displayed anywhere.

There are two ways to access physical memory. The two interfaces are /dev/mem and /proc/kcore. As root, you can read from these. (However, if you try writing to them you'll probably mess up your system.) They are not identical, and it seems that /dev/mem doesn't let me access memory above 896MB (High Memory Support in linux kernel parlance), so just use /proc/kcore.

To find that lost message in raw memory, it helps if you can remember a phrase from it. Then do

cat /proc/kcore | grep -a --color -C1 "a phrase from it"

This will search the memory treating it like text, and highlight the phrase when it's found. It also prints "one line" above and below the line where the text was found (although considering this is binary data, the notion of "a line" is somewhat diffuse). Anyway, you probably now have enough context to get your whole message. If not, increase it to -C2 and so on.

This way I was able to recover my message. :party:

In principle, you can also recover lost files this way, provided they are still in memory, but searching for binary data within binary data is a bit trickier, so it would take a clever approach.