<?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>amnuts &#187; snippet</title>
	<atom:link href="http://blog.amnuts.com/tag/snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amnuts.com</link>
	<description>php projects, javascript, and... stuff.</description>
	<lastBuildDate>Fri, 07 May 2010 09:11:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Easy table sorting with jQuery</title>
		<link>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/</link>
		<comments>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 16:48:32 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=115</guid>
		<description><![CDATA[I came across a jQuery plug-in the other day to sort tables, and it works great and is exceptionally simple to implement (and as anyone who&#8217;s flicked through this blog knows, I like the simple things in life&#8230; Don&#8217;t need any more gray hairs popping up, you know!).
The plug-in is called tablesorter (found at tablesorter.com), [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a jQuery plug-in the other day to sort tables, and it works great and is exceptionally simple to implement (and as anyone who&#8217;s flicked through this blog knows, I like the simple things in life&#8230; Don&#8217;t need any more gray hairs popping up, you know!).</p>
<p>The plug-in is called <a href="http://www.tablesorter.com/">tablesorter (found at tablesorter.com)</a>, by <a href="http://lovepeacenukes.com/">Christian Bach</a>.<br />
<span id="more-115"></span><br />
As I mentioned, it&#8217;s really simple to implement:</p>
<pre class="brush: jscript;">
    $(&quot;table.sortable&quot;).tablesorter();
</pre>
<p>But also gives you the ability to add extra functionality by the use of &#8216;widgets&#8217;.  One example of a widget from the tablesorter site is to add headers every number of rows.  Here&#8217;s my rather paltry contribution to the widgets &#8211; highlighting rows when you hover over them.</p>
<pre class="brush: jscript;">
$.tablesorter.addWidget({
    id: &quot;highlightOnHover&quot;,
    format: function(table) {
        $(&quot;tbody tr.highlight&quot;, table).remove();
        $(&quot;tbody tr&quot;, table).hover(
            function(){ $(this).children(&quot;td&quot;).addClass(&quot;highlight&quot;); },
            function(){ $(this).children(&quot;td&quot;).removeClass(&quot;highlight&quot;); }
        );
    }
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple pleasures with jQuery</title>
		<link>http://blog.amnuts.com/2009/01/28/simple-pleasures-with-jquery/</link>
		<comments>http://blog.amnuts.com/2009/01/28/simple-pleasures-with-jquery/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 10:22:50 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=110</guid>
		<description><![CDATA[Somethings it&#8217;s the simple things in life that make you really happy.  For me yesterday, that was thanks to jQuery.  Have you ever wanted to have a check box that, when the user checks it it also checks a lot of other checkboxes?  Yeah, of course you have!  I wanted to do that yesterday.  Now, [...]]]></description>
			<content:encoded><![CDATA[<p>Somethings it&#8217;s the simple things in life that make you really happy.  For me yesterday, that was thanks to jQuery.  Have you ever wanted to have a check box that, when the user checks it it also checks a lot of other checkboxes?  Yeah, of course you have!  I wanted to do that yesterday.  Now, it&#8217;s not the first time I&#8217;ve had to do that kind of functionality, but it always came with a bunch of javascript that seemed over the top for what was wanted.  With jQuery it just took a line or two of code!</p>
<pre lang="javascript">
    $(document).ready(function() {
        $('#selectall').click(function() {
        	$(":checkbox", $('#checkboxlist')).attr('checked', $(this).is(':checked'));
        });
    });
</pre>
<p>And with that, on and off go the other checkboxes.</p>
<p>Marvelous!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/01/28/simple-pleasures-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Force a file download</title>
		<link>http://blog.amnuts.com/2007/10/24/force-a-file-download/</link>
		<comments>http://blog.amnuts.com/2007/10/24/force-a-file-download/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 12:03:01 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/2007/10/24/force-a-file-download/</guid>
		<description><![CDATA[Here&#8217;s a small function that will allow you to force a file download.
/**
 * Force a file download via HTTP.
 *
 * File is required to be on the same server and accessible via a path.
 * If the file cannot be found or some other error occurs then a
 * '204 No content' header [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a small function that will allow you to force a file download.</p>
<pre class="brush: php;">/**
 * Force a file download via HTTP.
 *
 * File is required to be on the same server and accessible via a path.
 * If the file cannot be found or some other error occurs then a
 * '204 No content' header is sent.
 *
 * @param string $path Path and file name
 * @param string $name Name of file when saved on user's computer,
 *                     null for basename from path
 * @param string $type Content type header info (e.g., 'application/vnd.ms-excel')
 * @return void
 * @access public
 */
/* public static */ function download($path, $name = null, $type = 'binary/octet-stream')
{
    if (headers_sent()) {
        echo 'File download failure: HTTP headers have already been sent and cannot be changed.';
        exit;
    }

    $path = realpath($path);
    if ($path === false || !is_file($path) || !is_readable($path)) {
        header('HTTP/1.0 204 No Content');
        exit;
    }

    $name = (empty($name)) ? basename($path) : $name;
    $size = filesize($path);

    header('Expires: Mon, 20 May 1974 23:58:00 GMT');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', false);
    header('Cache-Control: private');
    header('Pragma: no-cache');
    header(&quot;Content-Transfer-Encoding: binary&quot;);
    header(&quot;Content-type: {$type}&quot;);
    header(&quot;Content-length: {$size}&quot;);
    header(&quot;Content-disposition: attachment; filename=\&quot;{$name}\&quot;&quot;);
    readfile($path);
    exit;
}</pre>
<p>Very easy to use, too!  Here are some examples of how you might call the function:</p>
<pre class="brush: php;">download('./myfile.txt');

download(__FILE__, 'a file for you.php');

download('/home/you/files/spreadsheet.xml', 'ssheet_' . date('Ymd'), 'application/vnd.ms-excel');</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2007/10/24/force-a-file-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
