<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>@sikac.hu</title>
 <link href="/atom.xml" rel="self"/>
 <link href="https://sikac.hu/"/>
 <updated>2026-10-25T16:23:17+00:00</updated>
 <id>https://sikac.hu</id>
 <author>
   <name>Prem Sichanugrist</name>
 </author>

 
 <entry>
   <title>A faster way to exit a Pry session</title>
   <link href="https://sikac.hu/exit-pry-session-with-bang-bang-bang"/>
   <updated>2018-06-01T14:01:01+00:00</updated>
   <id>https://sikac.hu/exit-pry-session-with-bang-bang-bang</id>
   <content type="html">&lt;p&gt;If you are using Pry in your project,
you might run into a situation where you are in a loop or
have multiple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;binding.pry&lt;/code&gt; calls
so you have to use exit multiple times to get out of it.&lt;/p&gt;

&lt;p&gt;So, instead of using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit&lt;/code&gt; multiple times,
you can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit-program&lt;/code&gt; to continue the execution
without breaking into Pry again.&lt;/p&gt;

&lt;p&gt;There is also a handy shortcut for this, which is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!!!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can read more about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exit-program&lt;/code&gt;
and other ways to navigate around in your Pry session
in &lt;a href=&quot;https://github.com/pry/pry/wiki/State-navigation#exit-the-program-completely&quot;&gt;Pry’s wiki page&lt;/a&gt;.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Poison Object: An Antidote for Your Nil</title>
   <link href="https://sikac.hu/poison-object"/>
   <updated>2015-11-10T14:09:15+00:00</updated>
   <id>https://sikac.hu/poison-object</id>
   <content type="html">&lt;p&gt;I recently submitted a &lt;a href=&quot;https://github.com/rails/rails/pull/20883&quot;&gt;pull request&lt;/a&gt; to Ruby on Rails
to make force reloading an association more explicit.
I then came across this &lt;a href=&quot;https://github.com/rails/rails/pull/20883#discussion_r34624606&quot;&gt;suggestion&lt;/a&gt; from &lt;a href=&quot;https://github.com/sgrif&quot;&gt;Sage Griffin&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Rather than using &lt;em&gt;nil&lt;/em&gt; here, can we be a little bit more explicit?
A user could have theoretically been passing &lt;em&gt;nil&lt;/em&gt; here,
since we were just relying on truthy/falsy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code that they commented on looked like this
(notice the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;force_reload = nil&lt;/code&gt; default):&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;reload: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Override `reload` if user passed in `force_reload`&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;nil?&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reload&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Executing code to reload the association&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;They proposed that instead of using &lt;em&gt;nil&lt;/em&gt; as a default value,
I should create a &lt;em&gt;poison object&lt;/em&gt; instead.
My code now looked like this:&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;no&quot;&gt;NO_FORCE_RELOAD_ARGUMENT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;new&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;reader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;NO_FORCE_RELOAD_ARGUMENT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;reload: &lt;/span&gt;&lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;NO_FORCE_RELOAD_ARGUMENT&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;reload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;force_reload&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reload&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Executing code to reload the association&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This way, if a user passes in &lt;em&gt;nil&lt;/em&gt; as an argument,
the code will properly set the &lt;em&gt;reload&lt;/em&gt; argument to &lt;em&gt;nil&lt;/em&gt;
instead of leaving it at the keyword argument’s value.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Next time you use &lt;em&gt;nil&lt;/em&gt; as a default argument,
don’t forget to ask yourself a question:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Do I actually want to check whether the user passed in an argument?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you do, consider using a poison object like the example above.
It will make your code much clearer.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>How to keep sensitive commands out of .zsh_history</title>
   <link href="https://sikac.hu/how-to-keep-sensitive-commands-out-of-zsh-history"/>
   <updated>2015-11-09T01:49:01+00:00</updated>
   <id>https://sikac.hu/how-to-keep-sensitive-commands-out-of-zsh-history</id>
   <content type="html">&lt;p&gt;By default,
if you enable command history in Zsh,
all commands including those that contain sensitive information
such as an access token or a password
will be saved into your command history file after you run them.&lt;/p&gt;

&lt;p&gt;It’s definitely a bad idea to have that information
wound up in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.zsh_history&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;However,
there is a way you can tell Zsh to not putting a command in your history file
by setting this option in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.zshrc&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-zsh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;setopt HIST_IGNORE_SPACE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After that,
Zsh will not store any command that starts with a space in a history file.&lt;/p&gt;

&lt;p&gt;So, instead of running this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ curl -u &quot;LOLNOPE:x-oauth-basic&quot; -i https://api.github.com/...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;add an empty space before your command like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$  curl -u &quot;LOLNOPE:x-oauth-basic&quot; -i https://api.github.com/...
  ^--------- notice an empty space here
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that this most recent command &lt;em&gt;will&lt;/em&gt; temporarily stay in the command history
in your current session
so you can go back to reuse or edit it by using the UP arrow,
and it will automatically disappear
after you run another command in the same session.&lt;/p&gt;

&lt;p&gt;You can read more about this in &lt;a href=&quot;https://zsh.sourceforge.io/Doc/Release/Options.html&quot;&gt;Zsh documentation&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 

</feed>
