Apr 30

I finally got around to writing an app I can run on my Blackberry. After investigating, I decided to make a MIDlet, rather than a native Blackberry app. This way, it will run on just about any java mobile platform. Plus, on first glance I thought the user interface API was clearer. In fact, after reading just one or two articles, I felt like I could make a simple MIDlet app with no problem.

The goal was simple: use the jaiku api to post presence updates to my jaiku stream. I know there are utilities like IMified that allow you to make updates over AIM or gtalk. To preserve my battery life, though, I often keep my Blackberry’s AIM/jabber client offline. I really just wanted a simple app to make the JSON api call. There is the moblet in 24hrs project, but it started on April 14th and isn’t done yet… that’s a loooong 24 hours! I got tired of waiting.

Programming Paradise

I had already written a command-line app to post to jaiku in haskell, so I knew how to make the API call already. All I needed to do was define a screen with a text field, and a ‘post’ command that would cause the HTTP POST. Initially, I just hardcoded the username and personal key information into the app. In the next version (next weekend?) I’ll use the mobile RMS api to store those settings in non-volatile memory. At that point, I’ll put the code up here so people can use it if they want.

So, I wrote the utility in probably half an hour, just starting with one of the many ‘hello world’ MIDlets you can find online. I downloaded the newest version of the Blackberry JDE (java development environment) to compile it with. Blackberrys run ‘java’ but they don’t use a normal JVM. This means you don’t move JAR files to your phone, but rather transcoded COD files. So, blackberry-specific tools are needed even when you are careful to only use standard java classes.

Learning how to make a mobile java-based app turned out to be not only easy, but fun. I was happy to see that the way they try to map commands to phone buttons in a phone-agnostic way matched up almost exactly with the way I had suggested doing this on another mobile platform. So, I felt very “in-tune” with the MIDlet way of doing things. I am always surprised by how much code you have to write in java to do anything, though. Haskell and OCaml have spoiled me with their brevity, I think! :-)

Trouble In Paradise

I was a bit annoyed that the JDE is a windows-only app. I do almost all my coding on macs. Oh well… I do have an XP laptop, so it wasn’t a huge deal. In the JDE, my code compiled and ran perfectly in their BB 8700 emulator. So, I moved the package onto my actual phone. You can imagine my surprise when the phone immediately went into an unending series of restarts. It never got past the blank white screen, always failing after a couple seconds and starting over. Worse, removing the battery and reinserting it didn’t help. The ‘java_loader’ application that can be used to wipe the phone’s memory could not connect to the device, since it never started up.

After a lot of searching, I found a way to reinstall the OS while the battery is not in the device. Thankfully, I had backed up all my data just prior to this adventure. But, when I re-loaded the app, the same problem arose, and I had to reinstall the OS again. This takes like 20 minutes, so I was not happy.

Problem Solved

After a lot of searching, I finally found the suggestion that the JDE version 4.1 was appropriate for 8700 phones, while the newest version (4.2) was not compatible. Apparently, the JDE versions are tied to the phone versions, even though I couldn’t find anything in the release notes about this. Not to mention, the JDE 4.2 comes with an 8700 simulator (and older models as well)! I was extremely skeptical that switching JDEs would do the trick. But, I tried it and sure enough, my phone was happy.

I guess RIM has never heard of cross-compiling. I can imagine that it must be terribly confusing to host an app for many blackberry models, if they all must be compiled with different JDE versions. It would be much better if the phone itself would transcode any JAR files you give it, I think…

Success!

I didn’t think to grab an emulator screenshot from my XP laptop, and I’m writing this from one of my macs. But, you can see the first successful post to jaiku!

Apr 28

Coming off years of C/C++ programming, my mind is organized so that I want to write functions such that most important argument comes first in the argument list. But, in a language like haskell, that’s not always the best way.

Here’s an example from just a moment ago. I was adding haddock documentation to some haskell libraries I had written, when I came across this little utility function I had written a while back:

percent_within_range val low high =
     (val-low) / (high-low)

This function takes a value, along with the highest and lowest boundaries of a range. It returns the percentage that the value is above the low of the range. So, passing in 5 0 10 returns 0.5, since 5 is 50% of the way between 0 and 10. 10 0 10 returns 1.0. get it?

Anyway, it was natural for me to pass the val first, since that’s the item I care about when I call the function. In an OO language, percent_within_range might even be a method on val! But, in haskell, this is really the opposite of what you want.

I re-wrote the function this way:

percent_within_range low high val =
       (val-low) / (high-low)

