<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martins Fridenbergs</title>
    <description>The latest articles on DEV Community by Martins Fridenbergs (@mafx).</description>
    <link>https://dev.to/mafx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F327140%2F919b3926-5cea-40cb-8b0b-dd8367a72273.jpeg</url>
      <title>DEV Community: Martins Fridenbergs</title>
      <link>https://dev.to/mafx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mafx"/>
    <language>en</language>
    <item>
      <title>PHP development on Win10 through WSL2, Laravel Valet and Tighten Takeout</title>
      <dc:creator>Martins Fridenbergs</dc:creator>
      <pubDate>Fri, 27 Nov 2020 09:04:23 +0000</pubDate>
      <link>https://dev.to/mafx/php-development-on-win10-through-wsl2-laravel-valet-and-tighten-takeout-5en8</link>
      <guid>https://dev.to/mafx/php-development-on-win10-through-wsl2-laravel-valet-and-tighten-takeout-5en8</guid>
      <description>&lt;p&gt;I've been doing PHP development professionally for pretty much the last 10 years. I've also been a Windows user pretty much forever. Put together that has not been the greatest experience as when it comes to running a local webserver the experience has always not been excellent. Nuances like Windows line endings always cause issues. I've tried switching over to Linux but the GUI has always felt like it has lacked. I've never been a fan of macOS but the tools they have like Laravel Valet have made me jealous a fair few times. Thankfully Win10 has WSL2 nowadays which is a game-changer.&lt;/p&gt;

&lt;p&gt;This guide explains steps how to set up a PHP environment for local development using Laravel Valet Linux and Tighten Takeout tools on Docker.&lt;/p&gt;

&lt;h2&gt;
  
  
  WSL2
&lt;/h2&gt;

&lt;p&gt;First of all you will need to set up WSL (Windows Subsystem for Linux) on your machine if you haven't done this already. The official guide for doing this can be found &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whilst the linux distro used is purely personal preference I've used Ubuntu as it is very widely used and always has good documentation / search results for any issues on web.&lt;/p&gt;

&lt;p&gt;Whilst most of the environment will be set up on WSL with Laravel Valet, it does not automatically set up database engine to allow users selecting their own preference. For this reason we will be using &lt;a href="https://github.com/tighten/takeout"&gt;Tighten Takout&lt;/a&gt; to set up any necessary engines like database / cache / search etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;First of all if you don't have docker installed - it is a &lt;a href="https://www.docker.com/get-started"&gt;simple install process&lt;/a&gt; to get started. After you set up docker you want to check and ensure docker uses WSL containers - guide to verify and adjust can be found &lt;a href="https://docs.docker.com/docker-for-windows/wsl/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up environment
&lt;/h2&gt;

&lt;p&gt;Now that we have pre-requisites installed we can set up the environment. &lt;/p&gt;

&lt;h4&gt;
  
  
  Update package lists
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Install php, its modules and unzip on system
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install unzip php php-cli php-fpm php-json php-intl php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath -yqq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need any other module you can install it via &lt;code&gt;sudo apt install php-module&lt;/code&gt; command. If you require a specific php version or php module version you can use &lt;code&gt;php7.4 php7.4-zip&lt;/code&gt; format.&lt;/p&gt;

&lt;h4&gt;
  
  
  Install composer
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -sS https://getcomposer.org/installer | php \
            &amp;amp;&amp;amp; sudo mv composer.phar /usr/local/bin/ \
            &amp;amp;&amp;amp; sudo ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Prepare for Laravel Valet
&lt;/h4&gt;

&lt;p&gt;We have few additional dependencies to install:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install network-manager libnss3-tools jq xsel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also edit &lt;code&gt;/etc/wsl.conf&lt;/code&gt; to add following lines. This is nescessary as WSL normally does recreate &lt;code&gt;/etc/resolv.conf&lt;/code&gt; file when you start it. Adding this line in wsl config will prevent it from re-writing file &lt;em&gt;as long as the file is not a symlink&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[network]
generateResolvConf=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Install Laravel Valet Linux &amp;amp; Tighten Takeout
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer global require cpriego/valet-linux tightenco/takeout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also want to make sure we can use commands like &lt;code&gt;valet&lt;/code&gt; or &lt;code&gt;takeout&lt;/code&gt; without specifying path so we want to make sure that the path to these binaries is registered as part of the system PATH variable. This can be added by updating the &lt;code&gt;~/.bashrc&lt;/code&gt; file by adding the path to global composer bin path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PATH=~/.config/composer/vendor/bin:$PATH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once file has been updated you can reload the bash shell for the new path to be loaded by running &lt;code&gt;source ~/.bashrc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we can install Valet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;valet install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will set up Laravel Valet on device. Valet does change the &lt;code&gt;/etc/resolv.conf&lt;/code&gt; file to a symlink which is going to be reset after WSL gets rebooted even with our wsl.conf file edit if we leave it as a symlink. Due to this it is recommended to copy the valet resolv config over.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo unlink /etc/resolv.conf
sudo cp /opt/valet-linux/valet-dns /etc/resolv.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An issue I've also noticed is that valet linux does not include default DNS config which can cause issues with accessing anything on web from the wsl (including composer installs, pinging and other actions). Due to this it is recommended to add &lt;code&gt;/opt/valet-linux/dns-servers&lt;/code&gt; file and have following in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nameserver 1.1.1.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;1.1.1.1&lt;/code&gt; is Cloudflare DNS, if you don't want to use it you can use &lt;code&gt;8.8.8.8&lt;/code&gt; for Google DNS or any other alternative.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting Services
&lt;/h2&gt;

