<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdeldjalil</title>
    <description>The latest articles on DEV Community by Abdeldjalil (@zendyani).</description>
    <link>https://dev.to/zendyani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F284466%2Fb5558547-430e-48be-8434-bd57e87db759.jpg</url>
      <title>DEV Community: Abdeldjalil</title>
      <link>https://dev.to/zendyani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zendyani"/>
    <language>en</language>
    <item>
      <title>The Developer's Survival Guide: Keeping Your Skills Sharp in an AI World</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Mon, 23 Sep 2024 15:09:06 +0000</pubDate>
      <link>https://dev.to/zendyani/the-developers-survival-guide-keeping-your-skills-sharp-in-an-ai-world-96o</link>
      <guid>https://dev.to/zendyani/the-developers-survival-guide-keeping-your-skills-sharp-in-an-ai-world-96o</guid>
      <description>&lt;p&gt;Hey there,&lt;/p&gt;

&lt;p&gt;In today's rapidly evolving tech landscape, developers like us are witnessing a massive shift. AI coding tools are popping up everywhere, offering to generate code with just a few prompts. It's like having a supercharged assistant at our fingertips—sounds fantastic, right?&lt;/p&gt;

&lt;p&gt;But let's address the elephant in the room.&lt;/p&gt;

&lt;p&gt;While AI tools can boost productivity, over-reliance on them brings significant challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;High Costs&lt;/strong&gt;: Frequent use of AI APIs can lead to hefty bills.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Insecure and Hard-to-Maintain Code&lt;/strong&gt;: AI-generated code might not follow best practices, leading to security vulnerabilities and maintenance headaches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unrealistic Expectations&lt;/strong&gt;: There's a growing belief that one developer with AI can replace an entire team, piling undue pressure on individuals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Buggy Software Flooding the Market&lt;/strong&gt;: Without proper oversight, AI-generated code can result in software riddled with bugs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here's the kicker: over-dependence on AI can become our Achilles' heel. If we lose access to these tools—due to costs, outages, or other issues—what then? Coding is a skill that thrives on regular practice. Without it, our problem-solving abilities can fade.&lt;/p&gt;

&lt;p&gt;We need to ensure we're leveraging AI as a valuable ally, not becoming dependent on it.&lt;/p&gt;

&lt;p&gt;So, how do we keep our minds sharp, stay creative, and continue to think like innovative developers—even when using AI intensively?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are some actionable ideas:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deep Dive into AI-Generated Code&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Understand the Code&lt;/strong&gt;: When AI provides code, take time to read through it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask Questions&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Why did it generate the code this way?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Is it secure?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Did the AI use the right library?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Is there a simpler way to achieve the same result?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Does it even need to use a library?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Optimize&lt;/strong&gt;: Consider how you might improve or streamline the code.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reflect on Your Work&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Self-Evaluate&lt;/strong&gt;: After completing a task, pause to reflect.

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;What did you learn?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Were there any challenges?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;How can you tackle similar problems more efficiently next time?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Stay Updated with Industry Trends&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Learning&lt;/strong&gt;: Use downtime to read tech blogs or newsletters.

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;What's new in your programming language?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Are there emerging technologies you should know about?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Participate in Code Reviews&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate&lt;/strong&gt;: Engage in code reviews to learn from others and share your insights.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Critical Thinking&lt;/strong&gt;: This practice hones your skills beyond what AI can offer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Limit AI Use for Certain Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Challenge Yourself&lt;/strong&gt;: Handle some tasks without AI assistance.

&lt;ul&gt;
&lt;li&gt;Start small—debugging code or writing simple functions.&lt;/li&gt;
&lt;li&gt;Gradually tackle more complex challenges.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Question the AI's Choices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Evaluate Suggestions&lt;/strong&gt;: Don't accept AI solutions blindly.

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Did the AI use the right library?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Is there a simpler way?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Is the solution efficient and appropriate?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Read Documentation and Short Articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Targeted Learning&lt;/strong&gt;: Focus on documentation and articles relevant to your projects for efficient, immediate application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By incorporating these practices into your routine, you can keep your developer mind sharp without overwhelming yourself. The goal isn't to shun AI tools—they're valuable assets—but to ensure you're still in control and not letting your skills atrophy.&lt;/p&gt;

&lt;p&gt;Remember, the quality of the output depends on the quality of the input. &lt;strong&gt;To get the most out of AI, we need to bring our A-game&lt;/strong&gt;, ensuring we're providing thoughtful prompts and critically evaluating the responses.&lt;/p&gt;

&lt;p&gt;Use AI as a powerful tool, not as a crutch. Maintain your skills, stay curious, and keep pushing the boundaries.&lt;/p&gt;

&lt;p&gt;In the end, the best developers are those who balance leveraging AI with continuous personal growth. So keep questioning, keep learning, and most importantly, keep coding—not because you have to, but because you love to.&lt;/p&gt;

