<?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: Rishi Baldawa</title>
    <description>The latest articles on DEV Community by Rishi Baldawa (@rishibaldawa).</description>
    <link>https://dev.to/rishibaldawa</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%2F67566%2F6a0a8264-84e0-4044-a8d9-e60a1f7e965e.jpg</url>
      <title>DEV Community: Rishi Baldawa</title>
      <link>https://dev.to/rishibaldawa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rishibaldawa"/>
    <language>en</language>
    <item>
      <title>Understanding Systems Through Tests</title>
      <dc:creator>Rishi Baldawa</dc:creator>
      <pubDate>Mon, 16 Apr 2018 05:00:00 +0000</pubDate>
      <link>https://dev.to/rishibaldawa/understanding-systems-through-tests-1k84</link>
      <guid>https://dev.to/rishibaldawa/understanding-systems-through-tests-1k84</guid>
      <description>&lt;p&gt;&lt;em&gt;I'm assuming the reader has  knowledge of differnt tests. If not, consider skimming through &lt;a href="https://www.hillelwayne.com/post/a-bunch-of-tests/"&gt;this blog post&lt;/a&gt; or wikipedia.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When I'm in a strange codebase&lt;sup id="fnref1"&gt;1&lt;/sup&gt; and short on time, I've taken shortcuts by going through all the tests first. If the tests are well organized, plentiful and easy to comprehend; I can swiftly understand the verified rules and restrictions of the system (or set of systems) and its neighbours. If they're sparse, messy or in dire need of help, I know my week got way more interesting. &lt;/p&gt;

&lt;h2&gt;
  
  
  Unit tests
&lt;/h2&gt;

&lt;p&gt;Reading unit tests should help you realize what the team thinks of as a single piece of unit. The input, output values help you guess what kind of data flows around. Mocks / Stubs should aid in figuring out how other components behave.  The test names should help you figure out the use-cases / edge-cases around the component. Tests around specific dimensions related edge-cases (like dates, country) tell you that the system, and any changes you make within it, needs to be respectful of them.&lt;/p&gt;

&lt;p&gt;Lack of tests or obvious gaps, implies the codebase has not been fully verified. You're in the wild wild west now, boy! &lt;/p&gt;

&lt;h2&gt;
  
  
  Integration Tests
&lt;/h2&gt;

&lt;p&gt;Integration tests help you figure out the boundaries of the system and services that we interact with. The input / output values help you understand the kind of data being shared between systems. Compared to unit tests, this should help you identify which data stays within the system and what gets passed around. &lt;/p&gt;

&lt;p&gt;If there's too many integration tests (esp over unit tests), expect the system to not care as much about latency (maybe even performance in general). It is possible that the system cares a lot more about availability or accurate interactions. If there's too many tests against a particular neighboring systems, I'd bet that service is flaky and, in past, developers have had bad experiences working with such systems. I would watchout for them as well.&lt;/p&gt;

&lt;p&gt;If there's too few tests, either the system doesn't have as many interactions or the integration with neighboring systems hasn't been painful yet.  It is generally a matter of time. Either the software get deprecated or someone adds the tests after a frustrating outage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Acceptance Tests
&lt;/h2&gt;

&lt;p&gt;Acceptance tests, when available, are a good way to understand the core functionality that the software supports. There's still a bit of code to business logic translation but is always an useful exercise. I don't focus too much on the inputs and outputs as these tests tend to have a bias towards the "happy path" use-cases. Any odd edge-case handling is probably present to counter the non-deterministic behaviour.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature Tests
&lt;/h2&gt;

&lt;p&gt;Generally what the non-programmers wished the code would do. If there's too many of these tests, a QA or Developer went to the town with BDD. Either way, it'll make an honest attempt to deliver the same value as an acceptance tests but with more humane language. &lt;/p&gt;

&lt;p&gt;From experience, there's very few accurate feature tests. Most express partial functionality or worse. The code executing the test spec could divulge more information but I've been burned few times in the past.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison Tests
&lt;/h2&gt;

&lt;p&gt;This tells me the code Extracts, Transforms and/or Loads critical datasets and the system needs to focus on accuracy. Also, as the cost of comparing the data is smaller than actually translating into POJOs, you may be dealing with a complicated structure or a very simple one; but nothing that sits in the middle. There may be compliance / regulations involved as well. One big takeaway would be that if you are adding new sources or  changing the output, ensuring that the tests are still accurate will be painful the first time. Probably a manual effort.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generative Tests
&lt;/h2&gt;

