Wonderfull New Woodstove
Monday, December 3rd, 2007We’ve been running this all weekend, heating the whole house. What a wonderful thing a woodstove is.
Popularity: 10% [?]
We’ve been running this all weekend, heating the whole house. What a wonderful thing a woodstove is.
Popularity: 10% [?]
Since my dbus post last week, I’ve been playing around more with dbus whenever I get a few minutes. The modern Linux desktop is pretty good, but with minor tweaks, you can make things even better. (all this code is now up in a mercurial repository called dbus-hackery).
Automating Inactivity
Pidgin makes sounds on every message to me, xchat makes sounds on certain key words. Without these cues, I’d never remember to go check these applications. Because I have a tendency to leave my laptop on overnight, I found that I’d often have xchat ringing away at midnight when someone was looking for me. If I forgot to mute my machine before that, it would often wake me up.
One of the programs sending signals on dbus is gnome-screensaver.
def mute()
IO.popen("aumix -vq") {|r|
r.read.scan(/(\d+)/) {|m|
@@vol = m
puts "saved volume: #{@@vol}"
break
}
}
puts "muting"
system("aumix -v 0")
end
def unmute()
puts "unmuting"
system("aumix -v #{@@vol}")
end
ss = connect_screensaver(session_bus)
ss.on_signal("ActiveChanged") {|s|
if s
mute
else
unmute
end
}
The connect will look exactly as expected from the previous look at dbus. The ActiveChanged signal outputs a single parameter, a boolean, which is true when the screensave goes active, false when the screensaver is deactivated.
Volume control on the command line is most easily done with aumix (though if you are on Ubuntu Gutsy you’ll have issues until you rebuild aumix yourself. Hopefully they’ll fix that bug soon.) A little regex fun captures the current levels to a package variable, and restores them back on unmute.
Now I’ve got global mute when the screensaver fires, restored when I return.
Better Away with Pidgin
My screensaver being locked is a pretty clear indication that I’m away, though it being unlocked isn’t a clear indication that I’m back. Especially on weekends, I pop back for a quick check of something, then the computer is put away again.
pidgin.PurpleSavedstatusSetMessage(status, "screen saver auto away")
pidgin.PurpleSavedstatusActivate(status)
end
ss.on_signal("ActiveChanged") {|s|
if s
mute
set_away(pidgin)
else
unmute
end
}
In order to set a status with a message, it has to be a saved status. To prevent growing that to infinity, I first look to see if it is defined, creating a new saved status if not. 5 is a magic number here meaning STATUS_AWAY (reference the pidgin status.h for more info). Then we set the message on that status, and activate it. A single line change on our screen saver signal adds this into play.
Keep on Hacking
One of the things I’m hoping to impress in these posts on dbus is that with a highly functional language like ruby, linking applications on a modern gnome desktop can be done even by mere mortals. Linking sound to your screen saver is something that would have required a reasonable chunk of c code. Now you can do it in 20 lines of ruby, thanks to dbus.
I’ve thought about creating some sort of extended control panel to enable the features I’ve hacked together, but the reality is the code is so small, and so simple, it seems like overkill. With code this easy, you should just jump in and hack it to your own needs.
As I keep playing with dbus, I’ll post more bits here. Twitter integration is still on my list of things to do, and maybe something I’ll even manage to get to this week.
Popularity: 25% [?]
A few weeks ago I was chatting with Dan about my one great annoyance with Pidgin: it takes up to 15 minutes to realize that it’s network connection isn’t valid any more and to automatically reconnect. With NetworkManager and dbus, this should be a reasonably simple feat. Dan got curious about this and wrote himself a python program that sets pidgin status in this way.
D-What?
A bit of background. One of the Freedesktop.org standards is d-bus:
D-Bus is a message bus system, a simple way for applications to talk to one another. In addition to interprocess communication, D-Bus helps coordinate process lifecycle; it makes it simple and reliable to code a “single instance” application or daemon, and to launch applications and daemons on demand when their services are needed.
The basic idea is that d-bus allows applications to publish interfaces that other applications on the desktop can interface with. Right now, only a few applications really support d-bus in a significant way. Fortunately, one of those is pidgin, which has an extremely rich d-bus interface.
Ruby & DBUS
Here’s a place where I know I’ll draw Dan’s ire. I’ve been on a Ruby kick recently, so my first reaction to Dan’s post was “great, I’ll have to figure out how to do this in ruby now.” It sounds like typical language bias, but I’ll try to justify it at least a little.
Right now I’m writing code on a weekly basis in 3 languages: C# (OpenSim), Java (Grad School Project), and Ruby (side web projects done in Rails). 3 languages is a lot to remain fluent in, and causes some interesting syntax errors when jumping back and forth between them. One less context switch seemed like a good idea. At some point I’ll bother writing up why ruby has seduced me, but that is for another day.
While finding python-dbus bindings are extremely straight forward, the ruby-dbus front is a little more of a wandering path. After finding a couple of abandoned efforts, I finally came to the active ruby-dbus project. Make sure to grab the latest and greatest code from there before proceeding.
Connecting to DBUS
Before I get into actually using dbus, I need to set up connections to it. There are 2 different buses, the system bus (which is shared for all users), and the session bus, which is unique per login session. Pidgin uses the session bus: it’s a user application. Network Manager uses the system bus: it’s events are system wide and affect all users.
#!/usr/bin/ruby
require “dbus”
bus = DBus::SystemBus.instance
session_bus = DBus::SessionBus.instance
# Get the Pidgin Service
pidgin_dbus = session_bus.service(“im.pidgin.purple.PurpleService”)
# Get the object from this service
pidgin = pidgin_dbus.object(“/im/pidgin/purple/PurpleObject”)
# Introspect it
pidgin.introspect
if pidgin.has_iface? “im.pidgin.purple.PurpleInterface”
pidgin.default_iface = “im.pidgin.purple.PurpleInterface”
puts “We have Pidgin interface”
end
n_dbus = bus.service(“org.freedesktop.NetworkManager”)
netman = n_dbus.object(“/org/freedesktop/NetworkManager”)
# Establish a proxy interface object for NetworkManager as it doesn’t support introspection
poi = DBus::ProxyObjectInterface.new(netman, “org.freedesktop.NetworkManager”)
Basically the pattern is clear. Get a service handle, get an object definition from that service handle, then get an interface from that object. There are 2 flavors for this, one where we’ve got introspection information, and one where we’ve got to go blind because introspection isn’t supported.
DBUS Introspection
DBUS interfaces come in 2 flavors, those that support introspection, and those that don’t. If an interface supports introspection you can get an interface definition off the dbus wire itself, otherwise you need to know the interface a priori. Pidgin supports introspection, Network Manager does not. The major short coming of the ars technica article on Pidgin and DBUS was the lack of information on using introspection to show all the other pidgin interface functions (of which there are > 600). Python dbus introspection throws an exception on my Ubuntu 7.10 environment, so it wasn’t helpful here. However, ruby, as usual, came to the rescue.

