NASA Wins Intergalactic Billiards Championship

The MESSENGER probe successfully completed its flyby of Venus, and heads towards Mercury.

Seriously, these guys are incredible. We want probes to get where they’re going fast, but going fast in space has one nasty implication: slowing down requires just as much energy as it took to speed up. In order to shed some of that speed, NASA sent their MESSENGER probe past extremely low by Venus to pass excess energy into Venus’ atmosphere.

Now the probe is heading on to do a flyby of Mercury, which will point it straight at the Sun. The technical ability this kind of feat requires is nothing short of astounding. It’s the world’s largest billiards trick shot, with the balls spaced 25 million miles apart.

Personal
Random

Comments (0)

Permalink

fork()

I’ve decided to spin off all my technical writings to another blog, and keep this one for my political and/or personal musings.

Technical

Comments (0)

Permalink

Subversion Repository Moved

For those of you using my gemtracker plugin or otherwise pointing to my repositories, the location of my anonymous Subversion repository has changed. It’s now svn://devel.touset.org/, with no svn component of the path.

I’m building a new VPS to host my open source development and blog (WordPress is grating on me, and DreamHost sucks at running Typo), so this move is part of that.

In other news, keep your eyes peeled for version 1.5.0 of Pallet, my cross-distribution Ruby packaging library. It’s gone through a major rewrite of the Debian backend. I’ll (hopefully) soon add an RPM backend as well.

Technical
Rails
Ruby

Comments (0)

Permalink

Trackin’ your gems like you just don’t care

After going through the hell of chasing down gem after gem for a Rails project at work, then discovering that it actually uses a few older gems than what are currently released, I decided to write the gemtracker plugin.

Short summary: you write config/gems.yml, which is nothing more than a YAML hash of gem names and versions. When Rails initializes (but before it starts loading any of your custom initializers), it loads those gems at the requested version.

How is this better than just specifying, for instance, gem rspec, '1.0.1' in the top of your environment.rb? When you run Rails, it will throw an exception that tells you all of the missing gem versions at once, rather than having to go through the tiring loop of running script/server, checking the exceptions for the missing gem, installing it, and repeating ad nauseum. My hope is that it will also encourage developers to explicitly list the version of any gems used, which is a good practice in general for writing production apps.

It also provides a singular rake task, gems:install, which installs any versions of required gems that you’re missing (run it under sudo if you need root privileges). This should prove useful for larger projects with several developers. It should also be pretty trivial to add a Capistrano task that runs rake gems:install during an upgrade, ensuring that the environment there is identical to the developers’.

Hope this helps some of you out there.

Update: Apparently, init.rb went missing when I did some layout reorganization a few days ago. Thanks to an anonymous reader and DerGuteMoritz for bringing this to my attention. This has now been fixed.

Technical
Rails
Ruby

Comments (1)

Permalink

Behold! RSpec and autotest get married

It’s been tried before, with Nick Sieger and Philippe Hanrigou both providing some .autotest files to customize autotest for the purposes of RSpec. Using both their code as a template, I’ve come up with a few small changes for my own nefarious purposes. Behold, my .autotest!

Autotest.add_hook :initialize do |at|
# run spec with rcov
if at.respond_to? :spec_command
at.spec_command = %{script/spec --diff unified --colour}
end
end

module Autotest::GnomeNotify

# Time notification will be displayed before disappearing
# automatically
EXPIRATION_IN_SECONDS = 4
ERROR_STOCK_ICON      = "gtk-dialog-error"
SUCCESS_STOCK_ICON    = "gtk-dialog-info"

# Convenience method to send an error notification message
#
# [stock_icon]   Stock icon name of icon to display
# [title]        Notification message title
# [message]      Core message for the notification
def self.notify stock_icon, title, message
options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{stock_icon}"
system "notify-send #{options} '#{title}' \"#{message.gsub(%r{"}, "\"")}\""
end

Autotest.add_hook :red do |at|
notify ERROR_STOCK_ICON, "Tests failed",
"#{at.files_to_test.size} test#{'s' if at.files_to_test.size != 1} failed.n" + at.results.scan(%r{'(.*)'}).flatten.first
end

Autotest.add_hook :green do |at|
if at.results.empty?
notify ERROR_STOCK_ICON, "No results", "Did you throw an exception?"
else
notify SUCCESS_STOCK_ICON, "All tests passed, good job!", at.results.scan(%r{d+ example[s]?, d+ failure[s]?}).first
end
end