… which is just a re-ordering of the arguments. Now, if you are just calling the function, this makes literally no difference. But, in haskell, this ordering makes it easy to define curried versions of the function like this:

pct_100 = percent_within_range 0 100

… or just use it curried directly:

map (percent_within_range 0 100) lst

You can see this style of argument ordering all over haskell (and other functional languages) libraries, and doing something different is an easy way to mark yourself as an fp n00b. I’ve finally become accustomed to writing code this way, and am still finding examples of “backwards” argument lists in code I wrote long ago.

[EDIT: Since all the comments talk about 'flip' and other strategies for rearranging elements, I want to say that: yes, there are plenty of ways to rearrange arguments, if you are faced with a function that does not curry naturally for your needs. That's not the point. The point is, with some thought, you can make occasions where you need such workarounds relatively rare. After all, I've needed to use ((flip map) [1..10]), but I’ve used (map (+1)) quite a bit more often! I was pointing out that usually the best argument order for common currying is not the order that a lot of imperative/OO programmers would choose.]

Apr 24

I’ve really got to learn more about how this works… assuming it wasn’t staged.

(originally seen via Trader’s Narrative… in the blog post it says this guy has good research on the topic)

Watch this post's video on Youtube

Apr 21

I have no idea when or where this came from, but it was enjoyable. It’s about violence, culture, and the media (same themes as a lot of his songs). He’s good at coming up with catchy phrases (or at least, finding them and repeating them):

“Is adult entertainment killing our children, or is killing our children entertaining for adults?”

Watch this post's video on Youtube

Apr 18

Problem

Some feeds are updated rarely. For these, however often jaiku wants to poll them is just fine. Other feeds, though, like last.fm feeds, can be updated very often. Jaiku seems to poll my last.fm feed every 10 to 12 hours (or maybe it just feels like that long, but it’s often several hours), which means lots of songs never get sent posted to my presence stream. Some twitter-users are very prolific, as well, which means that when you see their updates it’s always bunched together in “and 19 more” form.

Solution?

It seems to me that you could set up an adaptive structure like this:

  • Define some range of poll rates (say, minimum once per day and maximum once per hour, or something)
  • When you poll a feed, note whether there was anything new to post
    • if there was something new 3 of the last 5 times, then move to the next higher poll rate
    • if not, then move to the next lower poll rate
  • repeat, adjusting the poll rate to track the update rate of the feeds

So feeds that change a lot will get polled more often, while feeds that do not change will get polled less often. And, most importantly, jaiku would adapt to feeds that are updated in spurts. So, for instance, twitter and last.fm feeds will naturally update a lot more often when people are awake, and then go dormant when people are asleep.

Maybe a different algorithm would be better to capture the irregularity of the update rate:

  • When a feed has updates in it, bump this feed up to the highest poll rate
  • When a feed has no updates twice in a row, move to the next lower poll rate

So, in this scenario, say a last.fm feed has no updates all night. So, over the course of the night, jaiku polls their feed less and less often. When the user wakes up and starts listening to music, their feed will have updates again. The first time jaiku pulls the feed, it sees the changes and bumps the feed up to the “once per hour” poll rate. Each hour, there continue to be updates, since the user is awake. Once the user stops listening, jaiku will poll the following two hours, and not see updates. Then it will start polling every 2 hours, then every 3 hours, until an update is spotted again, and the cycle starts over.

For feeds (like most people’s netflix queues, for instance) which are usually updated once a day at most, the algorithms would usually not poll the feed very often. It only really affects the feeds that do get constant updates.

I haven’t done any research or modelling… probably there are some adaptive algorithms out there that would work better than these two ideas. But, it seems like it would improve the user experience…

Update: further ideas

Perhaps in addition to the above: when a person makes a jaiku post for the first time after a long break, schedule a person’s feeds for a couple test polls starting 30 minutes after that. The idea is, “this person maybe just woke up, or came back from some offline break, and is now active again.” This would help catch the start of an active period for their feeds quickly, since the poll rate might have gone down quite a bit during the downtime (which would mean a lag of up to 3 or 4 hours before jaiku would notice their feeds are active again).

Apr 17

Cool video, originally found via the Good Math, Bad Math blog.

Watch this post's video on Youtube

Apr 16

Squarepusher song, from Big Loada. Another excllent video from Chris Cunningham (who also did Aphex Twin’s “Come to Daddy” video, and others by Madonna and Bjork etc.). I love the way the action is synchronized with the music.

