<?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>Forem: Mpia</title>
    <description>The latest articles on Forem by Mpia (@codewithmpia).</description>
    <link>https://forem.com/codewithmpia</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%2F3616322%2Fd45ec119-8c54-46ca-bd37-9b7c334e206a.png</url>
      <title>Forem: Mpia</title>
      <link>https://forem.com/codewithmpia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codewithmpia"/>
    <language>en</language>
    <item>
      <title>LaTeX: Writing Scientific Documents Like a Pro</title>
      <dc:creator>Mpia</dc:creator>
      <pubDate>Wed, 31 Dec 2025 20:08:31 +0000</pubDate>
      <link>https://forem.com/codewithmpia/latex-writing-scientific-documents-like-a-pro-2490</link>
      <guid>https://forem.com/codewithmpia/latex-writing-scientific-documents-like-a-pro-2490</guid>
      <description>&lt;p&gt;After my Word document crashed for the third time, corrupting my math formulas and randomly changing my formatting... I discovered LaTeX.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And I'll never go back.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Word nightmare we've all lived
&lt;/h2&gt;

&lt;p&gt;You know the drill:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Equations that look like pixelated garbage&lt;/li&gt;
&lt;li&gt;Formatting that breaks between saves&lt;/li&gt;
&lt;li&gt;Copy-paste that destroys your entire layout&lt;/li&gt;
&lt;li&gt;"Table of contents updated" &lt;em&gt;[entire document shifts by 3 pages]&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sound familiar? 😅&lt;/p&gt;

&lt;h2&gt;
  
  
  What if your documents compiled like code?
&lt;/h2&gt;

&lt;p&gt;That's exactly what LaTeX does. You write markup, compile it, get a beautiful PDF.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why switch to LaTeX?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Math formulas&lt;/strong&gt; that actually look professional&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;No more formatting fights&lt;/strong&gt; - focus on content&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Git-friendly&lt;/strong&gt; - version control for documents&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Publication-ready&lt;/strong&gt; typography&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Automatic&lt;/strong&gt; table of contents, references, numbering&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;&lt;span class="k"&gt;\documentclass&lt;/span&gt;&lt;span class="na"&gt;[a4paper,11pt]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;article&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="na"&gt;[utf8]&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;inputenc&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\usepackage&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;amsmath&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;\title&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;My First LaTeX Document&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;\author&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;Your Name&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;\begin{document}&lt;/span&gt;
&lt;span class="k"&gt;\maketitle&lt;/span&gt;

&lt;span class="k"&gt;\section&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;Introduction&lt;span class="p"&gt;}&lt;/span&gt;
Einstein's famous formula: &lt;span class="p"&gt;$&lt;/span&gt;&lt;span class="nb"&gt;E &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt; mc&lt;/span&gt;&lt;span class="p"&gt;^&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;$&lt;/span&gt;

&lt;span class="p"&gt;\[&lt;/span&gt;&lt;span class="nb"&gt;
    x &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt; &lt;/span&gt;&lt;span class="nv"&gt;\frac&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;b &lt;/span&gt;&lt;span class="nv"&gt;\pm&lt;/span&gt;&lt;span class="nb"&gt; &lt;/span&gt;&lt;span class="nv"&gt;\sqrt&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;b&lt;/span&gt;&lt;span class="p"&gt;^&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="nb"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt; &lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="nb"&gt;ac&lt;/span&gt;&lt;span class="p"&gt;}}{&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="nb"&gt;a&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="nb"&gt;
&lt;/span&gt;&lt;span class="p"&gt;\]&lt;/span&gt;

&lt;span class="nt"&gt;\end{document}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compile → Beautiful PDF. Every single time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What my complete guide covers
&lt;/h2&gt;

