Archive for March, 2010
Pulling cheap tricks with JQuery
by David on Mar.29, 2010, under Uncategorized
Let’s say you got some tabular data with input button/anchor tags that ideally will cause previously hidden data to appear.
Attempt 1 went like:
//Simulated row <td> <a href="#" onclick="$('#my_SubData<?= $currentRecordId ?>').slideToggle(); return false">Click me to show stuff!</a><br> <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div> </td>
I hate messy code, but unfortunately this is PHP so there’s only so much one borderline pyschotic developer can accomplish. Or is there?
//prior to my table $('a.actionable').live('click',function(){ $($(this).attr('href')).slideToggle(); return false; }); //Now <td> <a href="#my_SubData<?= $currentRecordId ?>')" class="actionable">Click me to show stuff!</a><br> <div id="my_SubData<?= $currentRecordId; ?>" style="display: none "> Blah blah blah....</div> </td>
It’s almost elegant if you ignore the PHP inject. JQuery’s .live handler automatically routes all unhandled click events to the closest “.actionable” classed element, then inside the live event handler, you grab the anchor’s href value to get the element Id of what you want to edit.
Stupid PHP tricks: The Array builder
by David on Mar.22, 2010, under Uncategorized
class ArrayBuilder { public function __set($name, $value){ return $this->$name = $value; } public function __call($name, $value){ if(count($value) == 1){ $this->$name = $value[0]; }else{ $this->$name = $value; } return $this; } public function toArray(){ return get_object_vars($this); } public static function FACTORY(){ return new ArrayBuilder(); } }
Usage:
$x = ArrayBuilder::FACTORY()->hello("World")->digits(1,2,3,4,5)->foo("BaR?")->toArray(); var_dump($x); array(3) { ["hello"]=> string(5) "World" ["digits"]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } ["foo"]=> string(4) "BaR?" }
Works great for factory scenarios and confusing the $*&! out of the unwary.
Hosting local, the ghetto fabulous way
by David on Mar.05, 2010, under howto
One of the first big draws of Ruby on Rails in late 2006 was the ability to host my development environment locally. Not only did this cut down on the chore work of developing in an environment, but it probably also boosted productivity for me substantially. A year later when I started teaching myself Python, another nail was hammered into the coffin that is my opinion of PHP. That said, I’ve toyed with a lot of different idea’s of hosting a PHP environment locally but to a degree stymied in the effort.
(continue reading…)
Bridging the gap: GIT & SVN, B.F.F.
by David on Mar.02, 2010, under howto
Background
I’ve been using SVN for several years now, since late 2005 or early 2006, and its done me well since then. But a new darling has entered my life and its name is Git. I like git for some very specific reasons: It’s stupid easy to work with and as good or better then SVN for reliability. Also it helps that my preferred IDE, Komodo, recognizes and works with Git as well.
That said, I use google code for hosting my public projects and it only supports SVN and HG. So one night I read up on git and noticed that it had a plugin/support for bridging to a SVN managed repo. So began my journey.
(continue reading…)
Canvas tag: Collision detection & pixel decay
by David on Mar.02, 2010, under Uncategorized
Continuing my tests/experiments with the Canvas tag has led to the Ping prototype. I had 3 minimal things I wanted to accomplish: Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and lastly a test of performance. In addition I decided to experiment with another approach to Javascript object construction in the hopes of getting a performance gain.
(continue reading…)