&lt;p&gt;Stay sharp!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. This article was thought up by a human and generated by an AI—proof that when humans and AI team up, we get the best of both worlds (and maybe a few laughs along the way)!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>How to Prevent Infinite Loops in `save_post` Hook in WordPress</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Fri, 06 Sep 2024 17:58:40 +0000</pubDate>
      <link>https://dev.to/zendyani/how-to-prevent-infinite-loops-in-savepost-hook-in-wordpress-1l75</link>
      <guid>https://dev.to/zendyani/how-to-prevent-infinite-loops-in-savepost-hook-in-wordpress-1l75</guid>
      <description>&lt;p&gt;When you use the &lt;code&gt;save_post&lt;/code&gt; hook, you may run into an infinite loop issue. This happens when you try to update the post inside the &lt;code&gt;save_post&lt;/code&gt; action, which re-triggers the hook endlessly. &lt;/p&gt;

&lt;p&gt;To solve this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Hook into &lt;code&gt;save_post&lt;/code&gt;&lt;/strong&gt;: Add your custom function to save the post.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove the Hook Before Updating&lt;/strong&gt;: Before calling &lt;code&gt;wp_update_post()&lt;/code&gt;, temporarily unhook your function to stop it from firing again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Re-hook After Update&lt;/strong&gt;: Once the update is done, reattach the hook.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Final Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;your_custom_save_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$post_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Ensure this only runs once by unhooking&lt;/span&gt;
    &lt;span class="nf"&gt;remove_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'save_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your_custom_save_function'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Update the post without triggering the save_post hook again&lt;/span&gt;
    &lt;span class="nf"&gt;wp_update_post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'ID'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'post_title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Updated Title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="c1"&gt;// Re-hook the save_post action to handle future saves&lt;/span&gt;
    &lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'save_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your_custom_save_function'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Hook into save_post&lt;/span&gt;
&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'save_post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your_custom_save_function'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, you prevent the infinite loop and ensure your updates go through smoothly.&lt;/p&gt;

</description>
      <category>wordpress</category>
    </item>
    <item>
      <title>Python Data Structures Demystified: A Friendly Guide to Lists, Tuples, Dicts, Arrays, and Sets</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Thu, 22 Aug 2024 11:40:48 +0000</pubDate>
      <link>https://dev.to/zendyani/python-data-structures-demystified-a-friendly-guide-to-lists-tuples-dicts-arrays-and-sets-1cd</link>
      <guid>https://dev.to/zendyani/python-data-structures-demystified-a-friendly-guide-to-lists-tuples-dicts-arrays-and-sets-1cd</guid>
      <description>&lt;p&gt;Hey there, Python enthusiasts! 👋 Ever found yourself staring at your code, wondering whether you should use a list, a tuple, or maybe a dictionary? You're not alone! Today, we're going to break down these Python data structures in a way that hopefully makes you go "Aha!" rather than "Huh?". So grab your favorite beverage, and let's dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fantastic Five: Meet Your Data Structure Squad
&lt;/h2&gt;

&lt;p&gt;Python gives us a bunch of cool tools to organize our data, but today we're focusing on the fab five: lists, tuples, dictionaries, arrays, and sets. Each one has its own superpowers, and knowing when to use which can make your code faster, cleaner, and just plain better.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Lists: The Swiss Army Knife 🔪
&lt;/h3&gt;

&lt;p&gt;Lists are like that one friend who's always up for anything. Need to store a bunch of items and maybe change them later? Lists have got your back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;shopping_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;apples&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bananas&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;chocolate&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;shopping_list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Because, priorities!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need a flexible, ordered collection of items&lt;/li&gt;
&lt;li&gt;Your data might change (add/remove items)&lt;/li&gt;
&lt;li&gt;You want to do list-y things like sorting or reversing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pro tip:&lt;/strong&gt; Lists are great for most cases, but they can be memory-hungry with large datasets.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Tuples: The Reliable Ones 🏋️‍♀️
&lt;/h3&gt;

&lt;p&gt;Think of tuples as lists that hit the gym and got super strong. They're immutable, meaning once you create them, they're set in stone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;coordinates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;33.9416&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;118.4085&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# LAX airport coordinates
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have data that shouldn't change (like coordinates)&lt;/li&gt;
&lt;li&gt;You're returning multiple values from a function&lt;/li&gt;
&lt;li&gt;You need a slightly more memory-efficient version of a list&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Fun fact:&lt;/strong&gt; Because tuples are immutable, they can be used as dictionary keys. Try that with a list, and Python will give you the side-eye.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Dictionaries: The Librarians 📚
&lt;/h3&gt;