&lt;p&gt;I wrote everything I wish I knew when starting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 &lt;strong&gt;Setup guide&lt;/strong&gt; (VS Code, TeXstudio, Overleaf)&lt;/li&gt;
&lt;li&gt;📝 &lt;strong&gt;Document structure&lt;/strong&gt; and essential packages&lt;/li&gt;
&lt;li&gt;🧮 &lt;strong&gt;Mathematical formulas&lt;/strong&gt; (the LaTeX superpower)&lt;/li&gt;
&lt;li&gt;💻 &lt;strong&gt;Source code&lt;/strong&gt; with syntax highlighting&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;Tables and figures&lt;/strong&gt; done right&lt;/li&gt;
&lt;li&gt;🎨 &lt;strong&gt;Colored boxes&lt;/strong&gt; for terminal outputs&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;Complete templates&lt;/strong&gt; ready to use&lt;/li&gt;
&lt;li&gt;⚙️ &lt;strong&gt;pdflatex vs lualatex&lt;/strong&gt; explained&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-world examples from the guide
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Beautiful math:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;&lt;span class="nt"&gt;\begin{align}&lt;/span&gt;
    &lt;span class="k"&gt;\sum&lt;/span&gt;&lt;span class="p"&gt;_{&lt;/span&gt;i=1&lt;span class="p"&gt;}^{&lt;/span&gt;n&lt;span class="p"&gt;}&lt;/span&gt; x&lt;span class="p"&gt;_&lt;/span&gt;i &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;= x&lt;span class="p"&gt;_&lt;/span&gt;1 + x&lt;span class="p"&gt;_&lt;/span&gt;2 + &lt;span class="k"&gt;\cdots&lt;/span&gt; + x&lt;span class="p"&gt;_&lt;/span&gt;n &lt;span class="k"&gt;\\&lt;/span&gt;
    &lt;span class="k"&gt;\int&lt;/span&gt;&lt;span class="p"&gt;_&lt;/span&gt;0&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\infty&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; e&lt;span class="p"&gt;^{&lt;/span&gt;-x&lt;span class="p"&gt;}&lt;/span&gt; dx &lt;span class="p"&gt;&amp;amp;&lt;/span&gt;= 1
&lt;span class="nt"&gt;\end{align}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Code with highlighting:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;&lt;span class="nt"&gt;\begin{lstlisting}&lt;/span&gt;[language=Python]
def fibonacci(n):
    if n &amp;lt;= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)
&lt;span class="nt"&gt;\end{lstlisting}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Professional tables:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;&lt;span class="nt"&gt;\begin{tabular}&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;|l|c|c|&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;\hline&lt;/span&gt;
    &lt;span class="k"&gt;\textbf&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;Feature&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;\textbf&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;Word&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;\textbf&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;LaTeX&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;\\&lt;/span&gt;
    &lt;span class="k"&gt;\hline&lt;/span&gt;
    Equations &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; 😭 &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; 🚀 &lt;span class="k"&gt;\\&lt;/span&gt;
    &lt;span class="k"&gt;\hline&lt;/span&gt;
    Git &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; ❌ &lt;span class="p"&gt;&amp;amp;&lt;/span&gt; ✅ &lt;span class="k"&gt;\\&lt;/span&gt;
    &lt;span class="k"&gt;\hline&lt;/span&gt;
&lt;span class="nt"&gt;\end{tabular}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The turning point
&lt;/h2&gt;

&lt;p&gt;LaTeX has a learning curve. Your first compilation error will be frustrating.&lt;/p&gt;

&lt;p&gt;But once you get past that? You'll wonder how you ever survived with Word for technical documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the full guide here:&lt;/strong&gt; &lt;a href="https://codewithmpia.com/articles/19/latex-rediger-des-documents-scientifiques-comme-un-pro" rel="noopener noreferrer"&gt;codewithmpia.com/...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perfect for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎓 CS/Math/Physics students&lt;/li&gt;
&lt;li&gt;📚 Researchers and academics&lt;/li&gt;
&lt;li&gt;📄 Anyone writing technical documentation&lt;/li&gt;
&lt;li&gt;🔬 Scientists tired of equation editors&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Your experience?
&lt;/h2&gt;

&lt;p&gt;Already using LaTeX? Share your best tips!&lt;br&gt;
Still on Word? What's holding you back?&lt;/p&gt;

&lt;p&gt;Drop a comment below! 👇&lt;/p&gt;

</description>
      <category>latex</category>
      <category>tutorial</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
    <item>
      <title>Regular Expressions in Python: The Complete Guide to Finally Understanding Regex</title>
      <dc:creator>Mpia</dc:creator>
      <pubDate>Wed, 31 Dec 2025 19:57:26 +0000</pubDate>
      <link>https://forem.com/codewithmpia/regular-expressions-in-python-the-complete-guide-to-finally-understanding-regex-53p9</link>
      <guid>https://forem.com/codewithmpia/regular-expressions-in-python-the-complete-guide-to-finally-understanding-regex-53p9</guid>
      <description>&lt;p&gt;Let's be honest: you've copy-pasted a regex from Stack Overflow without really understanding what it does, right? 😅&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="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;+-&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+@&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;\&lt;span class="p"&gt;.[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zA&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Z0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;.]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does this make sense to you? No? Me neither at first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The regex problem
