<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Khalid Dabjan on Medium]]></title>
        <description><![CDATA[Stories by Khalid Dabjan on Medium]]></description>
        <link>https://medium.com/@khaliddabjan?source=rss-66f2138bcd66------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*G0ZhguCXfVBy7xIB.jpeg</url>
            <title>Stories by Khalid Dabjan on Medium</title>
            <link>https://medium.com/@khaliddabjan?source=rss-66f2138bcd66------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:34:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khaliddabjan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Laravel 5.5 — Higher Order Tap]]></title>
            <link>https://medium.com/@khaliddabjan/laravel-5-5-higher-order-tab-5364fd041a36?source=rss-66f2138bcd66------2</link>
            <guid isPermaLink="false">https://medium.com/p/5364fd041a36</guid>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Khalid Dabjan]]></dc:creator>
            <pubDate>Thu, 24 Aug 2017 14:45:49 GMT</pubDate>
            <atom:updated>2017-08-24T14:49:25.415Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNQrvc2-vWeISip9PoDlvA.jpeg" /></figure><p>Higher order tap is a feature that comes with Laravel 5.5, it is an improvement over the somehow “controversial” tap() function.</p><p>First, a little background on tap when it was released with laravel 5.4 (I think?). The idea behind it is to “tap” into a value, manipulate it via a closure that you pass and then <strong><em>return this value. </em></strong>so something like:</p><pre>$user-&gt;update([<br>    &#39;name&#39; =&gt; &#39;Phoebe Buffay&#39;<br>]);<br>return $user;</pre><p>could be turned into:</p><pre>return tap($user, function (<em>$value</em>) {<br>    <em>$value</em>-&gt;update([<br>        &#39;name&#39; =&gt; &#39;Phoebe Buffay&#39;<br>    ]);<br>});</pre><p>But now with 5.5 the closure parameter is optional, so…:</p><pre>return tap($user)-&gt;update([<br>     &#39;name&#39;=&gt;&#39;Phoebe Buffay&#39;<br> ]);</pre><p>Which is Awesome, and -I’m gonna say it- Magical! Well, unfortunately no <em>real</em> magic is taking place here. taking a look at the implementation of tap:</p><pre>function tap(<em>$value</em>, <em>$callback </em>= null)<br>{<br>    if (<em>is_null</em>(<em>$callback</em>)) {<br>        return new HigherOrderTapProxy(<em>$value</em>);<br>    }<br><br>    <em>$callback</em>(<em>$value</em>);<br><br>    return <em>$value</em>;<br>}</pre><p>It checks if the $callback is null and it delegates to a class called HigherOrderTapProxy in case it was. This class implements the __call() magic method:</p><pre>public function __call(<em>$method</em>, <em>$parameters</em>)<br>{<br>    $this-&gt;target-&gt;{<em>$method</em>}(...<em>$parameters</em>);<br><br>    return $this-&gt;target;<br>}</pre><p>What do you, there was some magic involved after all :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5364fd041a36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using JSON in SQL table with Laravel]]></title>
            <link>https://medium.com/@khaliddabjan/using-json-in-sql-table-with-laravel-9f7cd63fa511?source=rss-66f2138bcd66------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f7cd63fa511</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Khalid Dabjan]]></dc:creator>
            <pubDate>Mon, 31 Jul 2017 13:55:38 GMT</pubDate>
            <atom:updated>2017-07-31T14:00:20.693Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blAm2FH2ASldKp3BaWugdg.png" /></figure><p>JSON is great, it’s flexible, easy to use and compatible with pretty much everything. The problem is when storing it in a SQL database, you’ll find yourself encoding and decoding JSON all over the place, and things get out of hand pretty fast. To solve this problem I created a trait a while back that takes care of all the dirty work for me, and I made it flexible enough to be reusable with all the projects that I needed it in.</p><p>To demonstrate this trait I’m going to use a general settings table as an example, this table is key value pairs with the value column holding the JSON string, the migration looks something like:</p><pre>Schema::create(&#39;settings&#39;, function (Blueprint <em>$table</em>) {<br>    <em>$table</em>-&gt;increments(&#39;id&#39;);<br>    <em>$table</em>-&gt;string(&#39;key&#39;, 50);<br>    <em>$table</em>-&gt;json(&#39;value&#39;);<br>    <em>$table</em>-&gt;timestamps();<br>});</pre><p>For example, assume we have the following JSON string in the settings table:</p><pre>{<br>    &quot;text&quot;:&quot;Lorum epsom&quot;,<br>    &quot;image&quot;:&quot;public\/uploads\/EeoWjkoNKmnbszaO5I.jpeg&quot;<br>}</pre><p>To get the value of text in conventional way we would have to do something like this:</p><pre>$encodedJson = <em>json_decode</em>($setting-&gt;value);<br>return $encodedJson-&gt;text;</pre><p>and to set it it would be something like:</p><pre>$decodedJsonArray = <em>json_decode</em>($setting-&gt;value, true);<br>$decodedJsonArray[&#39;text&#39;] = &#39;New text&#39;;<br>$setting-&gt;value = <em>json_encode</em>($decodedJsonArray);</pre><p>It would be much simpler if I was able to get and set a property in the decoded JSON value without having to access the value property and then decoding the JSON in it every time. So the idea here is to access a property on a setting object that is not <em>directly</em> there. And this is exactly what PHP magic methods <a href="http://php.net/manual/en/language.oop5.overloading.php#object.get">__get</a> and <a href="http://php.net/manual/en/language.oop5.overloading.php#object.set">__set</a> do.</p><p>So this trait can be used by any Model in Laravel that has a JSON column. There two things this trait needs to know. First, the name of the column in the table that holds the JSON string, and second is all the names that are actual columns in the table and should not be assumed they are in the JSON decoded object, those properties are called $jsonColumn and $columns respectively in the trait. There are also the two magic methods __get and __set, so the trait is as follows:</p><pre>&lt;?php<br><br>namespace App;<br><br>trait Jasonable<br>{</pre><pre>    protected $jsonColumn = &#39;value&#39;;<br>    protected $columns = [&#39;created_at&#39;, &#39;updated_at&#39;];<br>    <br><br>    public function __get(<em>$name</em>)<br>    {<br>        if (<em>in_array</em>(<em>$name</em>, $this-&gt;columns)) <br>            return $this-&gt;getAttribute(<em>$name</em>);<br>        if (!isset($this-&gt;attributes[$this-&gt;jsonColumn]) || $this-&gt;attributes[$this-&gt;jsonColumn] === null) <br>            return false;<br>        $encoded = <em>json_decode</em>($this-&gt;attributes[$this-&gt;jsonColumn]);<br>        return isset($encoded-&gt;$name) ? $encoded-&gt;$name : false;<br>    }<br><br>    public function __set(<em>$name</em>, <em>$value</em>)<br>    {<br>        if (<em>in_array</em>(<em>$name</em>, $this-&gt;columns)) <br>            return;<br>        $decodedArray = <em>json_decode</em>($this-&gt;attributes[$this-&gt;jsonColumn], true);<br>        $decodedArray[<em>$name</em>] = <em>$value</em>;<br>        $this-&gt;attributes[$this-&gt;jsonColumn] = <em>json_encode</em>($decodedArray);<br>    }<br>}</pre><p>So assuming that the Setting model uses this trait, working with the model objects would be as simple as:</p><pre>$setting-&gt;text = &#39;New text&#39;;<br>return $setting-&gt;text;</pre><p>So making use of PHP magic methods made working with JSON in a Laravel model much easier. Hope someone would find this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f7cd63fa511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a console application using Symfony Console component]]></title>
            <link>https://medium.com/@khaliddabjan/building-a-console-application-using-symfony-console-component-6ddc9bec555a?source=rss-66f2138bcd66------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ddc9bec555a</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[console]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Khalid Dabjan]]></dc:creator>
            <pubDate>Sat, 29 Apr 2017 21:10:41 GMT</pubDate>
            <atom:updated>2017-04-29T21:10:41.586Z</atom:updated>
            <content:encoded><![CDATA[<p>The other day I came across a <a href="http://maqe.github.io/maqe-bot.html">challenge</a> posted on github.io for a command line bot that moves in a two dimensional plane, I found the idea to be interesting and thought I’d give it a shot, and post the workflow I followed.</p><p>Since I’m going to be using Symfony, I’ll start by creating a composer.json file:</p><pre>$ mkdir bot<br>$ cd bot<br>$ echo {} &gt; composer.json</pre><p>Next, require the console component:</p><pre>composer require symfony/console</pre><p>I’m going to take a TDD(Test Driven Development) approach on this, so we need to pull in phpunit</p><pre>composer require --dev phpunit/phpunit</pre><p>We’ll start with theBot class:</p><pre>&lt;?php<br><br>namespace App\Core;<br><br>class Bot<br>{<br><br>    /*<br>     * @var Position<br>     */<br>    protected $position;<br><br>    public function __construct()<br>    {<br>        $this-&gt;position = new Position();<br>    }<br>}</pre><p>It has a property called $position That is an instance of the class Position This class looks like this:</p><pre>&lt;?php<br><br>namespace App\Core;<br><br>class Position<br>{<br>    protected $direction;<br><br>    protected $x;<br><br>    protected $y;<br><br>    protected $directionNames;<br><br>    function __construct()<br>    {<br>        $this-&gt;direction = &#39;n&#39;;<br>        $this-&gt;x = 0;<br>        $this-&gt;y = 0;<br><br>        $this-&gt;directionNames = [<br>            &#39;n&#39; =&gt; &#39;north&#39;,<br>            &#39;e&#39; =&gt; &#39;east&#39;,<br>            &#39;s&#39; =&gt; &#39;south&#39;,<br>            &#39;w&#39; =&gt; &#39;west&#39;<br>        ];<br>    }<br>}</pre><p>This class will be responsible for the postioning of the bot, it hold its current $x,$y coordinates and the $direction it is facing. We initiate these values to 0,0 and n repectively. There is also an array $directionNames that is indexed by the four direction the bot can be facing n, e, s, w This is just a helper to return the full name of the direction that we will use later.</p><p>Now we need to set up a test class that will be responsible for the phpunit testing. Since the functionality isn’t that much and not that complicated, I’m going to use one test class, and it will be under /tests/ directory. For now this class will have:</p><pre>&lt;?php<br>use PHPUnit\Framework\TestCase;<br><br>class BotTest extends TestCase<br>{</pre><pre>    protected $bot;<br><br>    public function setUp()<br>    {<br>        parent::setUp();<br>        $this-&gt;bot = new \App\Core\Bot();<br>    }<br>}</pre><p>Now we can start with the actual functionality of the bot, the bot should be able to walk by a specified number of steps. The test for that:</p><pre>/** @test */<br>public function it_walks_1_step()<br>{<br>    $this-&gt;bot-&gt;walk(1);<br>    $this-&gt;assertEquals(&quot;X: 0 Y: 1 Direction: north&quot;, $this-&gt;bot<br>        -&gt;getPosition());<br>}</pre><p>I have the habit of running the test as soon as I write it (by typing this in the command line: phpunit ./tests) and see where it fails first and fix it, then run it again and fix it again, and so on. Obviously this will fail because we don’t have a walk method in the Bot class. So we’ll add it:</p><pre>public function walk(<em>$steps </em>= 1)<br>{<br>    $this-&gt;position-&gt;walk(<em>$steps</em>);<br>    return $this;<br>}</pre><p>Since the Position Class is responsible for the positioning of the bot, we’ll just delegate to a walk method on the Position class. and this method will actually do the walking:</p><pre>public function walk(<em>$steps </em>= 1)<br>{<br>    switch ($this-&gt;direction) {<br>        case &#39;n&#39;:<br>            $this-&gt;y += <em>$steps</em>;<br>            break;<br>        case &#39;e&#39;:<br>            $this-&gt;x += <em>$steps</em>;<br>            break;<br>        case &#39;s&#39;:<br>            $this-&gt;y -= <em>$steps</em>;<br>            break;<br>        case &#39;w&#39;:<br>            $this-&gt;x -= <em>$steps</em>;<br>            break;<br>    }<br>    return $this;<br>}</pre><p>This method will simply check the current direction the bot is facing, and then “walk” in the appropriate direction, and by “walk” I mean increment or decrement the Xs or Ys coordinates by the number of the provided $steps .</p><p>Next failure will be calling $this-&gt;bot-&gt;getPosition(). We want this function to return a text representation of the position object, this sounds like a good use case for the __toString() function:</p><pre>public function getPosition()<br>{<br>    return $this-&gt;position-&gt;__toString();<br>}</pre><p>Of course we need to override the function in the Position class:</p><pre>function __toString()<br>{<br>    return &quot;X: {$this-&gt;x} Y: {$this-&gt;y} Direction: {$this<br>        -&gt;getDirection(true)}&quot;;<br>}</pre><p>Now the getDirection() function will make use of that array of direction names we have in the Position class:</p><pre>public function getDirection(<em>$fullName </em>= false)<br>{<br>    return <em>$fullName </em>? <br>        $this-&gt;directionNames[$this-&gt;direction] :<br>        $this-&gt;direction;<br>}</pre><p>Now the test we wrote should pass:</p><pre><strong>vagrant@homestead</strong>:<strong>~/Code/bot</strong>$ phpunit ./tests/ --filter it_walks_1_step</pre><pre>PHPUnit 6.1.1 by Sebastian Bergmann and contributors.</pre><pre>.                                                                   1 / 1 (100%)</pre><pre>Time: 110 ms, Memory: 2.00MB</pre><pre>OK (1 test, 1 assertion)</pre><p>Now that we established that the bot is able to walk around the plane, we need to work on the turning, it should be able to turn to the right (its right) and to the left (its left):</p><pre>/** @test */<br>public function it_turns_to_the_right()<br>{<br>    $this-&gt;bot-&gt;turnRight();<br>    $this-&gt;assertEquals(&#39;e&#39;, $this-&gt;bot-&gt;getDirection());<br>}<br><br>/** @test */<br>public function it_turns_to_the_left()<br>{<br>    $this-&gt;bot-&gt;turnLeft();<br>    $this-&gt;assertEquals(&#39;w&#39;, $this-&gt;bot-&gt;getDirection());<br>}</pre><p>So it looks like we need two new methods in the Bot class: turnRight() and turnLeft() :</p><pre>public function turnRight()<br>{<br>    $this-&gt;position-&gt;turn(&#39;right&#39;);<br>    return $this;<br>}<br><br>public function turnLeft()<br>{<br>    $this-&gt;position-&gt;turn(&#39;left&#39;);<br>    return $this;<br>}</pre><p>They both delegate to the same function turn($to) on the position object. Now this bit is somehow tricky, the turning should result in a change in the $direction of the position of the bot. But this change is not only tied to the direction the bot is turning (left or right), but also the current direction the bot is facing (north, east, south or west). Say the bot is facing north and we tell it to turn right, then it should -after turning- face east, but it was facing east and we tell it to turn right, then it will be facing south after turning.</p><p>There are many ways to tackle this, what I went for is to define a function for every scenario the bot might be in when turning, like so:</p><pre>protected function northToRight()<br>{<br>    $this-&gt;direction = &#39;e&#39;;<br>}<br><br>protected function northToLeft()<br>{<br>    $this-&gt;direction = &#39;w&#39;;<br>}</pre><pre>protected function eastToRight()<br>{<br>    $this-&gt;direction = &#39;s&#39;;<br>}</pre><pre>protected function eastToLeft()<br>{<br>    $this-&gt;direction = &#39;n&#39;;<br>}<br>protected function southToRight()<br>{<br>    $this-&gt;direction = &#39;w&#39;;<br>}</pre><pre>protected function southToLeft()<br>{<br>    $this-&gt;direction = &#39;e&#39;;<br>}</pre><pre>protected function westToRight()<br>{<br>    $this-&gt;direction = &#39;n&#39;;<br>}</pre><pre>protected function westToLeft()<br>{<br>    $this-&gt;direction = &#39;s&#39;;<br>}</pre><p>So now we just need to figure out the function name to call according to the current position and where to turn, so a function that returns a function name to call:</p><pre>protected function getTurnFunctionName(<em>$to</em>)<br>{<br>    return $this-&gt;getDirection(true) . &quot;To&quot; . <em>ucfirst</em>(<em>$to</em>);<br>}</pre><p>Say the bot is facing south, $to is left, then this function will return southToLeft so we just call southToLeft. that will result in changing the bot direction to the east. Now vack to the turn($to) function, it should do the following:</p><pre>public function turn(<em>$to</em>)<br>{<br>    $functionName = $this-&gt;getTurnFunctionName(<em>$to</em>);<br>    $this-&gt;$functionName();<br>}</pre><p>Now the second test should pass as well, we can add a couple more tests for the turning:</p><pre>/** @test */<br>public function it_does_a_360_turn_clockwise()<br>{<br>    $this-&gt;bot<br>        -&gt;turnRight()<br>        -&gt;turnRight()<br>        -&gt;turnRight()<br>        -&gt;turnRight();<br>    $this-&gt;assertEquals(&#39;n&#39;, $this-&gt;bot-&gt;getDirection());<br>}<br><br>/** @test */<br>public function it_does_a_360_turn_anti_clockwise()<br>{<br>    $this-&gt;bot<br>        -&gt;turnLeft()<br>        -&gt;turnLeft()<br>        -&gt;turnLeft()<br>        -&gt;turnLeft();<br>    $this-&gt;assertEquals(&#39;n&#39;, $this-&gt;bot-&gt;getDirection());<br>}</pre><p>And for the sake of variety :)</p><pre>/** @test */<br>public function it_can_face_south()<br>{<br>    $this-&gt;bot<br>        -&gt;turnLeft()<br>        -&gt;turnLeft();<br>    $this-&gt;assertEquals(&#39;s&#39;, $this-&gt;bot-&gt;getDirection());<br>}<br><br>/** @test */<br>public function it_can_face_west()<br>{<br>    $this-&gt;bot<br>        -&gt;turnRight()<br>        -&gt;turnRight()<br>        -&gt;turnRight();<br>    $this-&gt;assertEquals(&#39;w&#39;, $this-&gt;bot-&gt;getDirection());<br>}</pre><p>Now the core functionality is done, we just need an entry point from the console application into the bot class, where we can receive a command string for the bot to move according to. In the requirement of the bot they said:</p><blockquote>For example, the walking code of <strong>RW15RW1</strong> means</blockquote><blockquote>MAQE Bot starts at 0, 0 facing up North.</blockquote><blockquote>MAQE Bot turns right (facing East) and walk straight 15 positions.</blockquote><blockquote>MAQE Bot turns another right (now facing South) and walk straight 1 position.</blockquote><p>Let’s have a move($command) method in the Bot class, this method will receive the move command string, it will parse it, validate it and run it.</p><p>So first we need the function that will parse the command string and turn it into a series (AKA: an array) of methods that we can invoke, the function has comment blocks for each step:</p><pre>protected function getMoveCommands(<em>$command</em>)<br>{<br>    $methods = [];<br>    /*<br>     * Split the command string into characters and loop over them.<br>     */<br>    foreach (<em>str_split</em>(<em>$command</em>) as $char) {<br>        switch ($char) {<br>            case &#39;R&#39;:<br>            case &#39;L&#39;:<br>                /*<br>                 * In case it was either R or L, then it is a turn command.<br>                 * So we need to call the turn method and a parameter indicating<br>                 * the direction of the turn (either &#39;right&#39; or &#39;left&#39;).<br>                 */<br>                $currentMethod = [];<br>                $currentMethod[&#39;method&#39;] = &#39;turn&#39;;<br>                $currentMethod[&#39;param&#39;] = $char == &#39;R&#39; ? &#39;right&#39; : &#39;left&#39;;<br>                $methods[] = $currentMethod;<br>                break;<br>            case &#39;W&#39;:<br>                /*<br>                 * A walk command, so just push it into the methods array.<br>                 */<br>                $methods[][&#39;method&#39;] = &#39;walk&#39;;<br>                break;<br>            default:<br>                /*<br>                 * If it&#39;s not a turn command or a walk command, then it is<br>                 * a number of steps for the walk command, and for it to be<br>                 * a valid number of steps, it must be a numeric value, the<br>                 * methods array must not be empty, and the last command that<br>                 * was pushed into the methods array must be a walk command.<br>                 * Anything other than that means that the command string is not<br>                 * formatted correctly, so we throw an exception and terminate.<br>                 */<br>                $lastMethodIndex = <em>count</em>($methods) - 1;<br>                if (!<em>is_numeric</em>($char) || <em>count</em>($methods) == 0 || $methods[$lastMethodIndex][&#39;method&#39;] !== &#39;walk&#39;) {<br>                    throw new \Exception(&#39;The move command is not in a valid format&#39;);<br>                }<br>                /*<br>                 * We check if param key was set on the last pushed command in the<br>                 * methods array for the case of having a two digit number of steps,<br>                 * So in case that key was already set, that means we need to concatenate<br>                 * the two digits.<br>                 */<br>                $methods[$lastMethodIndex][&#39;param&#39;] = isset($methods[$lastMethodIndex][&#39;param&#39;]) ? $methods[$lastMethodIndex][&#39;param&#39;] . $char : $char;<br>                break;<br>        }<br>    }<br>    return $methods;<br>}</pre><p>Then, the actual move() method will be:</p><pre>public function move(<em>$commandString</em>)<br>{<br>    $commands = $this-&gt;getMoveCommands(<em>$commandString</em>);<br>    foreach ($commands as $command) {<br>        $methodName = $command[&#39;method&#39;];<br>        $param = $command[&#39;param&#39;];<br>        $this-&gt;position-&gt;$methodName($param);<br>    }<br>    return $this-&gt;getPosition();<br>}</pre><p>The entry point for the application from the command line will be index.php. In this file we simply require the autoload file generated by composer, new up the application with a simple description and version number, add the BotCommand class to the $app, and then run it:</p><pre><strong>#!/usr/bin/env php<br></strong>&lt;?php<br><br>require <em>__DIR__ </em>. &#39;/vendor/autoload.php&#39;;</pre><pre>use Symfony\Component\Console\Application;<br><br>$app = new Application(&quot;The moving bot&quot;, 1.0);<br><br>$app-&gt;add(new \App\Commands\BotCommand());<br><br>$app-&gt;run();<br></pre><p>The actual BotCommand class looks like this:</p><pre>&lt;?php<br><br>namespace App\Commands;<br><br>use App\Core\Bot;<br>use Symfony\Component\Console\Command\Command;<br>use Symfony\Component\Console\Input\InputArgument;<br>use Symfony\Component\Console\Input\InputInterface;<br>use Symfony\Component\Console\Output\OutputInterface;<br><br>class BotCommand extends Command<br>{<br>    /**<br>     * Set the configuration for the command<br>     */<br>    protected function configure()<br>    {<br>        $this-&gt;setName(&#39;bot:move&#39;)<br>            -&gt;setDescription(&#39;Move the bot&#39;)<br>            -&gt;setHelp(&#39;Use this command to move the bot in a given fashion&#39;)<br>            -&gt;addArgument(&#39;direction&#39;, InputArgument::<em>REQUIRED</em>, &#39;The direction string for the bot to move&#39;);<br>    }<br><br>    /**<br>     * Execute the command<br>     * @param InputInterface $input<br>     * @param OutputInterface $output<br>     */<br>    protected function execute(InputInterface <em>$input</em>, OutputInterface <em>$output</em>)<br>    {<br>        $bot = new Bot();<br>        $bot-&gt;move(<em>$input</em>-&gt;getArgument(&#39;direction&#39;));<br>        <em>$output</em>-&gt;writeln($bot-&gt;getPosition());<br><br>    }<br>}</pre><p>Samples of running the app:</p><pre><strong>vagrant@homestead</strong>:<strong>~/Code/bot</strong>$ php index.php bot:move RW15RW1</pre><pre>X: 15 Y: -1 Direction: south</pre><pre><strong>vagrant@homestead</strong>:<strong>~/Code/bot</strong>$ php index.php bot:move LLLLLW99RRRRRW88LLLRL</pre><pre>X: -99 Y: 88 Direction: east</pre><p>If we provide a move command that is not correct:</p><pre><strong>vagrant@homestead</strong>:<strong>~/Code/bot</strong>$ php index.php bot:move L13W1R</pre><pre>[Exception]</pre><pre>The move command is not in a valid format</pre><pre>bot:move &lt;direction&gt;</pre><p>The full code can be found <a href="https://github.com/khalid-dabjan/bot">here</a>, if you have any suggestion or you see any mistake I might have made, please tell me in a response or submit a PR on GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ddc9bec555a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Confessions of a Mac virgin]]></title>
            <link>https://medium.com/@khaliddabjan/confessions-of-a-mac-virgin-96bc070a8187?source=rss-66f2138bcd66------2</link>
            <guid isPermaLink="false">https://medium.com/p/96bc070a8187</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[macbook]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Khalid Dabjan]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 16:59:15 GMT</pubDate>
            <atom:updated>2017-04-21T16:59:15.247Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been a windows user my whole life, a very faithful one. from its early Windows 98 days, up until Windows 10. We’ve had our ups and downs, but for the most parts it’s been a good relationship. That was till I took a career in web development, that was when trouble began.</p><p>During collage all my programming related subjects were either done with .Net (mainly C#) or Java, and setting a working environment for both wasn’t that hard as I recall. After collage I started embarking on the world of PHP, and you can probably guess what I went for regarding my local environment, Yes, WAMP, a tool that is just as bad as its name sounds. But to be fair, I didn’t need more than what WAMP had to offer for the basic run of the mill Wordpress themes that I was doing at the time.</p><p>Fast forward to early 2014, I was living in Cairo at that time, and I remember my good friend <a href="https://medium.com/u/e7bbf9c0f622">Mohamed Said</a> telling me about this kick-ass framework that he has been working with, and it’s called Laravel. a great tool that he said it’s going to be the next big thing (and in case you are living under a rock it’s now The best thing). Anyway that was when Windows and I started to have the troubles, and I specifically remember needing to install Memchached on my local machine, and let me tell you. It Is HARD, in fact I’m pretty sure with windows 10 it’s not even possible, not to mention Composer, Redis, NPM, PHP7 etc… And yeah I know Homestead offers all of that out of the box but have you tried installing it on a windows 10 machine? if you were successful then you are a wizard, even if your name isn’t Harry :)</p><p>A month ago, I started considering changing my two year old Lenovo laptop. The first thing that I was researching was the Windows Surface Book. It seemed decent, had good reviews and a nice range of specs to choose from. But, at the end of the day, it was Windows. Knowing all the pain that I’d have to go through setting up my development environment again, all the DLLs I’d have to download, all the tweaks I’d have to do to the .rb files of the Homestead scripts to get it NOT to work (and then having to turn to Laragon again), it all just made the whole process too overwhelming.</p><p>That was when I cave in to the pressure from all my friends and colleagues, and I decided to get The MacBook Pro 2016, with touch bar and touch ID and all. by the evening of the same day I got it in, all my repos were cloned and up and running. I used Homestead with PHP7 for my new Laravel projects. and now planning on having Valet setup with php5.6 for an old laravel 4.2 project that I’m still maintaining.</p><p>The laptop is amazing, for both work and entertainment. the keyboard and the touchpad are my favorite, the touch bar adds a nice “touch” to the whole experience, but you can totally do without it. The Arabic letters layout is a bit different and I still struggle typing in Arabic, but I guess that just needs getting used to. Siri is there too, personally I don’t find that much use to it (or to digital assistants in general, like Google assistant on my Pixel phone) but maybe that is just me.</p><p>During my research I’ve read, heard and seen so many reviews, comments and comparisons between Mac and Windows, Mac is not at all bad as some extremist Windows users make it to be, it’s easy, intuitive and very different from anything else. On the other hand, it’s not all powerful and almighty as Apple extremist make it to be, I’ve had a couple of times where it freezes and not respond. And regarding the battery, I’d have my virtual machine up, a dozen Google Chrome tabs open, and my IDE, and I’d get like 4 to 5 hours out of it, I don’t reckon that’s a “moderate use” per se, but these things are always running (more or less Chrome tabs) but never have I got 9 to 10 hours out of it as some people suggested.</p><p>So if you are a struggling web developer on a Windows machine please do yourself and favor and make the switch, and it doesn’t have to be to the 2016 version if you find the price too steep, older versions are more affordable and still pretty good. and since it’s so well built, it will last you way more than any other laptop for a cheaper price.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96bc070a8187" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>