&lt;h4&gt;
  
  
  valet
&lt;/h4&gt;

&lt;p&gt;Now everything should be set up and you should be able to get things started with &lt;code&gt;valet start&lt;/code&gt; command. In personal experience I've noticed that php-fpm on ubuntu tends not to start with valet linux and I'm yet to figure out why, but this can be bypassed by running &lt;code&gt;sudo service php7.4-fpm start&lt;/code&gt; (or your php version) after starting valet.&lt;/p&gt;

&lt;p&gt;Valet also requires you to park a directory to identify where to look for sites. Run &lt;code&gt;valet park&lt;/code&gt; in directory where you are locating your projects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Takeout
&lt;/h4&gt;

&lt;p&gt;Running &lt;code&gt;takout enable&lt;/code&gt; should bring up a menu allowing to enable specific service - mysql, postgres, redis, elasticsearch etc. Enabling these will set up a docker container that will be used to manage the service. Services already set up can be seen running &lt;code&gt;takeout list&lt;/code&gt; and started/stopped running &lt;code&gt;takeout start CONTAINER_ID&lt;/code&gt; and &lt;code&gt;takeout stop CONTAINER_ID&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NB&lt;/strong&gt; Services are available on 127.0.0.1 not localhost so make sure you update your environment variables to reflect this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additionals
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Node.js
&lt;/h4&gt;

&lt;p&gt;Node.js won't be installed by default, you can run install for this. I've also included npm, however yarn is also a popular package manager that can be used as an alternative to npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nodejs npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would recommend installing &lt;a href="https://github.com/nvm-sh/nvm#install--update-script"&gt;NVM (node version manager)&lt;/a&gt; as it allows easily switching between node versions which might come in handy if you need to support some legacy projects. It also could make it easier to upgrade when new version is released&lt;/p&gt;

&lt;h4&gt;
  
  
  Request routing / DNS
&lt;/h4&gt;

&lt;p&gt;The last thing to  get sites working is the requirement to add dns entries for your local pc to route the site to 127.0.0.1. This normally is done in &lt;code&gt;C:/Windows/System32/drivers/etc/hosts&lt;/code&gt; file where you specify the domain name and its IP address&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;127.0.0.1 mysite.test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a relatively large set-back when you compare it to the ease of valet on linux/macos where wildcard DNS routing is possible as it requires managing each site individually.&lt;br&gt;
There is however a potential workaround if you are using Chrome as your development web brower. As per &lt;a href="https://tools.ietf.org/html/rfc2606"&gt;IETF specification&lt;/a&gt; &lt;code&gt;*.localhost&lt;/code&gt; TLD is outlined to be a loopback domain and it should route back to 127.0.0.1. This is however for web browser companies to implement and there are mixed results. From my own testing I've found out that Chrome does support this functionality whilst other browsers (Firefox / Edge) do not do  this. So if you primarily work on this browser you can switch valet domain to localhost and it will remove necessity to manually add dns entries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;valet domain localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>development</category>
      <category>wsl2</category>
      <category>php</category>
      <category>devops</category>
    </item>
    <item>
      <title>Jack of all trades vs master of one</title>
      <dc:creator>Martins Fridenbergs</dc:creator>
      <pubDate>Thu, 06 Feb 2020 16:59:11 +0000</pubDate>
      <link>https://dev.to/mafx/jack-of-all-trades-vs-master-of-one-53c9</link>
      <guid>https://dev.to/mafx/jack-of-all-trades-vs-master-of-one-53c9</guid>
      <description>&lt;p&gt;No matter how we'd like to argue at the end of the day there are two types of people - those who are experts in one (relatively) narrow field and those who are capable/good at doing a lot of things but they don't shine in any.&lt;/p&gt;

