<?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>tech stuff &#187; programming</title>
	<atom:link href="http://codytaylor.org/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django on Dreamhost: Virtual Python Install</title>
		<link>http://codytaylor.org/2010/07/django-on-dreamhost-virtual-python-install.html</link>
		<comments>http://codytaylor.org/2010/07/django-on-dreamhost-virtual-python-install.html#comments</comments>
		<pubDate>Fri, 02 Jul 2010 21:37:51 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[django dreamhost]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[dreamhost django python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python developer]]></category>
		<category><![CDATA[python host]]></category>
		<category><![CDATA[python hosting]]></category>
		<category><![CDATA[python programmer]]></category>
		<category><![CDATA[virtual python]]></category>
		<category><![CDATA[virtual python install]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14330</guid>
		<description><![CDATA[Setting up a virtual Python environment for Django on a Dreamhost Debian shared host.]]></description>
			<content:encoded><![CDATA[<p>After writing the backend for a new web app in python I went to start working on the Django portion. I was planning on hosting this application with a Dreamhost shared hosting plan which already has Python 2.5 installed. After trying unsuccessfully to install some new middleware with easy_install, I started looking for a solution that gives me more control over what I want to do with Python without having to purchase dreamhost <a href='http://www.webhostgear.com/vps-hosting.php' title='vps hosting'>vps hosting</a>. It seems that you can set up a virtual python install in your home directory and it was surprisingly easy. I&#8217;ve only had the need to use this virtual python install on Dreamhost, which is using Debian, but I can&#8217;t see any reason why it wouldn&#8217;t work on other environments. </p>
<p>Note that this is completely unnecessary if you have root access.</p>
<p>Assuming you already have a shell account and you are ssh&#8217;d in, execute these commands to install your virtual python environment:<br />
<pre><code>$ wget http://peak.telecommunity.com/dist/virtual-python.py 
$ python virtual-python.py</code></pre> </p>
<p>Those commands copy the Python binary to your /home/user/bin directory and sets up symbolic links to the system wide libraries. This means that the ~/bin/python executable will have access to the same libraries as the system Python but that any extra installed software will not affect the system wide Python install.  </p>
<p>Next you should add the ~/bin directory to your PATH by adding this block to your .bash_profile:<br />
<pre><code> if [ -d ~/bin ] ; then&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;PATH=~/bin:&quot;${PATH}&quot; 
fi 
</code></pre><br />
You&#8217;ll have to log out and back in for this to take effect.<br />
After you&#8217;re logged back in, run these commands to install easy_setup:<br />
<pre><code>$ wget http://peak.telecommunity.com/dist/ez_setup.py 
$ python ez_setup.py </code></pre> </p>
<p>Now you should be able to install whatever you want using easy_install. The first thing I did was install django-db-log using this command:<br />
<code>$ easy_install django-db-log</code></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2010%2F07%2Fdjango-on-dreamhost-virtual-python-install.html&amp;linkname=Django%20on%20Dreamhost%3A%20Virtual%20Python%20Install"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2010/07/django-on-dreamhost-virtual-python-install.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>This is How Credit Card Numbers Are Generated</title>
		<link>http://codytaylor.org/2009/11/this-is-how-credit-card-numbers-are-generated.html</link>
		<comments>http://codytaylor.org/2009/11/this-is-how-credit-card-numbers-are-generated.html#comments</comments>
		<pubDate>Mon, 09 Nov 2009 19:45:49 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[American Express]]></category>
		<category><![CDATA[Credit Card Validation]]></category>
		<category><![CDATA[Credit Cards]]></category>
		<category><![CDATA[Discover]]></category>
		<category><![CDATA[Luhn Check]]></category>
		<category><![CDATA[Master Card]]></category>
		<category><![CDATA[Visa]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14305</guid>
		<description><![CDATA[This is How Credit Card Numbers Are Generated]]></description>
			<content:encoded><![CDATA[<p>I was reading an article today in one of my favorite publications about how to get free trials without actually using your credit card by generating valid credit card numbers using a simple algorithm called the Luhn check. So I wrote a little script that generates credit card numbers that will be deemed valid by most software checks. This will work because the service won&#8217;t know that the credit card is invalid until they actually try to charge it. Well, the card may be valid since my script uses random numbers. Obviously this if for informational purposes only and should never actually be used.</p>
<p>Most credit card numbers are validated using an algorithm called the &#8220;Luhn check&#8221;. This is a very simple algorithm that doubles the odd digits and does a sum to see if the number is divisible by 10. The credit card companies use a slightly different version that involves a check digit as the last digit. To generate a credit card number that will pass most validation software (as long as they don&#8217;t actually try to process the credit card) one only needs to follow these steps to make sure that the generated credit card is valid.</p>
<p>Choose 16 random numbers starting with a 3,4,5 or 6.<br />
Starting with the first digit, double every other number.</p>
<p>If doubling a number results in a two digit number, add those digits together to produce a single digit number</p>
<p>Replace the odd digits with the new ones just created. You should now have 16 numbers consisting of all the new numbers and the original even numbers</p>
<p>Add up all sixteen numbers.</p>
<p>Manipulate the check digit so that the sum is divisible by 10.</p>
<p>Replace the last digit of the original random string with the new manipulated check digit.</p>
<p>Thats really all there is to it. Check out the source of my javascript <a href='http://codytaylor.org/credit_cards.html' title='credit cards'>credit card generator</a> if you want to see how to generate and validate the credit card numbers. </p>
<p>The reason for starting with a 3,4,5, or 6 is that different card types start with different digit. The 3 is American Express, 4 is Visa, 5 is Master Card, 6 is a Discover Card. </p>
<p>Some companies use more digits to show that the card is from them. For example 5254 is a Master Card from the Bank of America and 4013 shows that it is a Visa card from Citibank. Also note that the expiry date has nothing at all to do with the card number.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F11%2Fthis-is-how-credit-card-numbers-are-generated.html&amp;linkname=This%20is%20How%20Credit%20Card%20Numbers%20Are%20Generated"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/11/this-is-how-credit-card-numbers-are-generated.html/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Vim Syntax Highlighting In Ubuntu</title>
		<link>http://codytaylor.org/2009/09/vim-syntax-highlighting-in-ubuntu.html</link>
		<comments>http://codytaylor.org/2009/09/vim-syntax-highlighting-in-ubuntu.html#comments</comments>
		<pubDate>Mon, 21 Sep 2009 14:08:49 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[vimrc]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14254</guid>
		<description><![CDATA[Get Vim Syntax Highlighting In Ubuntu.]]></description>
			<content:encoded><![CDATA[<p>Spending a lot of time on the command line lately I noticed that Ubuntu does not come with Vim syntax highlighting by default. Apparently it installs a version of Vim called vim-tiny which doesn&#8217;t include any syntax highlighting.</p>
<p>There are two packages that you can install to get syntax highlighting to work in Vim: vim-full and vim-common. Because I didn&#8217;t have gnome installed vim-full was a very large download (like 50MB) and it errored out anyway. vim-common is definitely the way to go.<br />
<pre><code>
sudo apt-get install vim
</code></pre><br />
The above line will replace vim-tiny with vim-common and will allow for syntax highlighting. A lot of the time you will have to enable syntax highlighting by editing the vimrc config file either in /etc/vim or in yur home directory. You will need to uncomment the line &#8220;syntax on&#8221;.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F09%2Fvim-syntax-highlighting-in-ubuntu.html&amp;linkname=Vim%20Syntax%20Highlighting%20In%20Ubuntu"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/09/vim-syntax-highlighting-in-ubuntu.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create A Simple Captcha With PHP and GD</title>
		<link>http://codytaylor.org/2009/08/create-a-simple-captcha-with-php-and-gd.html</link>
		<comments>http://codytaylor.org/2009/08/create-a-simple-captcha-with-php-and-gd.html#comments</comments>
		<pubDate>Wed, 12 Aug 2009 02:46:20 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[evil]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14213</guid>
		<description><![CDATA[Captchas are evil but really easy to implement.]]></description>
			<content:encoded><![CDATA[<p>Everyone hates captchas. I know I do. It sucks but they are a necessary evil. Most captchas are difficult (sometimes impossible) to read and they will consistantly drive visitors from your site. I&#8217;ve been on sites where the captcha was so hard to decipher that I&#8217;ve never gone back. </p>
<p>During the development of a new site I was forced to create one of these evil entities. It was surprisingly simple and painless. The captcha that I outline here is very, very simple and should never be used in production without a fair amount of tweaking. </p>
<p>Having developed my site using php I naturally turned to the GD library. </p>
<p>Firstly I generated a random string to display on the captcha :<br />
<pre><code>
//generate a random alphanumeric string of a specific length
function gen_random_string($length) 
{
&nbsp;&nbsp;$characters = &quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWZYZ&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;abcdefghijklmnopqrstuvwxyz&quot;;
&nbsp;&nbsp;$real_string_length = strlen($characters) - 1;
&nbsp;&nbsp;for($p=0;$p&lt;$length;$p++)
&nbsp;&nbsp;{ $string .= $characters[mt_rand(0, $real_string_length)]; }
&nbsp;&nbsp;return $string;
}

//add to session array so other scripts can access it for the comparison
$_SESSION[&#039;image_text&#039;]= gen_random_string(8);

//split into character array - str_split only works in PHP 5
$text_array = str_split($_SESSION[&#039;image_text&#039;]);
</code></pre><br />
<br />
Now that I have my string I need to create the image. Make sure that GD is installed on your php apache server.<br />
<pre><code>
//create the image with a background image
$NewImage =imagecreatefrompng(&quot;bg1.png&quot;);
$cntr = 0;
foreach($text_array as $letter)
{
&nbsp;&nbsp;//generate a random color for each letter
&nbsp;&nbsp;$r = rand(0,200);
&nbsp;&nbsp;$g = rand(0,200);
&nbsp;&nbsp;$b = rand(0,200);
&nbsp;&nbsp;$textcolor = imagecolorallocate($NewImage, $r, $g, $b);

&nbsp;&nbsp;//random horizontal spacing
&nbsp;&nbsp;$spacing = (rand(5,10)+($cntr*10));
&nbsp;&nbsp;
&nbsp;&nbsp;//add the character to the image
&nbsp;&nbsp;imagestring($NewImage, 5, $spacing, rand(0,10), $letter, $textcolor);
&nbsp;&nbsp;$cntr++;
}
</code></pre><br />
<br />
The code above will generate a GD captcha image with random coloring and random horizontal and vertical spacing on top of a background image.<br />
Now we just need to output it.<br />
<pre><code>
//output the headers than the image as a PNG
header(&#039;Content-type: image/png&#039;);
header(&#039;Cache-Control: max-age=0&#039;);
header(&#039;Expires: &#039;.gmdate(&#039;r&#039;,time()-3600*24*365));
header(&#039;Pragma:&#039;);
ImagePNG($NewImage);
imagedestroy($NewImage);
</code></pre><br />
<br />
So if I called this file simple-captcha.php I could call it with this html:<br />
<pre><code>
&lt;img id=&#039;captcha&#039; name=&#039;captcha&#039; src=&quot;simple-captcha.php&quot;&gt;
</code></pre><br />
<br />
Here is what it looks like : </p>
<p></p>
<table cellpadding=0 cellspacing=0>
<tr>
<td>
<img id='captcha' name='captcha' src="http://codytaylor.org/simple-captcha.php">
</td>
<td>
<input type='button' value='refresh captcha example' onclick='refresh_captcha();'>
</td>
<td>
</table>
<p>
This captcha can be strengthened by using other <a href='http://ca2.php.net/manual/en/ref.image.php' title='PHP GD image functions'>GD image functions</a> such as imagefilledellipse and imageline to create artifacts in the background. It also helps to use different fonts and to change the angle of the letters.<br />
<script type='text/javascript'>
function refresh_captcha()
{ document.getElementById("captcha").src = 'http://codytaylor.org/simple-captcha.php?asdf='+Math.random(); }
</script></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F08%2Fcreate-a-simple-captcha-with-php-and-gd.html&amp;linkname=Create%20A%20Simple%20Captcha%20With%20PHP%20and%20GD"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/08/create-a-simple-captcha-with-php-and-gd.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Decode Obfuscated Wordpress Strings Which Use eval, gzinflate, And base64_decode.</title>
		<link>http://codytaylor.org/2009/07/decode-obfuscated-wordpress-strings-which-use-eval-gzinflate-and-base64_decode-easily.html</link>
		<comments>http://codytaylor.org/2009/07/decode-obfuscated-wordpress-strings-which-use-eval-gzinflate-and-base64_decode-easily.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:55:38 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[obfuscate]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14195</guid>
		<description><![CDATA[I've been using wordpress for awhile and it seems that whenever I find a useful plugin or theme on the web the author always seems to embed some affiliate link or some other garbage on my main page. Usually they..]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using wordpress for awhile and it seems that whenever I find a useful plugin or theme on the web the author always seems to embed some affiliate link or some other garbage on my main page. Usually they make sure that these links show up on every page and sometimes they even make other features of the software depend on it. Usually when I try to edit out the code it&#8217;s not as easy as removing an anchor or a bit of javascript. They always seem to obfuscate what they are doing as much as possible.</p>
<p>The most popular way to do this is to use a combination of gzinflate, base64_decodes, eval, and str_rot13. For most users this is really difficult to decode to figure out what is really going on. I wrote this function to hopefully make peoples lives easier (or harder, depending on who you are).<br />
Usually the obfuscated code is written in the wordpress add-on like this :<br />
<pre><code>
$coded_string = &quot;eval(gzinflate(base64_decode(&#039;FZfFDs..sdff/7nr/8B&#039;)));&quot;
</code></pre><br />
If your string looks like that then the function that follows should take decode it and return the html code pretty easily.<br />
<pre><code>
function decode_goofy_string($coded_string)
{
&nbsp;&nbsp;while(preg_match(&quot;/eval\(gzinflate/&quot;,$coded_string)) 
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;$contents=preg_replace(&quot;/&lt;\?|\?&gt;/&quot;, &quot;&quot;, $coded_string); 
&nbsp;&nbsp;&nbsp;&nbsp;eval(preg_replace(&quot;/eval/&quot;, &quot;\$coded_string=&quot;, $coded_string)); 
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;return trim($coded_string);
}
</code></pre></p>
<p>This function is pretty straight forward but if anyone has any troubles then leave a comment or send me an email at cody@codytaylor.org</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F07%2Fdecode-obfuscated-wordpress-strings-which-use-eval-gzinflate-and-base64_decode-easily.html&amp;linkname=Decode%20Obfuscated%20Wordpress%20Strings%20Which%20Use%20eval%2C%20gzinflate%2C%20And%20base64_decode."><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/07/decode-obfuscated-wordpress-strings-which-use-eval-gzinflate-and-base64_decode-easily.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wordpress Shortcode To Generate A TinyURL For Any Post</title>
		<link>http://codytaylor.org/2009/06/wordpress-shortcode-to-generate-a-tinyurl-for-any-post.html</link>
		<comments>http://codytaylor.org/2009/06/wordpress-shortcode-to-generate-a-tinyurl-for-any-post.html#comments</comments>
		<pubDate>Tue, 30 Jun 2009 02:11:49 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[shortcode]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14188</guid>
		<description><![CDATA[TinyURLs can be very useful when you have a long url to type into something like an iphone or some other mobile device where the keyboard is rather tedious. On a few of my sites..]]></description>
			<content:encoded><![CDATA[<p>TinyURLs can be very useful when you have a long url to type into something like an iphone or some other mobile device where the keyboard is rather tedious. On a few of my sites I was looking for a way to automatically generate a tinyURL with the least amount of effort. Since I use wordpress for most of them I decided to go with a shortcode. </p>
<p>Shortcodes seem to be gaining a fair amount of attention in the wordpress community and with good reason. The Shortcode API, which was new in wordpress 2.5, is a simple set of functions for creating macro codes for use in your posts. Shortcodes are written by providing a handler function and they accept parameters too. Here is a wordpress shortcode to generate a tinyURL for a post.<br />
<pre><code>
//Generate Tiny URLS For A Post 
function get_tiny_url($arguments)
{
&nbsp;&nbsp;if(empty($arguments))
&nbsp;&nbsp;&nbsp;&nbsp;$url = get_permalink($post-&gt;ID);
&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;$url = urlencode($arguments[&#039;url&#039;]);
&nbsp;&nbsp;if($url)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$tiny_url = &#039;http://tinyurl.com/api-create.php?url=&#039;.$url;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$new_url = file_get_contents($tiny_url);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$new_url = &quot;Error&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;return $new_url;
}

add_shortcode(&#039;small_url&#039;, &#039;get_tiny_url&#039;);
</code></pre><br />
If the url parameter is not defined then the function will attempt to use the wordpress function get_permalink($post->ID) which will return the current posts url. Also you can pass in a parameter if you want to show a tinyURL to another location. Using curl instead of file_get_contents would probably be faster but I didn&#8217;t want to make the example to long. The add_shortcode function is what tells the API to use the get_tiny_url function when it encounters the small_url shortcode. Note that this will call on the tinyurl api every page view so it would probably be prudent to set the tiny urls in the database so you only have to check once on a production site although I&#8217;m not sure if they expire or not.<br />
This shortcode can be called in the post by typing :<br />
<pre><code>
[small_url]&nbsp;&nbsp;// or
[small_url url=&#039;http://codytaylor.org&#039;]
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fwordpress-shortcode-to-generate-a-tinyurl-for-any-post.html&amp;linkname=Wordpress%20Shortcode%20To%20Generate%20A%20TinyURL%20For%20Any%20Post"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/wordpress-shortcode-to-generate-a-tinyurl-for-any-post.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your PHP Faster</title>
		<link>http://codytaylor.org/2009/06/make-you-php-faster.html</link>
		<comments>http://codytaylor.org/2009/06/make-you-php-faster.html#comments</comments>
		<pubDate>Sat, 27 Jun 2009 03:17:38 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[dont]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14177</guid>
		<description><![CDATA[I was reading about some php performance tips at work today..]]></description>
			<content:encoded><![CDATA[<p>I was reading about some php performance tips at work today and decided to throw together some of the ways to make your php site faster.</p>
<p>Here&#8217;s a couple of short tips to avoid making your site lag for the user:</p>
<ol>
<li><a href='http://php.net/unset' title='unset'>Unset</a> your variables. This frees up a surprising amount of memory</li>
<li>Use <a href='http://php.net/memcache' title='memcache docs'>memcache</a> </li>
<li>Turn on apache&#8217;s mod_deflate</li>
<li>If your database is local then close your connections when you&#8217;re done with them</li>
<li>If your database is remote then use persistant connections</li>
<li>Don&#8217;t use functions inside of a for loop control expression unless absolutely necessary. Example :<br />
<pre><code>
for($i=0;$i&lt;some_big_calculation(20);$i++)
</code></pre><br />
The some_big_calculation function will be called every iteration.
</li>
<li>
Use string concatenation instead of embedding variables in strings.<br />
<pre><code>
$some_string = &quot;asdf $asdf2 asdf&quot;; //bad
$some_string = &#039;asdf &#039;.$asdf2.&#039; asdf&#039;; //good
</code></pre>
</li>
<li>
When including files, use at least a relative path so PHP doesn&#8217;t have to look in the entire path.<br />
<code></code>
</li>
<li>
Try not to use include_once or require_once. They are more expensive and it really isn&#8217;t that hard to only include files once
</li>
<li>
Not everything needs to be an object. There is a fair amount of overhead when doing everything OOP.
</li>
<li>
Use <a href='http://ca.php.net/manual/en/book.outcontrol.php' title='output buffering documentation'>output buffering</a> to make everything seem faster.</a>
</li>
</ol>
<p>Hopefully I didn&#8217;t miss any of the big ones. </p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fmake-you-php-faster.html&amp;linkname=Make%20Your%20PHP%20Faster"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/make-you-php-faster.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Update Twitter using Command Line, Javascript, Or PHP.</title>
		<link>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html</link>
		<comments>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html#comments</comments>
		<pubDate>Tue, 23 Jun 2009 02:13:09 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14162</guid>
		<description><![CDATA[Everyone seems to be all about twitter so here's some simple examples of how to integrate twitter...]]></description>
			<content:encoded><![CDATA[<p>Everyone seems to be all about Twitter so here&#8217;s some simple examples of how to update your Twitter status from a command line prompt, web server or simple html web site. These three examples require curl so install it if you don&#8217;t already have it. For these examples I&#8217;ll be using my Twitter user name &#8216;codytaylor1234&#8242;. My password is not &#8216;mypassword&#8217; so make sure you put in your own information.</p>
<p>The easiest way to update your Twitter account is to just call curl from the command line with this command.<br />
<pre><code>
curl --basic --user &quot;codytaylor1234:mypassword&quot; --data-ascii 
&quot;status=This Twitter update brought to you by curl on the command line&quot; 
&quot;http://twitter.com/statuses/update.json&quot;
</code></pre><br />
<br />
To update your Twitter status with PHP you are going to want to do the same sort of thing but with a bit more typing.<br />
<pre><code>
&lt;?php
$username = &#039;codytaylor1234&#039;;
$password = &#039;mypassword&#039;;

$update = &#039;This Twitter update is from a php script using curl&#039;;

$url = &#039;http://twitter.com/statuses/update.json&#039;;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &quot;$url&quot;);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, &quot;status=&quot;.$update);
curl_setopt($ch, CURLOPT_USERPWD, $username.&quot;:&quot;.$password);
$result = curl_exec($ch);
curl_close($ch);

if($result)
&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;success&#039;;

?&gt;;
</code></pre></p>
<p>Since a cross-domain request in Javascript isn&#8217;t really an option we have to create a proxy using PHP in order to authenticate the user on the Twitter API. If anyone knows an easy way authenticate a Twitter user using only javascript I&#8217;d love to hear it. Anyway if we replace a small amount of code in the above example and put it in a file then we can use a simple ajax request to update our Twitter status. So the new PHP file would be:<br />
<pre><code>
&lt;?php
$username = $_POST[&#039;username&#039;];
$password = $_POST[&#039;password&#039;];

$update = $_POST[&#039;update&#039;];

$url = &#039;http://twitter.com/statuses/update.json&#039;;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, &quot;$url&quot;);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, &quot;status=&quot;.$update);
curl_setopt($ch, CURLOPT_USERPWD, $username.&quot;:&quot;.$password);
$result = curl_exec($ch);
curl_close($ch);

?&gt;
</code></pre></p>
<p>For this example I called that php file &#8216;twitter-update.php&#8217;. Now that we have our simple proxy we can update our twitter status with a simple html form and a little ajax. I used the prototype framework for my javascript.<br />
<pre><code>
&lt;script src=&quot;includes/prototype.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;script type=&#039;text/javascript&#039;&gt;
function update_twitter()
{
&nbsp;&nbsp;var param_string = &quot;username=&quot;+$(&#039;username&#039;).value+&quot;&amp;password=&quot;+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&#039;password&#039;).value+&quot;&amp;update=&quot;+$(&#039;update&#039;).value;
&nbsp;&nbsp;alert(param_string);
&nbsp;&nbsp;var options = {
&nbsp;&nbsp;&nbsp;&nbsp;method: &quot;post&quot;,
&nbsp;&nbsp;&nbsp;&nbsp;parameters: param_string,
&nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function (xhr, Json) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Response received successfully.&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;onFailure: function (xhr, Json) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Request was unsuccessful.&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;};
&nbsp;&nbsp;
&nbsp;&nbsp;var oRequest = new Ajax.Request(&quot;twitter-update.php&quot;, options);
}

&lt;/script&gt;
</code></pre></p>
<p>Obviously this is for example purposes only and if you&#8217;re actually using it for production then you should edit it a lot. Now for the last little bit here&#8217;s the simple html form that starts it all.<br />
<pre><code>
User Name : &lt;input type=&#039;text&#039; id=&#039;username&#039; value=&#039;codytaylor1234&#039;&gt;&lt;br&gt;
Password&nbsp;&nbsp;: &lt;input type=&#039;password&#039; id=&#039;password&#039; value=&#039;mypassword&#039;&gt;&lt;br&gt;
New Status : &lt;input type=&#039;text&#039; id=&#039;update&#039; 
value=&#039;Twitter Update from html/javascript/php&#039;&gt;&lt;br&gt;
&lt;input type=&#039;button&#039; value=&quot;Update Twitter&quot; onclick=&#039;update_twitter();&#039;&gt;
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fupdate-twitter-using-command-line-javascript-or-php.html&amp;linkname=Update%20Twitter%20using%20Command%20Line%2C%20Javascript%2C%20Or%20PHP."><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/update-twitter-using-command-line-javascript-or-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Get Integer Bit Parity In PHP</title>
		<link>http://codytaylor.org/2009/06/get-integer-bit-parity-in-php.html</link>
		<comments>http://codytaylor.org/2009/06/get-integer-bit-parity-in-php.html#comments</comments>
		<pubDate>Sat, 20 Jun 2009 19:20:50 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[bytes]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14144</guid>
		<description><![CDATA[I was forced to use php to generate a cyclic redundancy..]]></description>
			<content:encoded><![CDATA[<p>I was forced to use php to generate a cyclic redundancy check (CRC) byte earlier this week. When generating this CRC I needed to check the bit parity of a byte. At first I thought that there would be an example that I could just cut and paste into my code or a library including the function somewhere. I guess that most PHP users don&#8217;t really have to work with bits and bytes very often because I couldn&#8217;t find an example of doing this. Granted I didn&#8217;t really search that hard because writing it was pretty simple. But hopefully the next guy searching for this actually finds this example.</p>
<p>Most of the time we don&#8217;t really have to think about types in php. But if you&#8217;re dealing with this kind of thing then you usually want to know what you&#8217;re working with. This php function example will only work with integers and will return a value of -1 if the first parameter is not a number. The function returns 1 if the number of bits set in the number pased in is odd. Otherwise it will return 0. The second parameter defaults to 4 because that is the number of bytes in a normal php integer. In php if a number becomes larger than an integer can handle, which is called an overflow, it becomes a float. The default integer size is platform dependant but it&#8217;s usually 4 bytes. It can be set using the constant PHP_INT_SIZE if you need to change it.</p>
<p><pre><code>
&lt;?php

function odd_parity($something,$number_of_bytes_to_check=4,$double_check=0)
{
&nbsp;&nbsp;&nbsp;&nbsp;//test to make sure it&#039;s a number
&nbsp;&nbsp;&nbsp;&nbsp;if(!is_numeric($something)) {return -1;}&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;$setbits = 0;

&nbsp;&nbsp;&nbsp;&nbsp;//get the number of bits that are set
&nbsp;&nbsp;&nbsp;&nbsp;for($i=0;$i&lt;$number_of_bytes_to_check*8;$i++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($something &amp; (1&lt;&lt;$i)) $setbits++;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;//check if the number of bits set is even or odd&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;$result =&nbsp;&nbsp;$setbits % 2;
&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;//spit out the results to double check it&#039;s working 
&nbsp;&nbsp;&nbsp;&nbsp;if($double_check)
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&nbsp; &quot;&lt;br&gt;Parity of : &quot;.$something.&quot; is &quot;.
&nbsp;&nbsp;&nbsp;&nbsp;$result.&quot; In Binary : &quot;.decbin((int)$something).
&nbsp;&nbsp;&nbsp;&nbsp;&quot; Checking the right &quot;.($number_of_bytes_to_check*8).
&nbsp;&nbsp;&nbsp;&nbsp;&quot; Bits&quot;;

&nbsp;&nbsp;&nbsp;&nbsp;return $result;
}

//will return 0 because it&#039;s defaulting to 4 bytes
echo odd_parity(0x0100010001);&nbsp;&nbsp;

?&gt;
</code></pre></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fget-integer-bit-parity-in-php.html&amp;linkname=Get%20Integer%20Bit%20Parity%20In%20PHP"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/get-integer-bit-parity-in-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generate A Tiny URL On The Fly With PHP</title>
		<link>http://codytaylor.org/2009/06/generate-a-tiny-url-on-the-fly-with-php.html</link>
		<comments>http://codytaylor.org/2009/06/generate-a-tiny-url-on-the-fly-with-php.html#comments</comments>
		<pubDate>Thu, 18 Jun 2009 02:07:08 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[tinyurl]]></category>
		<category><![CDATA[uri]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14140</guid>
		<description><![CDATA[Uniform resource locators (URL) are starting to get very long and I&#8217;m getting sick of typing ridiculously long strings into safari on my iphone. I don&#8217;t really care about the extra bandwidth, It&#8217;s just annoying when you&#8217;re on the phone telling someone to go check out a 67 character long url and they mistype it [...]]]></description>
			<content:encoded><![CDATA[<p>Uniform resource locators (URL) are starting to get very long and I&#8217;m getting sick of typing ridiculously long strings into safari on my iphone. I don&#8217;t really care about the extra bandwidth, It&#8217;s just annoying when you&#8217;re on the phone telling someone to go check out a 67 character long url and they mistype it three times. </p>
<p>I&#8217;ve just started using the tiny url service and so far it&#8217;s been useful. On one of my sites I wanted to generate a tiny url for each of my pages to make them quicker to type in and also so people don&#8217;t know what get variables I&#8217;ve set until they get there. Here is the PHP function that I used to generate a tiny url for every page on the site. </p>
<p>There doesn&#8217;t seem to be any documentation at all on the Tiny URL website about this so I&#8217;m not sure if it&#8217;ll change in the future.<br />
This function passes your desired url to the api-create.php script on the tinyurl domain which returns a nice short url that isn&#8217;t a pain to put into your iphone.<br />
<pre><code>
function get_tiny_url($url)
{
&nbsp;&nbsp;$new_url = file_get_contents(&#039;http://tinyurl.com/api-create.php?url=&#039;.$url);
&nbsp;&nbsp;return $new_url;
}

$tiny_url = get_tiny_url(&quot;http://codytaylor.org&quot;);
</code></pre><br />
Not much to it but it made my life easier.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F06%2Fgenerate-a-tiny-url-on-the-fly-with-php.html&amp;linkname=Generate%20A%20Tiny%20URL%20On%20The%20Fly%20With%20PHP"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/06/generate-a-tiny-url-on-the-fly-with-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