&lt;/h2&gt;

&lt;p&gt;We all have this love-hate relationship with regular expressions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We know they're powerful&lt;/li&gt;
&lt;li&gt;We need them regularly&lt;/li&gt;
&lt;li&gt;But we avoid truly understanding them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result?&lt;/strong&gt; We spend 30 minutes searching for the right pattern on Google instead of writing it in 2 minutes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What if you could finally master regex?
&lt;/h2&gt;

&lt;p&gt;I wrote a complete guide that demystifies regex once and for all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Basic syntax &lt;strong&gt;explained simply&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ Python's &lt;code&gt;re&lt;/code&gt; module &lt;strong&gt;in detail&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Practical examples&lt;/strong&gt; (emails, phone numbers, URLs, passwords...)&lt;/li&gt;
&lt;li&gt;✅ Common &lt;strong&gt;pitfalls to avoid&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Best practices&lt;/strong&gt; for readable regex&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick examples from the guide
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Validate an email:&lt;/strong&gt;&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;re&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&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;Extract all URLs from text:&lt;/strong&gt;&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;extract_urls&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https?://[^\s&amp;lt;&amp;gt;\"&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]+&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&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;Clean text intelligently:&lt;/strong&gt;&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\s+&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; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Multiple spaces → single space
&lt;/span&gt;    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[^\w\s.,!?-]&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Remove special chars
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stop struggling with regex
&lt;/h2&gt;

&lt;p&gt;Whether you're a beginner who avoids regex or a developer tired of copy-pasting without understanding, this guide is for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read the full article here:&lt;/strong&gt; &lt;a href="https://codewithmpia.com/articles/14/les-expressions-regulieres-en-python-le-guide-complet-pour-enfin-comprendre-les-regex" rel="noopener noreferrer"&gt;codewithmpia.com/...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No more cryptic patterns. No more trial and error. Just clear explanations and practical examples you can use today.&lt;/p&gt;

&lt;p&gt;What's your biggest regex challenge? Share in the comments! 👇&lt;/p&gt;

</description>
      <category>python</category>
      <category>regex</category>
      <category>code</category>
    </item>
    <item>
      <title>Flask + SELinux: Fixing the Mysterious 502 Error on Alma Linux</title>
      <dc:creator>Mpia</dc:creator>
      <pubDate>Fri, 28 Nov 2025 23:04:06 +0000</pubDate>
      <link>https://forem.com/codewithmpia/flask-selinux-fixing-the-mysterious-502-error-on-alma-linux-3jp2</link>
      <guid>https://forem.com/codewithmpia/flask-selinux-fixing-the-mysterious-502-error-on-alma-linux-3jp2</guid>
      <description>&lt;p&gt;You deploy your Flask app on Alma Linux, everything looks perfect, you hit your URL and... &lt;strong&gt;BAM!&lt;/strong&gt; 502 Bad Gateway. &lt;/p&gt;

&lt;p&gt;You check configs, permissions, logs. Nothing works. Then you try &lt;code&gt;sudo setenforce 0&lt;/code&gt; and... it works! 🎉&lt;/p&gt;

&lt;p&gt;But now you're stuck running with SELinux disabled, and you know that's not the solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sound familiar?&lt;/strong&gt; Let me show you how to fix this properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Problem
&lt;/h2&gt;

&lt;p&gt;SELinux isn't your enemy - it's just doing its job. By default, it blocks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;nginx connecting to your Gunicorn Unix socket&lt;/li&gt;
&lt;li&gt;systemd launching Gunicorn from &lt;code&gt;/home&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Your app sending emails via SMTP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, everything a modern web app needs to do. 😤&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Diagnosis
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# See what SELinux is blocking&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;ausearch &lt;span class="nt"&gt;-m&lt;/span&gt; avc &lt;span class="nt"&gt;-ts&lt;/span&gt; recent

&lt;span class="c"&gt;# Check your service logs&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;journalctl &lt;span class="nt"&gt;-u&lt;/span&gt; your-service &lt;span class="nt"&gt;-n&lt;/span&gt; 50 &lt;span class="nt"&gt;--no-pager&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see &lt;code&gt;Permission denied&lt;/code&gt; with code 203/EXEC, that's SELinux blocking you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution (Step by Step)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Move to &lt;code&gt;/var/www&lt;/code&gt; (seriously, do it)
&lt;/h3&gt;