&lt;p&gt;During school we are taught generic education - they throw everything at you from literature, art to math and physics. By the time we get to university we start getting specialization. You already have some of the subjects fading away and with each year you get narrower in your field. This specialization happens also in programming - and it might seem a bit more subtle than you'd think at first. But it slowly creeps in day by day.&lt;/p&gt;

&lt;p&gt;I've been meaning to expand my view on programming, try new things and learn a new language. And in this decision I found myself in a very much stuck in my narrow skill-set. You see - after spending 10k hours working with web, working with PHP, working with Laravel-like platforms I've trapped myself in thinking in certain directions, always thinking about certain issues.&lt;/p&gt;

&lt;p&gt;I like learning by doing, code by building a prototype solution. For web its easy - I already have 5 ideas in my head for what I want to do and once I start pulling on one it tangles itself into another 5. But trying to do something else, something I am not familiar with, appears to be a lot more difficult. It is not only difficult to formulate the concept, but on top of it it is in a new language with new techniques, new processes. Every step comes slowly - even the point of setting up the environment to start writing code appears to be a lot trickier when its not something you've spent years to optimise.&lt;/p&gt;

&lt;p&gt;It might seem better to be on the other side of the table. But its not - whilst having wide general knowledge is good, it is very limiting. Not only job opportunities will be more difficult because expert will do the job better but balancing this status quo in long term is very difficult. &lt;/p&gt;

&lt;p&gt;In fairness I do believe that being a master of one field is a lot better than being jack of all - at least in long term. You just need to remember to try something else and different now and then.&lt;/p&gt;

</description>
      <category>skills</category>
      <category>learning</category>
    </item>
    <item>
      <title>Old school developer vs new school developer</title>
      <dc:creator>Martins Fridenbergs</dc:creator>
      <pubDate>Sun, 02 Feb 2020 10:24:16 +0000</pubDate>
      <link>https://dev.to/mafx/old-school-developer-vs-new-school-developer-3m8b</link>
      <guid>https://dev.to/mafx/old-school-developer-vs-new-school-developer-3m8b</guid>
      <description>&lt;p&gt;Every language has its quirks. PHP has been know to be a language where it is very easy to do things badly. In reality it is not the languages fault but how we as developers treat it. Being a lead developer and seeing new employees (and candidates) in action has shown me that there are two types of PHP developers - new school and old school, each with their own issues.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Old School Devleoper&lt;/em&gt; is one that has been building functionality for a long time time (obviously). He/she started doing this before the advent of frameworks, most likely even before Composer was a thing. This is a person at whose CV you'll look and consider for a senior level position. But it is not always as great as it looks.&lt;/p&gt;

&lt;p&gt;Some of the main risks of the old-school developer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;old habits die hard - the longer you do something, the more you get used to it. It becomes hard to adapt to new techniques, new technologies and even new coding styles.&lt;/li&gt;
&lt;li&gt;if the person is not driven to keep improving the code will be functional but more costly. Features will be built from scratch instead of using a library loaded from composer. Templating will be built manually (and will likely include a risk for XSS vulnerability) instead of using an existing library like twig / blade. &lt;/li&gt;
&lt;li&gt;harder adaptation to new frameworks and languages.&lt;/li&gt;
&lt;li&gt;ego - after doing something for a long time developer will get the confidence of the approach. Whilst not bad on its own, this can cause issues when task is misunderstood or the approach/code does not follow the company's overall guidelines. Also can struggle with having respect for co-workers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the strenghts of old-school:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;usually a strong understanding of tasks and how to build it.&lt;/li&gt;
&lt;li&gt;strong time estimation skills.&lt;/li&gt;
&lt;li&gt;understanding of vulnerabilities and how to avoid security issues.&lt;/li&gt;
&lt;li&gt;usually some dev-ops experience.&lt;/li&gt;
&lt;li&gt;good patterns for analysing and debugging. Doesn't go in circles but knows where to look for issues and how to find them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;New School Developer&lt;/em&gt; is one that has started web development in the "green days" of PHP. These developers will likely use one of the major frameworks/platforms (Laravel/Symfony/Wordpress/Magento etc.) and will be a powerful tool in your company's arsenal as long as they don't have to step of the comfort of their knowledge.&lt;/p&gt;

