<?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 moo on Medium]]></title>
        <description><![CDATA[Stories by moo on Medium]]></description>
        <link>https://medium.com/@devdotpy?source=rss-16ce135dfa1f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Mx977R9ptO5r_Vc8vDeOgg.jpeg</url>
            <title>Stories by moo on Medium</title>
            <link>https://medium.com/@devdotpy?source=rss-16ce135dfa1f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:25:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devdotpy/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[My Most Prideful Project]]></title>
            <link>https://devdotpy.medium.com/my-most-prideful-project-c7b8f5d1546e?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7b8f5d1546e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Sat, 21 Sep 2024 16:50:01 GMT</pubDate>
            <atom:updated>2024-09-21T16:50:01.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSH9ZGl_dgHDGn3JJ9q0fg.png" /></figure><p>There’s always that one project you remember fondly from your early programming days — a Discord bot, a Chrome extension, or perhaps your first HTML “website” (guilty as charged). These small projects often hold sentimental value, but for me, there was a long stretch of time where nothing stuck. My projects ended up as forgotten folders on my computer, lacking the passion to see them through.</p><p>Then Laravel came along…</p><p>I stumbled upon Laravel out of sheer curiosity, eager to explore how people built web apps outside the JavaScript maze. It opened up a world of possibilities. Whatever I envisioned, Laravel had me covered.</p><p>I began following a course on Laracasts, marking the start of my journey into building meaningful applications. Finally, I was creating things that motivated me to learn more and engage with the community.</p><p>Since I started developing with Laravel, I found myself spending less time watching YouTube tutorials and more time writing code and diving into the comprehensive documentation — truly a gift.</p><p>The course guided me to build a job board, which turned out to be quite rewarding, though I had low expectations. The real prize was the development process itself. The course is, in my opinion, the perfect starting point for anyone; it covers the framework’s basics thoroughly, complete with practical use cases.</p><h3>Early Projects</h3><p>I dedicated time to refining the job board, and I’m quite pleased with how it turned out. You can check it out on <a href="https://github.com/EngMohammedKareem/JobBoard">GitHub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMwjajQpCYShww2k5tcZ3w.png" /></figure><p>After that, I decided to experiment with Livewire — essentially React for PHP. I created a simple journaling app that allowed users to write about their day and rate it, helping them keep track of what made them happy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t03W2loBn-bHEQT2wx1iJQ.png" /></figure><p>But now, let’s talk about my latest project ✨.</p><h3>The Project Begins</h3><p>While browsing YouTube, I found a video and realized I’d been enjoying Laravel for three months of consistent learning. I thought, “Why not spend an hour building a little blog web app?”</p><p>In just two hours, I had a functional CRUD app for posts and comments, complete with authentication. But I wanted more…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TOQPmV2vLwTwE1RH" /><figcaption>the first version of the app</figcaption></figure><h3>Adding Features to My Blog</h3><p>I quickly discovered how simple it was to add features. The first was a search bar to look up published posts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1xcweiB6ll8HvWwzNziNHQ.png" /></figure><p>Next, I implemented a <strong>follow/unfollow</strong> feature. This required more thought, as it involved setting up many-to-many relationships and a pivot table to track followers. Now, users can see every post from every user by default, but by following someone, their feed is customized to show only that user’s posts</p><h3>First Major “Wow” Moment with Laravel — User Profiles</h3><p>Installing Laravel Breeze introduced a dashboard view, which sparked my interest in modifying it. After tinkering with the database models (adding bio and username columns), I successfully created a user profile system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRrjuMF6OBeO7z7yrQp_Jw.png" /></figure><h4>Shortly after, I tackled the ability to search for users by their username. Thanks to Laravel and Eloquent, this was remarkably simple:</h4><pre> public function search(Request $request)<br>    {<br>        if (request(&#39;username&#39;)) {<br>            $users = User::where(&#39;username&#39;, &#39;like&#39;, &#39;%&#39; . request(&#39;username&#39;) . &#39;%&#39;)-&gt;get();<br>            return view(&#39;users.search&#39;, [&#39;users&#39; =&gt; $users]);<br>        }<br>        return view(&#39;users.search&#39;);<br>    }</pre><h3>Enhancing Profiles</h3><p>What’s a profile without a profile picture? I delved into Laravel’s file storage documentation and learned how to implement image uploads. Thanks to Laravel Breeze, most of this functionality was generated automatically; I just had to refine the form and backend logic.</p><h3>Adding Notifications</h3><p>I realized this blog would be lengthy if I detailed every development step, so I focused on features that truly excited me — like notifications. Laravel provides several types, including email notifications (which my app sends upon signup), database notifications (which show on the frontend), and third-party channels.</p><p>I created a sleek notification screen using Tailwind CSS and spent a day debugging a strange issue that was resolved in an unexpected way — sometimes, just undoing changes works wonders!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QPh5eOgCXwsu1diI" /></figure><h3>Final Thoughts and Future Plans</h3><p>This project has transformed me, instilling confidence and pushing me beyond my comfort zone. Future features I plan to implement include:</p><ul><li>User followers/following screens</li><li>Modals to view post likes and navigate to profiles</li><li>A report feature</li><li>Admin accounts</li><li>Markdown support (partial)</li><li>Full CRUD for comments and replies</li><li>A landing page</li><li>Social media login/signup (GitHub and Google)</li></ul><p>All this was accomplished in just one week! Laravel made this dream a reality, and I’m excited to revisit my old projects for a full facelift soon.</p><p>I firmly believe Laravel is the right tool for my journey. I respect everyone’s choice of tech stacks, but I can confidently say that giving Laravel a chance can be life-changing.</p><p>If you’re interested in my project, <a href="https://github.com/EngMohammedKareem/Justablog">Justablog</a> is available on GitHub. I’m continually committing to it and would love feedback from anyone interested in Laravel or experienced developers.</p><p>Happy coding, everyone!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7b8f5d1546e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Is The Way To Go — And Here’s Why ]]></title>
            <link>https://devdotpy.medium.com/laravel-is-the-way-to-go-and-heres-why-bb666825a471?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb666825a471</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[webdev]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Thu, 19 Sep 2024 00:31:39 GMT</pubDate>
            <atom:updated>2024-09-19T15:35:58.783Z</atom:updated>
            <content:encoded><![CDATA[<h3>Laravel Is The Way To Go — And Here’s Why 🚀</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A6gF3azr7u3DtXlj-tMdSg.jpeg" /></figure><p>I’ve long heard the refrain of “PHP is bad” echoing through online discussions since I started programming. I never bothered to explore it until three months ago, and now I have so much to share with you all.</p><h4>What Do I Find in Laravel That I Never Found in JavaScript? 🤔</h4><p>As you may know, I primarily blogged about JavaScript and its ecosystem. However, I often struggled to transform my ideas into fully realized projects. Some might say that’s on me for not working hard enough, which I don’t entirely disagree with. But when I discovered Laravel, I found that my ideas could come to life more easily, thanks to the framework’s extensive features right out of the box.</p><h4>Database Configuration 💾</h4><p>With Laravel, setting up a database is seamless. You can use a literal SQLite file with zero configuration. Just start coding! If you’re using a solution like XAMPP, which comes with phpMyAdmin, your setup is even easier. Just uncomment some environment variables, and you’re good to go.</p><h4>MVC Architecture 📐</h4><p>Laravel embraces the MVC architecture, which is a natural fit for web applications. Think about it: a web app is essentially a sophisticated database interface. It uses logic to determine how data is presented to users. In this setup:<br>- <strong><em>Model</em></strong>: Holds the data.<br>- <strong><em>View</em></strong>: Displays the data.<br>- <strong><em>Controller</em></strong>: Organizes the interaction between the model and the view.</p><p>This structure just makes sense!</p><h4>Eloquent ORM 🌟</h4><p>One of the most beautiful features of Laravel is Eloquent ORM. It allows you to interact with your database without writing raw SQL. Your joins and filtering become incredibly straightforward:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6194f4a9c76d52285582a3840efea04/href">https://medium.com/media/f6194f4a9c76d52285582a3840efea04/href</a></iframe><h4><strong>A Vibrant Ecosystem 🌍</strong></h4><p>The Laravel ecosystem is nothing short of vibrant and robust. With tools and packages like **Laravel Forge** for server management and **Laravel Envoyer** for deployment, you have everything you need to build a full-fledged application without reinventing the wheel.</p><ul><li><strong><em>Authentication:</em></strong> Implementing user authentication is a breeze with — Laravel Breeze<strong><em>.</em></strong> It provides a clean and simple starting point for building authentication features, allowing you to focus on your app’s unique functionality.</li><li><strong>Social Authentication</strong>: Want to add social login/signup? **Socialite** has you covered. With just a few lines of code, you can enable functionality for almost any provider in seconds, streamlining user onboarding.</li><li><strong><em>Payment Processing</em></strong>: Need to handle payments? **Laravel Cashier** simplifies subscription billing and invoicing, letting you focus on your business logic rather than payment complexities.</li><li><strong><em>Inertia.js</em></strong>: Want a modern single-page application experience? Inertia.js seamlessly integrates with Laravel, allowing you to build reactive applications using Vue.js or React while keeping the server-side benefits of Laravel.</li></ul><h4>Powerful Artisan ⚙️</h4><p>One of Laravel’s standout features is **Artisan**, its command-line interface. Artisan makes it incredibly easy to scaffold various components of your application. Want to create a new model, controller, or mail class? Just run commands like:</p><p>php artisan make:model Post<br>php artisan make:controller PostController<br>php artisan make:mail WelcomeEmail</p><p>This rapid scaffolding allows you to focus on building your application instead of setting up boilerplate code.</p><h4>Intuitive Configuration ⚙️</h4><p>Laravel’s configuration files are also super intuitive and easy to set up. Whether it’s file storage, database connections, or mail settings, you can manage everything from the `config` directory.</p><p>After a simple configuration inside your env file, you’re now able to send email using mailtrap.io (Sending emails is one of my favorite parts of using Laravel) The setup is incredibly straightforward. If I want to send a welcome email when a new user joins the app, it only takes a few lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc73cf2742efa3089f05c64bff866a2/href">https://medium.com/media/6dc73cf2742efa3089f05c64bff866a2/href</a></iframe><h4>Battery-Included Framework 🔋</h4><p>Laravel is truly a “battery-included” framework. It comes with everything you need to get started quickly, from routing and middleware to session management and caching. This means you can focus on building your application without worrying about the underlying infrastructure. The integrated tools are thoughtfully designed, ensuring that they work seamlessly together.</p><h4>The Documentation 📚</h4><p>I can’t express how rich, informative, and easy-to-understand Laravel’s documentation is. It’s a walk in the park to implement features without getting lost in YouTube tutorials or endless Medium articles. (I may never recover from saying that!)</p><h3>Conclusion 🎉</h3><p>Overall, my experience has been phenomenal. I’ve felt like I’ve been in coding heaven for the past three months, and I can’t wait to continue learning and building with Laravel. Everything makes sense, tasks are easy to execute, and there’s a clear consensus on best practices.</p><p>I’ll be sharing a lot of Laravel content on this blog to document my journey and showcase projects I’ve completed. I hope some of you will find it interesting!</p><p>Happy coding! 🎈</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb666825a471" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Pretend To Be Hackers With Shell Scripting]]></title>
            <link>https://blog.devgenius.io/lets-pretend-to-be-hackers-with-shell-scripting-113c47554e1?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/113c47554e1</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 11:53:02 GMT</pubDate>
            <atom:updated>2022-08-09T18:13:12.790Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings nerds 👋 i recently grew very bored and decided to write real code to make fake programs, if that doesn’t make sense, think of (almost) every Hollywood film / tv show that involved hacking stuff</p><p>Now the idea led me to another idea which is adding basic GUI elements to my shell scripts and i cared to share the idea because it’s quite useful and can come in handy for many projects where you want some delightful user interface</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*PQT3s4B6hApbeppN.jpg" /><figcaption><a href="https://image.shutterstock.com/image-photo/young-asian-programmer-working-office-260nw-2129787857.jpg">https://image.shutterstock.com/image-photo/young-asian-programmer-working-office-260nw-2129787857.jpg</a></figcaption></figure><p><strong><em>A brief introduction to zenity</em></strong></p><p><a href="https://help.gnome.org/users/zenity/stable/">Zenity</a> is a useful utility that helps us add GUI widgets to our shell scripts to add more interactivity to them and allow an average user to interact with the program</p><p>I believe the description is enough to interest you and to serve our purpose so let’s dive right in and pretend to be super hackers 😎</p><p><strong><em>Zenity widgets</em></strong></p><p>There are <a href="https://help.gnome.org/users/zenity/stable/">plenty of really useful widgets</a> included so i will choose as much as i can and hopefully leave you with enough knowledge to explore the rest</p><p>Some examples of the widgets are shown below and they’re the ones we’ll be using in this dummy project so stay tuned</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*DeFp_nLZ154Yg5zBF60qcA.png" /><figcaption>entry widget to take user input</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*_fiaLTrvq8ey2G2bedSvDA.png" /><figcaption>calendar widget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*WTRWtdbrapQH1SW6NQBbWQ.png" /><figcaption>error message</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*J3jwShqO4VO5YJ-rk1OvRw.png" /><figcaption>info widget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/169/1*G3E3bf3eY2_y_zBJFWGQwg.png" /><figcaption>warning widget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*MczkMVcp-mQolhdx6EExoA.png" /><figcaption>text info widget used to display all sorts of content including a webpage or a file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*8BfQSZEw49bI7m1djocOBA.png" /><figcaption>progress indication</figcaption></figure><p>And many more you could find on <a href="https://help.gnome.org/users/zenity/stable/">their website</a> or simply running zenity --help once you’ve installed zenity</p><p>ALL the widgets are customizable in terms of their size using the --height and --width options</p><p>To get help just run zenity --help it’s so so useful and run zenity --help-warning or any other widget to get specific help for that widget</p><p><strong><em>Installing zenity for your distro</em></strong></p><p>So I’m using ubuntu but it’s gonna be the same for the other distros as per your package manager so to install zenity we simply run sudo apt install zenity</p><p><strong><em>What we’re building today and how</em></strong></p><p>So our fake hacking tool is a discord IP resolver, basically you give it a discord user ID, which we can obtain if we have developer mode enabled, and the tool should give you that user IP address — trust me it would work on some high school skids-</p><p>So the plan is as follows</p><ol><li>View a dummy user agreement which we’ll create with html</li><li>Prompt the user to enter the target user ID</li><li>throw in a bunch of bull 💩 using lolcat — a very cool utility-</li><li>Show some dummy progress bar as if the tool was doing stuff</li><li>Show a success message……yeah it serves the plot fr</li></ol><p><strong><em>Step one : creating the license agreement thingy</em></strong></p><p>Just jump to Vscode and create an index.html and throw in the following nonsense i made using the “lorem” trick in Vscode</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;LICENSE&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;DISCORD IP PULLER LICENSE AGREEMENT&lt;/h1&gt;<br>    &lt;p&gt;<br>        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Hic, ullam ab voluptatibus exercitationem iure ratione ea at quisquam, quidem ma&gt;<br>    &lt;/p&gt;<br>    &lt;i&gt;<br>        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Cupiditate ex ducimus eaque nulla blanditiis distinctio, iure cumque dolorem nem&gt;<br>    &lt;/i&gt;<br>    &lt;br&gt;&lt;br&gt;&lt;br&gt;<br>    &lt;b&gt;&amp;copy; 2022 | DISCORD IP PULLER&lt;/b&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong><em>Viewing our widget</em></strong></p><p>Now to use zenity widgets, in this case our text info widget, we’ll run</p><pre>zenity --text-info --filename=&quot;./index.html&quot; --html --height=500 --width=500 --checkbox=&quot;I READ AND ACCEPT THE TERMS AND CONDITIONS&quot;</pre><p>--html to enable html rendering</p><p>--filename to specify our html file</p><p>--checkbox to add a checkbox so the user can say they read and accepted the license to proceed further</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*AOP3twlYv2hAffoppLRW_w.png" /></figure><p><strong><em>Step two : taking user input using entry widget</em></strong></p><p>This is relatively simple, we’ll use an entry widget to take user input and store it in a variable so to do that</p><pre>set TARGET_ID (zenity --entry --text=&quot;ENTER USER ID&quot; --height=150 --width=300)</pre><p><em>As you know i only use fish shell now hence the variable assignment syntax</em></p><p>Now we have the returned valued of our entry widget stored in our TARGET_ID variable to use in our script</p><p><strong><em>Step three : having fun with lolcat and other widgets</em></strong></p><p>lolcat is a Ruby gem used to colorize your terminal output like rainbows, to install it you first need to install Ruby — it’s already on many linux distros- and then run gem install lolcat and it can give you output like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3WM0pyjKIRLpek5bJCO7Sg.png" /></figure><p>Pretty sweet right ? It’s mostly used in many tools to make them look more cool and appealing to non programming people and it’s so simple to use</p><p>Just pipe any command into lolcat and watch the magic and rainbows 🌈</p><p>Another personal favorite flag is the -a to add animation to the output</p><p>Now back to our script, we now need to print some real nonsense and of course spice it up with lolcat so i decided to add this fun part</p><pre>for i in (seq 1 50)<br>  echo &quot;intercepting packets to obtain $TARGET_ID ip address...&quot; | lolcat<br>  if test $i -gt 20<br>    set_color -o brred<br>    echo &quot;IP ADDRESS PULLED......&quot;<br>  end<br>end</pre><p>Nothing too fancy, just a little loop to simulate some work in progress</p><p><strong><em>Step four : adding a little progress bar and final touches</em></strong></p><p>Now let’s add what appears to be a progress indicator because cmon it looks super cool so please type with me</p><pre>begin<br>  for i in (seq 1 10 100)<br>    echo $i<br>    sleep 1<br>  end<br>end | zenity --progress --text=&quot;REPORTING BACK TO THE CNC SERVER&quot; --percentage=0 --auto-close</pre><p>Again, this is a fish shell syntax, we’re simply using the begin and end keywords to use a code block, which is basically a block of code whose output we can pipe into a progress bar widget because trust me that’s how it works i don’t know how but yeah 👍</p><p>We use the --auto-close so the progress automatically closes when the the counting has finished</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*Z2T5GeihxPuRFCluOJyUog.png" /></figure><p>Now a little final message to confirm our amazing hack has completed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*PjR0_LIGs8dDHgLKdB0u4A.png" /></figure><p>And the code to go with it</p><pre>zenity --info --text=&quot;IP ADDRESS HAS BEEN SUCCESSFULLY PULLED AND REPORTED BACK&quot; --height=150 --width=250</pre><p><strong><em>Adding a banner for our script</em></strong></p><p>You know how many of those hacking scripts has that fancy ascii art like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*yQKAsNfAm7b0r48x2ZikAw.png" /></figure><p>We’re gonna use a handy tool called figlet which helps us generate this ascii art so to install it sudo apt install figlet and you can man figlet to figure out how it works</p><p>So let’s add a silly banner I’m gonna call the tool “Cypher” named after the cyber terrorist from Fast &amp; Furious 8</p><pre>set_color -i green<br>figlet &quot;CYPHER&quot;<br>set_color -o green<br>echo &quot;<br>  A blazingly fast tool to resolve any Discord user ID into an IP address<br>  by : G3tPwn3d<br>  version: 1.0<br>  Github_repo: soon!</pre><pre>***INSTRUCTIONS***<br>  1- Go to your discord settings<br>  2- Look for &quot;developer mode&quot; and enable it<br>  3- Go to integrations then webhooks and create one<br>  4- Copy the link<br>  5- Go to your target and right click on their name<br>  6- Click &quot;copy ID&quot;<br>***USAGE***<br>  simply run ./discord_ip_puller</pre><pre>&quot;</pre><p>I added some instructions to it looks cooler and more legit</p><p><strong><em>The final script</em></strong></p><p>Now that we concluded this fun and interesting tutorial I’m going to leave the full script down below for those lazy nerds to copy and paste, i hope you’ll enjoy it and feel free to add your own touch to it or maybe add more functionality</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9cbe7fba52a9fe851cdb60c47abb78f6/href">https://medium.com/media/9cbe7fba52a9fe851cdb60c47abb78f6/href</a></iframe><p>Happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=113c47554e1" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/lets-pretend-to-be-hackers-with-shell-scripting-113c47554e1">Let’s Pretend To Be Hackers With Shell Scripting</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Download Memes And Tiktoks Using Fish Scripting]]></title>
            <link>https://blog.devgenius.io/download-memes-and-tiktoks-using-fish-scripting-e430fbddf744?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e430fbddf744</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Fri, 05 Aug 2022 15:25:28 GMT</pubDate>
            <atom:updated>2022-08-29T06:43:29.096Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings nerds 👋 today we’re gonna learn how to download content from the web, specifically reddit as it’s very easy to “hack around’ as a dev, so if you’re looking to download memes to post later to your discord server or watch random tiktoks, this blog’s for you</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*ckgECDbzKS43ztr1" /><figcaption><a href="https://media.istockphoto.com/photos/friends-watching-smartphone-content-in-the-street-picture-id1066622066?k=20&amp;m=1066622066&amp;s=612x612&amp;w=0&amp;h=FHqqjEfbu-qbEGZWX6Kz1OBMr5B37U_eJ3mZcaHSAvs=">https://media.istockphoto.com/photos/friends-watching-smartphone-content-in-the-street-picture-id1066622066?k=20&amp;m=1066622066&amp;s=612x612&amp;w=0&amp;h=FHqqjEfbu-qbEGZWX6Kz1OBMr5B37U_eJ3mZcaHSAvs=</a></figcaption></figure><p><strong><em>On today’s menu</em></strong></p><ul><li>Download images from reddit using curl</li><li>Download videos using the amazing youtube-dl</li><li>And lastly using crontab to schedule posting to our server</li></ul><p>Without any further boilerplate let’s get to it</p><p><strong><em>Using curl and wget to download content from the web</em></strong></p><p>In today’s episode of terminal kicks 🍑 we have a powerful command line tool called wget which we can use to download videos and images from the web if we provide it any URL or a file with a list of URLs , pretty cool right ?</p><p>You can use it to download images from reddit or any other source if you’ve the image link so we’ll simply gonna download some memes from r/memes and you’ll see it’s so simple</p><pre>curl -s -A &quot;cute bot&quot; <a href="https://reddit.com/r/memes/top.json">https://reddit.com/r/memes/top.json</a> | jq &#39;.&#39;</pre><p>Here is a neat trick to obtain any subreddit content in JSON format, you can also do /subreddit/hot.json , /subreddit/new.json or specify a limit with ?limit= which only returns 101 results max, next we pipe the output to jq for pretty parsing</p><p>Now open the link in your browser to see the JSON structure as I’ll extract only the links containing either jpg , png or gif as they’re the only ones we see from the response</p><pre>curl -s -A &quot;handsome boy&quot; <a href="https://www.reddit.com/r/memes/hot.json">https://www.reddit.com/r/memes/hot.json</a> | jq -r &#39;.data.children[].data.url_overridden_by_dest&#39; | grep -Eoh &quot;https:\/\/\i\.\w+\.\w+\/\w+(\.jpg|\.gif|\.png)&quot;</pre><p>Please check out <a href="https://blog.devgenius.io/youll-learn-regex-after-reading-this-bb80e915e391">my blog</a> on regular expressions if that didn’t make any sense to you</p><p>Now let’s wrap it in a nice for loop to download all the extracted links using wget , so our script now should look like this</p><pre>#!/usr/bin/env fish<br>for meme in (curl -s -A &quot;handsome boy&quot; <a href="https://www.reddit.com/r/memes/hot.json">https://www.reddit.com/r/memes/hot.json</a> | jq -r &#39;.data.children[].data.url_overridden_by_dest&#39; | grep -Eoh &quot;https:\/\/\i\.\w+\.\w+\/\w+(\.jpg|\.gifv|\.gif|\.png)&quot;)<br>   wget $meme<br>end</pre><p>And just like that we downloaded every meme in the hot section of r/memes</p><p><strong><em>Downloading videos using curl and youtube-dl</em></strong></p><p>If you didn’t know — which is quote unfortunate to say the least —<a href="https://github.com/ytdl-org/youtube-dl"> youtube-dl</a> is an amazing and quite popular command line utility used to download videos from multiple sources including youtube of course, combined with our shell scripting we’re gonna extract video links from r/tiktokcringe and download them using the <a href="https://github.com/ytdl-org/youtube-dl">youtube-dl </a>utility</p><p>Firstly, let’s see how those links look like so we write a proper regex</p><pre>curl -s -A &quot;handsome bot&quot; <a href="https://reddit.com/r/tiktokcringe/top.json?t=week">https://reddit.com/r/tiktokcringe/top.json?t=week</a> | jq &#39;.data.children[].data.url_overridden_by_dest&#39;</pre><p>That will get us the top posts of the week, you can use day , month or year</p><p>Judging by the output it appears that we don’t need a regex in this case because we don’t need to filter out any content so we’ll proceed to download those links</p><pre>#!/usr/bin/env fish</pre><pre>for video in (curl -s -A &quot;handsome boy&quot; <a href="https://www.reddit.com/r/memes/hot.json">https://www.reddit.com/r/memes/hot.json</a> | jq -r &#39;.data.children[].data.url_overridden_by_dest&#39;<br>   wget $video<br>end</pre><p>And now you have your tiktoks in your current directory</p><p><em>Homework: make the script more interactive by prompting the user to enter an output directory</em></p><p>This concludes our blog for today i hope you all learned a thing or two and if you liked it please hit the 👏 down below</p><p>Happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e430fbddf744" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/download-memes-and-tiktoks-using-fish-scripting-e430fbddf744">Download Memes And Tiktoks Using Fish Scripting</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Learn Fish Scripting ]]></title>
            <link>https://blog.devgenius.io/lets-learn-fish-scripting-1d66928ebd2f?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d66928ebd2f</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Sun, 31 Jul 2022 12:05:28 GMT</pubDate>
            <atom:updated>2022-08-01T20:07:06.761Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings nerds 👋 have you wanted to customize your developer experience in the terminal even more ? Wanted to level up your scripting game AND still have fun ? If yes then i hope you’ll find this blog useful 🙌</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gYpUP0PZHh20nGuJ.png" /><figcaption>https://fishshell.com/</figcaption></figure><p><strong><em>So what the fish is going on ?</em></strong></p><p>I previously shared a <a href="https://medium.com/geekculture/bash-scripting-for-dummies-5d855cbada66">blog</a> about bash scripting and how it can really make your life easier but let’s be honest for a sec……you def find yourself wanting to commit 🪢 every time you run into some variable expansion stuff or forgot the comparison operators or wuteva that you’re having</p><p>I remember finding <a href="https://www.youtube.com/watch?v=ux1SP9B5lSQ">this video</a> which i personally found so so much fun and promising and i decided to finally try out <a href="https://fishshell.com/"><strong><em>the fish</em></strong></a></p><p><strong><em>But what’s wrong with bash ?</em></strong></p><p>You see, bash is amazing and all that but it’s really easy to grow frustrated with it especially when the bug was something so simple as i stated above</p><p>For example, if you wanted to change your shell prompt inside bash you’d have one ugly confusing line to format the color and font like this `\e[0;32m[\u@\h \W]\$ \e[0m just to change the color to green and show your username and working directory</p><p>Meanwhile in fish all you gotta do is override a builtin function like this</p><pre>function fish_prompt; set_color green;echo &quot;$USER@$PWD 😎 &quot;; end</pre><p>So you see, things could be way simpler and more fun, especially for those newly coming to Linux world</p><p><strong><em>Installing a cool 🍑 terminal (optional)</em></strong></p><p>If you’ve made it this far you def have a terminal but there is a really cool terminal i came across it’s called <a href="https://alacritty.org/">alacritty</a> and I’ve been in love so let’s install it too</p><p>sudo add-apt-repository ppa:aslatter/ppa &lt;- add the repo<br>sudo apt update &lt;- run updates<br>sudo apt install alacritty &lt;- installing it<br>alacritty -v &lt;- view the version to make sure it installed</p><p>This is a screenshot from my own alacritty and how it looks with fish shell</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NdOMQSm0D_MbsVeuPkzxHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZ2cGaXFCYUvIC8Uw9ScMg.png" /></figure><p><strong><em>Installing fish</em></strong></p><p>Installing this shell is so easy and straightforward so according to their repo you install it by running these commands</p><pre>sudo apt-add-repository ppa:fish-shell/release-3<br>sudo apt update<br>sudo apt install fish</pre><p>Then, in your terminal run fish to get in the shell</p><p><strong><em>Writing your first fish script — kind of —</em></strong></p><p>I’m not gonna bore you out with what scripting is blah blah blah, instead we’re focusing more BUT NOT ENTIRELY on what makes fish scripting way simpler and where does it stand out so expect me to bundle up multiple concepts at once</p><p><strong>Setting up variables and using them</strong></p><p>In fish, it’s very simple to declare variables and <em>unlike other shells </em>there isn’t a variable=value syntax so the way to do that is by using the keyword set</p><p>set girl &#39;Isla 🥺&#39;<br> echo &quot;$girl&quot;</p><p>Nothing much changed except the cleaner way of declaring variables instead of losing your sanity bcz you forgot to stick the equal sign right in between</p><p>So the syntax is set name value</p><p><strong>Lists in fish</strong></p><p>In fish, it’s important to utilize lists in many areas, for example $PATH in most shells is a colon separated list like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl9f6njVzrx2t6wBp2CxkQ.png" /></figure><p>But in fish it’s actually a list and it can be accessed using indices that start at one — i know, quite disgusting to the point i physically slapped my forehead when i found out —</p><p>This is $PATH inside fish shell and how we can access elements</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmsMK6GShDdypCkl-Z-rYg.png" /></figure><p><strong>Looping and conditionals</strong></p><p>Pretty basic stuff except for few handy tweaks thanks to fish shell so let’s see examples</p><p>Let’s see how the range based for loop works first</p><pre>for i in (seq 20)<br>    echo &quot;i love fish&quot;<br>end</pre><p>This is a much neater way to iterate over a range and it can be configured more to specify start, end, increment like so</p><pre># specify the start and end<br>for i in (seq 2 30)<br>    echo &quot;$i&quot;<br>end <br># specify the increment value<br>for x in (seq 1 2 40)<br>    echo &quot;$x&quot;<br>end</pre><p>An if statement changed a little — no weird fi at the end so yay — and the new test operator that solves so many problems when it comes to comparisons as in those examples</p><pre># comparing numbers</pre><pre>echo &quot;enter your age plz: &quot;<br>read age<br>if test $age -ge 18<br>    echo &quot;welcome aboard&quot;<br>else<br>    echo &quot;you&#39;re too young to be here&quot;<br>end</pre><pre># comparing strings -there is a catch-</pre><pre>echo &quot;what&#39;s your name: &quot;<br>read username<br>if test &quot;$username&quot; = &quot;$USER&quot;<br>  echo &quot;welcome back sir&quot;<br>else<br>  echo &quot;hello $username, nice to meet you&quot;<br>end</pre><p>The more you practice the more you’ll get used to using test</p><p>Let’s see the amazing switch/case now</p><pre>switch (uname)<br>case Windows<br>    echo &quot;gross plz fuck off&quot;<br>case Linux <br>    echo &quot;based asf&quot;<br>case Darwin<br>    echo &quot;a chad too&quot;<br>end<br></pre><p>Important takes, no more weird esac at the end and no need for the break keyword if you’re used to another programming languages</p><p><strong><em>Functions in fish</em></strong></p><p>It’s no surprise how crucial functions are in programming and fish is no different than other scripting languages so let’s see how are functions in fish are different</p><pre>function myfunc<br>    echo &quot;arguments passed: $argv&quot;<br>end<br>myfunc red green blue #arguments passed: red green blue</pre><p>Unlike other shells like bash, fish treats the arguments passed to the function as a list which you can access with indices — again that start at 1 for some God damn reason omg —</p><p>You can also view built in functions by typing functions then ENTER</p><p><strong><em>Spicing up our prompt</em></strong></p><p>As i mentioned earlier in this blog, changing your shell prompt is so easy and customizable so let’s find out how and break it down bcz i wanna point out super cool stuff about fish</p><p>So in your terminal just type</p><pre>function fish_prompt; set_color -o -i red;echo &quot;$USER@$PWD 💻 &quot;; end</pre><p>Now let’s explain what’s goin on</p><ol><li>function fish_prompt everything in fish is a function pretty much and here we’re just gonna change a built in function to code our own, this function is interesting bcz it’s so simple, all it does is using the output of it to change the prompt so whatever you type in will be your new prompt</li><li>set_color is another amazing function that helps us change text color, it changes the text that follows it and here we’re using the -i flag to enable italic font and the -o to enable bold font, for more info on it or any function please use man</li><li>semicolons is just a way to drop down a line whilst staying on one line</li></ol><p>This is how my prompt now looks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*FBrsSomSHGdxj4Q9YGiz9A.png" /></figure><p>If you wanna have a prompt on the right, just use fish_right_prompt instead oof the one above and tweak it as you like</p><p><strong><em>Math in fish</em></strong></p><p>Math operations in fish are incrediby simple and intuitive, thanks to a built in function called math which we can invoke and follow it by a math expression</p><pre>math 1 + 2 # 3<br>math 40 - 10 # 30<br>math 30 &#39;*&#39; 3 # you have to escape the asterisk bcz it&#39;s an operator in fish by using quotes or \<br>math 50 / 10 # 5</pre><p><strong><em>Command substitution in fish</em></strong></p><p>When you’re writing your scripts you’ll 99% need to assign the output of a variable to a command output, for example curl response so how do we do that in fish ? Simple as hell just look</p><pre>echo i am currently at (pwd)<br>echo i am running (uname)</pre><p>Yeah so that’s about it and why i think fish is so damn cool and fun for scripting, if you’re using fish or were inspired to start using it and love something else about it, please share it in the comments and I’ll be more than happy to explore it too</p><p>Happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d66928ebd2f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/lets-learn-fish-scripting-1d66928ebd2f">Let’s Learn Fish Scripting 🐟</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started With The Twitch API]]></title>
            <link>https://blog.devgenius.io/getting-started-with-the-twitch-api-855d481471b4?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/855d481471b4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[twitch]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 12:57:11 GMT</pubDate>
            <atom:updated>2022-07-25T20:12:35.314Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings nerds 👋, I recently started enjoying tinkering around with the Twitch API and I thought it’s worth sharing with you guys so you can build your next project powered by Twitch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U3LF6M18fHZKdMNl" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>THE TWITCH API IN DEPTH</strong></p><p>Twitch offers a variety of APIs with specific services they provide so to have a better look at the available options please check <a href="https://dev.twitch.tv/docs/api/">this link</a>, To follow along with me you’ll really need to refer to <a href="https://dev.twitch.tv/docs/api/reference">this link</a></p><p><strong>FIRST OFF LET’S CREATE A TWITCH APPLICATION</strong></p><p>In order for us to use the APIs, we need to create an application so we can obtain the credentials needed to make requests to their endpoints</p><p>The process is quite easy so let’s get to it without wasting any more time</p><ul><li>head to <a href="https://dev.twitch.tv/">Twitch developers portal</a> and at the top right corner click login with twitch</li><li>click on “your console” at the same location</li><li>find and click “register your application” and you should be presented with this form</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UKV5fFCEc9mVyCHgaIvegA.png" /></figure><p>For the Oauth redirect, it can be honestly any link because we’re not implementing any login with the twitch feature, and for the category you can pick “chat bot”</p><ul><li>now with all that set, you should now see your client id and client secret when you click on your application and in the next part we’ll get our oauth token which is an important part of the authentication process</li></ul><p><strong><em>Getting our OAuth token</em></strong></p><p>Before this part, let’s set up our development environment which is going to be minimal as we’re not really building anything specific</p><ul><li>terminal — duh</li><li>curl installed</li><li>jq as it will help us parse the response into beautifully formatted json</li></ul><p>Now we can launch our terminal and start slapping some commands in 😝</p><p>To get an OAuth token we need to make a POST request to https://id.twitch.tv/oauth2/token with the following parameters in the body</p><ol><li>client_id which you can get from your twitch dev console</li><li>client_secret same as above</li><li>grant_type which should be set to client_credentials</li></ol><p>Now to formulate such request using curl it should look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VdRG5Nv_uTjJ-kaGXfC1hg.png" /></figure><p><em>of course I’m deleting this application before i publish this so don’t ever think ;)</em></p><p>Now that we have our bearer token / OAuth token and our client id, we can have a look at few endpoints :)</p><p><strong><em>Getting top games now</em></strong></p><p>If we look at the <a href="https://dev.twitch.tv/docs/api/reference">API reference </a>we could search so many endpoints and each one has super detailed instructions and examples so we’ll pick two endpoints just because this blog is all about the “getting started” part so you get to experiment on your own</p><p>To get the top games for now we’ll make this request</p><pre>curl  <a href="https://api.twitch.tv/helix/games/top">https://api.twitch.tv/helix/games/top</a> -H &quot;Authorization:Bearer &lt;your oauth token&gt;&quot; -H &quot;Client-Id:&lt;your client id&gt;&quot; | jq &#39;.data[]&#39;</pre><p>Since all endpoints return a JSON response inside an array named data , we pass this to jq and now let’s see the response and see how to access inner properties using jq</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPf3mR5Cc5MU1Xvv5NWSrw.png" /></figure><p>Now this is a very elegant response and so easy to parse so let’s access the name property for instance</p><pre>curl  <a href="https://api.twitch.tv/helix/games/top">https://api.twitch.tv/helix/games/top</a> -H &quot;Authorization:Bearer &lt;your oauth token&gt;&quot; -H &quot;Client-Id:&lt;your client id&gt;&quot; | jq &#39;.data[].name&#39;</pre><p>Pretty simple right ? If you’ve done any javascript and parsed JSON, this is gonna be super familiar to you</p><p><strong><em>Getting information about a specific game</em></strong></p><p>Now we’ll request this endpoint `https://api.twitch.tv/helix/games and supply it with the ID of a game from our previous response, Dota 2 for instance, and see what info we get back</p><pre>curl <a href="https://api.twitch.tv/helix/games?id=29595">https://api.twitch.tv/helix/games?id=29595</a> -H &quot;Authorization: Bearer &lt;oauth token here&gt;&quot; -H &quot;Client-Id:&lt;your client id&gt;&quot; | jq &#39;.&#39;</pre><p>and the response should be similar to this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*bSEf1kFfQA2zq-H92KOe6A.png" /></figure><p>This should be enough to start working with the Twitch API as the authentication and authorization process was a bit tricky to some newbies but the documentation is quite rich in content so don’t ignore it</p><p>Thanks for showing interest in my blog and having the time to read this far, happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=855d481471b4" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/getting-started-with-the-twitch-api-855d481471b4">Getting Started With The Twitch API</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You’ll Learn Regex After Reading This]]></title>
            <link>https://blog.devgenius.io/youll-learn-regex-after-reading-this-bb80e915e391?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb80e915e391</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[regex]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Tue, 12 Jul 2022 10:58:29 GMT</pubDate>
            <atom:updated>2022-07-14T16:38:58.584Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s no surprise to any beginner / intermediate programmer that seeing stuff like this ^[\w]+#[\d]{4}$ will freak them out and make them wish they’d never touched a computer before</p><p>I myself have never grown the ⚽⚽ to really learn regex and have always found it so so confusing, reading tutorials and watching videos didn’t help any so i kept ignoring the subject and doing anything to avoid touching regex</p><p>This all changed two days ago when i found <a href="https://youtu.be/bgBWp9EIlMM">this treasure of a video</a> that changed my mind completely and i still feel i learned so much from one simple video that i ever had, so i thought it’s time i hopefully inspire others to learn regex as well and truly enjoy the so much power it brings you</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*fMl70HAb-s1aXNGA" /><figcaption>source : unsplash</figcaption></figure><p><strong>WHAT’S REGEX AND WHY DO I NEED IT ?</strong></p><p>Regex is text pattern matching that helps us match pieces of text according to a pattern we specify using special operators, so arranging those regex operators in a way to do any text processing task you could imagine</p><p>Examples include : email validation, phone number validation, postal code validation, credit card validation, etc etc……</p><p><strong>HOW ARE WE GONNA LEARN REGEX ?</strong></p><p>As in <a href="https://youtu.be/bgBWp9EIlMM">the video</a> that inspired this blog, we’re gonna use <a href="https://www.debuggex.com/">this online tool</a> to help us test and visualize our regex in real time, it’s an amazingly great tool to learn since we can see our mistakes as well as finding out why such pattern worked</p><p>We’re gonna build few examples to learn as much regex as we need to start and it’ll be just enough for now until we run into super complex stuff</p><ul><li>phone number example</li><li>email example</li><li>price tag example</li><li>discord username example</li><li>DD/MM/YYYY date format example</li></ul><p>Now let’s begin to learn</p><p><strong>OUR CHEATSHEET</strong></p><ul><li>^ beginning of a line</li><li>$ end of the line</li><li>[] grouping — basically means “ranges” like [a-z], [0–9]</li><li>{} means how many times you’d like this pattern to occur</li><li>? one or zero times aka optional operator</li><li>+ at least one or more times, basically means i don’t care how many time this pattern occurs</li><li>* zero or more times</li><li>\w will match every letter, number and underscore</li><li>\d will match single digits only</li><li>\s space</li><li>\t tab</li><li>/ escape special characters — in case we wanna match an actual dollar sign for example</li></ul><p><strong>LEARNING THE BASICS</strong></p><p>So now let’s use those available operators to match very simple pieces of text</p><p>So the most basic regex we can write is the text itself ! suppose you wanna extract a name for example “Bridget”, you can literally write Bridget so let’s jump to our online tool and find out</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*I4aoXulvzv_BZlxLKqrf4w.png" /></figure><p>See ? We matched that exact pattern but that’s boring isn’t it, let’s throw in some basic operators this time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCgypu1qzt3BCUdZVPcc5Q.png" /></figure><p>Don’t panic 😄 there’s nothing fancy going on at all there, so our pattern now says “start the line, find Bridget, close the line”, as discussed earlier the carrot ^ means the line begins with……everything that follows and the $ means the end of the line, so again, <em>find me this pattern where the line starts with the word Bridget and the line ends</em></p><p><strong>USING GROUPING TO ADD MORE FLEXIBILITY</strong></p><p>OK so now our regex only matches this one word…..but what if we wanna match more ? We’re not gonna write every name are we 😂</p><p>For that we’re gonna use the square brackets to use grouping, which means find me a pattern that consist of this group of letters or numbers or special characters, so let’s write a regex that simply matches any given <strong>first name </strong>then we’ll extend it to include more words separated by spaces basically to simulate a full name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uslNDDE8iBo_PS3lPiNFiQ.png" /></figure><p><strong><em>HMMMMMM </em></strong>that’s strange now, i wonder why doesn’t it work 🤔</p><p>So to clarify the mistake i purposely made above, let’s see what the pattern means, inside our square brackets we specified the letters a-z meaning <strong>ONLY SMALL LETTERS </strong>meanwhile our Bridget has a capitalized first letter so let’s add capital letters to our pattern as well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LD2PmKtZds0m8GZ5Iczc9w.png" /></figure><p>And now our regex is ready to match any word……but let’s try to break it shall we 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCP-4SnkJ4Y7oRIPQfynRQ.png" /></figure><p>Now why doesn’t it work ? Doesn’t it match small and capital letters already ?</p><p><strong>EXTENDING OUR REGEX TO INCLUDE FURTHER WORDS</strong></p><p>Regex matches an exact pattern, which means word by word so what i mean is, this pattern matches a single word since we basically provided a <strong>single word + space + single word </strong>and that’s basically how every regex works so let’s repeat the same exact pattern but for a second word</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fjxnLNM_ZS-_zK7fgbgWpA.png" /></figure><p>Now pay attention to the visualization and how we now have two “blocks” basically, it simply says, <strong>find me this pattern where there is a small or a capital letter infinitely followed by a space followed by the same pattern for the block prior</strong></p><p><em>quick note, English is my second language so my explanation can be a little misunderstood or inaccurate so please pardon me, I’ll try to explain as simple as possible and provide visuals</em></p><p><strong>PHONE NUMBER EXAMPLE</strong></p><p>Now that we know some regex let’s try to validate a phone number, so a US phone number consists of 3-digit area code followed by another 3 digits that represent a central office, followed by 4digits that represent the subscriber number so it should look like <a href="https://fakenumber.org/generator-us/usa202-555-0160">202–555–0160</a> ( a fake number btw ) and we’ll include the dashes too 👀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ea-ASgtJTr9Lr4t8MeDgpA.png" /></figure><p>See how easy it is now :) isn’t regex so much fun so far 😍, notice how we simply added the dashes as they don’t represent anything in regex so they’re treated literally as they look, you notice how we so far “draw” how our data should look like ? I really hope it clicked :)</p><p><strong>PRICE TAG EXAMPLE TO LEARN TO ESCAPE SPECIAL CHARACTERS</strong></p><p>Suppose you’re scraping amazon and want to extract a price for a product with the dollar sign, but but the $ is already a regex operator so how do we go around that ? Let me show you it’s so easy really</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tuBNy6FCBHGjQo6FB3g2Cw.png" /></figure><p>voila ✨ we simply needed was the forward slash \ to tell our regex that “hey we need the actual dollar sign too and not to end the line here”</p><p>But what if the price in question is a whole number ? Wouldn’t that break our pattern ? Well yes it sure will but I’m here to help you 😎</p><p><strong>USING THE ? OPERATOR TO INDICATE OPTIONAL</strong></p><p>We’re gonna use the question mark ? operator to tell our regex that this is optional, so in our case we want to make the floating part optional because maybe the price is 17$ so how do we do that ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pJcnVGhOCZ17BGNJHQxx2w.png" /></figure><p>You see when we use the ? operator <strong>to the right </strong>of the desired “rule” it then becomes optional, so in our example we tell our regex that <strong>it’s optional to find one or more number from 0–9 and a dot</strong></p><p>Btw the dot is also a regex operator so we needed to escape it</p><p><strong>EMAIL VALIDATION</strong></p><p>Now we’re gonna do a classic regex which is validating an email address but bear in mind that this is pretty basic as i imagine real production level regex patterns will be far more complex but we’re just tinkering around for fun :)</p><p>This example will demonstrate how can we add more than just numbers and letters to our group</p><p>For the sake of this example we’ll allow letters, numbers, dashes, underscores, periods, and the forward slash but you can add every single special character on your keyboard as well</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCNcXkSs_HZ6aWgYunZVnw.png" /></figure><p>See you can add whatever special characters you want as long as they’re being properly escaped in case of being actual operators</p><p><strong>EXCLUDING A PATTERN USING THE ^ OPERATOR</strong></p><p>I forgot to mention that the carrot operator ^ can be used to exclude items if used inside the square brackets so let’s use an example where we don’t allow gmail accounts for instance so how do we do that ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBhoJCB02vLuEZ_6bXWSmg.png" /></figure><p>And just like that we successfully applied an exclusion, btw you can add more exclusions like {^yahoo}[^gmail][^hotmail] and so on then follow it with the allowed patterns</p><p><strong>DISCORD NAME VALIDATION</strong></p><p>OK for those unfamiliar, <a href="https://discord.com/">discord</a> is a messaging app for mobile and desktop, it’s common among gamers and nerds in general ( myself included 😏)</p><p>A discord username is composed of a regular username followed by a # sign and four digits, so for instance unicorn#1111, it allows any unicode characters and for our example we’re gonna use the same pattern as in our email example for simplicity but you get the idea</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JWV7aRdYVjy9c9PqPGkBg.png" /></figure><p>Nothing new about this example at all huh</p><p><strong>DD/MM/YYYY DATE FORMAT EXAMPLE</strong></p><p>I think you’re already visualizing your regex in your head now 😉 but let’s find out how to pull this off which should be so easy since we’ve done similar stuff earlier</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0av23SRzv5r9OsJMivo9aA.png" /></figure><p>Note : It’s a very basic regex and can be easily hacked / tricked so as a homework try to make it a more precise regex</p><p>Now that we’re done with our examples, you now know just enough regex for many tasks or at least start to research more as it won’t seem like gibberish to you anymore……hopefully</p><p><strong>DON’T FORGET TO PRACTICE ON THE ONLINE TOOL, PRACTICE IS EVERYTHING SO PLEASE SOLVE AS MANY EXAMPLES AS YOU CAN AND CHALLENGE YOURSELF IT’S THE ONLY WAY TO MASTER REGEX</strong></p><p>I hope you had as much fun as i did and may you have a pleasant day / night ♥️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb80e915e391" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/youll-learn-regex-after-reading-this-bb80e915e391">You’ll Learn Regex After Reading This</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Are .env Files And How Should I Use Them ? And Why ?]]></title>
            <link>https://blog.devgenius.io/what-are-env-files-and-how-should-i-use-them-and-why-5fdb1d228016?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fdb1d228016</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Sun, 10 Jul 2022 22:05:11 GMT</pubDate>
            <atom:updated>2022-07-11T16:43:49.130Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Are .env Files And How Should I Use Them ? And Why ?</h3><p>When deploying your web app / project online, the last thing you’d want is to have sensitive information leaked such as some auth tokens or api keys etc etc</p><p>So this begs the question : <strong>how can i secure sensitive data my program needs ?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*xF6vqnl8hdtrm9rm" /></figure><p>Now to answer your question we first need to know what are <strong><em>environment variables</em></strong></p><p><strong>ENVIRONMENT VARIABLES</strong></p><p>Now as usual I’ll quote parts of wikipedia then I’ll tell you what you need to know for our context</p><blockquote>An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer</blockquote><p>Basically, an environment variables is just a regular variable that your system needs rather than a program……I’ll explain further</p><p>We know that a variable is simply a piece of data that our program needs, for example a variable to store a name so we can greet that name, now put in that way, the program itself needs that variable and nothing else, only that one specific program</p><p>Meanwhile an environment variables as the name suggests, is needed by the environment itself AKA your operating system !</p><p>You know how an operating system has a giant giant biggggg libraries and pieces of software it needs to run to maintain the system, those programs often need some info about the system itself and they’ll definitely change how a certain system program behaves</p><p><strong>HOW CAN I SEE MY ENVIRONMENT VARIABLES ? (Linux)</strong></p><p>Did you know you could view your current environment variables on your local system ? Linux for example keeps track of a heap of those and we can view them with the command env and to print any of them we simply use echo followed by a $[VARIABLE] so to print your current shell just type echo $SHELL</p><p>Notice the naming convention where you need to use uppercase letters for your environment variables</p><p><strong>HOW CAN I ADD MY OWN ENVIRONMENT VARIABLE ?</strong></p><p>So you must be curious to find out how can you add your own environment variables in case you’ll need them in your bash scripts or anything, that’s fairly simple all you need to do is use the set command in the following format export NAME=VALUE so for example export MEOW=simba</p><p>And to view them we use the echo command as earlier, notice that those variables you set this way will only exist in the current user session, in other words once you close the terminal and launch it again they’ll be gone</p><p><strong>JEFF LEAKED HIS API KEY </strong>😱</p><p>So let’s say Jeff has just built the sickest discord bot to tell the weather using node.js and he’s excited to show it off on his github</p><p>But few hours later……. the bot doesn’t return the current weather as it should, hmmm quite odd isn’t it? Jeff goes to the api provider website to check his dashboard and see how much of daily quota he used and……..IT’S GONE BUT HOW DID IT HAPPEN</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FyvBAuESRTsETqNFlEl%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FyvBAuESRTsETqNFlEl%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FyvBAuESRTsETqNFlEl%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/03aee298eba703d4cf480571d3d6f892/href">https://medium.com/media/03aee298eba703d4cf480571d3d6f892/href</a></iframe><p>When Jeff deployed the the project to his Github repo he forgot to hide his weather api key, an api key is used to authenticate the user and ensures they don’t use the resources way too much, So Jeff enabled anyone viewing the code to see his api key and use it in their own app, eventually abusing the key and running Jeff out of his daily usage</p><p><strong>HOW CAN WE NOT END UP LIKE JEFF</strong></p><p>Trust me you don’t wanna be like Jeff, you’ve got to protect your api keys or auth tokens or any piece of authentication info that should only be used by YOU and ONLY YOU so how do we do that ?</p><p>In this example we’ll assume we’re building some node.js app because you can’t really hide your credentials on the front end, all it takes is checking the network tab and you can see the request headers and bam you’re screwed</p><p>Create a file named .env , yep just an extension without a file name and we’re gonna add our super secret keys</p><pre>API_KEY=&quot;SUPER SECRET API KEY&quot;<br>CONSUMER_KEY=&quot;some other stuff here&quot;<br>OTHER_VERY_SECRET_TOKEN=&quot;blah blah&quot;</pre><p><strong>HOW DO WE ACCESS THOSE VARIABLES</strong></p><p>OK so our keys are hidden, what do we do ? In node we will install a package called dotenv so go ahead and npm i dotenv and now in your script you can access the keys using the process.env like so</p><pre>require(&#39;dotenv&#39;).config();</pre><pre>let api_key = process.env.API_KWY;</pre><pre>// OR YOU COULD ACCESS THEM AS AN ARRAY</pre><pre>let api_key = process.env[&#39;API_KEY&#39;]</pre><p>And just like that, you could safely use your credentials in your script but there’s an extra layer of security required before we could actually share this online — in case of sharing it as a whole project on github for example</p><p><strong>.GITIGNORE FILES</strong></p><p>Now when we usually share a project, say a react app, we need to enable people to clone the repo and start developing locally right ? Well as we mentioned above that the environment variables are crucial to our program because they’re just a secure way to reference our data, so now you might ask yourself……if I’m sharing this whole project to my Github, wouldn’t that expose my credentials too since I’m literally sharing the .env files too ?</p><p>.gitignore file is a file we use to <em>ignore </em>files and directories from being included in our version control aka being pushed to our repo on Github so let’s create one to ignore our .env file and enjoy sharing the sick discord bot on Github without compromising our api keys and stuff</p><p>Create a .gitignore file and add this one line .env and that’s it 🎉 you’ve successfully secured your app now and you should always use this workflow</p><p><strong>A QUICK RECAP</strong></p><ul><li>environment variables are normal variables except they exist and used by our system</li><li>we can create our own environment variables in our programs to avoid hardcoding sensitive information and compromising our apps</li><li>.env files are used to store those variables and they should be written in all uppercase separated with underscores for naming convention</li><li>we access those variables through process.env after installing dotnev npm package</li><li>we use .gitignore file to avoid having our .env files pushed to our repo when we use version control to share on Github</li></ul><p><strong>THANKS SO MUCH FOR READING AND MAKE SURE TO FOLLOW FOR MORE COOL BLOGS, HAVE A LOVELY DAY / NIGHT ♥️</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fdb1d228016" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/what-are-env-files-and-how-should-i-use-them-and-why-5fdb1d228016">What Are .env Files And How Should I Use Them ? And Why ?</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux For Dummies ]]></title>
            <link>https://blog.devgenius.io/linux-for-dummies-f24ecd6c5b61?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f24ecd6c5b61</guid>
            <category><![CDATA[penguins]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Sun, 10 Jul 2022 11:47:23 GMT</pubDate>
            <atom:updated>2022-07-14T16:39:01.024Z</atom:updated>
            <content:encoded><![CDATA[<p>So you’ve probably heard how cool Linux is and people use it and the eternal debate of my operating system is better than yours blah blah blah 🥱 and you wanna give it a go, you wanna see for yourself what’s the hype about Linux and tinker around with it, you’ve come to the right blog……hopefully 😄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*47HbJX-XTrGB2wEI" /></figure><p><strong>FIRST OFF, WHY LINUX ? WHY DO I USE IT ?</strong></p><p>OK this is 100% my own opinion but i hope most of my fellow penguin gang will relate to some of all of it</p><ol><li>Linux is free : unlike Windows, which is the most dominant desktop operating system no doubt, Linux is a free operating system, just pick a flavor of it and download it</li><li>Linux is so “hackable”: since Linux is an open source software, you get to customize <strong>EVERY SINGLE ASPECT OF IT</strong>, whether you wanna create your own desktop widgets or literally inject code into the kernel and run it, everything’s possible with Linux, there is no barrier between you and your dearly beloved Linux ♥️, you can even create your own Linux and distribute it online !</li><li>Security: don’t get me wrong there are recorded vulnerabilities discovered on Linux but you don’t even find an antivirus on Linux….. this is possible due to the concept of privileges on Linux, so to put it simply there is a root account that can do far more privileged actions than a regular user account</li></ol><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0Hlw1wlzvxTvxiZG%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0Hlw1wlzvxTvxiZG%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fl0Hlw1wlzvxTvxiZG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="392" frameborder="0" scrolling="no"><a href="https://medium.com/media/808cb5cddf6d5ad3884ce195b6032665/href">https://medium.com/media/808cb5cddf6d5ad3884ce195b6032665/href</a></iframe><p>4. Amazing tools out of the box: command line tools such as curl, wget make your life easier especially if you’re like me and live in the terminal the whole time and love your sweet little bash scripts</p><p>5. Accounts concept: as explained above, Linux has this great concept which is emphasized greatly and is really useful to organize and limit access to the system</p><p>6. Developer friendly: the flexibility and usability of Linux makes it very developer friendly as everything is easy to set up, you want to start developing in c++ ? just install the g++ compiler and you’re good to go, wanna start using Rust maybe ? just install rustup , Just wanna write your own scripts for your own needs or showing off ? Bash scripting is your best friend, wife and mistress</p><p>And other reasons mainly revolve around transparency and flexibility but i cared to share my very own reasons that keep me going</p><p><strong>HOW DO I GET LINUX ?</strong></p><p>When it comes to Linux, there isn’t really a “Download Linux For Free” link i can provide, however the community has developed over 8000 “flavors” of Linux for several needs ranging from production level cyber security to actual operating system used by the military, just make your choice and download the .iso file and fire up virtualbox on Windows to run the OS in a virtual machine</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJIX9t2j0ZTN9S%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJIX9t2j0ZTN9S%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZ3VsdjN5bHViNWRuM2oyemhlaGg1b3hyaTRrZHY4aXVzMHhsNDd2dSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FJIX9t2j0ZTN9S%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/a511fb273fbe6d94dbd501d00490d73c/href">https://medium.com/media/a511fb273fbe6d94dbd501d00490d73c/href</a></iframe><p><strong>WHICH LINUX DISTRO SHOULD I GET ?</strong></p><p>Honestly I’d suggest Ubuntu as it’s so user friendly and if you’re coming from a Windows background, which you’ll 99.99% be, it’ll be easy for ya to pick up until you’re comfy enough with the “Linux way” of things and you can get another distro / flavor</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3og0ICG4WxdKSRzE3K%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3og0ICG4WxdKSRzE3K%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3og0ICG4WxdKSRzE3K%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d339cf7969223967cccef735d5ca302/href">https://medium.com/media/3d339cf7969223967cccef735d5ca302/href</a></iframe><p><strong>BASIC LINUX COMMANDS</strong></p><p>OK now to the real deal, we’re gonna learn few Linux commands that every average user will find themselves using so let’s learn them and most importantly <strong>PRACTICE THEM</strong></p><ul><li>echo — print to the terminal</li></ul><p>This command prints anything and everything after it just like any other print function in your favorite programming language</p><p>Example: echo hello world or you could add double quotes echo &quot;hello world&quot;</p><ul><li>pwd — print working directory</li></ul><p>This command, as the name suggests, tells you which directory you’re in</p><p>- ls — listing</p><p>Now that you know where you are, you might as well wanna find out what files or directories are in your current location, For that we use the ls command, but this command is mostly used with “flags” for much better results such as ls -la this command will not only show you the files and directories but even the hidden ones and the permissions associated with them, more on that later</p><ul><li>cd — change directory</li></ul><p>Now you wanna move inside a directory of your choice so you use the cd command to do so, simply cd followed by the directory name so for example cd Downloads will move us into the Downloads directory</p><ul><li>mkdir — make directory</li></ul><p>Now you might wanna create your own directory in your current location or somewhere else, simply use mkdir followed by the directory name and voila ✨ you have a new directory, example mkdir exercises</p><p>If you add a dot before the directory name, such as mkdir .secrets it’ll create a hidden directory only visible using ls -la and it could be helpful</p><ul><li>touch — creating files</li></ul><p>To create empty files in your current directory, any file you want really just use it followed by the file name like so touch index.js then open it with your preferred text editor</p><ul><li>rm — remove file or directory</li></ul><p>Now you wanna remove a file from your system because you don’t need it or something like that, to remove a file simply rm followed by the file name such as rm index.js and it’ll be removed immediately</p><p>Now to remove a directory, we can’t just rm that bad boy like how we did with files, instead we need to add a couple more flags to indicate that we want to remove a directory recursively and it looks like this rm -rf node_projects so the command will remove the directory and its contents</p><ul><li>chmod — change the mode</li></ul><p>OK time for real penguin 💩 so if you view contents of a directory you’re gonna find some weird letters to the left</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/0*PQmqtKqH4Bhcrv1l" /><figcaption>source: how-to-geek</figcaption></figure><p>So we have a -followed by three “chunks” of letters and each chunk has three letters as well so what are they ?</p><p>The very first character indicates whether this a file or a directory so a - means a file and the letter d means a directory as in the pic below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*-SNRBe55K0mx1e5M.png" /><figcaption>source: LinuxForDevices</figcaption></figure><p>Now let’s talk about those three segments of letters</p><ol><li>the first segment is the “user” permissions which means the very person who made the file / directory</li><li>second is the “group” permissions which means user accounts we create and add to a group on the system</li><li>third is the “other” permissions</li></ol><p>Now moving to the actual permissions in each segment</p><p>r means read, being able to read the file or view it</p><p>w means write to the file or edit it</p><p>x means execute the file, or run it</p><p>As an average Linux user like myself, you only care about those regardless of who can do what, i.e no need to worry if the group can execute the file or not, so now when you see -rw-r--r-- it means we can <strong>read </strong>and <strong>write </strong>to that <strong>file</strong></p><p>So the chmod command changes those permissions to what we desire and in most if not all the cases you’ll need chmod 777 or chmod +x which makes the file executable so we can run it like like ./FILE</p><p>The command is so often used when creating shell scripts and you wanna execute them</p><ul><li>sudo — execute as root</li></ul><p>Often times in Linux you’re gonna run into an error that says “permission denied” and that’s because most commands in Linux require <strong><em>root privileges </em></strong>but what the heck does that mean ? It’s Linux way of enforcing security in a way by distributing permissions as we mentioned earlier, so the sudo command helps us run a command as root if we’re just a regular user</p><p>For example the apt update command is used to update your system repositories in order to download packages and it needs root to modify some system files so running apt update will cause an error Permission denied so we use sudo apt update then it’ll ask us for our root password and if correct it’ll run the command</p><ul><li>su — switch user</li></ul><p>Used to switch from regular user to root if you’re lazy and don’t wanna type sudo before most things and enter your password every time</p><ul><li>man — manual page</li></ul><p>Now this is the king of all commands, whenever you’re lost and have no idea how to use <strong>ANY </strong>command on your Linux, simply run man followed by the command name, example man sudo man mkdir</p><p>This should be more than enough to start having fun with your Linux box and I’ll bring you more Linux fun if you guys seem to enjoy this blog ♥️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f24ecd6c5b61" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/linux-for-dummies-f24ecd6c5b61">Linux For Dummies 🐧</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Use Templates In Your Express.js App ?]]></title>
            <link>https://blog.devgenius.io/how-to-use-templates-in-your-express-js-app-3ff9f4607423?source=rss-16ce135dfa1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ff9f4607423</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[moo]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 23:23:46 GMT</pubDate>
            <atom:updated>2022-07-08T07:39:29.911Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Use Templates In Your Express.js App ?</h3><p>Have you ever thought to yourself “what if i built a massive web app and now i need a profile page for every single user 😨” or maybe you need to view a page for every piece of news on your web app ?</p><p>There are plenty of other scenarios too where you wanna think of a way to simply render the same page for different content <strong>AND IN THIS ARTICLE I HAVE THE ANSWER TO THAT QUESTION 😅</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*erZxdpkk6qEnaLLP.jpeg" /></figure><p><strong>LETS BRIEFLY TALK ABOUT TEMPLATE ENGINES</strong></p><p>So what the 🦆 is a template engne anyway ? And what problems does it solve me ? So according to the<a href="https://expressjs.com/en/guide/using-template-engines.html"> express.js documentation</a></p><blockquote>A <em>template engine</em> enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page.</blockquote><p>So it allows us to pass arguments to pre-defined templates of our own, it also supports logic like conditionals, filtering and all that stuff so you have great control over the data</p><p><strong>WHAT TEMPLATE ENGINE SHOULD I USE ?</strong></p><p>Honestly there are plenty of choices and among them are</p><ul><li>Pug</li><li>Jade</li><li>Ejs</li><li>Mustache</li></ul><p>And many others you can look at <a href="https://expressjs.com/en/resources/template-engines.html">here</a>, for this tutorial i picked the easiest option which is <a href="https://pugjs.org/api/getting-started.html">Pug</a>, it has great features and the template language itself is easy peasy 🍋 squeezy</p><p><strong>SETTING UP A PROJECT AND INSTALLING PUG</strong></p><p>As per every node / express project the steps are simple</p><p>make a new directory and navigate into it with mkdir express_templates &amp;&amp; cd express_templates</p><p>initialize a new project with the defaults using npm init --y</p><p>Then just install Pug using npm npm i pug</p><p>We’ll also need nodemon to save time so npm i --save-dev nodemon</p><p>And let’s write some puggggggg code 😉</p><p><strong>SET UP OUR EXPRESS APP TO WORK WITH PUG</strong></p><p>This is extremely simple but just cared to to have it in a separate section you know</p><p>Add this to your express code after requiring Pug itself app.set(&#39;view engine&#39;, &#39;pug&#39;); this will tell express to look out for .pug files to use for rendering templates and by default it’ll look inside a directory called views so please go ahead and make that directory as we’ll create our first template</p><p><strong>WRITING OUR FIRST PUG TEMPLATE</strong></p><p>So in your views directory create a new file and name it home.pug now this .pug extension says that this is a pug file so it has a tiny bit different syntax than html BUT TRUST ME it’s just as easy</p><p>Paste in this code please</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4303921047627498db1223c121ee7a54/href">https://medium.com/media/4303921047627498db1223c121ee7a54/href</a></iframe><p><strong>INDENTATION IS IMPORTANT, </strong>anyway so let’s see what does this mean exactly, think of Pug files as html files but with variables and stuff, because that’s literally what a template is, it helps us pass arguments and do programming stuff inside the file, so this tells us that the title tag in our file equals a variable called title and then we see an h1 tag but the value of the text to it equals a variable called message</p><p>So how the heck do we pass those arguments ?</p><p><strong>PASSING ARGUMENTS TO OUR TEMPLATE FILES</strong></p><p>Now that we have our template ready, next thing to do is actually pass these arguments to the .pug file which is also dummy easy</p><p>We’ll create a route so it renders our template like so :</p><pre>app.get(&quot;/&quot;, (req,res) =&gt; {<br>    res.render(&#39;home.pug&#39;, {<br>        title: &#39;welcome to pug&#39;,<br>        message: &#39;this is soooooo pug 😜&#39;<br>    })<br>});</pre><p>So to pass arguments we simply supply a second argument to the render() method which is an object that maps to those variables in the template file, that’s it really</p><p><strong>LETS WRITE JAVASCRIPT INSIDE OUR PUG 😍</strong></p><p>OK so Pug allows us to write inline javascript in our very own .pug for logic purposes of course so let’s write basic stuff</p><p>To write javascript we must begin the line with - a dash, and watch for the indentation as it matters, so add this right below our h1</p><pre>- const user = {name: &quot;Cecelia&quot;, age:18,country: &quot;Italy&quot;}</pre><pre>h2= user.name</pre><p>And now you can write any javascript you want and interact with the data too</p><p>Important thing to note, <strong><em>the javascript we get to write is node.js code and not your usual browser DOM javascript</em></strong></p><p>In other words, alert,prompt,confirm and browser web APIs are invalid and we can confirm this by simply writing — console.log(&quot;which console tho&quot;) now if you open up your browser devtools you won’t find anything logged BUTTTTT if you check out your terminal you’re gonna find it logged there</p><p><strong>CONDITIONALS IN PUG</strong></p><p>So let’s write a little conditional that if Cecelia is a javascript developer she’s assigned some cute emoji next to her name, and if she’s not…….let’s find out 😉</p><pre>- const user = {name: &quot;Cecelia&quot;, age:18,country: &quot;Italy&quot;, preference: &quot;javascript&quot;}</pre><pre>- if(user.preference === &quot;javascript&quot;)</pre><pre>  h1 #{user.name} 😽</pre><pre>- else</pre><pre>  h1 #{user.name} kiss this 🐸</pre><p>Pretty fun right ? Notice how the indentation here matters since we have an else block so that’s why i always recommend to use the indentation to avoid most errors</p><p><strong>INTERPOLATION IN PUG</strong></p><p>I know i know, what a fancy word 🇬🇧 but let’s explain it, it means “combining” variables with normal strings, we saw it earlier when we gave Cecelia a frog, notice how i didn’t add an equal sign because i wasn’t essentially assigning a value to a tag</p><p>This is a more fun example</p><pre>- let currentDateTime = new Date().toLocaleString()</pre><pre>h2 Current date and time is: #{currentDateTime}</pre><p>Notice how we use this #{} syntax to inject variables into our string</p><p><strong>ITERATING OVER ITEMS</strong></p><p>Pug provides a very easy <em>directive </em>to enable us to iterate over any collection so easily without the need to write javascript so let’s see an example of the each directive</p><pre>ul</pre><pre>    each val in [&quot;winter&quot;, &quot;spring&quot;, &quot;summer&quot;, &quot;automn&quot;]</pre><pre>      li= val</pre><p>How fun and easy was that ? We can also use the powerful feature of interpolation like so</p><pre>each lang in [&#39;ruby&#39;, &#39;python&#39;, &#39;javascript&#39;]</pre><pre>    h4 #{lang} is a fun language to learn</pre><p>Voila ✨ now you’re having fun with Pug aren’t you :))</p><p><strong>EXTENDING TEMPLATES</strong></p><p>This is a very important feature of Pug and template engines in general, which is being able to “inherit” a base layout and extend it so let’s create a new template called base.pug</p><p>So the idea is very simple, we have a base layout that has content that has to appear in every other template / page for example a navbar and a footer, and this base template has “blocks” which you can think of as placeholder content we can manipulate in every template <strong>THAT EXTENDS THE BASE TEMPLATE</strong></p><p>Our base.pug will include a depressing navbar because it’s 2 am here and i can’t be bothered, and a footer, it’ll have a block for the title and the content, the “static” content it’ll have is the bootstrap CDN so that way we don’t need to include those annoying links in every template, so let’s get to coding</p><ol><li>our base.pug</li></ol><pre>html <br>  head <br>    block title<br>    link(rel=&quot;stylesheet&quot;, href=&quot;<a href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css</a>&quot;, integrity=&quot;sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3&quot;, crossorigin=&quot;anonymous&quot;)<br>  body.container<br>    navbar<br>      ul<br>        li home<br>        li feed<br>        li shop <br>        li about<br>    block content<br>    footer<br>        p 2022 total nerd</pre><p>I included the bootstrap CDN from their official CDN so that it works on all our templates that extend base.pug</p><p>2. our users.pug</p><pre>extends base.pug <br>blcok title<br>  title users page<br>block content<br>  h1= title<br>  p welcome to the users page</pre><p>As you can see, all you gotta do is fill in the blocks from the base template and voila ✨ you have a whole 🍑 web page</p><p>3. our news.pug</p><pre>extends base.pug</pre><pre>block title <br>    title news page<br>block content <br>    h1 news<br>    p welcome to the news page where you can read the latest news</pre><p>4. our articles.pug</p><pre>extends base.pug</pre><pre>block title<br>  title articles page<br>block content<br>  h1 articles<br>  p welcome to the articles page, enjoy reaading</pre><p>And that’s it, now we can make as many pages as we want with so little code !</p><p><strong>THINGS TO REMEMBER ABOUT INHERITING</strong></p><p>Well just one easy rule of thumb <strong><em>ALWAYS FILL IN THE BLOCKS AND EVERY CONTENT ON THE BASE LAYOUT THAT HAS NO BLOCK KEYWORD, WILL APPEAR ON ALL THE CHILD TEMPLATES</em></strong></p><p>Thanks so so much for reading and i hope you enjoyed this topic and i hope to always bring you interesting topics but please don’t hesitate to leave comments if you have questions or want me to blog about specific topics in the future</p><p>Have a lovely rest of day / night 😗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ff9f4607423" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/how-to-use-templates-in-your-express-js-app-3ff9f4607423">How To Use Templates In Your Express.js App ?</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>