&lt;p&gt;Dictionaries are like the smart librarians of the Python world. They organize information by keys, making it super fast to find what you need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;book&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;title&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;The Hitchhikers Guide to the Galaxy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;author&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Douglas Adams&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;answer_to_everything&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need fast lookups by a unique key&lt;/li&gt;
&lt;li&gt;You're working with JSON-like data&lt;/li&gt;
&lt;li&gt;You want to associate values with keys (like a real dictionary!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cool trick:&lt;/strong&gt; As of Python 3.7, dictionaries remember the order you put things in. It's like they got a memory upgrade!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Arrays: The Specialized Athletes 🏃‍♂️
&lt;/h3&gt;

&lt;p&gt;Arrays are like lists that decided to focus on one type of data and get really good at it. They're not used as often in everyday Python, but they shine in specific scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;
&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;i&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;# An array of integers
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're dealing with large amounts of numeric data&lt;/li&gt;
&lt;li&gt;Memory efficiency is crucial&lt;/li&gt;
&lt;li&gt;You're doing lots of math operations (especially with NumPy arrays)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Heads up:&lt;/strong&gt; For most Python tasks, you'll probably stick with lists. But when you need that extra performance boost for number crunching, arrays (especially NumPy arrays) are your best friends.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Sets: The Unique Snowflakes ❄️
&lt;/h3&gt;

&lt;p&gt;Sets are like lists that hate duplicates. They're perfect when you need to ensure each item only appears once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;unique_visitors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;alice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bob&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;charlie&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;alice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;  &lt;span class="c1"&gt;# Alice only counted once!
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unique_visitors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: {'bob', 'alice', 'charlie'}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to eliminate duplicates from a collection&lt;/li&gt;
&lt;li&gt;You're doing set operations (union, intersection, etc.)&lt;/li&gt;
&lt;li&gt;You want to quickly check if an item exists in a collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cool feature:&lt;/strong&gt; Set operations in Python are super intuitive. Need items that are in both set A and set B? Just do &lt;code&gt;A &amp;amp; B&lt;/code&gt;. Mind blown! 🤯&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing Your Data Structure: A Quick Guide
&lt;/h2&gt;

&lt;p&gt;Still not sure which to use? Here's a quick decision tree:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Need to maintain order and modify contents? → List&lt;/li&gt;
&lt;li&gt;Have fixed data that won't change? → Tuple&lt;/li&gt;
&lt;li&gt;Want fast lookups by a unique key? → Dictionary&lt;/li&gt;
&lt;li&gt;Dealing with lots of numeric data and need performance? → Array (consider NumPy)&lt;/li&gt;
&lt;li&gt;Need a collection of unique items? → Set&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;There you have it, folks! A whirlwind tour of Python's fantastic five data structures. Remember, there's no one-size-fits-all solution. The best data structure depends on your specific needs, the operations you'll perform most often, and sometimes just personal preference.&lt;/p&gt;

&lt;p&gt;The more you work with these structures, the more intuitive your choices will become. So go forth and structure your data like a pro! And remember, in the wise words of the Python zen: "There should be one-- and preferably only one --obvious way to do it."&lt;/p&gt;

&lt;p&gt;Happy coding, Pythonistas! 🐍✨&lt;/p&gt;

</description>
      <category>python</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>A Simple Guide to Developing AJAX-Driven Plugins for WordPress</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Sun, 04 Feb 2024 22:02:51 +0000</pubDate>
      <link>https://dev.to/zendyani/a-simple-guide-to-developing-ajax-driven-plugins-for-wordpress-3kk3</link>
      <guid>https://dev.to/zendyani/a-simple-guide-to-developing-ajax-driven-plugins-for-wordpress-3kk3</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8qjdnrv4hu4jr2xqowc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8qjdnrv4hu4jr2xqowc.gif" alt="Plugin demo" width="600" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this comprehensive guide, we will explore how to develop AJAX-driven plugins for WordPress, covering everything from setting up the basic structure to securing AJAX requests and adding custom admin menus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plugin Structure and Setup
&lt;/h2&gt;

&lt;p&gt;To get started, let's take a look at the overall structure of our plugin. We will follow best practices by organizing our code within a namespace and creating a class to encapsulate all functionality. Here's what the initial setup might look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="cm"&gt;/*
Plugin Name: WP AJAX Plugin
Description: A simple AJAX example for WordPress.
Version: 1.0
Author: Your Name here
Text Domain: wp-ajax-plugin
*/&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;MyAjaxPlugin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Prevent direct access&lt;/span&gt;
&lt;span class="nb"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'No script kiddies please!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyAjaxPlugin&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyAjaxPlugin&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sets up the basic plugin structure, including the necessary PHP comments for proper identification and activation of the plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enqueuing Scripts
&lt;/h2&gt;

&lt;p&gt;Now that we have our plugin set up, let's enqueue the necessary scripts for our AJAX-driven plugin. To do this, we will use the &lt;code&gt;add_action('admin_enqueue_scripts', ...)&lt;/code&gt; hook to register our JavaScript file and localize variables for use in our JavaScript code. Here's an example of how to enqueue a script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;adminScripts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hook&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'toplevel_page_my-ajax-plugin'&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nv"&gt;$hook&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;wp_enqueue_script&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'my-ajax-request'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;plugin_dir_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'js/ajax-script.js'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'jquery'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;wp_localize_script&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'my-ajax-request'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'MyAjax'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ajaxurl'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;admin_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'admin-ajax.php'&lt;/span&gt;&lt;span class="p"&gt;)]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;adminScripts&lt;/code&gt; method checks whether the current hook matches our plugin's top-level page. If it does, it enqueues the &lt;code&gt;my-ajax-request&lt;/code&gt; script and localizes the &lt;code&gt;ajaxurl&lt;/code&gt; variable for use in our JavaScript code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Localizing JavaScript
&lt;/h2&gt;

&lt;p&gt;Localization is crucial for ensuring that our plugin works correctly across different languages and environments. By using the &lt;code&gt;wp_localize_script&lt;/code&gt; function, we can pass data from PHP to JavaScript while preserving any existing translations. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myAjaxRequest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MyAjax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ajaxurl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MyAjax&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nonce&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we're passing the &lt;code&gt;ajaxurl&lt;/code&gt; and &lt;code&gt;nonce&lt;/code&gt; values from our PHP code to our JavaScript code, allowing us to make secure AJAX requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Secure AJAX Handling
&lt;/h2&gt;

&lt;p&gt;When working with AJAX in WordPress, security should always be a priority. One way to ensure secure communication between the server and client is by using nonces. Nonces help protect against cross-site request forgery attacks by verifying that the request was initiated by an authorized source. Here's an example of how to handle AJAX requests securely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;wp_verify_nonce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nonce'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="s1"&gt;'my-ajax-nonce'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Process the request&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Invalid nonce, reject the request&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By checking the validity of the nonce before processing the request, we can prevent unauthorized actions and maintain the security of our plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Admin Menu
&lt;/h2&gt;

&lt;p&gt;Adding a custom admin menu to our plugin is straightforward thanks to the &lt;code&gt;add_menu_page&lt;/code&gt; function. This function takes several arguments, including the page title, menu title, capability, menu slug, callback function, and icon URL. Here's an example of how to add a custom admin menu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;adminMenu&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add_menu_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'My AJAX Plugin Settings'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'my-ajax-plugin'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// Page title&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'My AJAX Plugin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'my-ajax-plugin'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;// Menu title&lt;/span&gt;
        &lt;span class="s1"&gt;'manage_options'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Capability&lt;/span&gt;
        &lt;span class="s1"&gt;'my-ajax-plugin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Menu slug&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'settingsPage'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;// Function to display the settings page&lt;/span&gt;
        &lt;span class="s1"&gt;'dashicons-admin-generic'&lt;/span&gt; &lt;span class="c1"&gt;// Icon URL&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code adds a new top-level menu item called "My AJAX Plugin" with a submenu titled "My AJAX Plugin Settings". It also specifies the appropriate capabilities and icon for the menu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Displaying Plugin Page
&lt;/h2&gt;

&lt;p&gt;Once we have added the admin menu, we need to create the actual settings page for our plugin. This involves creating an HTML form where users can input their desired text and submit it via AJAX. Here's an example of how to display the plugin page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;function settingsPage() {
    ?&amp;gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"wrap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php esc_html_e('My AJAX Plugin', 'my-ajax-plugin'); ?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my-ajax-form"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php esc_html_e('Enter your name:', 'my-ajax-plugin'); ?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"hidden"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"nonce"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_nonce"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"&amp;lt;?php echo wp_create_nonce('my-ajax-nonce'); ?&amp;gt;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"submit-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php esc_html_e('Submit', 'my-ajax-plugin'); ?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code creates a simple form with an input field for the user's name and a hidden nonce field. When the user submits the form, the AJAX request will be sent to update the "message" div with a success message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, By understanding the various aspects involved, such as plugin structure, script enqueuing, localization, secure AJAX handling, and custom admin menus, we can create powerful and engaging experiences for our users.&lt;br&gt;
Keep in mind that this code is not intended to be used on production.&lt;/p&gt;

&lt;p&gt;The complete code is on this &lt;a href="https://github.com/zendyani/wp-ajax-plugin"&gt;Github repository&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>ajax</category>
    </item>
    <item>
      <title>The Ultimate Guide to Effortless PostgreSQL Database Backups</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Sat, 03 Feb 2024 18:31:04 +0000</pubDate>
      <link>https://dev.to/zendyani/the-ultimate-guide-to-effortless-postgresql-database-backups-57dc</link>
      <guid>https://dev.to/zendyani/the-ultimate-guide-to-effortless-postgresql-database-backups-57dc</guid>
      <description>&lt;p&gt;Welcome to the ultimate guide on how to easily back up your PostgreSQL database. Whether you're a novice or an experienced web developer, this comprehensive guide will walk you through the process step by step. We'll be using two essential commands: pg_dump for creating backups and pg_restore for restoring them. So, let's dive in!&lt;br&gt;
Why Back Up Your PostgreSQL Database?&lt;/p&gt;

&lt;p&gt;Before we get started with the commands, it's important to understand the importance of database backups. Imagine you've spent countless hours developing your web application, and suddenly, disaster strikes. Your database gets corrupted, or crucial data is accidentally deleted. Without a backup, you could be facing a nightmare scenario.&lt;/p&gt;

&lt;p&gt;That's where PostgreSQL's pg_dump and pg_restore commands come to the rescue. They allow you to create backups and restore your database to a previous state, ensuring the integrity of your data and the peace of mind every developer deserves.&lt;br&gt;
Backing Up Your PostgreSQL Database with pg_dump&lt;/p&gt;

&lt;p&gt;The pg_dump command is your go-to tool for creating a backup of a PostgreSQL database. Let's break down the command:&lt;br&gt;
bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pg_dump -h 127.0.0.1 -U myUserName --format custom --clean --no-owner --no-privileges -d my_database_name &amp;gt; /..destination../full_db_backup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what each part of the command does:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-h 127.0.0.1: Specifies the hostname of your PostgreSQL server.
-U myUserName: Sets the username for accessing the database.
--format custom: Chooses the custom format for the backup.
--clean: Includes SQL commands to drop existing objects before recreating them.
--no-owner: Prevents the backup file from specifying the owner, making it usable in different configurations.
--no-privileges: Omits SQL commands for granting or revoking privileges, it will help in moving the db to a new server hasslefree.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The backup file will be saved at /..destination../full_db_backup.sql. With this command, you've successfully created a backup of your "my_database_name" database.&lt;br&gt;
Restoring Your PostgreSQL Database with pg_restore&lt;/p&gt;

&lt;p&gt;Now that you have your backup, it's essential to know how to restore it using the pg_restore command. Here's the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pg_restore -h 127.0.0.1 -U myOtherDbUsername -W --no-owner --no-privileges -d my_new_database_name path/full_db_backup.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what's happening:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-h 127.0.0.1: Specifies the hostname of the local PostgreSQL server.
-U myOtherDbUsername: Sets the username for accessing the database.
-W: Prompts for a password to ensure security.
--no-owner: Skips specifying ownership, allowing you to use the backup on different configurations.
--no-privileges: Omits privilege-related SQL commands.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The command will restore your backup file located at path/full_db_backup.sql into the "my_new_database_name" database on your local server.&lt;br&gt;
Understanding --clean, --no-owner, and --no-privileges&lt;/p&gt;

&lt;p&gt;These three options are essential for ensuring the versatility of your backup file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--clean: Adds SQL commands to drop existing objects before recreating them, ensuring a clean restoration.
--no-owner: Avoids specifying ownership, making the backup usable in various setups.
--no-privileges: Excludes privilege-related SQL commands, allowing flexibility when restoring.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;With the power of pg_dump and pg_restore at your fingertips, you can effortlessly create and restore backups of PostgreSQL databases. These commands provide a convenient way to safeguard your database's integrity and recover swiftly from any unexpected mishaps. So, go ahead and put this knowledge into action to ensure the security and reliability of your PostgreSQL database! Happy coding!&lt;/p&gt;

</description>
      <category>postgressql</category>
      <category>backup</category>
      <category>database</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Navigating the Depths of Log Analysis: Unleashing the Power of Lnav</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Sun, 17 Sep 2023 03:56:22 +0000</pubDate>
      <link>https://dev.to/zendyani/navigating-the-depths-of-log-analysis-unleashing-the-power-of-lnav-4n5m</link>
      <guid>https://dev.to/zendyani/navigating-the-depths-of-log-analysis-unleashing-the-power-of-lnav-4n5m</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Navigating through log files can be quite cumbersome, particularly when you're unsure about what you're looking for. However, with the appropriate tools at your disposal, this process can become significantly more manageable. Before discovering Lnav, I relied on a variety of tools and a series of piped commands to extract the information I needed from logs. Lnav, on the other hand, is an all-encompassing tool that simplifies log navigation and greatly enhances efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use Lnav:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Start Lnav:
&lt;/h3&gt;

&lt;p&gt;To begin using Lnav, open your terminal and run the following command, replacing &lt;code&gt;logfile.log&lt;/code&gt; with the path to your log file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lnav logfile.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Navigation:
&lt;/h3&gt;

&lt;p&gt;Once you have your log file open in Lnav, you can navigate through the log entries using the following keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;j&lt;/code&gt; and &lt;code&gt;k&lt;/code&gt; or arrow keys: Move up and down through the log entries.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-u&lt;/code&gt; and &lt;code&gt;Ctrl-d&lt;/code&gt;: Scroll up and down one page at a time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;g&lt;/code&gt;: Go to the beginning of the log file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G&lt;/code&gt;: Go to the end of the log file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:q&lt;/code&gt; : To quit Lnav, yes the same way you quit Vim.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Goto:
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;goto&lt;/code&gt; command in Lnav allows you to navigate log entries based on timestamps or line numbers.&lt;br&gt;
Running goto is similar to running a command within Vim, where you essentially use '':'' followed by goto.&lt;/p&gt;

&lt;p&gt;Let's jump to the examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Jump to a Specific Timestamp:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto 2023-09-15 15:30:00
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Navigate Relative to the Current Time:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto 1 hour ago
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto 2 days ago
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These relative time expressions are helpful for quickly reviewing recent log entries or identifying issues that occurred in the past.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Go to a Specific Line Number:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto 5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Find the First or Last Log Entry:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto first
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto last
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. The Offset Keyword:&lt;/strong&gt;&lt;br&gt;
You can also use the &lt;code&gt;offset&lt;/code&gt; keyword with the &lt;code&gt;goto&lt;/code&gt; command to move forward or backward by a specific number of log entries. For example:&lt;/p&gt;

&lt;p&gt;To move forward by 100 log entries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto offset 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To move backward by 50 log entries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:goto offset &lt;span class="nt"&gt;-50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Searching and Filtering:
&lt;/h3&gt;

&lt;p&gt;Lnav's search and filtering capabilities help you find specific log entries quickly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/&lt;/code&gt;: Start a text search. For example, &lt;code&gt;/error&lt;/code&gt; will highlight all lines containing the word "error."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n&lt;/code&gt; and &lt;code&gt;N&lt;/code&gt;: Move to the next and previous search results.&lt;/li&gt;
&lt;li&gt;:filter-in: can be used the same way as a regular search, matches are highlighted in green in the text view.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;:filter-in 404
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;In conclusion, Lnav's user-friendly interface, coupled with its rich feature set, positions it as an invaluable tool for log analysis and management. Whether you're an experienced system administrator or a developer seeking to streamline log-related tasks, Lnav's versatility and efficiency make it an essential addition to your toolkit.&lt;/p&gt;

&lt;p&gt;To learn more about Lnav &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://lnav.org/features"&gt;Features | The Logfile Navigator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.lnav.org/en/v0.11.2/index.html"&gt;Welcome to lnav’s documentation!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>logs</category>
      <category>cli</category>
      <category>systems</category>
      <category>linux</category>
    </item>
    <item>
      <title>Comparison of npm, Yarn, pnpm, and npx.</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Sat, 02 Sep 2023 10:33:25 +0000</pubDate>
      <link>https://dev.to/zendyani/comparison-of-npm-yarn-pnpm-and-npx-2975</link>
      <guid>https://dev.to/zendyani/comparison-of-npm-yarn-pnpm-and-npx-2975</guid>
      <description>&lt;p&gt;The Node.js ecosystem is a rapidly evolving realm filled with a plethora of tools and technologies. For developers, keeping pace with these innovations can be a formidable challenge. Personally, I struggle to remember the differences between each package manager.&lt;/p&gt;

&lt;p&gt;In this article, we'll delve into the distinctions between npm, Yarn, pnpm, and npx, helping you understand the differences between each tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Package Manager Comparison
&lt;/h2&gt;

&lt;h3&gt;
  
  
  npm
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Package Manager Type&lt;/strong&gt;: npm is primarily a package manager used for installing and managing JavaScript packages (dependencies) in your Node.js projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Management&lt;/strong&gt;: It handles dependencies defined in your project's &lt;code&gt;package.json&lt;/code&gt; file and installs them in the &lt;code&gt;node_modules&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scripts&lt;/strong&gt;: npm also allows you to define and run scripts in your &lt;code&gt;package.json&lt;/code&gt; file, making it a build tool to some extent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Packages&lt;/strong&gt;: You can install packages globally using the &lt;code&gt;-g&lt;/code&gt; flag, making them available for command-line use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lock File&lt;/strong&gt;: npm uses a &lt;code&gt;package-lock.json&lt;/code&gt; (or &lt;code&gt;npm-shrinkwrap.json&lt;/code&gt; in older versions) for dependency locking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Installations&lt;/strong&gt;: It installs packages sequentially by default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disk Space Efficiency&lt;/strong&gt;: npm creates a separate copy of each package in the &lt;code&gt;node_modules&lt;/code&gt; directory for each project, which can lead to high disk space usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community and Ecosystem&lt;/strong&gt;: npm has a large and established community with a vast ecosystem of packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Yarn
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Package Manager Type&lt;/strong&gt;: Yarn is another package manager like npm, designed to be faster and more reliable in terms of dependency resolution and installation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Management&lt;/strong&gt;: It handles dependencies defined in your project's &lt;code&gt;package.json&lt;/code&gt; file and installs them in the &lt;code&gt;node_modules&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scripts&lt;/strong&gt;: Yarn allows you to define and run scripts in your &lt;code&gt;package.json&lt;/code&gt; file, similar to npm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Packages&lt;/strong&gt;: You can install packages globally using the &lt;code&gt;global&lt;/code&gt; flag, similar to npm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lock File&lt;/strong&gt;: Yarn uses a &lt;code&gt;yarn.lock&lt;/code&gt; file for deterministic dependency resolution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Installations&lt;/strong&gt;: Yarn introduced parallel installation by default, making it faster than npm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disk Space Efficiency&lt;/strong&gt;: Yarn stores packages in a global cache and links them to projects, reducing disk space usage compared to npm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community and Ecosystem&lt;/strong&gt;: Yarn gained popularity quickly due to its speed improvements and has a strong community.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  pnpm
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Package Manager Type&lt;/strong&gt;: pnpm is a package manager like npm and Yarn but with a unique approach to dependency management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Management&lt;/strong&gt;: pnpm installs packages concurrently, which can result in faster installations compared to npm (sequential) and is similar to Yarn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scripts&lt;/strong&gt;: It does not have a concept of global installations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Packages&lt;/strong&gt;: no global installations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lock File&lt;/strong&gt;: pnpm uses a &lt;code&gt;pnpm-lock.yaml&lt;/code&gt; file for dependency locking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Installations&lt;/strong&gt;: pnpm installs packages concurrently, similar to Yarn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disk Space Efficiency&lt;/strong&gt;: pnpm uses a hard-linking mechanism that allows multiple projects to share the same package dependencies without duplicating them, significantly reducing disk space usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Community and Ecosystem&lt;/strong&gt;: pnpm has a smaller but growing community, particularly among projects looking to save disk space and improve installation speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  npx
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Utility Type&lt;/strong&gt;: npx is a utility for executing Node.js packages (usually binaries) that aren't globally installed on your system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage&lt;/strong&gt;: It helps resolve the correct command to execute from the local project's &lt;code&gt;node_modules&lt;/code&gt; or from the global npm/yarn installations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global Packages&lt;/strong&gt;: npx is not used for global installations but for running commands from local or global packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Note&lt;/strong&gt;: It is not primarily a package manager but a tool for executing package binaries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary:
&lt;/h2&gt;

&lt;p&gt;Here are the main differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;npm&lt;/strong&gt;: A traditional package manager with a focus on dependency management and script execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Yarn&lt;/strong&gt;: Similar to npm but with a focus on faster and deterministic installations, as well as workspace support.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pnpm&lt;/strong&gt;: A package manager that installs packages concurrently and efficiently manages disk space through hard-linking, making it faster and more space-efficient compared to npm and Yarn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;npx&lt;/strong&gt;: A command-line utility for running binaries or scripts from Node.js packages without the need for global installations. It is not primarily a package manager but a tool for executing package binaries.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>npm</category>
      <category>pnpm</category>
      <category>yarn</category>
    </item>
    <item>
      <title>How to use Systemd Timers to Schedule the Execution of a Specific Command</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Sat, 31 Dec 2022 19:09:58 +0000</pubDate>
      <link>https://dev.to/zendyani/how-to-use-systemd-timers-to-schedule-the-execution-of-a-specific-command-1eol</link>
      <guid>https://dev.to/zendyani/how-to-use-systemd-timers-to-schedule-the-execution-of-a-specific-command-1eol</guid>
      <description>&lt;p&gt;If you need to run a command periodically on your Linux server, you might consider using a Systemd timer instead of a cron job. Systemd timers offer more control over your command and are more flexible than Cron jobs. &lt;br&gt;
Here's a quick comparison between the two:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Systemd timers are more flexible than Cronjobs. They allow you to specify more granular time intervals, such as "every 15 minutes" or "every other hour on weekdays." They also allow you to specify more complex schedules, such as "every Monday, Wednesday, and Friday at 10am."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systemd timers are easier to manage. You can use the &lt;code&gt;systemctl&lt;/code&gt; command to start, stop, enable, disable, and view the status of Systemd timers. This is much more convenient than having to manually edit Cronjob configuration files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systemd timers offer better integration with the rest of the system. They can be used to trigger system-wide events, such as triggering a system shutdown or reboot. They can also be used to trigger custom targets, which are collections of units (such as services, sockets, and paths) that can be started, stopped, or restarted as a group.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systemd timers can be used to trigger actions based on system state. For example, you can use a timer to trigger a script that checks for low disk space and takes action to free up space if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Systemd timers are more reliable than Cronjobs. Systemd is a modern and reliable init system that is used by default in most modern Linux distributions. In contrast, Cron has a long history of security vulnerabilities and can be prone to errors. By using Systemd timers, you can take advantage of the reliability and security benefits of Systemd.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As an example, let's update Algolia indexes for Magento products using the default Magento command, we will need to create two files: a Systemd unit file and a Systemd timer file.&lt;/p&gt;

&lt;p&gt;The unit file will contain the configuration for the service that will be run to update the Algolia indexes. This will include details such as the command to be run, the working directory, and any dependencies or requirements for the service.&lt;/p&gt;

&lt;p&gt;The timer file will contain the configuration for the timer that will control how often the service is run. This will include details such as the time interval between runs, as well as any special scheduling considerations (e.g. only running the service on certain days of the week).&lt;/p&gt;

&lt;p&gt;Once these two files are created, we can use the &lt;code&gt;systemctl&lt;/code&gt; command to start, stop, enable, and disable the timer as needed. This will allow us to easily automate the process of updating the Algolia indexes for our Magento products.&lt;/p&gt;

&lt;p&gt;Let's first create the Systemd unit file on /etc/systemd/system/update-products-indexes.service&lt;/p&gt;

&lt;p&gt;The content of &lt;strong&gt;update-products-indexes.service&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;Unit]
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Update indexes
&lt;span class="nv"&gt;Requires&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx.service
&lt;span class="nv"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx.service

