<?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>Just answer the F*#king question</title>
	<atom:link href="http://www.jatfq.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jatfq.com</link>
	<description></description>
	<lastBuildDate>Fri, 06 Aug 2010 13:05:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Allow ZLIB compression in CURL and PHP</title>
		<link>http://www.jatfq.com/archives/149</link>
		<comments>http://www.jatfq.com/archives/149#comments</comments>
		<pubDate>Fri, 06 Aug 2010 13:05:27 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/?p=149</guid>
		<description><![CDATA[function file_get_contents_utf8($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HEADER, 1); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $URL); curl_setopt($c, CURLOPT_HTTPHEADER, array("Accept-Encoding: gzip, deflate","Accept: */*")); $ret = curl_exec($c); curl_close($c); if(strpos($ret, "\r\n\r\n")){ $add = 4; }else{ $add = 0; } $m_body = substr($ret, strpos($ret, "\r\n\r\n")+$add ); $m_header = substr($ret, 0, -strlen($m_body)); if(strstr($m_header,"Content-Encoding: gzip")){ $contents = gzinflate(substr($m_body,10)); }else{ [...]]]></description>
			<content:encoded><![CDATA[<p><code>function file_get_contents_utf8($URL)<br />
    {<br />
        $c = curl_init();<br />
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);<br />
	 curl_setopt($c, CURLOPT_HEADER,         1);<br />
	 curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);<br />
        curl_setopt($c, CURLOPT_URL, $URL);<br />
	 curl_setopt($c, CURLOPT_HTTPHEADER, array("Accept-Encoding: gzip, deflate","Accept: */*"));<br />
        $ret = curl_exec($c);<br />
        curl_close($c);</p>
<p>	if(strpos($ret, "\r\n\r\n")){<br />
		$add = 4;<br />
	}else{<br />
		$add = 0;<br />
	}</p>
<p>	$m_body   = substr($ret, strpos($ret, "\r\n\r\n")+$add );<br />
	$m_header = substr($ret, 0, -strlen($m_body));</p>
<p>	if(strstr($m_header,"Content-Encoding: gzip")){<br />
		$contents =  gzinflate(substr($m_body,10));<br />
	}else{<br />
		$contents = $m_body;<br />
	}</p>
<p>        if ($contents) return $contents;<br />
            else return FALSE;<br />
    }</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F149&amp;title=Allow+ZLIB+compression+in+CURL+and+PHP" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/149/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find unused indexes in Postgresql</title>
		<link>http://www.jatfq.com/archives/147</link>
		<comments>http://www.jatfq.com/archives/147#comments</comments>
		<pubDate>Thu, 29 Jul 2010 00:56:05 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
				<category><![CDATA[Postgresql]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/?p=147</guid>
		<description><![CDATA[SELECT *, (pg_relation_size(indexrelname)) FROM pg_stat_all_indexes WHERE schemaname = 'public' ORDER BY pg_relation_size(indexrelname) DESC, idx_scan ASC]]></description>
			<content:encoded><![CDATA[<p><code>SELECT *, (pg_relation_size(indexrelname))<br />
 FROM pg_stat_all_indexes<br />
 WHERE schemaname = 'public'<br />
 ORDER BY pg_relation_size(indexrelname) DESC, idx_scan ASC</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F147&amp;title=Find+unused+indexes+in+Postgresql" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/147/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selecting random single row on large table</title>
		<link>http://www.jatfq.com/archives/142</link>
		<comments>http://www.jatfq.com/archives/142#comments</comments>
		<pubDate>Tue, 13 Jul 2010 21:27:26 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
				<category><![CDATA[Postgresql]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/?p=142</guid>
		<description><![CDATA[This assumes that id is your unique SERIAL field, and that {table}_id_seq is the field for the next value. select * from {table} where id >= ( select floor(random() * ( select last_value from {table}_id_seq )) ) order by id asc limit 1]]></description>
			<content:encoded><![CDATA[<p>This assumes that id is your unique SERIAL field, and that {table}_id_seq is the field for the next value.</p>
<p><code>select * from {table}<br />
where id >= (<br />
select floor(random() * (<br />
select last_value<br />
from {table}_id_seq )) ) order by id asc limit 1</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F142&amp;title=Selecting+random+single+row+on+large+table" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/142/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting apache fullstatus to work</title>
		<link>http://www.jatfq.com/archives/136</link>
		<comments>http://www.jatfq.com/archives/136#comments</comments>
		<pubDate>Mon, 12 Jul 2010 17:23:18 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/archives/136</guid>
		<description><![CDATA[Make sure mod_status is enabled in your httpd / apache config, and add the following lines ExtendedStatus On SetHandler server-status Order deny,allow Deny from all Allow from localhost If you are getting permission errors, try setting UseCanonicalName Off]]></description>
			<content:encoded><![CDATA[<p>Make sure mod_status is enabled in your httpd / apache config, and add the following lines</p>
<p><code><br />
ExtendedStatus On<br />
<code><</code>Location /server-status><br />
SetHandler server-status<br />
Order deny,allow<br />
Deny from all<br />
Allow from localhost<br />
<code><</code>/Location></code></p>
<p>If you are getting permission errors, try setting</p>
<p><code>UseCanonicalName Off</code></p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F136&amp;title=Getting+apache+fullstatus+to+work" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/136/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using IPtables and PHP to block SPAM/DOS</title>
		<link>http://www.jatfq.com/archives/130</link>
		<comments>http://www.jatfq.com/archives/130#comments</comments>
		<pubDate>Thu, 08 Jul 2010 01:30:53 +0000</pubDate>
		<dc:creator>Sime</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.jatfq.com/?p=130</guid>
		<description><![CDATA[Had some issues with bots hammering one of my servers. For a while I was blocking by hand and returning 404 errors, with a simple 404 redirect, however, this will still used up resources and http / apache threads. This is a very basic method that was implemented to stop spammers from your site. You [...]]]></description>
			<content:encoded><![CDATA[<p>Had some issues with bots hammering one of my servers. For a while I was blocking by hand and returning 404 errors, with a simple 404 redirect, however, this will still used up resources and http / apache threads.</p>
<p>This is a very basic method that was implemented to stop spammers from your site. You could modify this to be a bit more intelligent, in this case I have a &#8220;honeypot&#8221; page that only the spammers and bad bots seem to access plus a few sanity checks just incase google visits by accident, however, you could put a counter in to a DB or do some other simple checking before triggering the firewall.  </p>
<p>First step, you need to use visudo to allow apache ( or www-data ) access to iptables.</p>
<p><code>visudo</code></p>
<p>and then add the following line</p>
<p><code>apache ALL = NOPASSWD: /sbin/iptables -I INPUT -m iprange --src-range * -j DROP</code></p>
<p>Replace &#8220;apache&#8221; with www-data if needed ( if you are unsure, do a <code>ps -al | grep apache </code> or  <code>ps -al | grep httpd</code> ) and get the user &#8230; we hope apache is not running as root.</p>
<p>This will allow the apache user access to the specific command above. You could probably lock this down more if needed.</p>
<p>Exit out, and then add the following to your &#8220;honeypot&#8221; page</p>
<p><code>exec("sudo /sbin/iptables -I INPUT -m iprange --src-range ".$REMOTE_ADDR."-".$REMOTE_ADDR." -j DROP");</code></p>
<p>Now, obviously <strong>DON&#8217;T TEST THIS FROM YOUR OWN IP</strong>. Otherwise your going to block yourself from your server. To test, hardcode a different IP in there or do it from another public IP. </p>
<p>So, hopefully, the next time a spammy IP comes and touches your IP address, they will be locked right out. If someone gets blocked by accident, do a <code>sh /etc/init.d/iptables save</code> then edit the saved files ( normally /<code>etc/sysconfig/iptables </code>) to remove the DROP command for that IP and then <code>sh /etc/init.d/iptables restart</code></p>
<p>You could also modify the code to block a bigger range of IP&#8217;s by padding the range to the class C address or more depending on what level of activity you are getting.</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.jatfq.com%2Farchives%2F130&amp;title=Using+IPtables+and+PHP+to+block+SPAM%2FDOS" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://www.jatfq.com/archives/130/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
