<?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>Brain Goo &#187; Programming</title>
	<atom:link href="http://www.popmartian.com/tipsntricks/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.popmartian.com/tipsntricks</link>
	<description>Carpe Crap 'em</description>
	<lastBuildDate>Mon, 10 Oct 2011 14:42:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HOW TO detect STDIN with Python</title>
		<link>http://www.popmartian.com/tipsntricks/2011/07/25/how-to-detect-stdin-with-python/</link>
		<comments>http://www.popmartian.com/tipsntricks/2011/07/25/how-to-detect-stdin-with-python/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 16:00:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=214</guid>
		<description><![CDATA[In Python, as with most languages, STDIN is treated like a file. You can read from it any time, but knowing what kind of file it is lets us know if someone passed us something via STDIN or if we are going to prompt them for it. import os, sys if os.isatty(file.fileno(sys.stdin)): &#160;&#160;&#160;&#160;print "Reading list [...]]]></description>
			<content:encoded><![CDATA[<p>In Python, as with most languages, STDIN is treated like a file.  You can read from it any time, but knowing what kind of file it is lets us know if someone passed us something via STDIN or if we are going to prompt them for it.</p>
<p><code>import os, sys</p>
<p>if os.isatty(file.fileno(sys.stdin)):<br />
&nbsp;&nbsp;&nbsp;&nbsp;print "Reading list from STDIN."<br />
&nbsp;&nbsp;&nbsp;&nbsp;print "Enter your list. Press ^D to continue, ^C to quit."<br />
&nbsp;&nbsp;&nbsp;&nbsp;my_list = sys.stdin.readlines()<br />
else:<br />
&nbsp;&nbsp;&nbsp;&nbsp;print "Thank you for passing me a list through a pipe."<br />
&nbsp;&nbsp;&nbsp;&nbsp;my_list = sys.stdin.readlines()</code></p>
<p>Now lets try it two ways:</p>
<p>First, pass it some stuff:<br />
<code>echo mother sister father brother | ./myapp.py</code></p>
<p>Then try it plain:<br />
<code>./myapp.py</code></p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=214&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2011/07/25/how-to-detect-stdin-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HowTo Use an HTTP Proxy With Git</title>
		<link>http://www.popmartian.com/tipsntricks/2011/04/29/howto-use-an-http-proxy-with-git/</link>
		<comments>http://www.popmartian.com/tipsntricks/2011/04/29/howto-use-an-http-proxy-with-git/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 16:03:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=210</guid>
		<description><![CDATA[git should use the environment variable $http_proxy so set that and you should be ok. If you don&#8217;t want to use the environment, set it statically like this: $ git config --global http.proxy http://proxy.example.com:8080 $ git config --get http.proxy http://proxy.example.com:8080]]></description>
			<content:encoded><![CDATA[<p>git should use the environment variable $http_proxy so set that and you should be ok.  If you don&#8217;t want to use the environment, set it statically like this:</p>
<p><code>$ git config --global http.proxy http://proxy.example.com:8080<br />
$ git config --get http.proxy</p>
<p>http://proxy.example.com:8080</code></p>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=210&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2011/04/29/howto-use-an-http-proxy-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build A Custom PERL Installation</title>
		<link>http://www.popmartian.com/tipsntricks/2011/04/11/build-a-custom-perl-installation/</link>
		<comments>http://www.popmartian.com/tipsntricks/2011/04/11/build-a-custom-perl-installation/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 18:55:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=198</guid>
		<description><![CDATA[If you want to build a PERL installation that is separate from your standard PERL, you can compile one, complete with CPAN support. Just follow these steps: mkdir /custom/perl/ cd /custom/perl/ curl -O http://www.cpan.org/src/perl-5.12.3.tar.gz mkdir perl-5_12_3 gunzip perl-5.12.3.tar.gz tar -xf perl-5.12.3.tar cd perl-5.12.3 ./Configure -d -Dprefix=/custom/perl/perl-5_12_3 make make test make install /custom/perl/perl-5_12_3/bin/perl -v /custom/perl/perl-5_12_3/bin/perl -e [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to build a PERL installation that is separate from your standard PERL, you can compile one, complete with CPAN support.  Just follow these steps:</p>
<ol>
<li>mkdir /custom/perl/</li>
<li>cd /custom/perl/</li>
<li>curl -O http://www.cpan.org/src/perl-5.12.3.tar.gz</li>
<li>mkdir perl-5_12_3</li>
<li>gunzip perl-5.12.3.tar.gz</li>
<li>tar -xf perl-5.12.3.tar</li>
<li>cd perl-5.12.3</li>
<li>./Configure -d -Dprefix=/custom/perl/perl-5_12_3</li>
<li>make</li>
<li>make test</li>
<li>make install</li>
<li>/custom/perl/perl-5_12_3/bin/perl -v</li>
<li>/custom/perl/perl-5_12_3/bin/perl -e &#8216;print &#8220;hello world.\n&#8221;;&#8217;</li>
<li>/custom/perl/perl-5_12_3/bin/perl -MCPAN -e shell
<ul>
<li>Auto configure as much as possible.  Step 15 will edit it.</li>
</ul>
</li>
<li>Edit /custom/perl/perl-5_12_3/lib/5.12.3/CPAN/Config.pm
<ul>
<li>Change the following paths:</li>
<li>&#8216;cpan_home&#8217; =&gt; q[/custom/perl/perl-5_12_3/cpan/],</li>
<li>&#8216;build_dir&#8217; =&gt; q[/custom/perl/perl-5_12_3/cpan/build],</li>
<li>&#8216;histfile&#8217; =&gt; q[/custom/perl/perl-5_12_3/cpan/histfile],</li>
<li>&#8216;keep_source_where&#8217; =&gt; q[/custom/perl/perl-5_12_3/cpan/sources],</li>
<li>&#8221;prefs_dir&#8217; =&gt; q[/custom/perl/perl-5_12_3/cpan/prefs],</li>
<li>&#8221;urllist&#8217; =&gt; [q[ftp://my.cpan.mirror/pub/cpan/]],</li>
</ul>
</li>
<li>Run CPAN and install Bundle::CPAN Bundle::LWP and any required packages</li>
<li>tar -cvf /custom/perl/custom-perl5.12.13.tar /custom/perl/perl-5_12_3/*</li>
<li>gzip /custom/perl/custom-perl5.12.13.tar</li>
<li>Ship custom-perl5.12.13.tar.gz out to your matching architectures or mount it on a shared NAS.</li>
<li>Call it with #!/custom/perl/perl-5_12_3/bin/perl</li>
</ol>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=198&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2011/04/11/build-a-custom-perl-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Pass PERL Library Paths From The Environment</title>
		<link>http://www.popmartian.com/tipsntricks/2011/04/11/how-to-pass-perl-library-paths-from-the-environment/</link>
		<comments>http://www.popmartian.com/tipsntricks/2011/04/11/how-to-pass-perl-library-paths-from-the-environment/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 18:07:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=192</guid>
		<description><![CDATA[You can have PERL look in different places for libraries and modules using a number of methods. If you find yourself using a custom PERL module repository, you can make sure your PERL programs always reference it without touching the code. What we&#8217;re doing in a nutshell is telling PERL to push values on to [...]]]></description>
			<content:encoded><![CDATA[<p>You can have PERL look in different places for libraries and modules using a number of methods.  If you find yourself using a custom PERL module repository, you can make sure your PERL programs always reference it without touching the code.</p>
<p>What we&#8217;re doing in a nutshell is telling PERL to push values on to the @INC array before loading any modules.  You can do this on the command line, in your PERL code or with the environment variable <code>PERL5LIB</code>.</p>
<p><code>PERL5LIB</code> can contain more than one value.  Just set it in you .bashrc file or wherever you see fit.  This method works in bash:</p>
<p><code>export PERL5LIB=/first/path/to/libs"${PERL5LIB:+:$PERL5LIB}"<br />
export PERL5LIB=/second/path/to/libs"${PERL5LIB:+:$PERL5LIB}"<br />
export PERL5LIB=/third/path/to/libs"${PERL5LIB:+:$PERL5LIB}"</code></p>
<p>You can check what PERL is going to use by printing out the contents of @INC.  <a href="http://www.popmartian.com/tipsntricks/2009/02/06/perl-how-to-print-a-list-without-a-loop/">You can print an array without a loop using join() as I blogged about before</a>:</p>
<p><code>perl -e 'print join "\n", @INC;'</code></p>
<p>Let&#8217;s put it together:<br />
~$ <code>perl -e 'print join "\n", @INC;'</code><br />
<em>/etc/perl<br />
/usr/local/lib/perl/5.10.0<br />
/usr/local/share/perl/5.10.0<br />
/usr/lib/perl5<br />
/usr/share/perl5<br />
/usr/lib/perl/5.10<br />
/usr/share/perl/5.10<br />
/usr/local/lib/site_perl<br />
.</em></p>
<p>~$ <code>env|grep -i perl</code><br />
~$</p>
<p>~$ <code>export PERL5LIB=/first/path/to/libs"${PERL5LIB:+:$PERL5LIB}"</code><br />
~$ <code>export PERL5LIB=/second/path/to/libs"${PERL5LIB:+:$PERL5LIB}"</code><br />
~$ <code>export PERL5LIB=/third/path/to/libs"${PERL5LIB:+:$PERL5LIB}"</code></p>
<p>~$ <code>env|grep -i perl</code><br />
<em>PERL5LIB=/third/path/to/libs:/second/path/to/libs:/first/path/to/libs</em></p>
<p>~$ <code>perl -e 'print join "\n", @INC;'</code><br />
<em>/third/path/to/libs<br />
/second/path/to/libs<br />
/first/path/to/libs<br />
/etc/perl<br />
/usr/local/lib/perl/5.10.0<br />
/usr/local/share/perl/5.10.0<br />
/usr/lib/perl5<br />
/usr/share/perl5<br />
/usr/lib/perl/5.10<br />
/usr/share/perl/5.10<br />
/usr/local/lib/site_perl<br />
.</em></p>
<p>And there it is.  Your PERL apps will look in those locations starting from the top.</p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=192&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2011/04/11/how-to-pass-perl-library-paths-from-the-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Prevent A PERL Script From Running As Root</title>
		<link>http://www.popmartian.com/tipsntricks/2011/03/29/how-to-prevent-a-perl-script-from-running-as-root/</link>
		<comments>http://www.popmartian.com/tipsntricks/2011/03/29/how-to-prevent-a-perl-script-from-running-as-root/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 03:11:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=184</guid>
		<description><![CDATA[At or near the top of your app, before it executes anything sensitive, place the following code: if((getpwuid($]]></description>
			<content:encoded><![CDATA[<p>At or near the top of your app, before it executes anything sensitive, place the following code:</p>
<p><code>if((getpwuid($<) eq "root") || ($< == 0)){<br />
    print STDOUT "Cannot run as root!\n";<br />
    exit(1);<br />
}</code></p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=184&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2011/03/29/how-to-prevent-a-perl-script-from-running-as-root/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python HOWTO Push a Dict on to a List (push a hash on to an array)</title>
		<link>http://www.popmartian.com/tipsntricks/2010/04/23/python-howto-push-a-dict-on-to-a-list-push-a-hash-on-to-an-array/</link>
		<comments>http://www.popmartian.com/tipsntricks/2010/04/23/python-howto-push-a-dict-on-to-a-list-push-a-hash-on-to-an-array/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 14:37:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=159</guid>
		<description><![CDATA[One of my more popular posts is How to Push a Hash on to an Array in PERL, but how do you push a dict on to a list in Python? Lists are one-dimensional arrays and dicts are associative arrays or hash arrays.  This means we can do the same thing we do in other [...]]]></description>
			<content:encoded><![CDATA[<p>One of my more popular posts is <a href="http://www.popmartian.com/tipsntricks/2008/08/12/perl-howto-push-a-hash-onto-an-array/">How to Push a Hash on to an Array in PERL</a>, but how do you push a dict on to a list in Python?</p>
<p>Lists are one-dimensional arrays and dicts are associative arrays or hash arrays.  This means we can do the same thing we do in other languages, with syntax to match Python&#8217;s object-oriented data structures.</p>
<p><code>import pprint</code></p>
<p><code># Define the list<br />
somelist = []</code></p>
<p><code># Do add some elements to the list<br />
somelist.append({'key1':'value1', 'key2': 'value2'})<br />
somelist.append({'key1':'value1', 'key2': 'value2'})<br />
somelist.append({'key1':'value1', 'key2': 'value2'})</code></p>
<p><code># Print it out<br />
pp = pprint.PrettyPrinter(indent=4)<br />
pp.pprint(somelist)</code></p>
<p>Will give you:</p>
<p><code>[   {   'key1': 'value1', 'key2': 'value2'},<br />
{   'key1': 'value1', 'key2': 'value2'},<br />
{   'key1': 'value1', 'key2': 'value2'}]</code></p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=159&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2010/04/23/python-howto-push-a-dict-on-to-a-list-push-a-hash-on-to-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PERL How To Print A List Without A Loop</title>
		<link>http://www.popmartian.com/tipsntricks/2009/02/06/perl-how-to-print-a-list-without-a-loop/</link>
		<comments>http://www.popmartian.com/tipsntricks/2009/02/06/perl-how-to-print-a-list-without-a-loop/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 16:47:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=71</guid>
		<description><![CDATA[PERL has a built-in function called join() that will concatenate a list with a given string. The official perldoc states: join EXPR,LIST Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example: $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell); From the code example, you [...]]]></description>
			<content:encoded><![CDATA[<p>PERL has a built-in function called join() that will concatenate a list with a given string.  The official perldoc states:</p>
<p><em><strong>join EXPR,LIST</strong><br />
Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example:</em><br />
<code>$rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);</code></p>
<p>From the code example, you can make CSV output and all kinds of goodies, but what the doc misses and the example doesn&#8217;t show is that combining join() with a print statement makes writing lists to STDOUT or a file handle a snap.  This is where join() really shines.</p>
<p>Example:</p>
<p><em><strong>Code</strong></em><br />
<code>@names = ('Mark', 'Jim', 'Bob','Mary','Steven','Gomer');<br />
print join("\n", @names);</code></p>
<p><em><strong>Output</strong><br />
Mark<br />
Jim<br />
Bob<br />
Mary<br />
Steven<br />
Gomer</em></p>
<p>Note that this will NOT print a final or beginning string.  Join() concatenates the elements, meaning it puts the string value BETWEEN the list elements.</p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=71&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2009/02/06/perl-how-to-print-a-list-without-a-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>perl howto push a hash onto an array</title>
		<link>http://www.popmartian.com/tipsntricks/2008/08/12/perl-howto-push-a-hash-onto-an-array/</link>
		<comments>http://www.popmartian.com/tipsntricks/2008/08/12/perl-howto-push-a-hash-onto-an-array/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 20:59:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/?p=24</guid>
		<description><![CDATA[use Data::Dumper; my @array; push @array, {'key1' =&#62; 'value1', 'key2' =&#62; 'value2'}; push @array, {'key1' =&#62; 'value1', 'key2' =&#62; 'value2'}; push @array, {'key1' =&#62; 'value1', 'key2' =&#62; 'value2'}; print Dumper(@array); Will give you: $VAR1 = { 'key2' =&#62; 'value2', 'key1' =&#62; 'value1' }; $VAR2 = { 'key2' =&#62; 'value2', 'key1' =&#62; 'value1' }; $VAR3 = [...]]]></description>
			<content:encoded><![CDATA[<p><code>use Data::Dumper;<br />
my @array;<br />
push @array, {'key1' =&gt; 'value1', 'key2' =&gt; 'value2'};<br />
push @array, {'key1' =&gt; 'value1', 'key2' =&gt; 'value2'};<br />
push @array, {'key1' =&gt; 'value1', 'key2' =&gt; 'value2'};<br />
print Dumper(@array);</code></p>
<p>Will give you:<br />
<code><br />
$VAR1 = {<br />
'key2' =&gt; 'value2',<br />
'key1' =&gt; 'value1'<br />
};<br />
$VAR2 = {<br />
'key2' =&gt; 'value2',<br />
'key1' =&gt; 'value1'<br />
};<br />
$VAR3 = {<br />
'key2' =&gt; 'value2',<br />
'key1' =&gt; 'value1'<br />
};<br />
</code></p>
<p>Snazzy!</p>
<blockquote><p>Did you find this post useful or have questions or comments?  Please let me know!</p></blockquote>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=24&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2008/08/12/perl-howto-push-a-hash-onto-an-array/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick Character Escaping in PHP</title>
		<link>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/</link>
		<comments>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 17:48:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/</guid>
		<description><![CDATA[When writing PHP web apps, I tend to run in to a portability issue when dealing with SQL connectivity. Since I can&#8217;t count on having the PEAR DB module available, I rolled my own set of functions to interact with a MySQL database. The problem lies in escaping characters in your SQL queries. Do I [...]]]></description>
			<content:encoded><![CDATA[<p>When writing PHP web apps, I tend to run in to a portability issue when dealing with SQL connectivity.  Since I can&#8217;t count on having the PEAR DB module available, I rolled my own set of functions to interact with a MySQL database.</p>
<p>The problem lies in escaping characters in your SQL queries.  Do I <code>addslashes()</code>?  Is magic_quotes_gpc enabled?</p>
<p>My quick-and-dirty solution is the following function:</p>
<p><code><br />
function request_cleanup()<br />
{<br />
&nbsp;&nbsp;if(get_magic_quotes_gpc() == 0)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;foreach($_REQUEST as $req_key => $req_value)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$_REQUEST[$req_key]=addslashes($_REQUEST[$req_key]);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>By calling that function on every page that deals with inserting content in to the database, I know will will get my content escaped correctly.</p>
<p>Of course it escapes all submitted content, including that which isn&#8217;t going in to the database so don&#8217;t forget to <code>stripslashes()</code> when you are working with data that doesn&#8217;t need it.</p>
<p>Example:<br />
<code><br />
request_cleanup();</p>
<p>$notes = $_REQUEST['notes '];<br />
$confirmation = stripslashes($_REQUEST['notes ']);</p>
<p>$SQL = "INSERT INTO notes (note) VALUES ('$notes')";<br />
sql_proc($SQL);</p>
<p>print "Your note was: $confirmation";<br />
</code></p>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=18&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2007/10/10/quick-character-escaping-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl code to find an IP A in subnet B/C</title>
		<link>http://www.popmartian.com/tipsntricks/2007/06/05/perl-code-to-find-an-ip-a-in-subnet-bc/</link>
		<comments>http://www.popmartian.com/tipsntricks/2007/06/05/perl-code-to-find-an-ip-a-in-subnet-bc/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 22:14:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[ip addressing]]></category>
		<category><![CDATA[ipv4]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/2007/06/05/perl-code-to-find-an-ip-a-in-subnet-bc/</guid>
		<description><![CDATA[my $ip = '1.2.3.4'; my $block1 = '1.2.3.0/27'; if(checkip($ip, $block1)) { print STDOUT "$ip is in $block1\n"; } else { print STDOUT "$ip is not in $block1\n"; } sub checkip() { my $ip = shift; my $block = shift; @ip1 = split(/\./, $ip); $ip1 = $ip1[0] * 2**24 + $ip1[1] * 2**16 + $ip1[2] * [...]]]></description>
			<content:encoded><![CDATA[<pre>
my $ip = '1.2.3.4';
my $block1 = '1.2.3.0/27';

if(checkip($ip, $block1)) {
    print STDOUT "$ip is in $block1\n";
}
else {
    print STDOUT "$ip is not in $block1\n";
}

sub checkip() {
    my $ip = shift;
    my $block = shift;

    @ip1 = split(/\./, $ip);
    $ip1 = $ip1[0] * 2**24 + $ip1[1] * 2**16 + $ip1[2] * 2**8 + $ip1[3];
    my @temp = split(/\//, $block);

    $ip2 = $temp[0];
    my $netmask = $temp[1];

    @ip2 = split(/\./, $ip2);
    $ip2 = $ip2[0] * 2**24 + $ip2[1] * 2**16 + $ip2[2] * 2**8 + $ip2[3];

    if( $ip1 >> (32-$netmask) == $ip2 >> (32-$netmask) ) {
            return 1;
    }
    return 0;
}</pre>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=8&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2007/06/05/perl-code-to-find-an-ip-a-in-subnet-bc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

