<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Tenzin Chemi]]></title><description><![CDATA[Software writer out of curiosity.  322D 9687 C273 50CE 5F39  7A03 0D27 F9C6 BDAF B6D3]]></description><link>https://tenzinchemi.in</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 18:15:33 GMT</lastBuildDate><atom:link href="https://tenzinchemi.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Gotcha: Request spec]]></title><description><![CDATA[You may have faced this issue where { key: false } was treated as { “key”: “false” } when writing request specs in rails application development.
Request params need to be passed as json along with content-type header in order for the Rails API to ca...]]></description><link>https://tenzinchemi.in/gotcha-request-spec</link><guid isPermaLink="true">https://tenzinchemi.in/gotcha-request-spec</guid><category><![CDATA[Ruby]]></category><category><![CDATA[#rspec]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 17 Dec 2025 11:55:13 GMT</pubDate><content:encoded><![CDATA[<p>You may have faced this issue where <code>{ key: false }</code> was treated as <code>{ “key”: “false” }</code> when writing request specs in rails application development.</p>
<p>Request params need to be passed as json along with content-type header in order for the Rails API to cast the types properly. The <code>to_json</code> converts the ruby hash to a json string and then the <code>headers</code> help Rails parse the request body.</p>
<pre><code class="lang-ruby">put <span class="hljs-string">'/api/v1/crm/update_sync_settings'</span>, 
    <span class="hljs-symbol">params:</span> request_param.to_json, 
    <span class="hljs-symbol">headers:</span> {<span class="hljs-string">'Content-Type'</span> =&gt; <span class="hljs-string">'application/json'</span>}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Ruby |= pipe assignment operator]]></title><description><![CDATA[irb(main):021> arr = [3]
=> [3]
irb(main):022> arr |= [3]
=> [3]
irb(main):023> arr |= [3, 2]
=> [3, 2]
irb(main):024> arr |= [3, 2]
=> [3, 2]]]></description><link>https://tenzinchemi.in/ruby-pipe-assignment-operator</link><guid isPermaLink="true">https://tenzinchemi.in/ruby-pipe-assignment-operator</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Thu, 11 Dec 2025 07:10:52 GMT</pubDate><content:encoded><![CDATA[<pre><code class="lang-ruby">irb(main)<span class="hljs-symbol">:</span><span class="hljs-number">021</span>&gt; arr = [<span class="hljs-number">3</span>]
=&gt; [<span class="hljs-number">3</span>]
irb(main)<span class="hljs-symbol">:</span><span class="hljs-number">022</span>&gt; arr <span class="hljs-params">|= [3]
=&gt; [3]
irb(main):023&gt; arr |</span>= [<span class="hljs-number">3</span>, <span class="hljs-number">2</span>]
=&gt; [<span class="hljs-number">3</span>, <span class="hljs-number">2</span>]
irb(main)<span class="hljs-symbol">:</span><span class="hljs-number">024</span>&gt; arr <span class="hljs-params">|= [3, 2]
=&gt; [3, 2]</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Remove Nested module constant in ruby]]></title><description><![CDATA[You might have seen this solution.
Object.send(:remove_const, :ExampleClass)

But what if you want to remove namespaced classes in Ruby. You can use the same method, but instead of Object use the parent module where your class is nested.
module App
 ...]]></description><link>https://tenzinchemi.in/remove-nested-module-constant-in-ruby</link><guid isPermaLink="true">https://tenzinchemi.in/remove-nested-module-constant-in-ruby</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 18 Oct 2023 16:58:34 GMT</pubDate><content:encoded><![CDATA[<p>You might have seen this solution.</p>
<pre><code class="lang-ruby">Object.send(<span class="hljs-symbol">:remove_const</span>, <span class="hljs-symbol">:ExampleClass</span>)
</code></pre>
<p>But what if you want to remove namespaced classes in Ruby. You can use the same method, but instead of <code>Object</code> use the parent module where your class is nested.</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">App</span></span>
  <span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">ExampleClass</span></span>
  <span class="hljs-keyword">end</span> 
<span class="hljs-keyword">end</span> 

Object.send(<span class="hljs-symbol">:remove_const</span>, <span class="hljs-symbol">:App</span><span class="hljs-symbol">:</span><span class="hljs-symbol">:ExampleClass</span>) <span class="hljs-comment">### ❌ Does not work!!!!</span>

