<?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: Ricardo Sawir</title>
    <description>The latest articles on DEV Community by Ricardo Sawir (@ricardosawir).</description>
    <link>https://dev.to/ricardosawir</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%2F521352%2F5bec59de-9c04-415b-beaf-f4c159ac6d19.png</url>
      <title>DEV Community: Ricardo Sawir</title>
      <link>https://dev.to/ricardosawir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ricardosawir"/>
    <language>en</language>
    <item>
      <title>Tutorial: Sorting ~1761 subreddits to see which subreddits are popular</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Thu, 14 Jan 2021 01:40:48 +0000</pubDate>
      <link>https://dev.to/ricardosawir/tutorial-sorting-1761-subreddits-to-see-which-subreddits-are-popular-ifg</link>
      <guid>https://dev.to/ricardosawir/tutorial-sorting-1761-subreddits-to-see-which-subreddits-are-popular-ifg</guid>
      <description>&lt;p&gt;Hi, I am researching of subreddits to make my next product. I want to get an overview of how I sort subreddits.&lt;/p&gt;

&lt;p&gt;This will use vanilla JS.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. grab the subreddits data from here &lt;a href="https://pastebin.com/XVBDM4jn"&gt;https://pastebin.com/XVBDM4jn&lt;/a&gt; (copy the raw paste data)
&lt;/h2&gt;

&lt;p&gt;Copy the json data to your html code like this (and don't forget to parse it)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;json_subreddits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`//the copy pasted json data`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. We need to sort the subreddits from most popular to least popular. We need to use sort() function.
&lt;/h2&gt;

&lt;p&gt;But the problem is our data is an object, and not an array.&lt;br&gt;
To convert it, we need to iterate the object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;json_subreddits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`the copy pasted json data`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sortable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;subreddits&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;json_subreddits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;subreddits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;subreddits&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;now we have an array&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Use sort function
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;json_subreddits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`the copy pasted json data`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sortable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;subreddits&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;json_subreddits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;subreddits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;subreddits&lt;/span&gt;&lt;span class="p"&gt;]]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;sortable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;b&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="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&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="c1"&gt;// this will return from big to small. to inverse it, just switch the a and b&lt;/span&gt;
&lt;span class="c1"&gt;// return a[1] - b[1];&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Console.log(sortable) to see the result
&lt;/h2&gt;

&lt;p&gt;And you can view subreddits in your console. Enough to give you which subreddits are popular and which are least popular.&lt;/p&gt;

&lt;p&gt;If you like this, you can follow my journey live on Twitter &lt;a href="https://twitter.com/RicardoSawir"&gt;https://twitter.com/RicardoSawir&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Here's how I make app fast yet flexible to extend. Suitable for those who want to ship app fast (Suitable for any langs)</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Mon, 04 Jan 2021 01:58:42 +0000</pubDate>
      <link>https://dev.to/ricardosawir/here-s-how-i-make-app-fast-yet-flexible-to-extend-suitable-for-those-who-want-to-ship-app-fast-suitable-for-any-langs-5bm1</link>
      <guid>https://dev.to/ricardosawir/here-s-how-i-make-app-fast-yet-flexible-to-extend-suitable-for-those-who-want-to-ship-app-fast-suitable-for-any-langs-5bm1</guid>
      <description>&lt;p&gt;I wrote SingleFile App&lt;/p&gt;

&lt;p&gt;This is how I built apps fast in a single file. You're free to modify how it should be done.&lt;/p&gt;

&lt;p&gt;Some examples I built with this file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hnanalytics.sawirstudio.com"&gt;https://hnanalytics.sawirstudio.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://kolapedia.com"&gt;https://kolapedia.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://typecatch.com"&gt;https://typecatch.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://hampersy.com"&gt;https://hampersy.com&lt;/a&gt;&lt;br&gt;
&lt;a href="https://christmas2020.sawirstudio.com"&gt;https://christmas2020.sawirstudio.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on Twitter for feedbacks or live updates &lt;a href="https://twitter.com/RicardoSawir"&gt;https://twitter.com/RicardoSawir&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See the repository here: &lt;a href="https://github.com/sawirricardo/singlefileapp"&gt;https://github.com/sawirricardo/singlefileapp&lt;/a&gt;&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="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;// 1. uncomment if you want to turn on your error&lt;/span&gt;
&lt;span class="c1"&gt;// error_reporting(E_ALL);&lt;/span&gt;

