<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mike Lezhnin</title>
    <description>The latest articles on DEV Community by Mike Lezhnin (@mike239x).</description>
    <link>https://dev.to/mike239x</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F250364%2Fe8c07771-5fae-4795-ae2f-9b20a6129647.jpeg</url>
      <title>DEV Community: Mike Lezhnin</title>
      <link>https://dev.to/mike239x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mike239x"/>
    <language>en</language>
    <item>
      <title>HUGO (also I move away from dev.to to github pages)</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Tue, 30 Mar 2021 16:14:01 +0000</pubDate>
      <link>https://dev.to/mike239x/hugo-also-i-move-away-from-dev-to-to-github-pages-20gi</link>
      <guid>https://dev.to/mike239x/hugo-also-i-move-away-from-dev-to-to-github-pages-20gi</guid>
      <description>&lt;p&gt;Welp, I finally took my time to look into &lt;a href="https://gohugo.io/"&gt;HUGO&lt;/a&gt; - a static website generator. This thing is amazing!&lt;/p&gt;

&lt;p&gt;Just out of the box it already has the capability to turn markdown files into html, with syntax highlighting included; but it can do a whole bunch more. Custom themes, custom templates, custom everything.&lt;/p&gt;

&lt;p&gt;Hence I plan to move away from dev.to to self-hosting - first on github pages, then maybe somewhere else if I feel the need. Right now I already got &lt;a href="https://mike239x.github.io/"&gt;a website&lt;/a&gt; with github pages, but it is not using hugo - I am yet to set up CI and move my posts from different places into one - so far I got &lt;a href="https://github.com/mike239x/mike239x.github.io-source"&gt;the repo&lt;/a&gt; for that with posts cloned from dev.to.&lt;/p&gt;

&lt;p&gt;Two main reasons to move to self hosting: first - I can do more stuff, for example I can integrate any javascript I want, such as &lt;a href="https://p5js.org/"&gt;p5.js&lt;/a&gt; sketches; second - I can post different content together - dev.to is kinda limited to IT-related things, so I can't post here something on how much I enjoyed some anime, or record some weird dream of mine.&lt;/p&gt;

&lt;p&gt;One thing I would lose would be human interaction - no more comments / likes / content from other people - however, I feel like nothing of value is lost, I was using this site to express myself more than anything else.&lt;/p&gt;

&lt;p&gt;What else to say... Nothing really. So long, and thanks for all the fish.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>ls</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Mon, 22 Mar 2021 16:24:23 +0000</pubDate>
      <link>https://dev.to/mike239x/ls-1795</link>
      <guid>https://dev.to/mike239x/ls-1795</guid>
      <description>&lt;p&gt;Idk how often that happens to you, but for me at work I have some folders with many thousands files in them, and sometimes I repeat my old mistake and try to &lt;code&gt;ls&lt;/code&gt; in such a directory, to be met with a terminal freeze, which - depending on the folder size - is either for just 10 seconds, or pretty much forever, until I manage to stop it with &lt;code&gt;ctrl-c&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I decided to benchmark &lt;code&gt;ls&lt;/code&gt; against &lt;code&gt;cat&lt;/code&gt; with a matching number of files / lines of text.&lt;br&gt;
I understand that such a comparison is not fair - &lt;code&gt;cat&lt;/code&gt; doesn't have to deal with the file system all that much. &lt;/p&gt;

&lt;p&gt;Now, a few words on possible reasons for &lt;code&gt;ls&lt;/code&gt; being slow. One is the need to load some spread-out data into RAM. This can hopefully be mitigated by warm-up runs when benchmarking.&lt;br&gt;
Another two issues I found when googling for "why is &lt;code&gt;ls&lt;/code&gt; slow": usually &lt;code&gt;ls&lt;/code&gt; tabulates the output, which is a costly process; and also &lt;code&gt;ls&lt;/code&gt; colors the output, meaning one has to request info on permissions on all the files one encounters to chose the right colors. To avoid those issues one can benchmark &lt;code&gt;ls &amp;lt;dir&amp;gt; | cat&lt;/code&gt;, which just prints files/dirs one per line.&lt;/p&gt;

