<?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: Alex Bender</title>
    <description>The latest articles on DEV Community by Alex Bender (@alexbender).</description>
    <link>https://dev.to/alexbender</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%2F80230%2F6b82d358-2254-4cb3-acd0-3c9ecbdead78.jpeg</url>
      <title>DEV Community: Alex Bender</title>
      <link>https://dev.to/alexbender</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexbender"/>
    <language>en</language>
    <item>
      <title>Python debugger aliases</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Thu, 12 Nov 2020 10:41:56 +0000</pubDate>
      <link>https://dev.to/alexbender/python-debugger-aliases-38jc</link>
      <guid>https://dev.to/alexbender/python-debugger-aliases-38jc</guid>
      <description>&lt;p&gt;Hello all! In this note I'd like to collect some useful aliases which you can use in your &lt;a href="https://github.com/python/cpython/blob/master/Lib/pdb.py#L55-L56"&gt;&lt;code&gt;.pdbrc&lt;/code&gt;&lt;/a&gt; file which you can place to your HOME folder or current dir.&lt;/p&gt;

&lt;p&gt;So let's start from docstring of pdb &lt;a href="https://github.com/python/cpython/blob/master/Lib/pdb.py#L42-44"&gt;module&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The debugger supports aliases, which can save typing. And
aliases can have parameters (see the alias help entry) which
allows one a certain level of adaptability to the context
under examination.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what is an &lt;em&gt;alias&lt;/em&gt; after all?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; alias [name [command]]

    Create an alias called _name_ that executes _command_. The 
command must not be enclosed in quotes. Replaceable 
parameters can be indicated by %1, %2, and so on, while %* is 
replaced by all the parameters. If no command is given, the 
current alias for name is shown. If no arguments are given, 
all aliases are listed.

    Aliases may be nested and can contain anything that can 
be legally typed at the pdb prompt. Note that internal pdb 
commands can be overridden by aliases. Such a command is then
 hidden until the alias is removed. Aliasing is recursively
 applied to the first word of the command line; all other 
words in the line are left alone.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty simple, right?&lt;br&gt;
Yet so powerful. Next in documentation we ca see two examples:&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="c1"&gt;# Print instance variables (usage "pi classInst")
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mf"&gt;1.&lt;/span&gt;&lt;span class="n"&gt;__dict__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keys&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;"%1."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;k&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="o"&gt;%&lt;/span&gt;&lt;span class="mf"&gt;1.&lt;/span&gt;&lt;span class="n"&gt;__dict__&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="c1"&gt;# Print instance variables in self
&lt;/span&gt;&lt;span class="n"&gt;alias&lt;/span&gt; &lt;span class="n"&gt;ps&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second one shows that aliases could be &lt;code&gt;recursively applied to the first word of the command line&lt;/code&gt; meaning that alias &lt;code&gt;ps pi self&lt;/code&gt; will be expanded further. Each alias handled in &lt;code&gt;Pdb.precmd&lt;/code&gt; &lt;a href="https://github.com/python/cpython/blob/master/Lib/pdb.py#L390"&gt;method&lt;/a&gt; which accepts one argument -- &lt;code&gt;line&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
        &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;in&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;aliases&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&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;aliases&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what does first alias do?&lt;br&gt;
