<?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: MMJ</title>
    <description>The latest articles on DEV Community by MMJ (@mmj).</description>
    <link>https://dev.to/mmj</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%2F575193%2F4dfd1ccb-ca64-4239-b398-acf09cb8d0ab.jpeg</url>
      <title>DEV Community: MMJ</title>
      <link>https://dev.to/mmj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mmj"/>
    <language>en</language>
    <item>
      <title>From a HTML JS PHP Website to an Installable Desktop Application</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sun, 22 May 2022 14:29:25 +0000</pubDate>
      <link>https://dev.to/mmj/from-a-html-js-php-website-to-an-installable-desktop-application-1i41</link>
      <guid>https://dev.to/mmj/from-a-html-js-php-website-to-an-installable-desktop-application-1i41</guid>
      <description>&lt;p&gt;If you developed a website or a web app it’s &lt;strong&gt;very easy&lt;/strong&gt; to transform it in an &lt;strong&gt;installable desktop application&lt;/strong&gt;. Here’s how.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 1
&lt;/h2&gt;

&lt;p&gt;Go to this repo &lt;a href="https://github.com/cztomczak/phpdesktop"&gt;https://github.com/cztomczak/phpdesktop&lt;/a&gt; by &lt;strong&gt;Czarek Tomczak&lt;/strong&gt;, then search for downloads. As I’m working with Windows, I used &lt;strong&gt;PHP Desktop v57.0 for Windows&lt;/strong&gt; release (&lt;a href="https://github.com/cztomczak/phpdesktop/releases/tag/chrome-v57.0-rc"&gt;https://github.com/cztomczak/phpdesktop/releases/tag/chrome-v57.0-rc&lt;/a&gt;).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Download&lt;/strong&gt; the zip file and &lt;strong&gt;extract&lt;/strong&gt; the content wherever you want. Rename the folder as you prefer, you could use the name of your website. Let’s call it &lt;code&gt;Myapp&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
This is a sort of &lt;strong&gt;container&lt;/strong&gt; with a self-contained web server (&lt;strong&gt;Mongoose&lt;/strong&gt;) and &lt;strong&gt;PHP 7.1.3&lt;/strong&gt;.&lt;br&gt;
For example, launching the exe file called &lt;code&gt;phpdesktop-chrome.exe&lt;/code&gt; will “read” what’s inside the &lt;code&gt;Myapp/www&lt;/code&gt; folder. That’s where you will have to move your entire website to.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP 2
&lt;/h2&gt;

