blog
history
projects

profiles
about
hortont · blog · code

YouTube Bookmarklets

2008.06.05 in code

These are here for Amy... drag them into your bookmark bar.

Download from YouTube

Switch to High Resolution

A New Baby, Rectangles, and Ma Bell

2008.06.04 in code, personal, photography, and summer of code

Of note: the three title characters are not related in any way, except they were all a part of my day yesterday!

Firstly, and most-excitingly, thanks to Google, and mom, and dad, I purchased a Nikon D80 today! I simply cannot wait until it gets here... I've managed to read literally hundreds of pages of reviews and such and I'm very excited and happy and can't wait to see what it can do. Soooooooo excited — can'tcha tell?! The D80 replaces the Nikon Coolpix 8700 (don't immediately shrug it off because it's a Coolpix — for a point 'n shoot, that camera is astounding!) that Aunt Vivian graciously handed down to me a few years ago (first picture I still have appears to be from May 6, 2006, so pretty much exactly 2 years). That day was unbelievably important to me, because — before that, I'd never had a usable camera of my own (Kodak PalmPix for the IIIxe does not count!), and I'd just been handed something that would stay more or less attached to my hip for the next two years, recording countless memories (really, my memory is somewhat sketchy, so the pictures from this camera provide a great deal of my memory for me!) — almost 4000 pictures that I kept, in the end! (probably 10x that in total, because I use burst mode a lot!) So, while I most certainly have to thank Vivian for it, I'd say that it and I had an excellent run, especially through APAD'07 and all! This (outside a nursing home in Waterloo, ON, Canada) is probably the picture from this camera that gets the most 'wow's, but if I had to pick a favorite, I'd come back with about 150 pictures!

Second thing! I've got a much more stable, git-based workflow for working on Evas now, and I've even gotten the framework of the Evas-Quartz (without GL) engine sitting there! This is where the bulk of the summer's work goes, so I'm glad to have sat down and gotten that worked out. In addition, rectangles, polygons, and lines draw and animate properly! It was really awesome the first time I got the rectangles to draw, despite the fact that moments later they were animating over top of the window decorations... Text is working, to some extent, but I'm currently using an unacceptable text API (the built-in CoreGraphics one) which is so underpowered that it doesn't even support Unicode. I've got to move to ATSUI, but that involves reading lots of documentation and learning things I've never had to deal with before. I suppose that's sort-of the point of this, though, no? That might be tomorrow's job, since I know I'm not going to get much work done whichever day my new camera comes! EDIT: apparently there's a new CoreText API in Leopard. I think I'll use that instead!

The last bit — the Ma Bell bit — is that either AT&T recently added, or I recently noticed, the ability to download your call data in CSV (per-month). This meant I could clean up my call data grapher quite well (no more screen scraping means it actually works now — they broke it in January!)... so here y'all go. Figure it out on your own! My graph is below the jump!

LifeSaver

2008.05.30 in code

Here's my (slow, naïve, resource hungry, stupid) implementation of Conway's Game of Life in a Mac OS X screensaver. Source here.

Don't use it on a laptop — it'll suck your battery dry. Don't use it on big displays (it works on my 1440x900 MacBook Pro on battery power just fine, but heats up one of the cores almost completely), it'll be slow. Basically, I'm just posting it here ... for fun. I know there's a billion better ways to do Life. Maybe someday, but not today!

iTunes Library Size, Over Time

2008.05.27 in code and music

I've recently been merging a few different music libraries together into my iTunes library on my laptop, so I was interested to see what sort of growth my library's had, over time. I whipped up a quick Perl script (which you can grab yourself, here — though you'll definitely have to modify it to work on Windows). I plotted the data from my library with Mathematica, and got this:



There's now a cleaner-but-less-succinct Objective-C version, and its source. The built version (first link) will run and then just disappear, having created 'music-chart.csv' in your home directory, which is a CSV of: (UNIX date, iTunes Library Count) pairs. You can chart it with anything that can chart pairs... Mathematica works (ListLinePlot[Import["/Users/hortont/music-chart.csv"], PlotStyle->Thick]); Numbers might, but I've seen it do nasty things (you have to manually set minimum and maximum X values, or something...); gnuplot will definitely work...

OpenGL Success!

2008.05.25 in code and summer of code

YAY! Here's EVAS drawing to OpenGL-on-Quartz!

I have some issues...

1) I can't drag/resize/focus the window. At all. I don't know why.

2) I'm currently using Carbon to create the window. That's kind of awkward because of the semi-deprecated state of Carbon in Leopard... that would prevent us from ever having a 64-bit Evas-on-OS-X application. I would like to use Cocoa, of course. For one, that would greatly reduce the amount of code required; secondly, it would probably fix #1 without any fuss; thirdly, it would fix the 64-bit problem, and be much more forward-compatible. However, I really can't fight with Autotools any more today, so I won't be getting Objective-C into the mix today, so... no Cocoa! Perhaps tomorrow. Or next week. Or something!