App.send(<span class="hljs-symbol">:remove_const</span>, <span class="hljs-symbol">:ExampleClass</span>) <span class="hljs-comment"># ✅ This works</span>
</code></pre>
<p>Now before removing the const, you can check if the constant is defined or not.</p>
<pre><code class="lang-ruby"><span class="hljs-keyword">if</span> App.const_defined?(<span class="hljs-symbol">:ExampleClass</span>)
  App.send(<span class="hljs-symbol">:remove_const</span>, <span class="hljs-symbol">:ExampleClass</span>)
<span class="hljs-keyword">end</span>
</code></pre>
<p>Perfect! 🍄</p>
]]></content:encoded></item><item><title><![CDATA[Polygon's interior and exterior angle]]></title><description><![CDATA[A polygon always has an exterior angle sum to 360 no matter the number of sides or their width.
A triangle has an exterior angle sum equal to 360
A square has an exterior angle sum equal to 360
A pentagon has an exterior angle sum equal to 360
Quadri...]]></description><link>https://tenzinchemi.in/polygons-interior-and-exterior-angle</link><guid isPermaLink="true">https://tenzinchemi.in/polygons-interior-and-exterior-angle</guid><category><![CDATA[Mathematics]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Fri, 22 Sep 2023 03:34:26 GMT</pubDate><content:encoded><![CDATA[<p>A polygon always has an exterior angle sum to 360 no matter the number of sides or their width.</p>
<p>A triangle has an exterior angle sum equal to 360</p>
<p>A square has an exterior angle sum equal to 360</p>
<p>A pentagon has an exterior angle sum equal to 360</p>
<p>Quadrilaterals have exterior angle sum equal to 360</p>
<p>There's a pattern.</p>
<p>All of the above shapes are polygons, and polygons could have n-sides or n-angles.</p>
<p>To find the sum of interior angles for these polygons, we just subtract the exterior angle sum from the interior</p>
<pre><code class="lang-plaintext">a + b + ... aN = N * 180 - 360 

where a, b .. N are interior angles. 
N is number of angles in the polygon.
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Parabolas wrapped in equation]]></title><description><![CDATA[y = a(x-h)^2 + k 

If there's a parabola. You can find and tweak it with these parameters
'a' defines whether parabola is facing upward of downward
'h' defines horizontal position of the vertex of parabola. 
'k' defines the narrowness of parabola. 

...]]></description><link>https://tenzinchemi.in/parabolas-wrapped-in-equation</link><guid isPermaLink="true">https://tenzinchemi.in/parabolas-wrapped-in-equation</guid><category><![CDATA[Mathematics]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 20 Sep 2023 02:56:49 GMT</pubDate><content:encoded><![CDATA[<pre><code class="lang-plaintext">y = a(x-h)^2 + k 

If there's a parabola. You can find and tweak it with these parameters
'a' defines whether parabola is facing upward of downward
'h' defines horizontal position of the vertex of parabola. 
'k' defines the narrowness of parabola. 