Let's take a look. Write some code to provide a context to our tests.&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;Spam&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="s"&gt;"""Run Away! Run Away!"""&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;ham&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;ham&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ham&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;egg&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;print&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;ham&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;spam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Spam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'ham'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;spam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;egg&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run this file with &lt;code&gt;pdb3&lt;/code&gt; command, see the &lt;code&gt;(Pdb)&lt;/code&gt; prompt and enter &lt;code&gt;l&lt;/code&gt; which stands for &lt;code&gt;list&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pdb3 /tmp/spam.py 
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /tmp/spam.py&lt;span class="o"&gt;(&lt;/span&gt;1&lt;span class="o"&gt;)&lt;/span&gt;&amp;lt;module&amp;gt;&lt;span class="o"&gt;()&lt;/span&gt;
-&amp;gt; class Spam&lt;span class="o"&gt;()&lt;/span&gt;:
&lt;span class="o"&gt;(&lt;/span&gt;Pdb&lt;span class="o"&gt;)&lt;/span&gt; l
  1  -&amp;gt; class Spam&lt;span class="o"&gt;()&lt;/span&gt;:
  2         &lt;span class="s2"&gt;"""Run Away! Run Away!"""&lt;/span&gt;
  3         def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, ham&lt;span class="o"&gt;)&lt;/span&gt;:
  4             self.ham &lt;span class="o"&gt;=&lt;/span&gt; ham
  5     
  6         def egg&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
  7             print&lt;span class="o"&gt;(&lt;/span&gt;self.ham&lt;span class="o"&gt;)&lt;/span&gt;
  8     
  9     
 10     spam &lt;span class="o"&gt;=&lt;/span&gt; Spam&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ham'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
 11     spam.egg&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;Pdb&lt;span class="o"&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then enter &lt;code&gt;n&lt;/code&gt; two times, so we will be here:&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pdb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;
  &lt;span class="mi"&gt;6&lt;/span&gt;         &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;egg&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="mi"&gt;7&lt;/span&gt;             &lt;span class="k"&gt;print&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;ham&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="mi"&gt;8&lt;/span&gt;     
  &lt;span class="mi"&gt;9&lt;/span&gt;     
 &lt;span class="mi"&gt;10&lt;/span&gt;     &lt;span class="n"&gt;spam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Spam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'ham'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="mi"&gt;11&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;spam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;egg&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;EOF&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pdb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's create an alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) alias for k in %1.__dict__.keys(): print("{}.{} = {}".format(%1, k, %1.__dict__[k]))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's a slightly changed version of the alias from the documentation.&lt;br&gt;
Now let's use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) pi spam
&amp;lt;__main__.Spam object at 0x7effec0f3358&amp;gt;.ham = ham
(Pdb) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hmm.. not much...&lt;br&gt;
Let's try this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) pi Spam
&amp;lt;class '__main__.Spam'&amp;gt;.__module__ = __main__
&amp;lt;class '__main__.Spam'&amp;gt;.__doc__ = Run Away! Run Away!
&amp;lt;class '__main__.Spam'&amp;gt;.__init__ = &amp;lt;function Spam.__init__ at 0x7fd414c622f0&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.egg = &amp;lt;function Spam.egg at 0x7fd414c62268&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.__dict__ = &amp;lt;attribute '__dict__' of 'Spam' objects&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.__weakref__ = &amp;lt;attribute '__weakref__' of 'Spam' objects&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yeah, much better!&lt;br&gt;
Now let's try &lt;code&gt;ps spam&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) ps spam
*** NameError: name 'self' is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What do we have here is an usage of the alias out of context.&lt;br&gt;
Let's check alias again to refresh it in mind:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) alias ps
ps = pi self
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And alias pi&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) alias pi
pi = for k in %1.__dict__.keys(): print("{}.{} = {}".format(%1, k, %1.__dict__[k]))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So &lt;code&gt;pi&lt;/code&gt; accepts one argument: &lt;code&gt;%1&lt;/code&gt;, and &lt;code&gt;ps&lt;/code&gt; tries to pass &lt;code&gt;self&lt;/code&gt; to that alias and fails because &lt;code&gt;self&lt;/code&gt; is not in context. Let's define it and try again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) self = Spam
(Pdb) ps
&amp;lt;class '__main__.Spam'&amp;gt;.__module__ = __main__
&amp;lt;class '__main__.Spam'&amp;gt;.__doc__ = Run Away! Run Away!
&amp;lt;class '__main__.Spam'&amp;gt;.__init__ = &amp;lt;function Spam.__init__ at 0x7fdbc40f1e18&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.egg = &amp;lt;function Spam.egg at 0x7fdbc40f1d90&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.__dict__ = &amp;lt;attribute '__dict__' of 'Spam' objects&amp;gt;
&amp;lt;class '__main__.Spam'&amp;gt;.__weakref__ = &amp;lt;attribute '__weakref__' of 'Spam' objects&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We cheated a bit here. As described in the documentation aliases are treated as commands typed directly into the prompt meaning that all needed &lt;em&gt;ingredients&lt;/em&gt; must be prepared to digest. You can treat aliases as functions which accepts &lt;em&gt;n&lt;/em&gt; variables which would be taken from &lt;code&gt;locals&lt;/code&gt; or &lt;code&gt;globals&lt;/code&gt;.&lt;br&gt;
And where variable &lt;code&gt;self&lt;/code&gt; is usually defined? In the class methods.&lt;br&gt;
Let's restart our session with &lt;code&gt;restart&lt;/code&gt; command (You can check all available commands typing &lt;code&gt;help&lt;/code&gt; into prompt).&lt;br&gt;
You don't need worry about lost progress because &lt;code&gt;restart&lt;/code&gt; will handle everything automatically: all breakpoints and defined aliases will be there at your service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) restart
Restarting /tmp/spam.py with arguments:
    /tmp/spam.py
