<?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>Thu, 20 May 2010 17:52:39 +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>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[Software]]></category>
		<category><![CDATA[python]]></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 languages, [...]]]></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>
<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[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[perl]]></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 can make CSV [...]]]></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[Programming]]></category>
		<category><![CDATA[perl]]></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 = {
'key2' =&#62; 'value2',
'key1' =&#62; 'value1'
};

Snazzy!
Did you find this post useful or have questions or comments?  [...]]]></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[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[php]]></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 [...]]]></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[Programming]]></category>
		<category><![CDATA[ip addressing]]></category>
		<category><![CDATA[ipv4]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[perl]]></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);
    [...]]]></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>
		<item>
		<title>PHP Header injection</title>
		<link>http://www.popmartian.com/tipsntricks/2007/05/21/php-header-injection/</link>
		<comments>http://www.popmartian.com/tipsntricks/2007/05/21/php-header-injection/#comments</comments>
		<pubDate>Mon, 21 May 2007 17:43:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How Tos]]></category>
		<category><![CDATA[Mail Post]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/2007/05/21/php-header-injection/</guid>
		<description><![CDATA[I regularly shut down web sites that use the PHP mail() function.  While the users of the sites mean well, they generally don&#8217;t do any checking before sending data to mail().  I&#8217;m not going to weigh in mail().  Enough has been said about it.  Just remember to take your code and [...]]]></description>
			<content:encoded><![CDATA[<p>I regularly shut down web sites that use the PHP mail() function.  While the users of the sites mean well, they generally don&#8217;t do any checking before sending data to mail().  I&#8217;m not going to weigh in mail().  Enough has been said about it.  Just remember to take your code and code security seriously.</p>
<p>Remember, never trust data submitted by site visitors.  Sanitize the heck out of it.</p>
<p>Jelly and Custard has an excellent explanation of PHP Header Injection when using the PHP mail() function.</p>
<p><a href="http://www.jellyandcustard.com/2006/02/24/email-header-injection-in-php/" target="_blank">http://www.jellyandcustard.com/2006/02/24/email-header-injection-in-php/</a></p>
<p><a href="http://www.jellyandcustard.com" target="_blank">http://www.jellyandcustard.com</a> is an excellent PHP blog.</p>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=7&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2007/05/21/php-header-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Panic Releases Coda, and I can&#8217;t use it</title>
		<link>http://www.popmartian.com/tipsntricks/2007/05/17/panic-releases-coda-and-i-cant-use-it/</link>
		<comments>http://www.popmartian.com/tipsntricks/2007/05/17/panic-releases-coda-and-i-cant-use-it/#comments</comments>
		<pubDate>Thu, 17 May 2007 16:54:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.popmartian.com/tipsntricks/2007/05/17/panic-releases-coda-and-i-cant-use-it/</guid>
		<description><![CDATA[http://www.panic.com/ released Coda a web-oriented IDE that contains a terminal, FTP, SSH, etc. all rolled in to one.  It looks great and I want it, but it&#8217;s Mac only.  Some day&#8230;
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.panic.com/">http://www.panic.com/</a> released Coda a web-oriented IDE that contains a terminal, FTP, SSH, etc. all rolled in to one.  It looks great and I want it, but it&#8217;s Mac only.  Some day&#8230;</p>
<img src="http://www.popmartian.com/tipsntricks/?ak_action=api_record_view&id=5&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.popmartian.com/tipsntricks/2007/05/17/panic-releases-coda-and-i-cant-use-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
