<?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.naghdbishi.com/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><managingEditor>hossein@naghdbishi.com (Hossein Naghdbishi)</managingEditor><webMaster>hossein@naghdbishi.com (Hossein Naghdbishi)</webMaster><lastBuildDate>Mon, 11 May 2026 23:19:04 +0330</lastBuildDate><atom:link href="https://hossein.naghdbishi.com/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>The Courage to Be Disliked Summary</title><link>https://hossein.naghdbishi.com/posts/en/the-courage-to-be-disliked-summary/</link><pubDate>Mon, 11 May 2026 23:19:04 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/en/the-courage-to-be-disliked-summary/</guid><description>
&lt;p&gt;
The Courage to Be Disliked is a book written in a dialogue form between a young man and a philosopher. The book uses this Socratic form to teach us about Adlerian psychology.&lt;/p&gt;
&lt;div id="outline-container-headline-1" class="outline-2"&gt;
&lt;h2 id="headline-1"&gt;
We are All Subjective Beings
&lt;/h2&gt;
&lt;div id="outline-text-headline-1" class="outline-text-2"&gt;
&lt;p&gt;The book posists that we can never escape from our subjectivity, and that we ourselves choose how to interpret what we see and what meaning to attribute to it. For example a person who is short can see it as an advantage or a disadvantage, it&amp;#39;s totally up to them. A diamond, too, could be seen as nothing but a small stone. Objective facts cannot be altered, but we can change our subjective interpretation as much as we like. Therefore, our attitude, how we see the world, is of utmost importance. Our present is not determined by our experiences in the past, but by the meaning we have attributed to them: “No matter what has occurred in your life up to this point, it should have no bearing at all on how you live from now on.”&lt;/p&gt;
&lt;p&gt;
The most important thing is not in what circumstances we were born, but on how we utilize the hands we&amp;#39;re dealt. “It’s not what one is born with but what use one makes of that equipment”. Instead of focusing on the past and what could have been, we must focus on what we can do with our current equipment:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Freudian etiology is a psychology of possession, and eventually it arrives at determinism. Adlerian psychology, on the other hand, is a psychology of use, and it is you who decides it.&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;
Etiology vs Teleology
&lt;/h2&gt;
&lt;div id="outline-text-headline-2" class="outline-text-2"&gt;
&lt;p&gt;We can approach psychology either through etiology or teleology (then there is logotherapy which focuses on the future). In Freudian psychology we tell ourselves stories of the past to study why we behave in a certain way. Etiology is studying the past to understand the causes of a behavior. In Adlerian psychology, however, it is suggested that we decide our behavior right now, and any decision on our part is because we have chosen to benefit from it.
For example, the reason a NEET doesn&amp;#39;t leave the house is not because of a past trauma or fear, but rather because they enjoy the comfort and attention they are paid by their parents, even if they&amp;#39;re miserable in all other respects. The book stresses that there is no such thing as trauma and every one of our behaviors is used for a purpose. Studying what we hope to achieve by our current behavior is teleology, in other words: &lt;strong&gt;&amp;#34;People are not driven by past causes, but move toward goals that they themselves set&amp;#34;&lt;/strong&gt;. Instead of asking &amp;#39;Why am I like this?&amp;#39; (Etiology), Adler asks &amp;#39;What is my goal in acting this way?&amp;#39; (Teleology). This shifts the power back to the individual.
Another example is being unhappy. If we&amp;#39;re unhappy, it&amp;#39;s because we actively choose being unhappy, and that we&amp;#39;ve judged it to be good for us. If there&amp;#39;s something we want to change in ourselves, again, we&amp;#39;re always able to do so, and the only reason we don&amp;#39;t is because we are making the decision not to. By holding this view, we don&amp;#39;t wait for others to change or the situation to change, we take the first step ourselves. The past and how we got here don&amp;#39;t matter, and how we do from here on is our responsibilty.
Here&amp;#39;s another example from the book, about the son of a father who hit him in his childhood:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As long as I use etiology to think, It is because he hit me that I have a bad relationship with my father, it would be a matter that was impossible for me to do anything about. But if I can think, I brought out the memory of being hit because I don’t want my relationship with my father to get better, then I will be holding the card to repair relations. Because if I can just change the goal, that fixes everything.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&amp;#34;Lifestyle&amp;#34;, one&amp;#39;s worldview and outlook on life, is something the person chooses for themselves. If we don&amp;#39;t change it, it&amp;#39;s mostly because we&amp;#39;ve grow accustomed to it, and we fear that by going to uncharted territories we may get hurt. &lt;strong&gt;Anxiety is generated by changing, and disappointment by not changing, and most people usually choose the latter.&lt;/strong&gt; In other words, most people are lacking in the courage to change and be happy.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-3" class="outline-2"&gt;
&lt;h2 id="headline-3"&gt;
Apparent Cause and Effect
&lt;/h2&gt;
&lt;div id="outline-text-headline-3" class="outline-text-2"&gt;
&lt;p&gt;The book offecs a poignant observation on &amp;#34;apparent cause and effect&amp;#34;—the way we contruct logical-sounding excuses to justify our stagnation. For example the book tells the story of a girl who created a fear of blushing to avoid proposing to a boy she liked and risking rejection. Many of us are guilty of the same crime. We come up with excuses every day, and force ourselves to see a as door closed, in order to escape the pain of trying and risking.&lt;/p&gt;
&lt;p&gt;
A parabole for an unwritten and procrastinating life itself:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I have a young friend who dreams of becoming a novelist, but he never seems to be able to complete his work. According to him, his job keeps him too busy, and he can never find enough time to write novels, and that’s why he can’t complete work and enter it for writing awards. But is that the real reason? No! It’s actually that he wants to leave the possibility of “I can do it if I try” open, by not committing to anything. He doesn’t want to expose his work to criticism, and he certainly doesn’t want to face the reality that he might produce an inferior piece of writing and face rejection. He wants to live inside that realm of possibilities, where he can say that he could do it if he only had the time, or that he could write if he just had the proper environment, and that he really does have the talent for it. In another five or ten years, he will probably start using other excuses like “I’m not young anymore” or “I’ve got a family to think about now.”
YOUTH: I can relate all too well to how he must feel.
PHILOSOPHER: He should just enter his writing for an award, and if he gets rejected, so be it. If he did, he might grow, or discover that he should pursue something different. Either way, he would be able to move on. That is what changing your current lifestyle is about. He won’t get anywhere by not submitting anything.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-4" class="outline-2"&gt;
&lt;h2 id="headline-4"&gt;
Life Is Not a Competition
&lt;/h2&gt;
&lt;div id="outline-text-headline-4" class="outline-text-2"&gt;
&lt;p&gt;Human beings are equal but not the same; this means that a math genius is no more valuable than a child who can&amp;#39;t do simple arithmetic, or even a bedridden person with no activity. If we have a view that leads us to believe there is a competition going on, it will make us say words like &amp;#34;I lost to that person&amp;#34; or &amp;#34;I beat that person&amp;#34;. In turn, we will see other people as enemies. We can&amp;#39;t celebrate their happiness because their victory is our defeat, and this deprives us of a sense of community.&lt;/p&gt;
&lt;p&gt;
But every person has a sense that they need to grow even more, and a small amount of feeling lacking in a good quality is healthy for growth. Since we&amp;#39;re equals, this healthy sense comes not from comparing ourselves with other people, but with comparing us with our ideal selves. &lt;strong&gt;Life is not a competition&lt;/strong&gt; and we should move forward without competing with others. However, a problem is created when a healthy sense of inferiority becomes inferiority complex. In this case, we will use our sense of inferiority as an excuse, we will say things like &amp;#34;A happened so B can&amp;#39;t&amp;#34;, or &amp;#34;If it only weren&amp;#39;t for A, I could have achieved B&amp;#34;. These are all excuses/life-lies.&lt;/p&gt;
&lt;p&gt;
One may even not aim for success—perhaps to protect their leisure time or out of a deep-seated fear of failure. So while one might claim &amp;#34;the reality is that having a good education makes it easier to be successful in society.&amp;#34; but &amp;#34;The real issue is how one confronts that reality. If what you are thinking is, I’m not well educated, so I can’t succeed, then instead of I can’t succeed, you should think, I don’t want to succeed.&amp;#34;
If we don&amp;#39;t lack the courage, we will be diligent and find a solution to our problem. However, if we lack the courage, we will either boast about our misfortunes (saying things like &amp;#39;you don&amp;#39;t know what I&amp;#39;ve been through&amp;#39;, like a baby who rules with his weakness), or get caught up in a superiority complex, boasting about the memories past.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-5" class="outline-2"&gt;
&lt;h2 id="headline-5"&gt;
Life-tasks
&lt;/h2&gt;
&lt;div id="outline-text-headline-5" class="outline-text-2"&gt;
&lt;p&gt;According to Adler, all problems are interpersonal problems. But not only our unhappiness is caused by interpersonal relationship, so is our happiness.&lt;/p&gt;
&lt;p&gt;
In Adlerian psychology, there are 2 objectives for human behavior: to be self-reliant, and to live in harmony with the society, which are supported by the two objectives of psychology: &amp;#34;I have the ability&amp;#34; and &amp;#34;People are my comrades&amp;#34;. These two objectives can be achieved by facing &amp;#34;life tasks&amp;#34;: tasks of work, tasks of love and tasks of friendship, all of which involve interpersonal relationships.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-6" class="outline-2"&gt;
&lt;h2 id="headline-6"&gt;
Courage and Worth
&lt;/h2&gt;
&lt;div id="outline-text-headline-6" class="outline-text-2"&gt;
&lt;p&gt;If one is not following through with their life-tasks, it is not because they&amp;#39;re not able to, but because they have lost the &lt;em&gt;courage&lt;/em&gt; to face their tasks. They should first realize that it is them who holds all the cards and decides what to do with them (have a teleological attitude and change the goal), and other people who want to help should use &amp;#39;encouragement&amp;#39;. They should not judge the person or let assistance become intervention, but show by gratitude that they believe in them, that they value their relationship with them, and respect them. In Adler&amp;#39;s view, &amp;#34;It is only when a person is able to feel that he has worth that he can possess courage&amp;#34;, and courage is a prerequisite to change.
But how can one feel like they have worth? It is when they feel &amp;#34;I am beneficial and making a contribution to the community&amp;#34; or that &amp;#34;I am of use to someone&amp;#34;. However this feeling of worthiness doesn&amp;#39;t have to be something at the level of acts, but &lt;strong&gt;at the level of being&lt;/strong&gt;. We love our grandparents just by them being present, not but the things that they do for us. The same can be true for anyone, even NEETs. “People can be of use to someone else simply by being alive, and have a true sense of their worth just by being alive.”&lt;/p&gt;
&lt;p&gt;
How should we increase courage then? Acceptance, Confidence, Focusing on the Strength.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We should first accept who we are, just the way we are, and feel at ease with ourselves. We should also believe in ourselves and have the courage to take the step forward regardless of the outcome. This focus on the process of growth and journey, rather than the outcome is called encouragement.&lt;/li&gt;
&lt;li&gt;We should form a belief within, that we&amp;#39;re capable and we&amp;#39;re &amp;#39;enough&amp;#39; as long as we have the courage try. It is the antidote to inferiority complex and moves us from praise based on the outcome &amp;#34;I like it when I/you do well/achieve.&amp;#34; to &amp;#34;I believe in my/your ability to handle this.&amp;#34;, &amp;#34;I am worthy because I had the courage, regardless of the outcome&amp;#34;.&lt;/li&gt;
&lt;li&gt;By noticing on every small step that we get right, our confidence in ourselves increases and we may grow even more.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;#34;The state of coming up with all manner of pretexts [excuses] in order to avoid the life tasks&amp;#34; is a “life-lie”. And life-lies aren&amp;#39;t about being bad or evil, but about lacking courage. When telling a life-lie:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;One shifts one’s responsibility for the situation one is currently in to someone else. One is running away from one’s life tasks by saying that everything is the fault of other people, or the fault of one’s environment. It’s exactly the same as with the story I mentioned earlier about the female student with the fear of blushing. One lies to oneself, and one lies to the people around one, too. When you really think about it, it’s a pretty severe term.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-7" class="outline-2"&gt;
&lt;h2 id="headline-7"&gt;
Happiness
&lt;/h2&gt;
&lt;div id="outline-text-headline-7" class="outline-text-2"&gt;
&lt;p&gt;Happiness deeply relates to the matter of self-acceptance. We are the unhappiest of all when we dislike ourself, but we can begin to like ourselves by using the feeling of community and being of use to other people, and by self-acceptance. Our effect of contribution need not be visible either, its just a feeling that we decide to have:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Does one accept oneself on the level of acts, or on the level of being? This is truly a question that relates to the courage to be happy&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You are not the one who decides if your contributions are of use. That is the task of other people, and is not an issue in which you can intervene. In principle, there is not even any way you can know whether you have really made a contribution. That is to say, when we are engaging in this contribution to others, the contribution does not have to be a visible one—all we need is &lt;strong&gt;the subjective sense&lt;/strong&gt; that “I am of use to someone,” or in other words, a feeling of contribution.
…
All human beings can be happy. But it must be understood that this does not mean all human beings are happy. Whether it is on the level of acts or on the level of being, one needs to feel that one is of use to someone. That is to say, one needs a feeling of contribution.
…
In a word, happiness is &lt;em&gt;the feeling&lt;/em&gt; of contribution. That is the definition of happiness.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Note that this sense of being of use to the community is intrinsic, and is deeply different from being recognized and valued by others.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If one really has a feeling of contribution, one will no longer have any need for recognition from others. Because one will already have the real awareness that “I am of use to someone,” without needing to go out of one’s way to be acknowledged by others. In other words, a person who is obsessed with the desire for recognition does not have any community feeling yet, and has not managed to engage in self-acceptance, confidence in others, or contribution to others.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-8" class="outline-2"&gt;
&lt;h2 id="headline-8"&gt;
Separation of Tasks, and Avoiding of Judgement
&lt;/h2&gt;
&lt;div id="outline-text-headline-8" class="outline-text-2"&gt;
&lt;p&gt;Adlerian psychology denies the need for recognition from others, and states that one should neither rebuke, nor praise. If we seek recognition from others, we are living other people&amp;#39;s lives, and letting them have the interpersonal relationship cards. &amp;#34;If you don&amp;#39;t live your life, who is going to live it for you?&amp;#34; One might imagine that we at least need recognition from our parents, or God to live a good life, but this is false.&lt;/p&gt;
&lt;p&gt;
We need to continually separate our tasks from those of others. A simple way to see whose task it is, is to ask who&amp;#39;s going to ultimately get the result from the choice being made. Even things that seem mundane, such as urging a child to study is not recommended, it is not the parent&amp;#39;s tasks to study, just to lend a hand whenever they&amp;#39;re asked. The child has no obligation to fulfill their parents&amp;#39; expectations either. When doing the right thing, how people construe our actions and feel as a result is not our task either, it is their task to choose their attitude. Also, we must be astute enough to know when to resign, if it is not our task, or if we&amp;#39;re unable to change something, we must know when to resign. To be able to do so shows that we have a firm grasp on the truth of things.&lt;/p&gt;
&lt;p&gt;
Freedom is being disliked by other people. We must not be afraid of being disliked. Behaving in a decent manner is our task, but whether other people like us or not is not. It is not our task to fulfill other people&amp;#39;s expectations.
Freedom is resisting one&amp;#39;s instincts and impulses, a stone is powerless once it has begun to roll downhill, but we are not stones.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-9" class="outline-2"&gt;
&lt;h2 id="headline-9"&gt;
Community
&lt;/h2&gt;
&lt;div id="outline-text-headline-9" class="outline-text-2"&gt;
&lt;p&gt;Adler put great emphasis on the feeling of community, on the feeling of &amp;#34;having one&amp;#39;s refuge&amp;#34; and &amp;#34;it&amp;#39;s okay to be here&amp;#34;, that other people (and even animals and objects) are our comrades. It is when we realize that &amp;#34;I&amp;#34; is not the center of the world and when we switch from self-interest to concern for others that are we are the most happy. It is through active commitment to the community of one&amp;#39;s accord that this happens, not by simply being there. Instead of &amp;#34;What will this person give me?&amp;#34;, we will ask &amp;#34;What can I give to this person&amp;#34;.&lt;/p&gt;
&lt;p&gt;
The relationships we build in the community should be horizontal, meaning that in its basis we must treat and be treated as equals. It is for this reason that we don&amp;#39;t praise other people, praising (as well as rebuke) is a form of manipulation. We must not praise or rebuke, but encourage and express confidence in one another and gratitude. We could even treat our friends in a vertical manner:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Even if you are not treating them in a boss-or-subordinate kind of way, it is as if you are saying, “A is above me, and B is below me,” for example, or “I’ll follow A’s advice, but ignore what B says,” or “I don’t mind breaking my promise to C.”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But this undermines the very purpose of relationships, as &amp;#34;the final goal of interpersonal relationships is a feeling of community&amp;#34;.&lt;/p&gt;
&lt;p&gt;
For community feeling, &amp;#34;self-acceptance&amp;#34;, &amp;#34;confidence in others&amp;#34;, and &amp;#34;contribution to others&amp;#34; is required.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Self-acceptance is not &amp;#34;I can&amp;#34; or &amp;#34;I am strong&amp;#34;, it is not self-affirmation, but acknowledging our not being perfect and trying anyway.&lt;/li&gt;
&lt;li&gt;Confidence is different from trust, in the sense that confidence is a form of belief that requires no surety and is unconditional. The opposite of confidence is doubt, and one should not doubt the ability of their friends and loved ones.&lt;/li&gt;
&lt;li&gt;Contribution to others happens not as a self-sacrifice which is something Adler denies, but as a way to get a sense of community, and feeling worthy, dedicated to a cause greater than ourselves.&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Concept&lt;/td&gt;
&lt;td&gt;Definition&lt;/td&gt;
&lt;td&gt;The &amp;#34;Shift&amp;#34;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;strong&gt;Self-Acceptance&lt;/strong&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Acknowledging imperfection without self-affirmation lies.&lt;/td&gt;
&lt;td&gt;From &amp;#34;I must be special&amp;#34; to &amp;#34;I am enough as I am.&amp;#34;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;strong&gt;Confidence&lt;/strong&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Unconditional belief in others without requiring surety.&lt;/td&gt;
&lt;td&gt;From &amp;#34;I trust you if…&amp;#34; to &amp;#34;I believe in you regardless.&amp;#34;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;strong&gt;Contribution&lt;/strong&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The subjective sense of being of use to the community.&lt;/td&gt;
&lt;td&gt;From &amp;#34;What do I get?&amp;#34; to &amp;#34;What can I give?&amp;#34;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;strong&gt;Teleology&lt;/strong&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The study of the purpose behind current behaviors.&lt;/td&gt;
&lt;td&gt;From &amp;#34;I am stuck because of my past&amp;#34; to &amp;#34;I choose this for a goal.&amp;#34;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-10" class="outline-2"&gt;
&lt;h2 id="headline-10"&gt;
Life is a Series of Dots
&lt;/h2&gt;
&lt;div id="outline-text-headline-10" class="outline-text-2"&gt;
&lt;p&gt;There is much merit in accepting to be normal, and normal doesn&amp;#39;t mean incapable. Both children that try to get excellent grades and those who try to attract attention by problem behavior are in search of being a &amp;#34;special being&amp;#34;. However, pursuit of superiority is an unhealthy attitude. Avoiding perfectionism and accepting to be a normal being is an important part of self-acceptance. People who pursue superiority are tentative in their being, &amp;#39;en route&amp;#39; to some destination. They can&amp;#39;t rest until they arrive, but life is not a competition but a journey to be enjoyed. Life is not a line (kinetic) but a series of dots (energeial). If you finished a marathon using a helicopter that&amp;#39;d be pretty meaningless, so life is not a marathon, but a dance:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Life is a series of moments, which one lives as if one were dancing, right now, around and around each passing instant. And when one happens to survey one’s surroundings, one realizes, I guess I’ve made it this far. Among those who have danced the dance of the violin, there are people who stay the course and become professional musicians. Among those who have danced the dance of the bar examination, there are people who become lawyers. There are people who have danced the dance of writing and become authors. Of course, it also happens that people end up in entirely different places. But none of these lives came to an end “en route.” It is enough if one finds fulfillment in the here and now one is dancing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In a dance one is engaged in each moment, and it is enough that we do what we can do now, earnestly and conscientiously, but in doing so we must not get too serious and keep our lives simple.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For example, one wants to get into a university but makes no attempt to study. This an attitude of not living earnestly here and now. Of course, maybe the entrance examination is still far off. Maybe one is not sure what needs to be studied or how thoroughly, and one finds it troublesome. However, it is enough to do it little by little—every day one can work out some mathematical formulas, one can memorize some words. In short, one can dance the dance. By doing so, one is sure to have a sense of “this is what I did today”; this is what today, this single day, was for. Clearly, today is not for an entrance examination in the distant future.
…
And the same may be said with regard to your own life. You set objectives for the distant future, and think of now as your preparatory period. You think, I really want to do this, and I’ll do it when the time comes. This is a way of living that postpones life. As long as we postpone life, we can never go anywhere and will pass our days only one after the next in dull monotony, because we think of here and now as just a preparatory period, as a time for patience. But a “here and now” in which one is studying for an entrance examination in the distant future, for example, is the real thing.
…
&lt;strong&gt;The greatest life-lie of all is to not live here and now.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
Life&amp;#39;s meaning is what we attribute to it. We have freedom in the meaning we assign to it and the choices we make, and our guiding star in these is contributing to the community:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Regardless of the circumstances, we must take some form of action. We must stand up to Kant’s “inclination.”
Now, suppose one experiences a major natural disaster, and one’s response is to look back at the past in an etiological manner and say, “What could have caused such a thing to happen?” How meaningful would that be? An experience of hardship should be an opportunity to look ahead and think, What can I do from now on?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-headline-11" class="outline-2"&gt;
&lt;h2 id="headline-11"&gt;
Misc
&lt;/h2&gt;
&lt;div id="outline-text-headline-11" class="outline-text-2"&gt;
&lt;p&gt;Adler believed in holism, meaning that we can&amp;#39;t separate ourselves from our emotion, or somehow make us think of us as being cosisted of different systems.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;PHILOSOPHER: Suppose, for instance, that there is a certain Mr. A whom you don’t like because he has some flaws that are hard to forgive.
YOUTH: Ha-ha, if we’re looking for people I don’t like, there’s no shortage of candidates.
PHILOSOPHER: But it isn’t that you dislike Mr. A because you can’t forgive his flaws. You had the goal of taking a dislike to Mr. A beforehand and then started looking for the flaws to satisfy that goal.
YOUTH: That’s ridiculous! Why would I do that?
PHILOSOPHER: So that you could avoid an interpersonal relationship with Mr. A.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;</description></item><item><title>Summary of Man's Search for Meaning</title><link>https://hossein.naghdbishi.com/posts/en/mans-search-for-meaning-summary/</link><pubDate>Sun, 10 May 2026 14:54:47 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/en/mans-search-for-meaning-summary/</guid><description>&lt;p&gt;
&amp;#34;Man&amp;#39;s Search for Meaning&amp;#34; is about the experiences and philosophy of Viktor Frankl, a concentration camp survivor. As a psychiatrist who endured many atrocities, he uses his observations in the camp to claim that life remains meaningful and worthwhile even under the most extreme circumstances. As we have freedom, not in conditions of life, but in how we respond to life, we get to choose to become a saint or a swine, not as the effect of the environment, but because of our freedom to choose. One&amp;#39;s attitude is the ultimate liberty that cannot be taken away from us, and what makes life meaningful under the most extreme circumstances.&lt;/p&gt;
&lt;p&gt;
His answer to the famous question of &amp;#34;life&amp;#39;s meaning&amp;#34; is similar to that of Tolstoy&amp;#39;s famous &amp;#39;&lt;a href="https://en.wikipedia.org/wiki/The_Three_Questions"&gt;Three Questions&lt;/a&gt;&amp;#39; story. Just like a chess game that has no &lt;em&gt;best move&lt;/em&gt; in general, but a best move at every moment, so does life. The best thing we can do, and the meaning of our life is determined by the moment we are facing now and how we decide to respond to life&amp;#39;s circumstances. Therefore, it is not that we ask what&amp;#39;s the meaning of life, but that we get to know what life asks of us, and whether we wish to endure hardships and live it with much dignity.&lt;/p&gt;
&lt;p&gt;
He claims that human life usually derives its meaning from one of these:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Being creative and actually creating something, such as authoring a book&lt;/li&gt;
&lt;li&gt;Interpersonal relationships, like the joy of seeing one&amp;#39;s child, or loving another person&lt;/li&gt;
&lt;li&gt;While the most important thing is to be creative and change the root cause of our suffering, if need be, just facing an unchangeable hardship with great dignity and courage, learning to change ourselves and grow spiritually as a result is a worthy meaning.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As a result, life remains valuable in all circumstances, and we can &amp;#34;say yes to life, in spite of everything&amp;#34;. One reason that every life is valuable and meaningful is that we don&amp;#39;t know everything. He points out that since we do not know everything about this world, there might be a supermeaning to our life, a meaning beyond our comprehension. Therefore, we must try our best at all times.&lt;/p&gt;
&lt;p&gt;
He also warns against trying to live in the past. While one can do so in moderation, doing so excessively may cause us to lose sight of the opportunity of growth that is in front of us. Every difficulty is a chance to test our inner strength and a chance to grow and reach inner triumph.
It is of utmost importance that we &lt;strong&gt;believe&lt;/strong&gt; (a belief, a kind of faith as William James would put it) in the future. &amp;#34;The prisoner who had lost faith in the future—his future—was doomed. With his loss of belief in the future, he also lost his spiritual hold; he let himself decline and became subject to mental and physical decay.&amp;#34;&lt;/p&gt;
&lt;p&gt;
Frankl believes that human&amp;#39;s main concern is not to seek pleasure or avoid pain, but to see a meaning in one&amp;#39;s life. He reports that it wasn&amp;#39;t the bulky men who survived at the end, but those who had a goal beyond themselves such as writing a book only they could write, or seeing their children again.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;That is why people sometimes even choose to suffer. And it is how one can restore a man’s inner strength in the camp, by showing him some future goal. Nietzsche’s words, “He who has a why to live for can bear with almost any how,” could be the guiding motto for all psychotherapeutic and psychohygienic efforts regarding prisoners. Whenever there was an opportunity for it, one had to give them a why—an aim—for their lives, in order to strengthen them to bear the terrible how of their existence. Woe to him who saw no more sense in his life, no aim, no purpose, and therefore no point in carrying on. He was soon lost. The typical reply with which such a man rejected all encouraging arguments was, “I have nothing to expect from life any more.” What sort of answer can one give to that?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;What was really needed was a fundamental change in our attitude toward life. We had to learn ourselves and, furthermore, we had to teach the despairing men, that it did not really matter what we expected from life, but rather what life expected from us. We needed to stop asking about the meaning of life, and instead to think of ourselves as those who were being questioned by life—daily and hourly. Our answer must consist, not in talk and meditation, but in right action and in right conduct. Life ultimately means taking the responsibility to find the right answer to its problems and to fulfill the tasks which it constantly sets for each individual.&amp;#34;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
Frankl&amp;#39;s philosophy extends beyond the camps. Jerry Long is another logotherapist. He, a quadriplegic who became a university professor, says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Once, after speaking to a large audience, I was asked if I ever felt sad because I could no longer walk. I replied, &amp;#34;Professor Frankl can hardly see, I cannot walk at all, and many of you can hardly cope with life. What is crucial to remember is this - We don&amp;#39;t need just our eyes, just our legs, or just our minds. All we need are the wings of our souls and together we can fly.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
Reading this book I think I found my answer to a question I have had for a long time. While people are equal and cannot be compared due to different circumstances, ceteris paribus, what makes another person better than the other? &amp;#34;It is a question of the attitude one takes toward life’s challenges and opportunities, both large and small.&amp;#34; People should be an active designer of their life story by making good decisions in every single moment of their life, determining how they want their life to look like.&lt;/p&gt;</description></item><item><title>مانع</title><link>https://hossein.naghdbishi.com/posts/fa/resistence/</link><pubDate>Sun, 15 Feb 2026 15:58:31 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/fa/resistence/</guid><description>&lt;p&gt;
مثالی که در مورد کارهای سخت در قوانینم نوشتم اینه:‌«کارهای سخت مثل دوش آب سردن، بعد از ۵ ثانیه‌ی اول انجامشون آسون میشه». من اصولا دوش آب سرد می‌گیرم،‌ یعنی جهت شیر آب همیشه به صورت تمام و کمال به سمت آب سرده مگر اینکه سرماخورده باشم. امروز بعد چند مدت دوش با آب گرم به علت سرماخوردگی، برگشتم به آب سرد. نکته اینجا بود که چون از این عادت فاصله گرفته بودم، انجامش برام سخت‌تر از پیش بود. از خودم می‌پرسیدم که اصلا این کار چه ضرورتی داره؟‌ آیا لازمه به خودم سختی بدم در حالی که زندگیم در نقاط دیگه‌اش به اندازهٔ کافی سختی داره؟ سعی داشتم خودم رو منصرف کنم. از طرفی عمیقا تردید داشتم که بتونم واقعا دوش آب سرد بگیرم. می‌دونستم که بارها این کار رو کردم، زیر آب‌های سرد خوابگاه یا آب‌های خیلی سرد خونه دووم اورده بودم، از پنج ثانیه تا مدت‌های طولانی و چندین دقیقه، ولی باز هم به طرز عجیبی به خودم شک داشتم. نکنه چون مدتیه فاصله گرفتم دیگه نمی‌تونم دوش آب سرد بگیرم؟
در عین حال قانون همیشگیم رو به خودم یادآوری کردم: «فقط ۵ ثانیه میرم زیر دوش آب سرد و دیگه نمیرم.» ۵ ثانیه رفتم و سخت بود، بعد از ۵ ثانیه از زیر آب خودم رو کنار کشیدم. با این حال همون ۵ ثانیه بهم شهامت داد و تردید رو کنار گذاشتم. توی این شستشو هم مثل بقیهٔ حمام‌رفتن‌های قبل از سرماخوردگیم، از آب گرم هیچ استفاده‌ای نکردم.
حالا تمام این‌ها رو ننوشتم که روایت شستن خودم رو بازگو کنم، نوشتم که از «مانع» یا اون چیزی که خارجی‌ها بهش مقاومت یا Resistance می‌گن بگم. وقتی داشتم با یکی درمورد اهمال‌کاری و انجام‌دادن‌ کارهای با اولویت پایین می‌گفتم، اون به چیزهایی مثل ترس از شکست، ترس از شکستن تجسم خود بی‌نقص، گفتن اینکه «من تمام تلاشم رو نکردم پس این من نیستم که خفن نیست بلکه فقط نمیخواستم و تلاش نکردم» اشاره می‌کرد. نکته اینجا بود که من مدت‌هاست هیچ‌وقت هیچ‌کدوم رو با صدای بلند به خودم نگفتم. مطمئن نبودم که آیا درست میگه یا نه چون هیچ مدرکی از این افکار در من نبود. بعد به اون مانع و سد ذهنی قبل از رفتن زیر دوش آب سرد فکر کردم. توی لحظاتی که آدم مردده که بره زیر دوش آب سرد یا نه، ذهن خالیِ خالیه. هیچ اثری از فکر درش نیست. فقط بدوی‌ترین احساساتن که توی زمان‌هایی که ذهنت خالیه، تردید داری و نزدیک آب سردی فریاد می‌زنن رفتن زیر دوش آب سرد دردناکه. حتی ذهن هم خودش تصویرسازی می‌کنه برات که اگر بری زیر دوش آب سرد و آب بریزه روی پشتت قطره قطره‌اش قراره اذیت کنه. هیچ کدوم از این احساسات تبدیل به فکر نمی‌شن، خیلی قبل‌تر از اون برات یک مانع می‌سازن. اینکه بری رمزگشایی کنی که چه احساساتی برات مانع میسازن با خودته،‌ ولی خبر خوب اینه که راه حل معلومه: کافیه پنج ثانیه به هر طریقی که شده خودت رو بندازی توی دل ترست.&lt;/p&gt;</description></item><item><title>ترجمهٔ فارسی Todo Cambia</title><link>https://hossein.naghdbishi.com/posts/fa/todo-cambia-persian-translation/</link><pubDate>Tue, 20 Jan 2026 00:19:29 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/poor-mans-vpn-autossh/</link><pubDate>Sat, 03 Jan 2026 23:53:49 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/ique-suffix-in-nishapuri-language/</link><pubDate>Sat, 20 Dec 2025 19:55:18 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/pwn-cheatsheet/</link><pubDate>Sun, 16 Nov 2025 23:30:51 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/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.naghdbishi.com/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.naghdbishi.com/posts/fa/irans-sanctions/</link><pubDate>Mon, 27 Oct 2025 16:59:24 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/python-and-pyladies/</link><pubDate>Wed, 17 Sep 2025 19:26:32 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/believe/</link><pubDate>Thu, 04 Sep 2025 14:48:09 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/choosing-a-major/</link><pubDate>Thu, 04 Sep 2025 14:38:09 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/fa/choosing-a-major/</guid><description>&lt;img src="https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/github-sharif-sanctions/</link><pubDate>Thu, 04 Sep 2025 14:36:09 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/fa/github-sharif-sanctions/</guid><description>&lt;img src="https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/goiania-accident/</link><pubDate>Thu, 04 Sep 2025 14:33:09 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/email-quiz/</link><pubDate>Thu, 04 Sep 2025 14:32:09 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/fa/email-quiz/</guid><description>&lt;img src="https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/how-to-share-a-secret/</link><pubDate>Mon, 11 Aug 2025 13:15:47 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/tail-recursion/</link><pubDate>Sun, 10 Aug 2025 11:18:51 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/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.naghdbishi.com/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.naghdbishi.com/posts/en/mullvad-termux-android-vpn-share/</link><pubDate>Sat, 02 Aug 2025 20:53:23 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/doh-and-odoh-using-curl/</link><pubDate>Tue, 29 Jul 2025 18:37:04 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/so-you-want-to-learn-quicksort/</link><pubDate>Tue, 29 Jul 2025 11:54:15 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/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.naghdbishi.com/posts/en/dining-cryptographers/</link><pubDate>Sat, 26 Jul 2025 01:02:24 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/telegram-sticker-to-signal-conversion/</link><pubDate>Mon, 26 May 2025 23:29:20 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/make-capslock-great-again/</link><pubDate>Tue, 06 May 2025 11:28:33 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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="./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.naghdbishi.com/posts/fa/watermarking-llms/</link><pubDate>Tue, 22 Apr 2025 12:26:24 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/how-does-opensnitch-work-under-the-hood/</link><pubDate>Wed, 16 Apr 2025 12:20:13 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/make-a-hugo-blog-on-codeberg/</link><pubDate>Sat, 12 Apr 2025 12:41:00 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/the-little-prince-cassette/</link><pubDate>Tue, 01 Apr 2025 00:00:00 +0000</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/posts/fa/the-little-prince-cassette/</guid><description>&lt;p&gt;&lt;img src="https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/chai-or-tea/</link><pubDate>Fri, 28 Mar 2025 00:00:00 +0000</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/fa/laser-espionage/</link><pubDate>Wed, 26 Mar 2025 00:00:00 +0000</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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.naghdbishi.com/posts/en/xkb-customization-swaywm/</link><pubDate>Sun, 26 May 2024 01:20:00 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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, Arabic_shadda, 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.naghdbishi.com/posts/en/buddhism/</link><pubDate>Fri, 24 Nov 2023 18:33:58 +0330</pubDate><author>hossein@naghdbishi.com (Hossein Naghdbishi)</author><guid>https://hossein.naghdbishi.com/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></channel></rss>