<?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>Levi Jackson</title>
	<atom:link href="http://www.levijackson.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.levijackson.net</link>
	<description></description>
	<lastBuildDate>Wed, 11 Mar 2020 19:47:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.6</generator>
	<item>
		<title>Installing AWS CLI on Mac</title>
		<link>http://www.levijackson.net/installing-aws-cli-on-mac/</link>
					<comments>http://www.levijackson.net/installing-aws-cli-on-mac/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Wed, 11 Mar 2020 19:47:46 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=909</guid>

					<description><![CDATA[<p>The AWS guide is still a good starting point for this. The main piece I had trouble with was using `aws &#8211;version` once it was installed. Prerequisite: have Python3 and Pip3 installed Quick answer: adjust $PATH so it has the path to the AWS executable. 1) Find where it installed AWS.  The guide says to &#8230; <a href="http://www.levijackson.net/installing-aws-cli-on-mac/" class="more-link">Continue reading <span class="screen-reader-text">Installing AWS CLI on Mac</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/installing-aws-cli-on-mac/" target="_blank">Installing AWS CLI on Mac</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html" target="_blank" rel="noopener noreferrer">AWS guide</a> is still a good starting point for this. The main piece I had trouble with was using `aws &#8211;version` once it was installed.</p>
<p><strong>Prerequisite: have Python3 and Pip3 installed</strong></p>
<h3>Quick answer: adjust <em>$PATH</em> so it has the path to the AWS executable.</h3>
<p>1) Find where it installed AWS.  The guide says to use <code>which python3</code> &#8211; but when I installed Python it installed it to my user, not the system. When you ran `pip3 install awscli &#8211;updgrade &#8211;user` it should have spit out something like this `&#8230; awscli in ./Library/Python/3.8/lib/python/site-packages (1.18.18)`.  The <strong>&#8220;./&#8221;</strong> indicated it is a local path, NOT the system path. You can confirm by checking `ls -la /Users/<strong>&lt;insert_user_name&gt;</strong>/Library/Python/3.8/bin/aws`</p>
<p>2) Edit  <em>~./bash_profile </em>and add the path</p>
<pre><em>export PATH=/Users/<strong>&lt;insert_user_name&gt;</strong>/Library/Python/3.8/bin:$PATH</em></pre>
<p>3) Reload the profile</p>
<pre><em>source .bash_profile</em></pre>
<p>4) Test &#8211; <em>aws &#8211;version</em> should output</p>
<pre><em>aws-cli/1.18.18 Python/3.8.2 Darwin/17.7.0 botocore/1.15.18</em></pre>
<p>&nbsp;</p>
<p>&nbsp;</p><p>The post <a href="http://www.levijackson.net/installing-aws-cli-on-mac/" target="_blank">Installing AWS CLI on Mac</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/installing-aws-cli-on-mac/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using a private repo with composer and bitbucket</title>
		<link>http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/</link>
					<comments>http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Sat, 01 Dec 2018 13:00:30 +0000</pubDate>
				<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=888</guid>

					<description><![CDATA[<p>Setting up composer to use a private repo is pretty easy&#8230; after you&#8217;ve done it once. There are a few things that can trip you up, such as the naming of the package and the version to include. The docs for getting the configuration set up got me about 95% of the way there. This guide &#8230; <a href="http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/" class="more-link">Continue reading <span class="screen-reader-text">Using a private repo with composer and bitbucket</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/" target="_blank">Using a private repo with composer and bitbucket</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Setting up composer to use a private repo is pretty easy&#8230; after you&#8217;ve done it once. There are a few things that can trip you up, such as the naming of the package and the version to include. The <a href="https://getcomposer.org/doc/05-repositories.md#using-private-repositories" target="_blank">docs</a> for getting the configuration set up got me about 95% of the way there.</p>
<p>This guide assumes you already have a <em>composer.json</em> file created, and you&#8217;re looking to add a new private repository to that.</p>
<h2>Part 1: Bitbucket configuration</h2>
<p>Composer is going to need access to your Bitbucket account in order to fetch the private git repo. An OAuth consumer can be used to give composer access.<br />
&#8211; In Bitbucket, go to your &#8220;Bitbucket Settings&#8221; page https://bitbucket.org/account/user/&lt;username&gt;/</p>
<p>&#8211; Click &#8220;OAuth&#8221;<br />
<a href="http://www.levijackson.net/wp-content/uploads/2018/11/oauth_link.png" target="_blank"><img loading="lazy" class="alignnone size-full wp-image-893" src="http://www.levijackson.net/wp-content/uploads/2018/11/oauth_link.png" alt="oauth_link" width="558" height="543" srcset="http://www.levijackson.net/wp-content/uploads/2018/11/oauth_link.png 558w, http://www.levijackson.net/wp-content/uploads/2018/11/oauth_link-300x292.png 300w" sizes="(max-width: 558px) 100vw, 558px" /></a></p>
<p>&#8211; Click the &#8220;Add consumer&#8221; button<br />
<a href="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_button.png" target="_blank"><img loading="lazy" class="alignnone size-full wp-image-894" src="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_button.png" alt="consumer_button" width="1506" height="575" srcset="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_button.png 1506w, http://www.levijackson.net/wp-content/uploads/2018/11/consumer_button-300x115.png 300w, http://www.levijackson.net/wp-content/uploads/2018/11/consumer_button-1024x391.png 1024w" sizes="(max-width: 1506px) 100vw, 1506px" /></a></p>
<p>&#8211; Fill in the name, description, callback URL (this can be anything &#8211; composer won&#8217;t use it but it is required by Bitbucket), select <i>This is a private consumer</i>, and select <i>Repositories: Read</i> for the permissions.<br />
<a href="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt1.png" target="_blank"><img loading="lazy" class="alignnone size-full wp-image-895" src="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt1.png" alt="consumer_config_pt1" width="663" height="688" srcset="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt1.png 663w, http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt1-289x300.png 289w" sizes="(max-width: 663px) 100vw, 663px" /></a></p>
<p><a href="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt2.png" target="_blank"><img loading="lazy" class="alignnone size-full wp-image-896" src="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt2.png" alt="consumer_config_pt2" width="612" height="442" srcset="http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt2.png 612w, http://www.levijackson.net/wp-content/uploads/2018/11/consumer_config_pt2-300x217.png 300w" sizes="(max-width: 612px) 100vw, 612px" /></a></p>
<p>&nbsp;</p>
<h2>Part 2: Composer configuration</h2>
<p>Using the <em>Key </em>and<em> Secret </em>from the OAuth consumer you created in part 1, you will need to add an <em>auth.json</em> file in composer&#8217;s home directory.</p>
<pre> vi ~/.composer/auth.json</pre>
<pre class="brush: jscript; title: ; notranslate">
{
    &quot;bitbucket-oauth&quot;: {
        &quot;bitbucket.org&quot;: {
            &quot;consumer-key&quot;: &quot;myKey&quot;,
            &quot;consumer-secret&quot;: &quot;mySecret&quot;
        }
    }
}
</pre>
<p>&nbsp;</p>
<h2>Part 3: Configure composer.json</h2>
<p>1) Add your private repository to the configuration so composer can look there for packages. The URL for the repo can be found in Bitbucket by clicking the &#8220;Clone&#8221; button in the top right of the repository view.</p>
<p><a href="http://www.levijackson.net/wp-content/uploads/2018/11/package_url.png" target="_blank"><img loading="lazy" class="alignnone size-full wp-image-899" src="http://www.levijackson.net/wp-content/uploads/2018/11/package_url.png" alt="package_url" width="1483" height="201" srcset="http://www.levijackson.net/wp-content/uploads/2018/11/package_url.png 1483w, http://www.levijackson.net/wp-content/uploads/2018/11/package_url-300x41.png 300w, http://www.levijackson.net/wp-content/uploads/2018/11/package_url-1024x139.png 1024w" sizes="(max-width: 1483px) 100vw, 1483px" /></a></p>
<pre class="brush: jscript; title: ; notranslate">
&quot;repositories&quot;: [
  {
    &quot;type&quot;: &quot;git&quot;,
    &quot;url&quot;: &quot;https://aerosox@bitbucket.org/aerosox/dataconverter.git&quot;
  }
]
</pre>
<p>2) Require the package in <em>composer.json. </em>With either of these methods.<br />
<em>&#8211;</em> CLI:<em> composer require aerosox/dataconverter<br />
&#8211; </em>Edit<em> composer.json</em></p>
<pre class="brush: jscript; title: ; notranslate">
&quot;require&quot;: {
    &quot;aerosox/dataconverter&quot;: &quot;master@dev&quot;
  }