3) No input. This might be because I can't give it focus, but I think the fact that I don't handle input is also why I can't focus the window. Catch-22!

Autolocate Maths

2008.05.21 in code

I mentioned yesterday that I made up some random math for Autolocate. The exact thoughts behind this escape me at this point — I had been awake for well over 24 hours when I found myself in Commons (our dining hall) with my computer and a bunch of printouts on Bayes' theorem (?!? I don't think this applied in the end, and might not have been related at all!)... and a preliminary version of the following equation:

p=\frac{\sum i\cdot e^{-\frac{(c-i)^{2}}{.03}}}{\sum i}

Where i is the ideal network strength, c is the current network strength, and you sum over the set of networks. I think I came up with 0.03 (it's the factor that changes the width of the bell curve) by playing around with stuff in Mathematica until the curves looked right (who knows what that means!)

I quickly implemented it, and created a small test application that I played around with for a few more days (this is the code I mentioned in the previous post)... here's a partial implementation, which seems to work:
+ (float)partialProbability:(float)c withOptimal:(float)i
{
    return powf(M_E,-(powf(c-i,2)/.03));
}

+ (float)locationProbability:(NSDictionary *)testLocation knownLocation:(NSDictionary *)knownLocation { float totalProbability = 0; float count = 0;

for(NSString * key in testLocation) { if([knownLocation objectForKey:key] == nil) continue;

totalProbability += [ALController partialProbability: [[testLocation objectForKey:key] floatValue] withOptimal: [[knownLocation objectForKey:key] floatValue]] * [[knownLocation objectForKey:key] floatValue]; count += [[knownLocation objectForKey:key] floatValue]; }

if(count == 0) return 0; else return totalProbability/count; }

Full source (but don't expect to be able to use it, it's a complete mess...)

Introducing Carmen!

2008.05.20 in code

I'm happy to finally be to a point in development where I can't really see myself giving up on this project, so I think that means it's time to write a post about it! This is going to be very ... freeform ... and varied in technical detail throughout. More of a ... launchpad for ideas and examples than a ... press release!

Carmen is a Mac OS X application which watches for changes in your environment, and allows you to assign actions to particular environments. Taken most simply, this allows you to perform numerous different tasks when you, say, move your computer from your home to your office. However, the power of Carmen is made clear when you want to act upon more subtle changes — say, the presence of a device, of a power adapter, etc.

I was inspired to design and write Carmen after spending a few months with MarcoPolo. While MarcoPolo is wonderful, it's GUI leaves something to be desired, and it's missing a fundamental level of power that I couldn't really see implementing within the existing codebase. I'm borrowing a LOT of code from MarcoPolo, mostly from their many excellent actions and evidence sources. MarcoPolo is GPL'd, and, unlike the other handful of less-powerful but more-'pretty' alternatives, so is Carmen!

I've got lots of sketches and notes and things that I think I'm going to scan and post at some point, because I really don't have a mockup that I feel willing to post anywhere at all at this point. I (surprisingly, for a project like this!) need a lot of art, and I'm either going to have to buckle down and do it myself, or convince someone else to help me (we'll see!)... but that's really a blocker on having a good mockup to show off!

Time for extremely contrived examples within a list of features:

Environments are hierarchical — you can, for example, have a 'Home' environment, which has sub-environments 'Studio' and 'Kitchen'. Say, in the studio, you have a Bluetooth tablet, and you want your volume automatically muted so as not to disturb your creative juices. However, you take the same tablet to work, where you're continually on conference calls, and need to keep your volume unmuted. A wireless network at home indicates that you're in the 'Home' environment, and, combined with the connected tablet, Carmen realizes that it's OK to mute your volume. If you're connected to the VPN at work, it instead places you in the 'Work' environment, and doesn't evaluate the actions for the 'Studio' context.

Cascading Actions — I haven't thought about this much, but there's fragments written about it in my notes. This would involve the ability to set an action on, say, the 'Home' environment, and have it execute even if you're found to be in the 'Home/Studio' environment. This is not how hierarchical contexts work in MarcoPolo, but seems like a far more useful model to me!

Fuzzy Logic — when multiple rules are provided for an environment, the confidence that a particular rule gives to the whole is taken into account, giving extreme flexibility to the rule system. For example, if you have a dock for your phone on your desk at home, there's a good chance you're at your desk when your phone is attached to your computer, and you can add this as a rule with, say, 75% probability. However, if you're at work and need to sync your bookmarks, the fact that you're connected to the internal VPN can give, say, a 100% probability that you're at work, meaning that you won't get switched to your home context when you plug your phone in! Probabilities will be expressed in words, instead of percentages (unlike MarcoPolo's somewhat confusing and random slider), but — you get the picture!

Autolocate — this feature appears to be unique to Carmen (also, it desperately needs a better name). Based on some completely random and wacky formula that I made up by playing around with stuff in Mathematica after having not slept for well over 24 hours (and will write about at some future point in time) it allows Carmen to collect data on the strengths of wireless networks at a particular location, and then later compare the current information to saved states, and determine, with reasonable accuracy, one's location. What's really cool about this is that — in preliminary tests — I was able to walk a few dozen feet down the hall, make a new 'autolocate' location, and the demo code consistently and repeatedly distinguished between them, even though, the whole time, I stayed connected to a single network (the normal, MarcoPolo way of differentiating between network contexts). Now, this was in a college dorm, with lots of networks (something like 9) to work with. When you're talking about a single network, this really isn't feasible, and you'll have to rely on other sources (like the normal, MarcoPolo 'what network am I connected to' one)...

Plugins — Every action and rule is actually a full-blown plugin, allowing third parties to create plugins that enable Carmen actions on their software. The plugin system also allows for the development of a community around Carmen, updating actions and rules without the need for a new release of the entire package! An internet-based plugin update system similar to the one found in Quicksilver will be implemented in order to keep everyone's systems up to date, and to allow simple acquisition of new plugins as they are created. (of course, plugins allowed into this system will be thoroughly reviewed by myself, and will need to be GPL'd as well). MarcoPolo currently ships with rule plugins for: Audio output device, Bluetooth devices, Bonjour services, Firewire and USB devices, Light level, IP address, Displays, connected network, running applications, time of day, and power source. Since I'm borrowing their code, I expect to support all of these in the first version of Carmen, plus the Autolocate plugin. Eventually I hope to expand this list to many more! Actions in MarcoPolo include: setting default printer, changing desktop background, setting Adium/iChat status, setting default outgoing mail server, mounting network drives, changing system audio volume, opening or closing an application, changing the timeout on the screensaver, running a shell script, toggling Bluetooth, WiFi, and any VPNs. Again, I expect to support all of these (and attempt to repair the ones that are currently somewhat broken, like setting the Adium status!) in the first shipping version of Carmen!

Guile-backed — (Power User Alert) This is where the crazy power of Carmen comes in! The probability of being in a particular location is actually the evaluated result of a Scheme s-expression. Something that looks like, say:

(context
	(list
		(rule (ambient-light-range 0.6 1.0) 0.7)
		(rule (usb-device-connected "Apple iPhone") 0.9)
		(rule (not (usb-device-connected "RMS")) 1.0)
	)
)
You have the complete power to edit this however you'd like, if you so wish. Adding any kind of complex logic — or anything else supported by the GNU Guile Scheme interpreter — is quite possible. More complex changes won't show up in the Carmen UI (we wouldn't need Scheme behind the scenes if we could specify everything everyone's ever going to want in the GUI!), but a special 'advanced user' mode will toggle on, constantly providing a color-coded view of the Scheme source for each context, easily editable to match whatever your desires may be. I'm not even going to try to come up with an example for this section — there's so many possibilities!

Small Things — Sparkle automatic updater support, Growl support, icons for contexts, certainly more I'm forgetting at the moment!