&lt;p&gt;Some of the main risks of the new-school developer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Knowledge is usually tied to one framework/platform. Likes to avoid and often shows negative attitude to other tools available.&lt;/li&gt;
&lt;li&gt;With frameworks like Laravel handling large amount of sanitation (through templating &amp;amp; PDO) is likely to not know to deal with security risks as they are always handled by the framework.&lt;/li&gt;
&lt;li&gt;Usually has less experience and can lead to functionality not matching requirements perfectly or required time may be underestimated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the strengths of new-school developer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Knows a framework very well and prefers usage of external libraries to build functionality quicker.&lt;/li&gt;
&lt;li&gt;On overall can be quicker as doesn't need to build functionality from scratch, knows the tools and doesn't consider security on every step taken.&lt;/li&gt;
&lt;li&gt;Is more fond of the new techniques like Test Driven Development and package building.&lt;/li&gt;
&lt;li&gt;Can bring a new and fresh perspective into a company.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So with these two contrasting developer types which is the right one? That largely would depend what kind of developer you need/want to be. For what I've seen in my work there needs to be a mix of both. Old-school developers can achieve this by encouraging new technologies, "keeping the finger on the pulse" to ensure they don't settle into their ways too much. New-school developers need to encourage diversity of frameworks, learn not only about what they are skilled in but also branch out into other frameworks/platforms. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Where do I consider myself in this? I would probably call myself an old-school developer by heart. But to ensure I don't settle in too deep I spend a lot of time deep-diving into frameworks like Laravel and its underlying Symfony features. I build complex functionality like search filters and shopping baskets in vue.js. I try to ensure I keep learning and growing my skill-set.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>growth</category>
      <category>learning</category>
      <category>agency</category>
    </item>
    <item>
      <title>Hello Symfony QuestionHelper, hello undocumented features</title>
      <dc:creator>Martins Fridenbergs</dc:creator>
      <pubDate>Thu, 30 Jan 2020 15:09:47 +0000</pubDate>
      <link>https://dev.to/mafx/hello-symfony-questionhelper-hello-undocumented-features-3mdb</link>
      <guid>https://dev.to/mafx/hello-symfony-questionhelper-hello-undocumented-features-3mdb</guid>
      <description>&lt;p&gt;TL;DR - everyone is bad ad documenting functionality under the assumption that it is obvious.&lt;/p&gt;

&lt;p&gt;Over the last 2-3 months I've been (passively) looking for a piece of functionality in Laravel artisan console conversation tools - ability to ask a choice question with multiple answers. This hasn't been a priority, but something I've kept noticing and wondered why it isn't there.&lt;/p&gt;

&lt;p&gt;Background - I work in a web agency and a large point is the ability to start a new project quickly and efficiently - we are using a plug-and-play module structure and ability to install modules during initial project setup stage is a good feature to have. We already have a list of modules available from an API endpoint, so key aspect is to select ones you want. So what I want to achieve is a list of modules where you just navigate through with arrows and tick the ones you want to install.&lt;/p&gt;

&lt;p&gt;First attempt (few months ago) - Laravel has &lt;code&gt;choice()&lt;/code&gt; method where you can pass options and select which you want. But no mention of accepting multiple values in documentation and for some reason I've learned to gloss over function attributes from 4th onward. Tweeted asking if anyone knows about a package that does this and shelved it.&lt;/p&gt;

&lt;p&gt;Second attempt (few days ago) - started looking at this again and noticed few things. First of all - Laravel Command is Macroable so nothing stops me from building up a &lt;code&gt;multiChoice()&lt;/code&gt; method and injecting it into the Command class. But I also noticed that &lt;code&gt;choice()&lt;/code&gt; 5th attribute is &lt;code&gt;$multiple&lt;/code&gt;. Tried it out and indeed, if I enter the options &lt;code&gt;0,2&lt;/code&gt; they come up, yay.. or maybe not. Having to enter the options manually feels slow and maybe could be improved?&lt;/p&gt;

&lt;p&gt;Third attempt(today) - ok, without further inverstigation I wanted to start playing around and build up the &lt;code&gt;multiChoice()&lt;/code&gt; method. Laravel side is easy - with Marcroable I can quickly inject a method inside Command. The tricky bit comes down to how underlying input processing will work (this most likely would mean creating a pull request to Symfony project repos which actually makes me excited). &lt;/p&gt;

&lt;p&gt;Having done a few js framework installs and seeing how they tend to handle "checkbox" options in console I already imagined of handling space bar keystroke in multiple question scenario. Started diving through code until was inside Symfony QuestionHelper class. Strarted mocking around, quickly got to the point where I knew what I would need to do, but then I found out that the functionality I was looking for already existed via tab character instead of space. However it's not as intuitive as I'd like, so I'm torn - should I stop and just add a comment for users to understand the usage during usage or should I attempt to build up a functionality that might be declined when it gets to the PR review?&lt;/p&gt;

&lt;p&gt;Luckily I haven't spent too much time on this - maybe 2 or 3 hours in total. But these could've been 2-3 minutes if they were documented or made a bit more obvious. I've already submitted a PR to Laravel docs to add information about the multiple choice functionality. I've also learned how important is the documentation of functionality - even the minor details you see as obvious. This is why I'm aiming to revisit the documentation for the functionality my organisation has and ensure it is up to date and detailed.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>symfony</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
