<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Lateral Code</title>
	
	<link>http://www.lateralcode.com</link>
	<description>A Web Development Blog Focused on Code and Technology</description>
	<lastBuildDate>Fri, 15 Jul 2011 03:00:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/lateralcode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="lateralcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">lateralcode</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/lateralcode" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Flateralcode" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>JavaScript Fade Effect without Libraries</title>
		<link>http://www.lateralcode.com/javascript-fade-effect/</link>
		<comments>http://www.lateralcode.com/javascript-fade-effect/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 00:29:11 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1727</guid>
		<description><![CDATA[Using JavaScript libraries like jQuery and Mootools does simplify your code, but this comes with the price of an added footprint. Often times, the same effects can be accomplished in raw JavaScript with little to no hassle. Indeed, this tutorial will explain how to create the classic fade effect without resorting to jQuery or Mootools. [...]]]></description>
			<content:encoded><![CDATA[<p>Using JavaScript libraries like jQuery and Mootools does simplify your code, but this comes with the price of an added footprint. Often times, the same effects can be accomplished in raw JavaScript with little to no hassle. Indeed, this tutorial will explain how to create the classic fade effect without resorting to jQuery or Mootools.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/javascript-fade-effect/2.jpg" alt="Fade" class="list-post-img"/></p>
<p>The fade effect, as its name denotes, is an animation used to fade an element off of a page. You can find a demo of it in the <a href="http://api.jquery.com/fadeOut/#example-0">jQuery documentation</a>.</p>
<p><span id="more-1727"></span></p>
<p>To begin, let&#8217;s create a <code>fade</code> function that accepts a DOM element and a time as parameters:</p>
<pre><code>function fade( elem, time )</code></pre>
<p>To achieve the fade effect, we can use the CSS opacity property, which determines the transparency of an element. Setting the opacity to 1 means the object is fully visible. As the value lowers, so too does the transparency. Consequently, 0 represents a completely invisible element.</p>
<p>Our logic will roughly abide by the following outline:</p>
<ol>
<li>Find the starting opacity of <code>elem</code>, the given element. This is the value we have to reduce to 0 in <code>time</code>, the given number of milliseconds.</li>
<li>Begin an asynchronous recursion loop that runs every 100 milliseconds.</li>
<li>In the loop, decrement the opacity by the correct fraction to ensure that in <code>time</code> milliseconds, <code>elem</code> has an opacity of 0.</li>
</ol>
<p>The correct fraction noted in step 3 will be equal to the starting opacity divided by <code>time</code> / 100. This is because the loop will go through <code>time</code> / 100 iterations in <code>time</code> milliseconds. In each iteration, the opacity must be decremented by the starting opacity / ( <code>time</code> / 100 ) to ensure that it will end up as 0 (the total decrement will equal the starting opacity) after the loop finishes its execution.</p>
<p>Let&#8217;s write some preliminary code based off this outline:</p>
<pre><code>function fade( elem, time )
{
	var startOpacity = elem.style.opacity || 1;
	elem.style.opacity = startOpacity;

	(function go() {
		elem.style.opacity -= startOpacity / ( time / 100 );
		setTimeout( go, 100 );
	})();
}</code></pre>
<p>Note that <code>startOpacity</code> is assigned to 1 if <code>elem.style.opacity</code> is not explicitly set. This explains why we have to set <code>elem.style.opacity</code> in the following line, as it may not be defined.</p>
<p>After finding the opacity, the <code>go</code> function is recursively called as per our specifications. In the code&#8217;s current state, however, it does not stop. To determine when it should finish executing, we have to check whether the element has faded. This can be done by monitoring its opacity in relation to the target value, or 0:</p>
<pre><code>if( elem.style.opacity > 0 )
	setTimeout( go, 100 );
else
	elem.style.display = 'none';</code></pre>
<p>Not only do we stop calling <code>go</code> when we&#8217;re done, but we also set the display to none so that other elements are repositioned; <code>elem</code> should not continue to take up page space after it has faded. This is the typical functionality of JavaScript libraries and applies to our code as well.</p>
<p>To ice our cake by making the code compatible with IE, we can use the filter property:</p>
<pre><code>elem.style.filter = 'alpha(opacity=' + elem.style.opacity * 100 + ')';</code></pre>
<p>The final code is included below:</p>
<pre><code>function fade( elem, time )
{
	var startOpacity = elem.style.opacity || 1;
	elem.style.opacity = startOpacity;

	(function go() {
		elem.style.opacity -= startOpacity / ( time / 100 );

		// for IE
		elem.style.filter = 'alpha(opacity=' + elem.style.opacity * 100 + ')';

		if( elem.style.opacity > 0 )
			setTimeout( go, 100 );
		else
			elem.style.display = 'none';
	})();
}</code></pre>
<p>And that&#8217;s it! See you next time.</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/SJcxe6zQhf4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/javascript-fade-effect/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Streamlining MySQL Insert Queries</title>
		<link>http://www.lateralcode.com/mysql-insert-queries/</link>
		<comments>http://www.lateralcode.com/mysql-insert-queries/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 23:21:24 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1719</guid>
		<description><![CDATA[PHP and MySQL have often been known as two peas in a pod. Unfortunately, when you use PHP to insert information into a MySQL database, you often have to write large queries that take up much of your time. Not only that, but you also have to clean user input. This quick tip aims to [...]]]></description>
			<content:encoded><![CDATA[<p>PHP and MySQL have often been known as two peas in a pod. Unfortunately, when you use PHP to insert information into a MySQL database, you often have to write large queries that take up much of your time. Not only that, but you also have to clean user input. This quick tip aims to streamline your efficiency by writing a simple function to do this job for you.</p>
<h2>Write helper functions</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/mysql-insert-queries/1.jpg" alt="Helper functions" class="list-post-img"/></p>
<p>Before we start working on the main program, we first need to create two helper functions which will be used later on:</p>
<p><span id="more-1719"></span></p>
<pre><code>function query( $mysql ) {
	$result = mysql_query( $mysql ) or die( mysql_error() );
	return $result;
}</code></pre>
<p>This first function runs a MySQL query and returns the result. It will also exit if the query fails to execute.</p>
<pre><code>function clean( $input ) {
	if( get_magic_quotes_gpc() )
		$input = stripslashes( $input );
	return mysql_real_escape_string( $input );
}</code></pre>
<p>User input is never guaranteed to be safe. This function cleans input and prevents malicious attacks.</p>
<p>Now we&#8217;re ready to start the main program.</p>
<h2>Create the function prototype</h2>
<p>To begin, we will create a function that requires two parameters: a table name and an associative array (map) of MySQL field names and their respective values. </p>
<pre><code>function insertInto( $table, $info )</code></pre>
<p>After the function finishes executing, a new row of the database will be created with values corresponding to those in <code>$info</code>.</p>
<h2>Find the columns in the MySQL table</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/mysql-insert-queries/2.jpg" alt="MySQL columns" class="list-post-img"/></p>
<p>In order to run an insert query, we must know what columns are in the given MySQL table. This can be done using the following query:</p>
<pre><code>$cols = query( "SHOW COLUMNS FROM $table" );</code></pre>
<h2>Loop through the columns and store the necessary information</h2>
<p>For each column that is found, we need to store the value in the <code>$info</code> map that corresponds to the its name:</p>
<pre><code>$fields = array();
while( ( $row = mysql_fetch_assoc( $cols ) ) !== false ) {
	// ignore primary keys, which are often times auto-incremented ids
	if( $row[ 'Key' ] === 'PRI' )
		continue;

	$name = $row[ 'Field' ];
	$fields[ $name ] = clean( $info[ $name ] );
	if( strpos(  $row[ 'Type' ], 'int' ) === false )
		$fields[ $name ] = "'" . $fields[ $name ] . "'";
}</code></pre>
<p>Notice how the value is cleaned before being stored inside the <code>$fields</code> array. In addition, if the type of the MySQL field is some sort of string, the value must be enclosed in single quotes for the query to work properly.</p>
<h2>Construct the query and run it</h2>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/mysql-insert-queries/3.jpg" alt="MySQL query" class="list-post-img"/></p>
<p>Now that we have all the information, we just need to construct a query based off of the keys (which are MySQL field names) and values (the corresponding information stored in each field) of the <code>$fields</code> array:</p>
<pre><code>$keys = array_keys( $fields );
$values = array_values( $fields );

$str = "INSERT INTO $table(" . implode( $keys, ', ' )  . " ) VALUES( " . implode( $values, ', ' ) . " )";
query( $str );</code></pre>
<p>PHP&#8217;s implode function is perfect in this situation, as it places all array elements into a string separated by a given delimiter. By using a comma and space as the delimiter, the MySQL query is easily formed.</p>
<h2>Conclusion</h2>
<p>The function is now complete. It can be used in a form handler by simply passing in the <code>$_POST</code> or <code>$_GET</code> array as a parameter:</p>
<pre><code>// post data
insertInto( 'tableName', $_POST );

// get data
insertInto( 'tableName', $_GET );</code></pre>
<p>And that&#8217;s really all there is to it. The full function along with the helpers can be found below:</p>
<pre><code>function insertInto( $table, $info ) {
	$cols = query( "SHOW COLUMNS FROM $table" );

	$fields = array();
	while( ( $row = mysql_fetch_assoc( $cols ) ) !== false ) {
		if( $row[ 'Key' ] === 'PRI' )
			continue;

		$name = $row[ 'Field' ];
		$fields[ $name ] = clean( $info[ $name ] );
		if( strpos(  $row[ 'Type' ], 'int' ) === false )
			$fields[ $name ] = "'" . $fields[ $name ] . "'";
	}

	$keys = array_keys( $fields );
	$values = array_values( $fields );

	$str = "INSERT INTO $table(" . implode( $keys, ', ' )  . " ) VALUES( " . implode( $values, ', ' ) . " )";
	query( $str );
}

function query( $mysql ) {
	$result = mysql_query( $mysql ) or die( mysql_error() );
	return $result;
}

function clean( $input ) {
	if( get_magic_quotes_gpc() )
		$input = stripslashes( $input );
	return mysql_real_escape_string( $input );
}</code></pre>
<p>For those of you who prefer something more MySQLi-related (MySQL Improved), take a look at my <a href="https://github.com/karthikv/silent-boss/blob/master/boss/dependencies/db.php">active records database class on GitHub</a>, which can streamline your select, insert, update, and delete queries. It supports where clauses, joins, ordering, limits, and more.</p>
<p>Thanks for reading!</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/ugAAfGKg0zo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/mysql-insert-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How Can This Image Detect My Browser!?</title>
		<link>http://www.lateralcode.com/images-detect-browsers/</link>
		<comments>http://www.lateralcode.com/images-detect-browsers/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 06:03:48 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1690</guid>
		<description><![CDATA[Take a look at this image in Firefox or Opera. Now view it again in any other browser. Notice a difference? In case you don&#8217;t have multiple browsers, here&#8217;s a screenshot of a side-by-side comparison of Firefox and Safari: So how is it possible that this PNG file can magically detect what browser you&#8217;re using? [...]]]></description>
			<content:encoded><![CDATA[<p>Take a look at <a href="http://www.lateralcode.com/wp-content/uploads/browserdetector.png">this image</a> in Firefox or Opera. Now view it again in any other browser. Notice a difference?</p>
<p>In case you don&#8217;t have multiple browsers, here&#8217;s a screenshot of a side-by-side comparison of  Firefox and Safari:<br />
<img class="list-post-img" title="comparison in ff/safari" src="http://www.lateralcode.com/wp-content/uploads/browserdetector2.jpg" alt="comparison in ff/safari" width="500" height="234" /></p>
<p>So how is it possible that this PNG file can magically detect what browser you&#8217;re using? Read on to find out.</p>
<p><span id="more-1690"></span></p>
<p>Well the answer is that it actually can&#8217;t. It&#8217;s exploiting a feature that some browsers support but others do not.</p>
<p>The image is an APNG, or Animated Portable Network Graphics, file. The APNG standard was developed as a possible replacement to animated GIFs, with the intention of using the advantages of PNGs.</p>
<p>APNG isn&#8217;t an official standard, though. In fact, only Opera, Firefox, and Firefox derivatives currently support it. Safari, Chrome, Internet Explorer, and other browsers do not.</p>
<p>The APNG file mentioned at the beginning of this post has two frames. Browsers that do not support the animation only display the first, grey frame, whereas browsers that do switch to the second, indigo frame.</p>
<p>Interesting concept, eh? If you&#8217;re interested in the technicalities of it, you can read the <a href="https://wiki.mozilla.org/APNG_Specification">APNG Specification at Mozilla</a>.</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/mfItdGhkv94" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/images-detect-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Under the Hood: Custom WordPress Pagination System</title>
		<link>http://www.lateralcode.com/wordpress-pagination/</link>
		<comments>http://www.lateralcode.com/wordpress-pagination/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 19:07:36 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1641</guid>
		<description><![CDATA[If you use WordPress, you know that after a few months of blogging, there are far too many posts to display simultaneously. To reduce the loading time of your website, you could consider a pagination system, in which you display only a certain number of posts per page. By giving the user the ability to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use WordPress, you know that after a few months of blogging, there are far too many posts to display simultaneously. To reduce the loading time of your website, you could consider a pagination system, in which you display only a certain number of posts per page. By giving the user the ability to navigate through pages, your posts will all be available and left intact.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/wordpress-pagination/1.jpg" alt="Pagination" class="list-post-img"/></p>
<h2>Pagination? How?</h2>
<p>Unfortunately, changing the posts per page option under your WordPress reading settings does not automatically create pagination; rather, you have two options:</p>
<ol>
<li>Use WordPress&#8217; in-built functions (<code>posts_nav_link</code>, <code>previous_posts_link</code> and/or <code>next_posts_link</code>) to allow the user to navigate between pages.</li>
<li>Create your own pagination system.</li>
</ol>
<p>The main problem with the first option is that WordPress only allows the user to go to the next or previous page; there is no way to jump a set of pages without having to visit everything in-between. Consequently, the bottleneck is in the user-experience.</p>
<p>With the second option, the burden is on the developer. Even though it requires more coding, the user experience is not compromised. As a result, today&#8217;s article will focus on how to write your own <strong>custom WordPress pagination system</strong>. To view a demo, see <a href="/#pagination">Lateral Code&#8217;s pagination</a>.</p>
<p><span id="more-1641"></span></p>
<h2>Specifications</h2>
<p>Before we begin coding, let&#8217;s lay out our specifications. Our pagination system will ensure that the user can visit the first and last page. It will also provide links to pages within a certain range of the current page. We will call this the scope.</p>
<p>For example, if we have twenty pages, our scope is set to two, and the user is currently on page 5, our pagination would look like this:</p>
<pre><code>1	...	3	4	5	6	7	...	20</code></pre>
<p>Note that the ellipses (&#8230;) are just used as visual indicators of a jump in page number.</p>
<p>Since three, four, six, and seven are two of less numbers away from five, they are displayed. In like manner, if we had our scope to set to one, the pagination would be:</p>
<pre><code>1	...	4	5	6	...	20</code></pre>
<p>In this example, three and seven are removed because their range from our current page number, five, is two. This is greater than the scope of one.</p>
<p>Although this system seems to work, what if the scope is two and the current page number is one? No previous page exists to link to. As a result, we can just add more pages to the other side:</p>
<pre><code>1	2	3	4	5	...	20</code></pre>
<p>Since we missed two pages to the left of one, we added them to the right. That&#8217;s why pages four and five are visible. Using the same principal, if our current page is twenty, the pagination would be:</p>
<pre><code>1	...	16	17	18	19	20</code></pre>
<p>In this case, the pages are added to the left since they can&#8217;t be placed to the right.</p>
<h2>Code</h2>
<p>Now that our specification is complete, let&#8217;s begin coding. We will create a pagination function in functions.php which will be later used in our index.php template. The scope, or range, will have a default value of two:</p>
<pre><code>function pagination( $scope = 2 )</code></pre>
<p>Our first task is to find the number of pages and the current page:</p>
<pre><code>global $wp, $posts_per_page;

$numPages = (int) ( wp_count_posts()->publish / $posts_per_page );
if( $numPages < = 1 )
	return; // no need for pagination with one page

$queryVars = $wp->query_vars;
$curPage = isset( $queryVars[ 'paged' ] ) ? (int) $queryVars[ 'paged' ] : 1;</code></pre>
<p><code>wp_count_posts()->publish</code> represents the total number of published posts. <code>$posts_per_page</code> is the posts per page setting under the reading area of the WordPress dashboard. Dividing the former by the latter will give us the number of pages.</p>
<p>To find the current page, we can use the <code>$wp->query_vars</code> array. If the <code>paged</code> key exists, its value will be the page. Otherwise, the user is on page one.</p>
<p>After finding the statistics, we need to create the pagination. Although we know that the first and last page will be included, the middle has yet to be found:</p>
<pre><code>// page bounds
$start = $curPage - $scope;
$end = $curPage + $scope;

// if we can't satisfy the scope (add enough pages) on one side,
// add pages to the other side
if( $start < = 1 ) {
	$end += ( 1 - $start );
	$start = 2;
}
else if( $end >= $numPages ) {
	$start -= ( $end - $numPages );
	$end = $numPages - 1;
}

// limit the start and end to their extreme values
$start = max( $start, 2 );
$end = min( $end, $numPages - 1 );</code></pre>
<p><code>$start</code> and <code>$end</code> correspond the left-most and right-most page value, respectively. The <code>if</code> block is used to display more pages on one side if they cannot be added to the other, as per the last two examples of the specification. Finally, <code>$start</code> and <code>$end</code> are capped at their boundary values to ensure they are within range.</p>
<p>Now that we have the pages, we can aggregate them into an array:</p>
<pre><code>$pagesToLinkTo = array( 1 );
for( $page = $start; $page < = $end; $page++ )
	$pagesToLinkTo[] = $page;
$pagesToLinkTo[] = $numPages;</pre>
<p></code></p>
<p>Finally, we have to process the array and output list elements corresponding to each page number:
</pre>
<pre><code>$prevPage = $pagesToLinkTo[0];
foreach( $pagesToLinkTo as $page ) {
	if( $page - $prevPage > 1 ) // skipped a few pages
		echo '&lt;li&gt;...&lt;/li&gt;'; // add a spacer

	// echo the link
	echo '&lt;li&gt;&lt;a href="' . get_bloginfo( 'home' ) . '/page/' . $page . '"&gt;' . $page . '&lt;/a&gt;&lt;/li&gt;';
	$prevPage = $page;
}</code></pre>
<p>The URL of each page is http://example.com/page/number, where http://example.com is the home of the WordPress site and number is the page number. We link to this URL for each page that we output.</p>
<p>To determine whether we need to add ellipses, we compare the current page with the previous page. If the difference is greater than one, we skipped a few pages and have to add the spacer.</p>
<p>Here is the pagination function as a whole:</p>
<pre><code>function pagination( $scope = 2 ) {
   	global $wp, $posts_per_page;

	$numPages = (int) ( wp_count_posts()->publish / $posts_per_page );
	if( $numPages < = 1 )
		return; // no need for pagination

	$queryVars = $wp->query_vars;
	$curPage = isset( $queryVars[ 'paged' ] ) ? (int) $queryVars[ 'paged' ] : 1;

	// page bounds
	$start = $curPage - $scope;
	$end = $curPage + $scope;

	// if we can't satisfy the scope (add enough pages) on one side,
	// add pages to the other side
	if( $start < = 1 ) {
		$end += ( 1 - $start );
		$start = 2;
	}
	else if( $end >= $numPages ) {
		$start -= ( $end - $numPages );
		$end = $numPages - 1;
	}

	// limit the start and end to their extreme values
	$start = max( $start, 2 );
	$end = min( $end, $numPages - 1 );

	$pagesToLinkTo = array( 1 );
	for( $page = $start; $page < = $end; $page++ )
		$pagesToLinkTo[] = $page;
	$pagesToLinkTo[] = $numPages;

	$prevPage = $pagesToLinkTo[0];
	foreach( $pagesToLinkTo as $page ) {
		if( $page - $prevPage > 1 ) // skipped a few pages
		echo '&lt;li&gt;...&lt;/li&gt;'; // add a spacer

		// echo the link
		echo '&lt;li&gt;&lt;a href="' . get_bloginfo( 'home' ) . '/page/' . $page . '"&gt;' . $page . '&lt;/a&gt;&lt;/li&gt;';
		$prevPage = $page;
	}
}</code></pre>
<h2>Wrapping Up</h2>
<p>To finalize our system, we&#8217;ll have to call this function in our index.php template:</p>
<pre>&lt;ul id="pagination"&gt;
	&lt;?php pagination(); ?&gt;
&lt;/ul&gt;</pre>
<p>Well, that was easy, eh? Remember to style the pagination in accordance to your site&#8217;s design. To view a demo, see the <a href="/#pagination">bottom of Lateral Code&#8217;s home page</a>.</p>
<p>Thanks for reading!</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/3023zBY-bOw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/wordpress-pagination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated Uptime Verification</title>
		<link>http://www.lateralcode.com/automated-uptime-verification/</link>
		<comments>http://www.lateralcode.com/automated-uptime-verification/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 22:58:17 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1618</guid>
		<description><![CDATA[If you have ever administered a website, you know that downtime is unavoidable. Creating a system to automatically check if your website is up can help deal with downtime and provide a better user experience. Doing so is quite simple if you have the following tools available: A web server other that that on which [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever administered a website, you know that downtime is unavoidable. Creating a system to automatically check if your website is up can help deal with downtime and provide a better user experience. Doing so is quite simple if you have the following tools available:</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/automated-uptime-verification/1.jpg" alt="Automated Uptime Verification" class="list-post-img" /></p>
<ul>
<li>A web server other that that on which the website is hosted</li>
<li>Cron (if you do not have this, you can use an online service)</li>
<li>PHP with libcurl support</li>
<li>PHP with mail support (optional)</li>
</ul>
<p><span id="more-1618"></span></p>
<h2>Setting up PHP and libcurl</h2>
<p>In case you don&#8217;t know, libcurl (and its cousin cURL) are tools for working with URLs and web pages. Provided that you have libcurl support and PHP, you can check if a site is active by using the following function:</p>
<pre><code>function checkURL($url) {
	$return = array();
	$curl = curl_init(); // Initialize libcurl
	// set options:
	curl_setopt ($curl, CURLOPT_URL, $url ); // URL to visit
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE); // returns a string instead of echoing to screen
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // follows redirects (recursive)
	curl_setopt($curl, CURLOPT_NOBODY, TRUE); // Only get headers, not content (saves on time)
	$result = curl_exec($curl);
	$errno = curl_errno($curl);
	if ( $errno != 0 ) { // curl_errno returns 0 if no error, otherwise returns the error code
		$return['message'] = "An error occurred while trying to $url! ".curl_err($curl); // If there was an error, return the error message
		$return['success'] = false;
	} else {
		$http = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Get the HTTP return code
		$return['code'] = $http;
		if ( $http &gt;= 200 &#038;&#038; $http &lt; 300 ) { // An HTTP code greater than 200 and less than 300 means a successful load
			$return['message'] = "$url is up! ($http)";
			$return['success'] = true;
		} else {
			$return['message'] = "$url is down! ($http)";
			$return['success'] = false;
		}
	}
	curl_close($curl);
        return $return;
}
</code></pre>
<p>This function returns an array containing a success boolean (true, your site is up or false, your site is down) and a corresponding message string. Now that our checking works as specified, let&#8217;s move on to the notifications.</p>
<h2>Notifications</h2>
<p>In this section, we will present two ways to receive notifications.</p>
<h3>Notification by E-mail/SMS</h3>
<p>After checking the URL, you can use the PHP mail function to send the status to your e-mail account. On the other hand, you can find out the address for your SMS by sending a text to your own e-mail. For example, Verizon phones have the e-mail address &lt;phone number&gt;@vtext.com</p>
<p>The code:</p>
<pre><code>$result = checkURL($your_url);
if ( $result['success'] == true; )
	$subject = "Your site is still up!";
else
	$subject = "Oh no! Your site is down."
mail($your_email, $subject, $result['message']);
</code></pre>
<p>As you can see, this is a fairly easy method with minimal code.</p>
<h3>Push notifications for your iDevice</h3>
<p>If you have an iDevice, such as an iPhone or iPod Touch, you can use <a href="http://en.wikipedia.org/wiki/Apple_Push_Notification_Service">push notifications</a> as an alternative to e-mail or SMS.</p>
<p>First, download the app <a href="http://itunes.apple.com/us/app/pushme-to-free-instant-messages/id343341970?mt=8">pushme.to</a> and make and account. Take note of your username. This app will allow you to send pushed messages to your iDevice.</p>
<p>Then, you will need the following function:</p>
<pre><code>function pushmeto($username, $message) {
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, "http://pushme.to/$username/");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($curl, CURLOPT_POST, TRUE);
	curl_setopt($curl, CURLOPT_POSTFIELDS, "message=".urlencode($message);
	curl_exec($ch);
	curl_close($ch);
}
</code></pre>
<p>Usage is simple:</p>
<pre><code>$result = checkURL($your_url);
pushmeto($your_username, $result['message']);
</code></pre>
<h2>Automation</h2>
<p>Cron can be used to automate the checking uptime process. If you don&#8217;t have cron on your server (which is rare), you can use an online service such as <a href="http://www.onlinecronjobs.com/">Online Cron Jobs</a>.</p>
<p>Cron jobs are set using the following format:</p>
<pre>
[min] [hour] [date] [month] [day_of_week] [command]
</pre>
<p>A cron job set to run at 7am every Tuesday would look like this:</p>
<pre>
0 7 * * 2 [command]
</pre>
<p>For more information on how to use cron, see this <a href="http://adminschoice.com/crontab-quick-reference">quick reference</a>.</p>
<p>As for the command, you can use the following (which assumes you saved the uptime verification code to a file called uptime.php):</p>
<pre>
php /path/to/uptime.php > /dev/null 2>&#038;1
</pre>
<p>Remember, of course, to change the path.</p>
<p>Once activated by the automated command, the code in the PHP file will check if your site is up and notify you. You can set this to occur as often as you want.</p>
<h2>Conclusion</h2>
<p>Do you have any other ways to monitor uptime? If so, please join the discussion below!</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/qUbiPPMKh-k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/automated-uptime-verification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use the new Google Maps API! Part 2</title>
		<link>http://www.lateralcode.com/new-google-maps-api-2/</link>
		<comments>http://www.lateralcode.com/new-google-maps-api-2/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 19:33:30 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1600</guid>
		<description><![CDATA[A few days ago, our experiments with the Google Maps API resulted in static images of various locations. Today, these same experiments will continue in a new medium: JavaScript. As we expand our knowledge of the API, we&#8217;ll cover the creation of a dynamic map, fully equipped with both movement and zooming. View the Demo [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, <a href="http://www.lateralcode.com/new-google-maps-api/">our experiments with the Google Maps API</a> resulted in static images of various locations. Today, these same experiments will continue in a new medium: JavaScript. As we expand our knowledge of the API, we&#8217;ll cover the creation of a dynamic map, fully equipped with both movement and zooming.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/new-google-maps-api-2/1.jpg" alt="Maps" class="list-post-img"/></p>
<p><a class="view" href="http://demo.lateralcode.com/new-google-maps-api-2/">View the Demo</a> <a class="dl" href="http://www.lateralcode.com/wp-content/uploads2/new-google-maps-api-2/new-google-maps-api-2.zip">Download the Files</a></p>
<p><span id="more-1600"></span></p>
<p>To begin our mad science, we&#8217;ll first need to include the API itself (note the HTML 5 that omits the <code>type</code> attribute of the <code>script</code> tag):</p>
<pre><code>&lt;!-- sensor=false tells google images we aren't trying to sense the user's location --&gt;
&lt;script src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;</code></pre>
<p>Moving forward, we&#8217;ll create a function which, when given an address, will display a dynamic map centered on it. Dutifully called <code>setMapAddress</code>, the function will have the following container:</p>
<pre><code>function setMapAddress( address )
{
	// code goes here
}</code></pre>
<p>To specify a location, Google Maps requires a latitude and longitude. As a result, our first task will be to convert the given <code>address</code> into the necessary format. Of course, this process has it&#8217;s own scientific term: geocoding. Being both scientifically and technologically-savvy, Google does the work for us in their <code>Geocoder</code> object. All we need to do is instantiate one and subsequently call its <code>geocode</code> method:</p>
<pre><code>var geocoder = new google.maps.Geocoder();

geocoder.geocode( { address : address }, function( results, status ) {

} );</code></pre>
<p>The geocode method requires, as arguments, an object as well as a callback function. Looking at the first parameter, <code>{ address : address }</code>, may strike initial confusion. The first use of the word <code>address</code> refers to a property of the object. On the contrary, the second use refers to the variable passed into the <code>setMapAddress</code> function, which we are trying to geocode.</p>
<p>Once the geocoding finishes, the callback function is invoked with a <code>results</code> array and <code>status</code> that is used to determine success. If the <code>status</code> notes a successful geocode, we&#8217;ll have to get the location (latitude/longitude) from the <code>results</code> array, setup options (similar to the options for the static images in the previous article), and finally construct the map. In its completed form, the callback function is:</p>
<pre><code>if( status == google.maps.GeocoderStatus.OK ) {
	var latlng = results[0].geometry.location;
	var options = {
		zoom: 8,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	new google.maps.Map( document.getElementById( 'map' ), options );
}</code></pre>
<p>The <code>options</code> object specifies the zoom, center, and type of the resultant map. In this case, these have been set to 8, the given address converted to a latitude/longitude, and road map respectively.</p>
<p>In addition, note that the constructor requires a DOM element and the aforementioned options. This means we&#8217;ll have to create the element, which has an <code>id</code> of <code>map</code>.</p>
<pre><code>&lt;div id="map"&gt;&lt;/div&gt;</code></pre>
<p><code>#map</code> also needs a defined width and height:</p>
<pre><code>#map {
	width: 512px;
	height: 512px;
}</code></pre>
<p>Last, but certainly not least, we have to call the <code>setMapAddress</code> function we recently finished:</p>
<pre>setMapAddress( "Chicago, IL" );</pre>
<p>Voila! That&#8217;s all we need for a functioning dynamic map. You can <a href="http://demo.lateralcode.com/new-google-maps-api-2/">view the demo</a> or <a href="http://www.lateralcode.com/wp-content/uploads2/new-google-maps-api-2/new-google-maps-api-2.zip">download the files</a>.</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/BMATER6IVJs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/new-google-maps-api-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Working with Addresses? Use the new Google Maps API!</title>
		<link>http://www.lateralcode.com/new-google-maps-api/</link>
		<comments>http://www.lateralcode.com/new-google-maps-api/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:10:25 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1575</guid>
		<description><![CDATA[Would you like to travel to Paris? Maybe Singapore? How about Hawaii? Many people love to travel to discover new places, meet family, or just have a great time. In order to get from place to place, they often use maps. Indeed, maps are a vital part of traveling, providing directions to new, exciting locations. [...]]]></description>
			<content:encoded><![CDATA[<p>Would you like to travel to Paris? Maybe Singapore? How about Hawaii? Many people love to travel to discover new places, meet family, or just have a great time. In order to get from place to place, they often use maps. Indeed, maps are a vital part of traveling, providing directions to new, exciting locations.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/new-google-maps-api/1.jpg" alt="Maps" class="list-post-img"/></p>
<p>With the new technology age, maps have moved from tangible paper to the virtual world, allowing anyone to access them with a simple visit to <a href="http://maps.google.com">Google Maps</a>. More importantly, with the new <a href="http://code.google.com/apis/maps/index.html">Google Maps API Version 3</a>, it&#8217;s simple to integrate these maps into any website.</p>
<p>In the following article, I&#8217;ll be explaining how to get started with the new API and embrace the technology from the folks at Google.</p>
<p><span id="more-1575"></span></p>
<h2>Focus</h2>
<p>We&#8217;re going to focus on creating a static map, which is just an image of a location. This is in contrast to a dynamic map, which enables the user to move and zoom. In a follow-up article, which will be posted later this week, we&#8217;ll tackle a dynamic map using JavaScript.</p>
<h2>Static Map</h2>
<p>The static map only requires an image tag and a few configuration options:</p>
<pre><code>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false" alt="Static Map of Chicago, Illinois"&gt;&lt;/img&gt;</code></pre>
<p>It looks a bit daunting at first, but, when broken down, it&#8217;s much easier to understand. Note that all the magic happens in the <code>src</code> attribute:</p>
<ul>
<li><code>http://maps.google.com/maps/api/staticmap?</code> &#8211; the base URL which we pass configuration options to.</li>
<li><code>center=Chicago,IL</code> &#8211; the center of the map, which, in this case, is Chicago, Illinois. Note that this can be any address.</li>
<li><code>zoom=8</code> &#8211; the amount to zoom in. This value was determined purely by experimentation.</li>
<li><code>size=512x512</code> &#8211; the size of the map in pixels. In this case, it&#8217;s 512px by 512px.</li>
<li><code>maptype=roadmap</code> &#8211; the type of the map. Possible values are roadmap, terrain, satellite, and hybrid.</li>
<li><code>sensor=false</code> &#8211; tells Google Maps whether we are trying to sense the user&#8217;s location. In this case, we aren&#8217;t.</li>
</ul>
<p>The above code produces the following image:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false" alt="Static Map of Chicago, Illinois" class="list-post-img"/></p>
<p>We can play around with the options a bit to produce a much different map:</p>
<pre>&lt;img alt="Static Map of New York City, New York" src="http://maps.google.com/maps/api/staticmap?center=New+York+City,NY&#038;zoom=4&#038;size=512x512&#038;maptype=hybrid&#038;sensor=false"&gt;&lt;/img&gt;</pre>
<p>These new configuration options yield the following map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=New+York+City,NY&#038;zoom=4&#038;size=512x512&#038;maptype=hybrid&#038;sensor=false" alt="Static Map of New York City, New York" class="list-post-img"/></p>
<p>When creating maps, it&#8217;s also necessary to mark important locations, whether they be destinations or areas to avoid. To do so, we can use the <code>markers</code> parameter:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=Chicago,IL" alt="Static, Marked Map of Chicago, Illinois"&gt;&lt;/img&gt;</pre>
<p>Notice the new parameter:</p>
<pre>markers=Chicago,IL</pre>
<p>This will create the following marked map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=Chicago,IL" alt="Static, Marked Map of Chicago, Illinois" class="list-post-img"/></p>
<p>We can add in more configuration options to the marker parameter, including a color and a label. For example:</p>
<pre>markers=color:blue|Chicago,IL</pre>
<p>Notice the pipe operator (<code>|</code>) which separates the color from the location. This change will edit the marker color, yielding the following map:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|Chicago,IL" alt="Static, Marked (Blue) Map of Chicago, Illinois" class="list-post-img"/></p>
<p>As you can see, the blue marker still has a dot representing the location. When working with multiple locations, you might want to change this dot to a number or letter in order to differentiate between locations:</p>
<pre>markers=color:blue|label:A|Chicago,IL</pre>
<p>Instead of the dot, the image now has the letter <em>A</em>:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL" alt="Static, Marked (Labeled A) Map of Chicago, Illinois" class="list-post-img"/></p>
<p>To add multiple markers, just add in another <code>markers</code> parameter:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana"&gt;&lt;/img&gt;</pre>
<p>Now there are two markers: one for Chicago, Illinois and another for Hammond, Indiana:<br />
<img src="http://maps.google.com/maps/api/staticmap?center=Chicago,IL&#038;zoom=8&#038;size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana" class="list-post-img"/></p>
<p>This is accomplished using the following marker code:</p>
<pre>markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN</pre>
<p>Finally, when specifying the markers attribute, note that the <code>center</code> and <code>zoom</code> parameters are no longer required. If we omit these, we get the following code:</p>
<pre>&lt;img src="http://maps.google.com/maps/api/staticmap?size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom"&gt;&lt;/img&gt;</pre>
<p>And the corresponding map:<br />
<img src="http://maps.google.com/maps/api/staticmap?size=512x512&#038;maptype=roadmap&#038;sensor=false&#038;markers=color:blue|label:A|Chicago,IL&#038;markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom" class="list-post-img"/></p>
<p>As shown in the image, Google Maps will automatically use a fitting <code>center</code> and <code>zoom</code> in order to display the two locations.</p>
<h2>Conclusion</h2>
<p>As you can see, we&#8217;ve created multiple static maps all through the new Google Maps API. With no needed API key (which was previously required) and some simple URL manipulation, Google makes it near effortless to integrate a map into any website.</p>
<p>Are you interested in the <a href="http://code.google.com/apis/maps/index.html">Google Maps API</a>? Do you have any questions or comments? Did you stumble upon more useful features for static maps? Leave a comment below and a share your thoughts!</p>
<p>Don&#8217;t forget that we&#8217;ll be creating dynamic maps with the JavaScript API later this week!</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/1UCd6mi_wdI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/new-google-maps-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Elegant jQuery Slideshow Plugin: Lateral Slider</title>
		<link>http://www.lateralcode.com/lateral-slider/</link>
		<comments>http://www.lateralcode.com/lateral-slider/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 03:44:57 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1541</guid>
		<description><![CDATA[Let&#8217;s start with the defintion: Slider &#8211; The easiest known way to showcase your images and photos on the web in style. Who can deny it? This is the generation of web 2.0 sliders. A few JavaScript files, some CSS, and a bit of markup is all you need to generate an elegant showcase of [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start with the defintion:</p>
<p>Slider &#8211; The easiest known way to showcase your images and photos on the web in style.</p>
<p>Who can deny it? This is the generation of web 2.0 sliders. A few JavaScript files, some CSS, and a bit of markup is all you need to generate an elegant showcase of your images. Best part? 99% of it is <strong>done for you</strong>.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/lateral-slider/1.jpg" alt="Lateral Slider" class="list-post-img"/></p>
<p>Well, that&#8217;s the ideal situation. Unfortunately, it&#8217;s often times much more complicated. That&#8217;s why I created <a href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/109908?ref=nviswan10">Lateral Slider</a>.</p>
<p><a class="view" href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/full_screen_preview/109908?ref=nviswan10">View the Demo</a><a class="dl" href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/109908?ref=nviswan10">Purchase it from CodeCanyon</a></p>
<p><span id="more-1541"></span></p>
<p>Lateral Slider is a jQuery slideshow plugin that I recently released on <a href="http://codecanyon.net/?ref=nviswan10">CodeCanyon</a>. How does it work? Simple.</p>
<h2>1. Include the CSS/JavaScript</h2>
<p>CSS:</p>
<pre>&lt;link rel="stylesheet" href="slider.css" type="text/css" media="screen" /&gt;</pre>
<p>JavaScript:</p>
<pre>&lt;!-- jQuery --&gt;
&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;!-- Lateral Slider --&gt;
&lt;script src=&quot;slider.jquery.js&quot;&gt;&lt;/script&gt;</pre>
<h2>2. Write the Markup</h2>
<p>All you&#8217;ll need is a div and a few images:</p>
<pre>&lt;div id=&quot;slider&quot;&gt;
	&lt;img src=&quot;image1.jpg&quot; alt=&quot;Image 1&quot; /&gt;
	&lt;img src=&quot;image2.jpg&quot; alt=&quot;Image 2&quot; /&gt;
	&lt;img src=&quot;image3.jpg&quot; alt=&quot;Image 3&quot; /&gt;
&lt;/div&gt;</pre>
<h2>3. Activate Lateral Slider</h2>
<pre>&lt;!-- no need for type="text/javascript" in HTML 5 --&gt;
&lt;script&gt;$( '#slider' ).lateralSlider();&lt;/script&gt;</pre>
<h2>4. Celebrate</h2>
<p>Lateral Slider is ready to be displayed.</p>
<h2>5. Oops, was there supposed to be a fifth step?</h2>
<p>Nope. You&#8217;re done.</p>
<h2>Features</h2>
<p>Simple setup is great, but I&#8217;m sure you&#8217;re also looking for features. Fear not:</p>
<ul>
<li>13 different transitions</li>
<li>Support for all major browsers (including IE6)</li>
<li>Image linking</li>
<li>Many configurable options</li>
<li>Controls (forward, back, pick a slide)</li>
<li>Comprehensive documentation</li>
<li>Much more&#8230;</li>
</ul>
<p>Want to know more? Check out the <a href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/109908?ref=nviswan10">description at CodeCanyon</a>. Better yet, why don&#8217;t you take a look at the <a href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/full_screen_preview/109908?ref=nviswan10">live preview</a> and see Lateral Slider for yourself.</p>
<h2>Purchase It!</h2>
<p>Interested? It&#8217;s only $10. Why not <a href="http://codecanyon.net/item/lateral-slider-jquery-plugin-with-13-transitions/109908?ref=nviswan10">purchase it from CodeCanyon</a>? <img src='http://www.lateralcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/0_75q3FPDDs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/lateral-slider/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Snippet: Generate the DZone Button with PHP (Save HTTP Requests!)</title>
		<link>http://www.lateralcode.com/dzone-button-php/</link>
		<comments>http://www.lateralcode.com/dzone-button-php/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 06:20:54 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1530</guid>
		<description><![CDATA[The folks at DZone provide a great way for developers to share links in one, concentrated area. URLs which rank highly in their system (those that receive many &#8220;up&#8221; votes) often get quite a bit of traffic. As a result, many developers use the DZone button to provide their visitors a way to rate articles [...]]]></description>
			<content:encoded><![CDATA[<p>The folks at <a href="http://www.dzone.com/links/index.html">DZone</a> provide a great way for developers to share links in one, concentrated area. URLs which rank highly in their system (those that receive many &#8220;up&#8221; votes) often get quite a bit of traffic. As a result, many developers use the <a href="http://www.dzone.com/links/buttons.jsp">DZone button</a> to provide their visitors a way to rate articles directly from their own website.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/dzone-button-php/1.jpg" alt="DZone" class="list-post-img"/></p>
<p>Do you use the DZone button on your website? If not, you should definitely consider it. Unfortunately, each one of these buttons requires the inclusion of a JavaScript file, which adds an HTTP request (and thus slows down the page). With some quick studying of the <a href="http://widgets.dzone.com/links/widgets/zoneit.js">included JavaScript</a>, it&#8217;s possible (not to mention quite easy) to generate this same button with only PHP, thus saving a request.</p>
<p><span id="more-1530"></span></p>
<p>Here&#8217;s the function to do so:</p>
<pre><code>function dzone_button( $style, $url, $title, $description = false )
{
	$html = '&lt;iframe src=&quot;http://widgets.dzone.com/links/widgets/zoneit.html?t=' . $style;
	$html .= '&amp;url=' . urlencode( $url ) . '&amp;title=' . urlencode( $title );

	if( $description !== false )
		$html .= '&amp;description=' . $description;

	if( $style == 1 )
		$html .= '&quot; height=&quot;70&quot; width=&quot;50&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;';
	else
		$html .= '&quot; height=&quot;25&quot; width=&quot;155&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;';

	return $html;
}</code></pre>
<p>It requires the same parameters are the JavaScript file: the type of button (1 for tall, 2 for wide), URL, title, and description (optional).</p>
<p>To use it, just plug, chug, and echo:</p>
<pre><code>echo dzone_button( 1, 'http://example.com', 'Example', 'Example description' );</code></pre>
<p>If you&#8217;re using WordPress, consider the following snippet:</p>
<pre><code>echo dzone_button( 1, get_permalink(), get_the_title() );</code></pre>
<p>If you want a description, use <code>get_the_excerpt</code>:</p>
<pre><code>echo dzone_button( 1, get_permalink(), get_the_title(), get_the_excerpt() );</code></pre>
<p>That&#8217;s all there is to it; you&#8217;ve generated the same button without the JavaScript. The only real difference is that you&#8217;ll have an <code>iframe</code> directly in the HTML page rather than one generated by JavaScript. Happy DZoning!</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/-Y1flp4a1Fg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/dzone-button-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Snippet: Backup your Files through SSH</title>
		<link>http://www.lateralcode.com/backup-files-ssh/</link>
		<comments>http://www.lateralcode.com/backup-files-ssh/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 23:38:11 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1517</guid>
		<description><![CDATA[Today we&#8217;re introducing a new type of post at Lateral Code: the simple snippet. These articles are meant to provide you with concise, meaningful snippets of code for use on your website. To kickoff off the simple snippet, we begin with an important topic for any site: backups. Have you ever lost important files? If [...]]]></description>
			<content:encoded><![CDATA[<p><em>Today we&#8217;re introducing a new type of post at Lateral Code: the simple snippet. These articles are meant to provide you with concise, meaningful snippets of code for use on your website. To kickoff off the simple snippet, we begin with an important topic for any site: backups.</em></p>
<p>Have you ever lost important files? If you have, you know the importance of keeping backups.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/backup-files-ssh/1.jpg" alt="Files" class="list-post-img"/></p>
<p>Backups could mean the difference between life and death for your site. It&#8217;s vital to constantly generate backups and even store them on a remote machine in order to ensure full protection. All it takes is a determined attacker to possibly corrupt all of your files. As a result, this simple snippet is focused on getting you started with the backup process.</p>
<p><span id="more-1517"></span></p>
<p>Generating backups through secure-shell (SSH) can be quite a simple task. The <code>tar</code> command is all you&#8217;ll need:</p>
<pre><code>$ tar czvf backup.tar.gz path/to/directory</code></pre>
<p>Let&#8217;s break down this snippet into it&#8217;s constituents:</p>
<pre><code>tar - the command to create a <a href="http://en.wikipedia.org/wiki/Tar_(file_format)">tar file</a>

c - the option that creates a tar ball
z - add gzip compression
v - verbose option to display files that are added to the tar ball
f - used to specify the archive file (in this case backup.tar.gz)

backup.tar.gz - the name of the archive file for the f option
path/to/directory - recursively search this directory for files to place in the tar ball</code></pre>
<p>After running this command on the directory of your choice (generally the public or public_html directory for a full backup), you should have an archive of files which you can easily download to your own computer (or keep on your web server).</p>
<p>You can read more about the <code>tar</code> command <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?tar">here</a>.</p>
<img src="http://feeds.feedburner.com/~r/lateralcode/~4/KIfMyEAVcdk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/backup-files-ssh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