&lt;p&gt;SELinux hates &lt;code&gt;/home&lt;/code&gt; for web apps. Move to the standard location:&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="nb"&gt;sudo &lt;/span&gt;systemctl stop your-service
&lt;span class="nb"&gt;sudo mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /var/www
&lt;span class="nb"&gt;sudo mv&lt;/span&gt; /home/user/my-app /var/www/my-app
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; user:user /var/www/my-app
&lt;span class="nb"&gt;sudo &lt;/span&gt;restorecon &lt;span class="nt"&gt;-Rv&lt;/span&gt; /var/www/my-app  &lt;span class="c"&gt;# SELinux magic!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Update systemd service
&lt;/h3&gt;

&lt;p&gt;Edit &lt;code&gt;/etc/systemd/system/your-service.service&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[Unit]&lt;/span&gt;
&lt;span class="py"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;Gunicorn for Flask app&lt;/span&gt;
&lt;span class="py"&gt;After&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;network.target&lt;/span&gt;

&lt;span class="nn"&gt;[Service]&lt;/span&gt;
&lt;span class="py"&gt;User&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;your-user&lt;/span&gt;
&lt;span class="py"&gt;Group&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;your-group&lt;/span&gt;
&lt;span class="py"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/var/www/my-app&lt;/span&gt;

&lt;span class="py"&gt;ExecStartPre&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/bin/mkdir -p /var/run/my-app&lt;/span&gt;
&lt;span class="py"&gt;ExecStartPre&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/bin/chown your-user:nginx /var/run/my-app&lt;/span&gt;
&lt;span class="py"&gt;ExecStartPre&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/bin/chmod 755 /var/run/my-app&lt;/span&gt;

&lt;span class="py"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"PATH=/var/www/my-app/venv/bin"&lt;/span&gt;

&lt;span class="py"&gt;ExecStart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/var/www/my-app/venv/bin/gunicorn &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="s"&gt;--workers 4 &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="s"&gt;--bind unix:/var/run/my-app/my-app.sock &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="s"&gt;--umask 007 &lt;/span&gt;&lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="s"&gt;wsgi:app&lt;/span&gt;

&lt;span class="py"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;always&lt;/span&gt;

&lt;span class="nn"&gt;[Install]&lt;/span&gt;
&lt;span class="py"&gt;WantedBy&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;multi-user.target&lt;/span&gt;
&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;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Configure SELinux contexts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Tell SELinux the socket is legitimate&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;semanage fcontext &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; httpd_var_run_t &lt;span class="s2"&gt;"/var/run/my-app(/.*)?"&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;restorecon &lt;span class="nt"&gt;-Rv&lt;/span&gt; /var/run/my-app

&lt;span class="c"&gt;# Allow nginx to connect&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;setsebool &lt;span class="nt"&gt;-P&lt;/span&gt; httpd_can_network_connect 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Create a custom SELinux policy (THE game changer!)
&lt;/h3&gt;

&lt;p&gt;This is the crucial step:&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="c"&gt;# Temporary permissive mode&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;setenforce 0

&lt;span class="c"&gt;# Start your app to generate violations&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart your-service
&lt;span class="nb"&gt;sleep &lt;/span&gt;5
curl http://localhost

&lt;span class="c"&gt;# Generate custom policy from violations&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;ausearch &lt;span class="nt"&gt;-m&lt;/span&gt; avc &lt;span class="nt"&gt;-ts&lt;/span&gt; recent | audit2allow &lt;span class="nt"&gt;-M&lt;/span&gt; my_policy

&lt;span class="c"&gt;# Install the policy&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;semodule &lt;span class="nt"&gt;-i&lt;/span&gt; my_policy.pp

&lt;span class="c"&gt;# Back to enforcing mode&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;setenforce 1