A vertex of a parabola is the maximum or the minimum of the parabola.
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Lines that go up and down]]></title><description><![CDATA[Do you agree that lines can go upward / direction or downward \ ? What's the direction of the following line?

Yes, upward. This line is represented by y = x .




xy



-1-1

00

11

22


Now, let's see a line going downward.

This is represented by...]]></description><link>https://tenzinchemi.in/lines-that-go-up-and-down</link><guid isPermaLink="true">https://tenzinchemi.in/lines-that-go-up-and-down</guid><category><![CDATA[Mathematics]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Sun, 17 Sep 2023 04:41:53 GMT</pubDate><content:encoded><![CDATA[<p>Do you agree that lines can go upward <code>/</code> direction or downward <code>\</code> ? What's the direction of the following line?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694923832154/aea03c4a-ae00-442c-9173-1542ef801538.png" alt class="image--center mx-auto" /></p>
<p>Yes, upward. This line is represented by <code>y = x</code> .</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>x</td><td>y</td></tr>
</thead>
<tbody>
<tr>
<td>-1</td><td>-1</td></tr>
<tr>
<td>0</td><td>0</td></tr>
<tr>
<td>1</td><td>1</td></tr>
<tr>
<td>2</td><td>2</td></tr>
</tbody>
</table>
</div><p>Now, let's see a line going downward.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694924117909/fab41451-8582-45cd-877a-5a60f09c5f7a.png" alt class="image--center mx-auto" /></p>
<p>This is represented by <code>y = -x</code></p>
<p>Do you see the difference between the equations representing lines going upward and downward? If yes, what is it?</p>
<p>Let me tell you.</p>
<p>The first equation representing the line going upward has a positive <code>+x</code> equation on the right-hand side.</p>
<p>The second equation representing the line going downward has a negative <code>-x</code> equation on the right-hand side.</p>
<p>Let's try to understand a little bit more about them</p>
<p>Whenever we write <code>y = (something) times (x)</code> , that <code>something</code> is the slope of the line. So we could rewrite <code>y = x</code> as</p>
<pre><code class="lang-plaintext">y = (1) times (x)
</code></pre>
<p>The slop of the equation here is 1 which indicates that when <code>x</code> increases by 1, our <code>y</code> value also increases by 1.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694924821357/a19940b7-b1fd-418f-981d-47c1e31970bc.png" alt class="image--center mx-auto" /></p>
<p>Similarly, for <code>y = -x</code> , we can rewrite as</p>
<pre><code class="lang-plaintext">y = (-1) times (x)
</code></pre>
<p>The slope of the equation is -1 which indicates that when x increases by 1, y decreases by 1.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1694924770894/012d8f84-4dcf-420e-9a65-397df35b5b7f.png" alt class="image--center mx-auto" /></p>
<p>These equations can be represented by some symbols through which we can talk and discuss more easily. So, we can say the above equations are represented by</p>
<pre><code class="lang-plaintext">y = (m) times (x)
</code></pre>
<p>Here, <code>m</code> is the slope of the equation which equals to <code>+1</code> or <code>-1</code> in our equations. So in short, we can say <code>y = mx</code> represents a line on the graph that might be going upward or downward depending on the value of <code>m</code> - the slope.</p>
<p>So next time you see an equation like this</p>
<pre><code class="lang-plaintext">y = -7x
</code></pre>
<p>You can say, oh the slope is <code>-7</code> which means for every increase of <code>x</code> , <code>y</code> decreases by 7 times.</p>
<p>Or when you see an positive equation like this</p>
<pre><code class="lang-plaintext">y = 13x
</code></pre>
<p>You can say, the slope is <code>+13</code> , and this means when <code>x</code> increases by 1, <code>y</code> also increases by <code>13</code> times that of x.</p>
<p>These lines we have discussed are very simple linear lines that go through the origin <code>(0, 0)</code> . Both the lines intercept <code>y</code>-axis at 0.</p>
<p>Why these equations are important to recognize and knowing how to plot them could reveal insightful data when applied to our real-life problems related to growth, budgeting and obviously other phenomena in the universe.</p>
<p>Next, we will talk about <code>y</code> intercepts.</p>
]]></content:encoded></item><item><title><![CDATA[Ruby: What is class instance variable]]></title><description><![CDATA[Class instance variables are variables that have punctual prefix @ and are used inside class definition.
class Shape 
  @count = 6

  def instance_method_x
    puts "No: '#{@count}'"
  end 

  class << self 
    def class_method_x
      puts "No: '#{...]]></description><link>https://tenzinchemi.in/ruby-what-is-class-instance-variable</link><guid isPermaLink="true">https://tenzinchemi.in/ruby-what-is-class-instance-variable</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Tue, 29 Aug 2023 19:02:23 GMT</pubDate><content:encoded><![CDATA[<p>Class instance variables are variables that have punctual prefix <code>@</code> and are used inside class definition.</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span> </span>
  @count = <span class="hljs-number">6</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">instance_method_x</span></span>
    puts <span class="hljs-string">"No: '<span class="hljs-subst">#{@count}</span>'"</span>
  <span class="hljs-keyword">end</span> 

  <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;&lt; self </span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">class_method_x</span></span>
      puts <span class="hljs-string">"No: '<span class="hljs-subst">#{@count}</span>'"</span>
    <span class="hljs-keyword">end</span> 
  <span class="hljs-keyword">end</span> 
<span class="hljs-keyword">end</span>
</code></pre>
<p>They are not visible to instance methods</p>
<pre><code class="lang-ruby">Shape.new.instance_method_x <span class="hljs-comment">#=&gt; No: ''</span>
</code></pre>
<p>They are visible to class methods</p>
<pre><code class="lang-ruby">Shape.class_method_x <span class="hljs-comment">#=&gt; No: '6'</span>
</code></pre>
<p>You can expose class instance variable via <code>attr_reader</code></p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span></span>
  @count = <span class="hljs-number">6</span>

  <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;&lt; self </span>
    <span class="hljs-keyword">attr_reader</span> <span class="hljs-symbol">:count</span> 
  <span class="hljs-keyword">end</span> 
<span class="hljs-keyword">end</span> 

<span class="hljs-comment"># With that, you can access </span>
$&gt; Shape.count 
<span class="hljs-comment">#=&gt; 6</span>
</code></pre>
<p>Other points:</p>
<ul>
<li><p>They can be replaced by <code>@@</code> class variables.</p>
</li>
<li><p>They can be confusing with ordinary instance variables. Without the punctuation <code>@@</code> or <code>@</code>, it can be difficult to understand whether the variable is associated with class or instance.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Ruby: What is a class variable?]]></title><description><![CDATA[Class variable
Class variables are variables prefixed by @@ .
class Shape 
  @@no_of_shapes = 6

  def instance_method_x
    puts "No: #{@@no_of_shapes}"
  end 

  class << self 
    def class_method_x
      puts "No: #{@@no_of_shapes}"
    end 
  en...]]></description><link>https://tenzinchemi.in/ruby-what-is-a-class-variable</link><guid isPermaLink="true">https://tenzinchemi.in/ruby-what-is-a-class-variable</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Tue, 29 Aug 2023 18:46:16 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-class-variable">Class variable</h2>