&amp;gt; /tmp/spam.py(1)&amp;lt;module&amp;gt;()
-&amp;gt; class Spam():
(Pdb) l
  1  -&amp;gt; class Spam():
  2         """Run Away! Run Away!"""
  3         def __init__(self, ham):
  4             self.ham = ham
  5     
  6         def egg(self):
  7             print(self.ham)
  8     
  9     
 10     spam = Spam('ham')
 11     spam.egg()
(Pdb) b 7
Breakpoint 1 at /tmp/spam.py:7
(Pdb) c
&amp;gt; /tmp/spam.py(7)egg()
-&amp;gt; print(self.ham)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's &lt;code&gt;restart&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt;ist code, put &lt;code&gt;b&lt;/code&gt;reakpoint at line &lt;code&gt;7&lt;/code&gt; and &lt;code&gt;c&lt;/code&gt;ontinue execution.&lt;br&gt;
We end up at line 7 as we supposed to.&lt;br&gt;
Let's check &lt;code&gt;ps&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(Pdb) ps
&amp;lt;__main__.Spam object at 0x7fc94d49cef0&amp;gt;.ham = ham
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We do not get errors because self is already defined.&lt;/p&gt;




&lt;p&gt;That was short demo of aliases usage in pdb.&lt;/p&gt;

&lt;p&gt;Be aware that aliases are executed in the current context so they can clutter with your variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  6 B-&amp;gt;     def egg(self):
  7             print(self.ham)