&lt;p&gt;With that in mind, here is some data:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#files/lines&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;cat&lt;/code&gt; time[ms]&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;ls&lt;/code&gt; time[ms]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20K&lt;/td&gt;
&lt;td&gt;0.9 ± 0.4&lt;/td&gt;
&lt;td&gt;38.2 ± 3.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40K&lt;/td&gt;
&lt;td&gt;1.4 ± 0.3&lt;/td&gt;
&lt;td&gt;79.9 ± 7.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60K&lt;/td&gt;
&lt;td&gt;1.5 ± 0.4&lt;/td&gt;
&lt;td&gt;131.5 ± 11.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;80K&lt;/td&gt;
&lt;td&gt;1.5 ± 0.2&lt;/td&gt;
&lt;td&gt;172.0 ± 6.6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At the very least the growth seems to be linear. Also, here one sees the times about one fifth of a seconds at most, while I was talking about 10 seconds before. There are two reasons for this. First, at work I got some special remotely mounted drive; so operating it takes extra time. Second, for my benchmark I used empty files. Turns out file size actually affects speed of &lt;code&gt;ls&lt;/code&gt;. For example if instead of creating empty files I write into each one 10K characters, I get the following table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#files&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;ls&lt;/code&gt; time[ms]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20K&lt;/td&gt;
&lt;td&gt;42.7 ± 3.5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40K&lt;/td&gt;
&lt;td&gt;90.9 ± 2.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60K&lt;/td&gt;
&lt;td&gt;153.3 ± 10.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;80K&lt;/td&gt;
&lt;td&gt;214.3 ± 37.4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The funniest part is that these new results are kinda inconsistent, even though I do warm-up runs. Oh well 🤷&lt;/p&gt;

&lt;p&gt;Conclusion - I got no clue how linux filesystem works, however, from a user perspective, this experiment makes me wonder if &lt;code&gt;ls&lt;/code&gt; could be faster...&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>linux</category>
    </item>
    <item>
      <title>Python `property`</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Mon, 15 Mar 2021 14:41:21 +0000</pubDate>
      <link>https://dev.to/mike239x/python-property-2pdo</link>
      <guid>https://dev.to/mike239x/python-property-2pdo</guid>
      <description>&lt;p&gt;Welp, I discovered descriptors in python. I was trying to implement something similar to &lt;code&gt;@property&lt;/code&gt;, which I thought of as some weird decorator, which turns a function into some sort of a function that is called without the &lt;code&gt;()&lt;/code&gt; brackets.&lt;br&gt;
Of course an automatically called function is something impossible, but one could inject something into &lt;code&gt;cls.__getattr__&lt;/code&gt; perhaps? Turns out this is also impossible (afaik) - to get to the class one has to either hook into where the function is defined; or have something called to reach &lt;code&gt;self&lt;/code&gt; and then hook into &lt;code&gt;__getattr__&lt;/code&gt;, but we don't have anything being called...&lt;/p&gt;

&lt;p&gt;After understanding that I got no clue how to create &lt;code&gt;property&lt;/code&gt; on my own, I googled for that, and now I got this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fget&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fget&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__get__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;objtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;prop&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I produce an object with a method &lt;code&gt;__get__(self, obj, objtype=None)&lt;/code&gt; inside another class, then this object is magically called without any brackets. Yeap, descriptors.&lt;/p&gt;

&lt;p&gt;Btw, here is a link for more info: &lt;a href="https://docs.python.org/3/howto/descriptor.html#properties"&gt;https://docs.python.org/3/howto/descriptor.html#properties&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As for what I wanted to do, I now got this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'scan'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;'_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;
        &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__get__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;objtype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;hasattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;)()&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;getattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;desc&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;A&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;other&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_other&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I can have multiple properties lazily loaded when they are needed. Yeaay.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Caching wikipedia</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Fri, 12 Mar 2021 17:09:23 +0000</pubDate>
      <link>https://dev.to/mike239x/caching-wikipedia-30l8</link>
      <guid>https://dev.to/mike239x/caching-wikipedia-30l8</guid>
      <description>&lt;p&gt;Well, I am sure the idea is not new and on the internet there are better articles about this, yet I'd like to write something as well. I should include a disclaimer - I did zero research on this topic, so maybe what I'd talk about already exists, and I just don't know about it.&lt;/p&gt;

