<?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>Joseph Piché &#187; code</title>
	<atom:link href="http://jpiche.com/tags/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://jpiche.com</link>
	<description>Web development professional with expertise in PHP, MySQL query optimization, Ajax, and XHTML</description>
	<lastBuildDate>Tue, 20 Jul 2010 04:04:51 +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>Getting Paid to Write AI</title>
		<link>http://jpiche.com/2010/06/getting-paid-to-write-ai/</link>
		<comments>http://jpiche.com/2010/06/getting-paid-to-write-ai/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 01:01:17 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://jpiche.com/?p=453</guid>
		<description><![CDATA[One of the best parts of my previous job&#8212;and also the part that kept me going for so long&#8212;is that I had the chance to work on a variety of projects, in many cases for completely different business ventures. One week I had been privileged with the task of writing a small program which ended [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best parts of my previous job&mdash;and also the part that kept me going for so long&mdash;is that I had the chance to work on a variety of projects, in many cases for completely different business ventures. One week I had been privileged with the task of writing a small program which ended up being semi-intelligent (of course artificially, thus AI). As it so happens I also seemed to have stretched PHP to its limits.</p>
<p>When originally typing up this post, I kept the details to a minimum, but now that I&#8217;ve moved on I can freely discuss it. This program&mdash;code-named &ldquo;twitterbot&rdquo;&mdash;was tasked with searching Twitter for tweets with certain keywords within a radius of a location, like for tweets containing &#8220;hungry&#8221; within 30 miles of Minneapolis, and <a href="http://help.twitter.com/entries/13920-frequently-asked-questions#replies">@reply</a> to that person within an hour of their tweet about &#8230; a website I probably shouldn&#8217;t name. However this becomes tricky since Twitter is really good at detecting spam, and a lot of Twitter users really hate spam (like me). To get around it, I made a bunch of twitter accounts using anonymous email addresses, created bios, set profile pictures, and set color schemes, all to make them look like real people.</p>
<p>However, just because a Twitter account has a profile picture, it does not mean it will be treated like a human: the account has to have realistic-looking posts. No problem. First I set a limit to the number of posts an account can make per day, make sure all the posts are within normal waking hours (like 6am to 10pm), have 30-50% of the tweets be the spamming tweets, and the rest be copies of tweets from a different search that none of the accounts will be replying to. Then since the spam tweets themselves are also randomized, the sum of it all equals twitter accounts that even people are sometimes not able to recognize that the account is a bot.
<p>For the technical, I wrote this program in PHP both because we had thousands and thousands of lines of legacy code in other programs that we didn&#8217;t want to touch, and second because it is extremely simple and quick to code and deploy. With a semi-AI bot though, the scene changes and suddenly both opportunities and concerns that weren&#8217;t there before suddenly are. Example opportunity: <a href="http://www.php.net/manual/en/function.pcntl-fork.php">pcntl-fork</a> becomes available. Example concern: the PHP program will probably be running as a daemon on a server, use up all your RAM and explode.</p>
<p>In the end, the bot ran strong for about 2 weeks before management changed their minds and had it shut down&mdash;spamming people does not make for good press. I felt terrible having to write such a program; I really don&#8217;t like spam, let alone being the one doing the spamming. But since then I&#8217;ve moved on to a position at a <a href="http://http://www.irishtitan.com/" title="Irish Titan">different company</a> and write ethical code now.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2010/06/getting-paid-to-write-ai/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>while, for, and foreach</title>
		<link>http://jpiche.com/2009/05/while-for-and-foreach/</link>
		<comments>http://jpiche.com/2009/05/while-for-and-foreach/#comments</comments>
		<pubDate>Tue, 05 May 2009 02:37:40 +0000</pubDate>
		<dc:creator>Joseph Piché</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[languages]]></category>

		<guid isPermaLink="false">http://blog.jpiche.com/?p=9</guid>
		<description><![CDATA[As a PHP programmer, I actually write code in many different languages. Many times in a single file I will have (X)HTML, CSS, Javascript, PHP, and SQL. Most of the time, I can keep this straight. Semi-often I forget to put a semi-colon at the end of a line (like when I do a bunch [...]]]></description>
			<content:encoded><![CDATA[<p>As a <acronym title="recursive acronym for PHP: Hypertext Preprocessor">PHP</acronym> programmer, I actually write code in many different languages. Many times in a single file I will have (X)HTML, CSS, Javascript, PHP, and SQL. Most of the time, I can keep this straight. Semi-often I forget to put a semi-colon at the end of a line (like when I do a bunch of <a href="http://python.org/">Python</a> programming the night before). But there are certain instances where I get tripped up all the time: <code>while</code>, <code>for</code>, and <code>foreach</code>.</p>
<p>Those three little words are very powerful, and are fundamental constructs of programming languages. I don&#8217;t know what I would do if I couldn&#8217;t iterate over an array. I also don&#8217;t know what to do with myself when I forget how each is used in the current language I&#8217;m writting in.</p>
<p>For example: If I&#8217;m writting in PHP, it&#8217;s <code>foreach ($array as $val =&gt; $key)</code>, in Python it&#8217;s <code>for $i in range(10):</code>, in Perl <code>for</code> and <code>foreach</code> are actually the same thing and can be used interchangably (I did a bunch of Perl stuff while at my last job), and I&#8217;m pretty sure JavaScript doesn&#8217;t have an object iterator construct&mdash;probably because JavaScript implements objects in the most terrible way.</p>
<p>What about <code>while</code>s? They are just strange. I never know when I can use <code>do</code> or when the truth statement is processed. Plus, sometimes the thought of an infinite loop scares me a little. Of course in Perl 6, you can form a lazy infinite loop out of a <code>for</code> statement.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpiche.com/2009/05/while-for-and-foreach/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
