<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>List of all posts and notes in all languages on Hossein Naghdbishi</title><link>https://hossein.me/posts/</link><description>Recent content in List of all posts and notes in all languages on Hossein Naghdbishi</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 15 Feb 2026 15:58:31 +0330</lastBuildDate><atom:link href="https://hossein.me/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>مانع</title><link>https://hossein.me/posts/fa/resistence/</link><pubDate>Sun, 15 Feb 2026 15:58:31 +0330</pubDate><guid>https://hossein.me/posts/fa/resistence/</guid><description>&lt;p&gt;
مثالی که در مورد کارهای سخت در قوانینم نوشتم اینه:‌«کارهای سخت مثل دوش آب سردن، بعد از ۵ ثانیه‌ی اول انجامشون آسون میشه». من اصولا دوش آب سرد می‌گیرم،‌ یعنی جهت شیر آب همیشه به صورت تمام و کمال به سمت آب سرده مگر اینکه سرماخورده باشم. امروز بعد چند مدت دوش با آب گرم به علت سرماخوردگی، برگشتم به آب سرد. نکته اینجا بود که چون از این عادت فاصله گرفته بودم، انجامش برام سخت‌تر از پیش بود. از خودم می‌پرسیدم که اصلا این کار چه ضرورتی داره؟‌ آیا لازمه به خودم سختی بدم در حالی که زندگیم در نقاط دیگه‌اش به اندازهٔ کافی سختی داره؟ سعی داشتم خودم رو منصرف کنم. از طرفی عمیقا تردید داشتم که بتونم واقعا دوش آب سرد بگیرم. می‌دونستم که بارها این کار رو کردم، زیر آب‌های سرد خوابگاه یا آب‌های خیلی سرد خونه دووم اورده بودم، از پنج ثانیه تا مدت‌های طولانی و چندین دقیقه، ولی باز هم به طرز عجیبی به خودم شک داشتم. نکنه چون مدتیه فاصله گرفتم دیگه نمی‌تونم دوش آب سرد بگیرم؟
در عین حال قانون همیشگیم رو به خودم یادآوری کردم: «فقط ۵ ثانیه میرم زیر دوش آب سرد و دیگه نمیرم.» ۵ ثانیه رفتم و سخت بود، بعد از ۵ ثانیه از زیر آب خودم رو کنار کشیدم. با این حال همون ۵ ثانیه بهم شهامت داد و تردید رو کنار گذاشتم. توی این شستشو هم مثل بقیهٔ حمام‌رفتن‌های قبل از سرماخوردگیم، از آب گرم هیچ استفاده‌ای نکردم.
حالا تمام این‌ها رو ننوشتم که روایت شستن خودم رو بازگو کنم، نوشتم که از «مانع» یا اون چیزی که خارجی‌ها بهش مقاومت یا Resistance می‌گن بگم. وقتی داشتم با یکی درمورد اهمال‌کاری و انجام‌دادن‌ کارهای با اولویت پایین می‌گفتم، اون به چیزهایی مثل ترس از شکست، ترس از شکستن تجسم خود بی‌نقص، گفتن اینکه «من تمام تلاشم رو نکردم پس این من نیستم که خفن نیست بلکه فقط نمیخواستم و تلاش نکردم» اشاره می‌کرد. نکته اینجا بود که من مدت‌هاست هیچ‌وقت هیچ‌کدوم رو با صدای بلند به خودم نگفتم. مطمئن نبودم که آیا درست میگه یا نه چون هیچ مدرکی از این افکار در من نبود. بعد به اون مانع و سد ذهنی قبل از رفتن زیر دوش آب سرد فکر کردم. توی لحظاتی که آدم مردده که بره زیر دوش آب سرد یا نه، ذهن خالیِ خالیه. هیچ اثری از فکر درش نیست. فقط بدوی‌ترین احساساتن که توی زمان‌هایی که ذهنت خالیه، تردید داری و نزدیک آب سردی فریاد می‌زنن رفتن زیر دوش آب سرد دردناکه. حتی ذهن هم خودش تصویرسازی می‌کنه برات که اگر بری زیر دوش آب سرد و آب بریزه روی پشتت قطره قطره‌اش قراره اذیت کنه. هیچ کدوم از این احساسات تبدیل به فکر نمی‌شن، خیلی قبل‌تر از اون برات یک مانع می‌سازن. اینکه بری رمزگشایی کنی که چه احساساتی برات مانع میسازن با خودته،‌ ولی خبر خوب اینه که راه حل معلومه: کافیه پنج ثانیه به هر طریقی که شده خودت رو بندازی توی دل ترست.&lt;/p&gt;</description></item><item><title>ترجمهٔ فارسی Todo Cambia</title><link>https://hossein.me/posts/fa/todo-cambia-persian-translation/</link><pubDate>Tue, 20 Jan 2026 00:19:29 +0330</pubDate><guid>https://hossein.me/posts/fa/todo-cambia-persian-translation/</guid><description>&lt;p&gt;
یک آهنگ بسیار زیبای اسپانیایی هست که توی ذهنم پخش میشه و دوست دارم براتون ترجمه‌اش کنم. ممکنه براتون سوال شه آیا اسپانیایی بلدم؟ جواب اینه که نه D:&lt;/p&gt;
&lt;p&gt;
Cambia lo superficial
آنچه سطحی است دگرگون می‌شود
Cambia también lo profundo
آنچه عمیق است نیز دگرگون می‌شود
Cambia el modo de pensar
شیوه تفکر آدم‌ها عوض می‌شود
Cambia todo en este mundo
همهٔ موجودات دنیا تغییر می‌کنند&lt;/p&gt;
&lt;p&gt;
Cambia el clima con los años
آب و هوا با گذر سال‌ها تغییر می‌کند
Cambia el pastor su rebaño
چوپان گله‌اش را تغییر می‌دهد
Y así como todo cambia
و از آنجایی که همه چیز باید تغییر کند
Que yo cambie no es extraño
اینکه من تغییر کنم عجیب نیست&lt;/p&gt;
&lt;p&gt;
Cambia el más fino brillante
زیباترین درخشش تغییر می‌کند
De mano en mano su brillo
هنگامی که از دستی به دستی دیگر می‌رود
Cambia el nido el pajarillo
پرندهٔ کوچک لانه‌اش را تغییر می‌دهد
Cambia el sentir un amante
احساسات یک عاشق هم تغییر می‌کند
Cambia el rumbo el caminante
رَه‌رو مسیرش را تغییر می‌دهد
Aunque esto le cause daño
اگرچه ممکن است برایش آسیب‌زا باشد
Y así como todo cambia
و از آنجایی که همه چیز باید تغییر کند
Que yo cambie no es extraño
اینکه من تغییر کنم عجیب نیست&lt;/p&gt;
&lt;p&gt;
Cambia, todo cambia
تغییر می‌کند، همه چیز تغییر می‌کند
Cambia, todo cambia
تغییر می‌کند، همه چیز تغییر می‌کند
Cambia, todo cambia
تغییر می‌کند، همه چیز تغییر می‌کند
Cambia, todo cambia
تغییر می‌کند، همه چیز تغییر می‌کند
Cambia el sol en su carrera
خورشید در مسیر خود تغییر می‌کند
Cuando la noche subsiste
وقتی که شب پایدار می‌ماند
Cambia la planta y se viste
گیاه تغییر می‌کند و جامه‌ی
De verde en la primavera
سبز رنگ بهاری‌اش را از تن به در می‌کند&lt;/p&gt;
&lt;p&gt;
Cambia el pelaje la fiera
پوستین حیوانات تغییر می‌کند
Cambia el cabello el anciano
موی افراد سالخورده نیز؛
Y así como todo cambia
و از آنجایی که همه چیز باید تغییر کند
Que yo cambie no es extraño
اینکه من تغییر کنم عجیب نیست&lt;/p&gt;
&lt;p&gt;
Pero no cambia mi amor
اما عشق من تغییر نمی‌کند
Por más lejos que me encuentre
هرچقدر هم که به دوردست‌ها سفر کرده باشم
Ni el recuerdo ni el dolor
 نه خاطره و نه دردِ