&lt;span class="o"&gt;[&lt;/span&gt;Service]
&lt;span class="nv"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oneshot
&lt;span class="nv"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/var/www/magento-website/current
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin/php bin/magento indexer:reindex

&lt;span class="o"&gt;[&lt;/span&gt;Install]
&lt;span class="nv"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are a few things to note in the following configuration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The &lt;code&gt;Type=oneshot&lt;/code&gt; parameter specifies that the service should only be run once, and not kept alive.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;WorkingDirectory&lt;/code&gt; parameter specifies the directory in which the command will be run. In this case, it will be inside the Magento installation located at &lt;code&gt;/var/www/magento-website/current&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;ExecStart&lt;/code&gt; parameter specifies the command to be run, which comes with the Magento installation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information, you can refer to the official documentation.&lt;/p&gt;

&lt;p&gt;Next we will create the timer file and save it on /etc/systemd/system/update-products-indexes.timer&lt;/p&gt;

&lt;p&gt;The content of &lt;strong&gt;update-products-indexes.timer&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;Unit]
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Timer &lt;span class="k"&gt;for &lt;/span&gt;products indexes update
&lt;span class="nv"&gt;Requires&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;update-products-indexes.service

&lt;span class="o"&gt;[&lt;/span&gt;Timer]
&lt;span class="nv"&gt;Unit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;update-products-indexes.service