Oddly enough, I tried to buy this disc from amazon, but they sent me the wrong disc inside the correct cd case/booklet. Obviously a problem with whoever pressed and packaged it, rather than amazon. Weird. Luckily, I liked the disc I received just fine!

Watch this post's video on Youtube

Apr 16

I am a fan of extreme metal music, and have noticed over the years a funny kind of quirk. It’s fairly rare when a single line in a song has an echo on it (either via an actual delay effect, or by manually recording a second version of the line). But, when a line is echo’ed, it often has to do with “shadows.” I think it’s kinda like, not an inside joke, but like an insider’s nod… to what, though? I wonder who kicked the whole thing off?

The three examples on my mind right now are:

  • Obituary: Circle of the Tyrants from Cause of Death. “And hunts and wars are like everlasting shadows.” the last line in the song, only the word ‘shadows’ gets the echo treatment by the main voice. To be fair, several other lines in this song are doubled by a deep voice in the background. Nothing as emphatic as the ‘shadows’ word, though.
  • Morbid Angel: Blessed Are the Sick from Blessed are the Sick. “No intent could shadow my disease”… “shadow” is the only word in any of the verses that is echo’ed, though the choruses use the effect a lot.
  • Nasum: Breach of Integrity from Helvete. “I’d rather watch from the shadows, and be my own.” It’s the last line in the song, and the only doubled line.

I’m sure I’ve noticed more, but can’t think of any others at the moment. I don’t have the Celtic Frost version of Circle of the Tyrants… maybe that would be the originator? I don’t know.

All three songs, albums, and bands are fantastic… you should definitely own them. On the off chance anyone reads this and knows of more examlpes, feel free to comment.

Update: I’ve never heard the song, but I see via internet search that Children of Bodom have a song called “Deadnight Warrior” containing the line: “Always in the moonlight shadow [echo: shadow]“

Apr 14

A lot of my day-to-day haskell scripts produce html that’s intended to go on my stock market blog. Because I generally just hack stuff together, I’m producing the html along with the output via hPutStr. If I wanted to be a little more fancy and pure about it, I would put another step between my domain and the final HTML output. Looking at the hierarchical haskell libraries, I see Text.XHtml just waiting for me to use it.

So, I played with it for a few minutes. Here, for my own reference, is a very basic use of Text.XHtml:

import Text.XHtml.Strict

myheader = thetitle << "My First Page"

mybody = (h1 << "First Off...") +++
         (paragraph << "Hello, there!")

myhtml = (header << myheader) +++ (body << mybody)

main = do
       putStrLn $ showHtml myhtml

You can also use showHtmlFragment to get a just the html you wrote, with no doctype stuff prepended. I was surprised that it doesn’t seem to put the <?xml … > tag at the top, since it’s xhtml, after all. But, it doesn’t.

Had I been familiar with this library when I wrote all those scripts, I would have used it. Since I wasn’t, I didn’t, and I’m not sure it’s worth my time to replace that stuff now. Maybe, whenever I update one of them, I’ll go ahead and convert it. That way, they’ll eventually all get converted… you know… lazily. And what could be more in the haskell spirit than lazy conversion :-)

Apr 14

It’s all coming together… I’ve seen that jaiku has IM support on the way in the unspecified future. I’m assuming jabber at least, but am hoping for AIM support as well.

Until then, because I want to be able to use jaiku on the go, I was gathering info on how to create a Blackberry app (have never done it, but is based on J2ME so shouldn’t be too terribly hard). I would have cobbled together just enough to make presence updates over JSON and view my overview RSS feed. But, as I was looking, I came across this project aiming to make a jaiku mobile app in 24hrs! So, I guess I can wait a few hours and see if this app will take care of my needs! The screenshots look cool. It’s neat that it’s being developed jaiku-style… with constant jaiku posts on the progress here.

This will be the final nail in twitter’s coffin, for my use. I had been continuing to use twitter over IM when I was out and about with my blackberry. With mobile access to jaiku, I don’t see any reason for me to use twitter anymore.

As I mentioned recently, though, twitter is servicing (or at least attempting to) many more requests per second than jaiku is… so maybe as jaiku grows the stability I’ve been enjoying will start to falter. The main reason I looked for a twitter alternative was all the outages and slowness. The reason I’ll stay with jaiku, even if it suffers under load, is commenting. Commenting rules.

Seriously, now that I am used to the enhanced jaiku features, twitter is starting to look a bit lame. They have a much larger user base, but if they don’t fix their stability issues it will start bleeding away. Web2.0 users are fickle…

« Previous Entries