scriptNode

Web development with a focus on JavaScript RSS

Evaluating Script Tags Dynamically

Advanced Matt Hackett Published September 21st, 2008 by Matt Hackett

First, a disclaimer: dynamically evaluating scripts is not recommended! Indeed, if your application requires the usage of this script, chances are you're doing it wrong. The separation of design and logic likely hasn't been properly enforced if you're using this method. It's just an awkward use-case that should be avoided. That said, here it is…

Many JavaScript libraries support the evaluating of data returned via XHR. Some, like YUI, do not (yet). In other cases, folks have rolled their own "AJAX library" but still want this behavior. The below script supports searching HTML for scripts and evaluating them:

You can execute some examples yourself below:

Update 9/28/08: Fixed a bug thanks to Isaac Schlueter (see comments).

Read other articles tagged: , , ,

Software Development Meme

Novice Matt Hackett Published September 18th, 2008 by Matt Hackett

I've been tagged by the insanely creative Jacob Seidelin, which means it's my turn to fill out the Software Development Meme!

How old were you when you first started programming?

I was about 12 years old. That combined with my love of Nintendo really makes it sound like I never left the house, but I found time to play sports and get in trouble, really... ...

How did you get started in programming?

A mysterious friend of mine (Jim MacDonald, who all but doesn't exist online) and I used to play games all day, like Dragon Warrior and Shining Force. Then one day he wondered how games were made, and found...

What was your first language?

QBASIC! This has gotta be the easiest language to learn, and that says a lot in an age where PHP exists. I think more developers would benefit from starting with this fantastically simple language.

What was the first real program you wrote?

I wrote a program I simply called Dragon, which was a direct ripoff of Jim's game Wizard or something. It used QBASIC's DRAW commands to draw shapes and PLAY for sound effects. It was a single-battle, turn-based game pitting you (a knight) against a dragon. It was amazingly bad but pretty fun (for 12-year-olds anyway).

What languages have you used since you started programming?

Professionally: Only PHP and JavaScript

For fun and/or school: BASIC, C, C++, Perl, Python, QBASIC, Turbo Pascal, Visual BASIC

What was your first professional programming gig?

Working for Dav Glass at SchoolCenter. I was a PHP programmer making a measly $10/hour coding content management tools for K-12 schools. I was quickly promoted to lead designer (odd, right?), then when the company realized we needed engineers more than designers, put back into the development department. About a year after Dav moved to Yahoo!, I followed.

If you knew then what you know now, would you have started programming?

Oh hell yes. I'm always trying to learn as much as I can. Learning new languages is fascinating, and learning more about what you already are familiar with to me should be a daily exercise. If I had had the knowledge I have now when I was younger, I can't imagine what I would have built by now. Interesting to think about!

If there is one thing you learned along the way that you would tell new developers, what would it be?

In a normal curriculum in school, students are taught to read well before they are taught to write. I'm not sure why this isn't the case in programming. You've always got these wannabe developers that try to run before they can walk, and they end up tripping. There's no shame in beginning modestly.

I recommend to anyone of any programming level: read other people's code. The Internet is the ideal place to learn.

What’s the most fun you’ve ever had… programming?

Everytime I learn a new language, my first task is to build a game. I've been doing this for over a decade, in every single language I've dabbled in. But I think it was the most fun in QBASIC. I built an intentionally awful game called Seanbaby's Magic Bus Ride Trip for you guessed it... Seanbaby. Working in Flash is really fun too, but nothing beats JavaScript.

Who’s next?

Let's go with Isaac Schlueter, since he's a great writer and always has interesting things to say!

Read other articles tagged: , , ,

twittertyper

Intermediate Matt Hackett Published September 9th, 2008 by Matt Hackett

twittertyper

I unfortunately am not allowed to participate, but in anticipation of Yahoo!'s Hack Day 2008, I put together a little app I'll hopefully be able to port to YAP: twittertyper!

The concept is very simple. twittertyper displays the latest tweet from Twitter. To read the next one, first type out the tweet. The text is highlighted as you go. If you come across a character your keyboard (or operating system) won't let you type, just press Esc to move on to the next character.

twittertyper currently just pulls in from the public timeline; no authentication is supported to pull from your timeline (maybe in a future version). This mini-app is built on YUI. Source code (uncompressed) is free to peruse.

Try it out!

Note: If you use Twitter, I'm sure you're used to it being down. Errors happen often, but twittertyper attempts to handle them somewhat gracefully. Usually a page reload should suffice.

Read other articles tagged: , , ,
© 2009 scriptNode