&lt;p&gt;In the most general form the idea looks like this: it is better to keep a cached version of data instead of downloading it from the server each time. One important aspect though - the content should be immutable, so caching the main page of reddit makes little sense (or does it?). However. There are at least four topics to cover. First, books/music/videos. Second, wikipedia. Third, Social networks and similar. Lastly, websites in general.&lt;/p&gt;

&lt;p&gt;Books/music/videos is by far the easiest and the hardest one on the list. It is super easy to just cache things, so from the technical point of view it is easy, but when one actually wants to save a video from youtube per say, we get to the law/piracy/etc, and I do not want to discuss those topics here.&lt;/p&gt;

&lt;p&gt;Next, wiki. By far the most interesting one on the list. Let's assume for now that wiki is a static finished immutable thing. Then we can just have cache every page we visit, so we never need to load that page again. Neat, now we no longer need internet to visit pages we visited before, plus we reduced load on the wiki servers (less paying to keep wiki running?). Now, to address immutability issue. One can have a VCS per page, so whenever you open a page, if you have internet access you can pull new changes from the server.&lt;/p&gt;

&lt;p&gt;Social networks / news websites... I am not sure if caching would be of any use, for those are all about the new things. It might be useful - one can load only the new posts and nothing else.&lt;/p&gt;

&lt;p&gt;Lastly, websites in general. I think one can employ the same policy as with wiki - you visited the page, you cache it, now you have it. This can be cranked towards "more" or "less" - on the more controlled side you can get a cached version of website by, per say, bookmarking it, on the more automatic side you just cache everything you visit.&lt;/p&gt;

&lt;p&gt;You know what else might benefit from caching? google searches. How often did you search for exactly the same thing just because the page you found was not important enough to keep?&lt;/p&gt;

&lt;p&gt;One more thought before the concluding remarks. Multiple services like facebook, deepl, and reddit, and others go out of their way and make apps for people tp be used instead of the web-version. Even though the main reason is probably having more control over UI on smartphones, this also might be to be able to cache things.&lt;/p&gt;

&lt;p&gt;Okay, with all this being said, what to make of it?&lt;/p&gt;

&lt;p&gt;One idea is to have server that works in the incremental way to reduce server loads. Theoretically maybe possible, not so useful from my perspective of a user. This also requires some level of coordination between user of server, be it some specific protocol or something else, idk.&lt;/p&gt;

&lt;p&gt;Another idea - have a plugin that would cache wikipedia and stack overflow pages that you visit; plus one can cache pages on his own. To make the plugin useful it can f.e. offer some sort of search functionality for the pages you visited. Hm. This actually sounds nice. I want this. Not sure yet what the policy for updating the cached pages would be, but that is not so important.&lt;/p&gt;

&lt;p&gt;Ok, I'm done rambling. TLDR - read last paragraph.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>TIL sub for A if X else B</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Tue, 09 Mar 2021 14:16:52 +0000</pubDate>
      <link>https://dev.to/mike239x/til-sub-for-a-if-x-else-b-25lh</link>
      <guid>https://dev.to/mike239x/til-sub-for-a-if-x-else-b-25lh</guid>
      <description>&lt;p&gt;Welp, today instead of the usual&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;on the internet I saw&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It shall be noted that those are not equivalent - &lt;br&gt;
if &lt;code&gt;condition&lt;/code&gt; is &lt;code&gt;False&lt;/code&gt; we do get &lt;code&gt;value = b&lt;/code&gt;, but if &lt;code&gt;condition&lt;/code&gt; is &lt;code&gt;True&lt;/code&gt; we get &lt;code&gt;value = a or b&lt;/code&gt;, which is &lt;code&gt;a&lt;/code&gt; only under certain circumstances.&lt;br&gt;
So this method really only works for simple cases with &lt;code&gt;a&lt;/code&gt; not being an "empty" version of its type - since &lt;code&gt;0 or 5 == 5&lt;/code&gt; and &lt;code&gt;'' or 'qwe' == 'qwe'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Still, looks fancy and works sometimes. I am not a huge fan of how the construct &lt;code&gt;a if c else b&lt;/code&gt; looks like, so I might start doing this in my code.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>TIL to peek into zip archives</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Mon, 04 Jan 2021 14:55:06 +0000</pubDate>
      <link>https://dev.to/mike239x/til-to-peek-into-zip-archives-n0d</link>
      <guid>https://dev.to/mike239x/til-to-peek-into-zip-archives-n0d</guid>
      <description>&lt;p&gt;It is just a minute of googling, but I just learned it and I think it is worth sharing. Say you have &lt;code&gt;data.zip&lt;/code&gt;, then you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;$ vim data.zip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$ less data.zip&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;or the not-so-fancy &lt;code&gt;$ unzip -l data.zip&lt;/code&gt;