&lt;span class="c1"&gt;// 2. define your ABSPATH here. It's your choice you want to place this in root or in a 'public' folder&lt;/span&gt;
&lt;span class="c1"&gt;// this assume you put index.php in your public folder&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;'ABSPATH'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__DIR__&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// ucomment if you use composer/3rd party vendor&lt;/span&gt;
&lt;span class="c1"&gt;// include_once join(DIRECTORY_SEPARATOR, [ABSPATH, 'vendor', 'autoload.php']);&lt;/span&gt;

&lt;span class="c1"&gt;// you can include other files here if you want&lt;/span&gt;

&lt;span class="nf"&gt;run_app&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="cd"&gt;/**
 * Main App process happening here
 * @author Ricardo &amp;lt;sawir.ricardo@gmail.com&amp;gt;
 * @author Follow me on Twitter for feedback or live updates https: //twitter.com/RicardoSawir
 *
 * @return void
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;run_app&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//you can also initialize session here&lt;/span&gt;
    &lt;span class="nv"&gt;$arr_route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;explode&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;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parse_url&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="kc"&gt;PHP_URL_PATH&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="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;'REQUEST_METHOD'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&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;$arr_route&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="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// handle index here&lt;/span&gt;
            &lt;span class="nf"&gt;controller_get_index&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;//examples you can use to access other route&lt;/span&gt;
        &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr_route&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="s1"&gt;'about'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// handle /about&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr_route&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="s1"&gt;'contact'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//handle /contact&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// by the way, you can also add route for /api here&lt;/span&gt;
        &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr_route&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="s1"&gt;'api'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;// we need to handle assets here, else you cannot access assets&lt;/span&gt;
        &lt;span class="c1"&gt;// (I assume you use folder named 'assets')&lt;/span&gt;
        &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr_route&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="s1"&gt;'assets'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;controller_get_assets&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;span class="nf"&gt;controller_get_404&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="c1"&gt;//or die ('404');&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;elseif&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_METHOD'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// handle your post request here&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// if you want to include other request method like DELETE/PUT/PATH&lt;/span&gt;
    &lt;span class="k"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;controller_get_404&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// handle view&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;render_header&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;render_footer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;controller_get_assets&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$arr_route&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&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;ltrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parse_url&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="kc"&gt;PHP_URL_PATH&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;unset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$arr_route&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;$arr_route&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;$str_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$arr_route&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$name&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DIRECTORY_SEPARATOR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;ABSPATH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'public'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'assets'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$str_path&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nv"&gt;$fp&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'rb'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// send the right headers&lt;/span&gt;
    &lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type: image/png"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Length: "&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;filesize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// dump the picture and stop the script&lt;/span&gt;
    &lt;span class="nb"&gt;fpassthru&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;controller_get_index&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// handle view&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;render_header&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// I name this render_index just to follow the name convention. If your controller is controller_get_random_name, then I suggest you name render_random_name. Just to make things more easy to organize later.&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;render_index&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;render_footer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

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

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;render_index&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;ob_start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;ob_get_clean&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;render_header&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;ob_start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;ob_get_clean&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;render_footer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;ob_start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;ob_get_clean&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;



</description>
      <category>php</category>
      <category>programming</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I built a font pairing generator</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Fri, 18 Dec 2020 10:33:54 +0000</pubDate>
      <link>https://dev.to/ricardosawir/i-built-a-font-pairing-generator-1gd8</link>
      <guid>https://dev.to/ricardosawir/i-built-a-font-pairing-generator-1gd8</guid>
      <description>&lt;p&gt;&lt;a href="http://typecatch.com"&gt;http://typecatch.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>design</category>
    </item>
    <item>
      <title>How To Build A Tiny App/Product - The Tech Stacks And Tips I learned</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Fri, 04 Dec 2020 03:25:05 +0000</pubDate>
      <link>https://dev.to/ricardosawir/how-to-build-a-tiny-app-product-the-tech-stacks-and-tips-i-learned-1f7</link>
      <guid>https://dev.to/ricardosawir/how-to-build-a-tiny-app-product-the-tech-stacks-and-tips-i-learned-1f7</guid>
      <description>&lt;p&gt;Hi friends, today I want to talk about building tiny apps. During this pandemic, I have built some kind of 1 day 1 product, although I didn't intend to blast it as a hashtag #1day1product or #1day1app or whatever you would like to call it 😁&lt;/p&gt;

&lt;p&gt;Not long ago, I started Ask HN in Hacker News Forum asking if &lt;a href="https://news.ycombinator.com/item?id=25285289"&gt;can we sell tiny products?&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And there are a number of people who participated the discussions which gives me a hint to probably talk a bit more about making a tiny product/app.&lt;/p&gt;

&lt;p&gt;(And also I want to thank you for the kindness of the members there, they are kind to share what they thought and some gems. I feel humbled by the community's generosity.)&lt;/p&gt;

&lt;p&gt;So, let's discuss A Tiny app, shall we?&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a tiny app/product/game?
&lt;/h1&gt;

&lt;p&gt;Usually from my perspective, it is &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a one page app/game/info (if you are making an info product), &lt;/li&gt;
&lt;li&gt;you can use it directly without those sign-in page. (it may differ depending on your industry)&lt;/li&gt;
&lt;li&gt;you can get something out of it.&lt;/li&gt;
&lt;li&gt;(Optional) Only ask for 1 input, why would you put more inputs if you can put 1?&lt;/li&gt;
&lt;li&gt;(Optional &amp;amp; relative) You can build the tiny product in considerably short time (Less than 24 hrs to less than 1 week to less than 1 month maximum)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You may say, "That's an MVP, bro". And yes, you are correct. But I would argue MVP is also a product. But may be not so solid, still contains bugs, and so on. But we're not going to talk that here.&lt;br&gt;
Those are my opinions, if you have other opinions, you can comment below or have a discussion with me on My Twitter &lt;a href="https://twitter.com/RicardoSawir"&gt;@RicardoSawir&lt;/a&gt; or if you prefer by email, you can reach me out at &lt;a href="mailto:sawir.ricardo@gmail.com"&gt;sawir.ricardo@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During this pandemic, I have built these apps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://sawirricardo.itch.io/stay-off-please"&gt;~March'20 - Stay Off Please Game - Inspired from lock down&lt;/a&gt; - A mini game I built, If I'm not mistaken, it was made in &amp;lt;24 hrs including watching tutorials about Unity.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lol.sawirstudio.com/"&gt;~April'20 LOL Product. I made this inspired by Card Against Humanity, But I changed the answers with HN's articles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://rosario.sawirstudio.com/"&gt;~May'20 Rosary Prayer&lt;/a&gt; - It's  made HTML basically. It helps when people want to livestream prayer with their OBS App and just screen share this web so people could follow along, hence the giant font size.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://hn.sawirstudio.com/"&gt;~June'20 Hacker News, but with 3 sections of Top, Best, New Stories side by side &lt;/a&gt; - It's HTML and with Axios to help with HTTP Client.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fasticon.sawirstudio.com/"&gt;~August'20 FastIcon – Generate Icons for your mobile app with ease&lt;/a&gt; - I'm starting to use PHP for faster development.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://deeperingod.com/"&gt;~Early November'20 Deeper In God - An app to record 'rhema'/notes while reading bible&lt;/a&gt; - It may not fall into tiny, but rather small to medium app, built in 2-4 days if I'm not mistaken. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://apionly.sawirstudio.com/"&gt;~November'20 API Only Website&lt;/a&gt; - It is an API Only web. Really fun playing with returning JSON.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gum.co/EKmSuE"&gt;November'20 I make a tutorial about building login form with PHP - A screencast&lt;/a&gt; First time screencasting myself coding.&lt;/li&gt;
&lt;li&gt;[~Mid Novemeber'20 My Subscription Form][&lt;a href="https://subscribe.sawirstudio.com"&gt;https://subscribe.sawirstudio.com&lt;/a&gt;] - I build my own subscribe form.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gum.co/50phpcode"&gt;November'20 I create an ebook about 50 Useful Tips using PHP&lt;/a&gt; There's also a write up here in Dev.to - &lt;a href="https://dev.to/ricardosawir/9-useful-php-tips-and-code-snippets-that-get-the-jobs-done-1he5"&gt;9 useful php tips and code snippets that get the jobs done&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gum.co/34fastmvp"&gt;November'20 I also create an ebook about 34 design tips to apply&lt;/a&gt; - There's also a write up - &lt;a href="https://ricardosawir.medium.com/5-tactics-in-typography-and-design-that-can-help-you-ship-your-mvp-fast-and-good-for-indie-hackers-8d2bd2002804"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://hnanalytics.sawirstudio.com/"&gt;~Latest November'20 HN Analytics&lt;/a&gt; - I started to be more active in HN communities. I think if I want to nominate the most successful tiny product, I would vote for this. This one gets the most exposure to me.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Probably, there are more. But I could only note down this 12 tiny products based on my memory 😁.
&lt;/h2&gt;

&lt;p&gt;Now, let's discuss what tech stacks I used to build those.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I use mostly index.html and axios. It mostly done the job. especially if you are looking to host in static site. (like Netlify/Github).&lt;/li&gt;
&lt;li&gt;I have a shared hosting. Cheap. But good enough to validate my ideas and products. I usually copy/paste my local code to the production server code. (Not even with FTP 😅). I think that is fast enough.&lt;/li&gt;
&lt;li&gt;I use PHP if I need to handle logic. The HN Analytic contains a little PHP code, to parse the input logic. However in my opinion, PHP still excel in shipping fast and tiny product. I don't use framework for this. I will discuss about how I structure my tiny app project. (Spoiler: it's almost just an index.php!)&lt;/li&gt;
&lt;li&gt;Fortunately, My shared hosting provides &lt;strong&gt;MySQL&lt;/strong&gt; Database, so I use that. Easy connect with PDO. I use database usually to contain my subscribe form. Some of the apps mentioned above also use &lt;strong&gt;SQLite3&lt;/strong&gt; Database, if possible.&lt;/li&gt;
&lt;li&gt;App feels an app when you show modal (agree? no? 😅 comment below, then! hehe). I use &lt;a href="https://sweetalert2.github.io"&gt;Sweet Alert 2&lt;/a&gt;. Fast, good, and solid.&lt;/li&gt;
&lt;li&gt;CSS, I use mostly &lt;a href="https://tailwindcss.com"&gt;TailwindCSS&lt;/a&gt; and their Tailwind UI. Free, and I like it. Simple and help me fast to get start. You can also use &lt;a href="https://getbootstrap.com"&gt;Bootstrap&lt;/a&gt;, but I probably want to wait for their version 5 (as of this writing, their version is 4.5 latest).&lt;/li&gt;
&lt;li&gt;I use &lt;a href="https://datatables.net"&gt;DataTable&lt;/a&gt; if I need to show tables (HN Analytic uses it). That means I will also use jQuery.&lt;/li&gt;
&lt;li&gt;For dropdowns/accordions, I use &lt;a href="https://github.com/alpinejs/alpine"&gt;alpinejs&lt;/a&gt; (They have an example plus built in tailwind example) so if I ever need dropdown, I would just include alpine js script.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, without I realize it, the tech stacks here are for web apps. Do you have other not mentioned here? Comment below or tweet me some ideas, would love to here from you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now I want to share some of the tips I learned. (works for me at least 😋)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;I don't separate javascript and css. I just include it with HTML. Somehow, I can better debug it when things go wrong and not have to click css/js files just to fix it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;&lt;span class="c"&gt;/** Hello CSS **/&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;span class="c1"&gt;// Hello JS. Usually I put axios here&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yea, that looks more like it.&lt;br&gt;
How about you?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I use index.php. a single file is all I need. (again it depends).
PHP code on top, then below is the HTML code. I would take a &lt;a href="https://github.com/PHPMailer/PHPMailer/blob/master/examples/simple_contact_form.phps"&gt;PHPMailer example here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;I want to remind you, do basic security for your apps by putting your index.php/html into your "public" folder (especially if you are working with PHP). And point your server to /public path.
This will help you to prevent hacker accessing forbidden files, such as your database sqlite.
You also don't need to spam .htaccess or web.config to forbidden access.
Here are an example from &lt;a href="https://github.com/laravel/laravel/tree/8.x/public"&gt;Laravel Repository public folder&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;If you make a non app product, you may consider to use no-code if possible. I use &lt;a href="https://www.notion.so/"&gt;Notion&lt;/a&gt; for my ebook, and &lt;a href="https://gumroad.com"&gt;Gumroad&lt;/a&gt; to receive the payment.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;I am going to continue documenting about tiny app/product (may be also other things not related with this, who knows?) and share what I find useful to the community. &lt;/p&gt;