&lt;span class="c"&gt;# Restart and verify&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart your-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What just happened? &lt;code&gt;audit2allow&lt;/code&gt; analyzed all SELinux denials and created a policy that allows them. SELinux just learned what your app needs!&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Configure nginx
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="k"&gt;upstream&lt;/span&gt; &lt;span class="s"&gt;app_server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;server&lt;/span&gt; &lt;span class="s"&gt;unix:/var/run/my-app/my-app.sock&lt;/span&gt; &lt;span class="s"&gt;fail_timeout=0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kn"&gt;listen&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kn"&gt;server_name&lt;/span&gt; &lt;span class="s"&gt;my-domain.com&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kn"&gt;location&lt;/span&gt; &lt;span class="n"&gt;/&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kn"&gt;proxy_pass&lt;/span&gt; &lt;span class="s"&gt;http://app_server&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;Host&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kn"&gt;proxy_set_header&lt;/span&gt; &lt;span class="s"&gt;X-Real-IP&lt;/span&gt; &lt;span class="nv"&gt;$remote_addr&lt;/span&gt;&lt;span class="p"&gt;;&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nginx &lt;span class="nt"&gt;-t&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Issues &amp;amp; Quick Fixes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Emails not sending?&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="nb"&gt;sudo &lt;/span&gt;setsebool &lt;span class="nt"&gt;-P&lt;/span&gt; httpd_can_sendmail 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;External database connection blocked?&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="nb"&gt;sudo &lt;/span&gt;setsebool &lt;span class="nt"&gt;-P&lt;/span&gt; httpd_can_network_connect_db 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;API calls failing?&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="nb"&gt;sudo &lt;/span&gt;setsebool &lt;span class="nt"&gt;-P&lt;/span&gt; httpd_can_network_connect 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Verify It Works
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Check SELinux mode (should show "Enforcing")&lt;/span&gt;
getenforce

&lt;span class="c"&gt;# Service status&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl status your-service

&lt;span class="c"&gt;# No more violations?&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;ausearch &lt;span class="nt"&gt;-m&lt;/span&gt; avc &lt;span class="nt"&gt;-ts&lt;/span&gt; recent

&lt;span class="c"&gt;# Test your site&lt;/span&gt;
curl &lt;span class="nt"&gt;-I&lt;/span&gt; http://your-domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything's green, congratulations! 🎉 You've tamed SELinux!&lt;/p&gt;

&lt;h2&gt;
  
  
  Golden Rules
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;NEVER disable SELinux in production&lt;/strong&gt; - create policies instead&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Always use &lt;code&gt;/var/www&lt;/code&gt;&lt;/strong&gt; for web apps&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save your &lt;code&gt;.te&lt;/code&gt; files&lt;/strong&gt; - you'll need them later&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;restorecon&lt;/code&gt; after moving files&lt;/strong&gt; - saves hours of debugging&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Want the Full Guide?
&lt;/h2&gt;

&lt;p&gt;This is just the quick version! For a complete, detailed walkthrough with troubleshooting tips, deployment automation scripts, and more real-world scenarios, check out the full article on my blog:&lt;/p&gt;

&lt;p&gt;👉 Read the complete guide on  &lt;strong&gt;&lt;a href="https://codewithmpia.com/articles/2/flask-selinux-resoudre-l-erreur-502-sur-alma-linux-gunicorn-nginx/" rel="noopener noreferrer"&gt;codewithmpia.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You'll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to debug SELinux violations like a pro&lt;/li&gt;
&lt;li&gt;Setting up automated deployment scripts&lt;/li&gt;
&lt;li&gt;Handling edge cases and specific scenarios&lt;/li&gt;
&lt;li&gt;Best practices for production deployments&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Have you struggled with SELinux? Share your experience in the comments below!&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;And if this helped you fix that annoying 502 error, don't forget to share it with others who might be stuck in the same situation. 😉&lt;/p&gt;

&lt;p&gt;May the SELinux be with you! 🐧✨&lt;/p&gt;




&lt;h2&gt;
  
  
  👋 About Me
&lt;/h2&gt;

&lt;p&gt;Hi! I'm &lt;strong&gt;Mpia M.&lt;/strong&gt;, a computer science student passionate about web development. I created &lt;a href="https://codewithmpia.com" rel="noopener noreferrer"&gt;codewithmpia.com&lt;/a&gt; to share coding tutorials and make programming knowledge accessible to everyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Want more content like this?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 Visit my blog: &lt;a href="https://codewithmpia.com" rel="noopener noreferrer"&gt;https://codewithmpia.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📧 Subscribe to my newsletter for Python, Django, Flask, Svelte tips&lt;/li&gt;
&lt;li&gt;💬 Let's connect and share our dev experiences!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Topics I cover: Python, Django, Flask, SvelteKit, Vue.js, and DevOps.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>flask</category>
      <category>selinux</category>
    </item>
  </channel>
</rss>
