<?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 Marko Lekić on Medium]]></title>
        <description><![CDATA[Stories by Marko Lekić on Medium]]></description>
        <link>https://medium.com/@marlek?source=rss-9931797f548a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ouHEpJs35yvPJ5Bq7KjzYQ.jpeg</url>
            <title>Stories by Marko Lekić on Medium</title>
            <link>https://medium.com/@marlek?source=rss-9931797f548a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 20:33:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marlek/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[Translate Laravel’s reset password email]]></title>
            <link>https://medium.com/fleka-developers/translate-laravels-reset-password-email-b0f1d6e4709a?source=rss-9931797f548a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0f1d6e4709a</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Marko Lekić]]></dc:creator>
            <pubDate>Wed, 25 Jan 2017 10:25:46 GMT</pubDate>
            <atom:updated>2017-01-25T10:27:27.913Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*jMLMTOZd7DFAB2anOb3UBQ.png" /></figure><p>It takes a few steps to completely translate Laravel’s reset password email and I’m listing them here as a reminder for myself and others.</p><p>If you have a blank Laravel installation you’ll have to follow steps from the documentation to set up authentication:</p><p><a href="https://laravel.com/docs/5.3/authentication#introduction">https://laravel.com/docs/5.3/authentication#introduction</a></p><p>This will leave you with a general authentication functionality which includes forgot password emails in English. Here are the steps for fully translating the content:</p><h4>Step 1: Edit the general email layout</h4><blockquote>php artisan vendor:publish</blockquote><p>This will copy the email templates to your application and you’ll now find them in /resources/views/vendor/notifications directory. This particular layout contains some generic strings like “Hello”, “Regards”, … and you should translate those.</p><h4>Step 2: Create ResetPassword notification class</h4><blockquote>php artisan make:notification ResetPassword</blockquote><p>Make sure the class extends Illuminate\Auth\Notifications\ResetPassword:</p><pre><strong>use </strong>Illuminate\Auth\Notifications\ResetPassword <strong>as </strong>ResetPasswordNotification;<br><br><strong>class </strong>ResetPassword <strong>extends </strong>ResetPasswordNotification<br>{</pre><p>And update toMail function with the translation of the content of the notification:</p><pre><strong>public function </strong>toMail($notifiable)<br>{<br>    <strong>return </strong>(<strong>new </strong>MailMessage)<br>        -&gt;subject(<strong>&#39;Promjena lozinke - &#39; </strong>. config(<strong>&#39;app.name&#39;</strong>))<br>        -&gt;line(<strong>&#39;Ovaj e-mail Vam je poslat jer ste zahtijevali promjenu lozinke za vaš nalog.&#39;</strong>)<br>        -&gt;action(<strong>&#39;Promjena lozinke&#39;</strong>, url(https://medium.com/%3Cstrong%3E&#39;password/reset&#39;%3C/strong%3E,%20$this-&gt;token))<br>        -&gt;line(<strong>&#39;Ukoliko nijeste zahtijevali promjenu lozinke, ignorišite ovaj e-mail.&#39;</strong>);<br>}</pre><p>(You can open toMail function of the parent class to see the actual content in English)</p><h4>Step 3: Update User class to use the new notification</h4><p>You need to override sendPasswordResetNotification method in User.php class and make it look like this:</p><pre><strong>public function </strong>sendPasswordResetNotification($token)<br>{<br>   $this-&gt;notify(<strong>new </strong>ResetPassword($token));<br>}</pre><p>Make sure you import your new ResetPassword class in User.php.</p><h4>Done</h4><p>That’s it, the email for resetting password is now translated. In this example I was setting fixed language strings, but you could use Laravel’s localisation to make sure multiple languages are supported</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0f1d6e4709a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fleka-developers/translate-laravels-reset-password-email-b0f1d6e4709a">Translate Laravel’s reset password email</a> was originally published in <a href="https://medium.com/fleka-developers">Fleka Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular initial render speed and ‘above the fold’ content]]></title>
            <link>https://medium.com/fleka-developers/angular-initial-render-speed-and-above-the-fold-content-daaffc6df38d?source=rss-9931797f548a------2</link>
            <guid isPermaLink="false">https://medium.com/p/daaffc6df38d</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Marko Lekić]]></dc:creator>
            <pubDate>Tue, 17 Jan 2017 11:05:14 GMT</pubDate>
            <atom:updated>2017-01-17T19:35:30.203Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xd3lgYV7oB2NDqJI4QVErA.png" /></figure><p>There are usually static elements in your HTML that you can pull out of render blocking javascript to give visitors the impression of a faster page loading. <strong>We will add some static elements from Angular templates directly to index.html so they can be displayed before your Angular app renders.</strong></p><p>The reason for doing all of this is that initial loading speed has become a very important factor in visitor’s decision to stay on your website. <a href="https://blog.kissmetrics.com/loading-time/?wide=1">Some surveys</a> suggest that many visitors leave websites that take more than 3 seconds to load. When you’re making a website as an Angular single page application, you know it’s very hard to achieve a full render of your website in 2 seconds or less (I would argue it’s impossible without any server side rendering and caching). However, showing at least a piece of your website in that time can give the impression of a much better load time. There are some tricks that can be used to show ‘above the fold’ content before your Angular code is fetched and views rendered.</p><p>NOTE: I’m running examples of code on a simplified version of a page from our company website <a href="https://www.fleka.me/">https://www.fleka.me</a>. I’ll show the thumbnail images generated by Chrome Developer Tool’s timeline. To simulate real world environment I disabled caching and set network throttle to “Good 3G”. This allows me to better see the differences between approaches.</p><h3>The usual Angular way</h3><p>We see this, or a similar version of it, in most of Angular application root html files:</p><pre>&lt;!-- index.html --&gt;<br>&lt;div class=”root”&gt;</pre><pre>  &lt;header ui-view=&quot;header&quot;&gt;&lt;/header&gt;</pre><pre>  &lt;main ui-view&gt;&lt;/main&gt;</pre><pre>  &lt;footer ui-view=&quot;footer&quot;&gt;&lt;/footer&gt;</pre><pre>&lt;/div&gt;</pre><p>Until your app’s main .js file is fetched from the server and Angular is initialised your visitors see a blank page. This means that JavaScript is blocking the render of your page. While this may be ok for web applications, it’s not acceptable for websites.</p><p>Let’s start with a simplified example of pulling out a logo, as that is usually just an image or an anchor element that doesn’t depend on the data from an API or another data source.</p><h3>Extract the code for displaying the logo</h3><p>If you consider <em>index.html </em>file from above and we have this in our <strong>header template</strong>:</p><pre>&lt;!-- header.html --&gt;<br>&lt;div class=”navbar”&gt;</pre><pre>  &lt;div class=”navbar-header”&gt;<br>    &lt;a class=”logo”&gt;&lt;/a&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;div class=”collapse navbar-collapse”&gt;<br>    &lt;! — Menu code here →<br>  &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><p>We’re going to see a timeline similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*4qp9QEhvD9DVToJenPR17A.png" /></figure><p>We see here that <strong>~2.7 seconds</strong> pass until our visitor sees something happening on the page.</p><p>Now, let’s pull the code for displaying the logo out in <em>index.html</em>:</p><pre>&lt;! — index.html →<br>&lt;div class=”root”&gt;</pre><pre> &lt;header ui-view=”header”&gt;<br>   &lt;nav class=”navbar”&gt;<br>     &lt;div class=”container”&gt;<br>       &lt;div class=”navbar-header”&gt;<br>         &lt;a class=”logo” ui-sref=”home”&gt;&lt;/a&gt;<br>       &lt;/div&gt;<br>     &lt;/div&gt;<br>   &lt;/nav&gt;<br> &lt;/header&gt;</pre><pre> &lt;main ui-view&gt;&lt;/main&gt;</pre><pre> &lt;footer ui-view=”footer”&gt;&lt;/footer&gt;</pre><pre>&lt;/div&gt;</pre><p>You’ll notice that I only pulled out the code for the logo, I left the code for the menu in <em>header.html. </em>Your <em>header.html</em> can still stay the same, because when Angular loads it will render that and replace the code that you have inside &lt;header ui-view=”header”&gt; in <em>index.html.</em></p><p>Ok, running this gives us a timeline like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*dNIQ4wQwqtLkBVMOfntnoQ.png" /></figure><p>Much better. We see here that the first time the visitor sees something happening on the website is at <strong>~550 milliseconds</strong>. They will not see the actual content until Angular loads and renders it, but this gives them the impression that the website is responding quickly.</p><h3>Replacing logo .png with base64 encoded string</h3><p>You’ll notice in the last timeline screenshot that we first see the red line that is the header’s border, and then we see the logo. This is because the logo is a .png image and needs some more time to be loaded. We can slightly improve this by setting a logo to be a base64 encoded string, which means that it’s already there when our css file arrives and doesn’t have to be fetched (you can Google how to transform image from png to base64, but <strong>if your images are not small and simple it’s better to avoid this</strong>)</p><p>With this slight modification we finally achieve this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*P1P5fRie_L4AKskJBXzwFQ.png" /></figure><p>So now we have an improvement of <strong>~2 seconds </strong>in displaying the first piece of content on our website. Going back to the survey from the beginning of the text, this is a big plus.</p><h3>More options</h3><p>When you start playing with this approach, you can continue by extracting the code of your <strong>menu</strong> too (if it’s static and not fetched from an API or something like that, of course).</p><p>An interesting approach would be to display <strong>header </strong>in the correct size, color, with correct borders, … and then let Angular populate it with the data for the menu or anything like that later on. If you have a sticky <strong>footer</strong>, you can display that one too before Angular loads.</p><p>The step after all of this could be to extract the basic style for initial static data from your .css files and put them directly in the &lt;head&gt; element. Then you can load your css files asynchronously, which means they won’t block the render of the content from your index.html file, which will give you even faster load times then what we achieved here. This depends very much on the website you’re working on, because this could mean that, for example, you have to mimic some of Bootstrap’s styles, which can get pretty messy considering you have to worry about different screen sizes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=daaffc6df38d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fleka-developers/angular-initial-render-speed-and-above-the-fold-content-daaffc6df38d">Angular initial render speed and ‘above the fold’ content</a> was originally published in <a href="https://medium.com/fleka-developers">Fleka Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting rid of Laravel models to improve performance of the command (Blackfire.io profiling)]]></title>
            <link>https://medium.com/fleka-developers/getting-rid-of-laravel-models-to-improve-performance-of-the-command-blackfire-io-profiling-53884fa6573e?source=rss-9931797f548a------2</link>
            <guid isPermaLink="false">https://medium.com/p/53884fa6573e</guid>
            <category><![CDATA[blackfire]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Marko Lekić]]></dc:creator>
            <pubDate>Thu, 03 Dec 2015 09:37:22 GMT</pubDate>
            <atom:updated>2015-12-03T09:48:02.162Z</atom:updated>
            <content:encoded><![CDATA[<p>We are currently working on a very interesting system which is a digital Sommelier service. With complex formulas built by professional sommeliers we match dishes and wines, and we’ve built mobile apps to allow people in restaurants, shops or at home to see which wines match dishes they would like to combine.</p><p>To match dishes and wines we run a Laravel command as a cron job every night which runs formulas to calculate pairing score between a dish and a wine. The command needs to go through hundreds of items and run formulas on them.</p><p>I’ll avoid going into too much detail about the project and get straight to the steps we took to significantly improve one functionality of the system.</p><p>The two Laravel models we have are as follows:</p><ul><li><strong>Dish</strong> with table “<em>dishes</em>” and a lot of properties</li><li><strong>Vintage</strong> (single year of a wine) with table “<em>vintages</em>” and also a lot of properties</li></ul><p>There’s a “many to many” relationship between these two with table “<em>pairing_vintages_dishes</em>” which also contains score for each dish -&gt; wine pairing.</p><p>The first iteration of the command we built (in a hurry I might add) did a pretty straightforward thing:</p><ol><li>Fetch all Dishes</li><li>Fetch all Vintages</li><li>For every Dish, go through every Vintage and run formulas. There are several formulas here comparing multiple attributes of a Dish object to multiple attributes of a Vintage object. After running these formulas we run Laravel’s sync() function to save the score for all the related Vintages.</li></ol><p><em>(The command didn’t actually go through all the objects, it compared only those which were changed during the day. But this still happened to be a lot of objects.)</em></p><p>The command worked, but very slowly. We left it working like that for some time until we finished critical stuff in the system and had time to go back and refactor some slow running code.</p><p>We ran the command with Blackfire.io and saw some interesting information when we ordered functions by percentage of exclusive time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*giAs8GlEXuCxDPGkrbxjEw.png" /><figcaption>Screenshot from Blackfire.io profile, functions ordered by exclusive time percentage</figcaption></figure><p><em>Wall Time 57.6s<br>CPU Time 49.4s<br>I/O Time 8.23s<br>Memory 100MB</em></p><p>Instead of our complex formulas being the most called and expensive functions, it turns out our model’s functions are the ones being called the most.</p><p>This happens because Laravel’s Model is using PHP’s magic methods for getting attributes, meaning that every time you call $myObject-&gt;something it runs $myObject-&gt;getSomethingAttribute() function.</p><p>We’re definitely making a good use of models throughout the system, but it’s obvious that we can avoid them in this command, because it does a very specific thing. We can use regular objects instead of the objects that extend Laravel’s Model class.</p><p>So, instead of getting dish items like this (code simplified for brevity):</p><blockquote>$dishes = Dish::all();</blockquote><p>we used:</p><blockquote>$dishes = DB::table(‘dishes’)-&gt;get();</blockquote><p>Instead of getting a Collection object with Models as items, we get an array of objects of stdClass.</p><p>After doing this we had to remove our call to <em>sync()</em> function because it’s a function of Model class. Instead we used <em>DB::table(‘pairing_vintages_dishes’)-&gt;insert(…)</em> to insert the pairings.</p><p>Now, running the command with Blackfire.io we got this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9M4GJ6RKbikxlpH1_iH2Q.png" /><figcaption>Screenshot from Blackfire.io profile, functions ordered by exclusive time percentage</figcaption></figure><p><em>Wall Time 3.42s<br>CPU Time 3.02s<br>I/O Time 407ms<br>Memory 23.1MB</em></p><p>In the comparison view in Blackfire.io we see the difference in functions called:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*b5jBbhTYNQKgziBPBiSSqw.png" /><figcaption>Comparison of two Blackfire.io profiles, functions ordered by exclusive time percentage</figcaption></figure><p>It now makes much more sense, the important functions are the ones being called the most.</p><p>In the end two quite simple changes significantly improved the performance of the script ran daily:</p><ol><li>Removing Larevel Model objects by using <em>DB::table(‘…’)-&gt;get()</em> instead of <em>Model::all() </em>to avoid many calls to magic methods</li><li>Removing Laravel <em>sync()</em> call to save relationships and using <em>DB::insert([…])</em> instead to avoid many SQL statements being run</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53884fa6573e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fleka-developers/getting-rid-of-laravel-models-to-improve-performance-of-the-command-blackfire-io-profiling-53884fa6573e">Getting rid of Laravel models to improve performance of the command (Blackfire.io profiling)</a> was originally published in <a href="https://medium.com/fleka-developers">Fleka Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>