&lt;p&gt;Do you have other opinions or something in mind? I would like to hear from you.&lt;/p&gt;

&lt;p&gt;If you like this article, you can &lt;a href="https://twitter.com/RicardoSawir"&gt;follow me&lt;/a&gt; as I document my journey mostly there.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>productivity</category>
      <category>php</category>
      <category>programming</category>
    </item>
    <item>
      <title>My Formula in naming functions (Applicable in any programming languages)</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Mon, 30 Nov 2020 04:36:29 +0000</pubDate>
      <link>https://dev.to/ricardosawir/my-formula-in-naming-functions-applicable-in-any-programming-languages-4900</link>
      <guid>https://dev.to/ricardosawir/my-formula-in-naming-functions-applicable-in-any-programming-languages-4900</guid>
      <description>&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--E3CqPEh1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1116645238611697665/YNgcU2a9_normal.png" alt="Ricardo Sawir profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Ricardo Sawir
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/ricardosawir"&gt;@ricardosawir&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      My formula in naming a function:&lt;br&gt;function filename_whatItIsabout_whatItDoes(some arguments) { &lt;br&gt;// the code&lt;br&gt;} &lt;br&gt;&lt;br&gt;Useful especially when working with global/top functions.&lt;br&gt;&lt;br&gt;example: function session_handleToken_get() {&lt;br&gt;return $_SESSION['token'];&lt;br&gt;}&lt;br&gt;&lt;br&gt;applicable in any programming lang
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      04:28 AM - 30 Nov 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1333266694198857728" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1333266694198857728" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      0
      &lt;a href="https://twitter.com/intent/like?tweet_id=1333266694198857728" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      0
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;
&lt;br&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// filename.php&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;filename_whatItIsAbout_whatItDoes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;some&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
&lt;span class="c1"&gt;// the code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//example&lt;/span&gt;
&lt;span class="c1"&gt;//session.php&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;session_token_get&lt;/span&gt;&lt;span class="p"&gt;()&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;$_SESSION&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'token'&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;Do you have your own formula? You can share yours. I use this especially when dealing with top/global functions.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>php</category>
      <category>beginners</category>
      <category>functional</category>
    </item>
    <item>
      <title>Happiness is a choice</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Sat, 28 Nov 2020 13:13:51 +0000</pubDate>
      <link>https://dev.to/ricardosawir/happiness-is-a-choice-24f0</link>
      <guid>https://dev.to/ricardosawir/happiness-is-a-choice-24f0</guid>
      <description>&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--E3CqPEh1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1116645238611697665/YNgcU2a9_normal.png" alt="Ricardo Sawir profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Ricardo Sawir
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/ricardosawir"&gt;@ricardosawir&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Happiness is a choice. Well said.
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      13:07 PM - 28 Nov 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1332672395681824768" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1332672395681824768" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      0
      &lt;a href="https://twitter.com/intent/like?tweet_id=1332672395681824768" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      0
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;Today, I learned a point. At the extreme situation, you may still not get what you want. May be your code and mine still not working at the end of the day, may be there are still errors in our program, but thing is, I learned to be thankful at the end of the day. It's a choice.&lt;/p&gt;