The vim version is super fancy - you can even peek into different files in the archive there! (doesn't really work for images, but oh well, what can you do)&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>linux</category>
    </item>
    <item>
      <title>Analysis of MK11</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Mon, 28 Dec 2020 17:12:12 +0000</pubDate>
      <link>https://dev.to/mike239x/analysis-of-mk11-17o4</link>
      <guid>https://dev.to/mike239x/analysis-of-mk11-17o4</guid>
      <description>&lt;p&gt;Mortal Kombat 11 was on sale on Steam, so I bought it and after downloading 100G of whatever is inside of the game I got to play it for the first time in my life. I never played fighting games before (expect maybe for Nidhogg), and I only saw clips from gameplay of other MK games on youtube at most, so I was a complete beginner when I started, but I had a friend who was willing to explain things to me.&lt;/p&gt;

&lt;p&gt;I never got really good at the game - after playing for three days I finished all the tutorials, managed to make a fancy combo with a scorpion, and even beat a single opponent online (after losing about 10 times in a row); but then I got kinda bored and didn't play it since then. Nonetheless, there are a few interesting things I noticed while playing the game, which I would like to share with you.&lt;/p&gt;

&lt;h1&gt;
  
  
  Systems against juggling
&lt;/h1&gt;

&lt;p&gt;To juggle the opponent means to hit them upwards repeatedly, which makes them pretty much unable to do anything but wait and watch us do our thing. Feels quite unfair, doesn't it?&lt;/p&gt;

&lt;p&gt;MK11 got multiple systems in place to make the entire situation look fair. First, there is damage scaling - if the opponents does a series of punches in your face, each next punch deals less and less damage. Second, there is gravity scaling - the longer you are in the air, the more you are pulled towards the ground, making it so that your opponent just can't keep you in the air of some point. An important thing to add here - after you fell down, the opponent cannot punch you until you stand up - so falling down means breaking the combo.&lt;/p&gt;

&lt;p&gt;Lastly, while in the air the defending player gets a chance to use "combo breaker" - which pretty much instantly makes the juggled player fall down and effectively ends the combo. However, to do this one has to spend something called Defensive Gauge.&lt;/p&gt;

&lt;h1&gt;
  
  
  Offensive and defensive gauges
&lt;/h1&gt;

&lt;p&gt;Confusing topic at first, but turns out to be an interesting addition to the game. &lt;/p&gt;

&lt;p&gt;Besides the health both players have another resource - offensive and defensive gauges. Unlike health, these replenish over time. Also, these gauges have only 2 bars, meaning it is a fairly limited resource.&lt;/p&gt;

&lt;p&gt;These gauges are used to do some very special moves. One of the main ways to spend offensive gauge is to amplify special moves. Skipping details, this allows players to deal more damage and often lets players to extend juggling combos - it is also often the only way to extend the juggling combo. As for defensive gauge, you can break from combos using "combo breaker", and also to do get-up rolls - a way to roll to or away from the opponent when standing up after being knocked down. That can help to change the distance to opponent, which seems to be an important aspect of the gameplay.&lt;/p&gt;

&lt;p&gt;There is also other stuff that I didn't include, but the important point being - there are some very strong moves, which all share the same common resource to limit their usage. You would normally see this kind of system with shared resources in some kind of turn-based game with action points; however it fits quite nicely in MK11. Perhaps next time someone creates a game with a bunch of abilities with cooldowns one could instead have them all share some resource. Now that I think about it, it is kinda like mana in other games, but mana is rarely treated as a rare and limiting resource 🤔.&lt;/p&gt;

&lt;h1&gt;
  
  
  Interactive elements on the map
&lt;/h1&gt;

&lt;p&gt;Each match is played on a map, which mostly is there for background scene, but it also has interactive elements. Most of them can be used for punching enemies, dealing a lot of damage, spending offensive gauge, and triggering a fancy cinematic with breaking bones (typical MK11).&lt;/p&gt;

&lt;p&gt;I think interactive elements on the map in general is a very nice thing to have as an extra polish to any game.&lt;/p&gt;

&lt;h1&gt;
  
  
  Krushing blows
&lt;/h1&gt;

&lt;p&gt;The typo is intentional - in MK11 all words starting with 'C' are written with 'K' instead - not a bug, but a feature.&lt;br&gt;
Basically, under certain conditions your attack becomes a krushing blow, dealing a lot of damage and triggering a fancy cinematic with breaking bones (typical MK11 x2).&lt;/p&gt;

&lt;p&gt;It feels very rewarding to do crushing blows, and it also makes the gameplay more entertaining. Just a nice example of positive reinforcement, I guess.&lt;/p&gt;

&lt;h1&gt;
  
  
  Testing room
&lt;/h1&gt;

&lt;p&gt;One of the best implementations of testing rooms that I have seen. By testing room I mean a place to just test various stuff.&lt;/p&gt;

&lt;p&gt;First of all, it has a setting to save the settings! I think it is very nice option that isn't present in many other games.&lt;/p&gt;

&lt;p&gt;Second, in MK11 an important aspect of the game is the frame data of punches. Each punch has start-up frames, active frames, and recovery frames; with recovery frames varying based on whether the opponent blocked the punch or not. From that two more important numbers are deduced - hit advantage and block advantage - how many frames you gain/lose if your punch is face-tanked/blocked. With this info being so important one would assume this info would be easily accessible by players, and one would be correct! Not only you can look up all that info for all the different moves and combos you have, but you can also have an in-game UI showing you this data for the last move you did.&lt;/p&gt;

&lt;p&gt;Third, you can choose a bunch of behaviors for the opponent. I didn't explore that much, but I saw that one can choose a lot of options for how the bot blocks and attacks, making it nice to train certain scenarios.&lt;/p&gt;

&lt;p&gt;Fourth, you can restart the room by a press of a single button! Very nice option for practicing juggle combos.&lt;/p&gt;

&lt;p&gt;There is probably more to it, but I was too lazy to explore other options.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final words
&lt;/h1&gt;

&lt;p&gt;Overall, MK11 is by all means not a perfect game, but it has quite a few nice features to appreciate.&lt;/p&gt;

&lt;p&gt;I think I will eventually take a look at two other fighting games from my wishlist, "Skullgirls" and "Lethal League Blaze", to see what those have to offer.&lt;/p&gt;

</description>
      <category>gamedev</category>
    </item>
    <item>
      <title>Interesting bugs from the Miz Jam 1</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Sun, 13 Sep 2020 12:29:39 +0000</pubDate>
      <link>https://dev.to/mike239x/interesting-bugs-from-the-miz-jam-1-4og1</link>
      <guid>https://dev.to/mike239x/interesting-bugs-from-the-miz-jam-1-4og1</guid>
      <description>&lt;p&gt;Now, as I used Godot game engine to make my game, the bugs lists would be related to Godot quite a lot. That being said, I believe similar situations can happen with any other engine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Item fusing
&lt;/h3&gt;

&lt;p&gt;In my game there are UFO drones that can pick up and drop items. As for how it is implemented, I decided to just abuse the collision engine. I put collision boxes on everything, and if UFO and item collide, UFO can pick it up. In the game I also made something I called a "crafting box" (clearly stolen from minecraft) - you put items in, and it creates an item. In my code I would delete all items in the box, and then place the resulting craft in the center of the box.&lt;/p&gt;

&lt;p&gt;Here is the bug - the UFO could drop the item onto the newly crafted item, as if there is a split second delay between deleting all items in the box and creating the new item.&lt;/p&gt;

&lt;p&gt;I thought that the item creation is not instant, so I decided to add some sort of a lid to the craft box, that would be there to prevent item drops when the crafting happens, but that didn't really help and so in the end I still had that bug.&lt;/p&gt;

&lt;h3&gt;
  
  
  Item double-grab
&lt;/h3&gt;

&lt;p&gt;Two UFOs could grab the same item. The grabbing was coded like that - you take ownership of the item, and also you remove the item from the collision layer for items.&lt;/p&gt;

&lt;p&gt;Turns out - the collisions for items are updated on a cycle basis, meaning that any changes to collision shapes and layers are just stored will take place only on the next cycle. Godot has this behavior documented and explains that doing it the other way would be too complex.&lt;/p&gt;

&lt;p&gt;As for the bug - what happens is this - first UFO takes the item, removes the item from collisions, but that change is not yet active as the second UFO tries to grab the item.&lt;br&gt;
This also explains the previous bug - there is a moment when the item is created, but its collision shape is not accounted for.&lt;/p&gt;

&lt;p&gt;I ended up adding &lt;code&gt;lifted&lt;/code&gt; state to the items, so that one can't lift the lifted items.&lt;/p&gt;

&lt;h3&gt;
  
  
  Grabbing wrong things
&lt;/h3&gt;

&lt;p&gt;Of course I messed up many times with collision layer setup and hence UFOs could grab things they should not. They grabbed other UFOs, they grabbed invisible items from hidden scenes, they grabbed item spawners, etc. The craziest thing was when they grabbed the lid for the crafting box (which I made to fix the first bug on this list) - by that point I added &lt;code&gt;lifted&lt;/code&gt; state to items, and since the lid didn't have that, I was randomly getting segfaults about something that I try to grab not having the &lt;code&gt;lifted&lt;/code&gt; property.&lt;br&gt;
Fixing two bugs created a third one :)&lt;/p&gt;