The ruby-dbus code contains an example application called gd-bus, which performs introspection on all dbus interfaces it can find, and prints them out nicely. The cheat sheet goes something like so:
M PurpleAccountsFind(in name:s, in protocol:s, out RESULT:i)
Note: the ruby interface seems to always wrap arrays around the output parameters. I have no idea why, but it’s consistent, so a few extra “[0]“s get you a long ways. If you know why, please comment.
The translation of this interface specification into ruby gives you something like this:
def recycle_pidgin(pidgin)
accounts = pidgin.PurpleAccountsGetAll
for account in accounts[0]
if pidgin.PurpleAccountIsConnected(account)[0] > 0
pidgin.PurpleAccountDisconnect(account)
end
pidgin.PurpleAccountConnect(account)
end
end
This cycles through all pidgin accounts, disconnects all the connected ones, and then attempts to connect all accounts. This is effectively what I end up doing by hand every time I switch networks with my laptop.
Bringing it all together
I now had connections to the 2 buses, and code to cycle the pidgin accounts. Last bit is actually watching for the Network Manager signal that I’ve got a new active network device.
poi.on_signal(bus, "DeviceNowActive“) {
recycle_pidgin(pidgin)
}
main = DBus::Main.new
main << bus
main.run
Network manager doesn’t support introspection. However, it does have pretty decent docs to figure out what the interface is. I’m still sad it doesn’t show up nicely in gd-bus though.
The proxy interface object sets up a signal using 2 parameters and a code block. Every time there is a DeviceNowActive signal on the system bus, I recycle pidgin. Pretty straight forward.
The last little bit is making this thing go into a loop. Ruby dbus contains it’s own main loop for just this task. I created a new main loop, tell it to watch the system bus, and then start it. And, we’re done.
The future’s so bright…
DBUS has been on my list of “I need to go figure this out” for a while. A morning of reading docs, hacking a bit, and crashing network manager a few times, and voila, you’ve got this blog post.
I’ve got lots of ideas floating around in my head now for other things that I can do with dbus to make my applications work better for me. As I bang a few of those out into code, expect to see more here about it. Pidgin is an especially target rich environment given how rich and interface they expose (nice job guys!).
Popularity: 24% [?]
“We have so much… stuff. None of us really need any more of it this year. And yet all of the world there are people that don’t have enough. Wouldn’t it be better if we got someone a goat than giving each other more stuff?”
- my mother, 4 years ago
That was the beginning of changing our Dague family Christmas traditions. We don’t do gifts to each other any more, but instead give something to some cause that each of us cares about. It takes a major stress point out of the holidays, leaving only what is important behind: spending quality time with people you love.
This year my contributions are coming in two forms, and as time is running out on one, it seemed a good idea to post soon.
The One Laptop Per Child project has been nothing if not ambitious. The idea is to develop a portable computer specifically designed for developing countries, and distribute millions of them to children in these countries. It has wireless, mesh networking, and a set of base applications that let you do email, web browsing, instant messaging, simple programing, and a whole host of specific educational software to boot.
From now until November 26 you can Give One Get One, where you purchase 2 laptops, you get one sent to you, and one goes to a child in one of the participating countries. I purchased mine the other day. It runs all Linux and open source software, so I’m pretty excited to get mine, and that some possibly budding geek in another part of the world is going to get one because of me.
I’m also looking forward to ways in which I may be able to contribute to the software environment on the XO pc. With any luck it will even get here prior to my trip to India, as it would be interesting to bring along on that adventure.
Kiva is a microfinance organization, which lends small scale loans (usually a couple hundred US dollars) to individuals through out the developing world. When you participate in kiva you transfer money into their system, then you decide which loans you would like to support. Once the loan is repayed, you get your money back. You can reloan it to other individuals, or withdraw it from the system. It isn’t a gift, per say, but it does enable individuals to bootstrap themselves.
Chris has been active with Kiva for a while, selling Kiva products to help raise money for the core organization. I need to thank him for making me aware of the organization, and micro lending in general.
Popularity: 4% [?]
@strips = @user.comics.collect {|c|
c.strips.find(:all, :conditions => ["date > ?", 7.days.ago])}.
flatten.
delete_if {|c| c == nil}.
sort_by {|c| c.date}
The previous shows ruby in much of it’s glory, and is code that I needed this weekend for one of my side hacking projects. I’ve colored it to match what xemacs shows me, just to make it a little more clear.
First off, it shows off the power of mixins. 7.days.ago does exactly what you would expect, providing you with a date object.
Second, it shows off the power of collect (aka map in many other languages). Collect lets you iterate through a list you have, and return a new collection based on an arbitrary transform. In this case returning a list of strip objects for each comic.
And lastly, it shows the fact that collection operations can be chained. My list of lists becomes a single order list, I purge out nils (probably redundant at this point), and then sort all the objects by their date field.
Ruby is such a fun language to program in.
Popularity: 15% [?]
My grad school class this semester is the Project Course, where the whole semester is spent on a group project. No tests, no other grading besides the project, which is actually what I expected more of when starting grad work at Marist (that’s a different post though). The project domain is search.
We have to build an application with an integrated search engine tuned for a specific problem. Our group problem is an user driven online restaurant review site. Our canonical example is searching for “boston seafood”, which should return all the posts that a human would, given the same tasks. That means “the best lobster in bean town” counts as a hit that you’d want. Guess what, SQL like clauses and regex’s aren’t going to cut it here.
But that’s ok, we don’t have to do everything from scratch. We’re expected to base our solution on Lucene, which is a search SDK. You build custom indexer, analyzer, and searcher classes from the Lucene base classes, and feed it documents. Lucene does the heavily lifting of building the inverted index, and scoring the results based on the rules, weights, and policies you’ve given it. A project like this is pretty open ended, as you can always make it better given more time, and more interesting analysis tricks.
The whole team is making nice progress, so for the last two weeks I’ve been able to focus squarely on Lucene integration code itself. Pass one got some basic queries working in Lucene. Pass two was earlier this week, when scoring started to be useful. Pass three will be tonight, where I’ll start to integrate synonym support so that lobster is understood as a type of seafood, burgers are understood to be american food. Though I’ll have to think about how to make sure crab cakes don’t show up in the desert category, though maybe we just need a hybrid seafood desert category.
A few interesting lessons have come out of the work so far. First, search is way harder than most people think. While Lucene gives you lots of nobs and levers to tweak how documents are ranked, the results of those tweaking aren’t always what you think. It’s sort of like moving furniture by throwing bowling balls at it, you may get things close, but you do a lot of collatoral damage in the process. Recently I was attempting to boost scores based on terms showing up in the subject of posts, which completely overwhelmed our post rating scoring, making low quality posts show up at the top of the list.
You also notice when people are using search badly, or more specifically using bad search. Using SQL Like clauses is not search, it’s grep. Unfortunately most php sites do that because they don’t have anything better (Lucene has been ported to a lot of language environments, php is not one of them). The gentoo wikis fall into this category.
Finally, you realize that google’s scoring, while good in general, may not actually be what you want for your problem domain. The fact that the word seafood shows up 3 times in a post doesn’t make it a better post, but default scoring gives it a boost based on the number of times relevant terms show up. Badger, Badger, Badger, while being non kosher, shouldn’t be scored highly in our results, even if we had a category fully dedicated to badgers and mushrooms.
Popularity: 12% [?]

From our vacation last month. Something about the juxtaposition of muscle car vs. self propelled boat amuses me.
Popularity: 8% [?]
![]()
It’s Monarch season. No, not the dreaded form of government, but those butterflies that manage to migrate from the north east to Mexico every year. Because Susan has both milkweed and butterfly bushes in or garden, we’ve managed to attract a few this year, including one that is currently pupating.
And that left me with a question. I saw the caterpillar hanging from under the leaf when I went to work on Friday, and I saw the pupa when I got home, and the pupa is smaller. After a bit of searching on the internet I found a video which actually shows that transformation in time lapse, and it is definitely weird. I might have to rig up something to get my own time lapse of them next year.
Popularity: 15% [?]
After years on Livejournal, I’ve decided to migrate off to my own wordpress installation. This will hopefully help consolidate some of my content which has been spread out on a number of different sites recently. Expect to see some more traffic here shortly once I get all the changes in place.
Popularity: 8% [?]