&lt;p&gt;Erase what’s inside &lt;code&gt;Myapp/www&lt;/code&gt; folder and copy there your entire website (don't put inside a sub folder). Be careful that any resource used in your website &lt;code&gt;should be available inside that folder&lt;/code&gt;, locally, or &lt;code&gt;available online&lt;/code&gt; if you don’t mind your desktop application will need internet connection to work. If, for example, you used CDNs, then your desktop application will not work properly without connection.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP 3
&lt;/h2&gt;

&lt;p&gt;Rename the &lt;code&gt;Myapp/phpdesktop-chrome.exe&lt;/code&gt; file, you can use the name of your application, let’s put &lt;code&gt;Myapp.exe&lt;/code&gt;&lt;br&gt;&lt;br&gt;
At this point I suggest &lt;strong&gt;testing the application&lt;/strong&gt; by double clicking on &lt;code&gt;myapp.exe&lt;/code&gt; and be sure everything works as expected. If you find some bugs due to the different environment you can &lt;strong&gt;debug&lt;/strong&gt; it as a normal website from that same window, inspecting it with devtool and working on the &lt;code&gt;Myapp/www&lt;/code&gt; folder files in your IDE.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP 4
&lt;/h2&gt;

&lt;p&gt;To make your website look like a &lt;code&gt;real desktop application&lt;/code&gt; you’ll need to change some of the main settings you can find in the &lt;code&gt;Myapp/settings.json&lt;/code&gt; file.&lt;br&gt;
The things I suggest you change are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Under debugging&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"show_console"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will prevent the debug console to opening&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Under main_window&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Application Name"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"icon"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"www/img/applicationicon.ico"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;These will change the window title and the icon of the application's window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"start_maximized"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because you may want to make the app start maximized and not in a small window.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Under chrome&lt;/strong&gt;:
Here there are some options about the enabling/disabling of devtool, f5 reloading and other browser related features you may want to be disabled, cause they look good on a website but not on a local application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP 5
&lt;/h2&gt;

&lt;p&gt;At this point we have a &lt;strong&gt;portable program to run&lt;/strong&gt;, we could in fact create a shortcut to the &lt;code&gt;Myapp.exe&lt;/code&gt; file, put it anywhere and all should work as an application. But that’s not the goal. We want an installable desktop application that anyone can install and run on pc.&lt;br&gt;&lt;br&gt;
To achieve that we need another tool: Inno Setup (&lt;a href="https://jrsoftware.org/isinfo.php"&gt;https://jrsoftware.org/isinfo.php&lt;/a&gt;).&lt;br&gt;
This is a free software that will transform our &lt;code&gt;Myapp&lt;/code&gt; folder into an installable .exe file.&lt;br&gt;
So, download and install this software &lt;a href="https://jrsoftware.org/isdl.php"&gt;https://jrsoftware.org/isdl.php&lt;/a&gt;&lt;br&gt;&lt;br&gt;
After installing, if the software didn't open automatically, open it and choose &lt;strong&gt;Create a new script using the Script Wizard&lt;/strong&gt; (that’s the simplest way to go), then click next.&lt;br&gt;
This wizard is pretty self-explanatory, I’ll just point out some details that could be tricky:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Application Files&lt;/strong&gt; page, you have to select you exe file in the first input (in our case &lt;code&gt;Myapp/Myapp.exe&lt;/code&gt;) and in the &lt;strong&gt;Other application files&lt;/strong&gt; click on &lt;strong&gt;Add folder&lt;/strong&gt; and choose the entire folder &lt;code&gt;Myapp&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Application File Association&lt;/strong&gt; page, uncheck the checkbox.&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Setup Install Mode&lt;/strong&gt; page, I suggest you to leave &lt;strong&gt;Administrative install mode&lt;/strong&gt; option checked or allow user to choose that (last checkbox).&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Compiler Settings&lt;/strong&gt; page, in the &lt;strong&gt;first input&lt;/strong&gt; select where you want the installer exe file will be created to, then select a &lt;strong&gt;name&lt;/strong&gt; for that file and choose its icon (that will be the icon for the shortcut too if you choose to create one).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;At the end&lt;/strong&gt;, a script will be generated, and you’ll be asked if you want to &lt;strong&gt;run&lt;/strong&gt; it immediately. You can do it right away and/or save the script and open it later with the same program then run it. I suggest &lt;strong&gt;saving&lt;/strong&gt; the script anyway: after trying your desktop application you may need to change something you forgot or that doesn’t work properly, so after making some changes in your code you’ll just have to rerun the same script saved, avoiding to make it from scratch through the wizard again. Either way, run the script.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After the script compiling&lt;/strong&gt;, you’ll find your installer exe file in the location you specified, and that’s it. This will work as any other desktop application ready to be installed: it will copy the entire folder &lt;code&gt;Myapp&lt;/code&gt; into programs path (or anywhere depending on the user choice and yours during the wizard setup) and create a shortcut where you want.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  CONCLUSIONS
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope this is helpfuls in some way and if you stayed with me so far, I thank you giving some more tips and a desktop application I created from my “The Hangman” web game (described here &lt;a href="https://dev.to/mmj/php-hangman-game-4b26"&gt;https://dev.to/mmj/php-hangman-game-4b26&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Downloadable Hangman game -&amp;gt; &lt;a href="https://bit.ly/3yR8D8j"&gt;https://bit.ly/3yR8D8j&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  SPECIAL TIPS
&lt;/h2&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  What if I need to change PHP version?
&lt;/h3&gt;

&lt;p&gt;If you need to change PHP version, you can download the version you need from here &lt;a href="https://www.php.net/downloads.php"&gt;https://www.php.net/downloads.php&lt;/a&gt;&lt;br&gt;
Once you downloaded that, you can extract into the php folder of the project deleting what was in it. That’s it.&lt;/p&gt;
&lt;h3&gt;
  
  
  What if my application needs a database?
&lt;/h3&gt;

&lt;p&gt;Nothing prevents you from using an external online DB as long as it is reachable, its configuration will let users connect to it and you are ok with a desktop application that needs internet to work. You could even serve APIs to do so.&lt;br&gt;
But if you need a portable DB inside the application, that will work locally and even without connection, you can use SQLite which is an embedded database that runs on the host machine storing everything on a single file, so it can lies inside the project folder itself.&lt;br&gt;
In order to use that I suggest you download SQLite browser (&lt;a href="https://sqlitebrowser.org/"&gt;https://sqlitebrowser.org/&lt;/a&gt;). This tool will help you managing your SQLite DB, creating tables, editing records, and run queries.&lt;br&gt;
If you already built a small website with a MySql database, chances are you just have to dumb your db, run query to create it with SWLite and change the connection type to the DB. The rest will work as it was or will need a slight refactoring.&lt;/p&gt;
&lt;h3&gt;
  
  
  What if used a .htaccess redirect to index.php for friendly URLs?
&lt;/h3&gt;

&lt;p&gt;It happened that the first website of mine I tried to transform in a desktop application had a very simple routing system based on the reroute to the index.php set in the .htaccess file (with Apache web server).&lt;br&gt;
Now, Mongoose doesn’t support .htaccess but you can manage the redirect to one page file within the settings.json of the project folder.&lt;br&gt;
You can set the index here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"index_files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"index.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.php"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And set the file redirection in case of not-found page here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"404_handler"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/index.php"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That should do the trick. But I had to add a little step cause I used this type of rewriting in the .htaccess&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight apache"&gt;&lt;code&gt;&lt;span class="nc"&gt;RewriteEngine&lt;/span&gt; &lt;span class="ss"&gt;on&lt;/span&gt;
&lt;span class="nc"&gt;RewriteCond&lt;/span&gt; %{REQUEST_FILENAME} !-f
&lt;span class="nc"&gt;RewriteCond&lt;/span&gt; %{REQUEST_FILENAME} !-d
&lt;span class="nc"&gt;RewriteRule&lt;/span&gt; ^(.*)$ index.php?q=$1 [NC,L,QSA]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which will let you grab the requested URL like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This of course did not work anymore, and I had to use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so to make it work both with Apache and Mongoose I did something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>application</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>PHP Hangman Game</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sat, 14 May 2022 15:54:11 +0000</pubDate>
      <link>https://dev.to/mmj/php-hangman-game-4b26</link>
      <guid>https://dev.to/mmj/php-hangman-game-4b26</guid>
      <description>&lt;p&gt;Hello to everyone.&lt;/p&gt;

&lt;p&gt;In these days I’ve found an old project of mine and I decided to give it some refactoring.&lt;br&gt;
It’s a very simple Hangman Game developed using PHP &amp;amp; JS.&lt;br&gt;
It can be played in English or in Italian and you can play against the PC, which will chose a random word you'll have to guess among 60 thousand for each language, or you can play it with a friend inserting a custom word.&lt;br&gt;
A working example is &lt;a href="https://bit.ly/3wd6fqs"&gt;HERE&lt;/a&gt;&lt;br&gt;
But there I’ve created a public GitHub repo too: &lt;a href="https://github.com/MasonMassyJames/hangman"&gt;Hangman Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback is welcome.&lt;/p&gt;

&lt;p&gt;Hope you enjoy 😊&lt;/p&gt;

</description>
      <category>php</category>
      <category>game</category>
      <category>dev</category>
      <category>ajax</category>
    </item>
    <item>
      <title>Collatz Conjecture Sequence API Generator</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Mon, 23 Aug 2021 16:32:15 +0000</pubDate>
      <link>https://dev.to/mmj/collatz-conjecture-sequence-api-generator-4ho3</link>
      <guid>https://dev.to/mmj/collatz-conjecture-sequence-api-generator-4ho3</guid>
      <description>&lt;p&gt;Hi everyone. In these days I want to practice building and consuming an API. So, I developed a very simple API that returns a &lt;strong&gt;Collatz Conjecture sequence&lt;/strong&gt; from a given number.&lt;br&gt;
Basically, we are talking about a numeric sequence following this rule: given a Natural number greater than 0 (any positive integer), if this is odd, the next number in the sequence will be 3 times the previous plus 1. If it’s even, the next number will be half the previous. The conjecture states that, no matters what the first number is, the sequence will end in a &lt;strong&gt;4-&amp;gt;2-&amp;gt;1 loop&lt;/strong&gt;.&lt;br&gt;
Everything is explained in detail on the website itself: &lt;strong&gt;&lt;a href="https://www.pgxstudio.com/collatzconjecture"&gt;pgxstudio.com/collatzconjecture&lt;/a&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;As stated in the documentation, this is meant to be an &lt;strong&gt;open API&lt;/strong&gt; but also an &lt;strong&gt;open-source free project&lt;/strong&gt;. The source code, under MIT Licence, is available here: &lt;strong&gt;&lt;a href="https://github.com/MasonMassyJames/CollatzConjecture"&gt;github.com/MasonMassyJames/CollatzConjecture&lt;/a&gt;&lt;/strong&gt;.&lt;br&gt;
Please feel free to use it, partially or wholly, as you need to. A link to the source and the reporting of author name is not required but appreciated.&lt;br&gt;
If you have any advice or correction about it or if you feel this documentation lacks something, I'll be glad to know.&lt;/p&gt;

&lt;p&gt;Here I’m going to paste the README so you can check the features and the usage.&lt;/p&gt;


&lt;h1&gt;
  
  
  Collatz Conjecture 
&lt;/h1&gt;
&lt;h2&gt;
  
  
  The API
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Introduction
&lt;/li&gt;
&lt;li&gt;  How It Works
&lt;/li&gt;
&lt;li&gt;  Output &amp;amp; Examples
&lt;/li&gt;
&lt;li&gt;  Errors
&lt;/li&gt;
&lt;li&gt;  Usage Tips &amp;amp; PHP Call Examples
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Introduction &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;I developed this website and its related API to practice. This&lt;br&gt;
is a very simple &lt;strong&gt;PHP REST API&lt;/strong&gt; working with a single URL and a single&lt;br&gt;
HTTP verb: GET. No authentication is required. The purpose is to provide&lt;br&gt;
a &lt;strong&gt;Collatz Conjecture sequence&lt;/strong&gt; from a starting number specified by&lt;br&gt;
the user in the request.&lt;/p&gt;

&lt;p&gt;Note: this application has a limit about the size of the starting number&lt;br&gt;
provided to generate the sequence and this size is less the size of the&lt;br&gt;
greatest number tested by mathematicians to disprove the Collatz&lt;br&gt;
Conjecture. Hence, no number supplied to this API will escape the final&lt;br&gt;
4-&amp;gt;2-&amp;gt;1 loop. Having said that, my goal was to create something quite&lt;br&gt;
realistic, even if only "virtually", therefore the limit size of the&lt;br&gt;
starting number can be easly changed and the logic used to build up the&lt;br&gt;
sequence is not "blinded" to just stop when the sequence hit "1" but is&lt;br&gt;
able to find ANY other loop could occur.&lt;/p&gt;


&lt;h2&gt;
  
  
  How It Works &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;The single endpoint of this API is&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET | https://pgxstudio.com/collatzconjecture/API/{startingNumber}/[limit]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Parameters specifications:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;{startingNumber}&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Required.&lt;/strong&gt; Must be a Natural number greater than zero (positive integer). This is the number the sequence calculation starts from.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;[limit]&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Optional.&lt;/strong&gt; Must be a Natural number (positive integer). If zero or no parameter is given, no limit is applied. If a valid number is given, the number sequence length is limited up to that number.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  Output &amp;amp; Examples
&lt;/h2&gt;

&lt;p&gt;For any request a JSON formatted reply is provided.&lt;/p&gt;

&lt;p&gt;Basing on the request, the response is a JSON with this info:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"status" : a string with value "ok" or "error" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plus this info if the request is valid and no error occurred:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"sequence" : a JSON holding the indexed number sequence 
"odd" : the number of odd numbers present in the sequence   
"even" : the number of even numbers present in the sequence   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Else this info if the request is invalid or an error occured:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"error_code" : the code number of the error (list of errors below)  
"message" : a string message related to the specific error occurred 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Example of successful request without limit parameter&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Request:&lt;/p&gt;

&lt;p&gt;GET | &lt;a href="https://pgxstudio.com/collatzconjecture/API/6"&gt;https://pgxstudio.com/collatzconjecture/API/6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Response:&lt;/p&gt;


&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"sequence"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"5"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"6"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"7"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"8"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt; 
       &lt;/span&gt;&lt;span class="nl"&gt;"odd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"even"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example of successful request with limit parameter&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Request:&lt;/p&gt;

&lt;p&gt;GET | &lt;a href="https://pgxstudio.com/collatzconjecture/API/6/4"&gt;https://pgxstudio.com/collatzconjecture/API/6/4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Response:&lt;/p&gt;


&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"sequence"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt; 
       &lt;/span&gt;&lt;span class="nl"&gt;"odd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"even"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example of failed request&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Request:&lt;/p&gt;

&lt;p&gt;GET | &lt;a href="https://pgxstudio.com/collatzconjecture/API/string"&gt;https://pgxstudio.com/collatzconjecture/API/string&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Response:&lt;/p&gt;


&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"error_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; 
       &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ERROR. Starting number must be a positive integer between 1 and 1000000000000."&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;



&lt;h2&gt;
  
  
  Errors&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here's the list of possible errors coming from API&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Error Code&lt;/th&gt;
&lt;th&gt;Message&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;"ERROR. Too many parameters in request."&lt;/td&gt;
&lt;td&gt;The GET URL used is passing other parameters besides the starting number and the limit.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;"ERROR. Too few parameters in request."&lt;/td&gt;
&lt;td&gt;The GET URL used is not passing the starting number.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;"ERROR. Starting number must be a positive integer between 1 and [MAX_STARTING_NUMBER]"&lt;/td&gt;
&lt;td&gt;The starting number parameter is passed but is not a positive integer or it is 0 or it is greater than the maximum number allowed (set in the &lt;code&gt;API/include/bootstrap.php&lt;/code&gt; and now is set to 1'000'000'000'000).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;"ERROR. Limit number be a positive integer."&lt;/td&gt;
&lt;td&gt;The limit parameter passed is not a positive integer.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;"ERROR. Unknown error. Something went wrong."&lt;/td&gt;
&lt;td&gt;Something got f*cked up somehere and I have no clue :(&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Source Code &amp;amp; Examples&lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Project tree&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2LdUac78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvp761gmel4drqhcivkh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2LdUac78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvp761gmel4drqhcivkh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the previous image you can see the complete project tree you will&lt;br&gt;
find in the github repo &lt;strong&gt;&lt;a href="https://github.com/MasonMassyJames/CollatzConjecture"&gt;github.com/MasonMassyJames/CollatzConjecture&lt;/a&gt;&lt;/strong&gt;. The application consuming the API is written in a functional-procedural style, while the API is an Object driven architecture. The JS client-side logic interpreting JSON and showing graphs lies in the scripts.js file. The API lies in the the omonym folder you can see in details in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--othjjQp---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3fxlbs0onjmdx3jk4hj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--othjjQp---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3fxlbs0onjmdx3jk4hj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, if you need just the API, all it takes is inside that folder, you&lt;br&gt;
can grab it and put it in your project. The API is built with its own&lt;br&gt;
.htaccess and even if you change the request like&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.yourwebsite.com/something/somethingelse/API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;it will work unless you change the name of the API folder. If you plan&lt;br&gt;
to change it just set it accordingly in &lt;strong&gt;API/include/bootstrap.php&lt;/strong&gt;&lt;br&gt;
and it will work again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;  &lt;span class="c1"&gt;// Define API folder name (used to ensure correctness&lt;/span&gt;
  &lt;span class="c1"&gt;// of request array no matter the url of the API is)&lt;/span&gt;
  &lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"API_FOLDER"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'API'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this same file you can set the MAX accepted number for the starting&lt;br&gt;
number.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Example of a PHP Call to the API&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;      &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;call_CC_API&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Build url: if no limit is set, &lt;/span&gt;
        &lt;span class="c1"&gt;// append only one parameter (url/$number/[$limit]) &lt;/span&gt;
        &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;BASE_API_URL&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$url&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nv"&gt;$curl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;curl_init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nb"&gt;curl_setopt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$curl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CURLOPT_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;curl_setopt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$curl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CURLOPT_RETURNTRANSFER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;curl_exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$curl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nb"&gt;curl_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$curl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function I passed the (previously checked) starting number and&lt;br&gt;
limit provided by the user. Then I built the URL string basing on the&lt;br&gt;
presence of the limit value. The BASE_API_URL is a constant defined at&lt;br&gt;
the beginning of the same file (function.php).&lt;/p&gt;

</description>
      <category>api</category>
      <category>php</category>
      <category>github</category>
    </item>
    <item>
      <title>Sharing Local Server with Local Network (XAMPP)</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sun, 13 Jun 2021 12:25:54 +0000</pubDate>
      <link>https://dev.to/mmj/sharing-local-server-with-local-network-xampp-3h83</link>
      <guid>https://dev.to/mmj/sharing-local-server-with-local-network-xampp-3h83</guid>
      <description>&lt;p&gt;In this simple step-by-step tutorial I’m gonna explain how to &lt;strong&gt;share a local server&lt;/strong&gt; (using XAMPP) with your local network in order to share DB, folders in httpdocs (local websites) and &lt;strong&gt;even start a XAMPP server on other machines running a local website that connects to a DB in the shared server&lt;/strong&gt;. That last feature was the most important for me to achieve because I needed to work with a teammate on the same project, each one on a local copy but both connected to the same DB, managing changes with a git repository on Github.&lt;br&gt;&lt;br&gt;
I found many similar tutorials online, but none was merging all I needed, so I decided to share my solution. Hope this can help even with different environment too.  &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;STEP 1 – Getting static IPs for your machines&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;That’s not mandatory, but it’s the easiest and safest way to go.&lt;br&gt;
There are many ways to do so and internet is full of good tutorials. &lt;br&gt;
Here’s a video: &lt;a href="https://bit.ly/3zrB8HA" rel="noopener noreferrer"&gt;https://bit.ly/3zrB8HA&lt;/a&gt; &lt;br&gt;
And here’s an article: &lt;a href="https://bit.ly/2So11HC" rel="noopener noreferrer"&gt;https://bit.ly/2So11HC&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;STEP 2 – Change some XAMPP settings&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After setting static IP addresses let’s make an example assuming we have a machine sharing its XAMPP (which I’ll name &lt;strong&gt;“server”&lt;/strong&gt; from now on) with IP &lt;strong&gt;192.168.1.10&lt;/strong&gt; and another machine that will connect to the server (which I’ll name &lt;strong&gt;“client”&lt;/strong&gt; from now on) with IP &lt;strong&gt;192.168.1.11&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You need to change some &lt;strong&gt;XAMPP&lt;/strong&gt; server configuration in the server machine. &lt;strong&gt;I suggest to make a backup copy of the files we are going to change.&lt;/strong&gt;&lt;br&gt;
To reach the files you need to change, click on the Apache Config button in the XAMPP Control Panel as the image shows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fise4buifid0ar65zni9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fise4buifid0ar65zni9m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FIRST CHANGE&lt;/strong&gt;: Now click on the &lt;strong&gt;httpd.conf&lt;/strong&gt; and look for the part where it says &lt;/p&gt;

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

# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here you have to add the local IP address of your “server”, in this example 192.168.1.10. So, we’ll have&lt;/p&gt;

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

# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
Listen 127.0.0.1:80
Listen 192.168.1.10:80 #(IP PC SERVER)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;SECOND CHANGE&lt;/strong&gt;: Open again the Apache Config button in the XAMPP Control Panel and click on &lt;strong&gt;httpd-xampp.conf&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Here we have to find where it says&lt;/p&gt;

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

    &amp;lt;Directory "C:/xampp/phpMyAdmin"&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We have to grant access, so we need to change it like this:&lt;/p&gt;

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

   &amp;lt;Directory "C:/xampp/phpMyAdmin"&amp;gt;
        AllowOverride AuthConfig
        Require all granted
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    &amp;lt;/Directory&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3 – Firewall Settings&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This can be different basing on your machine and firewall settings.&lt;br&gt;
Anyway, &lt;strong&gt;port 80 must be reachable&lt;/strong&gt; from client but not open for anybody from anywhere.&lt;br&gt;&lt;br&gt;
To achieve that I had to &lt;strong&gt;turn off a blocking rule and adding one to open port 80&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
To do so open your firewall configuration, in this example I use windows firewall: click on windows logo, type &lt;strong&gt;“firewall”&lt;/strong&gt; then press enter.&lt;br&gt;
In next window click on &lt;strong&gt;advanced settings&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Then click on &lt;strong&gt;Inbound rules&lt;/strong&gt; and look for a blocking rule (red prohibition sign) that says &lt;strong&gt;“Apache HTTP Server”&lt;/strong&gt;. If you find it, right click on it and choose &lt;strong&gt;disable&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
After that, staying on &lt;strong&gt;Incoming rules&lt;/strong&gt; section, click on &lt;strong&gt;New rule…&lt;/strong&gt; in the upright corner.&lt;br&gt;&lt;br&gt;
In each step of the wizard to create rule choose:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Custom&lt;/li&gt;
&lt;li&gt;  All programs&lt;/li&gt;
&lt;li&gt;  Protocol: TCP, Local port: Specific port – 80&lt;/li&gt;
&lt;li&gt;  Remote IP address: 192.168.1.11 (client machine)&lt;/li&gt;
&lt;li&gt;  Allow the connection&lt;/li&gt;
&lt;li&gt;  Uncheck Public&lt;/li&gt;
&lt;li&gt;  Give name and description + finish button&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzw62np90tuffw9y39ba1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzw62np90tuffw9y39ba1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3mm6i63bodfcv5goo2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3mm6i63bodfcv5goo2b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point if server machine starts XAMPP, the client &lt;strong&gt;can reach the server&lt;/strong&gt; using its browser using the url &lt;code&gt;http://192.168.1.10&lt;/code&gt; as it was on the server machine, so it &lt;strong&gt;can reach phpadmin and DBs&lt;/strong&gt; (&lt;code&gt;http://192.168.1.10/phpmyadmin&lt;/code&gt;) or &lt;strong&gt;any website in the htdocs folder&lt;/strong&gt; (&lt;code&gt;http://192.168.1.10/AnyLocalWebsiteFolder&lt;/code&gt;).&lt;br&gt;&lt;br&gt;
Anyway, it could be still &lt;strong&gt;impossible&lt;/strong&gt; for any machine to start its own XAMMP, open a local copy of the same project and connect it to the DB on the server machine.&lt;br&gt;&lt;br&gt;
To make it work, we need another step.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4 – Adding PhpMyAdmin Users&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We finally have to add a user with all privileges &lt;strong&gt;for each machine&lt;/strong&gt; (server included) in PhpMyAdmin, in our example we have to add &lt;strong&gt;&lt;code&gt;root@192.168.1.10&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;root@192.168.1.11&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now each machine can work freely on their local copy of the project, using a git versioning on a remote common repository, connecting on a single local DB on the server machine.&lt;br&gt;&lt;br&gt;
The snippet defining constants to build the connection will be the same for every machine  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;

    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HTTP_HOST'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HTTP_HOST'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;"192.168.1.10"&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="c1"&gt;// Local Development Server &lt;/span&gt;
      &lt;span class="nb"&gt;DEFINE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MASTER_BASE_URL'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'http://localhost'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

      &lt;span class="nb"&gt;DEFINE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DB_USER'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;DEFINE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;DEFINE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'192.168.1.10'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;DEFINE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'DB_NAME'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'db_name'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Client machine(s) will run its XAMPP working on its local copy and checking the results on its local &lt;code&gt;http://localhost/LocalWebsiteFolder&lt;/code&gt;, but connection will be correctly set on the server DB.&lt;/p&gt;

&lt;p&gt;I'm aware that there could be many other ways to achive what I've described, if you know any and you think it's even easyer, please let me know. This is just the solution I came up with after smashing my head to the wall countless times.&lt;br&gt;
Anyway, I hope it helps.&lt;/p&gt;

</description>
      <category>xampp</category>
      <category>github</category>
      <category>sharing</category>
      <category>server</category>
    </item>
    <item>
      <title>Is coding kind of like making art?</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sat, 29 May 2021 10:54:12 +0000</pubDate>
      <link>https://dev.to/mmj/is-coding-kind-of-like-making-art-220h</link>
      <guid>https://dev.to/mmj/is-coding-kind-of-like-making-art-220h</guid>
      <description>&lt;p&gt;I usually ask myself questions about the most trivial things. Among these there is also investigating why I like a given thing or why I don’t.&lt;br&gt;
I have often wondered why I like coding and, writing music since I was a teenager, I think I have identified several things that these two have in common.&lt;/p&gt;

&lt;p&gt;The first similarity I found is that inspiration is needed. Although it seems counterintuitive for those unfamiliar with the world of coding, inspiration is a very important help. In music is even essential. The inspiration you need to fix a bug and the one you need to complete a chorus are really very similar because the two draw on both experience and creativity.&lt;/p&gt;

&lt;p&gt;Creativity is another aspect in common as well as the fluctuating state that can affect: many times, in both writing music and coding, a person can feel stuck, without creativity, remaining unproductive for a long time, even ending up thinking that he/she is not made to continue writing code or music, while other times creativity flows copiously, and he/she becomes extremely productive.&lt;/p&gt;

&lt;p&gt;In addition to inspiration and creativity, in writing music and coding you need to know how to get out of the lines and know how to adapt, to improvise, but always staying within the rules because, if you violate the basic rules, in music you’ll get a note out of tune or something unlistenable, while in coding... well, I certainly don't have to specify what happens.&lt;/p&gt;

&lt;p&gt;Furthermore, both for music and for coding, you need to study and practice a lot, you need to learn and execute. In both cases discipline and repetition (even boring) of the basics is necessary but all this is still fun and rewarding if you have passion. Here, even passion is an element in common: if you write music or code, you need passion, otherwise... it shows.&lt;/p&gt;

&lt;p&gt;Finally, when you complete a large section of code or a song you get a great satisfaction: I clearly feel a “completeness” feeling, having created something of my own and that works as I imagined.&lt;/p&gt;

&lt;p&gt;So, is coding like making art? No, it is certainly not the same thing because they are very different in a lot of aspects but, as I have described, they have some interesting similarities.&lt;br&gt;
Do you agree with my thinking? Is there any other similarity I missed? &lt;/p&gt;

</description>
      <category>art</category>
      <category>coding</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Accessors in Laravel - quick view with example</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sun, 28 Mar 2021 12:02:01 +0000</pubDate>
      <link>https://dev.to/mmj/accessors-in-laravel-quick-view-with-example-2og3</link>
      <guid>https://dev.to/mmj/accessors-in-laravel-quick-view-with-example-2og3</guid>
      <description>&lt;p&gt;First thing first: what’s an &lt;strong&gt;accessor&lt;/strong&gt;?&lt;br&gt;
An accessor is a &lt;strong&gt;custom method&lt;/strong&gt; we can create inside a model and that can get and manipulate an attribute of that model. Its result can be a new attribute of that model or “substitute” an existing one.&lt;/p&gt;

&lt;p&gt;Real case scenario: for instance, if we have a model mapping to an “album” table that has a “thumb” field in which the name of its thumbnail is stored. When we retrieve that value and put it in the src of a img tag, it can be annoying to build the path and then print that value at the end, especially if we have a lot of images.&lt;/p&gt;

&lt;p&gt;We can build our accessor that creates a new attribute of that model and that will return the complete url for us. The name of the method must be built in this way: &lt;strong&gt;get{Name}Attribute&lt;/strong&gt;. The “Name” can be what you want but if you use the name of the album’s field you are retrieving, the value of the field will be automatically passed.&lt;br&gt;
So, in the album model we can write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getPathAttribute&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'pathToThumbsFolder/'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;thumb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or using the field name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getThumbAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'pathToThumbsFolder/'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we have an instance of an album, this accessor will let us write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$album&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;thumb&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where we want to get or print the full url to the thumbnail.&lt;br&gt;
Of course, we can set that path in the .env file and use something like env('ALBUM_THUMB_DIR') as path in this method.&lt;/p&gt;

&lt;p&gt;Further example: it can help building an if statement to show a default image if album has no thumbnail make the html code cleaner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getThumbAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="s1"&gt;'pathToThumbsFolder/'&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="s1"&gt;'pathToDefaultImage/default.jpg'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This can be very helpful, save a lot of code and make it cleaner because every time you need to retrieve a value manipulating it first you have only one place to do it and possibly change it later.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>coding</category>
      <category>example</category>
    </item>
    <item>
      <title>Can you still save your soul?</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Wed, 03 Mar 2021 18:54:05 +0000</pubDate>
      <link>https://dev.to/mmj/can-you-still-save-your-soul-3pec</link>
      <guid>https://dev.to/mmj/can-you-still-save-your-soul-3pec</guid>
      <description>&lt;p&gt;Have you ever thought about how to clean your soul? Now there is someone who can do it for you. Find out how much time you have left before it's too late.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kF4DdXAo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6o8m6hk187jatjo5unr9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kF4DdXAo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6o8m6hk187jatjo5unr9.png" alt="soul reforger"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No. I don't think such things exist but, who knows? &lt;br&gt;
Just a small landing page I made for fun :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.pgxstudio.com/dev/soulreforger/"&gt;Take a look&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/MasonJamesDev/pen/wvoXyQK"&gt;Watch it on Codepen&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>html</category>
      <category>landingpage</category>
    </item>
    <item>
      <title>JFF - Who are these guys?</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Wed, 24 Feb 2021 17:36:38 +0000</pubDate>
      <link>https://dev.to/mmj/jff-who-are-these-guys-453g</link>
      <guid>https://dev.to/mmj/jff-who-are-these-guys-453g</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5n3w-mh6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73z4ag9hc9bklpnmgujb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5n3w-mh6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73z4ag9hc9bklpnmgujb.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;No code was harmed in the writing of this post&lt;/em&gt;&lt;/p&gt;

</description>
      <category>jff</category>
      <category>justforfun</category>
    </item>
    <item>
      <title>A Dice Game... as it was then and as it is now #reviewyourself</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sun, 21 Feb 2021 14:26:00 +0000</pubDate>
      <link>https://dev.to/mmj/a-dice-game-as-it-was-then-and-as-it-is-now-reviewyourself-p75</link>
      <guid>https://dev.to/mmj/a-dice-game-as-it-was-then-and-as-it-is-now-reviewyourself-p75</guid>
      <description>&lt;p&gt;A few days ago, I found an old folder on my pc that dates to the time when I was starting to study web development.&lt;br&gt;
Inside this folder I found an exercise I made up to practice which consisted in developing a dice game for two players.&lt;br&gt;
Obviously, it's a very simple code, but looking back at it I was surprised the way I developed it and I realized how different I am now both as a developer and as a person.&lt;br&gt;
The interesting thing, as well as revealing the use of bad practices, was reviewing the logic with which I faced problems and found solutions, following paths that I hardly recognize as "mine".&lt;br&gt;
So, I decided to put on codepen both that old version of the game and a new developed version as I would develop it now, leaving the frontend scaffolding intact, changing only the JS logic.&lt;br&gt;
I did this just for fun as now, being a backend developer, that’s not what I’m focused on, but I think this can be a good exercise in general and can help to understand yourself, looking from the outside and observing your own path to improve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#reviewyourself&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you get inspired from this and post something alike, please use the same hashtag and let me know in the comment section :)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here are the two versions of the game:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/MasonJamesDev/pen/XWNerJW"&gt;Old Version&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/MasonJamesDev/pen/LYbzYbr"&gt;New Version&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reviewyourself</category>
      <category>javascript</category>
      <category>game</category>
      <category>develop</category>
    </item>
    <item>
      <title>The struggle of faking data</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sat, 13 Feb 2021 15:17:50 +0000</pubDate>
      <link>https://dev.to/mmj/the-struggle-of-faking-data-2na6</link>
      <guid>https://dev.to/mmj/the-struggle-of-faking-data-2na6</guid>
      <description>&lt;p&gt;Who must test applications by creating fake data for invented users can often get through the day with a serious &lt;strong&gt;lack of imagination&lt;/strong&gt;.&lt;br&gt;
Of course, we often work with frameworks or libraries that offer tools to, for example, &lt;strong&gt;populate DBs&lt;/strong&gt; with very realistic data. But other times to test small applications you have to rely on the imagination only. This can be annoying and can also affect the speed of work at times.&lt;br&gt;
For these cases and to avoid entering names like John Doe, Foo, Asd or even 123, I point out one of the many sites that &lt;strong&gt;creates fake data for free&lt;/strong&gt;.&lt;br&gt;
This one is very complete: it gives you even coordinates, zodiac sign, credit card data, etc. and let you choose many options like nationality, age range and so on. Hope it will be useful :)&lt;br&gt;
If you know similar websites feel free to suggest me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.fakenamegenerator.com/advanced.php"&gt;Fake Name Generator&lt;/a&gt;&lt;/p&gt;

</description>
      <category>fakedata</category>
      <category>advice</category>
      <category>database</category>
      <category>data</category>
    </item>
    <item>
      <title>Generate a unique random code to store in DB</title>
      <dc:creator>MMJ</dc:creator>
      <pubDate>Sun, 07 Feb 2021 16:01:24 +0000</pubDate>
      <link>https://dev.to/mmj/generate-a-unique-random-code-to-store-in-db-23ne</link>
      <guid>https://dev.to/mmj/generate-a-unique-random-code-to-store-in-db-23ne</guid>
      <description>&lt;p&gt;In this post I will show one of the methods I usually choose to generate unique random code.&lt;/p&gt;

&lt;p&gt;First, the function that will return the string code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;generateCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nv"&gt;$chars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'0123456789ABCDEFGHIJKLMNOPQRSTUVZYabcdefghijklmnopqrstuvwxyz'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;$code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str_shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$chars&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;EXPLAN: A very simple function that accept an integer as attribute which will be the length of our code, in this case if the legth is not given, a 10 is passed by default.&lt;br&gt;
Then we set a string of characters we want to be used to build our code.&lt;br&gt;
Then the code itself is built by shuffling the string and get a substring from the first character as long as indicated by the int we pass in the function.&lt;/p&gt;

&lt;p&gt;For this to be unique, we can search the table we want to interact with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;      &lt;span class="c1"&gt;// Generate + update code&lt;/span&gt;
      &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Generate code&lt;/span&gt;
        &lt;span class="nv"&gt;$code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generateCode&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Loop to search for an identical code, if found generate another one&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT count(id) from tablename where code = ?"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bind_param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_result&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$row_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetch_row&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$row_code&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// Update record&lt;/span&gt;
      &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$conn&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"UPDATE tablename SET code = ? WHERE id = ?"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;bind_param&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"si"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;EXPLAN: with a do-while we can call the function and get a first-try code. Then we search for it in the table with a select. In the while we check if the result is different from zero (the code already exists). If it exists, the loop will keep running and create codes until a really brand new one is created. Then the code will exit the loop and we can do something with this unique code, maybe update an existing record.&lt;/p&gt;

&lt;p&gt;Of course, the shorter are the codes and the fewer are the characters used to build them, the higher will be the risk to have a very long and resources sucking code. &lt;/p&gt;

&lt;p&gt;If you have any suggestion or correction about this, I'll be glad to hear about it.&lt;/p&gt;

</description>
      <category>php</category>
      <category>randomcode</category>
      <category>unique</category>
    </item>
  </channel>
</rss>