&lt;p&gt;I usually post some tweets about coding related and around spirituality, You can follow me at Twitter here &lt;a href="https://twitter.com/RicardoSawir"&gt;https://twitter.com/RicardoSawir&lt;/a&gt;&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>todayisearched</category>
      <category>mentalhealth</category>
    </item>
    <item>
      <title>5 Tactics In Typography and Design That Can Help You Ship Your MVP Fast and Good for Indie Hackers, Bootstrappers &amp; Beginners</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Fri, 27 Nov 2020 16:16:45 +0000</pubDate>
      <link>https://dev.to/ricardosawir/5-tactics-in-typography-and-design-that-can-help-you-ship-your-mvp-fast-and-good-for-indie-hackers-bootstrappers-beginners-33lp</link>
      <guid>https://dev.to/ricardosawir/5-tactics-in-typography-and-design-that-can-help-you-ship-your-mvp-fast-and-good-for-indie-hackers-bootstrappers-beginners-33lp</guid>
      <description>&lt;p&gt;Hi friends, my name is Ricardo Sawir. Follow and subscribe if you like to get more updates on what I make: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My Newsletter &lt;a href="https://subscribe.sawirstudio.com" rel="noopener noreferrer"&gt;https://subscribe.sawirstudio.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter &lt;a href="https://twitter.com/RicardoSawir" rel="noopener noreferrer"&gt;https://twitter.com/RicardoSawir&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github &lt;a href="https://github.com/sawirricardo" rel="noopener noreferrer"&gt;https://github.com/sawirricardo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Youtube &lt;a href="https://www.youtube.com/channel/UC5Db4Y8Sb2pc0LgitPSRTkQ?view_as=subscriber" rel="noopener noreferrer"&gt;https://www.youtube.com/channel/UC5Db4Y8Sb2pc0LgitPSRTkQ&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Gumroad &lt;a href="https://gumroad.com/ricardosawir" rel="noopener noreferrer"&gt;https://gumroad.com/ricardosawir&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;(More to come...)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A little background story, before I jump into programming, I learned design in my university. I have worked as a graphic designer and have taken projects related with designing.&lt;/p&gt;