&lt;h3&gt;
  
  
  Hyperspeed glich
&lt;/h3&gt;

&lt;p&gt;I added speed controls to the game, so it can run faster or slower, so of course I decided to test how fast can it go. Turns out that at a certain (not too high) speed game just breaks.&lt;br&gt;
Normally after you make a drone and set a route from point A to point B for it the way it behaves is the following: take the item at A - go to B - drop item - go to A - take item - go to B - wait till previous item is taken. However with high enough speed the drone goes mad and just keeps running between A and B dropping items on top of one another.&lt;br&gt;
I still don't know how that happens, I just limited the maximum speed for my game and called it a day.&lt;/p&gt;

&lt;p&gt;I guess the only conclusion from all of this would be - better not use collision engine for puzzle games? Idk.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Devlog for Miz Jam 1</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Tue, 25 Aug 2020 01:47:29 +0000</pubDate>
      <link>https://dev.to/mike239x/devlog-for-miz-jam-1-3boj</link>
      <guid>https://dev.to/mike239x/devlog-for-miz-jam-1-3boj</guid>
      <description>&lt;p&gt;I recently participated in a light-core &lt;a href="https://itch.io/jam/miz-jam-1"&gt;game jam&lt;/a&gt; made by Miziziziz. It was 48 hours throughout a week to make a game, where everyone was obliged to use the same art-pack. Here is my &lt;a href="https://mike239x.itch.io/motherships-factory"&gt;game&lt;/a&gt; btw. Below is the devlog, later I will make a post on interesting bugs I had, another one on some nice things I learned, and a third one with just some side-notes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 1