<p>Class variables are variables prefixed by <code>@@</code> .</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span> </span>
  @@no_of_shapes = <span class="hljs-number">6</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">instance_method_x</span></span>
    puts <span class="hljs-string">"No: <span class="hljs-subst">#{@@no_of_shapes}</span>"</span>
  <span class="hljs-keyword">end</span> 

  <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;&lt; self </span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">class_method_x</span></span>
      puts <span class="hljs-string">"No: <span class="hljs-subst">#{@@no_of_shapes}</span>"</span>
    <span class="hljs-keyword">end</span> 
  <span class="hljs-keyword">end</span> 
<span class="hljs-keyword">end</span>
</code></pre>
<p>They are visible to class methods.</p>
<pre><code class="lang-ruby">Shape.class_method_x <span class="hljs-comment"># =&gt; No: 6</span>
</code></pre>
<p>They are visible to instance methods.</p>
<pre><code class="lang-ruby">Shape.new.instance_method_x <span class="hljs-comment"># =&gt; No: 6</span>
</code></pre>
<p>They cannot be accessed by instance of class.</p>
<pre><code class="lang-ruby">shape = Shape.new 
puts shape.no_of_shapes 
<span class="hljs-comment">#=&gt; class_var.rb:5:in `&lt;main&gt;': undefined method `no_of_shapes' for #&lt;Shape:0x000000011e968498&gt; (NoMethodError)</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Clear memoized value during request specs]]></title><description><![CDATA[There might be times when your @current_user instance variable gets re-used between multiple requests in your rspecs. This might result in strange test behaviours resulting in test failings. Just clear the cache completely.
Rails.cache.clear]]></description><link>https://tenzinchemi.in/clear-memoized-value-during-request-specs</link><guid isPermaLink="true">https://tenzinchemi.in/clear-memoized-value-during-request-specs</guid><category><![CDATA[Ruby on Rails]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Fri, 18 Aug 2023 05:54:20 GMT</pubDate><content:encoded><![CDATA[<p>There might be times when your <code>@current_user</code> instance variable gets re-used between multiple requests in your rspecs. This might result in strange test behaviours resulting in test failings. Just clear the cache completely.</p>
<pre><code class="lang-ruby">Rails.cache.clear
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Ruby tip 0001: Initialize hash from string or array]]></title><description><![CDATA[Problem:
Convert 'ABCD' to {"A"=>0, "B"=>0, "C"=>0, "D"=>0}

Using inject
 'ABCD'.chars.inject({}) { |memo, v| memo[v] = 0; memo  }


Using Hash
 Hash['ABCD'.chars.map { |v| [v, 0] }]]]></description><link>https://tenzinchemi.in/ruby-tip-0001-initialize-hash-from-string-or-array</link><guid isPermaLink="true">https://tenzinchemi.in/ruby-tip-0001-initialize-hash-from-string-or-array</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 09 Aug 2023 06:31:37 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-problem">Problem:</h2>