(Pdb) aaa=1
(Pdb) bbb=2
(Pdb) alias clutter aaa=bbb
(Pdb) locals()['aaa'], locals()['bbb']
(1,2)
(Pdb) clutter
(Pdb) locals()['aaa'], locals()['bbb']
(2,2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After executing &lt;code&gt;clutter&lt;/code&gt; alias variable &lt;code&gt;aaa&lt;/code&gt; got new value. So be sure to use variable names which are unique, prefix them with &lt;code&gt;___&lt;/code&gt; as an example.&lt;/p&gt;

&lt;p&gt;And I've got some more to share:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kf = __tmp = dir(%1); __filter = [k for k in __tmp if '%2' in k]; print(__filter); del __tmp; del __filter
pi = for k in %1.__dict__.keys(): print("{}.{} = {}".format(%1, k, %1.__dict__[k]))
ps = pi self
source = import inspect; print(inspect.getsource(%1))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please share your snippets if you have anything useful, let's learn together. Debugging is pretty important skill to master so do not hesitate to read documentation on Pdb and source code.&lt;br&gt;
Thanks for reading!&lt;/p&gt;

</description>
      <category>python</category>
      <category>debugging</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The Critical Engineer</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Sat, 21 Mar 2020 20:13:13 +0000</pubDate>
      <link>https://dev.to/alexbender/the-critical-engineer-hhn</link>
      <guid>https://dev.to/alexbender/the-critical-engineer-hhn</guid>
      <description>&lt;p&gt;Who is The Critical Engineer? And what is critical engineering at all?&lt;br&gt;
I found this site, I don't remember when and how. But it still sits in my mind. Another way to see world. The group of engineers and artists gathered once and wrote that manifesto out of 10 (zero based) items: here is the beginning.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;0. The Critical Engineer considers Engineering to be the most transformative language of our time, shaping the way we move, communicate and think. It is the work of the Critical Engineer to study and exploit this language, exposing its influence.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://criticalengineering.org/"&gt;https://criticalengineering.org/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>exploration</category>
    </item>
    <item>
      <title>Common Voice</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Fri, 20 Mar 2020 22:07:03 +0000</pubDate>
      <link>https://dev.to/alexbender/common-voice-l5o</link>
      <guid>https://dev.to/alexbender/common-voice-l5o</guid>
      <description>&lt;p&gt;For some reason clicking by "write a post" wiped my story, so here would be short one instead:&lt;br&gt;
I want to share some interesting places I found here and there, maybe they could be interesting for someone else.&lt;/p&gt;

&lt;p&gt;Take a look at "Common Voice". The aim of the project is to build a dataset of voices, you can help donating your sample of voice or validating existing one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://voice.mozilla.org/en"&gt;https://voice.mozilla.org/en&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To be continued...&lt;/p&gt;

</description>
      <category>exploration</category>
    </item>
    <item>
      <title>V is new black</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Mon, 29 Jul 2019 09:54:48 +0000</pubDate>
      <link>https://dev.to/alexbender/v-is-new-black-o73</link>
      <guid>https://dev.to/alexbender/v-is-new-black-o73</guid>
      <description>&lt;p&gt;I've been writing about the new language called V, it's pretty interesting and promising. But my draft post got overwritten by new empty post. And I don't remember much what I've wrote there. That's why here is a link.&lt;/p&gt;

&lt;p&gt;Just take a look, it won't take long: &lt;a href="https://vlang.io/"&gt;https://vlang.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What do you think about it?&lt;/p&gt;

</description>
      <category>v</category>
      <category>language</category>
    </item>
    <item>
      <title>New feature suggestion: map</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Fri, 20 Jul 2018 04:44:05 +0000</pubDate>
      <link>https://dev.to/alexbender/new-feature-suggestion-map-5gl0</link>
      <guid>https://dev.to/alexbender/new-feature-suggestion-map-5gl0</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZHEPCiFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/79k23negg4oru3zhvo1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZHEPCiFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/79k23negg4oru3zhvo1e.png" alt="A map"&gt;&lt;/a&gt;&lt;br&gt;
Hello guys!&lt;br&gt;
Dev.to is so cool that I can't stop thinking about it.&lt;br&gt;
So today I'd like to introduce you to the new feature suggestion: The Social Networking Map!&lt;br&gt;
I think that programming is about communicating with each other and it's always interesting to know what area your mesh is covering, so here is the proposal:&lt;/p&gt;

&lt;p&gt;Add new section to settings page with a map of globe, where 3 different type of connections could be viewed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;who is following you&lt;/li&gt;
&lt;li&gt;who are you following&lt;/li&gt;
&lt;li&gt;and (probably) network of tags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Giving that it is possible to easily convert that numbers (following\followers) into the beautiful map.&lt;/p&gt;

&lt;p&gt;There are different possible suited types of map, to name some of it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To display connections: Faux-3D Arcs: &lt;a href="http://bl.ocks.org/dwtkns/4973620"&gt;http://bl.ocks.org/dwtkns/4973620&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;To display density: &lt;a href="https://beta.observablehq.com/@mbostock/d3-choropleth"&gt;https://beta.observablehq.com/@mbostock/d3-choropleth&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Color of the lines could be taken from the user's color preference.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>meta</category>
      <category>networking</category>
      <category>suggestion</category>
      <category>map</category>
    </item>
    <item>
      <title>Settings is not an article</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Wed, 18 Jul 2018 12:40:47 +0000</pubDate>
      <link>https://dev.to/alexbender/settings-is-not-an-article-blb</link>
      <guid>https://dev.to/alexbender/settings-is-not-an-article-blb</guid>
      <description>&lt;p&gt;I'm trying to edit and save my profile --  getting error that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 error prohibited this article from being saved:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I understand that settings are build on top of Articles/post engine, but it's little bit weird.&lt;br&gt;
Also, I'm getting this message because &lt;code&gt;Employer url is not a valid URL&lt;/code&gt;.&lt;br&gt;
I've entered . Indeed this is not valid URL. I suppose that validator didn't allow that data because there is no protocol name. But, is it so important here? Are there many &lt;code&gt;ftp&lt;/code&gt; based employer urls? or any of &lt;a href="https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml"&gt;Uniform Resource Identifier (URI) Schemes&lt;/a&gt;.&lt;br&gt;
I can bet my boots that there are not.&lt;br&gt;
So may be it would be more convenient for users to fill in their employer urls without scheme, assuming http(s) by default?&lt;/p&gt;

&lt;p&gt;P.S.: &lt;a href="http://www.dailymail.co.uk/sciencetech/article-1220286/Sir-Tim-Berners-Lee-admits-forward-slashes-web-address-mistake.html"&gt;About the slashes&lt;/a&gt;&lt;/p&gt;

</description>
      <category>meta</category>
    </item>
    <item>
      <title>Solving the Cretan maze</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Tue, 17 Jul 2018 09:33:37 +0000</pubDate>
      <link>https://dev.to/alexbender/solving-the-cretan-maze-1p7a</link>
      <guid>https://dev.to/alexbender/solving-the-cretan-maze-1p7a</guid>
      <description>&lt;h1&gt;
  
  
  So let's play the game
&lt;/h1&gt;

&lt;p&gt;Recently &lt;a href="https://dev.to/leonorader"&gt;Leonora Der&lt;/a&gt; published great piece of work: &lt;a href="https://dev.to/leonorader/solve-the-cretan-maze-2fdg"&gt;Solve the Cretan maze&lt;/a&gt;.&lt;br&gt;
That challenge is really interesting because It doesn't require you to write a lot of code, but is still interesting to solve and think about it. Additional thanks for the design: simple and great.&lt;br&gt;
So I've decided to implement basic interface for that game, of course written in Python.&lt;br&gt;
My first intention was to write something like that:&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="p"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MazeRunner&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;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# For BasicHTTPAuth
&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;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;username&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;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_maze&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="s"&gt;"""POST - /api/mazes

        Will let you start the maze
        """&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;start_loop&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="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I even did that. Wrote a dozen methods, mostly non implemented yet but they are just stubs, you know. It covered all API provided. A few days later I've started to dig around &lt;code&gt;pdb&lt;/code&gt;, then its parent &lt;code&gt;bdb&lt;/code&gt;, and then back to &lt;code&gt;pdb&lt;/code&gt;. I've noticed something interesting: here is a piece of source code for the &lt;code&gt;Pdb&lt;/code&gt; class, file &lt;code&gt;Lib/pdb.py&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;line_prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;-&amp;gt; '&lt;/span&gt;   &lt;span class="c1"&gt;# Probably a better default
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pdb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Bdb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cmd&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;_previous_sigint_handler&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;wait, what was that? That second parent class. It is &lt;code&gt;cmd&lt;/code&gt;. So as usual, Python standard lib has solved a big part of my problems. I started to read docs on this module: &lt;a href="https://docs.python.org/3/library/cmd.html"&gt;cmd&lt;/a&gt;. It appears that I've been already using this interface for more than half of decade without even noticing that: Python debuggers like &lt;code&gt;pdb&lt;/code&gt;, &lt;code&gt;ipdb&lt;/code&gt;, &lt;code&gt;pudb&lt;/code&gt;.. this common REPL appears everywhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pdb&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;pdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set_trace&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;Return&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;stdin&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pdb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt;

&lt;span class="n"&gt;Documented&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="o"&gt;========================================&lt;/span&gt;
&lt;span class="n"&gt;EOF&lt;/span&gt;    &lt;span class="n"&gt;bt&lt;/span&gt;         &lt;span class="n"&gt;cont&lt;/span&gt;      &lt;span class="n"&gt;enable&lt;/span&gt;  &lt;span class="n"&gt;jump&lt;/span&gt;  &lt;span class="n"&gt;pp&lt;/span&gt;       &lt;span class="n"&gt;run&lt;/span&gt;      &lt;span class="n"&gt;unt&lt;/span&gt;   
&lt;span class="n"&gt;a&lt;/span&gt;      &lt;span class="n"&gt;c&lt;/span&gt;          &lt;span class="k"&gt;continue&lt;/span&gt;  &lt;span class="nb"&gt;exit&lt;/span&gt;    &lt;span class="n"&gt;l&lt;/span&gt;     &lt;span class="n"&gt;q&lt;/span&gt;        &lt;span class="n"&gt;s&lt;/span&gt;        &lt;span class="n"&gt;until&lt;/span&gt; 
&lt;span class="n"&gt;alias&lt;/span&gt;  &lt;span class="n"&gt;cl&lt;/span&gt;         &lt;span class="n"&gt;d&lt;/span&gt;         &lt;span class="n"&gt;h&lt;/span&gt;       &lt;span class="nb"&gt;list&lt;/span&gt;  &lt;span class="n"&gt;quit&lt;/span&gt;     &lt;span class="n"&gt;step&lt;/span&gt;     &lt;span class="n"&gt;up&lt;/span&gt;    
&lt;span class="n"&gt;args&lt;/span&gt;   &lt;span class="n"&gt;clear&lt;/span&gt;      &lt;span class="n"&gt;debug&lt;/span&gt;     &lt;span class="n"&gt;help&lt;/span&gt;    &lt;span class="n"&gt;n&lt;/span&gt;     &lt;span class="n"&gt;r&lt;/span&gt;        &lt;span class="n"&gt;tbreak&lt;/span&gt;   &lt;span class="n"&gt;w&lt;/span&gt;     
&lt;span class="n"&gt;b&lt;/span&gt;      &lt;span class="n"&gt;commands&lt;/span&gt;   &lt;span class="n"&gt;disable&lt;/span&gt;   &lt;span class="n"&gt;ignore&lt;/span&gt;  &lt;span class="nb"&gt;next&lt;/span&gt;  &lt;span class="n"&gt;restart&lt;/span&gt;  &lt;span class="n"&gt;u&lt;/span&gt;        &lt;span class="n"&gt;whatis&lt;/span&gt;
&lt;span class="k"&gt;break&lt;/span&gt;  &lt;span class="n"&gt;condition&lt;/span&gt;  &lt;span class="n"&gt;down&lt;/span&gt;      &lt;span class="n"&gt;j&lt;/span&gt;       &lt;span class="n"&gt;p&lt;/span&gt;     &lt;span class="k"&gt;return&lt;/span&gt;   &lt;span class="n"&gt;unalias&lt;/span&gt;  &lt;span class="n"&gt;where&lt;/span&gt; 

&lt;span class="n"&gt;Miscellaneous&lt;/span&gt; &lt;span class="n"&gt;help&lt;/span&gt; &lt;span class="n"&gt;topics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="o"&gt;==========================&lt;/span&gt;
&lt;span class="k"&gt;exec&lt;/span&gt;  &lt;span class="n"&gt;pdb&lt;/span&gt;

&lt;span class="n"&gt;Undocumented&lt;/span&gt; &lt;span class="n"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="o"&gt;======================&lt;/span&gt;
&lt;span class="n"&gt;retval&lt;/span&gt;  &lt;span class="n"&gt;rv&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pdb&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's write something useful
&lt;/h2&gt;

&lt;p&gt;What do we want to solve (what do we need?)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Implement all API calls&lt;/li&gt;
&lt;li&gt;Document them all&lt;/li&gt;
&lt;li&gt;Make it clear for the user what to do (document it again and provide help)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For implementing &lt;code&gt;cmd&lt;/code&gt; interface we have to know something:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the main function is &lt;code&gt;cmdloop&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;From the documentation:

Cmd.cmdloop(intro=None)

Repeatedly issue a prompt, accept input,
parse an initial prefix off the received input,
and dispatch to action methods, passing them the
remainder of the line as argument.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;command handlers are methods called &lt;code&gt;do_&amp;lt;command-name&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An interpreter instance will recognize a command name foo if and only
if it has a method do_foo()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;for providing help for this command we have to implement &lt;code&gt;help_&amp;lt;command-name&amp;gt;&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;standard &lt;code&gt;do_help&lt;/code&gt; method calls all &lt;code&gt;help_*&lt;/code&gt; methods.&lt;/li&gt;
&lt;li&gt;there are pre- and post- handlers for commands: &lt;code&gt;precmd&lt;/code&gt; and &lt;code&gt;postcmd&lt;/code&gt; methods.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Cmd.precmd(line)

    Hook method executed just before the command line line is interpreted, but
after the input prompt is generated and issued. This method is a stub in Cmd;
it exists to be overridden by subclasses. The return value is used as
the command which will be executed by the onecmd() method; the precmd()
implementation may re-write the command or simply return line unchanged.

Cmd.postcmd(stop, line)

    Hook method executed just after a command dispatch is finished.
This method is a stub in Cmd; it exists to be overridden by subclasses.
line is the command line which was executed, and stop is a flag which
indicates whether execution will be terminated after the call to postcmd();
this will be the return value of the onecmd() method. The return value of
this method will be used as the new value for the internal flag which
corresponds to stop; returning false will cause interpretation to continue.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ok, so enough talking
&lt;/h2&gt;

&lt;p&gt;Since I prefer using Python over other languages I'm going to change the name of my &lt;code&gt;cmd&lt;/code&gt; class to MazeCrawler because snakes does not run, yeah? But still, it's little bit boring. I'm gonna go little bit further and rename it to (with regards to It's always sunny in Philadelphia) : &lt;a href="http://itsalwayssunny.wikia.com/wiki/Night_Crawlers"&gt;MazeKroller&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;cmd&lt;/span&gt;                                                                                                                                                                                                   

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MazeKroller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cmd&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;"""Interface for walking through the maze

    https://coding-challanges.herokuapp.com/challanges/maze
    """&lt;/span&gt;                                                                                                                                                  

    &lt;span class="n"&gt;intro&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Welcome to Maze shell. Type `?' or `help' to list commands.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'~ '&lt;/span&gt;  &lt;span class="c1"&gt;# Because it's a snake!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now we have only one method -- it is init. And we have to implement rest of the REST.&lt;br&gt;