&lt;span class="c"&gt;# Time to wait after booting before we run first time&lt;/span&gt;
&lt;span class="nv"&gt;OnBootSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10min

&lt;span class="c"&gt;# Define a calendar event (see `man systemd.time`)&lt;/span&gt;
&lt;span class="nv"&gt;OnCalendar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0/6:00:00

&lt;span class="o"&gt;[&lt;/span&gt;Install]
&lt;span class="nv"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To tell Systemd to run our configured service, we need to start the corresponding timer with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start update-products-indexes.timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To ensure that the service is run at boot time in case the server is restarted, we need to enable both the service and the timer with these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl enable update-products-indexes.service
sudo systemctl enable update-products-indexes.timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note that we only need to start the timer file, as it will call the unit file (service) at the specified frequency. &lt;br&gt;
However, if you want to run the unit file directly, you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start update-products-indexes.service&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, using Systemd timers can be a powerful and convenient way to automate the execution of a specific command on a Linux server. They offer greater flexibility and ease of management compared to cron jobs, and provide better integration with the rest of the system. Whether you need to run a command periodically or based on system state, Systemd timers can help you get the job done efficiently and reliably. So next time you need to automate a task on your Linux server, consider using Systemd timers as an alternative to cron jobs.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>discuss</category>
      <category>programming</category>
    </item>
    <item>
      <title>Figma plugin project setup using Figsvelte boilerplate</title>
      <dc:creator>Abdeldjalil</dc:creator>
      <pubDate>Thu, 16 Dec 2021 01:21:49 +0000</pubDate>
      <link>https://dev.to/zendyani/figma-plugin-project-setup-using-figsvelte-boilerplate-2bim</link>
      <guid>https://dev.to/zendyani/figma-plugin-project-setup-using-figsvelte-boilerplate-2bim</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I always find working with Javascript framework on a Figma plugin project to be at a certain point an over-engineering choice that brings more maintenance cost without a real added value, at least from my point of view, at the same time it also brings a lot of ready to use features that make using it in a project appealing but still the tradeoffs were against it, yes I used the past because I think differently now, after discovering Svelte the tradeoffs turned in favor of using Javascript framework without sacrificing simplicity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Figsvel