&lt;p&gt;Now that I also enter into programming world, work as a programmer, too, what I'm going to share are some tips I learned along the way that can help someone create something fast for their MVPs, or even for someone who need it for their day-to-day job, or even for you who are just starting to learn about design, may be you are coming from developer background and want to grasp a bit about design, I hope this book can help you to achieve that.&lt;/p&gt;

&lt;p&gt;With that in mind, I just can't wait to share with you the tips and I hope the best for you. So, let's start from out first point!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Always aim for contrast
&lt;/h2&gt;

&lt;p&gt;You may or may not aware this but you may notice that heading is always bigger than the paragraph. And that's no coincidence. This is one of the basic design skill every design student learn. You want to differentiate either in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;font size&lt;/li&gt;
&lt;li&gt;font weight&lt;/li&gt;
&lt;li&gt;color&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%2Fimgur.com%2FTPRMvSk.jpg" 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%2Fimgur.com%2FTPRMvSk.jpg" alt="https://imgur.com/TPRMvSk.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And sure, you can combine these, too. Usually between bold and big, light and small, and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Emphasize important info
&lt;/h2&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%2Fimgur.com%2Fh2VdJ4S.jpg" 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%2Fimgur.com%2Fh2VdJ4S.jpg" alt="https://imgur.com/h2VdJ4S.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You just know what I'm trying to point at, right?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use &lt;strong&gt;Bold&lt;/strong&gt; or &lt;em&gt;italic&lt;/em&gt; to emphasize, not just regular&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. One font is enough
&lt;/h2&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%2Fimgur.com%2FIJlyVn9.jpg" 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%2Fimgur.com%2FIJlyVn9.jpg" alt="https://imgur.com/IJlyVn9.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: If you aim for MVP, I suggest use 1 font only. If you feel you understand font pairing, you can certainly try the middle type. Remember the 1st point? Aim for the contrast between 2 typeface.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Use color code #555 or #777  for paragraph. Safest Option.
&lt;/h2&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%2Fi.imgur.com%2FVMAz8by.jpg" 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%2Fi.imgur.com%2FVMAz8by.jpg" alt="https://i.imgur.com/VMAz8by.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Use color code #222 or #333 for heading.
&lt;/h2&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%2Fi.imgur.com%2FLn5iWz8.jpeg" 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%2Fi.imgur.com%2FLn5iWz8.jpeg" alt="https://i.imgur.com/Ln5iWz8.jpeg"&gt;&lt;/a&gt;&lt;br&gt;
Alright, I hope you find this useful for your work. Do you have any other tactics you are willing to share?&lt;/p&gt;