<p>Convert 'ABCD' to <code>{"A"=&gt;0, "B"=&gt;0, "C"=&gt;0, "D"=&gt;0}</code></p>
<ol>
<li><p>Using <code>inject</code></p>
<pre><code class="lang-ruby"> <span class="hljs-string">'ABCD'</span>.chars.inject({}) { <span class="hljs-params">|memo, v|</span> memo[v] = <span class="hljs-number">0</span>; memo  }
</code></pre>
</li>
<li><p>Using <code>Hash</code></p>
<pre><code class="lang-ruby"> Hash[<span class="hljs-string">'ABCD'</span>.chars.map { <span class="hljs-params">|v|</span> [v, <span class="hljs-number">0</span>] }]
</code></pre>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Include, extend, and then get fancy.]]></title><description><![CDATA[include: makes instance methods from module as instance methods
When you include a module inside class. 

All the instance method from the module becomes instance method for the instances of that class. 
All singleton or class methods from the module...]]></description><link>https://tenzinchemi.in/include-extend-and-then-get-fancy</link><guid isPermaLink="true">https://tenzinchemi.in/include-extend-and-then-get-fancy</guid><category><![CDATA[Ruby]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Fri, 04 Nov 2022 07:38:34 GMT</pubDate><content:encoded><![CDATA[<p><code>include</code>: makes instance methods from module as instance methods</p>
<p>When you include a module inside class. </p>
<ul>
<li>All the instance method from the module becomes instance method for the instances of that class. </li>
<li>All singleton or class methods from the module are not accessible from either instance or class. We will discuss soon.</li>
</ul>
<p><code>extend</code>: makes instance methods from module as class methods</p>
<p>When you extend a module inside class</p>
<ul>
<li>All the instance method from the module becomes singleton method of that class. </li>
<li>All the singleton method from the module becomes are not accessible from either instance of class. We will discuss. </li>
</ul>
<p>Let learn by example. </p>
<p>What happens when we include module <code>A</code> containing both instance method and class method inside class <code>Test</code></p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">A</span> </span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span></span>
    puts <span class="hljs-string">'foo'</span>
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">self</span>.<span class="hljs-title">bar</span> </span>
    puts <span class="hljs-string">'bar'</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>
  <span class="hljs-keyword">include</span> A 
<span class="hljs-keyword">end</span>

Test.new.foo 
<span class="hljs-comment">#=&gt; foo</span>
Test.foo  
<span class="hljs-comment">#=&gt; undefined method `foo' for Test:Class (NoMethodError)</span>
Test.new.bar 
<span class="hljs-comment">#=&gt; undefined method `bar' for #&lt;Test:0x000000012984f330&gt; (NoMethodError)</span>
Test.bar
<span class="hljs-comment">#=&gt; undefined method `bar' for Test:Class (NoMethodError)</span>
</code></pre>
<p>What happens when we extend module <code>A</code> inside class <code>Test</code></p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">A</span> </span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span></span>
    puts <span class="hljs-string">'foo'</span>
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">self</span>.<span class="hljs-title">bar</span> </span>
    puts <span class="hljs-string">'bar'</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>
  extend A 
<span class="hljs-keyword">end</span>