We need to be able to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;create the maze&lt;/em&gt;,&lt;/li&gt;
&lt;li&gt;&lt;em&gt;navigate through it&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;and &lt;em&gt;pick up the coins&lt;/em&gt;
to win (actually to get out from the maze). Also a couple of methods should be implemented for usability: &lt;em&gt;get info&lt;/em&gt; and &lt;em&gt;give up&lt;/em&gt;.
Here is the stubs for it:
&lt;/li&gt;
&lt;/ul&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;MazeKroller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cmd&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;"""Interface for crawling through the maze

    https://coding-challanges.herokuapp.com/challanges/maze
    """&lt;/span&gt;
    &lt;span class="n"&gt;intro&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Welcome to Maze shell. Type `?' or `help' to list commands.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&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;do_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;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="s"&gt;"""Credentials for BasicHTTPAuth."""&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&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;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_create_maze&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;size&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="s"&gt;"""Create a new maze.
        Now you have 3600 seconds to escape.

        POST /api/mazes&lt;/span&gt;&lt;span class="se"&gt;\n&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;do_info&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;maze_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="s"&gt;"""Get some general data about your maze

        GET - /api/mazes/{id}&lt;/span&gt;&lt;span class="se"&gt;\n&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;do_get_cells&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;maze_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="s"&gt;"""See the cells around you.

        GET - /api/mazes/{id}/steps&lt;/span&gt;&lt;span class="se"&gt;\n&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;do_get_coin&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="s"&gt;"""Pick up a coin.

        POST - /api/mazes/{id}/coins&lt;/span&gt;&lt;span class="se"&gt;\n&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;do_giveup&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="s"&gt;"""Gives up the game.

        DELETE /api/mazes/{id}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"""&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So here we have a basic class for our MazeKroller.&lt;br&gt;
This class does nothing right now, but could be instantiated with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MazeKroller().cmdloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Play around little bit with it and in the next post I will provide you with implementation of that methods.&lt;/p&gt;

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

</description>
      <category>python</category>
      <category>challenge</category>
      <category>tribute</category>
      <category>interface</category>
    </item>
    <item>
      <title>Makefile with help message</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Fri, 29 Jun 2018 13:33:23 +0000</pubDate>
      <link>https://dev.to/alexbender/makefile-with-help-message-3d4h</link>
      <guid>https://dev.to/alexbender/makefile-with-help-message-3d4h</guid>
      <description>&lt;h1&gt;
  
  
  The Makefile
&lt;/h1&gt;

&lt;p&gt;The idea is pretty simple: Add comment to each target from Makefile&lt;br&gt;
Here is the &lt;code&gt;clean&lt;/code&gt; target from makefile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clean:
    rm -f *.o
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Help message here is redundant but in sake of completeness let's add it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clean: ## Clean directory
    rm -f *.o
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we need filter out all &lt;em&gt;docstrings&lt;/em&gt;: here is the command for that:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ag '^[a-zA-Z_-]+:.*?## .*$$' --nofilename Makefile \
| sort \
| awk 'BEGIN{FS=": ## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here I'm using &lt;code&gt;silver-searcher&lt;/code&gt; aka &lt;code&gt;ag&lt;/code&gt;.&lt;br&gt;
Seems complicated, yeah? So what does that command do?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;filters out lines basing on this regular expression: &lt;code&gt;'^[a-zA-Z_-]+:.*?## .*$$'&lt;/code&gt;, namely  any string like "target_name: ##doc string".&lt;/li&gt;
&lt;li&gt;sorts output with command &lt;code&gt;sort&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;formats output with &lt;code&gt;awk&lt;/code&gt; command &lt;code&gt;BEGIN{FS=": ## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's look at that command. What do we have?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BEGIN{FS=": ## "}&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}&lt;/p&gt;

&lt;p&gt;From the documentation: &lt;code&gt;A BEGIN rule is executed once only, before the first input record is read&lt;/code&gt;. So it simply reads input and sets the Field separator to ": ##" to split input on two parts: before and after the FS.&lt;/p&gt;

&lt;p&gt;Second part just prints filtered output with formatting and colors.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One more thing -- we have to define default target to be executed when &lt;code&gt;make&lt;/code&gt; command launched without arguments:&lt;br&gt;
&lt;code&gt;.DEFAULT_GOAL := help&lt;/code&gt;&lt;br&gt;
Now we are ready.&lt;/p&gt;

&lt;p&gt;Here is what we have as a result:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Save that gist into &lt;code&gt;Makefile&lt;/code&gt; and run &lt;code&gt;make&lt;/code&gt; command in your terminal from the folder with Makefile. If everything is ok you will get formatted and colored output: all targets defined in Makefile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ make
clean                          Clean directory
help                           Help target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;But aware that &lt;code&gt;awk&lt;/code&gt; and &lt;code&gt;silver-searcher&lt;/code&gt; are required for that snippet to work.&lt;br&gt;
(Btw, &lt;code&gt;ag&lt;/code&gt; could be replaced with &lt;code&gt;grep&lt;/code&gt;, if needed with some modifications I guess.)&lt;/p&gt;

&lt;p&gt;And remember -- documentation's important!&lt;/p&gt;

</description>
      <category>cli</category>
      <category>makefile</category>
    </item>
    <item>
      <title>Doubled welcome email</title>
      <dc:creator>Alex Bender</dc:creator>
      <pubDate>Fri, 29 Jun 2018 09:05:37 +0000</pubDate>
      <link>https://dev.to/alexbender/doubled-welcome-email-4bf7</link>
      <guid>https://dev.to/alexbender/doubled-welcome-email-4bf7</guid>
      <description>&lt;h1&gt;
  
  
  Problem description:
&lt;/h1&gt;

&lt;p&gt;I've changed my primary email address here and got the "Welcome to dev.to" email.&lt;br&gt;
Again.&lt;br&gt;
Because I'm already registered user.&lt;/p&gt;

&lt;h1&gt;
  
  
  Proposition
&lt;/h1&gt;

&lt;p&gt;Changing email should not trigger procedure of sending welcome email. Instead user should be notified about that change.&lt;/p&gt;

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