&lt;/h2&gt;

&lt;p&gt;Start by installing Figsvel boilerplate as so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx degit thomas-lowry/figsvelte figma-plugin
cd figma-plugin
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update dependencies
&lt;/h2&gt;

&lt;p&gt;Even though you can work on your Figma plugin without updating dependencies I prefer to update it, so if you're the same this is how it's done.&lt;/p&gt;

&lt;p&gt;1- Installing &lt;code&gt;npm-check-updates&lt;/code&gt; with &lt;code&gt;npm i -g npm-check-updates&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2- Inside your project folder run &lt;code&gt;ncu --upgrade&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3- Before updating our node_modules with the new dependencies let's do one more thing, replace rollup-plugin-typescript with @rollup/plugin-typescript.&lt;/p&gt;

&lt;p&gt;4- Just to make sure no strange error emerge remove node_modules directory and run &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Done&lt;/p&gt;

&lt;h2&gt;
  
  
  Update manifest.json
&lt;/h2&gt;

&lt;p&gt;Lastly update public/manifest.json that the current version in Figsvelte repo lack a config update needed by Figma to run correctly the plugin which is: &lt;code&gt;"editorType": ["figma"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can learn more about it in the Figma plugin doc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulation, you're good to go for your next Figma plugin with Svelte framework without sacrificing the simplicity of JavaScript nor the advanced features a Framework can bring.&lt;/p&gt;

</description>
      <category>figma</category>
      <category>javascript</category>
      <category>svelte</category>
    </item>
  </channel>
</rss>