Test.new.foo 
<span class="hljs-comment">#=&gt; undefined method `foo' for #&lt;Test:0x000000014a106eb8&gt; (NoMethodError)</span>
Test.foo  
<span class="hljs-comment">#=&gt; foo</span>
Test.new.bar 
<span class="hljs-comment">#=&gt; undefined method `bar' for #&lt;Test:0x000000014791b228&gt; (NoMethodError)</span>
Test.bar
<span class="hljs-comment">#=&gt; undefined method `bar' for Test:Class (NoMethodError)</span>
</code></pre>
<p>What if we want to include a module having both instance and class level methods, and include both instance and class level methods. We can do it this way. Explanation after the example.</p>
<pre><code class="lang-ruby"><span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">A</span> </span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span></span>
    puts <span class="hljs-string">'foo'</span>
  <span class="hljs-keyword">end</span>

  <span class="hljs-comment"># Define all your singleton or class level methods here. Notice that we are not using `self` </span>
  <span class="hljs-comment"># reference here.</span>
  <span class="hljs-class"><span class="hljs-keyword">module</span> <span class="hljs-title">ClassMethods</span></span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bar</span> </span>
      puts <span class="hljs-string">'bar'</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>

  <span class="hljs-comment"># This is a hook which will run when the module is included by another module. `base` is </span>
  <span class="hljs-comment"># the class that included the module. Then we just `extend` all methods inside module </span>
  <span class="hljs-comment"># `ClassMethods` so that those methods become singleton inside the base class.</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">self</span>.<span class="hljs-title">included</span><span class="hljs-params">(base)</span></span>
    base.extend ClassMethods
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test</span> </span>
  <span class="hljs-keyword">include</span> A 
<span class="hljs-keyword">end</span>

Test.new.foo
<span class="hljs-comment">#=&gt; foo </span>
Test.bar
<span class="hljs-comment">#=&gt; bar</span>
Test.new.bar
<span class="hljs-comment">#=&gt; undefined method `bar' for #&lt;Test:0x0000000129186eb8&gt; (NoMethodError)</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[What is Kubernetes for me]]></title><description><![CDATA[Docker is the way to ship your application files in a binary package called image.
The image is used by a container.
A container has a process and is being instantiated by container orchestrators. 
Kubernetes, Mesos, Rkt, Docker Engine are all contai...]]></description><link>https://tenzinchemi.in/what-is-kubernetes-for-me</link><guid isPermaLink="true">https://tenzinchemi.in/what-is-kubernetes-for-me</guid><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Sun, 15 Dec 2019 05:47:31 GMT</pubDate><content:encoded><![CDATA[<p>Docker is the way to ship your application files in a binary package called image.</p>
<p>The image is used by a container.</p>
<p>A container has a process and is being instantiated by container orchestrators. </p>
<p>Kubernetes, Mesos, Rkt, Docker Engine are all container orchestrator engines.</p>
<p>Kubernetes engine does a lot of things for distributed, large scale deployment with containers. It can be deployed by anyone anywhere. Why? because it&#39;s open-sourced. It requires virtual machines to set up its own infrastructure. A most common architecture is a single master server and two worker nodes. </p>
<p>Some of the vendors that provide Kubernetes service are:</p>
<ul>
<li>Google provides GKS.</li>
<li>AWS provides EKS.</li>
<li>Azure provides AKS.</li>
<li>Digital Ocean Kubernetes</li>
</ul>
<p>You and your company can have your own on-premise Kubernetes cluster and manage it by yourself. </p>
]]></content:encoded></item><item><title><![CDATA[Create multiple database using Bitnami/MongoDB docker-entrypoint-initdb.d]]></title><description><![CDATA[⚠️ This is merely to ease away pain for testing and local development. Please avoid using this for production.
3. Create a directory
with following files. Each step shows what's in those files. 
├── docker-compose.yml
├── Dockerfile.Mongo.Local
├── d...]]></description><link>https://tenzinchemi.in/create-multiple-database-using-bitnamimongodb-docker-entrypoint-initdbd</link><guid isPermaLink="true">https://tenzinchemi.in/create-multiple-database-using-bitnamimongodb-docker-entrypoint-initdbd</guid><category><![CDATA[MongoDB]]></category><category><![CDATA[Docker]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 20 Nov 2019 18:46:54 GMT</pubDate><content:encoded><![CDATA[<p>⚠️ This is merely to ease away pain for testing and local development. Please <strong>avoid using this for production</strong>.</p>
<h3 id="3-create-a-directory">3. Create a directory</h3>
<p>with following files. Each step shows what&#39;s in those files. </p>
<pre><code>├── <span class="hljs-selector-tag">docker-compose</span><span class="hljs-selector-class">.yml</span>
├── <span class="hljs-selector-tag">Dockerfile</span><span class="hljs-selector-class">.Mongo</span><span class="hljs-selector-class">.Local</span>
├── <span class="hljs-selector-tag">db_init</span>
 │   └── <span class="hljs-selector-tag">create_databases</span><span class="hljs-selector-class">.sh</span>