&lt;h2&gt;
  
  
  P.S. There are 29 more points more that can help you ship your mvp fast and good
&lt;/h2&gt;

&lt;p&gt;If you want to see the rest, you can buy my ebook at &lt;a href="https://gumroad.com/l/34fastmvp/blackfriday" rel="noopener noreferrer"&gt;https://gumroad.com/l/34fastmvp/blackfriday&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;You can get this at $9.99 (Over 30% OFF from originally $14.99). Go and grab it fast!&lt;/p&gt;

</description>
      <category>design</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>books</category>
    </item>
    <item>
      <title>9 Useful PHP Tips and Code Snippets That Get The Jobs Done</title>
      <dc:creator>Ricardo Sawir</dc:creator>
      <pubDate>Thu, 26 Nov 2020 14:06:36 +0000</pubDate>
      <link>https://dev.to/ricardosawir/9-useful-php-tips-and-code-snippets-that-get-the-jobs-done-1he5</link>
      <guid>https://dev.to/ricardosawir/9-useful-php-tips-and-code-snippets-that-get-the-jobs-done-1he5</guid>
      <description>&lt;p&gt;Hi friends, my name is Ricardo Sawir. Follow and subscribe if you like to get more updates on what I make: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My Newsletter &lt;a href="https://subscribe.sawirstudio.com"&gt;https://subscribe.sawirstudio.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter &lt;a href="https://twitter.com/RicardoSawir"&gt;https://twitter.com/RicardoSawir&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github &lt;a href="https://github.com/sawirricardo"&gt;https://github.com/sawirricardo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Youtube &lt;a href="https://www.youtube.com/channel/UC5Db4Y8Sb2pc0LgitPSRTkQ?view_as=subscriber"&gt;https://www.youtube.com/channel/UC5Db4Y8Sb2pc0LgitPSRTkQ&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Gumroad &lt;a href="https://gumroad.com/ricardosawir"&gt;https://gumroad.com/ricardosawir&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;(More to come...)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, I think that's enough 😁 I collect these tips and code snippets mostly from the awesome communities in StackOverflow. This code snippets and advice works but not limited from PHP 5 to PHP 8. I curate this myself and use it firstly for my job. &lt;/p&gt;