</pre>
<p>&nbsp;</p>
<h2>Troubleshooting</h2>
<p>1)<b> </b> Ensure the package name in the <em>require</em> matches the name from the <em>composer.json</em> configuration for the package you are including.</p>
<pre class="brush: jscript; title: ; notranslate">
// composer.json from aerosox/dataconvert

{
    // even though the git repo is configured as aerosox/dataconverter.git, this name *could* be anything. This is what composer is going to be looking for when it searches for the package to install.
    &quot;name&quot;: &quot;aerosox/dataconverter&quot;,
    &quot;description&quot;: &quot;Convert data formats&quot;,
    &quot;type&quot;: &quot;library&quot;,
    &quot;authors&quot;: [
        {
            &quot;name&quot;: &quot;Levi Jackson&quot;,
            &quot;email&quot;: &quot;aerosox@gmail.com&quot;
        }
    ],
    &quot;autoload&quot;: {
        &quot;psr-4&quot;: {
            &quot;DataConverter\\&quot;: &quot;src/&quot;
        }
    },
    &quot;require-dev&quot;: {
        &quot;phpunit/phpunit&quot;: &quot;^6.5&quot;
    }
}
</pre>
<p>2) I saw a lot of guides say to load the package as <em>&#8220;aerosox/dataconverter&#8221;: &#8220;master-dev&#8221;</em>. I initially thought that <em>master-dev</em> was a composer standard, but it&#8217;s not. If you want to use that, you&#8217;d want to set up an alias in the package so it can be found.</p>
<pre class="brush: jscript; title: ; notranslate">
&quot;extra&quot;: {
  &quot;branch-alias&quot;: {
    &quot;dev-master&quot;: &quot;actual-branch-name&quot;
  }
}
</pre><p>The post <a href="http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/" target="_blank">Using a private repo with composer and bitbucket</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/using-a-private-repo-with-composer-and-bitbucket/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Are array_* functions faster than loops?</title>
		<link>http://www.levijackson.net/are-array_-functions-faster-than-loops/</link>
					<comments>http://www.levijackson.net/are-array_-functions-faster-than-loops/#comments</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Mon, 20 Apr 2015 23:30:51 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=825</guid>

					<description><![CDATA[<p>I was discussing the speed of filtering an array with a colleague and I had been under the assumption that using PHP array_* functions are considerably faster than using a loop (foreach, for, while) . I could not find evidence of that when I was doing some Google searches though so I decided to do a &#8230; <a href="http://www.levijackson.net/are-array_-functions-faster-than-loops/" class="more-link">Continue reading <span class="screen-reader-text">Are array_* functions faster than loops?</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/are-array_-functions-faster-than-loops/" target="_blank">Are array_* functions faster than loops?</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I was discussing the speed of filtering an array with a colleague and I had been under the assumption that using PHP <em>array_*</em> functions are considerably faster than using a loop (foreach, for, while) . I could not find evidence of that when I was doing some Google searches though so I decided to do a little bit of a speed test on my own.</p>
<p>For all of these tests I set up the following beforehand:</p>
<pre class="brush: php; title: ; notranslate">
ini_set('memory_limit', '500M');
$data = range(0, 1000000);
</pre>
<h3>Test 1: array_filter vs loops</h3>
<table>
<tbody>
<tr>
<td>Type</td>
<td>Time</td>
</tr>
<tr>
<td>foreach</td>
<td>0.37</td>
</tr>
<tr>
<td>while</td>
<td>0.58</td>
</tr>
<tr>
<td>for</td>
<td>0.61</td>
</tr>
<tr>
<td>array_filter</td>
<td>0.74</td>
</tr>
</tbody>
</table>
<pre class="brush: php; title: ; notranslate">
// array_filter loop average 0.74 seconds
$start = microtime(true);
$data = array_filter($data, function ($item) {
    return $item%2;
});
$end = microtime(true);

echo $end - $start;

// Foreach loop average 0.37 seconds
$start = microtime(true);
$newData = array();
foreach ($data as $item) {
    if ($item%2) {
        $newData[] = $item;
    }
}
$end = microtime(true);

echo $end - $start;

// For loop average 0.61 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
for($i=0;$i&lt;=$numItems;$i++) {
    if ($data[$i]%2) {
        $newData[] = $data[$i];
    }
}
$end = microtime(true);

echo $end - $start;

// While loop average 0.58 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
$i = 0;
while ($i &lt;= $numItems) {
    if ($data[$i]%2) {
        $newData[] = $data[$i];
    }
    $i++;
}
$end = microtime(true);

echo $end - $start;
</pre>
<h3>Test 2: array_map vs loops</h3>
<table>
<tbody>
<tr>
<td>Type</td>
<td>Time</td>
</tr>
<tr>
<td>foreach</td>
<td>0.65</td>
</tr>
<tr>
<td>while</td>
<td>0.69</td>
</tr>
<tr>
<td>for</td>
<td>0.76</td>
</tr>
<tr>
<td>array_map</td>
<td>1.38</td>
</tr>
</tbody>
</table>
<pre class="brush: php; title: ; notranslate">
// array_map average 1.38 seconds
$start = microtime(true);
$data = array_map(function ($item) {
    return $item+1;
}, $data);
$end = microtime(true);

echo $end - $start;

// For loop average 0.65 seconds
$start = microtime(true);
$newData = array();
foreach ($data as $item) {
    $newData[] = $item+1;
}
$end = microtime(true);

echo $end - $start;

// For loop average 0.76 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
for($i=0;$i&lt;=$numItems;$i++) {
    $newData[] = $data[$i]+1;
}
$end = microtime(true);

echo $end - $start;

// While loop average 0.69 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
$i = 0;
while ($i &lt;= $numItems) {
    $newData[] = $data[$i];
    $i++;
}
$end = microtime(true);

echo $end - $start;
</pre>
<h3>Test 3: array_walk vs loops</h3>
<table>
<tbody>
<tr>
<td>Type</td>
<td>Time</td>
</tr>
<tr>
<td>foreach</td>
<td>0.65</td>
</tr>
<tr>
<td>while</td>
<td>0.69</td>
</tr>
<tr>
<td>array_filter</td>
<td>0.72</td>
</tr>
<tr>
<td>for</td>
<td>0.76</td>
</tr>
</tbody>
</table>
<pre class="brush: php; title: ; notranslate">
// array_walk average 0.72 seconds
$start = microtime(true);
$data = array_walk($data, function ($item) {
    return $item+1;
});
$end = microtime(true);

echo $end - $start;

// Foreach loop average 0.65 seconds
$start = microtime(true);
$newData = array();
foreach ($data as $item) {
    $newData[] = $item+1;
}
$end = microtime(true);

echo $end - $start;

// For loop average 0.76 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
for($i=0;$i&lt;=$numItems;$i++) {
    $newData[] = $data[$i]+1;
}
$end = microtime(true);

echo $end - $start;

// While loop average 0.69 seconds
$start = microtime(true);
$newData = array();
$numItems = count($data);
$i = 0;
while ($i &lt;= $numItems) {
    $newData[] = $data[$i];
    $i++;
}
$end = microtime(true);

echo $end - $start;
</pre>
<h3>End Notes</h3>
<p>I was incorrect when I thought that <em>array_*</em> functions are faster! Albeit the speed difference is pretty negligible when talking about using it once or twice during page execution. I won&#8217;t stop using the <em>array_*</em> functions because of my findings, they still offer a cleaner way of writing the code. I will only second guess using them when I am writing code that has the potential to be processed thousands of times.</p>
<p><em>I tested these with a pretty basic data set. Speed may vary depending on the type of data being used as well as the version of PHP (I used 5.5.4).</em></p><p>The post <a href="http://www.levijackson.net/are-array_-functions-faster-than-loops/" target="_blank">Are array_* functions faster than loops?</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/are-array_-functions-faster-than-loops/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>GruntJS &#8220;Warning: Uglification failed.&#8221;</title>
		<link>http://www.levijackson.net/gruntjs-warning-uglification-failed/</link>
					<comments>http://www.levijackson.net/gruntjs-warning-uglification-failed/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Tue, 07 Apr 2015 00:57:38 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=844</guid>

					<description><![CDATA[<p>I was working with Grunt the other day attempting to update some legacy code to use uglify and I kept getting errors such as: When I went to line 12 I saw absolutely nothing wrong. It was a comment block like the following: I tried removing the file from the list being included and it happened &#8230; <a href="http://www.levijackson.net/gruntjs-warning-uglification-failed/" class="more-link">Continue reading <span class="screen-reader-text">GruntJS &#8220;Warning: Uglification failed.&#8221;</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/gruntjs-warning-uglification-failed/" target="_blank">GruntJS "Warning: Uglification failed."</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I was working with <a href="http://gruntjs.com/">Grunt</a> the other day attempting to update some legacy code to use <a href="https://github.com/gruntjs/grunt-contrib-uglify" target="_blank">uglify</a> and I kept getting errors such as:</p>
<pre class="brush: php; title: ; notranslate">&gt;&gt; Uglifying source path/to/file.js failed.
Warning: Uglification failed.
Unexpected token punc «(», expected punc «:».
Line 12 in path/to/file.js
 Use --force to continue.

Aborted due to warnings.
</pre>
<p>When I went to line 12 I saw absolutely nothing wrong. It was a comment block like the following:</p>
<pre class="brush: php; title: ; notranslate">
/*
An unobtrusive comment goes here
*/
</pre>
<p>I tried removing the file from the list being included and it happened again. Same error different file. Everything I was reading said it was most likely invalid Javascript doing it, but since I write code perfectly, that could not be the case. Fast forward 10-20 minutes and I found this<a href="https://github.com/mishoo/UglifyJS2/issues/521" target="_blank"> issue on Github</a> that sounded similar. A comment from <a href="https://github.com/ericrange" target="_blank">Eric Range</a> advised that their code editor had added a line ending of &#8220;\n\r&#8221; to the file and that caused their build to fail. So I took a look at line endings and sure enough, a handful of the files were using &#8220;\n\r&#8221;. I did a find/replace and changed them all to just a single new line (&#8220;\n&#8221;). I attempted to uglify it once more and yet again I was shown an error! I was beginning to think uglify and I were not going to be good friends.</p>
<pre class="brush: php; title: ; notranslate">
Running &quot;uglify:build&quot; (uglify) task
{ message: 'Unexpected token: eof (undefined)',
  filename: 'file.js',
  line: 3032,
  col: 0,
  pos: 129381,
  stack: 'Error\n    at new JS_Parse_Error (/path/to/node/node_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:196:18)\n    at js_error (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:204:11)\n    at croak (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:678:41)\n    at token_error (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:682:9)\n    at unexpected (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:688:9)\n    at block_ (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1000:28)\n    at /path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:974:25\n    at function_ (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:979:15)\n    at expr_atom (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1187:24)\n    at maybe_unary (/path/to/nodenode_modules/grunt-contrib-uglify/node_modules/uglify-js/lib/parse.js:1357:19)' }
&gt;&gt; Uglifying source path/to/file.js failed.
Warning: Uglification failed.
Unexpected token: eof (undefined).
Line 3032 in path/to/file.js
 Use --force to continue.

Aborted due to warnings.
</pre>
<p>I looked at the differences between the files that worked and the ones that failed. The only difference I found was that the failed files used tabs instead of spaces (they were created at a time when there was no convention for tabs vs spaces). So I converted the files that were using tabs to spaces and tried again. Bingo! It worked perfect.</p>
<h3>Final Solution</h3>
<p>My final solution was to change all files to use unix line endings (&#8220;\n&#8221;) and to convert tabs to spaces.</p><p>The post <a href="http://www.levijackson.net/gruntjs-warning-uglification-failed/" target="_blank">GruntJS "Warning: Uglification failed."</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/gruntjs-warning-uglification-failed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>RequireJS &#8220;jQuery not defined&#8221;</title>
		<link>http://www.levijackson.net/requirejs-jquery-not-defined/</link>
					<comments>http://www.levijackson.net/requirejs-jquery-not-defined/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Sat, 10 Jan 2015 20:44:24 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=818</guid>

					<description><![CDATA[<p>This is a super quick and simple post&#8230; but maybe it&#8217;ll save someone time down the line. I sure won&#8217;t make the mistake again. I spent more time than I would like to admit figuring out this issue. There are a lot of posts sprinkled around about different causes of the error, none of which were the &#8230; <a href="http://www.levijackson.net/requirejs-jquery-not-defined/" class="more-link">Continue reading <span class="screen-reader-text">RequireJS &#8220;jQuery not defined&#8221;</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/requirejs-jquery-not-defined/" target="_blank">RequireJS "jQuery not defined"</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>This is a super quick and simple post&#8230; but maybe it&#8217;ll save someone time down the line. I sure won&#8217;t make the mistake again. I spent more time than I would like to admit figuring out this issue. There are a lot of posts sprinkled around about different causes of the error, none of which were the cause of my error.</p>
<p>Given the following RequireJS config:</p>
<pre class="brush: php; title: ; notranslate">
require.config({
    &quot;baseUrl&quot;:&quot;\/path\/to\/dir\/&quot;,
    &quot;paths&quot;:{
        &quot;jQuery&quot;:&quot;jquery.js&quot;
    }
});
</pre>
<p>I was trying to do the following:</p>
<pre class="brush: php; title: ; notranslate">
require([jQuery], function ($) {
    console.log($);
});
</pre>
<p>That gave me the dreaded &#8220;jQuery not defined&#8221; error!</p>
<h3>Solution</h3>
<p>Add quotes around &#8220;jQuery&#8221;!</p>
<pre class="brush: php; title: ; notranslate">
require([&quot;jQuery&quot;], function ($) {
    console.log($);
});
</pre>
<p>Without the quotes jQuery was being treated as a Javascript variable instead of a string. So when it was looking for the jQuery dependency it did not exist. &#8220;jQuery&#8221; on the other hand does.</p><p>The post <a href="http://www.levijackson.net/requirejs-jquery-not-defined/" target="_blank">RequireJS "jQuery not defined"</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/requirejs-jquery-not-defined/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Working with iterators and arrays SPL</title>
		<link>http://www.levijackson.net/working-with-iterators-and-arrays-spl/</link>
					<comments>http://www.levijackson.net/working-with-iterators-and-arrays-spl/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Fri, 26 Dec 2014 16:21:04 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=801</guid>

					<description><![CDATA[<p>Iterators are the next thing from the SPL I am going to take a look at. For those that are not familiar with iterators yet, an iterator is like a list or a collection of items that you can move through (traverse). If that sounds familiar to you, it should. They share a lot of features &#8230; <a href="http://www.levijackson.net/working-with-iterators-and-arrays-spl/" class="more-link">Continue reading <span class="screen-reader-text">Working with iterators and arrays SPL</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/working-with-iterators-and-arrays-spl/" target="_blank">Working with iterators and arrays SPL</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Iterators are the next thing from the SPL I am going to take a look at. For those that are not familiar with iterators yet, an iterator is like a list or a collection of items that you can move through (traverse). If that sounds familiar to you, it should. They share a lot of features and functionality that an array has in PHP. The biggest differences are that they are often more efficient with memory, faster to process, and object oriented.</p>
<h2> Iterators</h2>
<p>There are a <em>lot</em> of <a href="http://php.net/manual/en/spl.iterators.php" target="_blank">iterators</a> in PHP. Not all of them are part of the SPL though, such as <a href="http://php.net/manual/en/class.simplexmliterator.php" target="_blank">SimpleXMLIterator</a>, so keep that in mind as you may come across an iterator in places you may not expect. It can be pretty intimidating looking at the list, and it only gets worse when you see something called a <em>RecursiveIteratorIterator</em>.</p>
<h3>ArrayIterator</h3>
<p><a href="http://php.net/manual/en/class.arrayiterator.php" target="_blank">ArrayIterator</a> is probably going to be the best spot to start out. ArrayIterator bridges the gap between Array and Iterator and allows for conversion back and forth. In it&#8217;s most basic implementation it accepts an array as the parameter and it converts it into an iterator.</p>
<pre class="brush: php; title: ; notranslate">
$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);

/*
You can alternatively use these methods to add items to an ArrayIterator
$cities = new ArrayIterator();
$cities-&gt;append('Torrington');
$cities[] = 'Burlington';
$cities[] = 'New York City';
$cities-&gt;append('Warwick');
*/
</pre>
<p>The first thing you will realize is that the ArrayIterator has methods for some of the more common array functions such as <em>asort, ksort, natsort, key, etc..</em> The second thing you will realize is that iterators do not have a 1:1 conversion in terms of array functions to iterator methods. So it may not be a suitable replacement for all instances where an array is currently used.</p>
<h2>Chain Iterators Together</h2>
<p>One great thing about iterators is the ability to chain them together. It opens up some pretty powerful capabilities such as filtering, merging items, and limiting output.  Some of it like limiting results, is exclusive to iterators, but other things like filtering can also be done using the <em>array_</em> functions.</p>
<pre class="brush: php; title: ; notranslate">
$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);
$cities = new LimitIterator($cities, 0, 2);
foreach ($cities as $city) {
    echo $city;
}
// returns Torrington, Burlington
</pre>
<h2>FilterIterator</h2>
<p>FilterIterator is an abstract class that you can use to create custom filters to apply to the data in an iterator.</p>
<pre class="brush: php; title: ; notranslate">
class CityFilter extends FilterIterator {
    protected $City;

    public function __construct(Iterator $iterator, $city) {
        parent::__construct($iterator);
        $this-&gt;City = $city;
    }

    public function accept() {
        return $this-&gt;current() == $this-&gt;City;
    }
}

$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);
$cities = new CityFilter($cities, 'Burlington');

foreach ($cities as $city) {
    echo $city;
}
// returns Burlington
</pre>
<h2>Merging Iterators</h2>
<p>I mentioned earlier that you can merge iterators together. You do that with <a href="http://php.net/manual/en/class.appenditerator.php" target="_blank">AppendIterator</a>.</p>
<pre class="brush: php; title: ; notranslate">
$cities1 = array('Torrington', 'Burlington');
$cities1 = new ArrayIterator($cities1);

$cities2 = array('New York City', 'Warwick');
$cities2 = new ArrayIterator($cities2);

$cities = new AppendIterator();
$cities-&gt;append($cities1);
$cities-&gt;append($cities2);

foreach ($cities as $city) {
    echo $city;
}
// returns Torrington, Burlington, New York City, Warwick
</pre>
<h2>Converting an Iterator to an Array</h2>
<p>So I showed you how to go from an array to an iterator. But what if you want to take your iterator and go back to an array if you need to use a function that is not available as a method? You have two options.</p>
<h4>Option 1: <a href="http://php.net/manual/en/arrayiterator.getarraycopy.php" target="_blank">ArrayIterator::getArrayCopy()</a></h4>
<pre class="brush: php; title: ; notranslate">
$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);
$cities = $cities-&gt;getArrayCopy();
</pre>
<h4>Option 2:<a href="http://php.net/manual/en/function.iterator-to-array.php" target="_blank"> iterator_to_array() function</a></h4>
<pre class="brush: php; title: ; notranslate">
$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);
$cities = iterator_to_array($cities);
</pre>
<p>One difference between the two options is that <em>ArrayIterator::getArrayCopy()</em> will not execute chained iterators while <em>iterator_to_array() </em>will.</p>
<pre class="brush: php; title: ; notranslate">
$cities = array('Torrington', 'Burlington', 'New York City', 'Warwick');
$cities = new ArrayIterator($cities);
$cities = new LimitIterator($cities, 0, 2);

$cities1 = iterator_to_array($cities);
print_r($cities1);
// returns Array ( [0] =&gt; Torrington [1] =&gt; Burlington )

$cities2 = $cities-&gt;getArrayCopy();
print_r($cities2);
// returns Array ( [0] =&gt; Torrington [1] =&gt; Burlington [2] =&gt; New York City [3] =&gt; Warwick )
</pre>
<h2> Closing</h2>
<p>There are a lot more iterators I didn&#8217;t go over for you to explore, like the <a href="http://php.net/manual/en/class.emptyiterator.php" target="_blank">EmptyIterator</a> in all its glory! I&#8217;m noticing one of the biggest advantages over <em>array_</em> functions is the ease of reading the code. I can&#8217;t tell you how many times i&#8217;ve had to look at something that uses <em>array_walk</em> and <em>array_map</em> in the same variable and had to spend a few minutes working my way through what it does.</p>
<pre class="brush: php; title: ; notranslate">
$something = array_walk(array_map(function(){
// some logic
}, $data) ,function() {
// some logic
});
</pre>
<p>An alternative to that might be to do:</p>
<pre class="brush: php; title: ; notranslate">
$something = ArrayIterator($data);
$something = CallbackFilterIterator($something, function($current, $key, $iterator) {
// some logic
});
</pre><p>The post <a href="http://www.levijackson.net/working-with-iterators-and-arrays-spl/" target="_blank">Working with iterators and arrays SPL</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/working-with-iterators-and-arrays-spl/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Working with files and SPL</title>
		<link>http://www.levijackson.net/working-with-files-and-spl/</link>
					<comments>http://www.levijackson.net/working-with-files-and-spl/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Thu, 30 Oct 2014 02:03:52 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=788</guid>

					<description><![CDATA[<p>The Standard PHP Library (SPL) has been around for a while now. Most of it was introduced in PHP 5.3 back in 2009,  but some of it has been around since PHP 5.0 released way back in 2004. The only experience I had with the SPL prior to writing this post was using a few of the &#8230; <a href="http://www.levijackson.net/working-with-files-and-spl/" class="more-link">Continue reading <span class="screen-reader-text">Working with files and SPL</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/working-with-files-and-spl/" target="_blank">Working with files and SPL</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The <a href="http://php.net/manual/en/book.spl.php" target="_blank">Standard PHP Library</a> (SPL) has been around for a while now. Most of it was introduced in PHP 5.3 back in 2009,  but some of it has been around since PHP 5.0 released way back in 2004. The only experience I had with the SPL prior to writing this post was using a few of the objects based on recommendations from Stackoverflow answers. So I never really delved into the complete library to see what is has to offer. The biggest hurdle I found with learning more about the SPL is that the classes are not that well documented. The best documentation is from the comments in most cases!</p>
<p>I&#8217;m sure most of us have had to work with files in some manner. For me it usually takes the form of a logger or parser (CSV or XML). One of the things I have always thought would be helpful is an object to wrap the <em>fopen, fwrite, fread, fclose</em> functions so you didn&#8217;t need to maintain the file handle. Enter the SPL. It wraps a lot of the reading, writing, searching, and parsing into easy to use objects so that you don&#8217;t need to preserve that file handle in a variable.</p>
<h2>SplFileInfo</h2>
<p><a href="http://php.net/manual/en/class.splfileinfo.php" target="_blank">SplFileInfo</a> offers a way to get information about a file (as the name would suggest). Because it handles some of the more basic aspects of working with files, it won&#8217;t come as a shock that a lot of the other file related SPL objects extend SplFileInfo. Need to get the extension? Use <em>SplFileInfo::getExtension()</em>. How about the last modified time? <em>SplFileInfo::getMTime()</em>. Is the file a symbolic link to a different file? <em>SplFileInfoisLink()</em> to check and <em>SplFileInfogetRealPath()</em> to resolve to the actual location. The only thing it doesn&#8217;t do is handle reading and writing, but that is where <em>SplFileInfo::openFile()</em> comes into the picture. The openFile method will return an instance of SplFileObject that can be used to do reading/writing.</p>
<h2>SplFileObject</h2>
<p><a href="http://php.net/manual/en/class.splfileobject.php" target="_blank">SplFileObject</a> inherits from SplFileInfo, so it has all of the same capabilities plus being able to read and write.</p>
<h3>CSV Parsing</h3>
<p>If you need to parse a CSV you can use the <em>setFlags() </em>method before parsing a file to set flags that will change how it handles parsing. <em>SplFileObject::setFlags(SplFileObject::READ_CSV) </em>sets the stage for parsing a csv file.  While on the topic of csv files&#8230; <em><em>SplFileObject::</em>setCsvControl()</em> allows you to set the delimiter, enclosure, and escape character.</p>
<h3>Reading Lines</h3>
<p>To read the file line by line it&#8217;s as easy as using a loop.</p>
<pre class="brush: php; title: ; notranslate">
foreach ($obj as $line) {
// SplFileObject::__toString() is set as an alias of SplFileObject::current(), which makes echo'ing the object return the current line.
echo $line;
}
</pre>
<h2>DirectoryIterator</h2>
<p><a href="http://php.net/manual/en/class.directoryiterator.php" target="_blank">DirectoryIterator</a> is used to list files and subdirectories. Like SplFileObject, it inherits from SplFileInfo. I&#8217;ll discuss iterators in another post, but for the sake of understanding the power of DirectoryIterator it is enough to know they are most often used in loops.</p>
<pre class="brush: php; title: ; notranslate">
foreach (new DirectoryIterator('/path/to/dir') as $file) {
    echo $fileInfo-&gt;getFilename() . &quot;\r\n&quot;;
}
</pre>
<p>This will yield something like:</p>
<pre>.
..
filename.txt
directory
image.jpg
</pre>
<p>One useful method available in DirectoryIterator but not available in SplFileInfo is <em>DirectoryIterator::isDot(). </em>This returns true if the &#8220;file&#8221; is a &#8220;.&#8221; or &#8220;..&#8221; system file.</p>
<h2>RecursiveDirectoryIterator</h2>
<p><a href="http://php.net/manual/en/class.recursivedirectoryiterator.php" target="_blank">RecursiveDirectoryIterator</a> is the recursive version of DirectoryIterator. It will go down into the subdirectories and list files and subdirectories and so on and so on.</p>
<pre class="brush: php; title: ; notranslate">
$files = new RecursiveDirectoryIterator('/path/to/dir');
$files = new RecursiveIteratorIterator($files);
foreach ($files as $file) {
    echo $file . &quot;\n\r&quot;;
}
</pre>
<p>This will yield something like:</p>
<pre>.
..
filename.txt
directory
directory/file.txt
directory/subdirectory
directory/subdirectory/image.jpg
image.jpg
</pre>
<h2>Closing</h2>
<p>I only touched on some of the basic and useful parts of the SPL that I found to make working with files much easier and more logical. There is so much more for you and I to learn about them though.</p><p>The post <a href="http://www.levijackson.net/working-with-files-and-spl/" target="_blank">Working with files and SPL</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/working-with-files-and-spl/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Install Elasticsearch Mac OSX 10.9.1</title>
		<link>http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/</link>
					<comments>http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Thu, 23 Oct 2014 00:50:52 +0000</pubDate>
				<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=684</guid>

					<description><![CDATA[<p>I waded through a few sets of instructions that didn&#8217;t work for me, so I figured i&#8217;d post the ones that did work. Download and unzip/untar the Elasticsearch files http://www.elasticsearch.org/download Download the latest version of Java (woo!) Copy the directory to /usr/local: sudo mv elasticsearch /usr/local To start it just execute: /usr/local/elasticsearch/bin/elasticsearch -f To stop it, &#8230; <a href="http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/" class="more-link">Continue reading <span class="screen-reader-text">Install Elasticsearch Mac OSX 10.9.1</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/" target="_blank">Install Elasticsearch Mac OSX 10.9.1</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I waded through a few sets of instructions that didn&#8217;t work for me, so I figured i&#8217;d post the ones that did work.</p>
<ol>
<li>Download and unzip/untar the Elasticsearch files <a href="http://www.elasticsearch.org/download" target="_blank">http://www.elasticsearch.org/download</a></li>
<li>Download the latest version of Java (woo!)</li>
<li>Copy the directory to /usr/local: <em>sudo mv elasticsearch /usr/local</em></li>
<li>To start it just execute: <em>/usr/local/elasticsearch/bin/elasticsearch -f</em></li>
<li>To stop it, just hit command+c</li>
</ol>
<p>Optional steps to allow you to start the service with just the &#8216;elasticsearch -f&#8217; command:</p>
<ol>
<li>Open your <code>.bash_profile</code> file for your bash profile settings</li>
<li>Add export ES_HOME=~/usr/local/elasticsearch/bin</li>
<li>Add export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home</li>
<li>Add export PATH=$ES_HOME/bin:$JAVA_HOME/bin:$PATH</li>
<li>Run &#8216;source ~/.bash_profile&#8217; from terminal</li>
</ol><p>The post <a href="http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/" target="_blank">Install Elasticsearch Mac OSX 10.9.1</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/install-elasticsearch-mac-osx-10-9-1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PHP pcntl_waitpid and pcntl_wait not working</title>
		<link>http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/</link>
					<comments>http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Fri, 29 Aug 2014 22:55:30 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=776</guid>

					<description><![CDATA[<p>I did a fair amount of work with using pcntl_fork recently to create child processes for an import script. The two main benefits of forking are that the processes are contained (if one fails, they all do not fail) and the speed increase. Instead of running an import of 100 posts sequentially, it would instead &#8230; <a href="http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/" class="more-link">Continue reading <span class="screen-reader-text">PHP pcntl_waitpid and pcntl_wait not working</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/" target="_blank">PHP pcntl_waitpid and pcntl_wait not working</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>I did a fair amount of work with using <a href="http://php.net/manual/en/function.pcntl-fork.php" target="_blank">pcntl_fork</a> recently to create child processes for an import script. The two main benefits of forking are that the processes are contained (if one fails, they all do not fail) and the speed increase. Instead of running an import of 100 posts sequentially, it would instead run 10 child processes importing 10 posts each.</p>
<p>Anyway, to get to the point. I was testing the importer from the browser and finding really inconsistent and perplexing things happening.</p>
<h2>pcntl_wait and pcntl_waitpid not working</h2>
<p>The code was setup to store an array of the pids used, and to not allow more than 10 child processes at a time. So it was supposed to hit <a href="http://php.net/manual/en/function.pcntl-wait.php" target="_blank">pcntl_wait</a> or <a href="http://php.net/manual/en/function.pcntl-waitpid.php" target="_blank">pcntl_waitpid</a> and clear out the pid that had finished.  The problem was that it never seemed to do that. I could see it was starting the processes and it was exiting them fine (ps -Hwfe from terminal verified there were no zombie processes).</p>
<p>My first thought after reading a bit about it was that perhaps the child process was finishing before the parent process had a chance to be informed the child process was starting. I tried adding sleep(10) into spots to try and delay the child process from finishing so quickly. Still didn&#8217;t work.</p>
<h2>Solution</h2>
<p>After realizing that pcntl_fork wasn&#8217;t supposed to be used from the browser when PHP was installed as an Apache module&#8230; I moved to using CLI to execute the script. I set it up so that I was using shell_exec() to execute the command after setting and uploading the import file. It worked great from CLI and I proceeded to bang my head into the wall a few times.</p>
<p><em>tldr; Use pcntl_fork, pcntl_wait, pcntl_waitpid in scripts run from CLI only&#8230; do not use them in the browser as that does not work as expected.</em></p><p>The post <a href="http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/" target="_blank">PHP pcntl_waitpid and pcntl_wait not working</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/php-pcntl_waitpid-and-pcntl_wait-not-working/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using Illuminate without Laravel</title>
		<link>http://www.levijackson.net/using-illuminate-without-laravel/</link>
					<comments>http://www.levijackson.net/using-illuminate-without-laravel/#respond</comments>
		
		<dc:creator><![CDATA[Levi Jackson]]></dc:creator>
		<pubDate>Sun, 06 Jul 2014 16:47:59 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">http://www.levijackson.net/?p=668</guid>

					<description><![CDATA[<p>If you have read past posts you know that I have decided to build a movie indexing app for personal use to make searching and finding movies I own easier. I decided to use just the Illuminate database component that Laravel uses to handle the CRUD. First step, pull it in (I used composer). Setting up the &#8230; <a href="http://www.levijackson.net/using-illuminate-without-laravel/" class="more-link">Continue reading <span class="screen-reader-text">Using Illuminate without Laravel</span> <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="http://www.levijackson.net/using-illuminate-without-laravel/" target="_blank">Using Illuminate without Laravel</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If you have read past posts you know that I have decided to build a movie indexing app for personal use to make searching and finding movies I own easier. I decided to use just the <a href="https://github.com/illuminate/database" target="_blank">Illuminate database component</a> that Laravel uses to handle the CRUD.</p>
<p>First step, pull it in (I used composer).</p>
<pre class="brush: php; title: ; notranslate">
{
    &quot;name&quot; : &quot;name of app&quot;,
    &quot;description&quot; : &quot;Desc of app&quot;,
    &quot;license&quot; : &quot;MIT&quot;,
    &quot;require&quot; : {
        &quot;illuminate/database&quot;: &quot;*&quot;
    }
}
</pre>
<p>Setting up the database connection is relatively easy if you use the docs on the Github and Laravel as a guide.</p>
<pre class="brush: php; title: ; notranslate">
$config = array(
    'db' =&gt; array(
        'driver' =&gt; 'mysql',
        'host' =&gt; '127.0.0.1',
        'database' =&gt; 'imdb',
        'username' =&gt; 'username',
        'password' =&gt; 'password',
        'collation' =&gt; 'utf8_general_ci',
        'charset' =&gt; 'utf8',
        'prefix' =&gt; 'imdb_',
        'port' =&gt; ''
    )
);

$connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(new \Illuminate\Container\Container());
$conn = $connFactory-&gt;make($config['db']);
$resolver = new \Illuminate\Database\ConnectionResolver();
$resolver-&gt;addConnection('default', $conn);
$resolver-&gt;setDefaultConnection('default');
\Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
</pre>
<p>Then all you really need to do is create your class file:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
namespace ProjectName\Models;

use Illuminate\Database\Eloquent\Model;

class Movie extends Model {
    protected $fillable = array('title', 'release_date');
    protected $guarded = array('id', 'updated_at', 'created_at');
}
</pre>
<p>You can easily add a record to the database by doing:</p>
<pre class="brush: php; title: ; notranslate">
$movie = new Movie(array('title' =&gt; A movie title, 'release_date' =&gt; '2014-01-23'));
$movie-&gt;save();
</pre>
<p>Nice and quick to get rolling so you aren&#8217;t spending so much time on the repetitive task of CRUD for each model.</p><p>The post <a href="http://www.levijackson.net/using-illuminate-without-laravel/" target="_blank">Using Illuminate without Laravel</a> first appeared on <a href="http://www.levijackson.net/" target="_blank">Levi Jackson</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>http://www.levijackson.net/using-illuminate-without-laravel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