end

What advantages does this bring? Well for one, you get colored output. For another, you get better notification of successes (number of tests passed, etc.) and failures (a description of the first failure). Even better, you get notified when you throw an exception (for instance, by mistyping the name of a method), which autotest would otherwise report as a success. It also does a dumb shell escape on any single quotes in the message sent to notify-send, so specs with apostrophes don’t break anything.

Of course, I’m sure it completely breaks if you try and use Test::Unit in conjunction, but who uses Test::Unit nowadays?

Update: Please excuse the unindented nature of my code. WordPress has a pathological need to reformat (read: “fuck with”) preformatted text. Because of general unhappiness with WordPress, I’m likely moving away quite soon. Possibly to Typo or Mephisto.

Technical
Rails
Ruby

Comments (0)

Permalink

Joyent Slingshot a Disappointment

The Atlanta RUG met today, and one of the topics discussed was the brand spanking new (released today) Joyent Slingshot. While sounding promising, it’s not really all that groundbreaking. Keep in mind that the following rant stems from initial impressions based on the presenter’s demonstration and group discussion about the application.

In case you aren’t familiar with it, Slingshot offers a way to run Rails applications in an online or offline mode for OS X and (theoretically) Windows. When online, changes made to the application by the user are done live, and when in offline mode, the user makes changes to a local copy that get synchronized when he can connect to the application again. It also runs as a native OS application, which seems great.

Unfortunately it’s not all that impressive. “Native OS application” simply means that it runs in an OS window, although all it really contains is an HTML control that renders the web page. Apparently there may be some OS integration features, but I’m not clear on that part. Essentially, all Slingshot does is runs script/server locally and gives the user a “control-less” web browser to use the application with. In other words, they’re dropped into a minimalist web browser with no back/forward button, no navigation controls, etc. The database is hosted locally in SQLite 3. When pulling changes, it serializes objects from the remote webapp into XML and loads them into your models locally. When pushing changes back to the webapp, it pretty much just calls ModelName.new(:foo => bar, :baz => :quux) which means anything you created likely gets a new id in the database (since other users may have added other objects and increased the primary key counter).

So, all it really seems to be is a glorified “single-click” script/server and local Rails instance, plus some lightweight synchronization and a way to detect whether the user is in online or offline mode.

But this has problems. The synchronization is intentionally dumb (real synchronization would need semantic understanding of your classes and how to manipulate them), which means lots of strange behavior. In a simple case, imagine creating a new Foo object with id 38. Sitting at http://localhost:3000/foos/38, you synchronize. Someone else already created a Foo object with id 38, so yours becomes 39. Now you’re pointed at the wrong page, but it hasn’t refreshed so you don’t know. With poorly-implemented local caching, this could become quite serious a problem when even a refresh fails to show the changed record.

In a more worrisome example, imagine you create an object and its id gets stored in the session for whatever reason. Now, you hit the synchronize button. The id of the object you were referring to changes, and another object holds that id instead. This could give you completely different sets of permissions (in the case of a User object), or do all sorts of other nasty things. You can potentially mitigate these issues by finding a way to use a UUID as your primary key, but it still doesn’t provide any sort of useful merging ability for when people edit the same record. acts_as_versioned might help you out here, but again this means you’ll need to add significant complexity in all but the simplest of cases.

In a way, Slingshot fails to live up to the excitement surrounding it. It seems kind of neat on the surface, but it looks like it will add so many potential problems to how your users access the application that on all but the smallest of sites with one or two concurrent users will suffer greatly.

Pros:

  • lets users work on a locally-cached copy of data while working offline
  • write local-only apps using only HTML and rails rather than Qt/GTK/Win32/Cocoa

Cons:

  • introduces synchronization issues
  • 100MB downloadable (ruby + rails + additional gems + application + slingshot)
  • no browser controls
  • won’t work if you use database-specific features in PostgreSQL, MySQL, etc.

Worries, potential gotchas, and sad reality:

  • running multiple slingshot apps at the same time might not work yet (just speculation)
  • no real support for OS-native features (my current understanding)
  • really just script/server and a local cached copy of the database (disappointing)

There are definitely some uses for this sort of thing (local apps without having to write a lick of GUI code), but far more limited than I was hoping for. The general consensus of the RUG seemed to be that it could potentially evolve into something neat, but it currently lacks anything generally compelling. Plus it has the potential of introducing lots of nasty synchronization bugs that would be hard to fix.