&lt;p&gt;I don't claim any of these code snippets or tips written here as mine. The credits goes to the respective authors. All of these tips and code snippets are collected by me that I see as "useful" for me and I hope you find them useful, too. &lt;/p&gt;

&lt;p&gt;If you find any errors, probably a typo from me, please let me know at my email (you can find at the bottom). &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So, let's jump directly to our 1st tip!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  1. Use Prepared Statements if you are working with database to prevent SQL injection
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/60496/9478774"&gt;https://stackoverflow.com/a/60496/9478774&lt;/a&gt;&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;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$pdo&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="s1"&gt;'SELECT * FROM employees WHERE name = :name'&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="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do something with $row&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is to set up the connection, you can copy paste 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;$dbConnection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'mysql:dbname=dbtest;host=127.0.0.1;charset=utf8'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$dbConnection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_EMULATE_PREPARES&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$dbConnection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_ERRMODE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ERRMODE_EXCEPTION&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$preparedStatement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$db&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="s1"&gt;'INSERT INTO table (column) VALUES (:column)'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$preparedStatement&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="s1"&gt;'column'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$unsafeValue&lt;/span&gt; &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Prepared Statements for dynamic queries? Restrict the possible values by using if else
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/60496/9478774"&gt;https://stackoverflow.com/a/60496/9478774&lt;/a&gt;&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;$dir&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'DESC'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nv"&gt;$dir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ASC'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// only 2 possible options&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Check if a string contains a specific word
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/4366748/9478774"&gt;https://stackoverflow.com/a/4366748/9478774&lt;/a&gt;&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;// @ver below 8&lt;/span&gt;
&lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'How are you?'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;strpos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'are'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// @ver 8&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str_contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'How are you'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'are'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="kc"&gt;TRUE&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;h2&gt;
  
  
  4. Handle undefined index/offset with array_key_exists() or isset()
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/4261200/9478774"&gt;https://stackoverflow.com/a/4261200/9478774&lt;/a&gt;&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;//isset()&lt;/span&gt;
&lt;span class="nv"&gt;$value&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;$array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'my_index'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'my_index'&lt;/span&gt;&lt;span class="p"&gt;]&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="c1"&gt;//array_key_exists()&lt;/span&gt;
&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;array_key_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'my_index'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'my_index'&lt;/span&gt;&lt;span class="p"&gt;]&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. When you want to get the value of $_POST or $_GET or $_REQUEST, you can use isset() or !empty()
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/4261200/9478774"&gt;https://stackoverflow.com/a/4261200/9478774&lt;/a&gt;&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;$value&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;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;]&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="c1"&gt;//empty()&lt;/span&gt;
&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;]&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="c1"&gt;//for PHP 7 and later&lt;/span&gt;
&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'value'&lt;/span&gt;&lt;span class="p"&gt;]&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Display Error in PHP
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/21429652/9478774"&gt;https://stackoverflow.com/a/21429652/9478774&lt;/a&gt;&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="nb"&gt;ini_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'display_errors'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;ini_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'display_startup_errors'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;error_reporting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;E_ALL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Always remember require_once() 99,99%
&lt;/h2&gt;

