CaseyBanner.ca | The while() loop of life

Freelensing

I’ve been trying a technique called ‘freelensing’. Freelensing is when you remove the lens from your camera and hold it in front, moving and tilting the entire lens to focus. You can get some really cool depth of field and tilt shift effects. Anyway, here are a few of my attempts:

MoPar
Mopar
Facebook

The technique is explained in more detail here: http://lukeroberts.us/2009/12/freelensing/. The freelensing group on flickr has some great work too: http://www.flickr.com/groups/freelensing/.

Try it out!
-Casey

Toronto Sunset Timelapse

This weekend the weather was ridiculously nice, so I went over to the islands to catch the sunset across the water.

Toronto Island Sunset from Casey Banner on Vimeo.

-Casey

Another Calculus Timelapse

Huzzah! Its exam time again and I’m back at my usual antics. Well, I’m actually studying this time. It looks to be an all day thing until the 20th. Anyway, here is what I did today:

Calculus Timelapse from Casey Banner on Vimeo.

-Casey

Cross-domain remote JSON in Javascript (without a proxy)

When I created Banter, I challenged myself to do the whole thing client-side, in the browser. Of course, that means it would all be done in Javascript.

The first problem I anticipated running into would be making remote queries to the Twitter API via AJAX. Since browsers enforce strict rules on what domains you can make remote requests to (you can only make requests to the same domain as the page running the javascript), I wouldn’t be able to get the JSON feed that way. This is a security limitation, so people can’t make malicious remote requests.

Normally what you do in a situation like this is to create a server-side proxy running on the same domain as your page, which makes the actual request to the remote domain, and returns the results. Since the proxy is on the same domain, the AJAX request is allowed and everything works fine. However, I had resolved not to use any server-side code to grab the Twitter feed, so that option was out.

After a little bit of research, I found about a slightly sneaky technique that people are using to load remote JSON without needing a server-side proxy. This is how it works:

If you add a <script> tag to the pages’s DOM, the browser will immediately run its contents. So, all you need to do is add a <script> tag to your page, with the URL of the remote JSON you want evaluated as the ’src’ attribute. Once the tag is added to the DOM, the browser fetches and evaluates the script.

Alone, this doesn’t do us much good. Sure, we can evaluate a bunch of JSON, but we can’t access that data from the other Javascript on the page since it wasn’t actually stored anywhere. Fortunately for us, most APIs that provide data in the JSON format also accept a ‘callback’ parameter. Provide that parameter, and the API will return your JSON, nicely wrapped in a function call to whatever you provided as your callback. Now, when that <script> tag gets evaluated, your callback function gets called with the data as its argument. Cross-domain JSON without anything done by us server-side!

Here is what it looks like in practice:

function remote_query() {
    url = 'http://api.twitter.com/1/statuses/user_timeline/kcbanner.json?callback=twitter';
    var script = document.createElement('script');
    script.src = url;
    document.body.appendChild(script);
}
 
function twitter(data) {
    // Do something with the results.
}

If you load that twitter url, you’ll see that it contains something like:

twitter([ A whole bunch of JSON ]);

So once the browser loads that script tag, it gets evaluated, and our twitter function gets called. No need for any XMLHttpRequests or server-side scripts.

Hopefully this was helpful!

Update: Apparently this is a well known technique called JSONP. I completely missed that in my googling. Thanks commenters!

-Casey

In-terminal tabbing with urxvt

Not many people know about the built in perl extensions to urxvt. There are a bunch of them, but the one I find most useful is tabbing.  All you have to do is add:

URxvt.perl-ext-common: default,tabbed

to your ~/.Xdefaults file, and restart your terminal.

You’ll get something like this:

The keyboard shortcuts are what make this awesome. Shift-down to create a new tab (or click ‘new’), and Shift-left/right to cycle between tabs.

-Casey

I miss the music

In high school I bought a couple Technics SL-1200MK2 turntables to play around with and to try my hand at mixing. I really enjoyed it, but when I moved to Ontario for school and work they had to be left behind, along with the crates of vinyl I accumulated. Most of the vinyl I have is house, electro house, trance, and various random novelty albums (Ghost Busters soundtrack!). I’m really looking forward to spending some quality time with the decks when I go home after exams.

Anyway, what got me thinking about this was listening to some awesome deep house mixes from http://soulshine.org/. He also has a great Sunday Snooze, and Laidback Niceness series for down-tempo, chilled out stuff.

-Casey

 

Stuff

Pages