&lt;/h3&gt;

&lt;p&gt;I looked at the provided tileset and damn that thing is huge! It has 47x22=1034 tiles of a size 16x16. I decided I want to use as many tiles in my game as I could. The two ideas on what kind of game I would like to make were as follows: 1) a 2D clone of &lt;a href="https://store.steampowered.com/app/1291340/Townscaper/"&gt;Townscaper&lt;/a&gt; or 2) a game in the style of &lt;a href="http://www.zachtronics.com/"&gt;Zachtronics&lt;/a&gt;, something with the player having to create production lines following some rules.&lt;/p&gt;

&lt;p&gt;I quickly realized that version 1 is not gonna happen - building above first floor would be impossible, so the end-result would not be interesting; so version 2 it is then.&lt;/p&gt;

&lt;p&gt;Zachtronics always has some sort of fusing thing on the level that one has to reuse to build things, so I decided to make something similar. I made it so my game is 15x9 tiles, and decided that a dedicated 3x3 area would be "the crafting box" - something I blatantly stole from Minecraft. I also made a UFO that would move items around.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 2
&lt;/h3&gt;

&lt;p&gt;Implemented the UFO, it can now grab/drop items. Implemented the crafting box. Added whole bunch of items.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 3
&lt;/h3&gt;

&lt;p&gt;Made the crafting recipes for whole bunch of items. Started making a scene where one can see all available recipes. The recipes I made were also pretty much stolen from Minecraft. You could make wood/stone/iron swords/axes/pickaxes, leather/iron armor, shields, arrows, bows. You could process trees to get wooden planks, and then use those to craft whole bunch of wooden things - doors, beds, and so on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 4
&lt;/h3&gt;

