Skip to main content

Posts

Showing posts from May, 2010

ActionScript: JavaScript Event Handlers for JW Player

JW Player has a rich JavaScript API. One of the things you can do is to create JavaScript event handlers for ActionScript events. However, there are a few things that can bite you in the butt if you don't keep them in mind.

First of all, as the documentation points out, you can't set an event handler until JW Player is ready for it. If you set it too early, it won't work, and you won't even get an error message. If you have a function called playerReady, it'll automatically be called by JW Player. That's a great place to setup your handlers.

Next, when JW Player calls playerReady, it's supposed to pass an obj containing the ID for the HTML DOM object. In my experience, it doesn't. Hence, you have to lookup the object manually. See my previous post about the fact that you can't use jQuery's $() to lookup the object, but should instead stick with document.getElementById.

Last of all, remember that when you give JW Player your JavaScript callb…

ActionScript: jQuery and ActionScript Callbacks

Let's suppose you have a SWF, and you're calling callbacks on that SWF from JavaScript. The following works:document.getElementById('id-of-your-embed').someActionScriptCallback('someJavaScriptCallback')The following doesn't work, and there is no error message:$('#id-of-your-embed').someActionScriptCallback('someJavaScriptCallback')I often think of $() as a way to use document.getElementById, but since it returns a jQuery shim, some things don't work as expected. This one took me quite a while to figure out.

Neuroscience: Burn-out Visible in the Brains of Patients

I just found this on Hacker News: Burn-out visible in the brains of patients. Since I've suffered from burnout for about a decade, this comes as no surprise to me.

Try to do pushups until you can't do any more. Now, wait a minute, and then do 50 more pushups. That's the best way I can explain what burnout feels like--my brain just feels like jello a lot of times.

I'm sure a lot of other programmers have to deal with this just like I do.

Apple: iPad and Emacs

Someone asked my boss's buddy Art Medlar if he was going to buy an iPad. He said, "I figure as soon as it runs Emacs, that will be the sign to buy." I think he was just trying to be funny, but his statement is actually fairly profound.

It's well known that submitting iPhone and iPad applications for sale on Apple's store is a huge pain--even if they're free and open source. Apple is acting as a gatekeeper for what is and isn't allowed on your device. I heard that Apple would never allow a scripting language to be installed on your iPad because it would allow end users to run code that they hadn't verified. (I don't have a reference for this, but if you do, please post it below.) Emacs is mostly written in Emacs Lisp. Per Apple's policy, I don't think it'll ever be possible to run Emacs on the iPad.

Emacs was written by Richard Stallman, and it practically defines the Free Software movement (in a manner of speaking at least). Stal…

Books: The Little Schemer

I just finished The Little Schemer. I liked it. It's a very short book. Most of my time was spent doing the exercises, which were very worthwhile. There were a few sections I had to read twice, but the book was far more accessible than say SICP. If you've never coded in Lisp or Scheme or if you're looking for some good exercises for your coding fu, I highly recommend this book. Happy hacking!

Python: The Halting Problem

I've been reading The Little Schemer, and I particularly enjoyed learning about the halting problem. I enjoyed learning about it so much that I figured I'd take the time to explain it in Python so that other Pythonistas could enjoy it with me ;)

Let's suppose I have two functions:def does_stop():
return True

def does_not_stop():
while True:
passdoes_stop does stop. does_not_stop does not stop. How do I implement the following function:def will_stop(f):
"""Return True if the function f eventually stops, and False otherwise."""
...Let's suppose for a moment that I can implement such a function. Now, let's look at this function:def just_might_stop():
return will_stop(just_might_stop) and does_not_stop()Does just_might_stop stop or does it continue forever? That is, what is the value of "will_stop(just_might_stop)"?

Well, I don't know yet, but let's suppose that "will_stop(just_might_stop)&quo…

Scheme: My Y Combinator

I've been reading The Little Schemer, and it posed an interesting question: how can you create a recursive function without having the ability to "define" a name for it? For instance, in Scheme, how can you create a simple, recursive function to calculate the length of a list without having the ability to use "define"?

Here's my approach:((lambda (my-length l)
(my-length my-length l))
(lambda (my-length l)
(cond
((null? l) 0)
(else (add1 (my-length my-length (cdr l))))))
'(1 2 3 4 5))The outer function is "(lambda (my-length l) ...)". It takes a reference to a function that it calls my-length. It calls that function "(my-length my-length l)". Hence, that function, which I call "my-length", receives the list as well as a reference to itself, "(lambda (my-length l) ...)". Since it receives a reference to itself, it's able to call itself recursively.

It turns out the real answer is called the…

Humor: An Environmentally-friendly Desktop

In an effort to be more environmentally conscious, I've decided to make my desktop more green. And although my sympathies lie with California's Central Valley farmers, I've also decided to show my support of the delta smelt by switching to a shell called "fish".

Do I think my actions will solve global warming? No--but it's important for each of us to do our part!

Linux: fish: The Friendly, Interactive Shell

I'm trying out a new shell called fish. Here are some screen shots and here is a great article to help you get started.

Usually, I'm a zsh user. fish aims to be as powerful as, say, zsh, but a heck of a lot easier to use and a lot easier to learn. So far, that's proven true. The shell provides intelligent tab completion, syntax highlighting, helpful error reporting, integrated documentation, etc.

Fish is inspired by Bourne shell syntax, but is not compatible with it. Specifically, a lot of ugly things have been cleaned up and made more regular. I do think that the syntax is nicer, although it takes a while to get the hang of if you're already a shell expert. About the only inconvenient part of switching to fish is that I can no longer copy and paste complicated bash one-liners from various places online.

The documentation is excellent. However, you might find this cheat sheet helpful for getting started:help:
: Get help with using fish.
Searching through history:
:…