&lt;p&gt;These are so rare. When they are present, they help me get a quick grasp of the core assumptions and expectations of the system. The variants help me realize the terminologies / technologies the system deals with. If these are hard to understand then you're dealing with a complex system with many side-effects&lt;sup id="fnref2"&gt;2&lt;/sup&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fuzz Tests
&lt;/h2&gt;

&lt;p&gt;These tell me that the system is expected to take care of all error handling and should not crash. All apis need to be conscious of random inputs&lt;sup id="fnref3"&gt;3&lt;/sup&gt; and insecure behavior cannot tolerated. &lt;/p&gt;

&lt;h2&gt;
  
  
  Side Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If the tests are not part of the deployment chain or aren't carried out on a frequent basis, you can bet they are out-of-date. Don't bother with them and just move on. At the very least, tread with care.&lt;/li&gt;
&lt;li&gt;There's way more types of tests. Even the ones I described have sub-categories. I picked the ones I come across frequent enough to form opinions.&lt;/li&gt;
&lt;li&gt;This is partially written during a particularly busy period. I ended up taking many gaps and days to complete this. I apologize for any inaccuracies, in advance.&lt;/li&gt;
&lt;/ul&gt;







&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;I was leading a ranger team for more than 2 years so this happened a lot.  ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn2"&gt;
&lt;p&gt;Probably justifies the need for Invariant testing ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn3"&gt;
&lt;p&gt;Property-based testing helps me know the reduced subset of valid input values that can be passed in. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>testing</category>
      <category>programming</category>
    </item>
    <item>
      <title>Fixing Corrupt ZSH History</title>
      <dc:creator>Rishi Baldawa</dc:creator>
      <pubDate>Sat, 07 Apr 2018 05:00:00 +0000</pubDate>
      <link>https://dev.to/rishibaldawa/fixing-corrupt-zsh-history-4nf4</link>
      <guid>https://dev.to/rishibaldawa/fixing-corrupt-zsh-history-4nf4</guid>
      <description>&lt;p&gt;Today, when I logged into my console, I saw following error message&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;zsh: corrupt &lt;span class="nb"&gt;history &lt;/span&gt;file /home/rishi/.zsh_history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;doing a quick search, I was able to reach a &lt;a href="https://superuser.com/a/957924"&gt;stackoverflow link&lt;/a&gt;&lt;sup id="fnref1"&gt;1&lt;/sup&gt; that recommended I run following set of commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mv&lt;/span&gt; .zsh_history .zsh_history_bad
strings .zsh_history_bad &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .zsh_history
&lt;span class="nb"&gt;fc&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; .zsh_history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran them and everything was handy-dandy again. This did made me wonder what these commands do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rename
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mv&lt;/span&gt; .zsh_history .zsh_history_bad
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well &lt;code&gt;mv&lt;/code&gt; should be familiar to anyone who's toyed with linux. It moves files from one path to another. Also often used as a cheap was to rename files as we did here. More details on move in the &lt;a href="https://linux.die.net/man/1/mv"&gt;man page&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Sanitize
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;strings .zsh_history_bad &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .zsh_history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strings is interesting. I had not come upon it before. Based on the &lt;a href="https://linux.die.net/man/1/strings"&gt;man page&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;... strings prints the printable character sequences that are at least 4 characters long (or the number given with the options below) and are followed by an unprintable character...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It seems &lt;code&gt;strings&lt;/code&gt; is a nice way to actually get the printable characters in a file. In our case, this means if the &lt;code&gt;.zsh_history&lt;/code&gt; was corrupted due to non-printable characters&lt;sup id="fnref2"&gt;2&lt;/sup&gt;, this will help parse them out. It also means if you ran any commands with non-printable characters, you've now lost them from your history as well. I'm very unlikely to run printable characters, so this wasn't as big of an issue but this may make past commands for QAs and pen-testers a tad-annoying.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parse
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;fc&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; .zsh_history
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fc&lt;/code&gt; was interesting. It doesn't show up in the manpage. I ended up in a searching a fair amount to realize that this is a zsh-built in feature. There's some  information about it within &lt;a href="http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html"&gt;zsh documentation&lt;/a&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;...'fc -R’ reads the history from the given file&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It seems &lt;code&gt;fc&lt;/code&gt; will interact with your zsh_history. In this case, we are reading from the file and, since no second file was mentioned, putting it back into the same history file. i.e. re-writing history by parsing the same file. &lt;/p&gt;