&lt;p&gt;I decided it is time to make some actual levels to the game. I decided to make 4 levels - forest/beach/mineshaft/furnace.&lt;br&gt;
I made forest level and the master level, which would allow user to move between the levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 5
&lt;/h3&gt;

&lt;p&gt;That day was a complete mess. I understood that - as is - my game will end up &lt;em&gt;really&lt;/em&gt; boring. The thing is, it is not hard to just follow a recipe and create a thing, but it takes quite some time to put the ingredients together - so the main "puzzle" of the game ends up being both easy and slow to do, making it unbearable.&lt;br&gt;
I got depressed and did nothing the entire day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 6
&lt;/h3&gt;

&lt;p&gt;I did some thinking. I realized I was still lacking the "production line" part of the game. I had in mind some idea - that if you make a cycle with the UFO it would create a drone that would start repeating the actions you made, so one would be able to set-up drones so that they create one and the same item all the time. This looked like the "production line" I wanted, but went quite against the level design I got by that time - having only 4 levels meant I can't really make more than 4 production lines, which is very little, plus I didn't really have any item generators - all resources were created from natural things lying around the world, and it would look really weird if trees and stones would instantly respawn after you take those away; but without item generators it would make the creation of "production line" much more annoying.&lt;/p&gt;

&lt;p&gt;The conclusion was to delete the levels I made and start again. This time levels were strictly separate, with well defined spawn locations and drop spots for results. I spent a while trying to come up with a way to spawn those drones in a way that will be somewhat intuitive. I ended up with this: you can move an item &lt;strong&gt;X&lt;/strong&gt; from point &lt;strong&gt;A&lt;/strong&gt; to point &lt;strong&gt;B&lt;/strong&gt;, and that will create a drone, that would move items of type &lt;strong&gt;X&lt;/strong&gt; from point &lt;strong&gt;A&lt;/strong&gt; to point &lt;strong&gt;B&lt;/strong&gt; directly following the path you took, then going back using the same path. This was both easy to code and easy for the player to understand.&lt;/p&gt;

&lt;p&gt;I also addressed the issue of difficulty. Let's take a look at an example.&lt;br&gt;
Three wooden planks make a stick:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AEGnsq_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lb2kmqjgbxcpuoe6nanp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AEGnsq_0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lb2kmqjgbxcpuoe6nanp.png" alt="Alt Text"&gt;&lt;/a&gt;And three sticks make a ladder:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uGsixbZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tzh8b3o7vec1h4wy0ua7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uGsixbZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tzh8b3o7vec1h4wy0ua7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Given two crafting boxes one can easily use one to create sticks, and another to create ladders. Easy. Looks nice, but still easy to do. Now imagine we give the player only one crafting box. Now the player should do two different crafts in just one box, alternating between those without clogging the box. Thankfully, with the way I designed the drone deployment this harder level was doable, though it is much harder to complete. Nice, now we got some complexity in the game.&lt;/p&gt;

&lt;p&gt;I made a whole bunch of levels + removed some "boring" crafts, such as all the armor and weapons based on minecraft.&lt;/p&gt;

&lt;h3&gt;
  
  
  Day 7
&lt;/h3&gt;

&lt;p&gt;With levels done I spent a while polishing the game - I added all the menus, added transitions between menu screens, added transitions between levels, buttons to change game speed, etc.&lt;br&gt;
I built the game and submitted it. Woohoo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Overall, the game turned out somewhat junky, but also - the way all the drones move together to make things is really satisfying.&lt;br&gt;
I kinda managed to make what I intended to make from the beginning, even though the gamedev process had a few unexpected turns here and there.&lt;/p&gt;