&lt;p&gt;Compared to include(), require() function will handles errors differently, it will stop the script execution while include() will still continue the script despite the error.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Helper functions if you want to redirect
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/768472/9478774"&gt;https://stackoverflow.com/a/768472/9478774&lt;/a&gt;&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;redirect&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="nv"&gt;$statusCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;303&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Location: '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$statusCode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="k"&gt;die&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;h2&gt;
  
  
  9. Return JSON with this script
&lt;/h2&gt;

&lt;p&gt;Source: &lt;a href="https://stackoverflow.com/a/4064468/9478774"&gt;https://stackoverflow.com/a/4064468/9478774&lt;/a&gt;&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="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cd"&gt;/** whatever you're serializing **/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type: application/json'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  And.. there are 41 more points to go.
&lt;/h2&gt;

&lt;p&gt;I hope you find this useful for your work. I hope the best for you!&lt;/p&gt;

&lt;p&gt;if you want see the rest, you may want to buy at &lt;a href="https://gumroad.com/l/50phpcode/blackfriday"&gt;https://gumroad.com/l/50phpcode/blackfriday&lt;/a&gt;&lt;br&gt;
P.S. It is Black Friday deals, so you may want to grab this rare opportunity fast 😁👍🏻&lt;/p&gt;

&lt;p&gt;Also, if you have any feedback, please send to my email at &lt;a href="//mailto:sawir.ricardo@gmail.com"&gt;sawir.ricardo@gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to thank you again, you are the best!&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>todayilearned</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
