<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sami supreme</title>
    <description>The latest articles on DEV Community by Sami supreme (@verax5).</description>
    <link>https://dev.to/verax5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1079179%2F4f93d426-cbdf-4321-aedd-d78766ebf7fd.png</url>
      <title>DEV Community: Sami supreme</title>
      <link>https://dev.to/verax5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/verax5"/>
    <language>en</language>
    <item>
      <title>SSE (service side events) example to update a table</title>
      <dc:creator>Sami supreme</dc:creator>
      <pubDate>Wed, 29 Jan 2025 17:31:42 +0000</pubDate>
      <link>https://dev.to/verax5/sse-service-side-events-example-to-update-a-table-46m1</link>
      <guid>https://dev.to/verax5/sse-service-side-events-example-to-update-a-table-46m1</guid>
      <description>&lt;p&gt;If you need to make constant calls to server to fetch data (ie. for SPA app), instead of making the call over and over again you can implement Server Side Socket.&lt;/p&gt;

&lt;p&gt;Server side socket is a listener/route/endpoint on server (ie php/laravel app) that runs a while loop constantly querying DB and returning the info in JSON.&lt;/p&gt;

&lt;p&gt;Once you implement this you can make a call from frontend to the backend.&lt;/p&gt;

&lt;p&gt;This call creates CONSTANT socket/steam connection to backend endpoint. ie. backend.com/file-status&lt;/p&gt;

&lt;p&gt;This frontend is contantly listening for an update from backend.&lt;/p&gt;

&lt;p&gt;When update comes from backend, the frontend stream code echoes it.&lt;/p&gt;

&lt;p&gt;Useful when there’s other services/code/crons that might be populating the backend, so whenever backend updates, the data is returned.&lt;/p&gt;

