<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Undefined Function</title>
	<atom:link href="http://undefinedfunction.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://undefinedfunction.org</link>
	<description></description>
	<lastBuildDate>Sat, 17 Apr 2010 03:06:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Simple IP Address &amp; Subnetting Class</title>
		<link>http://undefinedfunction.org/2009/10/simple-ip-address-subnetting-class/</link>
		<comments>http://undefinedfunction.org/2009/10/simple-ip-address-subnetting-class/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 00:30:48 +0000</pubDate>
		<dc:creator>Michael Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undefinedfunction.org/?p=13</guid>
		<description><![CDATA[On a few occasions, I&#8217;ve been faced with situations where I&#8217;ve needed to determine whether a given IP address was part of a particular subnet. Granted, usually PHP sites don&#8217;t need to worry about things like that, but sometimes it is necessary to restrict access to users in certain locations, or maybe you want a [...]]]></description>
			<content:encoded><![CDATA[<p>On a few occasions, I&#8217;ve been faced with situations where I&#8217;ve needed to determine whether a given IP address was part of a particular subnet. Granted, usually PHP sites don&#8217;t need to worry about things like that, but sometimes it is necessary to restrict access to users in certain locations, or maybe you want a reporting tool to be able to filter by a range of IPs when you click on an individual address.</p>
<p>To accomplish these tasks, I have written a couple of classes that are intended to simplify things. Rather than completely reinventing the wheel, I started with the excellent open source SubnetCalc project by Ramond Ferguson. I adapted the existing code into an object-oriented class structure, and updated the regular expression handling to use the superior preg_* functions to improve speed and future compatibility, as ereg has been deprecated. In addition to the detailed subnet calculation functions already offered by the project, I have added a few new features:</p>
<ul>
<li>Test if a given IP is a valid address</li>
<li>Determine IP type (node, network, or broadcast) based on the associated subnet schema</li>
<li>Test whether an IP is within in the subnet&#8217;s address range</li>
<li>Dynamically alter the subnet schema &#8212; calculations are automatically updated to the new values</li>
</ul>
<p>They always say the proof is in the pudding, so here are a couple of usage examples. First, let&#8217;s create an IP object. The class will automatically test to see that the IP is valid, and throw an exception if it&#8217;s not:</p>
<div class='code'>
<div class='title'>Create an IP object</div>
<pre>try {
	$ip = new IPAddress('192.168.1.12');
} catch( Exception $e ) {
	print $e;
}</pre>
</div>
<p>To assign a subnet mask, you can call the SetCIDR method:</p>
<div class='code'>
<div class='title'>Configure the subnet using SetCIDR</div>
<pre>$ip->Subnet->SetCIDR(24);</pre>
</div>
<p>And now your object is populated with a handful of useful calculations:</p>
<div class='code'>
<div class='title'>Output of the IPAddress object</div>
<pre>IPAddress Object
(
    [Address] => 192.168.1.12
    [Subnet] => Subnet Object
        (
            [Class] => C
            [Netmask] => 255.255.255.0
            [CIDR] => 24
            [Wildcard] => 0.0.0.255
            [Network] => 192.168.1.0
            [Broadcast] => 192.168.1.255
            [FirstHost] => 192.168.1.1
            [LastHost] => 192.168.1.254
            [Hosts] => 254
            [Private] => 1
        )

)</pre>
</div>
<p>You can also use the Subnet object by itself to perform simple calculations without a specific IP address, and you can call the IsValidHost() method to test an IP address to see if it fits in the subnet. An example of how this might look:</p>
<div class='code'>
<div class='title'>Working With Subnets</div>
<pre>try {
	$subnet = new Subnet("192.168.1.0/27");
        print $subnet->IsValidHost("192.168.1.21") ? "YES" : "NO";
        print $subnet->IsValidHost("192.168.1.64") ? "YES" : "NO";
} catch( Exception $e ) {
	print $e;
}</pre>
</div>
<p>In this example, a subnet is created, with possible hosts from 192.168.1.1 to 192.168.1.30. So the first print statement would display &#8220;YES&#8221;, since node 21 falls within the subnet, and the second statement would display &#8220;NO&#8221;, as node 64 is not part of the subnet.</p>
<p>If you would like to try these out for yourself, you can <a href='http://scripts.undefinedfunction.org/downloads/phpiplib-1.0.tar.gz'>download the classes here</a>. Thus far, the class seems to work well for my purposes, but as this is based on some unfamiliar code from another project, I could have easily missed something. I will continue to fine tune the code, and will be doing some minor cleanup on the imported functions as time permits, so be sure to check back periodically for any updates.</p>
]]></content:encoded>
			<wfw:commentRss>http://undefinedfunction.org/2009/10/simple-ip-address-subnetting-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yay for power outages</title>
		<link>http://undefinedfunction.org/2009/08/yay-for-power-outages/</link>
		<comments>http://undefinedfunction.org/2009/08/yay-for-power-outages/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 23:19:51 +0000</pubDate>
		<dc:creator>Michael Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undefinedfunction.org/?p=11</guid>
		<description><![CDATA[I love unexpected power outages, especially when they last for hours and prevent me from getting work done. So, if you couldn&#8217;t reach some of my less important sites, including this one, that&#8217;s why.]]></description>
			<content:encoded><![CDATA[<p>I love unexpected power outages, especially when they last for hours and prevent me from getting work done. So, if you couldn&#8217;t reach some of my less important sites, including this one, that&#8217;s why.</p>
]]></content:encoded>
			<wfw:commentRss>http://undefinedfunction.org/2009/08/yay-for-power-outages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apple and the App Store</title>
		<link>http://undefinedfunction.org/2009/07/apple-and-the-app-store/</link>
		<comments>http://undefinedfunction.org/2009/07/apple-and-the-app-store/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 01:30:49 +0000</pubDate>
		<dc:creator>Michael Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undefinedfunction.org/?p=9</guid>
		<description><![CDATA[I&#8217;ve had a very interesting response to my recent TUAW article regarding the removal of Google Voice from the App Store. Reader &#8220;VanillaSpice&#8221; gave some good insight into his opinion of the whole ordeal, and I think it&#8217;s worth reposting our exchange here: The way refunds are handled is explained (very clearly) in the developer [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a very interesting response to my recent TUAW article regarding the removal of Google Voice from the App Store. Reader &#8220;VanillaSpice&#8221; gave some good insight into his opinion of the whole ordeal, and I think it&#8217;s worth reposting our exchange here:</p>
<blockquote><p>The way refunds are handled is explained (very clearly) in the developer agreement, and each developer signs and agrees to that agreement. What you don&#8217;t do is, knowingly sign a contract and then complain about the terms. What you DO do is, don&#8217;t sign the contract at all if you don&#8217;t like it.</p>
<p>Every developer knew &#8211; before they signed &#8211; that the refund process meant they could be refunding more than 100% of their revenue. Their only two options &#8211; complain and don&#8217;t sign, or sign and don&#8217;t complain. Those who sign and complain have only themselves to blame, they KNOWINGLY signed up to this deal!</p></blockquote>
<p>Actually, if I remember correctly, for many developers the refund option didn&#8217;t even exist initially, and many developers were upset when it appeared in a later update to the agreement.</p>
<p>Either way, it&#8217;s a good point, since developers pretty much do agree to those terms just like many consumers agree to ridiculous terms on credit cards, and then complain when they are hit with huge fees because they didn&#8217;t actually read what they were agreeing to. And in this case, it&#8217;s no fault of Apple&#8217;s if the dev didn&#8217;t read their agreement. Luckily, in most cases, it doesn&#8217;t appear that Apple enforces it anyways.</p>
<blockquote><p>I do believe, personally, that users should only ever get from the developers the amount the devs have actually been paid, and no more, but then, I didn&#8217;t sign the agreement, hey.</p>
<p>&#8220;And yes, there are over 10,000 developers, 65,000 apps, 40 million devices, and 1 billion downloads from the App Store. But none of that matters unless you realize that the developers themselves are directly responsible for much of the iPhone&#8217;s success. By alienating those developers through inconsistent policy handling and refusal to communicate one-on-one with them to resolve problems, Apple is setting itself up for failure.&#8221;</p>
<p>I disagree with this. I think it *does* matter that 10,000 devs have made 65,000 apps without much hassle, and yet the number of rejections and complaints is &#8230; what? A dozen? A few dozen?</p></blockquote>
<p>Okay, I could have used better wording instead of saying &#8220;It doesn&#8217;t matter,&#8221; but I think you underestimate the number of rejections and complaints that actually happen. Yes, when compared to the total number of 65,000 apps, even saying as many as maybe (just throwing a number out there) 5,000 of those apps were rejected seems insignificant.</p>
<p>But looking at it from a different angle, we here at TUAW get a good number of e-mails regarding apps that were rejected or complaints about the approval process on a DAILY basis. Yeah, some are repeats and some days are more than others, but still, there is a much larger volume of rejections and complaints than what actually gets covered in the media.</p>
<blockquote><p>I think it is very important for you to put things in context, otherwise you are misrepresenting the true situation &#8211; you&#8217;ve basically made it sound, from the article, that all developers have a problem with Apple, when in fact, we&#8217;ve only heard that a dozen or so do (out of 10,000 &#8211; that is a very small percentage!)</p></blockquote>
<p>Agreed. But what I believe the real problem is doesn&#8217;t lie in the number of developers affected, as much as in the significance of the problems those developers have faced.</p>
<p>If it were just a handful of devs getting apps rejected for blatantly violating terms of the SDK, I don&#8217;t think there&#8217;d really be much to complain about, and we wouldn&#8217;t be having this discussion. But what&#8217;s happening is individual developers hit snags with Apple, where they follow all of the rules but, for one reason or another, Apple removes/rejects their app or some other problem arises that makes everyone stop and wonder what is going on.</p>
<p>And it is here that Apple stumbles, because they don&#8217;t deal with the problem in an efficient manner, they usually either give vague, inconsistent responses to the developer, or they choose not to communicate at all. Then the developer gets upset, the media gets involved and it becomes a big PR nightmare, and only then does Apple (sometimes) step in and make an attempt to remedy the situation. But by that time, the damage is already done.</p>
<blockquote><p>I also disagree with the overall tone of the article which suggests that Apple benefits from developers while developers do not benefit from Apple at all.</p></blockquote>
<p>That&#8217;s not the tone I intended, so I apologize if that&#8217;s what you&#8217;re getting from it. The intention was to express and convey the frustration with Apple&#8217;s decision to pull the GV apps, and claim that they were &#8220;duplicating functionality&#8221; rather than being open and honest with developers about the true reasons for their removal and offering methods of recourse; their lack of communication to the parties involved when they encountered the problem; and the effects of penalizing the developers with refunds for a decision that really was not the developer&#8217;s fault.</p>
<blockquote><p>No developer designed, created and marketed the iPhone and App Store. That was Apple. But developers have been able to use this new market to make money &#8211; we know that some devs have profited (and profited well) from the App Store. So I think it is abundantly clear that devs have benefited from Apple as well as the reverse.</p></blockquote>
<p>Completely agree.</p>
<blockquote><p>Lastly, I don&#8217;t agree that Apple is setting themselves up for failure &#8211; I remember similar comments about Nintendo abandoning the polygon count race, and we know how that turned out.</p>
<p>Sometimes, decisions that look wrong on first glance, turn out to be right. This has been true of Apple in the past. It was wrong for Apple to launch a smartphone without copy-and-paste, without multitasking, without a replaceable battery, wasn&#8217;t it? More like 40 million points of right. Apple correctly identified what people wanted and needed, while most everyone else fell over themselves declaring that Apple had set themselves up for failure.</p></blockquote>
<p>This can be interpreted very differently, depending on how you define failure. Do I think that the App Store will collapse, killing the viability of the iPhone platform and destroy the future of Apple? Definitely not. But I think that it is reasonable to believe the App Store (and by effect, Apple) could ultimately be less successful as a result of these problems. Sure, they might have achieved their goal to create a viable platform that allows developers to easily create apps and users to easily find those apps, but the attitude they choose to use when interacting with developers and dealing with problems harbors more dissent and unwelcome feelings among the community, which has proven to be detrimental to many platforms over the years.</p>
<blockquote><p>I think you are discounting how much the iPhone&#8217;s and iPod Touch&#8217;s stability and friendliness comes from Apple&#8217;s &#8220;crazy&#8221; rules and the heavy-handed imposition of them, and I think you are blatantly assuming that Apple has had no reason to ever pull and reject apps. Apple might not be saying, but that does not mean that they don&#8217;t have a reason and that it isn&#8217;t a good one.</p></blockquote>
<p>Valid points, though I don&#8217;t assume that Apple has had no reason to pull or reject apps. My contention lies in the fact that they hide their reasons behind vague and inconsistent policies. If you&#8217;re going to reject application X for having a particular feature, then you need to reject applications Y and Z if they have the exact same feature. To me, it&#8217;s fine if they have to pull an app from the store, but they need to take the developer of the app aside, and explain to them exactly why it is being pulled, and what options of recourse they might have to prevent it (if the pulling is due to a specific element of the application).</p>
<p>I mean, seriously, the developer is already under an NDA, so just remind them that under the terms of that NDA, they cannot disclose the reason the app was pulled to the public, and take them to court if they leak the details. And, if for some reason Apple simply *can&#8217;t* disclose to the developer their reasoning, don&#8217;t hide behind a vague claim that is obviously untrue, but instead tell the developer outright that they are unable to disclose the details, and then offer an olive branch to them by suggesting some form of recourse or compensation or *something* for the trouble.</p>
<p>But yeah, I agree that they might have reasons that they are not willing to discuss. And if they are going somewhere with those reasons, that&#8217;s fine. But they still need to keep an open line of communication to the developers. Even if that just means someone calling them up or sending a personal e-mail an saying something like this:</p>
<p>&#8220;Look, I&#8217;m really sorry, but we have to pull your app from the store. You didn&#8217;t do anything wrong, but we have to remove it for technical reasons. I&#8217;m afraid I can&#8217;t go into details at this time, but we will do our best to let you know if and when it can be resubmitted. I realize that you have put a lot of time and effort into this application, and due to the circumstances, we are willing to offer you ________________. In exchange, we ask you to keep the terms of this arrangement confidential, please inform users that the application had to be removed due to technical difficulties. In the event that refunds are requested, we will work with you on those cases.&#8221;</p>
<p>To me, a simple conversation like that would go A LONG WAY to keeping good spirits about the situation. Yes, it would still be a bit frustrating, but at least you&#8217;d have the feeling that *someone* at Apple actually cared, which unfortunately, doesn&#8217;t seem to be the case with many of these stories.</p>
<p>Ok, I&#8217;m done now. <img src='http://undefinedfunction.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://undefinedfunction.org/2009/07/apple-and-the-app-store/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplify Reporting Output</title>
		<link>http://undefinedfunction.org/2009/03/simplify-reporting-output/</link>
		<comments>http://undefinedfunction.org/2009/03/simplify-reporting-output/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 05:16:47 +0000</pubDate>
		<dc:creator>Michael Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undefinedfunction.org/?p=4</guid>
		<description><![CDATA[Recently, I have been tasked having to generate several reports containing various metrics, and then export these into an Excel sheet so that the data can be processed further.  I also occasionally get requests for data in a CSV format that can be imported into another system.  And these are just for the one-off reports&#8230; [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">Recently, I have been tasked having to generate several reports containing various metrics, and then export these into an Excel sheet so that the data can be processed further.  I also occasionally get requests for data in a CSV format that can be imported into another system.  And these are just for the one-off reports&#8230; most of the standard reporting tools I have written produce data in an XML format, which is then procssed by an AJAX frontend and displayed in an HTML table to the user.  Talk about messy.</div>
<div id="_mcePaste">So this morning, I finally sat down and wrote out a report abstraction class that has been floating around in my head for the past couple of months.  Rather than have to worry about writing display code when building a report, I can simply deal with the data and hand it over to the class for display processing:</div>
<blockquote>
<div id="_mcePaste" style="text-align: left;">$Report = new Report( &#8220;My Report&#8221; );</div>
<div id="_mcePaste" style="text-align: left;">if (isset($_GET['format'])) {</div>
<div id="_mcePaste" style="text-align: left;">$Report-&gt;Type = $_GET['format'];</div>
<div id="_mcePaste" style="text-align: left;">}</div>
<div id="_mcePaste" style="text-align: left;">$Report-&gt;Columns = array(&#8220;Employee&#8221;, &#8220;Department&#8221;, &#8220;Salary&#8221;);</div>
<div id="_mcePaste" style="text-align: left;">foreach ($Employees as $Employee) {</div>
<div id="_mcePaste" style="text-align: left;">$Report-&gt;Rows[] = array($Employee-&gt;Name, $Employee-&gt;Department, $Employee-&gt;Salary);</div>
<div id="_mcePaste" style="text-align: left;">}</div>
<div id="_mcePaste" style="text-align: left;">$Report-&gt;Display();</div>
</blockquote>
<div style="text-align: left;">From there, the class takes the type identifier (which in this case is being selected by the user and passed in the URL), and provides the data in the correct format.  The class itself is fairly small, weighing in with less than 200 lines of code, but can display data in Excel, CSV, XML, HTML, or PDF, as well as a printer-optimized layout if the data is intended to be printed instead of displayed on-screen.</div>
<p>Recently, I have been tasked having to generate several reports containing various metrics, and then export these into an Excel sheet so that the data can be processed further.  I also occasionally get requests for data in a CSV format that can be imported into another system.  And these are just for the one-off reports&#8230; most of the standard reporting tools I have written produce data in an XML format, which is then procssed by an AJAX frontend and displayed in an HTML table to the user.  Talk about messy.<br />
So this morning, I finally sat down and wrote out a report abstraction class that has been floating around in my head for the past couple of months.  Rather than have to worry about writing display code when building a report, I can simply deal with the data and hand it over to the class for display processing:</p>
<blockquote><p>
$Report = new Report( &#8220;My Report&#8221; );<br />
if (isset($_GET['format'])) {<br />
                 $Report-&gt;Type = $_GET['format'];<br />
        }<br />
        <br />
$Report-&gt;Columns = array(&#8220;Employee&#8221;, &#8220;Department&#8221;, &#8220;Salary&#8221;);<br />
        foreach ($Employees as $Employee) {<br />
                $Report-&gt;Rows[] = array($Employee-&gt;Name, $Employee-&gt;Department, $Employee-&gt;Salary);<br />
        }<br />
        $Report-&gt;Display();
</p></blockquote>
<p>From there, the class takes the type identifier (which in this case is being selected by the user and passed in the URL), and provides the data in the correct format.  The class itself is fairly small, weighing in with less than 200 lines of code, but can display data in Excel, CSV, XML, HTML, or PDF, as well as a printer-optimized layout if the data is intended to be printed instead of displayed on-screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://undefinedfunction.org/2009/03/simplify-reporting-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