</code></pre><h3 id="2-create-your-local-version-of-bitnami-mongodb-image">2. Create your local version of bitnami/mongodb image</h3>
<pre><code><span class="hljs-comment"># File name: Dockerfile.Mongo.Local</span>
<span class="hljs-attribute">FROM</span> bitnami/mongodb:<span class="hljs-number">4</span>.<span class="hljs-number">0</span>

USER root
RUN chmod <span class="hljs-number">755</span> libmongodb.sh
</code></pre><h3 id="3-your-docker-compose-yaml">3. Your docker compose yaml</h3>
<pre><code>version: <span class="hljs-string">"3"</span>
services:
  mongo-db:
    # image: <span class="hljs-string">'bitnami/mongodb:latest'</span>
    build:
      context: .
      dockerfile: Dockerfile.Mongo.Local
    ports:
      - <span class="hljs-string">"27017:27017"</span>
    volumes:
      - ./db_init:/docker-entrypoint-initdb.d
    environment:
      MONGODB_ROOT_PASSWORD: admin
</code></pre><h3 id="4-prepare-bash-script">4. Prepare bash script</h3>
<p>for creating multiple databases</p>
<pre><code><span class="hljs-comment"># create_databases.sh</span>
/libmongodb.sh

mongodb_execute <span class="hljs-string">'root'</span> <span class="hljs-string">"$MONGODB_ROOT_PASSWORD"</span> <span class="hljs-string">""</span> <span class="hljs-string">"127.0.0.1"</span> &lt;&lt;EOF
  <span class="hljs-keyword">use</span> schooldb
  db.getSiblingDB(<span class="hljs-string">'schooldb'</span>).createCollection(<span class="hljs-string">'students'</span>)
  <span class="hljs-keyword">use</span> accountdb
  db.getSiblingDB(<span class="hljs-string">'accountdb'</span>).createCollection(<span class="hljs-string">'customer'</span>)
EOF
</code></pre><h3 id="5-start-your-docker">5. Start your docker</h3>
<pre><code>$ docker-compose up 
...
...
mongo-db_1       | MongoDB shell version v4<span class="hljs-number">.0</span><span class="hljs-number">.13</span>
mongo-db_1       | connecting to: mongodb:<span class="hljs-comment">//127.0.0.1:27017/?gssapiServiceName=mongodb</span>
mongo-db_1       | Implicit session: session { <span class="hljs-string">"id"</span> : U<span class="hljs-built_in">UID</span>(<span class="hljs-string">"a7dc5873-e649-42dd-9b50-621521b57479"</span>) }
mongo-db_1       | MongoDB server version: <span class="hljs-number">4.0</span><span class="hljs-number">.13</span>
mongo-db_1       | switched to db schooldb
mongo-db_1       | { <span class="hljs-string">"ok"</span> : <span class="hljs-number">1</span> }
mongo-db_1       | switched to db accountdb
mongo-db_1       | { <span class="hljs-string">"ok"</span> : <span class="hljs-number">1</span> }
mongo-db_1       | bye