&lt;p&gt;There are a few things I wish I improved:&lt;br&gt;
1) Add some sounds - at least some nice background music&lt;br&gt;
2) Add counter to show level progress - how many items player produced&lt;br&gt;
3) Add an extra teaching level that would explain (somewhat) how to do the hardest puzzles in the game&lt;br&gt;
4) Fix an annoying bug where items can get jammed into each other.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Best webpage design IMHO</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Wed, 22 Jul 2020 21:34:41 +0000</pubDate>
      <link>https://dev.to/mike239x/best-webpage-design-imho-2p7f</link>
      <guid>https://dev.to/mike239x/best-webpage-design-imho-2p7f</guid>
      <description>&lt;p&gt;I just want to share this glorious website I found on the internet: &lt;a href="https://www.devroom.io/"&gt;devroom.io&lt;/a&gt;. It looks like all pages are written in markdown, and then rendered using some markdown rules + some coloring.&lt;/p&gt;

&lt;p&gt;If I ever end up making my own website, I'll for sure steal the design from that website.&lt;/p&gt;

&lt;p&gt;Maybe with a little effort I could even implement a back-end where one would write the pages using markdown, and then those would be turned into html and styled - using something like pygmentize - and then served 🤔&lt;/p&gt;

&lt;p&gt;P.S. I already contacted the owner of that website to find out if there is some open-source template for it, but sadly he told me the source code stays private.&lt;/p&gt;

</description>
      <category>markdown</category>
      <category>webdev</category>
      <category>design</category>
    </item>
    <item>
      <title>Vim black magic</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Tue, 31 Mar 2020 17:40:00 +0000</pubDate>
      <link>https://dev.to/mike239x/vim-black-magic-47ij</link>
      <guid>https://dev.to/mike239x/vim-black-magic-47ij</guid>
      <description>&lt;p&gt;I am watching &lt;a href="https://www.youtube.com/watch?v=aHm36-na4-4" rel="noopener noreferrer"&gt;More Instantly Better Vim&lt;/a&gt; by Damian Conway and he has a nice piece of code to put into vimrc of yours and your friends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="nb"&gt;highlight&lt;/span&gt; ColorColumn ctermbg&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;16&lt;/span&gt; ctermfg&lt;span class="p"&gt;=&lt;/span&gt;green
exec &lt;span class="s1"&gt;'set colorcolumn='&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="k"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Makes your python code look all cool like so:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo7wryvefxxfgdfanyw5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo7wryvefxxfgdfanyw5g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Grab while it's hot!&lt;/p&gt;

</description>
      <category>vim</category>
      <category>jokes</category>
    </item>
    <item>
      <title>Python segfault one-liner</title>
      <dc:creator>Mike Lezhnin</dc:creator>
      <pubDate>Mon, 24 Feb 2020 17:32:57 +0000</pubDate>
      <link>https://dev.to/mike239x/python-segfault-one-liner-2ogf</link>
      <guid>https://dev.to/mike239x/python-segfault-one-liner-2ogf</guid>
      <description>&lt;p&gt;Today I found a way to segfault Python, and after some investigation made a minimal working example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;threading&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Thread&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;itertools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

&lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()]).&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program runs infinitely, so you have to press &lt;code&gt;^C&lt;/code&gt; to stop it, and it raises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Exception ignored in: &amp;lt;module 'threading' from '/usr/lib/python3.6/threading.py'&amp;gt;
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 1294, in _shutdown
    t.join()
  File "/usr/lib/python3.6/threading.py", line 1056, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt
Fatal Python error: could not acquire lock for &amp;lt;_io.BufferedWriter name='&amp;lt;stdout&amp;gt;'&amp;gt; at interpreter shutdown, possibly due to daemon threads

Thread 0x00007f07e3866700 (most recent call first):
  File "segfault.py", line 4 in &amp;lt;listcomp&amp;gt;
  File "segfault.py", line 4 in &amp;lt;lambda&amp;gt;
  File "/usr/lib/python3.6/threading.py", line 864 in run
  File "/usr/lib/python3.6/threading.py", line 916 in _bootstrap_inner
  File "/usr/lib/python3.6/threading.py", line 884 in _bootstrap

Current thread 0x00007f07e53a0740 (most recent call first):
Aborted (core dumped)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It seems Python wants to print a nice traceback message for KeyboardInterrupt, but the spawned thread constantly steals the lock for stdout, so Python just breaks.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
  </channel>
</rss>
