Chomper Stomping jQuery/JavaScript/CSS 3/HTML 5, Java/PHP/Python/ActionScript, Git, Chrome/Firefox Extensions, Wordpress/Game/iPhone App Development and other random techie tidbits I've collected

27May/110

Introducing Limeberry

HTML5_Styling_512

Limeberry is a CSS 3 Finely Granular Color Gradient Generator. It allows you to input very precise (up to the nth decimal) numeric values to be used as your gradient color stops. Choose how many color stops you want and then define what colors you want at those stops.

 

This is definitely early beta. It's functional, but only just (but hey, I did it in an hour over my lunch break).

 

Check out the project page to see the roadmap and for info on how to contribute (this is an open source project).

 

This was developed with Chrome, but early testers have informed me it works with Firefox and Opera as well (yay!).

14Jan/110

Yet Another Reason to Namespace your JavaScript Variables

1306092411709_a923d

If you aren't namespacing your JS variables, you should be.

There are a plethora of great reasons to do so, which I won't go into here, but I just stumbled upon another great reason today.

It makes your code faster.

What? Yeah. According to my preliminary tests...

You can see here that we are running through three while loops two million times.

The first time we are creating a variable local to the while loop each time and incrementing it by 1 each time.

The second time we are referencing a global namespaced (namespaced to the random characters "GL" for absolutely no reason) variable and incrementing it by 1 each time.

The third time we are referencing a global variable (not namespaced) and incrementing it by 1 each time.

You'd think that the second and third times would be nearly identical. They aren't. Check out the results:

That's right, the local variables loop took 1584ms, the namespaced one took 1180ms and the global one took 1219ms. The namespaced one is consistently faster.

Now, think about an E-Commerce website with 50,000+ lines of JavaScript code. If these results mean what they seem to mean, imagine the performance improvements to be gained simply by namespacing your functions, variables, etc. Potentially huge? Maybe, this bears some looking into.

EDIT: These results were just bothering me. A lot. It didn't make any sense. So I Made a JSLitmus test to see if it was maybe just a firebug thing. Nope. Same results, actually even more disparate results in some browsers:

Try it for yourself (doesn't work in IE 9 for some reason).

Feel free to comment with any more tests/data you know of on this subject, I'd love to hear.

23Jun/100

Flurl – Part 5: The Unicorn/Panda Rainbow Connection

2011-05-23_1043

Wait, where's parts 2 through 4? Not done yet, but I'm done with the project and I may never get around to posting those other parts and wanted to post the finished product.

Again, Flurl is a little practice exercise I did. A mashup of Flickr and Qurl and no external JS libraries used (so I wrote my own).

I'm taking this photo stream (Be careful, since the photos are completely random "popular" flickr photos, even though they purport to be "safe" there are definitely some NSFW photos now and then) and sending the URLs to Qurl for shortening (using their API). This is the end result (best experienced in Chrome): The Unicorn/Panda Rainbow Connection UPDATE: LOST FOREVER (maybe... When my site got hacked I deleted a whole bunch of stuff trying to flush out the bad code. Apparently this got whacked in the process. I *might* have a copy somewhere, but, can't find it right now).

Some thoughts: Qurl sucks as far as response time. I had to limit my photos to five because Qurl was so darn slow responding to my requests and there is no way to do a batch request. BAD. What would I do to fix this? How about dump Qurl entirely. Flickr has their own shortening algorithm that doesn't even require an API call. If I had to keep using Qurl? I'd go ahead and load the photos to the page for the user with the long links, then I'd make a button on the photo (or link or something) that allowed them to request a shortened URL from Qurl. They click the button/link and an AJAX request fires off grabbing the URL and giving it to them.

I couldn't get the Flickr API to return only a certain number of Photos. I did everything I could find that it said I should do to get it to only return five or ten photos, but alas, it didn't work. So I had to make a loop that just used the first five/ten photos and ignore the rest. If it weren't for Qurl, which takes over 30 seconds most times to shorten 5 urls, I wouldn't care how many Flickr sent back. Still weird and wasteful and if I had more time I'd look into it until I got it working.

When I removed Qurl from the loop, the photos returned in less than five seconds flat (awesome!). However, with Qurl the response time ranges from 30s to 90s. So AS SOON AS I get the response back I fire off another request. If the response only took 5s total, I'd put a timeout or interval or something that queried only once a minute or so. Or, better yet, I'd make it fire off the request 10 seconds before my photo scroll ended and just put the new photos above my current scroll and make the scroll seem endless (like the pandas).

I spent far too much time on the library. I had big plans and it turned out I wrote way more code than I ended up needing because I was doing VERY LITTLE DOM manipulation. Of course if I worked on this for another forty hours or so the library really would have paid off because it would have saved me time as my interactions got more and more complex. If I had come up with the full design before I started writing the code I would have known I wasn't going to need much DOM interaction, but as it stands I didn't have any idea what the page was going to look like until I was almost completely finished with the cQuery JS library.