....
</code></pre>]]></content:encoded></item><item><title><![CDATA[How to dump and restore in MongoDB]]></title><description><![CDATA[1. Dump
Local database
mongodump --db=test-db
Remote database
mongodump -u=USERNAME -p=PASSWORD --host=HOST_NAME/HOST_IP --port=HOST_PORT  --out {YOUR_DIRECTOTY_PATH} --db=DB_NAME
After dumping you will have a dump directory
➜ ~ tree dump
dump
└── te...]]></description><link>https://tenzinchemi.in/how-to-dump-and-restore-in-mongodb</link><guid isPermaLink="true">https://tenzinchemi.in/how-to-dump-and-restore-in-mongodb</guid><category><![CDATA[MongoDB]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Wed, 06 Nov 2019 13:34:37 GMT</pubDate><content:encoded><![CDATA[<h1 id="1-dump">1. Dump</h1>
<p><strong>Local database</strong></p>
<pre><code>mongodump --db=<span class="hljs-built_in">test</span>-db
</code></pre><p><strong>Remote database</strong></p>
<pre><code>mongodump -u=USERNAME -p=PASSWORD --host=HOST_NAME/HOST_IP --port=HOST_PORT  --<span class="hljs-keyword">out</span> {YOUR_DIRECTOTY_PATH} --db=DB_NAME
</code></pre><p>After dumping you will have a dump directory</p>
<pre><code>➜ ~ <span class="hljs-selector-tag">tree</span> <span class="hljs-selector-tag">dump</span>
<span class="hljs-selector-tag">dump</span>
└── <span class="hljs-selector-tag">test</span>
    ├── <span class="hljs-selector-tag">cats</span><span class="hljs-selector-class">.bson</span>
    ├── <span class="hljs-selector-tag">cats</span><span class="hljs-selector-class">.metadata</span><span class="hljs-selector-class">.json</span>
    ├── <span class="hljs-selector-tag">device</span><span class="hljs-selector-class">.bson</span>
    ├── <span class="hljs-selector-tag">device</span><span class="hljs-selector-class">.metadata</span><span class="hljs-selector-class">.json</span>
    ├── <span class="hljs-selector-tag">event_data</span><span class="hljs-selector-class">.bson</span>
    ├── <span class="hljs-selector-tag">event_data</span><span class="hljs-selector-class">.metadata</span><span class="hljs-selector-class">.json</span>
    ├── <span class="hljs-selector-tag">organisation</span><span class="hljs-selector-class">.bson</span>
    ├── <span class="hljs-selector-tag">organisation</span><span class="hljs-selector-class">.metadata</span><span class="hljs-selector-class">.json</span>
    ├── <span class="hljs-selector-tag">organization</span><span class="hljs-selector-class">.bson</span>
    └── <span class="hljs-selector-tag">organization</span><span class="hljs-selector-class">.metadata</span><span class="hljs-selector-class">.json</span>
</code></pre><h1 id="2-restore">2. Restore</h1>
<p>This will restore everything to your local mongo instance</p>
<pre><code>mongorestore  <span class="hljs-built_in">dump</span>/
</code></pre><p>If you want to dump a specific collection, you can filter like below while restoring</p>
<pre><code>mongorestore --nsInclude=test.cats <span class="hljs-built_in">dump</span>/
</code></pre>]]></content:encoded></item><item><title><![CDATA[Nginx block all request except GET.]]></title><description><![CDATA[If you want to block a specific type of HTTP request methods like POST, then use  limit_except  directive.
Edit your /etc/nginx/sites-enabled/<your-app>
  location ~* {
    limit_except GET {
      allow 192.168.1.0/32;
      deny all;
    }
  }
Rest...]]></description><link>https://tenzinchemi.in/nginx-block-all-request-except-get</link><guid isPermaLink="true">https://tenzinchemi.in/nginx-block-all-request-except-get</guid><category><![CDATA[nginx]]></category><dc:creator><![CDATA[Tenzin Chemi]]></dc:creator><pubDate>Thu, 13 Jun 2019 19:51:09 GMT</pubDate><content:encoded><![CDATA[<p>If you want to block a specific type of HTTP request methods like POST, then use  <a target='_blank' rel='noopener noreferrer'  href="https://nginx.org/en/docs/http/ngx_http_core_module.html#limit_except"><code>limit_except</code></a>  directive.</p>
<p>Edit your <em>/etc/nginx/sites-enabled/&lt;your-app&gt;</em></p>
<pre><code>  <span class="hljs-attribute">location</span> <span class="hljs-regexp">~* </span>{
    <span class="hljs-attribute">limit_except</span> GET {
      <span class="hljs-attribute">allow</span> <span class="hljs-number">192.168.1.0</span>/<span class="hljs-number">32</span>;
      <span class="hljs-attribute">deny</span> all;
    }
  }
</code></pre><p>Restart your server:</p>
<pre><code><span class="hljs-attribute">sudo</span> service nginx restart
</code></pre><p>If the restart fails, then you might have made a syntax error in your nginx configuration. After a successful restart, you will start receiving 403 responses for all the requests except GET/HEAD. </p>
<pre><code><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>403 Forbidden<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">bgcolor</span>=<span class="hljs-string">"white"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">center</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>403 Forbidden<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">center</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">center</span>&gt;</span>nginx/1.14.0 (Ubuntu)<span class="hljs-tag">&lt;/<span class="hljs-name">center</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>Keep in mind,<code>limit_except</code> is required to be declared inside a location directive. </p>
]]></content:encoded></item></channel></rss>