<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sabbir Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Sabbir Ahmed on Medium]]></description>
        <link>https://medium.com/@sab-exp?source=rss-b7250361b078------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YT5NtcM4lYYdpkKv7BGoJw.jpeg</url>
            <title>Stories by Sabbir Ahmed on Medium</title>
            <link>https://medium.com/@sab-exp?source=rss-b7250361b078------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:21:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sab-exp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cache data with Redis in CakePHP 4]]></title>
            <link>https://sab-exp.medium.com/cache-data-with-redis-in-cakephp-4-f68ac62d6ea?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/f68ac62d6ea</guid>
            <category><![CDATA[cakephp4]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[cakephp]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Sat, 05 Mar 2022 23:53:05 GMT</pubDate>
            <atom:updated>2022-03-05T23:53:05.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wLCu7tnz6UmnEPuqOOpvSg.png" /><figcaption>Cache with CakePHP</figcaption></figure><p>It’s super easy to cache your DB results in CakePHP with Redis. Actually, it’s so easy it might make you uncomfortable.</p><h3>Contents</h3><ol><li>Setup Redis in your docker environment</li><li>Setup Redis in CakePHP</li><li>Use cache functionality with your query result (DB data)</li><li>Bonus</li></ol><h3>Setup Redis in the docker environment</h3><p>I am going to assume the reader has existing knowledge about docker environment and make this section brief.</p><p>Installing Redis has two parts :<br>- Setup the Redis server which will host the data<br>- Install the <a href="https://github.com/phpredis/phpredis">phpredis</a> extension</p><p>Setup the Redis server in the docker-compose.yml file with the following code:</p><pre>version: &#39;3&#39;</pre><pre>services:<br>    redis_server:<br>        image: redis<br>        volumes:<br>            - &quot;./redis/db-data:/data&quot;</pre><p>※ I am going to assume you have also CakePHP and DB setup in there too.</p><p>Install the <a href="https://github.com/phpredis/phpredis">phpredis extension</a> in the dockerfile. This should be the same file docker file where you are installing the php.</p><pre>FROM php:7.4-apache</pre><pre>RUN pecl install redis</pre><p>If you want to install the Redis not in docker container but in the Linux. You can use this <a href="https://trinitytuts.com/install-and-configure-redis-cache-in-php-web-application/">article here</a>.</p><h3>Setup Redis in CakePHP</h3><p>In the app.php file inside the cache adapters Cache[]array write the following code :</p><pre>/*<br> * Configure the cache adapters.<br> */<br>&#39;Cache&#39; =&gt; [<br> &#39;db_data_cache&#39; =&gt; [<br>  &#39;className&#39; =&gt; &#39;Redis&#39;,<br>  &#39;duration&#39; =&gt; &#39;+1 hours&#39;,<br>  &#39;host&#39; =&gt; &#39;redis_server&#39;,<br> ],<br>]</pre><p>※ There is already Cache array, so don’t write it again. Just add the array db_data_cache in there.</p><ul><li>db_data_cache is just a name to refer this config later in the code. You can use any name here you like</li><li>className here tells CakePHP which caching engine to use. CakePHP supports other cache engine too like Memcache etc.</li><li>duration is how long the data will be saved in the cache. So after this time has passed new data will be cached for the next 1 hour.</li><li>host This name is of the service which we have assigned in the docker-compose file earlier.</li></ul><h3>Use cache functionality with your query result (DB data)</h3><p>Now with CakePHP built in functionality the caching work just like magic. With your query you can just write the following codes to enable caching for the resultset:</p><pre>/**<br> * If a query has caching enabled, it will do the following when executed:<br> * - Check the cache for $key. If there are results no SQL will be executed.<br> *   Instead the cached results will be returned.<br> * - When the cached data is stale/missing the result set will be cached as the query<br> *   is executed.<br>*/<br>$query-&gt;cache(&#39;recent_articles&#39;, &#39;db_data_cache&#39;);<br>recent_articles above is the key name which is used to save the data in Redis. </pre><ul><li>recent_articles above is the key name in which the data is saved in Redis.</li><li>db_data_cacheis the name of the config which we have setup in app.php file.</li><li>And cache data will be renewed as the time mentioned in db_data_cache config duration in the app.php file. So in our case it’s in 1hour.</li></ul><p>That’s all actually you need to use the cache functionality. And rest of the article is just extra information. Read ahead if you want more ✌🏼</p><p>You can also generate a key for the cache like this :</p><pre>$query-&gt;cache(function ($q) {<br>    return &#39;articles-&#39; . md5(serialize($q-&gt;clause(&#39;where&#39;)));<br>});</pre><h4>Check whether cache is really working or not</h4><p>After you have executed the query, you can check whether the data has been cached or not with the following code:<br>debug( \Cake\Cache\Cache::read(&#39;recent_articles&#39;, &#39;db_data_cache&#39;) );</p><p>Remove all the existing cache with the following code:<br>\Cake\Cache\Cache::clear(&#39;db_data_cache&#39;);</p><h4>Learn more in details about the cache in CakePHP documentation:</h4><ul><li><a href="https://book.cakephp.org/4/en/orm/query-builder.html#caching-loaded-results">https://book.cakephp.org/4/en/orm/query-builder.html#caching-loaded-results</a></li><li><a href="https://book.cakephp.org/4/en/core-libraries/caching.html">https://book.cakephp.org/4/en/core-libraries/caching.html</a></li></ul><h3>Bonus</h3><p>Deciding name for a key could be a bother and specially if you have to cache a lot of places. To solve that I have used the full SQL statement as a key for the query results. Here’s the contents for this bonus section:</p><ol><li>Get the proper full SQL statement from query</li><li>Use the SQL statement as a key for the cache.</li><li>Change the code into a function for easier use in other places</li></ol><h4>Get the proper full SQL statement from query</h4><p>Unfortunately in CakePHP there is no built in function (as of CakePHP 4.2) to compile the proper full SQL statement. Although with debugKit you can use the function sql($query) to generate the the SQL statement, but the problem is this only available in with debug mode on. So not on the production environment.</p><p>To solve this, I have taken the <a href="https://github.com/cakephp/debug_kit/blob/4.x/src/DebugSql.php#L154">code from the debugKit</a> and added a few lines at the first few lines to make it simpler when using it with the query. Here’s how it looks :</p><pre>/**<br> * Helper function used to replace query placeholders by the real<br> * params used to execute the query.<br> * <br> * <a href="http://twitter.com/param">@param</a> query $query Query <br> * <a href="http://twitter.com/return">@return</a> string return the compiled SQL with the binding value with query<br> */<br>public static function compiledSQL($query)<br>{<br> $sql = $query-&gt;sql();<br> $bindings = $query-&gt;getValueBinder()-&gt;bindings();</pre><pre>$params = array_map(function ($binding) {<br>  $p = $binding[&#39;value&#39;];</pre><pre>if ($p === null) {<br>   return &#39;NULL&#39;;</pre><pre>}elseif (is_bool($p)) {<br>   return $p ? &#39;TRUE&#39; : &#39;FALSE&#39;;</pre><pre>}elseif( $p instanceof \DateTimeInterface ){<br>   return &quot;&#39;&quot;.$p-&gt;format(&#39;Y-m-d H:i:s.u&#39;).&quot;&#39;&quot;;</pre><pre>}elseif (is_string($p)) {<br>   $replacements = [<br>    &#39;$&#39; =&gt; &#39;\\$&#39;,<br>    &#39;\\&#39; =&gt; &#39;\\\\\\\\&#39;,<br>    &quot;&#39;&quot; =&gt; &quot;&#39;&#39;&quot;,<br>   ];</pre><pre>$p = strtr($p, $replacements);</pre><pre>return &quot;&#39;$p&#39;&quot;;<br>  }</pre><pre>return $p;<br> }, $bindings);</pre><pre>$keys = [];<br> $limit = is_int(key($params)) ? 1 : -1;<br> foreach ($params as $key =&gt; $param) {<br>  $keys[] = is_string($key) ? &quot;/$key\b/&quot; : &#39;/[?]/&#39;;<br> }</pre><pre>return preg_replace($keys, $params, $sql, $limit);<br>}</pre><p>And I have added this static function in a common Utilclass so that I can call it whenever I want.</p><p>The Util class resides in the file named Util.php which I have into cake/src/Lib/Util.php . And here’s how it looks inside the file:</p><pre>&lt;?php<br>namespace App\Lib;</pre><pre>class Util{</pre><pre>public static function compiledSQL($query)<br> {<br>  // code here .. <br> }<br>}</pre><h4>Use the SQL statement as a key for the cache.</h4><p>This is how you can call the function to generate the SQL statement to use it as a key in the cache:</p><pre>$query-&gt;cache(<br> // compiling the sql statement to use it as a key for caching<br> function ($query){<br>  return md5(\App\Lib\Util::compiledSQL($query));<br> },<br> &#39;db_data_cache&#39;<br>);</pre><h4>Change the code into a function for easier use in other places</h4><p>Awesome so far, right? We can compact it more by moving it to a function.</p><p>After compacting into a function the code for caching will look like this:</p><pre>\App\Lib\Util::cacheQueryData($query, &#39;db_data_cache&#39;);</pre><p>And this how it looks at the Utility class :</p><pre>/**<br> * If a query has caching enabled, it will do the following when executed:<br> * - Check the cache for $key. If there are results no SQL will be executed.<br> *   Instead the cached results will be returned.<br> * - When the cached data is stale/missing the result set will be cached as the query<br> *   is executed.<br> * <br> * <a href="http://twitter.com/param">@param</a> query <br> * <a href="http://twitter.com/param">@param</a> string cache engine config name <br>*/<br>public static function cacheQueryData($query, $cache_config)<br>{<br> $query-&gt;cache(<br>  // compiling the sql statement to use it as a key for caching<br>  function ($query){<br>   // This is the function which I have already shared above<br>   return md5(self::compiledSQL($query));<br>  },<br>  $cache_config<br> );<br>}</pre><p>If you have any questions let me know in the comments. And also this article was first published here in the <a href="https://webnation.co.jp/cache-data-with-redis-cakephp4/">WebNation blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f68ac62d6ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to keep the docker container running if it stops immediately]]></title>
            <link>https://sab-exp.medium.com/how-to-keep-the-docker-container-running-if-it-stops-immediately-9521c179bb43?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/9521c179bb43</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Mon, 20 Dec 2021 04:48:50 GMT</pubDate>
            <atom:updated>2021-12-20T04:48:50.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1glDLNQiYoJxPq2MJAR9Sw.png" /></figure><p>Alternate Title : Solve the container problem that it stops immediately after running.</p><p>When developing with docker you may feel like you want to use certain container like a virtual machine, and keep it running the background when you are not using it.</p><p>Or if for some other reason you want to keep the container running but it immediately stops after you run it.</p><p>If that sounds like you keep reading.</p><h4>Let’s create a container first and see it stops</h4><p>Here you can see the code in docker-compose for a simple container for python:3.7:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*cwToqzLImQdgg1O3zoW38g.png" /></figure><p>So when I run the container from this docker-compose, it shows the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zUw5DvG0ewHbfrIRGnl8dg.png" /></figure><p>You can see from the above image that the container stops.</p><p>(So the normal solution is to create a container and bash it to get inside at the time of creating the container, in that case it won’t stop. <br>But for some edge case, if you want to keep open the container and enter and exit the container to run scripts read ahead. )</p><h4>The solution : Keep the container running</h4><p>So <strong>there are few ways of making sure that it never stops</strong>. This <a href="https://stackoverflow.com/questions/28212380/why-docker-container-exits-immediately"><em>StackOverFlow</em></a> link mentions few of them.</p><p>The one I like most, after creating the container, is to attach an interactive shell to it. And because that interactive shell is active, it won’t get stopped.</p><p>Here’s how you can do it with docker-compose:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*ArORGlPPsTLok945YQKsUQ.png" /></figure><p>Here’s the after running this it doesn’t stop anymore :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVa_tyiyhijZnno1JKFICQ.png" /></figure><p>From the above image, you can see that the container is not stopping anymore and it is running.</p><p>Now you can bash into the container and do what ever you want with the this command : docker exec -it &lt;container name&gt; bash`</p><h4>Why the docker container stops</h4><p>Let me explain why a container gets stopped.</p><p>A docker container exits when its main process finishes. Containers main purpose is to run process or processes inside an isolated environment.</p><p>So when those process finishes, it gets stopped. Unlike let’s say a VM, containers are efficient. So they won’t stay around if all the processes finishes.</p><p>That said, because we run database or web servers inside the container. They are long living processes, so if you run any of those long-running process you will see it won’t get stopped.</p><p>Normally, developers don’t run into issues like this. But for some cases, you may need the containers to keep running.</p><p>This post was originally published <a href="https://webnation.co.jp/keep-the-docker-container-running-if-stops/">here</a>. The design of the site is very bad, so if you click this link, remember you have been warned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9521c179bb43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use PhpSpreadsheet with CakePHP 4]]></title>
            <link>https://sab-exp.medium.com/how-to-use-phpspreadsheet-with-cakephp-4-71c0a65cc698?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/71c0a65cc698</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Sat, 10 Jul 2021 03:06:11 GMT</pubDate>
            <atom:updated>2021-07-10T03:06:11.466Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use PhpSpreadsheet / excel with CakePHP 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eKhhBvwqezwz8Ius795puA.png" /><figcaption>Excel in CakePHP</figcaption></figure><p><strong>Contents :</strong></p><ol><li>What is PhpSpreadsheet</li><li>How to install</li><li>Create a test spreadsheet</li><li>Spreadsheet download from a button</li><li>Use a template file</li><li>Best Practices</li></ol><h3>What is PhpSpreadsheet ?</h3><p>Everyone who is reading this article have an idea already what is this, so in short, this is a library to create spreadsheet in PHP.</p><p>And this is the most popular one among others and maintained properly.</p><h3>How to Install</h3><p>You need composer to install this in your CakePHP project. This is the command for the composer :</p><p>composer require phpoffice/phpspreadsheet</p><p><strong>For people who are using docker :</strong></p><ul><li>Run the command in your project directory to install this inside your container :</li></ul><p>docker-compose exec app php ../composer.phar require phpoffice/phpspreadsheet</p><ul><li>Optional : PhpSpreadsheet needs a zip extension for PHP, so if you don’t have this already install in your container this with the following command :</li></ul><p>docker-compose exec app install-php-extensions zip</p><h3>Create a test spreadsheet</h3><p>Write the following codes inside a controller. In this case, I have created a SampleController.php</p><pre>// src/Controller/SampleController.php</pre><pre>&lt;?php</pre><pre>namespace App\Controller;</pre><pre>use PhpOffice\PhpSpreadsheet\Spreadsheet; // ← PhpSpreadsheet class<br>use PhpOffice\PhpSpreadsheet\Writer\Xlsx; // ← PhpSpreadsheet class</pre><pre>class SampleController extends AppController<br>{<br>    public function index()<br>    {<br>        // Create a new spreadsheet<br>        $spreadsheet = new Spreadsheet();</pre><pre>        // Add value in a sheet inside of that spreadsheet. <br>        // // (It&#39;s possible to have multiple sheets in a single spreadsheet)<br>        $sheet = $spreadsheet-&gt;getActiveSheet();<br>        $sheet-&gt;setCellValue(&#39;A1&#39;, &#39;Hello World !&#39;);</pre><pre>        // Save the spreadsheet in the webroot folder<br>        $writer = new Xlsx($spreadsheet);<br>        $writer-&gt;save(&#39;test.xlsx&#39;);<br>        exit;<br>    }<br>}</pre><p>This will save the file in the webrootfolder. If you open the file it will look like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*UUfUfdmopwVwvES4dmM8sA.png" /></figure><h3>Spreadsheet download from a button</h3><p>The above example created the xlsx file in the webroot folder. Now let’s create the code so that when the user clicks a button in a page, the spreadsheets downloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xYI5j5CKkAUaJUSwr-Jjg.png" /><figcaption>Downloading an excel sheet from a button</figcaption></figure><p>So the code for button looks like this in index.php:</p><pre>&lt;?= $this-&gt;Form-&gt;create(null, [&#39;url&#39;=&gt; [&#39;action&#39; =&gt; &#39;excel&#39;,], &#39;type&#39;=&gt;&#39;POST&#39;]); ?&gt;<br>    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Download&lt;/button&gt;<br>&lt;?= $this-&gt;Form-&gt;end() ?&gt;</pre><p>And the SampleController.php :</p><pre>&lt;?php<br>// src/Controller/SampleController.php</pre><pre>namespace App\Controller;</pre><pre>use PhpOffice\PhpSpreadsheet\Spreadsheet; <br>use PhpOffice\PhpSpreadsheet\Writer\Xlsx;<br>use Cake\Http\CallbackStream; // ← Added new in this sample</pre><pre>class SampleController extends AppController<br>{<br>    public function excel()<br>    {<br>        // Create a new spreadsheet<br>        $spreadsheet = new Spreadsheet();</pre><pre>        // Add value in a sheet inside of that spreadsheet. <br>        // // (It&#39;s possible to have multiple sheets in a single spreadsheet)<br>        $sheet = $spreadsheet-&gt;getActiveSheet();<br>        $sheet-&gt;setCellValue(&#39;A1&#39;, &#39;Hello World !&#39;);</pre><pre>        $writer = new Xlsx($spreadsheet);</pre><pre>        // ↓↓ Added new code from here in the eariler sample code</pre><pre>        // Save the file in a stream<br>        $stream = new CallbackStream(function () use ($writer) {<br>            $writer-&gt;save(&#39;php://output&#39;);<br>        });</pre><pre>        $filename = &#39;sample_&#39;.date(&#39;ymd_His&#39;);<br>        $response = $this-&gt;response;</pre><pre>        // Return the stream in a response<br>        return $response-&gt;withType(&#39;xlsx&#39;)<br>            -&gt;withHeader(&#39;Content-Disposition&#39;, &quot;attachment;filename=\&quot;{$filename}.xlsx\&quot;&quot;)<br>            -&gt;withBody($stream);<br>            }<br>}</pre><p>( To understand the specifics of the code, please read the comments which is in the code )</p><h3>Use a template file</h3><p>So let’s say you have lots of design in your spreadsheet and you want to use that template and just change the data in that file before download.</p><p>So this is how you can do that.</p><p>The code will be like this in the controller :</p><pre>&lt;?php<br>// src/Controller/SampleController.php</pre><pre>namespace App\Controller;</pre><pre>use PhpOffice\PhpSpreadsheet\Spreadsheet; <br>use PhpOffice\PhpSpreadsheet\Writer\Xlsx;<br>use Cake\Http\CallbackStream;<br>use PhpOffice\PhpSpreadsheet\IOFactory; // ← Added new in this</pre><pre>class SampleController extends AppController<br>{<br>    public function excel()<br>    {<br>  // Load the template file from the root folder<br>  $templateFile = WWW_ROOT . &#39;sample.xlsx&#39;;<br>  $spreadsheet = IOFactory::load($templateFile);</pre><pre>  // Add data in that file<br>  $templateSheet = $spreadsheet-&gt;getActiveSheet();<br>  $templateSheet-&gt;setCellValue(&#39;B1&#39;, &#39;Hello World !&#39;);</pre><pre>  // Save the data in a stream<br>  $writer = new Xlsx($spreadsheet);<br>  $stream = new CallbackStream(function () use ($writer) {<br>   $writer-&gt;save(&#39;php://output&#39;);<br>  });</pre><pre>  $filename = &#39;sample_&#39;.date(&#39;ymd_His&#39;);<br>  $response = $this-&gt;response;</pre><pre>  // Return the stream to the user<br>  return $response-&gt;withType(&#39;xlsx&#39;)<br>   -&gt;withHeader(&#39;Content-Disposition&#39;, &quot;attachment;filename=\&quot;{$filename}.xlsx\&quot;&quot;)<br>   -&gt;withBody($stream);<br>    }<br>}</pre><h3>Best Practices</h3><p>So in the above controller, we wrote the data, hello world, in the B1 cell. In here, we are actually creating the view from data. And we never create view in controller because we already have a specific place to write view. And that is in the template folder .</p><p>The reason I wrote in the controller above is to make the code simpler and easier to understand.</p><p>As now you have got the idea already on how to do this. Let’s learn how we should same code we wrote in the above section named <strong>Use a template file</strong>.</p><p>So the SampleController.php will look like this :</p><pre>class SampleController extends AppController<br>{<br>    public function excel()<br>            <br>        $this-&gt;viewBuilder()-&gt;disableAutoLayout();<br>        $this-&gt;set(&#39;some_string&#39;, &#39;This is so better !&#39;);<br>        <br>        // Take the view and return as a response to the user/browser<br>        $this-&gt;response = $this-&gt;response-&gt;withDownload(&#39;test.xlsx&#39;);<br>    <br>    }<br>}</pre><p>So simpler and not a fat controller at all 😄.</p><p>All the code related to the view has moved to the view in template.</p><p>So the view excel.php looks like this :</p><pre>&lt;?php</pre><pre>use PhpOffice\PhpSpreadsheet\Writer\Xlsx;<br>use PhpOffice\PhpSpreadsheet\IOFactory;</pre><pre>// Load the template file from the root folder<br>$templateFile = WWW_ROOT . &#39;sample.xlsx&#39;;<br>$spreadsheet = IOFactory::load($templateFile);</pre><pre>// Add data in that file<br>$spreadsheet-&gt;getActiveSheet()<br>   -&gt;setCellValue(&#39;B1&#39;, $some_string)<br>;</pre><pre>// Save the data in a stream<br>$writer = new Xlsx($spreadsheet);<br>$writer-&gt;save(&#39;php://output&#39;);</pre><p>So neat and clean.</p><ul><li>If you find any inconsistencies, or unclear sections please let me know in the comment below</li><li>This post was originally published in my <a href="https://webnation.co.jp/how-to-use-phpspreadsheet-excel-with-cakephp-4/">company’s blog</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71c0a65cc698" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My experience with AliExpress buying Xiaomi Band 6]]></title>
            <link>https://sab-exp.medium.com/bought-xiaomi-band-6-on-aliexpress-b1755f77bedd?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1755f77bedd</guid>
            <category><![CDATA[wearables]]></category>
            <category><![CDATA[aliexpress]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Mon, 26 Apr 2021 08:36:23 GMT</pubDate>
            <atom:updated>2021-09-30T02:10:10.613Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*oBiHFXVWkozed6fK_TG3aQ.png" /></figure><p>The Xiaomi band 6 was released in China April 1st. I wanted to buy one ASAP but it wasn’t available in Japan at that time anywhere. So what I did is went on AliExpress and ordered my self one on <strong>April 2nd.</strong></p><p><strong>Here’s the TLDR</strong>:</p><p>Name : Xiaomi band 6<br>Price : ¥ 4,836<br>Review : 5/5 — best value to money. Recommended.</p><p>Duration : 16 days<br>Delivery : 2/5. My package was damaged but the product inside was okay. <br>Buying experience on AliExpress : 4/5</p><h3><strong>Why Xiaomi band 6</strong></h3><p>After starting working remotely from home. I have started to think more about health and exercise. And to improve better, one need a better way of tracking.</p><p>The best wearable device on the market is Apple Watch hands down. But not only it’s expensive, you need to be in the Apple ecosystem.</p><p>As I am a android user, I was thinking of buying the Fit bit devices, but watching<strong> </strong><a href="https://youtu.be/QuvYWn1vZws"><strong>this data</strong> <strong>based </strong>review of Xiaomi band 6 in YouTube</a>, I changed my mind.</p><p>I found out the Xiaomi band 5 is comparable performance wise to Fitbit bands and price is 1/4. <br>Although Fitbit cost 3 times, the build quality is very bad. I found a few places on internet, where they had to replace the wearables.</p><p>So it was a no brainer for me at that time.</p><p>Also as I don’t use wearables normally, I was thinking of buying a cheaper version to decide whether it really will add value to my life.</p><p><strong>Another personal requirement for me was to have integration with Google Fit. Which Xiaomi wearables support.</strong></p><p>ℹ : <strong>Xiaomi band 6 doesn’t have built in GPS. </strong>Although understandable because the price is so cheap, but I didn’t know at the time when I bought it. <br>It means, you have to have your phone with you when you do any activities which need the GPS.</p><h3>Why Buy on AliExpress :</h3><p>Three reasons :</p><ul><li>Will have it sooner in my hands</li><li>A little bit cheaper</li><li>Buy directly from China and cut out the middle man.</li></ul><p>Okay, as this was released on April 1st and I wanted to buy this as soon as possible.</p><p>And I couldn’t find it anywhere in Japan and felt like, it may take at least 1 month to have it here in Japan.</p><p>And it takes around 2~4 weeks to buy from AliExpress which I knew anecdotally from my friends who buys from AliExpress.</p><p>And it generally is cheaper to buy from AliExpress but the demerit is it takes a long time.</p><p>(And it’s almost 23 days after it was released in China, and I still couldn’t find it locally. So my initial hunch was right. And band 6 is in my hands because I bought from China directly. Yay !!🎉🎉🎉)</p><h3>Ordering on AliExpress :</h3><p>I found two problems in general :</p><ul><li>The first buyer whom I bought from actually didn’t ship the product for 4 days. So I cancelled the order. And got my money back after 2 weeks. <br>Then, I bought from this seller, who shipped within one day. And I got it on the 16th days. <br>The seller I bought first, who didn’t ship for 4days, but the seller had 5star reviews ! But I don’t think is exactly AliExpress fault.</li></ul><p>(My suggestion : Message the seller first, to confirm when he can ship then only order)</p><ul><li>AliExpress logs me out every 30 minutes or 1 hour, I am not sure. But it was super irritating. Also as I have created the account with Google, it took me quite longer to log in.</li></ul><p>Mainly I had a bad UX for the log out problem.</p><h3>Delivery :</h3><p>This is where it gets worse. Although I got on the 16th day. My package was damaged. Fortunately(?), my device was alright. Here’s the picture :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZDUPWJGIoYxUIf5ao71m-w.png" /></figure><h3>Inside the box :</h3><p>There was the watch, the charger and the Chinese manual. Chinese because I ordered the Chinese version. btw, don’t worry if you buy a Chinese one, you can change the language settings and everything is same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*am7B5v9rpWD_wKqSHyUKxg.png" /></figure><p>This article was first published <a href="https://webnation.co.jp/bought-xiaomi-band-6-on-aliexpress/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1755f77bedd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use lambda to send message to WhatsApp]]></title>
            <link>https://sab-exp.medium.com/use-lambda-to-send-message-to-whatsapp-20c89d304c45?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/20c89d304c45</guid>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda-function-in-python]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 06:04:26 GMT</pubDate>
            <atom:updated>2021-03-11T12:15:41.579Z</atom:updated>
            <content:encoded><![CDATA[<h3>Use program (lambda) to send message to WhatsApp</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8ZQJXF3WwyHu-KDt4mJWA.png" /></figure><p>Let’s learn how to send messages periodically to a WhatsApp contact with Lambda.</p><p><strong>We would need an API for sending message to WhatsApp which will be provided by Twilio.</strong></p><p>(We will be using a sandbox for this time, not a real number to send message, because a real number API is not provided at the time of opening account, one have to apply and wait for a while)</p><p><strong>Then using that API, we will send message to WhatsApp with a few lines of code in Lambda.</strong></p><p>This article will be divided in 2 main parts :</p><ul><li><strong>Twilio : Get tokens/API for WhatsApp</strong></li><li><strong>Lambda : Use Lambda to send message</strong></li></ul><h3>1. Twilio Setup :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wCUwMhawe6mCXeedJEEQvA.png" /></figure><p>Okay, let’s go to the <a href="https://www.twilio.com/">official website</a> of Twilio and create a free tier account and log in.</p><p>After logging in, go to this <a href="https://www.twilio.com/console/sms/whatsapp/learn">WhatsApp-section</a>, which will take you to the following page :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pOOEYkCdqeUbUGOtsyTFQ.png" /><figcaption>Twilio WhatsApp Section</figcaption></figure><p>As you can see from the image, this is a sandbox. So do the following to send message from this sandbox to your WhatsApp account. ( If you have a production ready API then, you don’t need to do this. But for Sandbox which is what we are using, we need to do this verification of Sandbox)</p><ul><li>Save the number, marked in yellow in the image above, in your phone as Sandbox (or whatever name you like). Example image below :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*Vepr-88PhGq5dYhNKX6-KA.png" /></figure><ul><li>Then send join tongue-in message to that saved contact number (Sandbox Twilio in our case). Example image below :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*VX5UXFgTD_cBq0Yt4fG7jA.png" /></figure><ul><li>With this sandbox activated with our number. Now we can send messages to our number using account SID and token. Go to this link and get these ids. Example given below :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6P08NBKQ2Rixgpsnr1lLVg.png" /><figcaption>Location of getting the Twilio token</figcaption></figure><h3>🎉</h3><p>With this, our <strong>Twilio Setup is complete. </strong>Now let’s go the coding section where all the action is 🍆</p><h3><strong>2. Lambda</strong></h3><p>I have divide this section in two parts:</p><ul><li><strong>Python Code</strong> : Which will be sending the message using the API</li><li><strong>Lambda </strong>: Lambda is where we will put our code, and Lambda will run it for free for us.</li></ul><p><strong>Python Code :</strong></p><p>Download the code <a href="https://github.com/sab-exp/whatsapp_with_aws_lambda">from this repository</a>, and after downloading you will see :</p><ul><li>There is a file named send_message_whatsapp.py which contains the main source code</li><li>And a zip file named aws_lambda_deploy.zip which contains the library needed when uploading the file to Lambda.</li></ul><p>Main code example :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e98a3764c91403b3d414211effa2f34d/href">https://medium.com/media/e98a3764c91403b3d414211effa2f34d/href</a></iframe><p><strong>Now change the source code according the 👇 following instructions </strong>:</p><ul><li>This is where you have to include your Twilio Sid , and token which you have gotten in the Twilio section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*hUZ39yN1tvy3bh88dcVLJQ.png" /></figure><ul><li>Normally this number (same on which you have saved in you mobile as Sandbox Twilio )is same for everybody, so no need to change. But if changes in the future, you have to change it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*rTt3gWjussJri9r32hrXMA.png" /></figure><ul><li>Now in here, Change the name and number in which you will be sending the message. (This is the contact you used to send the message to Twilio Sandbox)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*1RQ-lhF50RdSHj0N90I3Ow.png" /></figure><p><strong>After doing the above changes</strong>, extract the zip file aws_lambda_deploy.zip and then copy this source file (which you have changed )to the extracted folder and replace it there. <br>Then, zip it again with the latest source code. Now it’s ready to be <strong>deployed to Lambda.</strong></p><h4>Lambda :</h4><p>We have done the hard work, now only the fun part is left to do. I am considering you have already an AWS free tier account and logged in right now. <br>(If you don’t then, please a google search, there should be a plenty of resource which teach you to do this )</p><ul><li>Create a function in the AWS console. Example image 👇<br>- Choose run time as Python 3.6 and give the function a name. <br>- Then just click on the button create function</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*L4_S6_5534BbKBhPKbkrrA.png" /></figure><p>(Optional : If you get any IAM related error, you have to get full access of IAM)</p><ul><li>After creating the function, you will be taken to the dashboard. <br>- Here select the option of uploading a zip file. Then upload the aws_lambda_deploy.zip ( Image given below : )</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZVURbKbpMsWIsbT1897GQ.png" /></figure><ul><li>After successfully uploading the zip file, select the edit option in run time settings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPEl4LPl53B2igaycSTX_Q.png" /></figure><ul><li>Ok, now we are ready to test our Lambda Function. Go to the test section and invoke the lambda.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wAeczkmDOWcl84uggszV1w.png" /></figure><ul><li>If the result is successful , you can see the following images :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrSaj6d5qGk2HItaB5NrtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Pq0Dy8byGJ3JdBKmqw9OBw.png" /></figure><p><strong>You can see, I have received a text message in WhatsApp.</strong></p><h4><strong>Yay Mission Successful 🎉</strong></h4><h3>Troubleshoot :</h3><p>When invoking the Lambda if you see the following error of time out :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsilvyCaRU40hhLR7VAgBw.png" /></figure><p>Go the Lambda Configuration and change lambda time out from 3 -&gt; 5 seconds. And it will work 😃</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DzTWnq6qX0MZPpawHhWOA.png" /></figure><p>If you want to a little challenge for yourself, you can create a CloudWatch event and then trigger the function at that specified time. If you want an article on how to set up, let me know.</p><p>This post was <a href="https://webnation.co.jp/use-lambda-to-send-message-to-whatsapp/">originally published</a> in my company’s blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20c89d304c45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to take better notes with the digital tool Obsidian.]]></title>
            <link>https://sab-exp.medium.com/how-to-take-better-notes-with-the-digital-tool-obsidian-60a6aaf0cc93?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/60a6aaf0cc93</guid>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 09:29:41 GMT</pubDate>
            <atom:updated>2021-01-18T09:29:41.060Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5pCmHdE4JGk8cGqrbv0nw.png" /></figure><pre><strong>Table of Contents<br></strong>1. Introduction<br> 1.1 What is Personal Knowledge Management?<br> 1.2 Do you even need this new software for your note or PKM ?<br>2. Obsidian<br>3. Plugins</pre><h3>Introduction</h3><p>So there are a lot of tools we know and use for note taking. For example, Evernote, Google Keep, Apple Notes, OneNote etc.</p><p>You can use those tools for any writing purposes, no doubt about it.</p><p>But all of them are not created for long term personal knowledge management. So I am going to introduce a tool called <strong>Obsidian</strong> which is the best for this type of note taking. You will soon know why it’s the best out there.</p><h4><strong>What is Personal Knowledge Management you ask ?</strong></h4><p>In this information age, we always get bombarded with all kinds of information, from social media posts, from even TickTock short video also teaches things.</p><p>All of this knowledge is needed in our life, but after a while we forget most of these. To all the book readers out there, I am sure you can relate that, you read a book a few years ago, which you liked a lot but now in the present, you forgot most of it.</p><p><em>To actively manage this kind of situations or knowledges is known as </em><strong><em>Personal Knowledge Management </em></strong><em>or in short </em><strong><em>PKM.</em></strong></p><p><em>It should be common sense that </em><strong><em>we need to manage our knowledge like we manage our finance</em></strong><em>.</em></p><h4>Do you even need this new software for your note taking or PKM ?</h4><p>Technically any kind of note software actually enough for keeping your notes. But with this software it gets so much easier. For how and why , please read on the next sections.</p><h3><strong>Obsidian</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2FGm1VnUw9y3JhYDheSrw.png" /><figcaption><a href="https://obsidian.md/">https://obsidian.md/</a></figcaption></figure><p>The best two features of <a href="https://obsidian.md/">Obsidian</a> :</p><ul><li>Link your one notes to another.</li><li>See how your notes are connected in a graph</li></ul><p>Although it doesn’t sounds much, but with the minimal design and these features it’s all you will ever need .</p><p><strong>Basics : Create and link your notes</strong></p><p>After downloading the apps, create your first note with ctrl + n :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EI0H-hmQ-iVx_9VLedBeqQ.gif" /></figure><p>Now comes the fun part. We can now now link another new notes by creating second brackets [[]]like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6EROG44aP2iiMUza5ISKQ.gif" /><figcaption>Linking one notes to another</figcaption></figure><p>Now that we have linked another two notes with [[Android]] and [[IOS]]. If we if ctrl + click on either of these, we can see the magic of creating of another note like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BrBRqi9MXvhWcE1cjm27BQ.gif" /></figure><p>We can see that, by clicking on the [[Android]] , we are in that file and can start writing another notes.</p><p>We can also see the color changes if there is a note already opened with that title. In the gif above, you can see the android color changed when I got back to Operating System Note.</p><p>Now here comes the graph !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nb2CXOg398Q3j0ww7K1RsQ.png" /></figure><p>With this graph, you can visualize how all of your ideas are connected together. And link new ideas by seeing this graph. I love this feature in the Obsidian.</p><p>For example : This is how mine looks after creating a few notes in this app :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*Iu1PDX2ICoAQysv0mMZIDg.png" /></figure><p><em>The great thing about this is, you can </em><strong><em>keep a backup of this in GitHub</em></strong><em>, or </em><strong><em>Drobox , google drive </em></strong><em>etc. Because this is just a folder in your computer. The tutorial I showed you has this following files inside the folder :</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3K8HQXlN9cPcmRjuoePafQ.png" /></figure><h3>Plugins</h3><p>First let’s turn on the option of using from third party plugins:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrEsIUQ5pBwQA8OCivkgoQ.gif" /></figure><p>So there are a lot of plugins to use with this app. A lot of great plugins are related to themes.</p><p>But <strong>most essential </strong>is I think this one :</p><p><strong>Automatic update to GitHub</strong></p><p>There is a <strong>requirement to use this plugin</strong>. First you have to init the git and then push the code to remote manually.</p><p>Then Go to the plugins section and search for git like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2GObxCy_WxIiYQ4vzG4vbw.gif" /></figure><p>After installing you can find the git settings option in settings. Go there and set the interval you would like to commit :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExUix0tgWOb5T4kzitQ_Fw.png" /></figure><p>I have also turned on the option to push automatically to GitHub. Like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcUTPdsecbINdD0Or_uK2A.png" /></figure><p>Hands down, this was the best software for me in 2020. And I can see myself using this software forever.</p><p>I know you are convinced already, Here’s the <a href="https://obsidian.md/"><strong>link</strong></a> , have fun :)</p><p>This article was first published here in my <a href="https://webnation.co.jp/how-to-take-better-note-with-digital-tool-obsidian/">company’s blog</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60a6aaf0cc93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a basic search engine algorithm works explained without math]]></title>
            <link>https://sab-exp.medium.com/how-a-basic-search-engine-algorithm-works-explained-without-math-86bdb571f4e8?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/86bdb571f4e8</guid>
            <category><![CDATA[search-engines]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Wed, 12 Aug 2020 01:37:31 GMT</pubDate>
            <atom:updated>2020-08-12T01:37:31.355Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WGE4gWLgObRqD9rh11jBMg.png" /></figure><p>This article is written for beginners who want to understand how search algorithm works.</p><p>I am going to write about how Google’s search algorithm (PageRank) worked when it launched in 1998 without writing any codes or technical terms. So that it’s easier to understand.</p><p>This algorithm was so superior at that time that, although it launched four years after the first commercial search engine and already popular Lycos and AltaVista, it outperformed all of them in terms of search quality.</p><p>I am going to explain the Hyperlink Trick and the Authority Trick, and how google solved the problem with those with the <strong>The Random Surfer Trick</strong></p><h3><strong>The Hyperlink Trick</strong></h3><p>You already know what a hyperlink is : it is a link on a web page that takes you to another web page when you click on it.</p><p>Hyperlinks are one of the most important tools used by search engines to perform ranking, and they are fundamental to Google’s PageRank technology. The first step in understanding PageRank is a simple idea we’ll call the hyperlink trick. This trick is most easily explained by an example.</p><p>Suppose you are interested in learning how to make scrambled eggs and you do a web search on that topic.</p><p>Now any real web search on scrambled eggs turns up millions of hits, but to keep things really simple, let’s imagine that only two pages come up —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*mzIvJbSdeVISGLIgQsmRHA.png" /><figcaption>Search results for scrambled eggs</figcaption></figure><p>one called “Ernie’s scrambled egg recipe” and the other called “Bert’s scrambled egg recipe.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nr-F3v3YiNa9rDRyxsnLEw.png" /><figcaption>Pages with hyperlink to recipes</figcaption></figure><p>Also imagine that there are four pages on the entire web that link to either of our two scrambled egg recipes. So there are total four hyperlinks for these two recipes.</p><p>The question is, which of the two hits should be ranked higher, Bert’s recipe or Ernie’s?</p><p>As humans, it’s not much trouble for us to read the pages that link to the two recipes and make a judgment call. But computers are not good at understanding what a web page actually means. So they can’t rank it like how a human ranks a web page.</p><p>On the other hand, computers are excellent at counting things. So one simple approach is to simply count the number of pages that link to each of the recipes — in this case, one for Ernie, and three for Bert — and rank the recipes according to how many incoming links they have.</p><p>Of course, this approach is not nearly as accurate as having a human read all the pages and determine a ranking manually, but it is nevertheless a useful technique.</p><p>It turns out that, if you have no other information, the number of incoming links that a web page has can be a helpful indicator of how useful, or “authoritative,” the page is likely to be.</p><p>In this case, the score is Bert 3, Ernie 1, so Bert’s page gets ranked above Ernie’s when the search engine’s results are presented to the user.</p><p>You can probably already see some problems with this “hyperlink trick” for ranking. One obvious issue is that sometimes links are used to indicate bad pages rather than good ones. For example, imagine a web page that linked to Ernie’s recipe by saying, “I tried Ernie’s recipe , and it was awful.” Links like this one, that criticize a page rather than recommend it, do indeed cause the hyperlink trick to rank pages more highly than they deserve. But it turns out that, in practice, hyperlinks are more often recommendations than criticisms, so the hyperlink trick remains useful despite this obvious flaw.</p><h3>The Authority Trick</h3><p>You may already be wondering why all the incoming links to a page should be treated equally.</p><p>Surely a recommendation from an expert is worth more than one from a novice? To understand this in detail, we will stick with the scrambled eggs example from before, but with a different set of incoming links.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aaKRkfQuIjdhM75_r8YnOQ.png" /><figcaption>Recipes got different authoritative incoming links</figcaption></figure><p>The figure shows the new setup: Bert and Ernie each now have the same number of incoming links/hyperlinks (just one), but Ernie’s incoming link is from a software engineer, whereas Bert’s is from the famous chef Alice Waters.</p><p>So, whose recipe would you prefer?</p><p>Obviously, it’s better to choose the one recommended by a famous chef, rather than the one recommended by a software engineer.</p><p>This basic principle is what we’ll call the “authority trick”: links from pages with high “authority” should result in a higher ranking than links from pages with low authority.</p><p>This principle is all well and good, but in its present form it is useless to search engines. How can a computer automatically determine that Alice Waters is a greater authority on scrambled eggs than an engineer?</p><p>Here is an idea that might help: let’s combine the hyperlink trick with the authority trick. All pages start off with an authority score of 1, but if a page has some incoming links, its authority is calculated by adding up the authority of all the pages that point to it. In other words, if pages X and Y link to page Z, then the authority of Z is just the authority of X plus the authority of Y.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*2VuFelMtxeAMXpOQ7CPTbw.png" /><figcaption>Calculation of authority scores for the two recipes</figcaption></figure><p>The figure gives a detailed example, calculating authority scores for the two scrambled egg recipes. The final scores are shown in circles.</p><ul><li>There are two pages that link to John’s home page; these pages have no incoming links themselves, so they get scores of 1. John’s page gets the total score of all its incoming links, which adds up to 2.</li><li>Alice Waters’s home page has 100 incoming links that each have a score of 1, so she gets a score of 100.</li></ul><p>Ernie’s recipe has only one incoming link, but it is from a page with a score of 2, so by adding up all the incoming scores (in this case there is only one number to add), Ernie gets a score of 2.</p><p>Bert’s recipe also has only one incoming link, valued at 100, so Bert’s final score is 100. And because 100 is greater than 2, Bert’s page gets ranked above Ernie’s.</p><h3>The Random Surfer Trick</h3><p>It seems like we have hit on a strategy for automatically calculating authority scores that really works, without any need for a computer to actually understand the content of a page. Unfortunately, there can be a major problem with the approach. It is quite possible for hyperlinks to form what computer scientists call a “cycle.” <strong>So if we can solve this problem, we have a working search algorithm !</strong></p><p>A cycle exists if you can get back to your starting point just by clicking on hyperlinks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*1tlm_tMLVt3PqDJFOL4GZQ.png" /><figcaption>An example of cycle</figcaption></figure><p>There are 5 web pages labeled A, B, C , D, and E. If we start at A, we can click through from A to B, and then from B to E — and from E we can click through to A , which is where we started. This means that A, B , and E form a cycle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*U_7BzCM5ncfmak0kVlnCKQ.png" /><figcaption>The problems with cycle</figcaption></figure><p>It turns out that our current definition of “authority score” (combining the hyperlink trick and the authority trick) gets into big trouble whenever there is a cycle. Let’s see what happens on this particular example. Pages C and D have no incoming links, so they get a score of 1. C and D both link to A, so A gets the sum of C and D, which is 1 + 1 = 2. Then B gets the score 2 from A, and E gets 2 from B. (The situation so far is summarized by the left-hand panel of the figure above.) But now A is out of date: it still gets 1 each from C and D, but it also gets 2 from E, for a total of 4. But now B is out of date: it gets 4 from A. But then E needs updating, so it gets 4 from B. (Now we are at the right-hand panel of the figure above.) And so on: now A is 6, so B is 6, so E is 6, so A is 8,…. You get the idea, right?</p><p>Calculating authority scores this way creates a chicken-and-egg problem. If we knew the true authority score for A, we could compute the authority scores for B and E. And if we knew the true scores for B and E , we could compute the score for A. But because each depends on the other, it seems as if this would be impossible.</p><p>Fortunately, we can solve this chicken-and-egg problem using a technique we’ll call the <strong>random surfer trick</strong>. Beware: the initial description of the random surfer trick bears no resemblance to the hyperlink and authority tricks discussed so far.</p><p><strong><em>Random surfer trick</em></strong><em> combines the desirable features of the hyperlink and authority tricks, but works even when cycles of hyperlinks are present.</em></p><p>I am going to make it brief here and just cover the basics of random surfer mechanics.</p><p>The trick begins by imagining a person who is randomly surfing the internet. To be specific, our surfer starts off at a single web page selected at random from the entire World Wide Web.</p><p>The surfer then examines all the hyperlinks on the page, picks one of them at random, and clicks on it. The new page is then examined and one of its hyperlinks is chosen at random. This process continues, with each new page being selected randomly by clicking a hyperlink on the previous page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*5TvbniSAqHNxf_odYjzkmQ.png" /><figcaption>Imagining the entire World Wide Web consists of just 16 web pages</figcaption></figure><p>The figure above shows an example, in which we imagine that the entire World Wide Web consists of just 16 web pages.</p><p>Boxes represent the web pages, and arrows represent hyperlinks between the pages. Four of the pages are labeled for easy reference later.</p><p>Web pages visited by the surfer are darkly shaded, hyperlinks clicked by the surfer are colored black, and the dashed arrows represent random restarts, which are described next.</p><p>There is one twist in the process: every time a page is visited, there is some fixed restart probability (say, 15%) that the surfer does not click on one of the available hyperlinks. Instead, he or she restarts the procedure by picking another page randomly from the whole web.</p><p>It might help to think of the surfer having a 15% chance of getting bored by any given page, causing him or her to follow a new chain of links instead. To see some examples, take a closer look at the figure above. This particular surfer started at page A and followed three random hyperlinks before getting bored by page B and restarting on page C. Two more random hyperlinks were followed before the next restart.</p><blockquote>(By the way, the random surfer example use a restart probability of 15%, which is the same value used by Google cofounders Page and Brin in the original paper describing their search engine prototype.)</blockquote><p>So how random surfer model solves the problem with ranking pages ?</p><ul><li>First, we had the hyperlink trick: the main idea here was that a page with many incoming links should receive a high ranking. This is also true in the random surfer model, because a page with many incoming link has many chances to be visited.</li><li>Second, we had the authority trick. The main idea was that an incoming link from a highly authoritative page should improve a page’s ranking more than an incoming link from a less authoritative page. Again, the random surfer model takes account of this. Why? Because an incoming link from a popular page will have more opportunities to be followed than a link from an unpopular page.</li></ul><p>Notice that the random surfer model simultaneously incorporates both the hyperlink trick and authority trick. In other words, the quality and quantity of incoming links at each page are all taken into account.</p><p><strong>The beauty of the random surfer trick is that, unlike the authority trick, it works perfectly well whether or not there are cycles in the hyperlinks.</strong></p><blockquote>This random surfer trick was described by Google’s co-founders in their now-famous 1998 conference paper, “The Anatomy of a Large-scale Hyper-textual Web Search Engine.”</blockquote><p>This article is written based on the chapter of the book called ‘<a href="https://www.amazon.com/Nine-Algorithms-That-Changed-Future/dp/0691158193">Nine Algorithms That Changed the Future: The Ingenious Ideas That Drive Today’s Computers</a>’ and all of the images here are taken from this book. If you want to learn more about algorithm, this book is highly recommended. Please check this out.</p><p>Random surfer trick is explained in details in the Google’s cofounders now-famous conference paper, “<a href="https://snap.stanford.edu/class/cs224w-readings/Brin98Anatomy.pdf">The Anatomy of a Large-scale Hypertextual Web Search Engine</a>.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86bdb571f4e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infinite Scroll with Vuetify || Nuxt]]></title>
            <link>https://sab-exp.medium.com/infinite-scroll-with-vuetify-nuxt-8bb3e8d0b408?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bb3e8d0b408</guid>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[infinite-scroll]]></category>
            <category><![CDATA[vuetify]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Thu, 05 Dec 2019 09:55:43 GMT</pubDate>
            <atom:updated>2020-01-17T01:32:51.651Z</atom:updated>
            <content:encoded><![CDATA[<h3>Infinite Scroll with Vuetify || Nuxt.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*PSuH8eZIvZgT6TxOedaNEA.png" /><figcaption>Infinite Scroll + Vuetify.js + Nuxt.js</figcaption></figure><p>I have already written a detailed step by step <a href="https://medium.com/@sabbir.study/infinite-scroll-in-nuxt-js-f34ee86906cb">article </a>on how to implement Infinite Scroll with Nuxt.js. In there I had to use an component named <em>Infinite-scroll </em>to implement it.</p><p>But with a recent update it has become much easier to do this in Vuetify (v2.1+) without needing any extra components. Check the following steps, it’s super convenient with Vuetify.</p><h3>1. Basic Setup</h3><p>I have forked a project from <a href="https://codesandbox.io/">codesandbox.io</a>. this is a default brand new project in Nuxt.js with Vuetify latest version included.</p><p>Wait ! Before starting the main coding part, let’s delete the default code &amp; create some markup with data from an free public API.</p><p>1.1</p><p><strong>Inside the pages folder</strong>:</p><ul><li>Delete README.md</li><li>Delete about.vue</li></ul><p><strong>Inside index.vue:</strong></p><p>change the code into the following ones:</p><p>(Creating Layout with Vuetify)</p><pre>&lt;template&gt;<br> &lt;v-flex&gt;<br>  &lt;v-container fluid grid-list-lg class=&quot;mt-5&quot;&gt;<br>   &lt;posts/&gt;<br>  &lt;/v-container&gt;<br> &lt;/v-flex&gt;<br>&lt;/template&gt;&lt;script&gt;<br>import posts from &quot;~/components/Posts.vue&quot;;</pre><pre>export default {<br> components: { posts }<br>};<br>&lt;/script&gt;</pre><p>1.<strong>2</strong></p><p>Now, Delete all the files in the components folder and create a new component named Posts.vue and paste the following codes:</p><pre>&lt;template&gt; <br>&lt;v-card flat&gt; <br>  &lt;v-layout row wrap&gt; <br>   &lt;v-flex v-for=&quot;(title, index) in titles&quot; :key=&quot;index&quot;&gt; <br>    &lt;v-card flat hover class=&quot;white pb-2 mb-1 pl-2&quot;&gt; <br>     &lt;v-layout&gt; <br>      &lt;v-flex xs10&gt; <br>       &lt;div class=&quot;py-2&quot;&gt;{{ title.body }}&lt;/div&gt;    <br>      &lt;/v-flex&gt; <br>     &lt;/v-layout&gt; <br>    &lt;/v-card&gt; <br>   &lt;/v-flex&gt; <br> &lt;/v-layout&gt; <br>&lt;/v-card&gt; <br>&lt;/template&gt;<br> <br>&lt;script&gt; <br>import axios from &quot;axios&quot;; <br>export default { <br> name: &quot;Posts&quot;, <br> data() { return {<br>  titles: [], page: 1 }; <br> },<br> <br> computed: {<br>  url() { return &quot;<a href="https://jsonplaceholder.typicode.com/posts?_page=">https://jsonplaceholder.typicode.com/posts?_page=</a>&quot; + this.page; } },<br> <br>  created() { <br>   this.fetchData(); },<br>  methods: { <br>   async fetchData() { const response = await axios.get(this.url); this.titles = response.data; } } <br>  }; <br>&lt;/script&gt; </pre><pre>&lt;style scoped&gt; <br>.theme--light.v-card { background-color: #f5f5f5; } <br>&lt;/style&gt;</pre><p>1.<strong>3</strong></p><p>In the layouts/default.vue file paste the following code:</p><pre>&lt;template&gt;<br> &lt;v-app&gt;<br>  &lt;nuxt class=&quot;mb-5&quot;/&gt;<br> &lt;/v-app&gt;<br>&lt;/template&gt;</pre><p>If you followed all the steps correctly your project will look like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fa-nuxtjs-project-with-a-json-api-d1065%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fa-nuxtjs-project-with-a-json-api-d1065%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Ddark&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fd1065%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ae8986093b9f3ddfad157c657925b15/href">https://medium.com/media/4ae8986093b9f3ddfad157c657925b15/href</a></iframe><p>You can fork this↑ , and start to experiment at the same time reading this article.</p><p>So now let’s go to the main coding part now.</p><h3>2. Main Part</h3><p>We are going to use <a href="https://vuetifyjs.com/en/directives/intersect">Intersection observer </a>directive from Vuetify. You must have latest version of Vuetify (2.1+) to use this feature.</p><p>Now let’s add the at the following code at the Posts.vue at the bottom of the page. In our case, after &lt;/v-layout&gt; .</p><pre>&lt;v-card v-intersect=&quot;infiniteScrolling&quot;&gt;&lt;/v-card&gt;</pre><p>In here v-intersect is the directive, and whenever the browser will contact with this v-card it will call the <em>infiniteScrolling</em> method.</p><p>Now let’s add the following the code in the methods section:</p><pre>infiniteScrolling(entries, observer, isIntersecting) {</pre><pre>setTimeout(() =&gt; {<br> this.page++;<br> axios<br>  .get(this.url)<br>  .then(response =&gt; {<br>   if (response.data.length &gt; 1) {<br>    response.data.forEach(item =&gt; this.titles.push(item));<br>   }<br>  })<br>  .catch(err =&gt; { console.log(err)});<br> }, 500);<br>}</pre><p>setTimeout is for to call the code a little bit late.</p><p>axios.get is getting the data from the API.</p><p>response.data.length is to check whether it’s getting data, if there is no data it will be false.</p><p>To know more about this observer go to this Vuetify documentation <a href="https://vuetifyjs.com/en/directives/intersect">Intersection observer</a>.</p><p>I haven’t written any explanation because I have already write about this in my earlier <a href="https://medium.com/@sabbir.study/infinite-scroll-in-nuxt-js-f34ee86906cb">article here</a>. If any part is unclear please write a comment. I will try to reply.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bb3e8d0b408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infinite Scroll in Nuxt.js]]></title>
            <link>https://sab-exp.medium.com/infinite-scroll-in-nuxt-js-f34ee86906cb?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/f34ee86906cb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Thu, 26 Sep 2019 02:09:17 GMT</pubDate>
            <atom:updated>2022-06-30T14:19:37.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORP09JJ6_yUiG29O_er9lw.png" /></figure><p>Because of better UX, you can see Infinite Scroll everywhere. Depending on the context it’s a wonderful solutions for adding new content to the page.</p><p>There are basically two ways you can implement the Infinite Scroll in your project.</p><ol><li>Vanilla JS</li><li>Plugins.</li></ol><p>After searching for a while, there wasn’t any easy way to do it with pure JS code.</p><p>So I used a plug in called <a href="https://peachscript.github.io/vue-infinite-loading/">Vue-infinite-loading</a>, it’s great to use and has nice animations. <br>Implementing wasn’t smooth for me, so I decided to write an article to save time for others.</p><blockquote>Edit on 10/19: If you are using Vuetify, it’s easiest with <a href="https://vuetifyjs.com/directives/intersect">v-intersect</a>. Available from the Vuetify version 2.1 or more.</blockquote><p>Here’s the demo :</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Finfinite-scroll-corrected-hoyxb&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Finfinite-scroll-corrected-hoyxb&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a368e9df6d7e4c2a528de93a7ccf4b0/href">https://medium.com/media/1a368e9df6d7e4c2a528de93a7ccf4b0/href</a></iframe><p>This article will be divided in <strong>two parts.</strong></p><ol><li>Set up a Nuxt.js page with the <a href="https://jsonplaceholder.typicode.com/">json:api</a> (optional)</li><li>Implement the Infinite Scroll</li></ol><h3>Part 1</h3><p>(This part is optional. If you have already an existing project, you can jump to the next part)</p><p>Let’s create a Nuxt.js project as written in the <a href="https://nuxtjs.org/guide/installation">official document</a>. Here’s a quick GIF:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*09on8AfTXxIbH2EOYDJYgA.gif" /><figcaption>Creating a Nuxtjs project</figcaption></figure><p>Here’s some basic codes to set up a working page. I’m not explaining the code because this should make sense if you know Nuxt.js. (And if you don’t, you should follow a beginner tutorial to create a basic app and then come here :) )</p><p><strong>1.1</strong></p><p>Delete all the files in the pages except the index.vue and change the code into the following ones:</p><pre>&lt;template&gt;<br> &lt;v-flex&gt;<br>  &lt;v-container fluid grid-list-lg class=&quot;mt-5&quot;&gt;<br>   &lt;posts/&gt;<br>  &lt;/v-container&gt;<br> &lt;/v-flex&gt;<br>&lt;/template&gt;</pre><pre>&lt;script&gt;<br>import posts from &quot;~/components/Posts.vue&quot;;</pre><pre>export default {<br> components: { posts }<br>};<br>&lt;/script&gt;</pre><p>(I am using Vuetify framework for design. So that’s why you are seeing the &lt;v-something&gt; tags. The “ v” is for Vuetify components.)</p><p>1.<strong>2</strong></p><p>Now, Delete all the files in the componentsfolder and create a new component named Posts.vue and paste the following codes:</p><pre>&lt;template&gt; <br>&lt;v-card flat&gt; <br>  &lt;v-layout row wrap&gt; <br>   &lt;v-flex v-for=&quot;(title, index) in titles&quot; :key=&quot;index&quot;&gt; <br>    &lt;v-card flat hover class=&quot;white pb-2 mb-1 pl-2&quot;&gt; <br>     &lt;v-layout&gt; <br>      &lt;v-flex xs10&gt; <br>       &lt;div class=&quot;py-2&quot;&gt;{{ title.body }}&lt;/div&gt;    <br>      &lt;/v-flex&gt; <br>     &lt;/v-layout&gt; <br>    &lt;/v-card&gt; <br>   &lt;/v-flex&gt; <br> &lt;/v-layout&gt; <br>&lt;/v-card&gt; <br>&lt;/template&gt;<br> <br>&lt;script&gt; <br>import axios from &quot;axios&quot;; </pre><pre>export default { <br> name: &quot;Posts&quot;, <br> data() { return {<br>  titles: [], page: 1 }; <br> },<br> <br> computed: {<br>  url() { return &quot;<a href="https://jsonplaceholder.typicode.com/posts?_page=">https://jsonplaceholder.typicode.com/posts?_page=</a>&quot; + this.page; } },<br> <br>  created() { <br>   this.fetchData(); },<br>  methods: { <br>   async fetchData() { const response = await axios.get(this.url); this.titles = response.data; } } <br>  }; <br>&lt;/script&gt; </pre><pre>&lt;style scoped&gt; <br>.theme--light.v-card { background-color: #f5f5f5; } <br>&lt;/style&gt;</pre><p>1.<strong>3</strong></p><p>In the layouts/default.vue file paste the following code:</p><pre>&lt;template&gt;<br> &lt;v-app&gt;<br>  &lt;nuxt class=&quot;mb-5&quot;/&gt;<br> &lt;/v-app&gt;<br>&lt;/template&gt;</pre><p>If you followed all the steps correctly your project will look like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fa-nuxtjs-project-with-a-json-api-d1065%3Ffontsize%3D14&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fa-nuxtjs-project-with-a-json-api-d1065%3Ffontsize%3D14&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9d1dad0424ebe54c8b3871eda849c2e/href">https://medium.com/media/b9d1dad0424ebe54c8b3871eda849c2e/href</a></iframe><p>You can see in the sandbox that there are a few posts in the page which I am calling from an API. And right now there are no Infinite Scroll.</p><p>The basic part is complete. Now with that out of the way.</p><h3>Part 2</h3><p>Next, install the <a href="https://peachscript.github.io/vue-infinite-loading/">Vue-infinite-loading</a> here with npm.</p><pre>npm install vue-infinite-loading -S</pre><p>Then in the pluginsfolder , create a blank file named infiniteloading.js and paste the following code:</p><pre>import Vue from &#39;vue&#39;<br>import InfiniteLoading from &#39;vue-infinite-loading&#39;<br><br>Vue.component(&#39;infinite-loading&#39;, InfiniteLoading)</pre><p>Now let’s add the plugin file in the nuxt.config.js .</p><pre>plugins: [<br>  { src: &#39;~/plugins/infiniteloading&#39;, ssr: false }<br>]</pre><h4>The infinite loading component set up is finished. <strong>Yay.</strong></h4><p><strong>2.1</strong></p><p>Now let’s add the following Infinite Scroll component at the <strong>bottom </strong>of the posts.vue component.</p><pre>&lt;infinite-loading <br>   spinner=&quot;spiral&quot;<br>   @infinite=&quot;infiniteScroll&quot;<br>&gt;&lt;/infinite-loading&gt;</pre><p><strong>Bottom</strong> of the page because whenever this component will be visible in the browser, it will trigger the selected method. In this case, the method is infiniteScroll which we will write soon below.</p><p>So if it is in the upper side of the page , it will trigger the method as soon as the page is created which we do not want because we haven’t scrolled yet.</p><p>I have selected the <strong>spinner type as spiral</strong>. You can change it to other type. Please check out the official documents of infinite loading component to choose other designs.</p><p><strong>2.2</strong></p><p>Add the following function in the methods: and you are <strong>done.</strong></p><pre>infiniteScroll($state) {</pre><pre>setTimeout(() =&gt; {<br>this.page++</pre><pre>axios.get(this.url)<br>.then((response) =&gt; {</pre><pre>  if (response.data.length &gt; 1) {<br>   response.data.forEach((item) =&gt; this.titles.push(item))<br>   $state.loaded()</pre><pre>  } else {</pre><pre>   $state.complete()</pre><pre>  }</pre><pre> }).catch((err) =&gt; {console.log(err)})</pre><pre>}, 500)</pre><p>setTimeout is for to call the code a little bit late.</p><p>axios.get is getting the data from the api.</p><p>response.data.length is to check whether it’s getting data, if there is no data it will be false.</p><p>response.data.forEach((item) =&gt; this.title.push(item)) is adding every new item from array to the title</p><p>$state.loaded(),$state.complete() is the animation of loading the component.</p><p>The complete code is available in this <a href="https://github.com/Sabbir-Noire/Infinity-Scroll">GitHub repository</a>. Originally published <a href="https://webnation.co.jp/infinite-scroll-in-nuxt-js/">here</a>.</p><p><a href="https://twitter.com/SabbirA00942588">My twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f34ee86906cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Vuetify 2.0 in a existing Nuxt.js project]]></title>
            <link>https://sab-exp.medium.com/adding-vuetify-2-0-in-a-existing-nuxt-js-project-dba8a71f198d?source=rss-b7250361b078------2</link>
            <guid isPermaLink="false">https://medium.com/p/dba8a71f198d</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sabbir Ahmed]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 07:41:03 GMT</pubDate>
            <atom:updated>2021-01-18T08:37:22.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*E5rLwFafmf6KdH7B2sLELg.png" /></figure><p>There are two ways to add Vuetify 2.0 in a existing Nuxt project.</p><ol><li><strong>With Nuxt.js </strong><a href="https://github.com/nuxt-community/vuetify-module"><strong>module</strong></a><strong> (Recommended)</strong></li><li><strong>With a plugin</strong></li></ol><p>I will explain both but the nuxt module is the recommended way as it’s maintained by the core group of Nuxt js. So the probability is higher that you would get reliable updates. And you should obviously if possible update to 2.0. And yes, Vuetify is way cooler now ;) .</p><h3>The Nuxt module way</h3><p>The <a href="https://github.com/nuxt-community/vuetify-module">official GitHub module page </a>was hard for me to understand at first. So I hope this helps.</p><p>So considering you have a running Nuxt application. You would already know how to install through npm/yarn.</p><p>So first add vuetify module through the following code:</p><pre>npm install --save-dev @nuxtjs/vuetify<br># or<br>yarn add --dev @nuxtjs/vuetify </pre><h3><strong>The Plugin Way</strong></h3><ol><li>First, Install Vuetify 2.0.0</li></ol><pre>npm install vuetify@2.0.0<br>// OR<br>yarn add vuetify@2.0.0</pre><ol><li>Vuetify uses <a href="https://materialdesignicons.com/">Material Design Icons</a> as its default iconfont. Let’s install it first:</li></ol><pre>npm install @mdi/font -D<br>// OR<br>yarn add @mdi/font -D</pre><p>2. Create plugin called vuetify.js in plugins folder and add this code.</p><pre>import Vue from &#39;vue&#39;<br>import Vuetify from &#39;vuetify&#39;<br>import &#39;vuetify/dist/vuetify.min.css&#39;<br>import &#39;@mdi/font/css/materialdesignicons.css&#39; // Ensure you are using css-loader version &quot;^2.1.1&quot; ,</pre><pre>Vue.use(Vuetify)<br><br>export default ctx =&gt; {<br>  const vuetify = new Vuetify({<br>    theme: {<br>      dark: false // From 2.0 You have to select the theme dark or light here<br>    }<br>  })<br><br>  ctx.app.vuetify = vuetify<br>  ctx.$vuetify = vuetify.framework<br>}</pre><p>You can change the value of dark to true to change it to dark mode, and also you can add your common color variables here. It will make the code complicated. I will include an example at the end of the article in the bonus section :D .</p><p>3. Then add the plugin in the nuxt.config.js</p><pre>plugins: [<br>    &#39;@plugins/vuetify&#39;<br>  ],</pre><p>Okay, that’s it. Done. :)</p><p>You can now play with the new components which have been added in version 2. Include any v-components in the template under v-app:</p><pre>&lt;template&gt;<br>  &lt;v-app&gt;<br>    //Include new components here and see the magics.<br>    //BTW,you must have v-app in the root file encompassing all the <br>    //Vuetify components  <br>  &lt;/v-app&gt;<br>&lt;/template&gt;</pre><p>I really liked the color picker. Here’s an image of the color picker you will get with this simple code &lt;v-color-picker&gt;&lt;/v-color-picker&gt; :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*BXw1ogsSdVUGRCh0-ABXPw.gif" /><figcaption>Color Picker</figcaption></figure><p><strong>Pro Tip</strong>: If Vuetify gets updated to a new version e.g 2.0.x something, you can npm update vuetify to upgrade easily. That’s the only 1 line of code you need.</p><p><strong>Bonus:</strong></p><p>Here’s how your code will look like, if you set common color. This is recommended as you can change the colors in one sweep.</p><p>You have to add it in the plugin section. plugins/vuetify.js</p><pre>import Vue from &#39;vue&#39;<br>import Vuetify from &#39;vuetify&#39;<br>import &#39;vuetify/dist/vuetify.min.css&#39;<br>import &#39;@mdi/font/css/materialdesignicons.css&#39;<br>import colors from &quot;vuetify/es5/util/colors&quot;;</pre><pre>Vue.use(Vuetify)<br><br>export default ctx =&gt; {<br>  const vuetify = new Vuetify({<br>    theme: {<br>      dark: false,<br>       themes: {<br>         dark: {<br>           primary: colors.deepPurple.lighten3,<br>           accent: colors.deepPurple.accent3,<br>           secondary: colors.amber.darken3,<br>           info: colors.teal.lighten1,<br>           warning: colors.amber.base,<br>           error: colors.deepOrange.accent4,<br>           success: colors.green.accent4<br>         }<br>        }<br>      },<br>  })<br><br>  ctx.app.vuetify = vuetify<br>  ctx.$vuetify = vuetify.framework<br>}</pre><p>Don’t forget to import colors :)</p><p>To get notifications about articles like this or for suggestions <a href="https://twitter.com/sab_exp">follow me on twitter</a>. <a href="https://webnation.co.jp/upgrading-to-vuetify-2-0-in-a-existing-nuxt-js-project/">Originally published here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dba8a71f198d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>