De mi pueblo y de mi gente
هم‌وطنانم و دیارم تغییری نمی‌کنند
Lo que cambió ayer
آنچه دیروز تغییر کرد
Tendrá que cambiar mañana
باید فردا نیز تغییر کند
Así como cambio yo
همان‌طور که من تغییر می‌کنم
En esta tierra lejana
در این سرزمین دور&lt;/p&gt;</description></item><item><title>Poor Man's VPN: How to Use Reverse SSH for Quick NAT Traversal</title><link>https://hossein.me/posts/en/poor-mans-vpn-autossh/</link><pubDate>Sat, 03 Jan 2026 23:53:49 +0330</pubDate><guid>https://hossein.me/posts/en/poor-mans-vpn-autossh/</guid><description>&lt;p&gt;
Suppose you want to connect from PC &lt;em&gt;A&lt;/em&gt; to PC &lt;em&gt;B&lt;/em&gt;, and neither have a pubilc IP. How can you do that? One way is to use &lt;a href="https://github.com/rustonbsd/iroh-ssh"&gt;iroh-ssh&lt;/a&gt;, it&amp;#39;s neat but currently they don&amp;#39;t support custom relays so it&amp;#39;s a deadend in more restricted networks. But if you own a VPS, you can actually can connect these two.&lt;/p&gt;
&lt;p&gt;
Assuming you have installed &lt;code class="verbatim"&gt;autossh&lt;/code&gt; on &lt;em&gt;B&lt;/em&gt;, create a systemd service on it as well &lt;code class="verbatim"&gt;/etc/systemd/system/autossh-ssh.service&lt;/code&gt;:&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[Unit]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Description=AutoSSH Service
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;After=network.target
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[Service]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Type=simple
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;User=user
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Environment=AUTOSSH_GATETIME=0
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ExecStart=/usr/bin/autossh -M 0 -N -o &amp;#34;ServerAliveInterval 30&amp;#34; -o &amp;#34;ServerAliveCountMax 10&amp;#34; -o &amp;#34;ExitOnForwardFailure yes&amp;#34; -o &amp;#34;AddressFamily inet&amp;#34; -o &amp;#34;TCPKeepAlive no&amp;#34; -R localhost:REMOTE_SSH_PORT_ON_VPS:localhost:SSH_PORT_OF_B -i YOUR_KEY_ADDRESS USER@VPS -p VPS_SSH_PORT
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Restart=always
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;RestartSec=5
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;KillMode=process # Ensure child processes are not killed
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[Install]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;WantedBy=multi-user.target&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Then enable it using &lt;code class="verbatim"&gt;sudo systemctl enable autossh-ssh&lt;/code&gt;. Now it will always keep a connection to your VPS and expose its SSH port on your VPS&amp;#39;s &lt;code class="verbatim"&gt;localhost:REMOTE_SSH_PORT_ON_VPS&lt;/code&gt; (localhost can be changed to your VPS&amp;#39;s static IP if that&amp;#39;s what you need). Now you can connect to &lt;em&gt;B&lt;/em&gt; on your VPS.&lt;/p&gt;
&lt;p&gt;
If you need &lt;em&gt;B&lt;/em&gt;&amp;#39;s SSH port on &lt;em&gt;A&lt;/em&gt;, you have to port forward: &lt;code class="verbatim"&gt;ssh user@VPS_IP -p VP_SSH_PORT -L localhost:REMOTE_SSH_PORT_ON_A:localhost:REMOTE_SSH_PORT_ON_VPS&lt;/code&gt;, which means you can connect to &lt;em&gt;B&lt;/em&gt; from &lt;em&gt;A&lt;/em&gt;: &lt;code class="verbatim"&gt;ssh user@localhost -P REMOTE_SSH_PORT_ON_A&lt;/code&gt;.
Q.E.D!&lt;/p&gt;
&lt;p&gt;
Side note: If for whatever reason you can&amp;#39;t connect to &lt;em&gt;B&lt;/em&gt;, then go to your VPS, kill the SSH that is responsible for the &lt;code class="verbatim"&gt;REMOTE_SSH_PORT_ON_VPS&lt;/code&gt;. After some time &lt;em&gt;B&lt;/em&gt; will create a fresh connection which has a better likelihood of good connection.&lt;/p&gt;
&lt;p&gt;
Side note: If you own a VPS maybe you&amp;#39;re not so poor monetarily but rather temporarily, since you don&amp;#39;t have time to deal with Wireguard and so on.&lt;/p&gt;
&lt;p&gt;
Update: Just use &lt;a href="https://yggdrasil-network.github.io/"&gt;yggdrasil&lt;/a&gt; instead.&lt;/p&gt;</description></item><item><title>پسوند «یک» در فارسی، و «وک» در نیشابوری</title><link>https://hossein.me/posts/fa/ique-suffix-in-nishapuri-language/</link><pubDate>Sat, 20 Dec 2025 19:55:18 +0330</pubDate><guid>https://hossein.me/posts/fa/ique-suffix-in-nishapuri-language/</guid><description>&lt;p&gt;
توی گویش نیشابوری یک پسوند هست که در فارسی اونقدر پررنگ نیست. اونم «ـوک» ه تلفظشم مثل ok در took توی انگلیسیه تقریبا. توی فارسی معادلش ـیک ه. مثلا شما تار/نزد رو دارید بعد ازش تاریک/نزدیک رو می‌گیرید. جوری که توی وب خوندم خود این پسوند از فارسی میانه میاد و با ique مثل تکنولوژیک فرانسوی هم‌ریشه است.&lt;/p&gt;
&lt;p&gt;
خلاصه با همین پسوند که توی فارسی مرده، میشه خیلی چیزا ساخت. پسوند ـی برای ساخت صفت از اسم توی خیلی جاها جواب نمیده. سر همین مثلا پیشنهاد دادن به‌جای گرفتن «بیضوی» از بیضی و «هذلولوی» از هذلولی بگیم «بیضیک» و «هذلولیک». یک سری کلمه‌های خوشگل و باکلاس هم میشه ساخت با این پسوند، مثل «دانشیک» به‌معنی علمی.&lt;/p&gt;
&lt;p&gt;
توی گویش نیشابوری هم چندین تا کلمه هست که ساختشون جالبه.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;پیر -&amp;gt; پیروک (پیرمانند مثلا پوستی که چروکیده باشه)&lt;/li&gt;
&lt;li&gt;باد -&amp;gt; بَدوک (کسی که پرباده، پر از فخرفروشیه)&lt;/li&gt;
&lt;li&gt;جیغ -&amp;gt; جیغوک (کسی که زیاد فریاد میزنه)&lt;/li&gt;
&lt;li&gt;ترسو -&amp;gt; تُرسُنوک (کسی که زیاد می‌ترسه)&lt;/li&gt;
&lt;li&gt;پورچَنه (پرچانه) -&amp;gt; پورچُنوک (کسی که زیاد حرف میزنه)&lt;/li&gt;
&lt;li&gt;چرب -&amp;gt; چوربوک (صفت ظرفای چرب)&lt;/li&gt;
&lt;li&gt;چسبنده -&amp;gt; چُسبُندُنوک (نوچ، چسب‌مانند)&lt;/li&gt;
&lt;li&gt;زرد &amp;gt; زردوک (بیمار)&lt;/li&gt;
&lt;li&gt;گوز -&amp;gt; گَوزوک (گوزو 😁) / چس -&amp;gt; چسّوک (به همین معنی)&lt;/li&gt;
&lt;li&gt;ریخ (فضولات انسانی) -&amp;gt; ریخوک (آنکه زیاد بریند)&lt;/li&gt;
&lt;li&gt;خیل (آب دماغ) -&amp;gt; خیلّوک (کسی که آب دماغش میزنه بیرون)&lt;/li&gt;
&lt;li&gt;عَل‌لُ‌توک (یعنی مریض نمیدونم از چی ساخته شده، احتمالا از علیل میاد)&lt;/li&gt;
&lt;li&gt;لپوک (هندونه یا خربزه رسیده)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;حدس‌های بی‌ربط خودم:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;چوب‌جیک (پرنده‌ای که روی چوب جیک‌جیک می‌کند) بدهد چوب‌جیغک که بدهد -&amp;gt; چغوک (گنجشک)&lt;/li&gt;
&lt;li&gt;ناز -&amp;gt; نَزوک (که بدهد همون نازک فارسی)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;ایدهٔ وبسایت: اگر کسی حال داشت می‌تونه بهم پیام بده خرد خرد و در درازمدت با هم یک سایت بسازیم برای گردآوری لهجه‌های مختلف ایران.&lt;/p&gt;</description></item><item><title>PWN Cheatsheet</title><link>https://hossein.me/posts/en/pwn-cheatsheet/</link><pubDate>Sun, 16 Nov 2025 23:30:51 +0330</pubDate><guid>https://hossein.me/posts/en/pwn-cheatsheet/</guid><description>
&lt;div id="outline-container-headline-1" class="outline-2"&gt;
&lt;h2 id="headline-1"&gt;
x86_64 Assembly
&lt;/h2&gt;
&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;%rax&lt;/code&gt; is a reference to &lt;code class="verbatim"&gt;rax&lt;/code&gt; register.&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;$0x4&lt;/code&gt; is a constant.&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;0(%esp)&lt;/code&gt; or &lt;code class="verbatim"&gt;(%esp)&lt;/code&gt; is the value loaded from the memory address that is stored in &lt;code class="verbatim"&gt;%esp&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;12(%esp)&lt;/code&gt; dereferences memory 12 bytes above the address contained in ESP&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class="verbatim"&gt;mov A,B&lt;/code&gt;, B is changed to become A. A&amp;#39;s value is -&amp;gt; put into B.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This is AT&amp;amp;T x86 syntax (what GDB uses). In this syntax the destination register comes last. In RISC-V assembly the opposite is true.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;push A&lt;/code&gt; adds &lt;code class="verbatim"&gt;A&lt;/code&gt; as the last element of the stack, decreases the value of &lt;code class="verbatim"&gt;rsp/esp&lt;/code&gt; by one word (since the stack grows from high to low).&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;pop rax/eax&lt;/code&gt; removes the last element of the stack, copies into &lt;code class="verbatim"&gt;rax/eax&lt;/code&gt; increases the value of &lt;code class="verbatim"&gt;rsp/esp&lt;/code&gt; by one word (since the stack grows from high to low).&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;jmp&lt;/code&gt; is equivalent to &lt;code class="verbatim"&gt;mov rip, target_address&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;call&lt;/code&gt; is equivalent to &lt;code class="verbatim"&gt;push rip(old return address)&lt;/code&gt; and &lt;code class="verbatim"&gt;jmp dst_func.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;ret&lt;/code&gt; is equivalent to &lt;code class="verbatim"&gt;pop rip(old return address)&lt;/code&gt; which is &lt;code class="verbatim"&gt;jmp src_func&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Because stack grows from high addresses to low addresses:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;sub $8,%rsp&lt;/code&gt; increases stack size.&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;add $8,%rsp&lt;/code&gt; decreases stack size.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-2" class="outline-2"&gt;
&lt;h2 id="headline-2"&gt;
Stack
&lt;/h2&gt;
&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;
&lt;div id="outline-container-headline-3" class="outline-3"&gt;
&lt;h3 id="headline-3"&gt;
Stack
&lt;/h3&gt;
&lt;div id="outline-text-headline-3" class="outline-text-3"&gt;
&lt;img src="https://hossein.me/images/stack.svg" alt="This figure shows the memory layout created by C." title="/images/stack.svg" style="height:100%;width:100%;"/&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-4" class="outline-3"&gt;
&lt;h3 id="headline-4"&gt;
Backgroud
&lt;/h3&gt;
&lt;div id="outline-text-headline-4" class="outline-text-3"&gt;
&lt;ul&gt;
&lt;li&gt;Each byte is 8 bits.&lt;/li&gt;
&lt;li&gt;Each word is 4 bytes in 32-bit systems and 8 bytes in 64-bit systems.&lt;/li&gt;
&lt;li&gt;Each register can store one word.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-5" class="outline-3"&gt;
&lt;h3 id="headline-5"&gt;
Registers
&lt;/h3&gt;
&lt;div id="outline-text-headline-5" class="outline-text-3"&gt;
&lt;div id="outline-container-headline-6" class="outline-4"&gt;
&lt;h4 id="headline-6"&gt;
Pointing to the code section
&lt;/h4&gt;
&lt;div id="outline-text-headline-6" class="outline-text-4"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;rip/eip&lt;/code&gt; is the instruction pointer, and it stores the address of the machine instruction currently being executed (code section). In RISC-V, this register is called the PC (program counter).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-7" class="outline-4"&gt;
&lt;h4 id="headline-7"&gt;
Pointing to the stack section
&lt;/h4&gt;
&lt;div id="outline-text-headline-7" class="outline-text-4"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;rbp/ebp&lt;/code&gt; is the base pointer, and it stores the address of the base of the current stack frame. In RISC-V systems, this register is called the FP (frame pointer).&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;rsp/esp&lt;/code&gt; is the stack pointer, and it stores the address of the last element of the current stack frame. In RISC-V, this register is called the SP (stack pointer).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-8" class="outline-4"&gt;
&lt;h4 id="headline-8"&gt;
General Purpose Registers
&lt;/h4&gt;
&lt;div id="outline-text-headline-8" class="outline-text-4"&gt;
&lt;ul&gt;
&lt;li&gt;16 general purpose registers in 64-bit systems: &lt;code class="verbatim"&gt;RAX&lt;/code&gt;, &lt;code class="verbatim"&gt;RBX&lt;/code&gt;, &lt;code class="verbatim"&gt;RCX&lt;/code&gt;, &lt;code class="verbatim"&gt;RDX&lt;/code&gt;, &lt;code class="verbatim"&gt;RSI&lt;/code&gt;, &lt;code class="verbatim"&gt;RDI&lt;/code&gt; and &lt;code class="verbatim"&gt;R8&lt;/code&gt; to &lt;code class="verbatim"&gt;R15&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;6 general puprose registers in 32-bit systems: &lt;code class="verbatim"&gt;EAX&lt;/code&gt;, &lt;code class="verbatim"&gt;EBX&lt;/code&gt;, &lt;code class="verbatim"&gt;ECX&lt;/code&gt;, &lt;code class="verbatim"&gt;EDX&lt;/code&gt;, &lt;code class="verbatim"&gt;ESI&lt;/code&gt;, &lt;code class="verbatim"&gt;EDI&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;table style="height:80%;width:50%; text-align:center; margin:auto;"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Argument&lt;/th&gt;
&lt;th&gt;Register (64-bit)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Arg 1&lt;/td&gt;
&lt;td&gt;%rdi&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arg 2&lt;/td&gt;
&lt;td&gt;%rsi&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arg 3&lt;/td&gt;
&lt;td&gt;%rdx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arg 4&lt;/td&gt;
&lt;td&gt;%rcx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arg 5&lt;/td&gt;
&lt;td&gt;%r8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arg 6&lt;/td&gt;
&lt;td&gt;%r9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-9" class="outline-3"&gt;
&lt;h3 id="headline-9"&gt;
Little Endian or Big Endian
&lt;/h3&gt;
&lt;div id="outline-text-headline-9" class="outline-text-3"&gt;
&lt;ul&gt;
&lt;li&gt;Address numbers point to bytes.&lt;/li&gt;
&lt;li&gt;Using little endian &lt;code class="verbatim"&gt;0x44332211&lt;/code&gt; will be stored like &lt;code class="verbatim"&gt;0x11 0x22 0x33 0x44&lt;/code&gt; in memory, meaning that the most signifcant byte has the highest address number (the memory starts from &lt;code class="verbatim"&gt;0x0&lt;/code&gt; to &lt;code class="verbatim"&gt;0x3&lt;/code&gt;, and &lt;code class="verbatim"&gt;0x44&lt;/code&gt; is stored at &lt;code class="verbatim"&gt;0x3&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-10" class="outline-2"&gt;
&lt;h2 id="headline-10"&gt;
Function Call in x86
&lt;/h2&gt;
&lt;div id="outline-text-headline-10" class="outline-text-2"&gt;
&lt;p alt="This figure shows the memory layout created by C, after the function foo below is called (almost)." style="height:100%;width:100%;"&gt;&lt;img src="https://hossein.me/images/stack-func-call.svg" alt="/images/stack-func-call.svg" title="/images/stack-func-call.svg"/&gt;
See the photos in &lt;a href="https://textbook.cs161.org/memory-safety/x86.html"&gt;UC Berkeley&amp;#39;s CS161 Textbook&lt;/a&gt; &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Function args are pushed into the stack. (or onto the general registers such as &lt;code class="verbatim"&gt;rdi&lt;/code&gt;, &lt;code class="verbatim"&gt;rsi&lt;/code&gt;, &lt;code class="verbatim"&gt;rdx&lt;/code&gt;, &lt;code class="verbatim"&gt;rcx&lt;/code&gt; if SysV x86-64)&lt;/li&gt;
&lt;li&gt;Return address (old &lt;code class="verbatim"&gt;rip&lt;/code&gt;) is pushed into the stack. &lt;/li&gt;
&lt;li&gt;Function jump happens (&lt;code class="verbatim"&gt;rip&lt;/code&gt; = new &lt;code class="verbatim"&gt;rip&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The new function pushes old &lt;code class="verbatim"&gt;rbp&lt;/code&gt; onto the stack.&lt;/li&gt;
&lt;li&gt;Previous frame&amp;#39;s &lt;code class="verbatim"&gt;rbp&lt;/code&gt; becomes the current &lt;code class="verbatim"&gt;rsp&lt;/code&gt; (old function&amp;#39;s last element is the new functions bottom)&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;rsp&lt;/code&gt; is grown to fit the new function.&lt;/li&gt;
&lt;li&gt;The new function does whatever it does&lt;/li&gt;
&lt;li&gt;At the end of the new function&amp;#39;s run, we are at its &lt;code class="verbatim"&gt;rbp&lt;/code&gt;, which is the old one&amp;#39;s &lt;code class="verbatim"&gt;rsp&lt;/code&gt;. Previous frame&amp;#39;s &lt;code class="verbatim"&gt;rsp&lt;/code&gt; is the present frame&amp;#39;s &lt;code class="verbatim"&gt;rbp&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Old &lt;code class="verbatim"&gt;rbp&lt;/code&gt; is poped back.&lt;/li&gt;
&lt;li&gt;Old &lt;code class="verbatim"&gt;rip&lt;/code&gt; is poped back.&lt;/li&gt;
&lt;li&gt;Decrease the size of the stack by the size of args.&lt;/li&gt;
&lt;/ol&gt;
&lt;div id="outline-container-headline-11" class="outline-3"&gt;
&lt;h3 id="headline-11"&gt;
Example C code
&lt;/h3&gt;
&lt;div id="outline-text-headline-11" class="outline-text-3"&gt;
&lt;div class="src src-c"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;foo&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; a, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; bar[&lt;span style="color:#ae81ff"&gt;4&lt;/span&gt;];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;foo&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Which gives the following assembly:&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;0000000000001129 &amp;lt;foo&amp;gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1129:	55 	push %rbp // Step 4. RBP is saved on the stack right below RIP (saved in the previous step).
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 112a:	48 89 e5 	mov %rsp,%rbp // Step 5. The new stack base is the previous stack pointer.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 112d:	89 7d ec 	mov %edi,-0x14(%rbp) // Foo saves first arg into its own stack to free up %edi 
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1130:	89 75 e8 	mov %esi,-0x18(%rbp) // Foo saves second arg into its own stack to free up %esi
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1133:	90 	nop // Alignment, could be Step 6. =sub $N, %rsp= &amp;amp; Step. 7 if our function involved anything.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // Since Step. 6 didn&amp;#39;t take place, rsp didn&amp;#39;t change.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // therefore =mov %rsp, %rbp= (Step 8) is not run either.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // We could change this behavior using gcc flag -mno-red-zone
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1134:	5d 	pop %rbp // Step 9. Old RBP is restored
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1135:	c3 	ret // == pop %rip which is Step 10. Old RIP is restored
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // Step 11. doesn&amp;#39;t happen since in the x86-64 ABI, since the caller
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // passed arguments in registers, there is nothing on the stack for
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // the caller to clean up
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;0000000000001136 &amp;lt;main&amp;gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1136:	55 	push %rbp // This is step 4 since main is not the starting function and is being called from _start
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1137:	48 89 e5 	mov %rsp,%rbp // this is also step 5 but we don&amp;#39;t analyze main.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 113a:	be 02 00 00 00 	mov $0x2,%esi // Step 1. Saving args (from right to left): 2 
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 113f:	bf 01 00 00 00 	mov $0x1,%edi // Step 1. Saving args (from right to left): 1 
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1144:	e8 e0 ff ff ff 	call 1129 &amp;lt;foo&amp;gt; // Step 2. RIP is pushed on the stack. Step 3. RIP is changed to the func address of foo (00001129).
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 1149:	b8 00 00 00 00 	mov $0x0,%eax
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 114e:	5d 	pop %rbp
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 114f:	c3 	ret&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-12" class="outline-2"&gt;
&lt;h2 id="headline-12"&gt;
Binary Background Check
&lt;/h2&gt;
&lt;div id="outline-text-headline-12" class="outline-text-2"&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Purpose&lt;/td&gt;
&lt;td&gt;Command&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Check security properties (NX bit, dynamic vs static)&lt;/td&gt;
&lt;td&gt;&lt;code class="verbatim"&gt;rabin2 -I a.out&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;List functions imported from shared libraries&lt;/td&gt;
&lt;td&gt;&lt;code class="verbatim"&gt;rabin2 -i a.out&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find functions likely written by the programmer&lt;/td&gt;
&lt;td&gt;&lt;code class="verbatim"&gt;rabin2 -qs a.out&lt;/code&gt; piped to &lt;code class="verbatim"&gt;grep -ve imp -e &amp;#39; 0 &amp;#39;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Find strings&lt;/td&gt;
&lt;td&gt;&lt;code class="verbatim"&gt;strings a.out&lt;/code&gt; or (better) &lt;code class="verbatim"&gt;rabin2 -z split&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-13" class="outline-2"&gt;
&lt;h2 id="headline-13"&gt;
Return Oriented Programming
&lt;/h2&gt;
&lt;div id="outline-text-headline-13" class="outline-text-2"&gt;
&lt;div id="outline-container-headline-14" class="outline-3"&gt;
&lt;h3 id="headline-14"&gt;
Finding ROPs
&lt;/h3&gt;
&lt;div id="outline-text-headline-14" class="outline-text-3"&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;With ROPGadget:&lt;/p&gt;
&lt;div class="src src-bash"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ROPgadget --binary libc.so.6 --only &lt;span style="color:#e6db74"&gt;&amp;#34;add|jmp&amp;#34;&lt;/span&gt; &amp;gt; output &lt;span style="color:#75715e"&gt;# in case you&amp;#39;re looking for add followed by jump for example, otherwise remove&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cat output | grep &lt;span style="color:#e6db74"&gt;&amp;#39;add rdi, 0x10 ; jmp rc&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With Ropper:&lt;/p&gt;
&lt;div class="src src-bash"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ropper --file ./libc.so.6 --search &lt;span style="color:#e6db74"&gt;&amp;#34;add rdi, 0x10; jmp rcx&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-15" class="outline-2"&gt;
&lt;h2 id="headline-15"&gt;
Misc
&lt;/h2&gt;
&lt;div id="outline-text-headline-15" class="outline-text-2"&gt;
&lt;ul&gt;
&lt;li&gt;PLT (Procedure Linkage Table): a small trampoline in the binary used for calls to external (dynamically linked) functions. Calls in the code go to func@plt; the PLT entry jumps to the real function address found in the GOT (or invokes the dynamic resolver on first call).&lt;/li&gt;
&lt;li&gt;GOT (Global Offset Table): a writable table of addresses in the binary. Each GOT slot holds the runtime address of a library function (or other dynamic symbol). The dynamic linker/loader fills GOT entries the first time a PLT entry is used (or at load time, depending on RELRO).&lt;/li&gt;
&lt;li&gt;They let the loader resolve and redirect calls to shared-library functions without embedding fixed library addresses in the code (works with ASLR and dynamic linking).&lt;/li&gt;
&lt;/ul&gt;
&lt;div id="outline-container-headline-16" class="outline-3"&gt;
&lt;h3 id="headline-16"&gt;
Memory Alignment
&lt;/h3&gt;
&lt;div id="outline-text-headline-16" class="outline-text-3"&gt;
&lt;ul&gt;
&lt;li&gt;Why it happens: &lt;a href="https://stackoverflow.com/a/381368"&gt;to give data to the CPU/CPU cache in one read instead of two&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-17" class="outline-2"&gt;
&lt;h2 id="headline-17"&gt;
Sources
&lt;/h2&gt;
&lt;div id="outline-text-headline-17" class="outline-text-2"&gt;
&lt;p&gt;Disclaimer: Some of the sentences here are a direct copy of the links below, so I don&amp;#39;t own their copyright. Follow the original sources.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ropemporium.com/guide.html"&gt;https://ropemporium.com/guide.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/7060970/substitutes-for-x86-assembly-call-instruction"&gt;https://stackoverflow.com/questions/7060970/substitutes-for-x86-assembly-call-instruction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://textbook.cs161.org/memory-safety/x86.html#fnref:2"&gt;https://textbook.cs161.org/memory-safety/x86.html#fnref:2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item><item><title>نظرات خواندنی هکرنیوز درمورد تحریم‌ها بر ایرانیان</title><link>https://hossein.me/posts/fa/irans-sanctions/</link><pubDate>Mon, 27 Oct 2025 16:59:24 +0330</pubDate><guid>https://hossein.me/posts/fa/irans-sanctions/</guid><description>&lt;p&gt;
یک آقای مهربون ایرانی توی اینترنت &lt;a href="https://news.ycombinator.com/item?id=45343108"&gt;درمورد تجربه‌ی تلخ ما ایرانی‌ها زیر تحریم نوشته&lt;/a&gt; و حسابی دیده شده و صحبت شده درموردش. دوست داشتید ببینید.&lt;/p&gt;
&lt;p&gt;
و خب جالبه که ما صدایی نداریم. یعنی بار اوله دارم می‌بینم درمورد اثر تحریم‌ها بر زندگی ایرانی‌های صحبت بشه توی جامعه‌ی فنی خارجی‌ها.&lt;/p&gt;
&lt;p&gt;
بحث خارجی‌ها درمورد تحریم‌ها جالبه ولی خود مطالب دوستمون برای هر ایرانی خاطره است. با این حال چیزی که از خوندنش یاد گرفتم اینه:
تحریم باید با پاسخ HTTP شماره‌ی ۴۵۱ (منع قانونی) گفته بشه نه ۴۰۳ (منع کلی). عدد ۴۵۱ هم از کتاب بسیار معروف «فارنهایت ۴۵۱» میاد که درمورد کتاب‌سوزی و سانسوره :)&lt;/p&gt;
&lt;p&gt;
نظر نمونه:&lt;/p&gt;
&lt;blockquote style="direction:ltr !important; text-align: left !important;"&gt;
&lt;p&gt;The sad part about living in Iran from a technology perspective is you are often blocked from both sides. Often you have to circumvent the government&amp;#39;s aggressive internal firewall and other times you will have to hide your IP from the service providers.&lt;/p&gt;
&lt;p&gt;
On the bright side, your average Iranian grandma can immediately work as a network engineer given the amount of experience she has with VPN protocols.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;😂😂😂&lt;/p&gt;</description></item><item><title>مستند پایتون، و زنان در فناوری</title><link>https://hossein.me/posts/fa/python-and-pyladies/</link><pubDate>Wed, 17 Sep 2025 19:26:32 +0330</pubDate><guid>https://hossein.me/posts/fa/python-and-pyladies/</guid><description>&lt;p&gt;
امروز بالاخره وقت کردم و مستند پایتون رو دیدم. مستند جالبیه توضیح میده زبان پایتون چه شکلی به‌وجود اومده و همه‌ی این مسائل.&lt;/p&gt;
&lt;img src="https://esmithy.net/images/pycon-guido.jpg" alt="تصویری از خالق زبان پایتون با یک تی‌شرت که روی آن به انگلیسی نوشته شده است پایتون برای دختران است." title="https://esmithy.net/images/pycon-guido.jpg" style="height:70%;width:90%;"/&gt;
&lt;p&gt;
تصویر برگرفته از &lt;a href="https://esmithy.net/2016/06/01/pycon-2016-day-2/"&gt;اینجا&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
ولی جدا از مسائل تاریخچه‌ای، سه نکته‌ی جالب داشت برام:&lt;/p&gt;
&lt;p&gt;
یکم، خالق پایتون، آقای خیدو فان روسوم در اصل هلندیه و زمانی که زبان رو خلق می‌کنه در هلند زندگی می‌کرده. خودش توی مستند می‌گه که وقتی پایتون رو منتشر کردم ۹۹٪ آدمایی که باهاشون صحبت می‌کردم توی آمریکا بودن پس برای پیشرفت بیشتر مهاجرت کردم به آمریکا.&lt;/p&gt;
&lt;p&gt;
دوم، با اینکه زبان پایتون تا سال ۲۰۱۸ تمامی تصمیماتش توسط شخص آقای خیدو گرفته می‌شده ولی سال ۲۰۱۸ استعفا میده از مقامش و الان تصمیمات زبان پایتون رو یک کمیته‌ی ۵ نفره می‌گیرن که با رای‌گیری انتخاب می‌شن.&lt;/p&gt;
&lt;p&gt;
سوم، یک قسمت مستند که به شخصه برام خیلیییی زیبا بود دیدنش؛ و حکایت از شخصیت بسیار عالی خالق پایتون داره، قسمتی مرتبط با حضور زنان بود. حتما سعی کنید اصلش رو از یوتیوب ببینید (از &lt;a href="https://youtu.be/GfH4QL4VqJ0?t=3329"&gt;این ثانیه&lt;/a&gt;)، یک بخش مستقله و نیازی نیست قبلش رو ببینید. اگر ندیدید، خلاصه‌ی زیر رو بخونید:&lt;/p&gt;
&lt;p&gt;
سازنده‌ی زبان پایتون آقای خیدو فان روسوم، داشته توی گوگل کار می‌کرده (نصف وقتش رو برای توسعه‌ی زبان پایتون میذاشته و نیمی از وقتش رو برای کارهاش در گوگل) که یک روز یک تی‌شرت توی جعبه‌ی پستیش در گوگل می‌گیره که روش نوشته Python is for girls. اون موقع متوجه میشه که چقدر جای زنان توی جامعه‌ی پایتون خالیه و مثلا فقط ۱٪ ارائه‌دهنده‌های کنفرانس پایتون توی سال ۲۰۱۱ خانم بودن. مشکل رو پی می‌گیره و این عدد توی سال ۲۰۱۶ به ۴۰٪ می‌رسه 🚀&lt;/p&gt;
&lt;p&gt;
توی سال ۲۰۱۵ هم آقای خیدو توی ارائه‌اش در کنفرانس پایتون اعلام می‌کنه که هدفش اینه که سال بعدی حداقل دوتا خانم توسعه‌دهندهٔ هسته‌ی پایتون باشن. و حاضره حتی خودش هر هفته وقت بذاره و اون خانم رو آموزش بده. خانمی به اسم ماریتا اونجا بوده و با خودش می‌گه که نه من ارزشش رو ندارم و نمی‌تونم. سال ۲۰۱۶ که دوباره کنفرانس برگزار میشه، خیدو میگه هیچ خانمی اعلام آمادگی نکرده و هنوزم حاضره که اگر خانمی داوطلب بشه آموزش بده. ماریتا داوطلب میشه و یک سال بعدش دسترسی commit به هسته‌ی پایتون می‌گیره 🎉&lt;/p&gt;
&lt;p&gt;
دیدن ویدئو حال و هوایی دیگه داره چون قشنگ میشه استرس و اون احساسات منفی‌ای که باعث می‌شده اون خانم و خانمای دیگه داوطلب نشن برای این کار رو توی چهره‌ی ماریتا خوند.
خلاصه دم آقای خیدو گرم هم بابت زبان پایتون و هم بابت شخصیت بزرگش.&lt;/p&gt;
&lt;p&gt;
و در نهایت هم باید بگم که تازه کشف کردم اسم زبان پایتون از &lt;a href="https://fa.wikipedia.org/wiki/%D9%85%D8%A7%D9%86%D8%AA%DB%8C_%D9%BE%D8%A7%DB%8C%D8%AA%D8%A7%D9%86"&gt;گروه کمدی مانتی‌پایتون&lt;/a&gt; میاد و نه مار پایتون :) ولی بسته‌ی آناکوندا علت نام‌گذاریش اینه که توی حیطه‌ی کلان‌داده است و آناکوندا هم یک مار بزرگه.&lt;/p&gt;
&lt;p&gt;
مطلب زیر هم با اجازه از صاحب متن، &lt;a href="https://t.me/crimson_diary/122"&gt;از این کانال تلگرامی&lt;/a&gt; برداشتم و به نظرم خیلی درسته:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;«چند روز پیش توی محل کار به شوخی صحبت این شد که تیممون (خصوصا بعد از مهاجرت دو تا از دخترهای تیم به خارج از کشور) چقدر مردونه شده و یه مشت انسان مذکر دور هم جمع شدیم و واسه تیم‌سازی حتی می‌تونیم بریم استخر و پارک آبی و خلاصه هی با هم شوخی‌های لوس و بی‌مزه می‌کردیم و هارهار می‌خندیدیم.
.
بعدتر من فکری شدم که چرا دایورسیتی جنسیتی کلا بخش‌های فنی یه دست نیست. نه توی شرکت ما که توی اکثر شرکت‌های Tech اگه دقت کنی، بیشتر نیروهای فنی (و البته مدیریتی) آقا هستند و خانم‌ها توی بخش‌های دیگه مثل HR یا بخش مالی و اداری و … حضور پررنگ‌تری دارن؟&lt;/p&gt;
&lt;p&gt;
این گوشه ذهنتون باشه تا یه چیز دیگه بگم…&lt;/p&gt;
&lt;p&gt;
خیلیا می‌دونن که من قدیم‌ترها سالیان سال توی مدارس تیزهوشان تدریس برنامه‌نویسی می‌کردم و البته توی چند سال اخیر علارغم میل شخصی، فرصت نشده دیگه هیچ‌ مدرسه‌ای برم و صرفا تک و توک پنج‌شنبه جمعه‌ها برای تنوع و حال دل خودم، خصوصی تدریس کردم. تقریبا درصد خیلی زیادی از شاگردهای من پسر بودن. و  به ندرت به دخترها درس می‌دادم. معمولا هم اولیا و خود بچه‌ها از نحوه تدریسم راضی بودن و من هیچ وقت، هیچ جا و به هیچ‌ شکلی، تبلیغی برای کلاسام نداشتم و همگی معرفی خود خونواده ها به همدیگه بوده.&lt;/p&gt;
&lt;p&gt;
منتهی به نظر خودم اقبالی که بین پسرها داشتم، پیش دخترها نداشتم. یعنی از نحوه پیشرفت کلاسم با دخترها کمتر راضی بودم.
این مشکل رو معمولا به این ربط می‌دادم که احتمالا ذهن دخترها آمادگی کمتری برای پیشرفت توی مباحث منطقی و الگوریتمی داره و یحتمل توی جاهای دیگه قوی‌تره. یه درصدی از مشکل رو هم البته کنار گذاشته بودم که چون با پسرها راحت‌تر هستم و البته تجربه خیلی بیشتری دارم، پس خروجی کارم هم در مورد پسرها بهتره و واسه دخترا هنوز قلق کار دستم نیومده!
.
مدت کمیه با یه دختری کلاس دارم. دختر خیلی باهوشی که فرانسه و انگلیسیش عالیه و از جلسه اول هم هوش و استعدادش مشخص بود. منتهی توی این یکی دو ماهی که باهاش کار کرده بودم، هر سری از سختی سوالات و تمرین‌ها شاکی بود و گاهی بود که هی می‌گفت که آٍقا من اینو تقریبا بلد بودم. بعد من می‌گفتم پس چرا هیچ کدی نزدی؟ که معمولا جواب درستی براش نداشت.
امروز پنج‌شنبه تصادفا از روی یکی از draft های کدش فهمیدم که این بشر چیزای خوبی هم می‌نوشته و تا حد خوبی به جواب نزدیک می‌شده و بعد پاکش می‌کرده و همش غر می‌زده که هیچی نمی‌فهمه! و من خیلی شانسی اینو کشف کردم!&lt;/p&gt;
&lt;p&gt;
این اعصابم رو یکم خط‌خطی کرد که چرا باید این مدلی باشه و دختری با این استعداد اعتماد به نفس کافی رو نداشته که اون برنامه نصفه نیمه رو به من نشون بده!
یکم سرچ کردم و یه تدتالک جالبی پیدا کردم که توی پست بعدی خلاصشو و لینکشو می‌ذارم و تقریبا حس می‌کنم تا حد خوبی جواب این مساله همین باشه و برای خودم زیبا و جالب بود.&lt;/p&gt;
&lt;p&gt;
تصویر بالا متعلق به خانومیه به اسم Reshma Saujani که یه خانم آمریکاییه که البته همونطور که از اسمشم مشخصه یکم رگ و ریشه هندی هم داره و زن باکمالاتیه.
کارای زیادی کرده و کله‌اش زیاد باد داشته که حالا ما کاری نداریم. ولی گویا اینم این مشکل شکاف جنیستی رو توی شرکت های فناوری درک کرده و به همین خاطر سال ۲۰۱۲ یه سازمان تاسیس کرده به اسم Girls Who Code. که هدفش این بوده که با آموزش مهارت های برنامه نویسی به دخترا و برگزاری سمینار و کارگاه و کوفت و زهرمار این شکاف رو یکم پر کنه.&lt;/p&gt;
&lt;p&gt;
توی این تدتالکی که ایشون صحبت کرده و من در ادامه لینکشو می‌ذارم، مشخصه طرف مثل من پرحرفه و توی سخنرانیش هم بنده خدا از هر دری یه صحبتی می کنه. ولی یه بخشیش که فوکوس می‌کنه روی این مساله ضعف دخترها توی برنامه نویسی، خیلی جالبه.&lt;/p&gt;
&lt;p&gt;
می گفت که مشکل اصلی اینه که نگاه تربیتی ما به پسرها اینه که باید شجاع بار بیان، ریسک کنن و از اشتباه نترسن. اما برعکس در مورد دخترها نگاه غالب اینه که بی نقص باشن و این ارزش رو براشون بولد می‌کنن.
و به زیبایی می‌گه که خیلیا توی آمریکا نگران کسری بودجه فدرال هستن ولی من نگران کسری شجاعت هستم!&lt;/p&gt;
&lt;p&gt;
و صحبت از یه آزمایش روانشناسی می‌کنه که خیلی سال پیش انجام شده در مورد دانش آموزای کلاس پنجمی که نتیجه‌اش این بوده که دخترهای باهوش خیلی زودتر مساله و چالشی که باهاش درگیر هستن رو رها می‌کنن و هرچی ضریب هوشی‌شون بالاتر، احتمال رها کردن کار هم بیشتره!
برعکس پسرها که کلا حال می‌کنن کار سخت رو باهاش درگیر بشن و ازش انرژی می‌گیرن و تازه وقتی گیر کنن خیلی بیشتر تلاش می‌کنن. چون کلا روحیشون از اول برای ریسک‌پذیری آماده شده برعکس دخترها که به واسطه ارزش بی‌نقص بودن مجبور بودن که همیشه محتاط‌تر باشن.&lt;/p&gt;
&lt;p&gt;
یه جای حرفش هم برای من خیلی جالب بود و شبیه تجربه‌ام توی کلاس خودم بود.
می‌گفت که توی موسسه‌اش یکی از دخترها اومده به معلمش گفته من اصن نمی‌دونم چه دستوری باید بنویسم؟ و معلم هم به صفحش نیگاه کرده و دیده که کلا صفحش خالیه و تصور می کنه که کل زمانی که اون دختر فرصت داشته رو انگار به صفحه خالی زل زده! ولی بعد چندباری دکمه کنترل زد رو می‌زنه و می بینه که دانش آموزش چندین بار برنامه رو نوشته و گاهی خیلی هم به جواب نزدیک شده بوده ولی به خاطر یکی دو تا مشکل کلشو پاک کرده بوده چون جواب دقیق و کامل رو به دست نیاورده بوده. و در واقع ترجیح داده به جای اینکه روندی که توی حل مساله پیش رفته رو نشون بده، هیچ چیزی نشون نده!&lt;/p&gt;
&lt;p&gt;
حتی یه مثال جالبی زده از استاد یه دانشگاه کلمبیا که جاوا تدریس می‌کرده. و می‌گفته که وقتی پسرها توی یه تکلیف به مشکل می‌خوردن، با یه ادبیاتی شبیه اینکه «استاد یه مشکلی توی کد من هست» سوالشونو مطرح می‌کردن. ولی دخترا معمولا اینجوری می‌گفتن که «استاد من یه مشکلی دارم!» و همین هم تفاوت نگاه پسرها و دخترها رو تا یه حدی نشون میده.&lt;/p&gt;
&lt;p&gt;
و خلاصه آخرش زیبا نتیجه گرفته که برای دخترها فقط آموزش برنامه نویسی کافی نیست و باید اون‌قدر شجاعتشون رو زیاد کنیم که از برنامه اشتباه نترسن. از سوال کردن و راهنمایی گرفتن هم نترسن. و اینجوریه که احتمالا به جایگاه واقعیشون توی جامعه نزدیک‌تر بشن.&lt;/p&gt;
&lt;p&gt;
پی‌نوشت:
اگه فرصتشو داشتید فیلم صحبت‌ها رو کامل ببینید چون مثال‌های جالب دیگه ای هم داشت.
.
و در کل اگه دور و برتون توی دوست و آشنا دختر جوونی هست که اول راهه، خیلی خوبه که تشویقش کنید که جسارتشو زیاد کنه. ریسک پذیر باشه و از سوال کردن و نشون دادن مشکلش نترسه. باشد که آینده‌ی بهتری در انتظارش باشه.&lt;/p&gt;
&lt;p&gt;
لینک ویدیوی تدتالک:
&lt;a href="https://www.youtube.com/watch?v=fC9da6eqaqg"&gt;https://www.youtube.com/watch?v=fC9da6eqaqg&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
لینک موسسه‌ای که اون خانومه راه انداخته:
&lt;a href="https://girlswhocode.com/"&gt;https://girlswhocode.com/&lt;/a&gt;
»&lt;/p&gt;
&lt;/blockquote&gt;</description></item><item><title>باور</title><link>https://hossein.me/posts/fa/believe/</link><pubDate>Thu, 04 Sep 2025 14:48:09 +0330</pubDate><guid>https://hossein.me/posts/fa/believe/</guid><description>
&lt;p&gt;
قسمت اول، یادداشت‌برداری بسیار نامرتب من از &lt;a href="https://en.wikipedia.org/wiki/The_Will_to_Believe"&gt;متن آقای ویلیام جیمز درمورد باوره&lt;/a&gt; و قسمت دوم از مقالهٔ &lt;a href="https://en.wikisource.org/wiki/The_Will_to_Believe_and_Other_Essays_in_Popular_Philosophy/Is_Life_Worth_Living"&gt;ارزش زندگی&lt;/a&gt;ه. برای قسمت دوم &lt;a href="https://reasonandmeaning.com/2015/10/30/william-james-faith-and-the-meaning-of-life"&gt;این متن&lt;/a&gt; خلاصه‌ی زیباتریه.&lt;/p&gt;
&lt;div id="outline-container-headline-1" class="outline-2"&gt;
&lt;h2 id="headline-1"&gt;
باور بدون مدرک
&lt;/h2&gt;
&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;
&lt;ol&gt;
&lt;li&gt;نمیشه با اراده باور کرد (مثلا که ابراهام لینکلن واقعی نیست یا درد نداریم وقتی چاقو خوردیم)&lt;/li&gt;
&lt;li&gt;با اینکه به بعضی چیزا باور داریم ولی نمیدونیم چرا. احتمالا تاثیر محیط اطرافه. مثلا به ملکول باور داریم چون پرستیژ باورداشتن بهش خوبه. اکثر اوقات باورمون به باور داشتن اطرافیان وابسته است.&lt;/li&gt;
&lt;li&gt;حتی اینکه یک حقیقت وجود داره رو هم نمیشه مطمئن بود (Pyrrhonistic) و برای این بهش باور داریم که جامعه ازمون همایت می‌کنه.&lt;/li&gt;
&lt;li&gt;پس ما به چیزهایی باور نداریم که به کارمون نمیاد. مثلا برای یک نفر مسیحیت به دردش نمیخوره پس بهش باور نداره. اگر یکی بیاد مثلا بگه تله‌پاتی هست ممکنه دانشمندها مسخره‌اش کنن ولی اگر بیاد این رو همراه با یک کاربرد به دانشمندها بگه یا کاری که بتونن باهاش بکنن دانشمندا بهش توجه می‌کنن.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;نتیجه‌گیری «بخش‌های غیرانتلکتی ما، بر باورهای ما اثرگذارند»&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;بعضی از تمایلات و کشش‌ها به سمت بعضی باورها فقط بعد از یک باور رخ میدن مثلا شرط پاسکال اینطوریه که برای یک مسیحی باعث تقویت ایمان میتونه باشه و بسیار باورپذیر ولی برای بقیه نه.&lt;/li&gt;
&lt;li&gt;برای یک شواهدگرا مهم نیست که یک منشا ایده اشتباه بوده یا درست، ‌مهم اینه که آیا مشاهدات بعدیش تاییدش می‌کنن یا نه و ادامه میده به درست بودن اون ایده یا نه. اگر ادامه داد پس برای اون شخص درسته.&lt;/li&gt;
&lt;li&gt;دو شیوه‌ی فکر کردن وجود داره:‌ یکی اینکه باید حقیقت رو پیدا کنیم، یکی اینکه باید از خطا بپرهیزیم. توی عقیده‌ی کسایی که با مسیحیت مخالفن میگن که باید حتما دلایل کافی داشت تا باور کرد و تا مدارک کافی نباشه، باور کردن اشتباهه. این طرز تفکر باعث میشه که انسان به کمتر چیزی باور داشته باشه. ولی اونایی که از خطا پرهیز می‌کنن میتونن حدس‌های زیادی درمورد حقیقت بزنن و باور داشته باشن، و باورهاشون رو در مسیر اگر با مدرک اشتباه بودن مواجه شدن عوض کنن.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;در واقع نویسنده بر این باوره که بهتره از اشتباه نترسید. مثل ژنرالی نباشید که به سربازهاش میگه که نجنگید که زخمی نشید. بهتره رفت و باور داشت اگر غلط بود ضربه دید و بعد باور رو عوض کرد.
هر زمان که فرق بین از دست دادن حقیقت و به‌دست آوردنش مهم نباشه، میتونیم تصمیم بگیریم که تا زمان به دست اوردن مدرک قطعی کلا بیخیال حقیقت شیم تا اقلا فریب نخوریم، توی کار یک قاضی معمولا این شکلیه و تصمیم‌نگرفتن میتونه یک گزینه باشه، یا درمورد روابط انسانی اینکه یک گزینه رو انتخاب کنیم ولی مدام حواسمون به مدارک له و علیهش هم باشه.
علم دقیقا اینطوریه و همیشه هر دو جانب رو به دقت نگاه می‌کنه و بیشتر علاقه‌مند به اینه که بشه به صورت تکنیکی چیزی رو تایید کرد. و قدرتش هم از همین میاد.&lt;/p&gt;
&lt;p&gt;
زمانی که مجبور به انتخاب نیستیم، بهترین شیوه همین شکاک بودنه تا اینکه فریب نخوریم. اما سوال اینه که در زمان‌هایی که باید انتخاب کنیم، آیا عاقلانه است که بی‌عمل باشیم و تا زمانی که مدارک پیدا نشه دست به انتخاب نزنیم؟&lt;/p&gt;
&lt;p&gt;
درمورد سوال‌های اخلاقی، زمانی برای یافتن پاسخ با مدرک وجود نداره، چون علم می‌تونه به ما بگه که «چه چیزی وجود دارد» ولی پاسخ اینکه چه چیزی ارزشمندتره رو نداره. در این موقع ما باید اونطور که پاسکال می‌گه به قلبمون گوش کنیم. (پاسکال: La coeur a ses raisons que la raison ne cannait pas)
اینکه آیا باید باورهای اخلاقی داشته باشیم یا نه با اراده‌ی ما مشخص می‌شه. آیا ترجیحات اخلاقی درستن یا غلط، آیا خوب و بد برای ما فقط تعریف میشه درحالی که در واقعیت امور بی‌تفاوتن؟ تنها با مغز نمیشه تصمیم گرفت. اگر قلب شما نخواد به دنیای اخلاقی باور کنه مغزتون هم نخواهد پذیرفت. مشابه اینکه در زمینه‌ی دانش میشه شکاک بود، در زمینه‌ی اخلاق هم میشه همینطور بود.&lt;/p&gt;
&lt;p&gt;
حالا اگر روابط انسانی رو در نظر بگیریم، مثلا این سوال که آیا از من خوشت میاد یا نه، علاقه هیچ وقت تحقق پیدا نمی‌کنه مگر اینکه حدی از اعتماد رو نشون بدی، (رویکرد اینکه اول باور می‌کنم و سعی می‌کنم با دیدن شواهد بعدی گول نخورم در مقابل رویکرد اینکه اول مدرک بیاد تا باور کنم) اگر منتظر مدارک بمونی عمل نخواهی کرد و علاقه‌ای هم شکل نخواهد گرفت. بنای اکثر گروه‌های اجتماعی هم همین شکلیه. مثلا اگر یک گروه باور داشته باشن که انقلاب میشه میشه و اگر فکر کنن که با بیان انقلاب قطعا سرکوب میشن و صدمه می‌بینن سمت این کار نمیرن.
بنا براین مواردی وجود دارند که «یک حقیقت نمیتونه واقعیت پیدا کنه مگر اینکه از پیش باوری به تحققش وجود داشته باشه» در این حالات «باور به یک حقیقت اون حقیقت رو محقق می‌کنه»
بنابراین برای حقایقی که وابسته به کنش‌های شخصی ماست، ایمان مبتنی بر خواستن، کاملا مجاز و احتمالا بخش جدانشدنی‌ای از زندگیه.
قاعده‌ی فکر کردنی که مرا از باور به برخی حقایقی که ممکن است درست باشند باز بدارد، قاعده‌ی بدی است.
ما حق داریم که با ریسک خودمان، به فرضیاتی که برای ما به‌اندازه‌ی کافی «زنده» و جذاب هستند تا اراده‌ی ما را وسوسه‌کنند، باور داشته باشیم.
اگر ما مطلق‌گرا بودیم(مدعی بودیم که میدانیم و زمانی که قطعا حقیقت را پیدا کرده‌ایم متوجه می‌شویم)، مشکلی نبود که صبر کنیم تا مدارک کافی پیدا شود ولی از آنجایی که مدرک‌گرا هستیم، اگر تعلل کنیم، همانقدری از دست می‌دهیم که اگر باور نکنیم.&lt;/p&gt;
&lt;blockquote style="direction:ltr !important; text-align: left !important;"&gt;
&lt;p&gt;What do you think of yourself? What do you think of the world?… These are questions with which all must deal as it seems good to them. They are riddles of the Sphinx, and in some way or other we must deal with them…. In all important transactions of life we have to take a leap in the dark…. If we decide to leave the riddles unanswered, that is a choice; if we waver in our answer, that, too, is a choice: but whatever choice we make, we make it at our peril. If a man chooses to turn his back altogether on God and the future, no one can prevent him; no one can show beyond reasonable doubt that he is mistaken. If a man thinks otherwise and acts as he thinks, I do not see that any one can prove that he is mistaken. Each must act as he thinks best; and if he is wrong, so much the worse for him. We stand on a mountain pass in the midst of whirling snow and blinding mist, through which we get glimpses now and then of paths which may be deceptive. If we stand still we shall be frozen to death. If we take the wrong road we shall be dashed to pieces. We do not certainly know whether there is any right one. What must we do? &amp;#39;Be strong and of a good courage.&amp;#39; Act for the best, hope for the best, and take what comes…. If death ends all, we cannot meet death better.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-2" class="outline-2"&gt;
&lt;h2 id="headline-2"&gt;
آیا زندگی ارزش زیستن داره؟
&lt;/h2&gt;
&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;
&lt;p&gt;بعضیا دیدگاهشون اونقدر خوش‌بینانه است که زندگیشون جز شادی چیزی نداره، اگر زندگی اینطور باشه سوال اینکه آیا زندگی ارزش زیستن داره بی‌‌معنیه چون خود زندگی به اون اثبات ارزش زیستن. مثلا شعر والت ویتمن اینطوریه سبک دیدگاهش.
حتی اگر چنین دیدگاهی داریم خوبه که زندگی افراد پرغم رو تصور کنیم چون ساخت ما با اون‌ها یکسانه.&lt;/p&gt;
&lt;p&gt;
حالا بیاید انسانی رو تصور کنیم که انقدر بداقبال بوده و پر رنج که جز فکر اینکه هر وقت خواست میتونه زندگی رو پایان بده چیزی تسکینش نمیده، چه چیزی میشه به این شخص گفت تا دوباره بار زندگی رو به دوش بکشه؟
از دید اشخاص دیندار معتقد به قوانین آسونه: باید بگین خدا خودکشی رو منع کرده.
از دید اشخاص دیگه چی؟‌ ویلیام جیمز ادعا می‌کنه که لازمه که باور داشته باشیم (بدون هیچ مدرک و شاهدی) که این اعمال ما در دنیا، اثراتی تا ابد ماندگار دارن و به نتایجی ابدی ختم می‌شن، در این حالت می‌شه در بدترین شرایط هم زیست و خوشحال بود، چون مادامی که هدف نیک بودن، نیکی کردن و زیستن اخلاقی در این دنیا تأمین بشه، زندگی ارزشمند خواهد بود.&lt;/p&gt;
&lt;blockquote style="direction:ltr !important; text-align: left !important;"&gt;
&lt;p&gt;Not a victory is gained, not a deed of faithfulness or courage is done, except upon a maybe; not a service, not a sally of generosity, not a scientific exploration or experiment or text-book, that may not be a mistake. It is only by risking our persons from one hour to another that we live at all. And often enough our faith beforehand in an uncertified result is the only thing that makes the result come true.
Suppose, for example, that I am climbing in the Alps, and have had the ill-luck to work myself into a position from which the only escape is by a terrible leap. Being without similar experience, I have no evidence of my ability to perform it successfully; but hope and confidence in myself make me sure I shall not miss my aim, and nerve my feet to execute what without those subjective emotions would perhaps have been impossible. But suppose that, on the contrary, the emotions of fear and mistrust preponderate; or suppose that, having just read the Ethics of Belief, I feel it would be sinful to act upon an assumption unverified by previous experience,—why, then I shall hesitate so long that at last, exhausted and trembling, and launching myself in a moment of despair, I miss my foothold and roll into the abyss. In this case (and it is one of an immense class) the part of wisdom clearly is to believe what one desires; for the belief is one of the indispensable preliminary conditions of the realization of its object. There are then cases where faith creates its own verification. Believe, and you shall be right, for you shall save yourself; doubt, and you shall again be right, for you shall perish. The only difference is that to believe is greatly to your advantage.&lt;/p&gt;
&lt;p&gt;
For here possibilities, not finished facts, are the realities with which we have actively to deal; and to quote my friend William Salter, of the Philadelphia Ethical Society, &amp;#34;as the essence of courage is to stake one&amp;#39;s life on a possibility, so the essence of faith is to believe that the possibility exists.&amp;#34;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote style="direction:ltr !important; text-align: left !important;"&gt;
&lt;p&gt;These, then, are my last words to you: Be not afraid of life. Believe that life is worth living, and your belief will help create the fact. The &amp;#39;scientific proof&amp;#39; that you are right may not be clear before the day of judgment (or some stage of being which that expression may serve to symbolize) is reached. But the faithful fighters of this hour, or the beings that then and there will represent them, may then turn to the faint-hearted, who here decline to go on, with words like those with which Henry IV. greeted the tardy Crillon after a great victory had been gained: &amp;#34;Hang yourself, brave Crillon! we fought at Arques, and you were not there.&amp;#34;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item><item><title>توصیه‌هایی درمورد انتخاب رشته</title><link>https://hossein.me/posts/fa/choosing-a-major/</link><pubDate>Thu, 04 Sep 2025 14:38:09 +0330</pubDate><guid>https://hossein.me/posts/fa/choosing-a-major/</guid><description>&lt;img src="https://hossein.me/images/jobvision-uni-comparison.jpg" alt="نمودار جاب‌ویژن درباره‌ی میزان رضایت از دانشگاه و سطح حقوق دانشجویان هر دانشگاه" title="/images/jobvision-uni-comparison.jpg"/&gt;
&lt;p&gt;
در باب انتخاب رشته:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;سایت جاب‌ویژن با همکاری گزینه دو &lt;a href="https://jobvision.ir/reports/education-field-selection"&gt;گزارشی&lt;/a&gt; گذاشته از رتبه‌های قبولی، رضایت از دانشگاه و درآمدها، حتما ببینید. مثلا عکس بالا از این گزارش اومده. کلی نمودار جالب قابل تأمل دیگه هم داره.&lt;/li&gt;
&lt;li&gt;سایت «مرکز آمار کار دولت آمریکا» گزارش جامعی داره. توش درمورد پیش‌بینی رشد ۱۰ ساله رشد یک شغل و درآمد میانه‌اش در آمریکا نوشته. مثلا درآمد، پیش‌بینی رشد و … شغلای مرتبط با کامپیوتر &lt;a href="https://www.bls.gov/ooh/Computer-and-Information-Technology/"&gt;اینجا&lt;/a&gt;ست. که در کل دید خوبی هم می‌ده، مثلا مشاغل مرتبط با وب درآمدشون کمتره نسبت به امنیت‌کارها. و پولدارترین‌ها توی آمریکا پزشکن، حتی از خلبان‌ها هم بیشتر در میارن :)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://t.me/Sharif_prm/15526"&gt;ویژه‌نامه شریف&lt;/a&gt; درمورد رشته‌های مختلف این دانشگاه&lt;/li&gt;
&lt;li&gt;یک سری &lt;a href="https://t.me/Qotbnama_Community/21"&gt;کانال تصادفی تلگرامی&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description></item><item><title>اعمال تحریم بر دانشگاه شریف توسط گیت‌هاب</title><link>https://hossein.me/posts/fa/github-sharif-sanctions/</link><pubDate>Thu, 04 Sep 2025 14:36:09 +0330</pubDate><guid>https://hossein.me/posts/fa/github-sharif-sanctions/</guid><description>&lt;img src="https://hossein.me/images/sharif-github-sanctions.jpg" alt="تصویری از محیط مرورگر فایرفاکس که در آن گیت‌هاب ایمیل منتهی به @sharif.edu را نمی‌پذیرد" title="/images/sharif-github-sanctions.jpg"/&gt;
&lt;p&gt;
خبر آنکه:
گیت‌هاب ایمیل شریف نمی‌پذیره و نمی‌شه دیگه باهاش حساب دانشجویی ساخت.&lt;/p&gt;
&lt;p&gt;
مدیر عامل گیت‌هاب اخیرا استعفا کرده و الان کنترل گیت‌هاب خیلی بیشتر از قبل دست مایکروسافته. اینه که اگر تا الان به فکر نبودید، بد نیست به جایگزین‌های گیت‌هاب فکر کنید. کلا مخربه که کد نرم‌افزار آزاد بیفته دست یک سکو که خودش آزاد نیست.&lt;/p&gt;
&lt;p&gt;
مثلا &lt;a href="https://codeberg.org"&gt;codeberg.org&lt;/a&gt; جای خوبیه یا &lt;a href="https://framagit.org"&gt;framagit.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
مهاجرت کنید 🚀&lt;/p&gt;</description></item><item><title>حادثهٔ گویآنیا</title><link>https://hossein.me/posts/fa/goiania-accident/</link><pubDate>Thu, 04 Sep 2025 14:33:09 +0330</pubDate><guid>https://hossein.me/posts/fa/goiania-accident/</guid><description>&lt;img src="https://imgs.xkcd.com/comics/cesium.png" alt="یک کمیک xkcd درمورد میگوهای آلوده به مواد رادیواکتیو" title="https://imgs.xkcd.com/comics/cesium.png"/&gt;
&lt;p&gt;
توی برزیل، سال ۱۹۸۴، یک درمانگاه پرتودرمانی منتقل می‌شه به یک مکان جدید. به خاطر دعوای حقوقی درمانگاه و مالک زمین، وسایل پزشکی، توی ساختمون قدیمی رها میشن به امان خدا.
مسئولین درمانگاه میدونستن باید وسایل رادیواکتیو رو خارج کنن، ولی به دستور دادگاه، پلیس نمیذاشته و یک نگهبان هم گذاشتن جلوی در که نه چیزی وارد شه و نه چیزی خارج.&lt;/p&gt;
&lt;p&gt;
خلاصه نزدیک‌های پاییز، نگهبان نرفت نگهبانی بده و موند خونه. دوتا دزد محترم هم رفتن از درمانگاه پرتودرمانی دزدی کردن. وسایل رو گذاشتن توی فرغون! و بردن خونه‌شون تا تیکه‌تیکه کنن و بفروشن.&lt;/p&gt;
&lt;p&gt;
بعد هم که وسایل رو تیکه تیکه کردن دیدن عه چه ماده‌های قشنگی، پودرای خوشگل که از خودشون نور آبی ساطع می‌کنن.
اینا رو هی مالیدن به خودشون و اینور اونور، که آدمای مختلفی مریض شدن. موقع اعلام شدن ماجرا، همه ترسیدن و دولت برزیل مجبور شد جمعا ۱۱۲,۰۰۰ نفر رو معاینه کنه، که ۲۴۹ نفرشون هم به مواد رادیواکتیو آلوده بودن.&lt;/p&gt;
&lt;p&gt;
نتیجه اخلاقی: برای انتخاب محل دزدی هم شیمی دبیرستان لازمه.&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://explainxkcd.com/3131/"&gt;توضیح تصویر&lt;/a&gt;: اخیرا یک سری میگوی یخ‌زده توی اندونزی هم آلوده به مواد رادیواکتیو شدن و FDA درخواست جمع‌آوری‌شون رو داده.&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://en.wikipedia.org/wiki/Goi%C3%A2nia_accident"&gt;منبع&lt;/a&gt;&lt;/p&gt;</description></item><item><title>آزمون دانش شما درمورد رایانامه</title><link>https://hossein.me/posts/fa/email-quiz/</link><pubDate>Thu, 04 Sep 2025 14:32:09 +0330</pubDate><guid>https://hossein.me/posts/fa/email-quiz/</guid><description>&lt;img src="https://hossein.me/images/email-wtf.jpg" alt="یک کمیک xkcd درمورد میگوهای آلوده به مواد رادیواکتیو" title="/images/email-wtf.jpg" style="width:35%;"/&gt;
&lt;p&gt;
اگر میخواید دانشتون رو درمورد RFCهای رایانامه (ایمیل) بسنجید بشتابید.&lt;/p&gt;
&lt;p&gt;
سایت &lt;a href="https://e-mail.wtf"&gt;e-mail.wtf&lt;/a&gt; یک بازیه که ازتون می‌خواد مشخص کنید چه آدرس ایمیلی معتبره، و چه آدرسی نه. آخرشم بهتون امتیاز میده.&lt;/p&gt;
&lt;p&gt;
دلم نمیاد مثال بزنم، پس برید و خودتون رو محک بزنید 😇&lt;/p&gt;
&lt;p&gt;
خودم ۱۱ از ۲۱ شدم، ‌شما چطور؟&lt;/p&gt;</description></item><item><title>How to Share a Secret: Summary of Shamir's Paper</title><link>https://hossein.me/posts/en/how-to-share-a-secret/</link><pubDate>Mon, 11 Aug 2025 13:15:47 +0330</pubDate><guid>https://hossein.me/posts/en/how-to-share-a-secret/</guid><description>&lt;p&gt;
In his 1979 paper, Adi Shamir explains an ingenious way to share a secret between &lt;code class="verbatim"&gt;n&lt;/code&gt; people, such that only if &lt;code class="verbatim"&gt;k&lt;/code&gt; of them cooperate will the secret be revealed. And that even if &lt;code class="verbatim"&gt;k-1&lt;/code&gt; people cooperated, nothing would be revealed.&lt;/p&gt;
&lt;p&gt;
How it works is simple.
For a polynomial of degree 1 (i.e, $f(x)=a_{1}x+a_{0}$), how many &lt;code class="verbatim"&gt;(x,y)&lt;/code&gt; points do you need to find $a_{1}$ and $a_{0}$? Two. If you had only one point, you could find a relationship between $a_{0}$ and $a_{1}$ but that would be all.
For a polynomial of degree 2 (i.e, $f(x)=a_{2}x^2+a_{1}x+a_{0}$), how many &lt;code class="verbatim"&gt;(x,y)&lt;/code&gt; points do you need to find $a_{2}, a_{1}$ and $a_{0}$? Three. If you had only two points, there would still be an infinite pairs of $a_{2}$, $a_{1}$ and $a_{0}$.&lt;/p&gt;
&lt;p&gt;
Knowing what we know about polynomials, suppose &lt;code class="verbatim"&gt;n&lt;/code&gt; people need to be able to be part of our trusted group, such that if &lt;code class="verbatim"&gt;k&lt;/code&gt; of them cooperated, they could work out the secret.&lt;/p&gt;
&lt;p&gt;
We set $a_{0}$ as our secret. We generate a polynomial of degree &lt;code class="verbatim"&gt;k-1&lt;/code&gt; so there are &lt;code class="verbatim"&gt;k&lt;/code&gt; coefficients and at least &lt;code class="verbatim"&gt;k&lt;/code&gt; points or cooperating members are needed. Except for $a_{0}$ which is our secret, we generate the coefficients ($a_{1}$ to $a_{n}$) randomly. Then we index our &lt;code class="verbatim"&gt;n&lt;/code&gt; members give them each the &lt;code class="verbatim"&gt;f(x)&lt;/code&gt; of their index, so member one gets &lt;code class="verbatim"&gt;f(1)&lt;/code&gt;, member two gets &lt;code class="verbatim"&gt;f(2)&lt;/code&gt; and so on up to member n who gets &lt;code class="verbatim"&gt;f(n)&lt;/code&gt;. Now if any &lt;code class="verbatim"&gt;k&lt;/code&gt; members cooperate, they&amp;#39;ll have the numbers to find out all the coefficients, and work out $a_{0}$. Easy as that. We will also use modulo arithmetic for our polynomial equations so every number is equally likely in it.&lt;/p&gt;</description></item><item><title>Tail Recursion</title><link>https://hossein.me/posts/en/tail-recursion/</link><pubDate>Sun, 10 Aug 2025 11:18:51 +0330</pubDate><guid>https://hossein.me/posts/en/tail-recursion/</guid><description>
&lt;p&gt;
As nice as recursion is, sometimes our stack may grow too large, causing our program to crash due to running out of stack space. However, some languages support tail call optimization. That is, if you write your function in a way that leaves no need to use the previous stack, the compiler will use the same stack for its job and you&amp;#39;ll never hit the stack overflow problem.&lt;/p&gt;
&lt;p&gt;
For example, here&amp;#39;s a Fibonacci implementation in C.&lt;/p&gt;
&lt;div class="src src-c"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// badfib.C
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt; &lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Non-tail recursive function for Fibonacci
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (n &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (n &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(n &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(n &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Enter a number: &amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;scanf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d&amp;#34;&lt;/span&gt;, &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;n);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Fibonacci of %d is %d&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;\n&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, n, &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(n));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;img src="https://hossein.me/images/fibonacci-stack.svg" alt="This figure shows how fibonacci&amp;#39;s 5th term is calculated." title="/images/fibonacci-stack.svg" style="height:100%;width:100%;color:red;"/&gt;
&lt;p&gt;
Using this code, calculating the 5th term (&lt;code class="verbatim"&gt;1,1,2,3,5&lt;/code&gt;) can be done like the picture above. You can see the stack frames grow too long. Each call of the function waits for the return of at least two other function calls, and neither of the first two branches can be calculated until we reach &lt;code class="verbatim"&gt;fibonacci(0)&lt;/code&gt; and &lt;code class="verbatim"&gt;fibonacci(1)&lt;/code&gt;. Since we need to keep track of what two numbers are being added together, we also can&amp;#39;t reduce the amount of data we keep.&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ gcc -O0 badfib.c -o badfib
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ ./badfib
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Enter a number: 500000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[1] 43221 segmentation fault (core dumped) ./badfib
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ gcc -O1 badfib.c -o badfib_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ ./badfib_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Enter a number: 500000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[1] 43283 segmentation fault (core dumped) ./badfib_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ gcc -O3 badfib.c -o badfib_super_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ ./badfib_super_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Enter a number: 500000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# takes too long :)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
As you can see, no matter the level of optimization, the code doesn&amp;#39;t finish in the way we want it to.&lt;/p&gt;
&lt;p&gt;
Now suppose we refactor our code like this:&lt;/p&gt;
&lt;div class="src src-c"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt; &lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Tail recursive function for Fibonacci
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci_tail&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; a, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (n &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; a;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (n &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; b;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci_tail&lt;/span&gt;(n &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, b, a &lt;span style="color:#f92672"&gt;+&lt;/span&gt; b);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fibonacci_tail&lt;/span&gt;(n, &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Enter a number: &amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;scanf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d&amp;#34;&lt;/span&gt;, &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;n);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Fibonacci&amp;#39;s %d term is %d&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;\n&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, n, &lt;span style="color:#a6e22e"&gt;fibonacci&lt;/span&gt;(n));
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Here&amp;#39;s how the functions are called:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib(5)&lt;/code&gt; : &lt;code class="verbatim"&gt;fib_tail(5, 0, 1)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib_tail(5,0,1)&lt;/code&gt; : &lt;code class="verbatim"&gt;fib_tail(4,1,1)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib_tail(4,1,1)&lt;/code&gt; : &lt;code class="verbatim"&gt;fib_tail(3,1,2)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib_tail(3,1,2)&lt;/code&gt; : &lt;code class="verbatim"&gt;fib_tail(2,2,3)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib_tail(2,2,3)&lt;/code&gt; : &lt;code class="verbatim"&gt;fib_tail(1,3,5)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class="verbatim"&gt;fib_tail(1,3,5)&lt;/code&gt; : &lt;code class="verbatim"&gt;5&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Or in a nice little picture:&lt;/p&gt;
&lt;img src="https://hossein.me/images/fibonacci-optimized-stack.svg" alt="This figure shows how fibonacci&amp;#39;s 5th term is calculated using the tail recursive optimized code." title="/images/fibonacci-optimized-stack.svg" style="width:35%;"/&gt;
&lt;p&gt;
You may have noticed that this time is no different. It is less messy, sure, but each function still needs to wait for the result of another function so that it can finally return the value and remove its stack. The nice thing about this function, though, is that it &lt;em&gt;can&lt;/em&gt; be optimized. At each turn we&amp;#39;re accumulating the values we need inside two variables, and even if we only keep track of the last function call, we will still have the correct result.&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Key idea:&lt;/strong&gt; You can refractor your recursive functions, such that the recursive function call is being done at the end of the function, and the ultimate result that you will return isn&amp;#39;t dependent on anything but the data in the very last function call. Then some languages like C will discard your stack at each new call and will just keep the last function call at each step. This will result in less memory usage and prevention of stack overflow. This is the essence of tail recursion optimization.&lt;/p&gt;
&lt;p&gt;
Let&amp;#39;s see if the optimization makes a difference:&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ ./fib_tail_unoptimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Enter a number: 500000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[1] 42515 segmentation fault (core dumped) ./fib_tail_unoptimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ gcc -O1 fib_tail.c -o fib_tail_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;❯ ./fib_tail_optimized
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Enter a number: 500000
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Fibonacci&amp;#39;s 500000 term is -1975568635&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It did! The answer is incorrect because &lt;code class="verbatim"&gt;int&lt;/code&gt; can&amp;#39;t such a large number, but we didn&amp;#39;t run into a stack overflow segfault either!&lt;/p&gt;
&lt;p&gt;
Not all programming languages support tail recursion optimization though. And you need to know that discarding the stack will make it harder to debug your code because the stack won&amp;#39;t be in its complete form.&lt;/p&gt;
&lt;p&gt;
The moral of the story is that whenever you feel like you&amp;#39;re at risk of stack overflow, go ahead and rewrite your code using an accumulator so that it can be tail optimized, or just use a loop. In the case of relying on an accumulator the compiler should support TCO optimizaiton. If it doesn&amp;#39;t no worries. You could use GOTO (it doesn&amp;#39;t call new functions then, and it&amp;#39;ll reuse the same variables so it&amp;#39;s nice) to use the same stack frame, or write a loop.&lt;/p&gt;
&lt;p&gt;
For example, here&amp;#39;s the Fibonacci function written using a loop, nice and easy:&lt;/p&gt;
&lt;div class="src src-c"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;long&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;fib&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; term){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(term &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(term &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#f92672"&gt;||&lt;/span&gt; term &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;long&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; a&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, b&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, c&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;i&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;term&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;2&lt;/span&gt;;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; c &lt;span style="color:#f92672"&gt;=&lt;/span&gt; a&lt;span style="color:#f92672"&gt;+&lt;/span&gt;b;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; a &lt;span style="color:#f92672"&gt;=&lt;/span&gt; b;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; b &lt;span style="color:#f92672"&gt;=&lt;/span&gt; c;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d: %ld&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;\n&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;, i&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt;, c);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; c;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fib&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;11&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-1" class="outline-3"&gt;
&lt;h3 id="headline-1"&gt;
Further Reading
&lt;/h3&gt;
&lt;div id="outline-text-headline-1" class="outline-text-3"&gt;
&lt;ul&gt;
&lt;li&gt;Tail Call Optimization in &lt;a href="https://inventwithpython.com/recursion/chapter8.html"&gt;The Recursive Book of Recursion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item><item><title>How to share Mullvad VPN from Android on all your network?</title><link>https://hossein.me/posts/en/mullvad-termux-android-vpn-share/</link><pubDate>Sat, 02 Aug 2025 20:53:23 +0330</pubDate><guid>https://hossein.me/posts/en/mullvad-termux-android-vpn-share/</guid><description>&lt;p&gt;Suppose you want to share your &lt;a href="https://mullvad.net"&gt;Mullvad VPN&lt;/a&gt; over the network, you&amp;rsquo;re connected to it on your Android phone but not on any other device. How cool would it be if you could share it with other devices? Well you can do that.&lt;/p&gt;
&lt;p&gt;Once you connect to Mullvad VPN on your device, you&amp;rsquo;ll have access to a socks5 proxy on &lt;code&gt;socks5://10.64.0.1:1080&lt;/code&gt;, however this IP is only accessible from your Android phone. To share it with your other devices, first install &lt;a href="https://termux.dev/"&gt;Termux&lt;/a&gt;, then download the correct &lt;a href="https://gost.run/en/"&gt;gost&lt;/a&gt; binary according to your phone&amp;rsquo;s CPU architecture. Then you can instruct gost to forward all the packets it gets on port 8090 for example, to the socks5 provided by Mullvad. Done!&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;wget https://github.com/go-gost/gost/releases/download/v3.1.0/gost_3.1.0_linux_arm64.tar.gz &lt;span style="color:#75715e"&gt;# change the version and architecture accordingly&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;tar xfv *.tar.gz
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;./gost -L :8090 -F socks5://10.64.0.1:1080 &lt;span style="color:#75715e"&gt;# If you&amp;#39;re in a hostile environment, use -L socks5://user:password@:8090 instead to have a socks5 proxy with authentication.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now if inside your Mullvad app settings, &amp;ldquo;Local network sharing&amp;rdquo; is turned on, then you can easily connect to your phone&amp;rsquo;s IP from other devices and use the socks5/http/https proxy provided on its port 8090.
You might think that since &lt;a href="https://mullvad.net/en/help/socks5-proxy"&gt;all servers in Mullvad offer socks5 proxy&lt;/a&gt;, you can access them all, but sadly this is not possbile because folks at Mullvad have decided that as soon as you turn on local network sharing, your connection to other servers should be lost.&lt;/p&gt;
&lt;p&gt;You can use this socks5 proxy using &lt;a href="https://addons.mozilla.org/en-US/android/addon/foxyproxy-standard/"&gt;FoxyProxy&lt;/a&gt; on Firefox on both Android (yes! you can install extensions on Firefox Android) and GNU\Linux/Windows/MacOS.&lt;/p&gt;</description></item><item><title>You Can Resolve Domains via curl Using DoH</title><link>https://hossein.me/posts/en/doh-and-odoh-using-curl/</link><pubDate>Tue, 29 Jul 2025 18:37:04 +0330</pubDate><guid>https://hossein.me/posts/en/doh-and-odoh-using-curl/</guid><description>&lt;p&gt;
Did you know you can use curl to get DNS information? Here&amp;#39;s how:&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ curl -X GET &amp;#34;https://cloudflare-dns.com/dns-query?name=example.com&amp;amp;type=A&amp;#34; -H &amp;#34;Accept: application/dns-json&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&amp;#34;Status&amp;#34;:0,&amp;#34;TC&amp;#34;:false,&amp;#34;RD&amp;#34;:true,&amp;#34;RA&amp;#34;:true,&amp;#34;AD&amp;#34;:true,&amp;#34;CD&amp;#34;:false,&amp;#34;Question&amp;#34;:[{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1}],&amp;#34;Answer&amp;#34;:[{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;23.192.228.84&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;23.215.0.136&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;23.192.228.80&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;23.215.0.138&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;96.7.128.175&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:276,&amp;#34;data&amp;#34;:&amp;#34;96.7.128.198&amp;#34;}]}%&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
It works on Cloudflare&amp;#39;s &lt;a href="https://research.cloudflare.com/projects/network-privacy/odns/"&gt;ODOH&lt;/a&gt; server too!&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ curl -X GET &amp;#34;https://odoh.cloudflare-dns.com/dns-query?name=example.com&amp;amp;type=A&amp;#34; -H &amp;#34;Accept: application/dns-json&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&amp;#34;Status&amp;#34;:0,&amp;#34;TC&amp;#34;:false,&amp;#34;RD&amp;#34;:true,&amp;#34;RA&amp;#34;:true,&amp;#34;AD&amp;#34;:false,&amp;#34;CD&amp;#34;:false,&amp;#34;Question&amp;#34;:[{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1}],&amp;#34;Answer&amp;#34;:[{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;23.192.228.84&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;23.215.0.138&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;23.215.0.136&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;96.7.128.198&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;96.7.128.175&amp;#34;},{&amp;#34;name&amp;#34;:&amp;#34;example.com&amp;#34;,&amp;#34;type&amp;#34;:1,&amp;#34;TTL&amp;#34;:35,&amp;#34;data&amp;#34;:&amp;#34;23.192.228.80&amp;#34;}]}%&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
If you can&amp;#39;t bootstrap a DoH server, you can always use &lt;a href="https://9.9.9.9/dns-query"&gt;https://9.9.9.9/dns-query&lt;/a&gt; instead (though not in this format) or &lt;a href="https://1.1.1.1/dns-query."&gt;https://1.1.1.1/dns-query.&lt;/a&gt; If you already know the IP of your target, you can use curl&amp;#39;s `–resolve` option too. curl has a `–doh-url` as well which can be used if you want curl to use DoH itself.&lt;/p&gt;
&lt;p&gt;
Note that although this method works for Cloudlare DoH servers, it is not part of any RFC so you can&amp;#39;t really rely on them and should refer to the &lt;a href="https://datatracker.ietf.org/doc/html/rfc8484"&gt;original RFC&lt;/a&gt; instead if you want to send your request to other servers.&lt;/p&gt;</description></item><item><title>So You Want to Learn Quicksort: Step-by-Step Guide to Basic, Lomuto &amp; Hoare Partitioning.</title><link>https://hossein.me/posts/en/so-you-want-to-learn-quicksort/</link><pubDate>Tue, 29 Jul 2025 11:54:15 +0330</pubDate><guid>https://hossein.me/posts/en/so-you-want-to-learn-quicksort/</guid><description>&lt;p&gt;I don&amp;rsquo;t have a Bachelor&amp;rsquo;s degree in computer science so I haven&amp;rsquo;t had any formal algorithm or data structure training. However, I am trying to remedy that by reading books and solving algorithmic questions on online platforms. One question in Hackerrank needed a sort implementation, which I couldn&amp;rsquo;t do without the help of AI, so I decided to learn about sort algorithms. I searched and found that quicksort has widespread usage, so I decided to learn it. However it was just too hard for me to grasp what was going on, so like a good programmer I decided to divide the problem into smaller parts and solve those :P.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The quicksort algorithm asks: what if we had an algorithm that takes a number (called the pivot) and divides our array into two parts, the ones smaller than the pivot and the ones larger than it? If an algorithm does this, we now have two arrays of numbers that we know don&amp;rsquo;t need to be compared. We could do the very same to those two arrays, then we keep doing this with the subarrays that are getting smaller and smaller in size, et voila! The resulting array is sorted. This is the essence of the quicksort algorithm.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The algorithm that partitions our arrays into subarrays that are all bigger or smaller than a certain number is called a partitioning algorithm. Most educational materials on quicksort conflate Lomuto&amp;rsquo;s and Hoare&amp;rsquo;s partitioning algorithms with the quicksort algorithm itself, so we could easily lose sight of the big picture. I have written a C quicksort program that is inefficient, yet easy to understand.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s learn about the silliest partitioning algorithm possible; then we can easily learn quicksort, even when it uses the right partitioning algorithms.&lt;/p&gt;
&lt;h2 id="basic-partitioning"&gt;Basic Partitioning&lt;/h2&gt;
&lt;p&gt;In the following code, we&amp;rsquo;ll partition an array of numbers into those bigger than the pivot and those smaller than the pivot in the silliest way: we go through all the numbers in the array one by one and put each number in one of the three temporary arrays we make — one temporary array for numbers bigger than the pivot, one for those smaller than the pivot, and one for those equal to it.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-C" data-lang="C"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#define MAX_INTS 100
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; place){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;i&lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt;place;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d,&amp;#34;&lt;/span&gt;,arr[i]);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;puts&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Partitions everything around the last array element (_high_ is the pivot) for elements **low** to high (not zero to high), returns the last array&amp;#39;s (pivot&amp;#39;s) new placement in the partitioned array.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;basicPartition&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;//nE/L/H == number of equals/lows/highs
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;//idx is defined at a function scope here and used later to place the elements in their correct position
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; idx&lt;span style="color:#f92672"&gt;=&lt;/span&gt;low,nE&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;,nL&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;,nH&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; pivot&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[high];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; Ls[MAX_INTS]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{},Hs[MAX_INTS]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{},Ps[MAX_INTS]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;{};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Element enumeration
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Here we place the numbers into temporary high, low, or equal arrays. 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;low;i&lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt;high;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(arr[i]&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt;pivot){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Hs[nH]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; nH&lt;span style="color:#f92672"&gt;++&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (arr[i]&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;pivot){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Ls[nL]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; nL&lt;span style="color:#f92672"&gt;++&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (arr[i] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; pivot){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Ps[nE]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; nE&lt;span style="color:#f92672"&gt;++&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Place from temp to arr
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;; i&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;nL;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;,idx&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[idx]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;Ls[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;; i&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;nE;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;,idx&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[idx]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;Ps[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;; i&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;nH;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;,idx&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[idx]&lt;span style="color:#f92672"&gt;=&lt;/span&gt;Hs[i];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// return the new position of the pivot 
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; low&lt;span style="color:#f92672"&gt;+&lt;/span&gt;nL&lt;span style="color:#f92672"&gt;+&lt;/span&gt;nE&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(low&lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt;high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; piv&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;basicPartition&lt;/span&gt;(arr, low, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, low, piv&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, piv&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;899&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;789&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;95&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;4&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;56&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;11&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;18&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;180&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;43&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(arr)&lt;span style="color:#f92672"&gt;/&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;/* printArray(arr,n-1); */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;/* int res = basicPartition(arr, 0, n-1); */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(arr,n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; EXIT_SUCCESS;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If I were to draw a picture it would look like this:
&lt;img src="https://hossein.me/images/quicksort-basic_partitioning.svg" alt="img"&gt;&lt;/p&gt;
&lt;p&gt;The problem with this implementation is that it uses O(n) in its partitioning. How can we improve that? Maybe instead of keeping everything in a temporary array of equal size, we could do in-place replacement? That&amp;rsquo;s what the Lomuto&amp;rsquo;s partitioning algorithm does. Let&amp;rsquo;s learn that.&lt;/p&gt;
&lt;h2 id="lomutos-partitioning-algorithm"&gt;Lomuto&amp;rsquo;s Partitioning Algorithm&lt;/h2&gt;
&lt;p&gt;So far we made a simple partitioning algorithm, but it left much to be desired in its memory usage. If we want to use less memory, how about we swap the elements instead of keeping them in temporary arrays? That&amp;rsquo;s what Lomuto&amp;rsquo;s algorithm does.
Imagine two little soldiers that we hire for sorting. The first one is named &lt;em&gt;i&lt;/em&gt;, and the second one is named &lt;em&gt;j&lt;/em&gt;.
Our little guy &lt;em&gt;i&lt;/em&gt;&amp;rsquo;s job is to protect the weak. He creates a firm boundary and all the elements smaller than the pivot line up before him.
Our adventurous fella &lt;em&gt;j&lt;/em&gt;&amp;rsquo;s job is to foray into the unknown, find those weaker than or equal to the pivot, and tell them they can find refuge if they line up before &lt;em&gt;i&lt;/em&gt;.
So here is how the algorithm works:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the last element of the array is chosen as our pivot&lt;/li&gt;
&lt;li&gt;&lt;em&gt;i&lt;/em&gt; stands at &lt;code&gt;low-1&lt;/code&gt;, behind where the array even begins.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;j&lt;/em&gt; stands at &lt;code&gt;low&lt;/code&gt;, where the array begins.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;j&lt;/em&gt; marches forward, on its way forward, it finds an element that is lower than or equal to the pivot, once it does, it stops to let &lt;em&gt;i&lt;/em&gt; know.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;j&lt;/em&gt; and &lt;em&gt;i&lt;/em&gt; cooperate, i moves one step forward to mark the new boundary, the element at the new boundary is swapped with the weak/equal element.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;j&lt;/em&gt; keeps doing this and marching on until it reaches &lt;code&gt;arr[high]&lt;/code&gt; which is our pivot.&lt;/li&gt;
&lt;li&gt;When &lt;em&gt;j&lt;/em&gt; is at one step behind &lt;code&gt;arr[high]&lt;/code&gt;, we already know that &lt;code&gt;arr[high]&lt;/code&gt; is going to be equal to the pivot since the last element is the pivot itself, so we swap &lt;code&gt;arr[i+1]&lt;/code&gt; with &lt;code&gt;arr[high]&lt;/code&gt; manually without doing a condition check.&lt;/li&gt;
&lt;li&gt;At the end of the process, we return &lt;em&gt;i&lt;/em&gt;+1, which is where our boundary (i.e. our pivot&amp;rsquo;s position in array) is after this one final swap.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Intuition: In Lomuto&amp;rsquo;s algorithm we use &lt;em&gt;i&lt;/em&gt; as a boundary, and everything before &lt;em&gt;i&lt;/em&gt; is smaller than or equal to the pivot. So at each step if &lt;code&gt;arr[j]&lt;/code&gt; is smaller than the pivot we increase our boundary and move the smaller numbers inside our boundary. Now, since everything before our pivot is smaller than or equal to it and everything after that is bigger than it, our pivot is in fact in its sorted position by the definition of sort.&lt;/p&gt;
&lt;p&gt;How does this relate to quicksort? Using Lomuto&amp;rsquo;s algorithm, you have an algorithm that efficiently partitions an array, such that one number of your array (the pivot) is already in its sorted position, and you have two separate arrays before and after the pivot, in a way that they don&amp;rsquo;t need to be compared with each other since we already know some of them are always bigger than the others. Isn&amp;rsquo;t that great? If we now ignore the pivot which is now in its sorted position and keep partitioning for arrays that come before and after it, we&amp;rsquo;ll have a fully sorted array.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s my implementation of quicksort using Lomuto&amp;rsquo;s partitioning algorithm.
Try not to repeat the mistakes I made during writing this code:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I used &lt;code&gt;i=-1&lt;/code&gt; instead of &lt;code&gt;i=low-1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I swapped &lt;code&gt;arr[high]&lt;/code&gt; and &lt;code&gt;arr[i]&lt;/code&gt; instead of &lt;code&gt;arr[high]&lt;/code&gt; and &lt;code&gt;arr[i+1]&lt;/code&gt; at the last step. The boundary is at &lt;em&gt;i&lt;/em&gt;+1, since we&amp;rsquo;re not doing that &lt;code&gt;i++&lt;/code&gt; which is inside our loop. Everything up to &lt;code&gt;i+1&lt;/code&gt; is lower than or equal to the pivot which is always at &lt;code&gt;arr[i+1]&lt;/code&gt; at the end of the algorithm.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-C" data-lang="C"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#define MAX_INTS 100
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; place){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;i&lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt;place;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d,&amp;#34;&lt;/span&gt;,arr[i]);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;puts&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;arrSwapInt&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; a, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; b){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; temp;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; temp &lt;span style="color:#f92672"&gt;=&lt;/span&gt; arr[b];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[b] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; arr[a];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[a] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; temp;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;lomutoPartition&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;low&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; piv&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[high];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; j&lt;span style="color:#f92672"&gt;=&lt;/span&gt;low;j&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;high;j&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(arr[j]&lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt;piv){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;arrSwapInt&lt;/span&gt;(arr,i,j);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;arrSwapInt&lt;/span&gt;(arr,high,i&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; i&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(low&lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt;high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; piv&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;lomutoPartition&lt;/span&gt;(arr, low, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, low, piv&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, piv&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;899&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;789&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;95&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;4&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;56&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;11&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;18&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;180&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;43&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(arr)&lt;span style="color:#f92672"&gt;/&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(arr,n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; EXIT_SUCCESS;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="hoares-partitioning-algorithm"&gt;Hoare&amp;rsquo;s Partitioning Algorithm&lt;/h2&gt;
&lt;p&gt;Now let&amp;rsquo;s learn Hoare&amp;rsquo;s partitioning algorithm.&lt;/p&gt;
&lt;p&gt;In Lomuto&amp;rsquo;s our soldiers &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; had different jobs, now they have the same job description. The only difference between &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; is that &lt;em&gt;i&lt;/em&gt; starts one step behind the beginning of the array and &lt;em&gt;j&lt;/em&gt; starts from one step after the end of the array. They take rounds to march on and stop where they find elements that shouldn&amp;rsquo;t be where they are. That is, first &lt;em&gt;i&lt;/em&gt; marches towards the end of the array and stops if it sees any element that is bigger than the pivot, and then &lt;em&gt;j&lt;/em&gt; marches towards the beginning of the array and stops if it sees any element that is smaller than the pivot. Once they&amp;rsquo;re both stopped, we can very astutely move two elements to their correct place with one swap and that&amp;rsquo;s what we do. Our soldiers &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; both keep moving until they face each other (&lt;code&gt;i==j&lt;/code&gt;) or get past one another (&lt;code&gt;i&amp;gt;j&lt;/code&gt;). That is when they know they&amp;rsquo;re done.&lt;/p&gt;
&lt;p&gt;In short, in Hoare&amp;rsquo;s algorithm, you move from both sides to the other, stop at the wrong elements from each side, and swap them.
Note that just like the two algorithms above, at the end of the Hoare&amp;rsquo;s algorithm it is guaranteed that all items left of the returned &lt;em&gt;j&lt;/em&gt; are smaller than the pivot, and all items right of the retuned &lt;em&gt;j&lt;/em&gt; are bigger than the pivot. But unlike those two, the pivot itself doesn&amp;rsquo;t end up at the returned &lt;em&gt;j&lt;/em&gt; and it won&amp;rsquo;t be at its sorted position. That is, while Hoare&amp;rsquo;s partitioning algorithm returns the boundary of our partitioned arrays (&lt;em&gt;j&lt;/em&gt;), our pivot is not at &lt;em&gt;j&lt;/em&gt; (even though we can move it with one extra swap since we already know the boundary, we don&amp;rsquo;t do this since at the end of the recursion each element will be in its sorted position and this is unnecessary). So this time in the quicksort algorithm, we don&amp;rsquo;t do quicksort on &lt;code&gt;(low,piv-1)&lt;/code&gt; and &lt;code&gt;(piv+1,high)&lt;/code&gt; which ignores the element at piv, instead we do &lt;code&gt;(low,piv)&lt;/code&gt; &lt;code&gt;(piv+1,high)&lt;/code&gt; which includes the element at piv.&lt;/p&gt;
&lt;p&gt;Try not to repeat the mistakes I made while writing this code:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I forgot to put the = in the loop break condition, so my code would get stuck in a loop.&lt;/li&gt;
&lt;li&gt;I forgot to make the pivot equal to &lt;code&gt;arr[low]&lt;/code&gt; and made it equal to &lt;code&gt;arr[0]&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-C" data-lang="C"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#include&lt;/span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span style="color:#75715e"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;#define MAX_INTS 100
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; place){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;i&lt;span style="color:#f92672"&gt;&amp;lt;=&lt;/span&gt;place;i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printf&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;%d,&amp;#34;&lt;/span&gt;,arr[i]);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;puts&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;arrSwapInt&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; a, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; b){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; temp;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; temp &lt;span style="color:#f92672"&gt;=&lt;/span&gt; arr[b];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[b] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; arr[a];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; arr[a] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; temp;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Returns piv_index instead of where the pivot is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// pivot is not in its sorted position
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;hoarePartition&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// low, not zero!
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; piv&lt;span style="color:#f92672"&gt;=&lt;/span&gt;arr[low];
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; i&lt;span style="color:#f92672"&gt;=&lt;/span&gt;low&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;,j&lt;span style="color:#f92672"&gt;=&lt;/span&gt;high&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;while&lt;/span&gt;(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; i&lt;span style="color:#f92672"&gt;++&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;while&lt;/span&gt; (arr[i]&lt;span style="color:#f92672"&gt;&amp;lt;&lt;/span&gt;piv);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;do&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; j&lt;span style="color:#f92672"&gt;--&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; } &lt;span style="color:#66d9ef"&gt;while&lt;/span&gt; (arr[j]&lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt;piv);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// if you don&amp;#39;t put the equal, for 11,4,18,13 it will get stuck in a loop since the j that is returned will be 0 instead of 1.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// since the pivot index is the same as the one that was called, it will get stuck in a loop, unless you break when both i and j are equal
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// breaking on j==i makes sense, since if i==j then we are already done comparing boundaries and at the correct pivot index.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(i&lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt;j){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;arrSwapInt&lt;/span&gt;(arr, i, j);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; j;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Counts from zero
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[], &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; low, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt;(low&lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt;high){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; piv_index&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;hoarePartition&lt;/span&gt;(arr, low, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// Different from Lomuto&amp;#39;s and basic partitioning
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, low, piv_index);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, piv_index&lt;span style="color:#f92672"&gt;+&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;, high);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;main&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;void&lt;/span&gt;){
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; arr[] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;899&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;789&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;1000&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;95&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;4&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;56&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;11&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;18&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;12&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;180&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;43&lt;/span&gt;,&lt;span style="color:#ae81ff"&gt;93&lt;/span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;/* int arr[] = {11,4,18,13}; */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; n &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(arr)&lt;span style="color:#f92672"&gt;/&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;sizeof&lt;/span&gt;(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;/* int res = hoarePartition(arr, 0, n-1); */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;quickSort&lt;/span&gt;(arr, &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;, n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;puts&lt;/span&gt;(&lt;span style="color:#e6db74"&gt;&amp;#34;Sorted array:&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;printArray&lt;/span&gt;(arr,n&lt;span style="color:#f92672"&gt;-&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; EXIT_SUCCESS;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id="extra-tips"&gt;Extra Tips&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pivots:&lt;/strong&gt; In Lomuto&amp;rsquo;s algorithm, the last element (&lt;code&gt;arr[high]&lt;/code&gt;) must be our pivot, because during the quicksort call on &lt;code&gt;(low,piv-1)&lt;/code&gt; and &lt;code&gt;(piv+1,high)&lt;/code&gt; we assume that the pivot is in its sorted position (that is, at the end of the boundary, where we have done our last swap), so we must choose the last element as our pivot. But if we need another array element to be our pivot, we can always swap it with the last element before we&amp;rsquo;re calling the algorithms and make the chosen element the last element. But in Hoare&amp;rsquo;s all we need is an arbitrary number that, ideally, is larger that half of the numbers and smaller than the other half, but we can choose any number really.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Best case and worse case:&lt;/strong&gt; Running the quicksort algorithm on an already sorted array will have a time complexity of O(n^2). So we usually choose a random element as our pivot (and if it is Lomuto&amp;rsquo;s, we need to swap it and make it the last element).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stability of the sort algorithms:&lt;/strong&gt; The basic partitioning algorithm is stable. But neither Lomuto&amp;rsquo;s nor Hoare&amp;rsquo;s algorithms are stable, meaning that for equal items (to which we have attached extra data) the order could be changed. That is &lt;code&gt;{(1,red),(2,blue),(1,blue)}&lt;/code&gt; could become &lt;code&gt;{(1,blue), (1,red), (2,blue)}&lt;/code&gt;. This would be really bad if we were sorting data in a database with timestamps for example.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="conclusion"&gt;Conclusion&lt;/h1&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Partition Method&lt;/th&gt;
 &lt;th&gt;Pivot Choice&lt;/th&gt;
 &lt;th&gt;Extra Memory&lt;/th&gt;
 &lt;th&gt;Pivot Position After Partition&lt;/th&gt;
 &lt;th&gt;Stability&lt;/th&gt;
 &lt;th&gt;Average Time&lt;/th&gt;
 &lt;th&gt;Worst-Case Time&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;Basic (temp arrays)&lt;/td&gt;
 &lt;td&gt;Doesn&amp;rsquo;t matter&lt;/td&gt;
 &lt;td&gt;O(n)&lt;/td&gt;
 &lt;td&gt;Pivot(s) end up in the middle of the concatenated lows-equals-highs block&lt;/td&gt;
 &lt;td&gt;Yes&lt;/td&gt;
 &lt;td&gt;O(n log n)&lt;/td&gt;
 &lt;td&gt;O(n²)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Lomuto&lt;/td&gt;
 &lt;td&gt;Must be the last element&lt;/td&gt;
 &lt;td&gt;O(1)&lt;/td&gt;
 &lt;td&gt;Pivot placed at its final sorted index (i+1)&lt;/td&gt;
 &lt;td&gt;No&lt;/td&gt;
 &lt;td&gt;O(n log n)&lt;/td&gt;
 &lt;td&gt;O(n²)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;Hoare&lt;/td&gt;
 &lt;td&gt;Doesn&amp;rsquo;t matter but usually the first element&lt;/td&gt;
 &lt;td&gt;O(1)&lt;/td&gt;
 &lt;td&gt;Pivot not guaranteed in final position; partitions around boundary j&lt;/td&gt;
 &lt;td&gt;No&lt;/td&gt;
 &lt;td&gt;O(n log n)&lt;/td&gt;
 &lt;td&gt;O(n²)&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Did you see what we did for sorting? There is much to be learned from what we did here. We used &lt;strong&gt;Divide and Conquer&lt;/strong&gt; to solve our problem. At each section we only had an algorithm that could do a single sort (a partitioning algorithm can put at most one element in its sorted position) but we used this algorithm - which can&amp;rsquo;t be seen as a sorting algorithm - 1. multiple times and 2. on smaller and smaller subsets of our problem, so at the end sorting happened efficiently. Any time you&amp;rsquo;re thinking about a problem that can&amp;rsquo;t be solved efficiently, maybe you could think about single items and then use D&amp;amp;C to solve the problem.&lt;/p&gt;
&lt;h1 id="todo"&gt;TODO&lt;/h1&gt;
&lt;p&gt;I asked AI what I should learn next and here are its opinions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; You never mention the importance of pivot choice on expected running time or practical performance (cache behavior, branch prediction, etc.). Real-world quicksort typically uses “median-of-three” or introspective quicksort (Introsort) that switches to heapsort if recursion gets too deep.&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Neither Lomuto’s nor Hoare’s implementations do tail recursion elimination. In the worst case (unbalanced splits), your recursion depth is O(n) and you risk a stack overflow. Best practice is to recurse on the smaller subarray first, then iterate on the larger one.&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Discuss three-way partitioning for many-duplicate inputs.
And I think I should:&lt;/li&gt;
&lt;li&gt;&lt;input disabled="" type="checkbox"&gt; Add pictures of our valiant soldiers &lt;em&gt;i&lt;/em&gt; and &lt;em&gt;j&lt;/em&gt; performing their duties in Lomuoto&amp;rsquo;s and Hoare&amp;rsquo;s algorithms.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Dining Cryptographers</title><link>https://hossein.me/posts/en/dining-cryptographers/</link><pubDate>Sat, 26 Jul 2025 01:02:24 +0330</pubDate><guid>https://hossein.me/posts/en/dining-cryptographers/</guid><description>&lt;p&gt;
Today I learned about the &lt;a href="https://en.wikipedia.org/wiki/Dining_cryptographers_problem"&gt;Dining cryptographers problem&lt;/a&gt;. It is such a great usage of XOR!&lt;/p&gt;
&lt;p&gt;
Suppose we have three cryptographers-a,b and c- seated in a circle. They all flip a coin and see the coin of the person sitting to the right of them. The goal: anonymously signal “I paid” (bit 1) or “Nobody paid” (bit 0) by publicly announcing XORs of coin flips, without revealing who paid. One of them can relay a message by saying the opposite of what the protocol usually expects. If a b and c gather round a table here&amp;#39;s how everyone&amp;#39;s positioned:&lt;/p&gt;
&lt;div class="src src-text"&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; a
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;b c&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
for a: a XOR c&lt;/p&gt;
&lt;p&gt;
for b: b XOR a&lt;/p&gt;
&lt;p&gt;
for c: c XOR b&lt;/p&gt;
&lt;p&gt;
Now you can easily see that if a, b and c toss a coin, and always say truth about the XOR of their coin&amp;#39;s state with the state of their neighbour&amp;#39;s coins, the result is always 0 because each element cancel itself out. That is: &lt;code class="verbatim"&gt;(a XOR c) XOR (b XOR a) XOR (c XOR b)&lt;/code&gt; is always zero. However if any of them want to say that a state is true (that at least one of them has paid for the dinner instead of the NSA for example) they can do so by opting to announce the NOT of their XORs instead. That way the answer would be 1, a message has been collaborated to the whole group, however the sender of the message is private. But the problem is that there can be only one sender, and one bit at each round to be sent.&lt;/p&gt;</description></item><item><title>How to Convert Telegram Stickers to Signal</title><link>https://hossein.me/posts/en/telegram-sticker-to-signal-conversion/</link><pubDate>Mon, 26 May 2025 23:29:20 +0330</pubDate><guid>https://hossein.me/posts/en/telegram-sticker-to-signal-conversion/</guid><description>&lt;p&gt;As Telegram is one of the most used messengers in Iran, it has a large pool of stickers. I don&amp;rsquo;t want my contacts to miss out on them, so I always try to bring good stickers to Signal. Luckily there is an awesome free (libre) app named &lt;a href="https://github.com/laggykiller/sticker-convert"&gt;sticker-convert&lt;/a&gt; that takes care of this.&lt;/p&gt;
&lt;p&gt;I use its command line version like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;./sticker-convert-x86_64.AppImage --download-telegram https://t.me/addstickers/GreatMindsColor --author 'None' --title 'None' --export-signal --signal-uuid UUID --signal-password 'PASSWORD' --telegram-userid USER_ID --telegram-token 'TELEGRAM_TOKEN'&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now there is good documentation on how you can find and generate the tokens for both &lt;a href="https://github.com/laggykiller/sticker-convert/blob/master/docs/guide_signal.md"&gt;Signal&lt;/a&gt; and &lt;a href="https://github.com/laggykiller/sticker-convert/blob/master/docs/guide_telegram.md"&gt;Telegram&lt;/a&gt;. But for better security, I enter fake Signal credentials and provide only a bot token to the script. Obviously the script throws out an error, but the APNG output is there. So you can easily use Signal Desktop (File menu -&amp;gt; Create/upload sticker pack), import the APNG files into it, and upload them. The only downside is that the script takes care of emojis automatically, but you have to enter them manually if you use Signal Desktop for importing APNG files.&lt;/p&gt;
&lt;p&gt;After you&amp;rsquo;re done converting the stickers, please make sure you share them on &lt;a href="https://signalstickers.org"&gt;https://signalstickers.org&lt;/a&gt; as well with good tags, so everyone can easily find and use them.&lt;/p&gt;</description></item><item><title>استفاده‌ی بهینه از کپس‌لاک</title><link>https://hossein.me/posts/fa/make-capslock-great-again/</link><pubDate>Tue, 06 May 2025 11:28:33 +0330</pubDate><guid>https://hossein.me/posts/fa/make-capslock-great-again/</guid><description>&lt;p&gt;اگر کاربر حرفه‌ای پشت کامپیوتر/لپ‌تاپ‌نشین باشید یکی از کارهای خوبی که می‌تونید بکنید اینه که دوباره کنترل دکمه‌ی Caps Lock رو به دست بگیرید.&lt;/p&gt;
&lt;p&gt;مزیتی که اینکار داره اینه که موقع تایپ ده‌انگشتی، انگشت‌هاتون کم‌تر اذیت میشه. مثلا یکی از نیازمندی‌های خیلی زیاد برای تغییر موقعیت دست استفاده از کلیدهای جهت‌نما (Arrow Keyها) است. برای اینکه توی متن بالا یا پایین برید لازمه که دستتون رو به کلی بلند کنید و ببرید سمت اون دکمه‌ها. یا حتی دکمه‌ی Backspace که برای پاک‌کردن کاراکترها هم استفاده می‌شه دکمه‌ی دوریه به نسبت و ممکنه انگشت کوچک دستتون در بلندمدت درد بگیره.&lt;/p&gt;
&lt;p&gt;برای اینکه همچین اتفاقی نیفته، دکمه‌ی Caps Lock رو جوری تعریف کردم که موقع فشردنش به همراه دکمه‌های hjkl دکمه‌های جهت‌نما فشرده بشن مثلا اگر کپس‌لاک رو بگیرم و دکمه‌ی k رو فشار بدم، عملا انگار جهت‌نمای بالا رو فشار دادم و میرم یک خط بالاتر. به شکل مشابه وقتی دکمه‌ی کپس‌لاک رو با f فشار بدم انگار که Backspace فشرده شده و یک کاراکتر حذف میشه. اینطوری دستم کمترین حرکت روی کیبورد رو داره.&lt;/p&gt;
&lt;p&gt;اگر توی لینوکس هستید میتونید از &lt;a href="https://hossein.me/posts/en/xkb-customization-swaywm/"&gt;keyd&lt;/a&gt; برای اینکار استفاده کنید و اگر هم توی مک یا ویندوز هستید از &lt;a href="https://github.com/Vonng/Capslock"&gt;این مخزن گیت‌هاب&lt;/a&gt; برنامه‌های لازم رو نصب کنید. مخزن گیت‌هاب تصویر خوبی داره و نمونه کاره برای مک که چیزای بیشتری داره، ولی چیزهایی که خودم تنظیم کردم رو لینوکس و روزمره استفاده می‌کنم همین‌هاست که نوشتم.&lt;/p&gt;
&lt;p&gt;پی‌نوشت: حالا ممکنه بپرسید چطوری تایپ ده‌انگشتی یاد بگیرم؟ من خودم به شخصه خیلی بد تایپ می‌کردم و اگرچه از عمده‌ی انگشت‌هام استفاده می‌کردم ولی باز هم به‌شیوه‌ی اصولی نبود، چون عادت کرده بودم هم کلا نمی‌شد عوضش کرد و سریع برمی‌گشتم به اشتباه‌هایی که سال‌ها روشون مونده بودم. این شد که یک روز رفتم سراغ اینکه کلا استفاده از چینش QWERTY رو بذارم کنار و تایپ کردن رو یکبار دیگه از نو و این بار با چینش Dvorak یاد گرفتم. توی این چینش خاص حروف صدادار انگلیسی (aoeu) کنار هم قرار گرفتن و کلا بهینه‌شده برای اینکه سرعت تایپ شما رو بیشتر کنه. پس اگر یاد بگیرید هم تایپتون مقداری سریع‌تر میشه (با گذر زمان البته، تا سه هفته داشتم مثل بچه‌های دبستانی تایپ می‌کردم) و هم اینکه مهلتی می‌شه که تایپ ده‌انگشتی رو اصولی یاد بگیرید.&lt;/p&gt;</description></item><item><title>سازوکار شبه‌واترمارک در مدل‌های زبانی بزرگ</title><link>https://hossein.me/posts/fa/watermarking-llms/</link><pubDate>Tue, 22 Apr 2025 12:26:24 +0330</pubDate><guid>https://hossein.me/posts/fa/watermarking-llms/</guid><description>&lt;p&gt;احتمالا عکس‌هایی رو دیدید که پایینش لوگوی یک شرکت هست، یا PDFهایی که پشت متنشون اسم یک شرکت بارها نوشته شده تا کسی پرینت کرد معلوم شه صاحب اصلی کی بوده. به این کار میگن Watermark زدن.
حالا شرکت‌های هوش مصنوعی می‌تونن کاری کنن که نه‌تنها توی تولید عکس و تصویر، بلکه توی تولید متن هم محصولاتشون روی پاسخ‌هاشون Watermark بزنن.
یعنی متنی رو که هوش مصنوعی تولید کرده باشه، با دقت خوبی بشه گفت که واقعا دست‌ساخت انسان نیست و هوش مصنوعی چه شرکتی ساختتش. بنا به دلایلی مثل هزینه و احتمال ریزش کاربرها، فعلا این کار انجام نمیشه.&lt;/p&gt;
&lt;p&gt;این مورد Watermark کردن به حساب نمیاد، اما اخیرا کاربرها کشف کردن که زیادی دقیق بودن هوش مصنوعی‌ها یکجورایی می‌تونه لو بده اون‌ها رو.
مثال: سایت‌های خفن برای اینکه عبارتی مثل صد کیلومتر که میشه:&lt;/p&gt;
&lt;p&gt;100 KM&lt;/p&gt;
&lt;p&gt;توی سایتشون به هم نریزه و موقع رفتن به خط بعدی، عبارت KM از 100 جدا نشه، به‌جای فاصله‌ی معمولی، از فاصله‌ی جدانشونده (&lt;a href="https://en.wikipedia.org/wiki/Non-breaking_space"&gt;Non-breaking space&lt;/a&gt;) استفاده می‌کنن. این نوع فاصله به چشم آدم فاصله‌ی معمولی میاد ولی توی یونی‌کد، کد مجزایی داره. یا مثلا &amp;hellip; رو آدما معمولا با زدن سه‌تا نقطه می‌نویسن که میشه سه‌تا کاراکتر نقطه ولی هوش مصنوعی می‌تونه … رو با یک کاراکتر (کاراکتر مخصوص خود سه‌نقطه) بنویسه. (البته خیلی از برنامه‌ها اگر سه‌نقطه رو بزنین این تبدیل رو براتون انجام میدن)&lt;/p&gt;
&lt;p&gt;همینا باعث میشه اگر کپی‌پیست کنید و به یونی‌کد توجه نکنید یکم لو برید. مگه اگه کسی ازتون پرسید با تک تک کاراکترهایی که استفاده کردید آشنا باشید :)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://news.ycombinator.com/item?id=43748629"&gt;منبع&lt;/a&gt;&lt;/p&gt;</description></item><item><title>The Secret Interplay Between OpenSnitch and nftables</title><link>https://hossein.me/posts/en/how-does-opensnitch-work-under-the-hood/</link><pubDate>Wed, 16 Apr 2025 12:20:13 +0330</pubDate><guid>https://hossein.me/posts/en/how-does-opensnitch-work-under-the-hood/</guid><description>&lt;p&gt;I use NixOS and I have enabled its &lt;code&gt;networking.nftables.enable = true;&lt;/code&gt; and &lt;code&gt;networking.firewall.enable = true;&lt;/code&gt;. This means I get to use &lt;a href="https://github.com/NixOS/nixpkgs/blob/1750f3c1c89488e2ffdd47cab9d05454dddfb734/nixos/modules/services/networking/nftables.nix"&gt;the default configuration of nftables on NixOS&lt;/a&gt;. Now, there are times when I wish to disable it. It is fairly easy to stop the firewall service: &lt;code&gt;systemctl stop nftables&lt;/code&gt; does it. This automatically flushes the nftables ruleset and gives me freedom to do whatever I want.&lt;/p&gt;
&lt;p&gt;Today, I wanted to run a small Debian VM, and I was in no mood to configure its networking, using QEMU&amp;rsquo;s SLiRP was the way. After creating the appropriate cloud-init files, here&amp;rsquo;s the command I ran:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;qemu-system-x86_64 &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -m &lt;span style="color:#ae81ff"&gt;2048&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -smp &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -drive file&lt;span style="color:#f92672"&gt;=&lt;/span&gt;debian-12-genericcloud-amd64.qcow2,format&lt;span style="color:#f92672"&gt;=&lt;/span&gt;qcow2 &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -netdev user,id&lt;span style="color:#f92672"&gt;=&lt;/span&gt;net0,hostfwd&lt;span style="color:#f92672"&gt;=&lt;/span&gt;tcp::2222-:22 &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -device virtio-net,netdev&lt;span style="color:#f92672"&gt;=&lt;/span&gt;net0 &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; -nographic -drive file&lt;span style="color:#f92672"&gt;=&lt;/span&gt;cloud-init.iso,media&lt;span style="color:#f92672"&gt;=&lt;/span&gt;cdrom
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But strangely, there was no Internet access inside the VM except for ICMP packets. Everything went fine when I flushed the nftables ruleset, but even after stopping nftables, no matter how many times I flushed the table via &lt;code&gt;nft flush ruleset&lt;/code&gt;, these two tables kept coming back in a matter of seconds:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-nft" data-lang="nft"&gt;table inet mangle {
 chain output {
 type route hook output priority mangle; policy accept;
 meta l4proto != tcp ct state related,new queue flags bypass to 0
 tcp flags &amp;amp; (fin | syn | rst | ack) == syn queue flags bypass to 0
 }
}
table inet filter {
 chain input {
 type filter hook input priority filter; policy accept;
 udp sport 53 queue flags bypass to 0
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;What could it possibly be? At the first step, I learned about what queues are for in nftables. I had never seen them before. Queue statements in nftables are used to pass packets to userspace, just at that moment I knew which application it was. I use &lt;a href="https://github.com/evilsocket/opensnitch"&gt;OpenSnitch&lt;/a&gt; to monitor which applications make what requests. OpenSnitch automatically added all these rules, no matter how many times I flushed the ruleset. As a program that needs to process packets, it makes sense for OpenSnitch to check for its rules, but it seemed frightening at first, when I didn&amp;rsquo;t know what was going on.&lt;/p&gt;
&lt;p&gt;I was under the assumption that using eBPF, &lt;em&gt;all&lt;/em&gt; packets are checked under OpenSnitch, but apparently only TCP packets with SYN flag, and new and related packets of other type are sent to OpenSnitch for further processing. Could a person use this to their advantage? If they have root access and can send malformed packets to initiate connections, then I guess so.&lt;/p&gt;</description></item><item><title>Hosting a Hugo Site Using Codeberg Pages with One-Click Deployment</title><link>https://hossein.me/posts/en/make-a-hugo-blog-on-codeberg/</link><pubDate>Sat, 12 Apr 2025 12:41:00 +0330</pubDate><guid>https://hossein.me/posts/en/make-a-hugo-blog-on-codeberg/</guid><description>&lt;p&gt;How to host a Hugo site using Codeberg Pages with one-click deployment?&lt;/p&gt;
&lt;p&gt;Yesterday I made a few changes to my site, namely I decided to merge my Persian and English blog into one, and write more blog posts.&lt;/p&gt;
&lt;p&gt;To write more, it is necessary for the act of publishing a blog post to be easy. It would be easy on Github, which has its own CI, but I don&amp;rsquo;t want to host my blog there (they&amp;rsquo;re not a big help to libre software). Not using Github means I lose access to a nice CI. I could request one from Codeberg but seeing that it&amp;rsquo;d take their resources I decided against that as well.&lt;/p&gt;
&lt;h2 id="using-bash-for-automatic-deployment"&gt;Using Bash for Automatic Deployment&lt;/h2&gt;
&lt;p&gt;To automate a series of repetitive shell commands, the ever-present bash is the first option to consider. So that&amp;rsquo;s what I went with.&lt;/p&gt;
&lt;p&gt;My blog is on a single repo, but has two different branches. This meant that I had to go through some extra loops (&lt;code&gt;git switch&lt;/code&gt;, &lt;code&gt;git clean&lt;/code&gt;, &amp;hellip;) to publish my blog. Wouldn&amp;rsquo;t it be nice if I could have both my branches, my source directory and its build results in separate directories? A simple yet stupid approach is to clone the repo twice and use each branch in a different folder. However the best practice is to use git worktrees. And that&amp;rsquo;s what I went with.&lt;/p&gt;
&lt;p&gt;First we need to create one directory for each of the branches. You can learn this trick from &lt;a href="https://morgan.cugerone.com/blog/workarounds-to-git-worktree-using-bare-repository-and-cannot-fetch-remote-branches/"&gt;here&lt;/a&gt;. Note that you may have to also allow for relative paths (&lt;code&gt;git config status.relativePaths true&lt;/code&gt;) if you&amp;rsquo;re moving the base folder around, or use the same folder on multiple devices (for example by using &lt;a href="https://syncthing.net/"&gt;Syncthing&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;After being done with the process, you will have this directory structure:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;├── deploy.sh
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;├── main
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;└── src
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Make sure to go inside each worktree and do a &lt;code&gt;git pull&lt;/code&gt;. You may need to set up upstream branches as well.&lt;/p&gt;
&lt;p&gt;Then you can run the following deployment code for &lt;code&gt;deploy.sh&lt;/code&gt; when you&amp;rsquo;re in the parent directory:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;set -ux
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;BOLD&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;\e[1m&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;RED&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;\e[31m&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;RESET&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;\e[0m&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo -e &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;${&lt;/span&gt;BOLD&lt;span style="color:#e6db74"&gt;}${&lt;/span&gt;RED&lt;span style="color:#e6db74"&gt;}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;Make sure to push to src, as it does not happen automatically&lt;/span&gt;&lt;span style="color:#e6db74"&gt;${&lt;/span&gt;RESET&lt;span style="color:#e6db74"&gt;}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Currently at &lt;/span&gt;$PWD&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cd src
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Removing old files&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rm -rf ./public/*
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Building...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;hugo build
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cd ..
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cd main
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Removing all files in main&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rm -rf *
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#f92672"&gt;[&lt;/span&gt; ! -f .domains &lt;span style="color:#f92672"&gt;]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;Error: File &amp;#39;.domains&amp;#39; does not exist.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exit &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Restoring main&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cp -r ../src/public/* .
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Git add&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git add .
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Git diff, do you verify?&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git diff HEAD
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;COMMIT_MESSAGE&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#e6db74"&gt;${&lt;/span&gt;1&lt;span style="color:#66d9ef"&gt;:-$(&lt;/span&gt;git -C ../src log -1 --pretty&lt;span style="color:#f92672"&gt;=&lt;/span&gt;%B&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;&lt;span style="color:#e6db74"&gt;}&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Using &lt;/span&gt;$COMMIT_MESSAGE&lt;span style="color:#e6db74"&gt; as commit message.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;read -p &lt;span style="color:#e6db74"&gt;&amp;#34;Do you want to continue? (y/n): &amp;#34;&lt;/span&gt; answer
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; &lt;span style="color:#f92672"&gt;[[&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$answer&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;n&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;]]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;You said no. Exiting...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exit &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;elif&lt;/span&gt; &lt;span style="color:#f92672"&gt;[[&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$answer&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;y&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;]]&lt;/span&gt;; &lt;span style="color:#66d9ef"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;Continuing...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; echo &lt;span style="color:#e6db74"&gt;&amp;#34;Invalid input. Please enter &amp;#39;y&amp;#39; or &amp;#39;n&amp;#39;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; exit &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Git commit...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git commit -m &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$COMMIT_MESSAGE&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;echo &lt;span style="color:#e6db74"&gt;&amp;#34;Git push...&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;git push
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With this setup, I push to the src branch manually, but I can then easily deploy the static build results locally without using any CI tooling.&lt;/p&gt;</description></item><item><title>نوار کاست مسافر کوچولو</title><link>https://hossein.me/posts/fa/the-little-prince-cassette/</link><pubDate>Tue, 01 Apr 2025 00:00:00 +0000</pubDate><guid>https://hossein.me/posts/fa/the-little-prince-cassette/</guid><description>&lt;p&gt;&lt;img src="https://hossein.me/images/the-little-prince-cassette.webp" alt=""&gt;
پنج روز دیگه رمان شازده کوچولو ۸۲ ساله میشه و من همین چند روز پیش کاست اجرای صوتی این کتاب رو پیدا کردم. خود کتاب که بی‌نهایت زیباست، و دلیلی برای یادگرفتن فرانسوی؛ و اجرای صوتی فارسی ۴۰ سال پیشش هم عالی.&lt;/p&gt;
&lt;p&gt;اگر خواستید گوش بدید خوشبختانه نیاز به نوار کاستش ندارید چون عزیزانی صوتش رو در اینترنت منتشر کردن. بشتابید و از &lt;a href="https://ketabnews.com/fa/news/10298/%D8%B4%D8%A7%D8%B2%D8%AF%D9%87-%DA%A9%D9%88%DA%86%D9%88%D9%84%D9%88-%D8%A8%D8%A7-%D8%A7%D8%AC%D8%B1%D8%A7%DB%8C-%D8%A7%D8%AD%D9%85%D8%AF-%D8%B4%D8%A7%D9%85%D9%84%D9%88-%D9%88-%D9%85%D9%87%D9%88%D8%B4-%D8%A7%D9%81%D8%B4%D8%A7%D8%B1%DB%8C-%D8%B5%D9%88%D8%AA"&gt;اینجا&lt;/a&gt; گوش بسپارید به این زیبایی.&lt;/p&gt;
&lt;p&gt;پی‌نوشت: یکی از دست‌اندرکاران این اثر خانم &lt;a href="https://fa.wikipedia.org/wiki/%D9%86%D9%88%D8%B4%D8%A7%D8%A8%D9%87_%D8%A7%D9%85%DB%8C%D8%B1%DB%8C"&gt;نوشابه امیری&lt;/a&gt; دوبلور و روزنامه‌نگار هم‌وطنمون هستن که اسمشون همیشه برام جالب بوده. راوی هم خود مترجمه، احمد شاملو 🔥&lt;/p&gt;
&lt;p&gt;پی‌نوشت دوم (۹ خرداد ۱۴۰۴): ظاهرا &lt;a href="https://www.softgozar.com/%DA%A9%D8%AA%D8%A7%D8%A8-%D8%B5%D9%88%D8%AA%DB%8C-%D8%B4%D8%A7%D8%B2%D8%AF%D9%87-%DA%A9%D9%88%DA%86%D9%88%D9%84%D9%88_/"&gt;نسخه‌ای&lt;/a&gt; هم هست که ایرج گرگین ترجمه و تبدیل به نمایش رادیویی کرده.&lt;/p&gt;</description></item><item><title>چای یا tea؟</title><link>https://hossein.me/posts/fa/chai-or-tea/</link><pubDate>Fri, 28 Mar 2025 00:00:00 +0000</pubDate><guid>https://hossein.me/posts/fa/chai-or-tea/</guid><description>&lt;p&gt;به غیر چند استثناء، فقط دو راه برای گفتن «چای» در جهان وجود داره. یکی مثل انگلیسی tea یا té در اسپانیایی و tee در زبان آفریکانس. یا تغییریافته‌ی cha مثل چای توی فارسی و هندی یا cha توی خود چینی.&lt;/p&gt;
&lt;p&gt;با این حال هر دو نسخه از منطقه‌ی جغرافیایی چین اومدن. توی تصویر &lt;a href="https://qz.com/1176962/map-how-the-word-tea-spread-over-land-and-sea-to-conquer-the-world"&gt;این سایت&lt;/a&gt; می‌تونید منشاء رو ببینید. کلماتی که شبیه &amp;ldquo;cha&amp;rdquo; هستند، از طریق خشکی و در امتداد جاده ابریشم گسترش پیدا کردن و عبارات شبیه &amp;ldquo;tea&amp;rdquo; از طریق آب، توسط بازرگانان هلندی که برگ‌های جدید را به اروپا آوردند، گسترش یافتند.&lt;/p&gt;
&lt;p&gt;اصطلاح cha (茶) «سینیتیک» است، به این معنی که در بسیاری از انواع چینی رایج است. این واژه در چین آغاز شد و از طریق آسیای مرکزی و جاده‌ی ابریشم با تجارت از ۲۰۰۰ سال پیش به &amp;ldquo;chay&amp;rdquo; (چای) در فارسی تبدیل شد. این شکل فراتر از فارسی گسترش یافت و به chay در اردو، «شاي» در عربی و chay در روسی تبدیل شد. حتی به آفریقا رسید و در سواحیلی به chai تبدیل شد. اصطلاحات ژاپنی و کره‌ای برای چای نیز بر اساس چینی cha هستند، هرچند که این زبان‌ها احتمالاً قبل از گسترش به سمت غرب به فارسی، این واژه را پذیرفته‌اند.&lt;/p&gt;
&lt;p&gt;اما این توضیحی برای &amp;ldquo;tea&amp;rdquo; نیست. کاراکتر چینی برای چای، 茶، توسط انواع مختلف چینی به طور متفاوتی تلفظ می‌شود، هرچند که در همه آن‌ها به یک شکل نوشته می‌شود. در ماندارین امروزی (که کوچیک شما داره یاد میگیره) تلفظش chá ه. اما در نوع Min Nan چینی، که در استان ساحلی فوجیان صحبت می‌شود، این کاراکتر te تلفظ می‌شود. به عبارت ساحلی توی جغرافیای این منطقه دقت کنید.&lt;/p&gt;
&lt;p&gt;فرم te که در زبان‌های چینی ساحلی استفاده می‌شود، از طریق هلندی‌ها به اروپا گسترش یافت، که در قرن 17 به عنوان بازرگانان اصلی چای بین اروپا و آسیا شناخته شدند. بنادر اصلی هلند در شرق آسیا در فوجیان و تایوان بودند، جایی که مردم از تلفظ te استفاده می‌کردند. واردات گسترده چای شرکت هند شرقی هلند به اروپا، thé و به فرانسوی، Tee رو به آلمانی آلمانی و tea رو به انگلیسی داد.&lt;/p&gt;
&lt;p&gt;با این حال، هلندی‌ها اولین کسانی نبودند که به آسیا رفتند. این افتخار به پرتغالی‌ها تعلق دارد که مسئول نام مستعمراتی تایوان، Formosa هستند. پرتغالی‌ها نه از طریق فوجیان بلکه از ماکائو تجارت کردند، جایی که chá استفاده می‌شود. به همین دلیل، در نقشه بالا، پرتغال یک نقطه صورتی در دریایی از آبی است.&lt;/p&gt;
&lt;p&gt;چند زبان روش خاص خود را برای صحبت درباره چای دارند. این زبان‌ها معمولاً در جاهایی هستند که چای به طور طبیعی رشد می‌کند، که باعث شده محلی‌ها روش خاص خود را برای اشاره به آن توسعه دهند. به عنوان مثال، در برمه، برگ‌های چای lakphak نامیده می‌شوند.&lt;/p&gt;
&lt;p&gt;نقشه دو دوره مختلف جهانی‌سازی را در عمل نشان می‌دهد: جاده‌ی ابریشم و داستان ۲۰۰۰ ساله‌ی گسترش کالاها و ایده‌ها از چین باستان به سمت غرب، و تجارت نوین ۴۰۰ سالهٔ اروپایی‌های دریانورد در عصر اکتشاف.&lt;/p&gt;
&lt;p&gt;و نکته‌ی خفن: شما با دونستن tea در انگلیسی و چای در فارسی، کلمه‌ی «چای»‌ رو بلدید تقریبا به همه‌ی زبان‌های دنیا بگید :)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://qz.com/1176962/map-how-the-word-tea-spread-over-land-and-sea-to-conquer-the-world"&gt;منبع&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ترجمه‌ی کثیف از GPT4o-mini و اصلاحات ریز بر ترجمه‌ی کثیف از خودم&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;زیاد بود نخوندم (خلاصه)&lt;/strong&gt;: اگر از دریا باشه tea اگر از زمین باشه چای؛ دربارهٔ «چای» پرچم جادهٔ ابریشم و فارسی بالاست.&lt;/p&gt;</description></item><item><title>شنیدن صدا با نور</title><link>https://hossein.me/posts/fa/laser-espionage/</link><pubDate>Wed, 26 Mar 2025 00:00:00 +0000</pubDate><guid>https://hossein.me/posts/fa/laser-espionage/</guid><description>&lt;p&gt;میدونستید میشه داخل یک اتاق از مترها دورتر لیزر انداخت و از این طریق صدایی که داخل اتاق هست رو شنید؟&lt;/p&gt;
&lt;p&gt;توی &lt;a href="https://m.youtube.com/watch?v=EiVi8AjG4OY"&gt;این ویدئو&lt;/a&gt; این آقا چنین کاری می‌کنه که البته تکنیک قدیمی‌ایه و در اصل توسط دانشمندان شوروی اختراع شده.
توی ویدئو از لیزر مرئی استفاده شده ولی ظاهرا نامرئی‌اش هم کاملا ممکنه.&lt;/p&gt;
&lt;p&gt;نکته‌ی خیلی خفن‌تر اینه که من گوشیم زبانش فرانسویه و مرورگرهای وب توی درخواست‌هاشون زبان کاربر رو به یوتیوب می‌فرستن.
حالا وقتی ویدئو رو باز کردم برام عنوان و حتی زبان ویدئوی در حال پخش فرانسوی بود، خیلی خوشحال بودم که دمم گرم فرانسوی می‌فهمم و چه خوب که یاد گرفتم وگرنه نمی‌فهمیدم تا چشمم خورد به زیر صفحه که به فرانسوی نوشته بود دوبله‌ی اتوماتیک! یوتیوب &lt;a href="https://support.google.com/youtube/answer/15569972?hl=en"&gt;قابلیت دوبله با هوش مصنوعی&lt;/a&gt; رو اضافه کرده و من حتی نفهمیدم دارم ترجمه و صدای هوش مصنوعی به فرانسوی رو گوش میدم 🥲&lt;/p&gt;</description></item><item><title>Make Capslock Great Again: XKB Customization for Sway</title><link>https://hossein.me/posts/en/xkb-customization-swaywm/</link><pubDate>Sun, 26 May 2024 01:20:00 +0330</pubDate><guid>https://hossein.me/posts/en/xkb-customization-swaywm/</guid><description>&lt;p&gt;As I&amp;rsquo;m on the unstable branch of NixOS, one day I woke up to a NixOS config that was failing to build. Specifically, the derivation for &lt;code&gt;sway.conf&lt;/code&gt; wouldn&amp;rsquo;t build.
The keyboard layout I use is special. I usually switch between two customized keyboard layouts. I use the Dvorak layout to write English, and Persian (with Persian numpad) as my second layout. All my attempts to use my previous config, where I just put two modified &lt;code&gt;xkb_symbol&lt;/code&gt; files in &lt;code&gt;~/.config/xkb/&lt;/code&gt; failed. I used to have some line like this in my &lt;a href="https://swaywm.org/"&gt;Sway&lt;/a&gt; config: &lt;code&gt;xkb_layout = &amp;quot;us_with_vim,ir_with_vim&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But now the only option that I could use without NixOS throwing an error at me was the &lt;code&gt;xkb_file&lt;/code&gt; which, as explained in &lt;a href="https://man.archlinux.org/man/sway-input.5"&gt;sway-input(5)&lt;/a&gt;, this option overrides the two previous options that I was using.&lt;/p&gt;
&lt;p&gt;It was hard to find an &lt;code&gt;xkb_file&lt;/code&gt; example with two layouts in it on the web. So, here you are, a XKB keymap that I wrote that not only has two layouts in it, but also &lt;a href="https://github.com/Vonng/Capslock"&gt;&lt;em&gt;makes capslock great again&lt;/em&gt;&lt;/a&gt; by changing capslock+hjkl into arrow keys. Also, the numpad is never turned off.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;xkb_keymap {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xkb_keycodes { include &amp;#34;evdev+aliases(qwerty)&amp;#34; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xkb_types { include &amp;#34;complete+numpad(mac)&amp;#34; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xkb_compat { include &amp;#34;complete&amp;#34; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xkb_symbols {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; include &amp;#34;pc+us(dvorak)+inet(evdev)+group(alts_toggle)&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; name[Group1] = &amp;#34;dvorak with vim&amp;#34;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; include &amp;#34;ir(pes_keypad):2+group(alts_toggle):2&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; name[Group2] = &amp;#34;persian with vim&amp;#34;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; // Changes for us(dvorak)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;CAPS&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;TWO_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ ISO_Level3_Shift ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ ISO_Level3_Shift ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC02&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ o, O, KP_Enter, KP_Enter ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_seen, Arabic_hamzaonyeh, KP_Enter, KP_Enter ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC03&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ e, E, Next, Next ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Farsi_yeh, Arabic_yeh, Arabic_alefmaksura ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC04&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ u, U, BackSpace, BackSpace ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_beh, Arabic_hamzaunderalef, BackSpace, BackSpace ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC06&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ d, D, Left, Left ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_alef, Arabic_maddaonalef, Left, Left ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC07&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ h, H, Down, Down ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_teh, Arabic_tatweel, Down, Down ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC08&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ t, T, Up, Up ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_noon, guillemotright, Up, Up ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AC09&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ n, N, Right, Right ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_meem, guillemotleft, Right, Right ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AD07&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ g, G, Prior, Prior ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_ain, Arabic_fatha, Prior, Prior ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AD08&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ c, C, Delete, Delete ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Arabic_heh, bracketright, Delete, Delete ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AE03&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ 3, numbersign, Home, Home ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Farsi_3, 0x100066b, Home, Home ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &amp;lt;AE04&amp;gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; type= &amp;#34;FOUR_LEVEL&amp;#34;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group1]= [ 4, dollar, End, End ],
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; symbols[Group2]= [ Farsi_4, 0x100fdfc, End, End ]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; xkb_geometry { include &amp;#34;pc(pc105)&amp;#34; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Update (May 2025):&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t use sway? You can use &lt;a href="https://github.com/rvaiya/keyd"&gt;keyd&lt;/a&gt; with the following &lt;code&gt;/etc/keyd/default.conf&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[ids]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;*
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[main]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Define capslock behavior:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# - When held with another key, activate the &amp;#39;nav&amp;#39; layer.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# - When tapped alone, behave as normal capslock.
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;capslock = overload(nav, capslock)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[nav]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;h = left
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;j = down
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;k = up
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;l = right
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;f = backspace
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;backspace = delete
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Buddhism</title><link>https://hossein.me/posts/en/buddhism/</link><pubDate>Fri, 24 Nov 2023 18:33:58 +0330</pubDate><guid>https://hossein.me/posts/en/buddhism/</guid><description>&lt;blockquote&gt;
&lt;p&gt;Gautama found that there was a way to exit this vicious circle. If, when the mind experiences something pleasant or unpleasant, it simply understands things as they are, then there is no suffering. If you experience sadness without craving that the sadness go away, you continue to feel sadness but you do not suffer from it. There can actually be richness in the sadness. If you experience joy without craving that the joy linger and intensify, you continue to feel joy without losing your peace of mind.&lt;/p&gt;
&lt;p&gt;But how do you get the mind to accept things as they are, without craving? To accept sadness as sadness, joy as joy, pain as pain? Gautama developed a set of meditation techniques that train the mind to experience reality as it is, without craving. These practices train the mind to focus all its attention on the question, ‘What am I experiencing now?’ rather than on ‘What would I rather be experiencing?’ It is difficult to achieve this state of mind, but not impossible.&lt;/p&gt;
&lt;p&gt;Gautama grounded these meditation techniques in a set of ethical rules meant to make it easier for people to focus on actual experience and to avoid falling into cravings and fantasies. He instructed his followers to avoid killing, promiscuous sex and theft, since such acts necessarily stoke the fire of craving (for power, for sensual pleasure, or for wealth). When the flames are completely extinguished, craving is replaced by a state of perfect contentment and serenity, known as nirvana (the literal meaning of which is ‘extinguishing the fire’). Those who have attained nirvana are fully liberated from all suffering. They experience reality with the utmost clarity, free of fantasies and delusions. While they will most likely still encounter unpleasantness and pain, such experiences cause them no misery. A person who does not crave cannot suffer.&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Sapiens: A Brief History of Humankind, Sapiens: A Brief History of Humankind&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description></item><item><title>VPS Troubleshooting: A Quick Guide</title><link>https://hossein.me/posts/en/vps-troubleshooting/</link><pubDate>Sun, 14 May 2023 18:10:53 +0330</pubDate><guid>https://hossein.me/posts/en/vps-troubleshooting/</guid><description>&lt;p&gt;Many problems may occur on a VPS, and solving them is no easy task. It&amp;rsquo;s like being a doctor, you can only see the symptoms and have to give educated guesses about what the cause of the problem may be.&lt;/p&gt;
&lt;p&gt;First you diagnose the problem by different tools you have. Then, depending on your guess about the root cause, you try different remedies until you find one that actually solves the problem.&lt;/p&gt;
&lt;p&gt;This article will go over some general problems that VPSes may have. We will also learn how one may solve them. Let&amp;rsquo;s go!&lt;/p&gt;
&lt;h2 id="unable-to-connect-to-the-server-via-ssh"&gt;Unable to connect to the server via SSH&lt;/h2&gt;
&lt;h3 id="use-the-web-console"&gt;Use the web console.&lt;/h3&gt;
&lt;p&gt;All VPS providers give you the ability to manage your VPS even if it doesn&amp;rsquo;t have an Internet connection. Find that section (usually called web console) in your VPS provider&amp;rsquo;s site and log in to your server, follow the rest of the article then.&lt;/p&gt;
&lt;h3 id="are-you-connecting-to-the-correct-port-and-ip"&gt;Are you connecting to the correct port and IP?&lt;/h3&gt;
&lt;p&gt;Check the IP you&amp;rsquo;re trying to connect to; is it the same as the one on your VPS provider site? If so, the problem may be that you&amp;rsquo;re trying to connect to the wrong port.&lt;/p&gt;
&lt;p&gt;First, try to see the port that your SSH server listens to. You can use this command on your server to find that out: &lt;code&gt;sudo ss -tulpn | grep ssh&lt;/code&gt; if it shows any port other than 22, try connecting to that port from your PC, for example for port 2222, we&amp;rsquo;ll have &lt;code&gt;ssh -p 2222 user@IP&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="is-your-sever-up-and-running"&gt;Is your sever up and running?&lt;/h3&gt;
&lt;p&gt;If you haven&amp;rsquo;t blocked ICMP packets with your firewall, you can use ping (or if you only have IPv6, ping6) to see whether your server is accessible over the Internet. Try: &lt;code&gt;ping x&lt;/code&gt; or &lt;code&gt;ping6 y&lt;/code&gt; where x is your IPv4 and y your IPv6 address.&lt;/p&gt;
&lt;p&gt;Can you ping your server? Or, equivalently, can you open a service hosted on it? If so, it&amp;rsquo;s good news! At least now you know that the OS on the server is up and is responding to the packets it receives. If it&amp;rsquo;s not, ping your server with online tools such as &lt;a href="https://ping.pe"&gt;ping.pe&lt;/a&gt; to make sure your server is really down, and it&amp;rsquo;s not a problem specific to your PC. If your server is down, you must reach out to your VPS provider. It&amp;rsquo;s most likely that they have turned off your VPS because you haven&amp;rsquo;t payed the bills, if it&amp;rsquo;s not that, then open a ticket and ask them for help.&lt;/p&gt;
&lt;h3 id="use-another-server-or-computer-for-ssh-connection"&gt;Use another server or computer for SSH connection&lt;/h3&gt;
&lt;p&gt;If your server&amp;rsquo;s up, but you can&amp;rsquo;t SSH to it, it may be your PC&amp;rsquo;s Internet connection that has problems. Try SSHing on other servers or computers and see if the problem&amp;rsquo;s on your server&amp;rsquo;s side. Ideally, you can use &lt;a href="https://tcp.ping.pe"&gt;tcp.ping.pe&lt;/a&gt; to verify that your server&amp;rsquo;s SSH port is open from multiple locations.&lt;/p&gt;
&lt;h3 id="use-the-verbose-mode-of-ssh"&gt;Use the verbose mode of SSH&lt;/h3&gt;
&lt;p&gt;Your SSH client itself can provide you with more details if you ask it to, use the &lt;code&gt;-vvv&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;option for the SSH command, it&amp;rsquo;ll become more verbose and you may find the problem just by doing that.&lt;/p&gt;
&lt;h3 id="is-your-firewall-allowing-tcp-packets-to-that-port"&gt;Is your firewall allowing TCP packets to that port?&lt;/h3&gt;
&lt;p&gt;It may be that you have enabled a firewall and it&amp;rsquo;s drops any packets sent to the port SSH server is currently listening to. It all really depends on your distro, or the firewall you have chosen to use, but on most distros, iptables is the default firewall, so try: &lt;code&gt;sudo iptables -L&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you have installed nftables, try this one: &lt;code&gt;sudo nft list ruleset&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;There must be nothing that indicates dropping of packets on the port that your SSH server is listening to. If there is, just change the configuration so that it allows TCP packets to that port.&lt;/p&gt;
&lt;h3 id="is-your-ssh-server-configured-well-is-it-running"&gt;Is your SSH server configured well? Is it running?&lt;/h3&gt;
&lt;p&gt;Sometimes it&amp;rsquo;s not about the firewall, it&amp;rsquo;s just that there&amp;rsquo;s no SSH server listening on any port, or if there is, it&amp;rsquo;s not allowing you to log in. Most GNU/Linux distros use OpenSSH as their SSH server and manage it with systemd. I&amp;rsquo;ll assume these tools for this article, but for example Alpine Linux and Gentoo use &lt;a href="https://en.wikipedia.org/wiki/OpenRC"&gt;openrc&lt;/a&gt; and not systemd, or some may use &lt;a href="https://en.wikipedia.org/wiki/Dropbear_(software)"&gt;dropbear&lt;/a&gt; as their SSH server. Keep these differences in mind if you&amp;rsquo;re not using mainstream distros such as Ubuntu and Debian.&lt;/p&gt;
&lt;p&gt;First let&amp;rsquo;s see if your SSH server is running with no problems. As before, &lt;code&gt;ss -tulpn | grep ssh&lt;/code&gt; will show if there&amp;rsquo;s a process with ssh in its name is running and listening to any port. OpenSSH&amp;rsquo;s server part is called &amp;ldquo;sshd&amp;rdquo; so if it&amp;rsquo;s listening it will show up.&lt;/p&gt;
&lt;p&gt;If it&amp;rsquo;s running but you can&amp;rsquo;t connect to it; or if it&amp;rsquo;s not running, you can look for some simple logs using this command: &lt;code&gt;journalctl -u ssh.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you can&amp;rsquo;t diagnose and solve the problem just by reading those logs, try looking up OpenSSH logs directly. You can do this by executing &lt;code&gt;cat /var/log/auth.log&lt;/code&gt; if this doesn&amp;rsquo;t work, try &lt;code&gt;cat /var/log/secure&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikibooks.org/wiki/OpenSSH/Logging_and_Troubleshooting"&gt;This book&lt;/a&gt; will help you understand what the log is saying.&lt;/p&gt;
&lt;p&gt;After reading logs and searching about them, you should have a general sense of what&amp;rsquo;s wrong with your sshd configuration, if you need to change anything, try using &lt;code&gt;sudo nano /etc/ssh/sshd_config&lt;/code&gt;
After saving your changes to this configuration file, run &lt;code&gt;sudo systemctl restart sshd&lt;/code&gt; for the changes to take place, repeat reading logs and making changes until you have a working SSH server.&lt;/p&gt;
&lt;p&gt;Some lines that you must pay attention to are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;PermitRootLogin&lt;/code&gt; If it&amp;rsquo;s &amp;ldquo;no&amp;rdquo;, then obviously you can&amp;rsquo;t log in as root and should try logging in as other users.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PasswordAuthentication&lt;/code&gt; If it&amp;rsquo;s set to no, you have to always log in using your private key (a good thing!). This is done by -i option in your ssh client: &lt;code&gt;ssh -i /path/to/privkey&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PubkeyAuthentication&lt;/code&gt; This must be set to yes if you&amp;rsquo;re trying to authenticate yourself by a private key as shown above.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ListenAddress&lt;/code&gt; This part specifies on which ports the SSH server listens to. Any IP other than &lt;code&gt;0.0.0.0&lt;/code&gt; (and it&amp;rsquo;s IPv6 counterpart &lt;code&gt;::&lt;/code&gt;) or the IP you&amp;rsquo;re currently SSHing to will cause the packets to drop since the IP you request and the IP the SSH server is listening to don&amp;rsquo;t match.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To check if the SSH server is running you can try: &lt;code&gt;sudo systemctl status sshd&lt;/code&gt;&lt;/p&gt;
&lt;h2 id="high-cpu-usage"&gt;High CPU usage&lt;/h2&gt;
&lt;h3 id="a-one-shot-or-a-chronic-problem"&gt;A one-shot or a chronic problem?&lt;/h3&gt;
&lt;p&gt;Look at the CPU usage graph of your VPS. You either have server monitoring tools such as Prometheus, or if you don&amp;rsquo;t, just use the one your VPS provider (probably) gives you.&lt;/p&gt;
&lt;p&gt;In the graph, if you see a sudden bump, it may be that you have suddenly too many people using your services, your VPS has a malware, or that you&amp;rsquo;re under a DDoS attack. For the latter, using a CDN is a good idea.&lt;/p&gt;
&lt;p&gt;If the graph is smooth and showing consistently high CPU usage, follow the steps below. If the processes that are using lots of CPU are legitimate, think about upgrading your VPS resources.&lt;/p&gt;
&lt;h3 id="find-the-cpu-consuming-processes"&gt;Find the CPU-consuming processes.&lt;/h3&gt;
&lt;p&gt;You can see which processes are using the most CPU by executing: &lt;code&gt;sudo top -o %CPU&lt;/code&gt;. You can find the culprit here. Once found, you can kill it or renice it. If the process is critical, you shouldn&amp;rsquo;t do either, just upgrade your VPS resources.&lt;/p&gt;
&lt;p&gt;To kill a process, press &lt;em&gt;k&lt;/em&gt; while top is open. It will ask you for a process ID (PID) and it will close that process for you.&lt;/p&gt;
&lt;p&gt;Instead of killing processes, you can renice them. Linux comes with the ability to change the priority of processes in CPU scheduling. It&amp;rsquo;s called renicing. While top is running press &lt;em&gt;r&lt;/em&gt; , then enter a PID and change its nice value. The nice value indicates the priority of the processes in getting CPU time. Nice can be any value from +19 to -20, the higher it is, the less CPU resource that process will get. When you&amp;rsquo;re done, press q to quit.&lt;/p&gt;
&lt;h3 id="kill-restart-or-renice-the-processes"&gt;Kill, restart, or renice the processes&lt;/h3&gt;
&lt;p&gt;If you don&amp;rsquo;t find the CPU consuming processes critical, kill them. To kill a process, press &lt;em&gt;k&lt;/em&gt; while top is open. It will ask you for a process ID (PID) and it will close that process for you. If they don&amp;rsquo;t go away gracefull, press &lt;code&gt;q&lt;/code&gt; to quit from top, then execute &lt;code&gt;kill -9 x&lt;/code&gt; where x is the PID. This will force kill the process. You can try restarting the services that run the processes (e.g. if nginx uses too much CPU: &lt;code&gt;systemctl restart nginx&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Instead of killing or restarting processes, you can renice them. Linux comes with the ability to change the priority of processes in CPU scheduling, it&amp;rsquo;s called renicing. While top is running press &lt;em&gt;r&lt;/em&gt; , then enter a PID and change its nice value. The nice value indicates the priority of the processes in getting CPU time. Nice can be any value from +19 to -20, the higher it is, the less CPU resource that process will get. When you&amp;rsquo;re done, press q to quit.&lt;/p&gt;
&lt;h3 id="case-by-case-solutions"&gt;Case-by-case solutions&lt;/h3&gt;
&lt;p&gt;Sometimes the problem is more subtle, a misconfiguration in, for example, your MySQL server, or a badly written Wordpress plugin might be the whole reason your VPS is consuming so much CPU. If you have a guess about the culprit (that shows up in the result of top command), try searching. Other users may have the same problem with the service, and you can ask them about how they have solved the issue.&lt;/p&gt;
&lt;h3 id="updating-everything"&gt;Updating everything&lt;/h3&gt;
&lt;p&gt;If the problem persists, try updating everything (from your entire OS to every docker container) as a last shot. If you have recently installed or upgraded something and guess that may be the cause, you can downgrade or reinstall that too.&lt;/p&gt;
&lt;h2 id="unexpected-reboot"&gt;Unexpected reboot&lt;/h2&gt;
&lt;p&gt;This one&amp;rsquo;s hard to catch! But let&amp;rsquo;s try.&lt;/p&gt;
&lt;h3 id="how-frequent-are-these-reboots-and-when-do-they-happen"&gt;How frequent are these reboots? and when do they happen?&lt;/h3&gt;
&lt;p&gt;First see your uptime, use the &lt;code&gt;uptime&lt;/code&gt; command, it will show you the current time and following that, how long your system has been up.&lt;/p&gt;
&lt;p&gt;Then try to see the frequency of the reboots. You can do this by: &lt;code&gt;sudo last -x | tac&lt;/code&gt; the &lt;code&gt;| tac&lt;/code&gt; part is optional and only shows you the latest info at the bottom of the terminal, instead of at the top.&lt;/p&gt;
&lt;p&gt;You may understand at this level that your system is not facing a reboot, it may just be that &lt;a href="https://href.li/?https://neo4j.com/developer/kb/linux-out-of-memory-killer/"&gt;OOM killer&lt;/a&gt; is killing your processes because you&amp;rsquo;re running out of memory and your process doesn&amp;rsquo;t restart automatically.&lt;/p&gt;
&lt;h3 id="look-through-the-logs"&gt;Look through the logs&lt;/h3&gt;
&lt;p&gt;After you get a rough idea of the times your server reboots, it&amp;rsquo;s time to dive into the logs. Try checking out either &lt;code&gt;/var/log/messages&lt;/code&gt; or &lt;code&gt;/var/log/syslog&lt;/code&gt;. Since you know exactly when you have had reboots and these files have timestamps, you know where you should look at. You can also use &lt;code&gt;cat&lt;/code&gt; and &lt;code&gt;grep&lt;/code&gt; to look for specific keywords.&lt;/p&gt;
&lt;p&gt;Mae sure you look into journalctl logs at a little bit before and after reboots using this command: &lt;code&gt;journalctl -S &amp;quot;2023-01-01 00:00:00&amp;quot; -U &amp;quot;2023-01-01 01:00:00&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Things get a lot easier once you use the journalctl command, first list the boots you have had by &lt;code&gt;journalctl --list-boots&lt;/code&gt; there will be a list of latest boots with a descending number assigned to each of them. If you want to see the logs for your current boot (which has the number 0) You would type: &lt;code&gt;journalctl -b 0&lt;/code&gt; and for the one before that &lt;code&gt;journalctl -b -1&lt;/code&gt; and so on &lt;a href="https://geekflare.com/check-linux-reboot-reason"&gt;(src)&lt;/a&gt;. Please note that journalctl uses a &lt;a href="https://en.wikipedia.org/wiki/Terminal_pager"&gt;pager&lt;/a&gt;. Use arrow keys to navigate, but if you want to jump to the latest logs just press &lt;em&gt;Shift+g&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id="check-for-common-culprits"&gt;Check for common culprits&lt;/h3&gt;
&lt;p&gt;Linux sometimes panics, and if you make it to, it will reboot on panics. You can see if this is the case by executing &lt;code&gt;sysctl kernel.panic&lt;/code&gt;. If the result is a negative number, Linux will immediately reboot after a panic, if it&amp;rsquo;s a positive number, it will reboot after that many seconds, and if it&amp;rsquo;s 0, it won&amp;rsquo;t reboot.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re using a Debian based distro, and have enabled &lt;em&gt;Unattended-Upgrade::Automatic-Reboot&lt;/em&gt; in your apt configuration, then apt will reboot the system on its own after upgrades.&lt;/p&gt;
&lt;p&gt;Are you running out of resources? Check for that too, in the following part of the article you&amp;rsquo;ll learn how.&lt;/p&gt;
&lt;h3 id="ask-for-your-vps-providers-uptime"&gt;Ask for your VPS provider&amp;rsquo;s uptime&lt;/h3&gt;
&lt;p&gt;There may be nothing with your VPS after all, maybe it&amp;rsquo;s just that the dedicated server hosting your server is not configured well, or that it&amp;rsquo;s having reboots, ask your VPS provider about this.&lt;/p&gt;
&lt;h2 id="slow-response-time--network-connection-instability"&gt;Slow response time / network connection instability&lt;/h2&gt;
&lt;h3 id="do-you-have-enough-cpudiskram-resources"&gt;Do you have enough CPU/Disk/RAM resources?&lt;/h3&gt;
&lt;p&gt;Network packets need to be processed, if your system is overwhelmed and there&amp;rsquo;s not enough RAM and CPU, your VPS may have problem with processing the incoming packets. So use the following commands to see how much available resource you have.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;free -h&lt;/code&gt; use this to see how much RAM and swap you have left.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;top&lt;/code&gt; see which processes are hogging resources&lt;/li&gt;
&lt;li&gt;&lt;code&gt;df -h&lt;/code&gt; see if you have enough space left. The usage percentage better be less than 98%.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;df -hi&lt;/code&gt; see how much inodes you have left on each partition. The usage percentage better be less than 98%.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You may wonder what disk has got to do with response time. Two things come to mind. First, your programs need disk space to function well (for example a SQL server needs to write to disk) and second, sometimes your RAM is full and the OS starts writing to swap, if there&amp;rsquo;s too much I/O going on, writing and reading may be slow and it will hurt all the running processes that use swap. You should not lean on swap and if it&amp;rsquo;s always full, just buy more RAM.&lt;/p&gt;
&lt;h3 id="is-your-hard-disks-io-speed-okay"&gt;Is your hard disk&amp;rsquo;s I/O speed okay?&lt;/h3&gt;
&lt;p&gt;Sometimes the root of slow response time lies within slow disk read and write. Check for that as well.&lt;/p&gt;
&lt;h2 id="is-your-network-okay"&gt;Is your network okay?&lt;/h2&gt;
&lt;p&gt;Sometimes it may not be that your provider is having problems, but that your server is being flooded with network requests. You can check that out an app called &lt;a href="https://github.com/raboof/nethogs"&gt;nethogs&lt;/a&gt;. If you&amp;rsquo;re using too much network resources, ask for a dedicated Internet port from your server provider. But if you&amp;rsquo;re not, try to see what&amp;rsquo;s happening under the hood.&lt;/p&gt;
&lt;p&gt;Try pinging yourself and some other IP: &lt;code&gt;ping -c 10 your_ip&lt;/code&gt; and &lt;code&gt;ping -c 1.1.1.1&lt;/code&gt;. Ping shows you how long (in milliseconds) a server takes to respond to your packets, the less it is, the better. Pinging yourself should take less than a millisecond and pinging 1.1.1.1, less than 200ms at most, although it usually is a lot less than 200ms. Other than average round trip time that is displayed at the bottom, there&amp;rsquo;s also another factor you should pay attention to: packet loss. Ideally you should have a 0% packet loss.&lt;/p&gt;
&lt;p&gt;Try testing your Internet speed, first &lt;a href="https://www.speedtest.net/apps/cli"&gt;install speedtest-cli&lt;/a&gt; and then run it. Depending on your VPS provider&amp;rsquo;s network and what plan you have bought, the speed you get will vary, but if it&amp;rsquo;s too slow (and other processes are not downloading anything either), open a ticket with your provider.&lt;/p&gt;
&lt;h3 id="check-for-software-issues"&gt;Check for software issues&lt;/h3&gt;
&lt;p&gt;If your network connection is okay, but you&amp;rsquo;re still having slow response time, then it&amp;rsquo;s time that you look into the configuration of the specific service that is slow, try searching about that specific piece of software, and then optimize it.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;In this article we went through some of the common problems that you may face by owning a VPS, introduced some diagnostic tools for the problems and offered solutions. I hope you find them useful. If you have any questions or comments, don&amp;rsquo;t hesitate to send me an email.&lt;/p&gt;</description></item><item><title>Hypothesis Testing, P-Value: Things We Learn From an Anime</title><link>https://hossein.me/posts/en/hypothesis-testing/</link><pubDate>Mon, 07 Mar 2022 16:14:30 +0330</pubDate><guid>https://hossein.me/posts/en/hypothesis-testing/</guid><description>&lt;p&gt;They say it is only everybody that knows &lt;em&gt;almost&lt;/em&gt; everything and I agree. I rarely claim to know about a concept. The only thing that I&amp;rsquo;m certain about, is that there is always something, somewhere about that concept that I don&amp;rsquo;t know. But this is good news, this means that there&amp;rsquo;s always room for learning more, and I can keep learning and understanding.&lt;/p&gt;
&lt;p&gt;Hypothesis testing is one of the pillars of scientific discoveries. After observations, hypotheses are made, and surely, they need to be tested one way or another. Let&amp;rsquo;s try to understand what it takes to test a hypothesis.&lt;/p&gt;
&lt;p&gt;The way I&amp;rsquo;m going to structure this post and demonstrate how the statistics behind scientific discoveries works, comes from an unlikely source. In its first episode, the 2020 anime &lt;a href="https://en.wikipedia.org/wiki/Science_Fell_in_Love%2C_So_I_Tried_to_Prove_It"&gt;Science Fell in Love, So I Tried to Prove It&lt;/a&gt;, demonstrates the essence of hypothesis testing in a way none of my professors could. What I do here is building upon that demonstration and adding a very small amount of R and mathematical mojo.&lt;/p&gt;
&lt;p&gt;Suppose you&amp;rsquo;re a scientist living in a magical land and you want to prove that all the crows in this magical land are black, however your magical powers can only take a random sample of 100 crows and this can happen only once. You cast the spell, out of all the crows in the land, a &lt;a href="https://www.investopedia.com/terms/s/simple-random-sample.asp"&gt;random sample&lt;/a&gt; of 100 crows appear in front of you and you check them: they are all indeed black.&lt;/p&gt;
&lt;p&gt;Does this mean you can victoriously claim that all crows are black? You know very well that any critic, even you yourself, can always say that you have reached this conclusion, only because of your limited powers of magic, because of the small sample size, and not because all the crows are black like you&amp;rsquo;re implying. How do you know that there wouldn&amp;rsquo;t have been a crow of a different color, had your magical powers enabled you to take a larger sample of the crows of the land? This is a question to be considered.
&lt;img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/ad/Carrion_crows_Corvus_corone%2C_Tottenham%2C_London%2C_England_3.jpg/1024px-Carrion_crows_Corvus_corone%2C_Tottenham%2C_London%2C_England_3.jpg" alt="4 crows sitting on branches of a tree"&gt;&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Does your limited powers of observation mean that you can claim nothing unless you can do a full survey of all the crows in the world? Not really; &lt;strong&gt;even with limited powers of random sampling, you can still make very reliable claims using probabilities and &lt;a href="https://towardsdatascience.com/hypothesis-testing-demystified-e434a665e055"&gt;contradiction.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To any critic, you can say, alright, probably you&amp;rsquo;re right, perhaps not all crows are black. What percentage of crows do you claim to be non-black? Let&amp;rsquo;s say they suggest that 50% of the crows are not black.&lt;/p&gt;
&lt;p&gt;But if this is the case, given that your sample is truly randomly chosen, you can calculate the possibility of getting such a sample from a population of crows that one half of it is black, and the other half is not.&lt;/p&gt;
&lt;p&gt;A crow can be either black or not. If we were dealing with just choosing one random crow from the population, we&amp;rsquo;d have a distribution called the &lt;a href="https://en.wikipedia.org/wiki/Bernoulli_distribution"&gt;Bernoulli distribution&lt;/a&gt;, since we have multiple crows drawn out from the population, we&amp;rsquo;re dealing with a &lt;a href="https://en.wikipedia.org/wiki/Binomial_distribution"&gt;Binomial distribution&lt;/a&gt;. In the formula below, p is the chance that a crow is black, k is the number of time&amp;rsquo;s we&amp;rsquo;ve seen a black crow in our sample and n is the total number of the times we&amp;rsquo;ve drawn out a crow from the population.&lt;/p&gt;
\[
P(X=k)=\binom{n}{k}(p)^k(1-p)^{n-k}
\]&lt;p&gt;Here&amp;rsquo;s the chance of getting 100 black crows &lt;strong&gt;given that&lt;/strong&gt; half of the crows are black and the other half are not:&lt;/p&gt;
\[
P(X=100)=\binom{100}{100}(\frac{1}{2})^{100}(\frac{1}{2})^{0}\approx 7.888\times10^{-31}
\]&lt;p&gt;This small values doesn&amp;rsquo;t sound very probable, does it?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://hossein.me/images/crow_dist_graph.png" alt="Distribution for when half the crows are non-black"&gt;&lt;/p&gt;
&lt;p&gt;You can even see it on the graph, the likelihood of getting 65 crows that are all black in this scenario is very unlikely, let alone 100 crows that are all black.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;d get the same improbable results unless the critic increases their evaluation of the portion of crows they think are black. Let&amp;rsquo;s say they argue that, yes, most crows are black but there&amp;rsquo;s a very small portion of crows that are non-black, and this rarity is why we have missed the non-black ones.&lt;/p&gt;
&lt;p&gt;For example they might say that only 4% of the crows are non-black and that&amp;rsquo;s why our sample of 100 has missed them.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://hossein.me/images/crow_dist_graph_2.png" alt="Distribution for when 4% of the crows are non-black"&gt;&lt;/p&gt;
&lt;p&gt;We can argue, once more, that even this time the chances that we have missed the non-black crows because of the sample size is really low, &lt;em&gt;the probability that a random sample of 100 black crows happens merely by chance, &lt;strong&gt;given that&lt;/strong&gt; 4% of the crows of the population are non-black_is less than 1.7%.&lt;/em&gt;&lt;/p&gt;
\[
P(X=100)=\binom{100}{100}(0.96)^{100}(0.4)^{0}\approx 0.01687
\]&lt;p&gt;If they&amp;rsquo;re smart enough, they can suggest a portion that actually undermines our findings, here&amp;rsquo;s how:&lt;/p&gt;
\[
P(X=100)=\binom{100}{100}(p)^{100}(1-p)^{0} = 0.05
\]&lt;p&gt;
&lt;/p&gt;
\[
p^{100} = 5 \times 10^{-2} \Rightarrow p=5^{\frac{1}{100}} \times 10^{\frac{-2}{100}} \approx 0.9705
\]&lt;p&gt;A binomial distribution with n=100 and p=0.9705 looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://hossein.me/images/crow_dist_graph_3.png" alt="Distribution for when 97.05% of the crows are black"&gt;&lt;/p&gt;
&lt;p&gt;If they claim that 97.05% crows are black, now our sample size begins to make problems, &lt;em&gt;the probability that a random sample of 100 black crows happens, &lt;strong&gt;given that&lt;/strong&gt; 97.05% of the crows of the population are black is around 5%.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The sentences above in italic tell us what p-value means for &lt;em&gt;our question&lt;/em&gt;. But we can state it in a more general form: &lt;strong&gt;it&amp;rsquo;s the probability that our sample (or what&amp;rsquo;s even more extreme than our sample) happens, given that the hypothesis we tried to contradict is true.&lt;/strong&gt;&lt;/p&gt;
\[
p-value=P(\mbox{occurrence of our sample or more extreme case}|H_0)
\]&lt;p&gt;The use of contradiction happens right here: If this probability is very low, then maybe what we&amp;rsquo;re assuming is wrong? In different branches of science, 5% is what we call really low probability. If for our null hypothesis, our p-value drops to anything less than 5%, we say:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;We reject the null hypothesis, in favor of the alternative hypothesis at the significance level of 5%&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are two important points to be made here. First: failing to reject the null hypothesis doesn&amp;rsquo;t mean it&amp;rsquo;s true, because you&amp;rsquo;re already assuming the null hypothesis in the calculations. It doesn&amp;rsquo;t make a whole lot of sense to accept the null hypothesis when you&amp;rsquo;re already assuming it. Null hypothesis can never be accepted, we can only &lt;em&gt;reject it&lt;/em&gt; at a certain significance level or &lt;em&gt;fail to reject it&lt;/em&gt; and that&amp;rsquo;s it.&lt;/p&gt;
&lt;p&gt;The other point is that here we worked with the most extreme case, had we chosen another statement as our hypothesis, we would have to consider both our own case and the extremer ones to calculate the p-value.&lt;/p&gt;
&lt;p&gt;At last, I encourage you to read about &lt;a href="https://www.wired.com/story/were-all-p-hacking-now/"&gt;p-hacking&lt;/a&gt; and what it means for science in general. &lt;a href="https://faculty.elgin.edu/dkernler/statistics/ch10/10-1.html"&gt;From what I&amp;rsquo;ve come to understand p-value is a great tool, &lt;/a&gt; but it can also be &lt;a href="https://www.tandfonline.com/doi/full/10.1080/00031305.2019.1583913"&gt;misused and misunderstood&lt;/a&gt;&lt;a href="https://faculty.elgin.edu/dkernler/statistics/ch10/10-1.html"&gt;.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And oh&amp;hellip; One more thing! Search for &amp;ldquo;p-value memes&amp;rdquo; or &amp;ldquo;null hypothesis memes&amp;rdquo; in your favorite web search engine, and have fun :)&lt;/p&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Image © &lt;a href="https://commons.wikimedia.org/wiki/User:Acabashi"&gt;Acabashi&lt;/a&gt; &lt;a href="https://creativecommons.org/licenses/by/4.0/legalcode"&gt;CC-BY-SA 4.0&lt;/a&gt;&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description></item></channel></rss>