Recently I deceided to explore requestAnimationFrame as a way to peer behind the jQuery.animate veil. While you should absolutely use jQuery.animate (or similar) when working on a "real" project, the results were pretty interesting:
Interestingly enough, the actual animation code is almost dwarfed by the code providing the API and fiddling with css properties to make sure they're in the right format.
Enough chit-chat, where's the bouncing ball?
I'm so glad you asked, I've even implemented the obligatory bouncing ball. Go take a look!
Last day of Io and what do we have? A small snippet that adds [1, 2, 3] style array literals to the language. Kind of neat that you can do it... also the kind of thing that can almost certainly get you in trouble.
... and a Builder document ends up looking like this:
Builderul(li("some text")attr("class","first"),li("some more text"),li("even more text")attr("class","last"))attr("class","fancy")attr("id","menu")render(0)
... and here's something that approaches useful: A two-dimensional matrix class that's backed by a one-dimentional list. It includes getter, setter and iterator methods. Yay!
Matrix:=ObjectMatrixdim:=method(x,y,selfwidth:=xselfheight:=yselfbuffer:=list()selfbuffersetSize(x*y))MatrixcheckBounds:=method(x,y,if(x>=widthory>=height,Exceptionraise("index out of bounds")))Matrixget:=method(x,y,checkBounds(x,y)returnselfbufferat(x+y*width))Matrixset:=method(x,y,value,checkBounds(x,y)selfbufferatPut(x+y*width,value))MatrixforEach:=method(f,for(y,0,height-1,for(x,0,width-1,fcall(x,y,selfget(x,y)))))
Io is the second language covered in Seven Languages in Seven Weeks and it is substantially further off the beaten path than Ruby was. The first day's worth of exercises didn't really have anything code snippet worthy, so here's recursive Fibonnaci to prove that I got the VM running ;-)
The emphasis for the final day of Ruby was on metaprogramming using open classes and mixins. So without further ado, here's a CSV reader that provides a mixin that lets you access the values of a CSV file using dynamic properties (Whee!):