Perhaps this is a mischaracterization of Slingshot. I hope it is. I have never used it, and these comments are based on an hour long discussion of Slingshot and demonstration by one of the (seven, supposedly — and this was the only one of those seven who actually ended up implementing something with it) few developers who were granted the privilege of getting a demonstration version of the software in order to beta it.

Technical
Rails
Ruby

Comments (1)

Permalink

Compressing Video

This is something that drives me batty when downloading torrents: compressing videos into .rar format.

What’s the point? First off, splitting it into multiple files was a reasonable idea, back when people had terribly slow connections, which were mostly unreliable. Nowadays, people have resumable downloads and always-on broadband. Not to mention, this is all in a torrent anyway — so what’s the point?

I hope it’s not to save space, because in most cases, adding another layer of compression actually increases the size of the file. Why? Because it’s already compressed. That’s all a video codec is: some way of compressing a raw stream of video into something more manageable.  The difference is, video codecs are explicitly written to take advantage of the specific types of redundant information in video, where generic compressors like WinRAR, gzip, and WinZip try and compress all types of files.

Composing the two together, though, doesn’t work. Once the codec is done, the video is already pretty damn near maximally compressed; there’s nothing redundant left to pack away. So all another layer of compression does is increase the size of the resulting file, because it has to tack on information about how to decompress it. Net result? Most videos end up being 10-15MiB larger, which means another few minutes downloading. It’s not much, but when you consider 10,000 people downloading it, it adds up to a lot of bandwidth and a lot of time.

So please, don’t be a donk. Just torrent the fucking video.

Technical

Comments (0)

Permalink

The Browsenberg Uncertainty Principle

I hereby present my Browsenberg Uncertainty Principle:

As one increases the layout precision of a section on a webpage, all other sections of the page have their layouts perturbed by a proportional amount.

And its corollary:

The more precisely one specifies positioning and layout for a page in one browser, the less accurately every other browser will render it.

Personally, I think these need no further explanation. The sad fact remains, though, that people don’t seem to understand this — especially those who happen to want webpages created for them.

The process is familiar to anyone with a modicum of web development under their belt.

Insane Customer: I’d like this webpage designed! Here, I’ve forwarded you a bunch of pictures of what I want it to look like. Our designers took screenshots of their Photoshop mockup and faxed it to us, then we ran it through the photocopier a few times, scribbled over it in sharpie, scanned it in, and pasted it into a Word document which we then zipped and attached to this email. Let us know when you can complete it.
Three days pass…
Enlightened Developer: We’ve completed the project. Here’s screenshots of every page being rendered in eight different browsers (including IE 5, 6, and 7). Please give us feedback [Lines of HTML/JavaScript hacks, and CSS: 14]
Insane Customer: We need you to have all text rendered in [company’s own font, which nobody else in the world has because it was developed in-house by their just-as-insane design team; it also happens to be missing glyphs for the letters “t” and “e”]. Also, the left sidebar needs to be seven pixels shorter. And I need you to make sure that the bottom of every section lines up with the exact pixel where the text ends in the section next to it. Thanks.
Two weeks pass…
Enlightened Developer: Here’s the page with your modifications. Unfortunately, it no longer works in Opera, Lynx, or Konqueror. But few people use those browsers, so it should be okay. [Lines of HTML/JavaScript hacks, and CSS: 173]
Insane Customer: That looks better, but now the alignment of the header is off by three pixels, and some of the letters show up as weird boxes with numbers in them! This is unacceptable!!! We were expecting to deploy this site six days ago, and you’ve done nothing but cause excess delays. We need this ASAP!!!
A month passes, with back-and-forth between Customer and Developer…
Enlightened Developer: Okay, this should do it. We’ve got the layout down now, but had to drop support for IE5 and Safari, since they don’t support [random CSS tomfoolery without which some absurd requirement couldn’t be satisfied]. Also, the viewer will automatically have his display resolution set to 640×480, or else one of the text blocks will roll off the edge of the screen. We’re ready to deploy this as soon as you give us the okay. [Lines of HTML/Javascript hacks, and CSS: 1,027]
Insane Customer: Perfect. However, we’ve recently developed our own internal server-side blink tag, and our new Website Design Policy states that any place our logo is, we need to use it. It will require this 16,641 line JavaScript file to directly send some PHP and SQL to our Application Server, and these small (500 or so) CSS changes in order to incorporate the actual blinking. Can you have this incorporated by tomorrow?
Three days later…
Enlightened Developer: Okay, we tasked the entire company to this and had every developer work without interruption for sixty-three hours straight. We were able to complete these last requirements. Unfortunately, your code only works in IE 7, so we’ve dropped support for Firefox and IE 6. All your customers will be forced to download a 117MB browser upgrade. Plus, we’ll have to look into the security issues of your server-side blink; namely, if a customer accidentally clicks on your logo while it’s blinked out, it will empty the contents of your entire SQL database, and format your webserver. On second thought, ignore that. I think we have a solution for this entire situation. We’ll deploy today. [Lines of HTML/Javascript hacks, and CSS: 69,552]

I’ve often considered simply making webpages as static images. Links can be done by a giant image map covering the entire thing, and input fields can just be superimposed on top. Or we could train marketing and sales types to realize that their customers don’t want them explicitly controlling every aspect of their sensory input or even to comprehend the fact that HTML wasn’t designed to do such silly things, no matter how much JavaScript and CSS you layer on top.

Nah, the first option is probably far easier.

Technical

Comments (3)

Permalink

Writing a Threading Library

The first assignment for my Operating Systems class is to write a threading library for Linux. It’s not comprehensive, but it should support most of the “basic” functions: init, create, wait, join, exit, and so on. Plus, it should come with a mutex library for synchronization (which, coincidentally, it should use itself in order not to trip over its own toes).

It’s one of the first programming assignments I’ve had in awhile which I’ve really actually gotten into. The code itself is surprisingly straightforward, only nuanced. What I mean by that, I suppose, is that the algorithms for doing this aren’t too mentally taxing (yet), but the API I’m using (ucontext.h’s setcontext, makecontext, swapcontext, and getcontext functions) is completely foreign to me, as is the concept of signal handling in C. There’s an alternative (setjmp.h’s longjmp, siglongjmp, setjmp, and sigsetjmp functions) which is generally used for comprehensive threading libraries (I believe pthreads uses it, but I’m not positive), but it’s a bit more difficult, and what I’m using now is “good enough”. I may still change to the latter library, but only once I’ve gotten the current implementation working.

Anyway, ucontext. It abstracts the concepts that I need pretty well, but there’s some leaks. For instance, valgrind, a popular program analzyer, reports a bunch of “interesting” memory reads and writes, plus a few uses of uninitialized memory. Even though they’re (what I believe to be) completely valid (and the memory is initialized, dammit), the fact that contexts are being swapped and the code pointer is being thrown around all over the place seems to be throwing it for a loop. Maybe this is an issue with any threading library, though, and simply a limitation of our ability to analyze memory accesses. I don’t know.

The problems reported by valgrind don’t seem to be causing any functional. There are other more substantial issues, however. For instance, the concept of a “thread” is something I’m inventing on top of these contexts (the quotes will be used from now on to distinguish between my simulated “threads”, and the operating system’s understanding of a thread). Because of this, I ran into an issue with my program terminating. As it turns out, when setcontext switches to a context, and that context reaches the end of the function it was told to run, the thread exits. But not my “thread” — the actual kernel-recognized concept of the thread my application is running in. Oops.

It was reasonably easy to fix. You’re allowed to give a context another context to return to when it’s finished running. This is similar to a callback function, only it requires more memory and yet more code to initialize the context. And I have to create one for each “thread” (more on this later). So, I make a context which starts running a function that turns the currently-executing “thread” into a zombie and re-runs the scheduler. I will have needed this anyway, but it would have been nice not to have my entire program exit just because some context returned, but I can see why the API was designed this way; it’s not entirely clear what the context should do when it’s finished (you’re not really running multiple programs at once using these contexts, you’re simply saving a context’s state, then swapping to it when a scheduler is run; how should a context know what other context to go to when it’s done executing unless you specifically tell it?). I’m going to have to extend this zombie function later, though; once I implement wait, join, and the like, the thread will have different things to do when it terminates. For instance, when I join a thread, the thread should clean itself up entirely and get its return value back to the joiner. When it’s waited on, yield back to the waiter. And finally, when nobody seems to care about it, it has to sit around in a zombie state until the program exits, just in case another piece of code ever ends up referring to it later.

I mentioned earlier that I have to create a zombie context for every “thread” I make. I had hoped I could make one zombie context that they can all share, but initial attempts to do so have all failed; I’ll return to it later. Essentially, a context includes not only all the memory and stack of the program at that point in time, but also where the code is currently being executed (i.e., the code pointer). So when a zombie thread calls the function to zombify it, it enters the function and continues down. I haven’t found a reasonable way to “reset” the context to its original state, so other zombies which would swap to this context find themselves past the cleanup and zombification steps.