Queue. Something interesting I came up with was a way of handling mutliple simultaneous AJAX requests and multiple simultaneous animations. A queue.

For the AJAX requests I had an AJAX queue that just held all of my requests (didn't end up needing this, but it is there if I decide to do the Qurl thing separate from the photo retrieval). I hope to go into the AJAX queue in more detail in another post, but the reason I needed it was the callback function. I needed somewhere to put it until the request completed.

For the animation queue, I didn't want to set up a whole bunch of different "set intervals" or "set timeouts" so instead I made an "animations" array and then made ONE setInterval that called a function that looped through the animation array. Each spot in the array held an "animation" Object, which had an "animate()" function. The animate function would get called on the object and be allowed to run in the proper context (with "this" functioning as expected). This ended up saving me a lot of code and headaches and made my JS run way faster than it otherwise would have. Of course I ended up only having one animation run at a time and I have no standard way of removing from the queue, but I could add that to the library and there is definitely room for more animations.

One last thing, the song is from Jonathan Neal (who is hilarious). I converted it to .ogg format because Firefox didn't allow anything else, however it appears that Safari doesn't accept .ogg format, so if I had more time I'd make something to detect with browser I'm in and respond with the .mp3 format instead...

22Jun/102

CSS 3 Animation? Yes Please!

Ok, I'm so mega busy right now working on Flurl. I need to have it done TONIGHT because I've got other pressing obligations coming up and I just won't have any time to work on it after today.

I wanted to have movement and sound and I wanted it REALLY CORNY as an homage to the flickr pandas from whom it gets it's photos.

Here's a little preview (Webkit only).

That's just a little taste. It's going to be much more. It's going to have music and it's going to have a photo stream.

Just a little tid-bit though I wanted to explain how I animated it (It's a grand total of 62 lines from <html> to </html>). I didn't use any JavaScript at all, it's all CSS3 (amazing!).

First I designed the animation:

@-webkit-keyframes turnit{
from{
-webkit-transform: rotate(0deg);
}
to{
-webkit-transform: rotate(-364deg);
}
}

Yeah, really simple I know. I'm just telling it to rotate from 0deg to -364deg. Note that I named the animation "turnit".

Next I applied the animation to my div.

#turningBG{
-webkit-animation-name: turnit;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 30s;
-webkit-animation-timing-function: linear;
}

Line 1: use the animation "turnit" we defined before. NOTE THAT THE ANIMATION DEFINITION MUST COME BEFORE WE TRY AND APPLY IT. If I tried to use it before I defined it in my stylesheet, nothing would happen.
Line 2: Loop forever.
Line 3: Last for 30s.
Line 4: Make it smooth (linear). Could ease-in or out or whatever, but I wanted it to be seamless with no apparent start or stop.

Notes: If you look at the source you will see that I made my turning div 3200px wide and tall and then put it inside of a container that was 100% wide and tall and overflow hidden to keep there from being scrollbars. I then positioned the div so the center of it would be right under the unicorn's foot.

Here's some reference for css3 animation stuff. Here's some more.

Here's the entire "view source":

8Feb/100

TOTW: Dynamic Dummy Image Generator

This week's Tool of the Week is Dynamic Dummy Image Generator.

What it does:

Allows you to display custom sized dynamic images on any webpage using nothing but a normal image tag and a special URL.

When you need it:

  • Mockups
  • Prototypes
  • Place Holder Images

How to use it:

The Example:

21Dec/090

TOTW: Firebug HTML > Layout

This week's tool of the week is another component of Firebug, the "Layout" tool.

What it does:

Allows you to edit html element box dimensions directly in the browser to get that perfect witdh/height/padding/margin/border combo you're looking for.

When you need it:

  • Resolving float issues
  • Adjusting Padding/Margin
  • Prototyping Layouts

How to use it:

Screencast on screencast.com

The example:

14Dec/092

TOTW: Spoon.net/browsers

This weeks Tool of the Week is spoon.net's browser sandbox tool.

What it does:

Allows you to run sand-boxed versions of each of the major (and minor) browsers from within Firefox.

When you need it:

  • Cross browser testing
  • Running multiple versions of the same browser at once

How to use it:

Screencast hosted on screencast.com

7Dec/090

TOTW: Firebug Console

This is a special Tool of the Week, because it focuses on a sub-set of a larger tool. This week's Tool of the Week is the console feature of the Firefox extension Firebug by Joe Hewitt, Rob Campbell, FirebugWorkingGroup.

What it does:

Allows you to run commands and play with the JavaScript on a web page, as well as output information from a webpage through a dos/shell style console; all from within the browser window. It's as if you "opened the hood" of the browser and started running diagnostics/talking to the robot that controls the page display.

When you need it:

  • prototyping JavaScript
  • debugging JavaScript
  • writing JavaScript

How to use it:

Please note that this doesn't even BEGIN to scratch the surface of the power of this little tool. Check out the documentation, here and here.

The Example: