<?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>Chris Kankiewicz &#187; Scripting</title>
	<atom:link href="http://www.chriskankiewicz.com/posts/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chriskankiewicz.com</link>
	<description>Web Design &#8226; Graphic Design &#8226; Code</description>
	<lastBuildDate>Thu, 27 May 2010 21:26:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>First Friday script updated and simplified</title>
		<link>http://www.chriskankiewicz.com/posts/2009/02/14/first-friday-script-updated-and-simplified/</link>
		<comments>http://www.chriskankiewicz.com/posts/2009/02/14/first-friday-script-updated-and-simplified/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 02:40:04 +0000</pubDate>
		<dc:creator>Chris Kankiewicz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[2600]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[First Friday]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Update]]></category>

		<guid isPermaLink="false">http://www.web-geek.net/?p=804</guid>
		<description><![CDATA[NOTE: The latest version of this script can always be found here: http://github.com/PHLAK/first-friday/blob/master/first-friday.php With this update I have drastically reduced and simpified the code to produce the same results.  I did some rigorous testing of my own to make sure &#8230; <a href="http://www.chriskankiewicz.com/posts/2009/02/14/first-friday-script-updated-and-simplified/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: </strong>The latest version of this script can always be found here: <a href="http://github.com/PHLAK/first-friday/blob/master/first-friday.php">http://github.com/PHLAK/first-friday/blob/master/first-friday.php</a></p>
<p>With this update I have drastically reduced and simpified the code to produce the same results.  I did some rigorous testing of my own to make sure this script will calculate the correct date, but that doesn&#8217;t mean it&#8217;s bullet-proof.  If you find a bug, please email me so I can fix it.</p>
<p><strong>first-friday.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
  <span style="color: #666666; font-style: italic;">// Calculate next Friday</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$timeStamp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'w'</span><span style="color: #339933;">,</span><span style="color: #000088;">$timeStamp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$nextFriday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// Check if next Friday is the first friday of the month.</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nextFriday</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$firstFriday</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nextFriday</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Calculate first Friday of next month</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$timeStamp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'w'</span><span style="color: #339933;">,</span><span style="color: #000088;">$timeStamp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$firstFriday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Echo next first Friday</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F j, Y&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$firstFriday</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.chriskankiewicz.com/posts/2009/02/14/first-friday-script-updated-and-simplified/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Calculate the first Friday of next month with PHP</title>
		<link>http://www.chriskankiewicz.com/posts/2008/10/20/calculate-the-first-friday-of-next-month-with-php/</link>
		<comments>http://www.chriskankiewicz.com/posts/2008/10/20/calculate-the-first-friday-of-next-month-with-php/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 05:50:40 +0000</pubDate>
		<dc:creator>Chris Kankiewicz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[First Friday]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHX2600]]></category>

		<guid isPermaLink="false">http://www.web-geek.net/?p=597</guid>
		<description><![CDATA[UPDATE: This script has been updated, see: http://www.web-geek.net/posts/2009/02/14/first-friday-script-updated-and-simplified/ While developing phx2600.org, I ran into a slight dilemma.  The PHX2600 meetings occur once a month on the first Friday of every month, and we wanted to display that on the site.  &#8230; <a href="http://www.chriskankiewicz.com/posts/2008/10/20/calculate-the-first-friday-of-next-month-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> This script has been updated, see: <a href="http://www.web-geek.net/posts/2009/02/14/first-friday-script-updated-and-simplified/">http://www.web-geek.net/posts/2009/02/14/first-friday-script-updated-and-simplified/</a></p>
<p>While developing <a title="PHX2600 - Phoenix, Arizona Netowrk of Hackers" href="http://www.phx2600.org" target="_blank">phx2600.org</a>, I ran into a slight dilemma.  The PHX2600 meetings occur once a month on the first Friday of every month, and we wanted to display that on the site.  However, it was becoming a tedious chore to change the date once a month manually.  So, being the automation addict I am, I thought, why not write a script.  So one night I hammered out the following script that will calculate the first Friday of next month:</p>
<p><span id="more-597"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/***************************************
  *  FILENAME: first-friday.php          *
  *  AUTHOR:   Chris Kankiewicz [PHLAK]  *
  *  WEBSITE:  http://www.web-geek.net   *
  ***************************************/</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// START FUNCTIONS</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> get_day<span style="color: #009900;">&#40;</span><span style="color: #000088;">$describer</span><span style="color: #339933;">,</span><span style="color: #000088;">$weekday</span><span style="color: #339933;">,</span><span style="color: #000088;">$reference_date</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// $reference_date format = m-Y</span>
&nbsp;
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #000088;">$reference_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$describer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'first'</span><span style="color: #339933;">:</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> get_day_offset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$reference_date</span><span style="color: #339933;">,</span><span style="color: #000088;">$weekday</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$r</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//returns timestamp format</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> get_day_offset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$anchor</span><span style="color: #339933;">,</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//$anchor format = m-Y</span>
&nbsp;
    <span style="color: #000088;">$ts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span><span style="color: #000088;">$anchor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mktime</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'01'</span><span style="color: #339933;">,</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$anchor</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$ts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$days</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'sunday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'monday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'tuesday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'wednesday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'thursday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'friday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'saturday'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">6</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$days</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$anchor</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">+=</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//returns 0-6 for use in get_day();</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//END FUNCTIONS</span>
&nbsp;
  <span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getdate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Get today's date</span>
&nbsp;
  <span style="color: #000088;">$today</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m-Y'</span><span style="color: #339933;">,</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Display today's date as MM-YYYY</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Calculate Next Month</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'12'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nm</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mday<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000ff;">'7'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>wday<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> <span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nm</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$nm</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> get_day<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;friday&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Checks if today is after the first friday of the month</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mday<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'12'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$nm</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ff</span> <span style="color: #339933;">=</span> get_day<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;friday&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mday<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j'</span><span style="color: #339933;">,</span><span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'12'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$nm</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>mon<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#91;</span>year<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$ff</span> <span style="color: #339933;">=</span> get_day<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;friday&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$nm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$ff</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$date</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// I know this code is crap, deal with it or fix it yourself!</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;F j, Y&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ff</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>I apologies for the crappy code, I was either tired, drunk or both the night I wrote this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriskankiewicz.com/posts/2008/10/20/calculate-the-first-friday-of-next-month-with-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>IP Uploader &#8211; Python Script (.py)</title>
		<link>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/</link>
		<comments>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 09:28:17 +0000</pubDate>
		<dc:creator>Chris Kankiewicz</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Cox]]></category>
		<category><![CDATA[Dynamic IP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[VNC]]></category>

		<guid isPermaLink="false">http://www.chriskankiewicz.com/wp/?p=148</guid>
		<description><![CDATA[NOTE: This script can now be found here:: http://github.com/PHLAK/ip-uploader This is my first python script I ever wrote. This script connects to whatismyip.com, fetches the external IP address of the network you are on, puts it into a text file &#8230; <a href="http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE:</strong> This script can now be found here:: <a href="http://github.com/PHLAK/ip-uploader">http://github.com/PHLAK/ip-uploader</a></p>
<p>This is my first python script I ever wrote.  This script connects to <a href="http://www.whatismyip.com/" target="_blank">whatismyip.com</a>, fetches the external IP address of the network you are on, puts it into a text file and uploads it via FTP to any server you want.</p>
<p>At home I have Cox, therefore I have a dynamic IP.  Even though this IP only changes about once every month, I got sick of needing to connect to my home computer via VNC and not being able because my IP had changed.  Therefore I created the following script and set up a scheduled task on my home computer to run this script every hour.</p>
<p>After running this script, you can then use PHP (or any  similar language) to include this file into any page you desire.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">ftplib</span>
&nbsp;
<span style="color: #008000;">file</span>=<span style="color: #483d8b;">&quot;ip.txt&quot;</span>
&nbsp;
conn = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPConnection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;www.whatismyip.com&quot;</span><span style="color: black;">&#41;</span>
conn.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;GET&quot;</span>,<span style="color: #483d8b;">&quot;/automation/n09230945.asp&quot;</span><span style="color: black;">&#41;</span>
response = conn.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
data = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
filename = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span>+<span style="color: #008000;">file</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Create file</span>
FILE = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename,<span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Open file ready for writing</span>
FILE.<span style="color: black;">writelines</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Write 'data' to file</span>
FILE.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Close file</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Replace [server], [user], and [pass] with your information.</span>
s = <span style="color: #dc143c;">ftplib</span>.<span style="color: black;">FTP</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'[server]'</span>,<span style="color: #483d8b;">'[user]'</span>,<span style="color: #483d8b;">'[pass]'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Connect</span>
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>,<span style="color: #483d8b;">'rb'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#File to send</span>
s.<span style="color: black;">storbinary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'STOR '</span>+<span style="color: #008000;">file</span>, f<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Send the file</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Close file and FTP</span>
s.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#Quit FTP</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Shouts to Automated Penguin and Nak!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriskankiewicz.com/posts/2008/09/30/ip-uploader-python-script-py/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