&lt;p&gt;This is opposite of a normal http connection where FRONTEND doesn’t even know that backend data has been updated until is explicitly make the request!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function filesStatus($clientId) {
    $resp = new StreamedResponse();
    $resp-&amp;gt;setCallback(function() use($clientId){
        while(true) { // Keep connection alive
            $data = ClientLink::where('client_id', $clientId)-&amp;gt;get();
            echo "data: " . json_encode($data) . "\n\n"; // Required format
            ob_flush();
            flush();
            sleep(2);
        }
    });

    $resp-&amp;gt;headers-&amp;gt;set('Content-Type', 'text/event-stream'); // Must have to start Server event
    $resp-&amp;gt;headers-&amp;gt;set('X-Accel-Buffering', 'no');
    $resp-&amp;gt;headers-&amp;gt;set('Cach-Control', 'no-cache');
    $resp-&amp;gt;send();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then on frontend we create and Stream connection (as soon as backend return data, stream echoes it on page):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var clientId = document.getElementById('client_id').value;
    var evtSource = new EventSource("/files-status/"+clientId, {withCredentials: true});
    evtSource.onmessage = function (e) {
        let d = JSON.parse(e.data);
        const tb = document.querySelector('#files tbody');
        tb.innerHTML = '';

        d.forEach(function(item){
            var data = `&amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;&amp;lt;a href="${item.link}" target="_blank"&amp;gt; ${item.link}&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.download_status}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.upload_status}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.filename}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.last_download}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.last_upload}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.last_download_file_hash}&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;${item.last_upload_file_hash}&amp;lt;/td&amp;gt;

                &amp;lt;td&amp;gt;
                    &amp;lt;form method="POST" action="/re-download/${item.id}"&amp;gt;
                        {{ csrf_field() }}
                        &amp;lt;button type="submit"&amp;gt;Download&amp;lt;/button&amp;gt;
                    &amp;lt;/form&amp;gt;
                &amp;lt;/td&amp;gt;

                &amp;lt;td&amp;gt;
                    &amp;lt;form method="POST" action="/upload/${item.id}"&amp;gt;
                        {{ csrf_field() }}
                        &amp;lt;button type="submit"&amp;gt;Upload&amp;lt;/button&amp;gt;
                    &amp;lt;/form&amp;gt;
                &amp;lt;/td&amp;gt;

                &amp;lt;td&amp;gt;
                    &amp;lt;form method="POST" action="/delete-link/${item.id}"&amp;gt;
                        {{ csrf_field() }}
                        &amp;lt;button type="submit"&amp;gt;Delete&amp;lt;/button&amp;gt;
                    &amp;lt;/form&amp;gt;
                &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;`;

            tb.innerHTML += data;
        });
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Why I don’t buy into “Self explanatory code”</title>
      <dc:creator>Sami supreme</dc:creator>
      <pubDate>Fri, 15 Sep 2023 18:58:34 +0000</pubDate>
      <link>https://dev.to/verax5/why-i-dont-buy-into-self-explanatory-code-24oc</link>
      <guid>https://dev.to/verax5/why-i-dont-buy-into-self-explanatory-code-24oc</guid>
      <description>&lt;p&gt;I think most people would be blown away once they see how heavily complex codebases are commented.&lt;/p&gt;

&lt;p&gt;I don’t buy into “Your code should be self explanatory” and the reasoning for that is once we start adding business insights into codebase, it loses half its meaning.&lt;/p&gt;

&lt;p&gt;The code can’t talk back to us and tell why certain things are behaving in certain way. No matter how “clean” we keep it. We can’t always add meaning to it.&lt;/p&gt;

&lt;p&gt;So for me, “WHY” something was done in certain way is absolutely critical before I can add any new features or refactor it.&lt;/p&gt;

&lt;p&gt;I know “WHAT” I need to do if requirements are clear but from what I’ve seen most codebases rarely answers “WHY” unless someone has been kind enough to leave comments.&lt;/p&gt;

&lt;p&gt;What I’ve also seen is as the code becomes more and more complex, the developers who maintain it tend to add as many comment as possible, not for future developers but for themselves (tests are not a replacement for comments, sorry!).&lt;/p&gt;

&lt;p&gt;I guess it goes to show that even people who regularly maintain it need additional comments to make sense of their own code as the complexity grows.&lt;/p&gt;

&lt;p&gt;I don’t think a function, class name, variable, how things are connected can ever give you a full picture.&lt;/p&gt;

&lt;p&gt;For context I’m working on an invoice management software and there’s no way it would’ve continued making sense without meaningful comments.&lt;/p&gt;

&lt;p&gt;Even though the “code” itself is quite clean the insights/comments and tests have become essential for proper development.&lt;/p&gt;

&lt;p&gt;Maybe this problem is specific to certain type of software!&lt;/p&gt;

</description>
      <category>cleancode</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>5 methods I personally use to fix bugs</title>
      <dc:creator>Sami supreme</dc:creator>
      <pubDate>Tue, 01 Aug 2023 17:26:44 +0000</pubDate>
      <link>https://dev.to/verax5/5-methods-i-personally-use-to-fix-bugs-5908</link>
      <guid>https://dev.to/verax5/5-methods-i-personally-use-to-fix-bugs-5908</guid>
      <description>&lt;p&gt;BUGS &amp;amp; more bugs in your code!&lt;/p&gt;

&lt;p&gt;Bugs will happen whether you like it or not.&lt;/p&gt;

&lt;p&gt;But it pays off to know the type of bugs they are.&lt;/p&gt;

&lt;p&gt;External bug in an API/service your system relies on?&lt;/p&gt;

&lt;p&gt;A syntax bug?&lt;/p&gt;

&lt;p&gt;A logical bug?&lt;/p&gt;

&lt;p&gt;A bug caused by server itself?&lt;/p&gt;

&lt;p&gt;The list goes on. But that’s really the first step. You must know the type of bug you’re dealing with!&lt;/p&gt;

&lt;p&gt;That out the picture here’s 5 methods I use personally:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Dig deeper into system’s architecture.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pretty simple but without having broad understanding of the system you’ll struggle to find or fix the bug in a reasonable way. There’s a time when you should narrow down vs think broadly. &lt;/p&gt;

&lt;p&gt;Do both, you can think in details but you can’t think broadly without understanding the system. Thinking broadly means you’re less likely to break other parts of the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Clear mental model of the bug/issue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When issues are reported they don’t have all the information from the beginning. Often, they’re written badly. It’s your job to understand the problem fully, line by line and create a solid mental model of the problem. This is better than having to visit the issue 20 times in 30 mins because you keep forgetting the details. &lt;/p&gt;

&lt;p&gt;Simply put, you need your own version of the issue/bug. How you understand it, not how someone else is framing it. Onto next step…&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Take a walk but know where your goal really is.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The step #2 is very important. Simply going for a walk doesn’t magically solve problems. You have to know the goal and every single detail about the bug. &lt;/p&gt;

&lt;p&gt;Once it’s in your head you’re free to go for a walk or make yourself a coffee. With everything absorbed in your brain, let it solve the bug in more relaxed way. Chill down now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Time does the trick&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Very easy to get frustrated but ultimately being patient pays off, if you put in enough time to resolve a bug, you’ll likely succeed. Every developer knows this! If not today, tomorrow!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Code isolation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your code is tightly coupled, you won’t be able to focus on portions of it. If you can isolate class/function from rest of the code, you’ll resolve the issue more easily. This works because instead of thinking about 50 different files you’re focused on 2-3 files. &lt;/p&gt;

&lt;p&gt;It’s easier said than done. Writing classes in a way where it accepts other objects as dependency help a lot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://samidev.gumroad.com"&gt;Check out my books&lt;/a&gt; 🙂&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What do employers look for in candidate when hiring?</title>
      <dc:creator>Sami supreme</dc:creator>
      <pubDate>Fri, 12 May 2023 22:01:20 +0000</pubDate>
      <link>https://dev.to/verax5/what-do-employers-look-for-in-candidate-when-hiring-46oi</link>
      <guid>https://dev.to/verax5/what-do-employers-look-for-in-candidate-when-hiring-46oi</guid>
      <description>&lt;p&gt;Most employers that I’ve spoken say following: &lt;/p&gt;

&lt;p&gt;People with most experience are generally the favorites. Capability is the key.&lt;/p&gt;

&lt;p&gt;So if you have worked on complex projects over the years and dug into the details, fixed the bugs, refactored the code, made changes on regular basis, wrote unit tests, added new features then you have gained the experience and made yourself capable.&lt;/p&gt;

&lt;p&gt;Note how I didn’t say anything about how you did that, as long as you did it.&lt;/p&gt;

&lt;p&gt;Experience can be gained by working for yourself as long as it matches the work you’d be doing if you were working for a company.&lt;/p&gt;

&lt;p&gt;The tricky part is finding what to work on.&lt;/p&gt;

&lt;p&gt;Do this: Pick a project that’ll take atleast 3-4 months to complete.&lt;/p&gt;

&lt;p&gt;This is the trick.&lt;/p&gt;

&lt;p&gt;(If you’re beginner then you’re better off working your way through basics. Couple months in you will have to pick a project aswell)&lt;/p&gt;

&lt;p&gt;Big projects will give you real experience.&lt;/p&gt;

&lt;p&gt;REAL EXPERIENCE!&lt;/p&gt;

&lt;p&gt;Download source code of an existing project written in language of your choice and make it work locally.&lt;/p&gt;

&lt;p&gt;Make a list of features project has. &lt;/p&gt;

&lt;p&gt;Understand each feature. Each functionality, add details to each step and create Jira ticket. &lt;/p&gt;

&lt;p&gt;Once you’ve got the tickets ready you’re ready to build an exact same project yourself.&lt;/p&gt;

&lt;p&gt;That’s the secret. Yup.&lt;/p&gt;

&lt;p&gt;That’s the way to fill your CV with lots of experience.&lt;/p&gt;

&lt;p&gt;You’ll also be able to talk about it because you actually built it all. No gimmicks.&lt;/p&gt;

&lt;p&gt;This will teach you exactly what real life experience teaches.&lt;/p&gt;

&lt;p&gt;This will also teach you to take accountability for your code.&lt;/p&gt;

&lt;p&gt;Lastly you’ll learn to work on things that you don’t understand, exactly like in a real job.&lt;/p&gt;

&lt;p&gt;If you get stuck, look at the source code, the downloaded source code will act as a Senior Dev ready to guide you, if that’s not enough use ChatGPT to explain the code.&lt;/p&gt;

&lt;p&gt;Best of luck!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>career</category>
    </item>
  </channel>
</rss>
