Objective-C / June 3, 2012

NSArray map

I had an NSArray of objects (all the same). I needed a property out of all of those objects. So I created a Category on NSArray to add this functionality. It loops through each object and performs a selector creating a new array from the results. One important note is that since you can’t put

Read More
PHP / July 7, 2011

PHP Delayed Invocation Object

By virtue of PHP’s many Magic functions it is possible and indeed quite easy to create an object that can be used to call a function or object method now, but have it invoked later. The reason I wrote this function was for lazy loading of data. I had the id’s and information required to

Read More
JavaScript / November 16, 2010

JS Generator – Newton’s Method

Basic implementation of the Newton’s Method for narrowing in on a square root. NOTE: in Firefox the yield keyword doesn’t exist unless the script tag loading the function has a type of “text/javascript;version=1.7”. version must be 1.7 or higher. [js] function newton(value, guess) { value = Math.abs(value); guess = Math.abs(guess); while (1) { guess =

Read More
JavaScript / October 4, 2010

Delegated AJAX

About a year ago I needed a quick and easy AJAX library to just grab XML or JSON. At that time I was working heavily in Objective-C on the iPhone which uses a lot of delegation of functionality. I wanted to build something similar for my web application. In most browsers the XMLHttpRequest object is

Read More
JavaScript / October 2, 2010

JS Generator – Fibonacci Example

[js] function fibonacci() { var i1 = 0, i2 = 1; while (true) { yield i1; var t = i1; i1 = i2; i2 += t; } } var g = fibonacci(); for (var i = 0; i < 10; i++) { document.write(g.next() + "\n"); } [/js] The function fibonacci contains the keyword “yield” making

Read More
JavaScript / October 1, 2010

First Post: JS Closure Example

While creating 10 <a> elements, each link pointing at a different id number. In that case, this example makes sense. [js autolinks=”false”] for (var i = 0; i < 10; i++) { var a = document.getElementById(‘a’); a.onclick = function(e) { location.href = ‘http://www.example.com/?id=’ + i; }; document.body.appendChild(a); } [/js] However, the creation of the anonymous

Read More