Another potential would be to create two zombie contexts. When one runs, it cleans up the other (which should theoretically no longer be in use, with proper mutex usage), reallocates the memory and creates a new, fresh zombie context, points the “current” zombie context to the newly-created one, and yields back to the scheduler. The next time a zombie is run, it uses the new context, frees and reallocates the (previously) old one, then points at that one again. I’ll try this approach whenever I have time.

Besides these issues, I’m proceeding quite quickly through the assignment. I’ll have to dedicate a lot of time over the weekend to it, but I’m not worried about the deadline, since I have nothing else due in the period (I do have one test, though). I’ve already implemented thread creation, grabbing the current thread handle (which is trivial in my implementation, so I might as well have) (note to self: I may want to use this function rather than referring to the current_thread pointer, just to be safe), scheduling, and thread cleanup. Only three of the several API functions I’m supposed to implement have been finished (i.e., create, get current thread, and init), but I have most of the actual threading code written, so writing the other publicly-exported functions should be relatively minor tasks that simply get or poke or manipulate the different structures I’ve already set up using functions I’ve already written. At least, I hope it’s that simple.

Technical

Comments (0)

Permalink

Assignments

I’m pretty overloaded right now between work and school.

Although, somewhat refreshing is that, for the first time in a long while that I can think of, I’m really enjoying my school assignments. They’re pretty difficult, and most of them time-consuming. On my plate so far:

  1. Prove five statements in computational theory. Completed, but took about an hour and a half per problem.
  2. Write a userspace threading library for Linux. Pretty difficult, and unlike anything I’ve done before. I have 10 days to do it in, and I hope I can manage to finish it by that time.
  3. Learn LISP. In two weeks. I’m finally at a level of Computer Science where they expect to be able to tell you to learn something on your own, and have you actually do it. This is something I’ve been waiting for since my first day at KSU.
  4. Build props to use as test obstacles for our DARPA Urban Challenge entry. This whole project will take roughly the entire semester, but it boils down to us getting to play with and test Georgia Tech’s entry: Sting, a Porsche Cayenne.

On the other hand, work has been grinding me with no end in sight. No matter how much I do, I continually get more piled on. I don’t blame them — we’re increasingly short staffed, and being off at school doesn’t do anything to fix a customer’s immediate problem. But I’ve told them I’m only going to work twenty hours a week, and only two days. Well, they’re okay with the two days, but apparently I’m needed at least 12 hours a day. And some hours during the school days.

For example, today. I check my email at school, and notice that our support team is having issues with a site I made a customization to. They found the problem on Tuesday, but never really conveyed to me the seriousness of the issue. So, I see a bunch of emails that have gone around since this morning trying to diagnose the issue. I’m sitting in a class, and I decided to try and see if I could help at all. At Kennesaw State this wasn’t such a big issue, because most of the classes there were trivial; I didn’t pay attention more often than not. But in graduate school it’s a completely different story; I need to listen to the professors, and pay attention to lecture, or I won’t be prepared for the tests. The lectures usually don’t cover material in the book, but supplementary knowledge we’re expected to know to succeed in the class.

At any rate, this was the wrong move. By replying to an email and attempting to diagnose the problem, I suddenly get sucked in. I’m asked to write up documentation about the customizations and deliver it to another team so they can continue their efforts. I, quite simply, don’t have the time to do that during the school day. It isn’t going to happen. Yes, the documentation should have been done back when the site was first customized, but this was done under severe time contsraints at the last minute, like most of our projects end up being. I’d gladly go back and complete documentation on it if I had any time whatsoever (and no, I don’t consider time in class to be eligible) between projects to do so.

I get an email about an hour later from a very pissed-off manager asking why this hasn’t been delivered to them, and to call him as soon as I receive the email. Of course, by this time I’ve closed my email client and don’t notice it until 10PM tonight, just after I get home from school. I can’t help but consider the sinking realization that if I’d just let them figure it out by themselves, I wouldn’t be getting flak from all directions for not being able to devote all of my time into fixing it.

So what’s it to be? Do I continue to be “generous”, and try and help fix problems even when I’m off-hours at school, or do I simply forget about it until the next day? I wish I could say I still saw any benefit in the former.

Technical

Comments (0)

Permalink