&lt;h2&gt;
  
  
  Cleanup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; .zsh_history_bad 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This wasn't part of the original script but you should always clean-up after yourself. This command deletes the tmp "bad" file that you created in the first step. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If I power shutdown my VM / linux box while zsh is still writing content, I can still corrupt the zsh_history. As long as I don't care about any other non-printable characters in the past and open to keep using zsh, I can run the above commands to get back to a happier stage&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;Technically not stackoverflow but I hope you know what I mean. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn2"&gt;
&lt;p&gt;Probably because I did a power shutdown while carrying out a load test on a tiny VM. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>linux</category>
      <category>zsh</category>
    </item>
    <item>
      <title>Virtual Environments in Python</title>
      <dc:creator>Rishi Baldawa</dc:creator>
      <pubDate>Sun, 07 Jan 2018 06:00:00 +0000</pubDate>
      <link>https://dev.to/rishibaldawa/virtual-environments-in-python-194c</link>
      <guid>https://dev.to/rishibaldawa/virtual-environments-in-python-194c</guid>
      <description>&lt;p&gt;I’ve been struggling a lot with understanding how to package python scripts &amp;amp; libraries. Some of the tool I use heavily rely on older version of the language. Some even rely on specific version of the older libraries. Working daily at a Java shop, this isn’t all that surprising. The bit that really caught me off-guard was how to make it all work when there’s different libraries to work with. e.g. some libraries require &lt;a href="https://www.python.org/download/releases/2.7/"&gt;Python 2.7&lt;/a&gt; while one of my other projects requires &lt;a href="https://www.python.org/download/releases/3.4.0/"&gt;Python 3.4 or above&lt;/a&gt;. It seems the solution is to use &lt;a href="https://virtualenv.pypa.io/en/latest/#"&gt;VirtualEnv&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;VirtualEnv allows you to isolate different packages &amp;amp; even python versions. You need to manually activate / deactivate a virtualenv but once you are in one of these, each virtualenv can have its own copy of the Python and dependencies in the site-packages directory. This allows you to create multiple environments within the same devlopment box / laptop. Typically, you create one virtual env for each workspace / project but you can just as create multiple envs for the same project to see how your library works in different situations. It’s a pretty sweet deal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To set it all up, follow&lt;a href="https://virtualenv.pypa.io/en/latest/installation/"&gt;the installation guide&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;sudo pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create an new virtualenv you basically go to your project &amp;amp; activate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd my_project_root_folder
virtualenv -p /usr/bin/python2.7 my_project
# now you activate
source my_project/bin/activate
# now do your dirty work like...
pip install -r requirements.txt
# when yo done, deactivate
deactivate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  More Resources
&lt;/h2&gt;

&lt;p&gt;Some links that really help me understand how packaging works in python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.fullstackpython.com/application-dependencies.html"&gt;Application Dependencies&lt;/a&gt; - overview of python dependencies&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://veekaybee.github.io/2017/09/26/python-packaging/"&gt;Alice in Python projectland&lt;/a&gt; - takes you through how packaging works at a very simplified level from a simple script to a fully fleged application / library&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/kennethreitz/setup.py"&gt;setup.py for Humans&lt;/a&gt; - sample project explain the different values within setup.py &amp;amp; the moar relevant resources&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://caremad.io/posts/2013/07/setup-vs-requirement/"&gt;setup.py vs requirements.txt&lt;/a&gt; - differentiates between setup.py &amp;amp; requirements.txt and explains why both are required.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/"&gt;Hitchiker’s Guide To VirtualEnv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Misc links I found on the way&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/PurpleBooth/109311bb0361f32d87a2"&gt;A template to make good README.md&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Note
&lt;/h2&gt;

&lt;p&gt;You have to always manually activate / deactivate your virutalenv. This makes you prone to human errors if you are not paying attention. There’s tool to automate this step as well but I’ve found them to not work as well (so far…)&lt;/p&gt;

&lt;p&gt;Another issue I’ve faced so far is inability to isolate dependencies into their own shell. Something along the lines of &lt;a href="https://github.com/shevek/jarjar"&gt;JarJar&lt;/a&gt;. I’m not convinced this is a bad thing but it’s still a minor annoyance I need to work around with (by creating a project / microserver).&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
