<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://pradyothkukkapalli.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://pradyothkukkapalli.com/" rel="alternate" type="text/html" /><updated>2026-05-29T06:16:49+00:00</updated><id>https://pradyothkukkapalli.com/feed.xml</id><title type="html">Pradyoth Kukkapalli</title><author><name>Pradyoth Kukkapalli</name></author><entry><title type="html">More fun with the Fried Liver Attack</title><link href="https://pradyothkukkapalli.com/chess/more-fried-liver/" rel="alternate" type="text/html" title="More fun with the Fried Liver Attack" /><published>2023-12-23T00:00:00+00:00</published><updated>2023-12-23T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/chess/more-fried-liver</id><content type="html" xml:base="https://pradyothkukkapalli.com/chess/more-fried-liver/"><![CDATA[<p>After writing my previous post about the <a href="/chess/fried-liver-attack/">Fried Liver Attack</a>, I
realized that I left out some more interesting lines that you might encounter.
In this post, we will look at other positions you will likely encounter as you
use this opening more often.</p>

<ol id="markdown-toc">
  <li><a href="#entering-the-fried-liver-attack" id="markdown-toc-entering-the-fried-liver-attack">Entering the Fried Liver Attack</a></li>
  <li><a href="#the-polerio-defense" id="markdown-toc-the-polerio-defense">The Polerio Defense</a></li>
  <li><a href="#the-ponziani-steinitz-gambit" id="markdown-toc-the-ponziani-steinitz-gambit">The Ponziani-Steinitz Gambit</a></li>
  <li><a href="#the-anti-fried-liver-defense" id="markdown-toc-the-anti-fried-liver-defense">The Anti-Fried Liver Defense</a></li>
  <li><a href="#parting-thoughts" id="markdown-toc-parting-thoughts">Parting Thoughts</a></li>
</ol>

<h2 id="entering-the-fried-liver-attack">Entering the Fried Liver Attack</h2>

<p>Just as a quick refresher, we enter the Knight Attack variation of the Italian
Game after we jump our knight forward to g5 to create a powerful double attack
on the vulnerable f7 square.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark sq-last"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    <svg class="chess-arrows" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360" aria-hidden="true">
  <defs>
  <marker id="chess-arrow-f8a15b4cc1" markerWidth="3" markerHeight="3" refX="1.5" refY="1.5" orient="auto">
    <path d="M0,0 L3,1.5 L0,3 z" fill="#388e3c" fill-opacity="0.45" />
  </marker>
</defs>
<g class="chess-arrows-highlight" stroke="#388e3c" stroke-opacity="0.45" stroke-width="6" stroke-linecap="round" fill="none" marker-end="url(#chess-arrow-f8a15b4cc1)">
  <line x1="112.5" y1="202.5" x2="247.5" y2="67.5" /><line x1="292.5" y1="157.5" x2="247.5" y2="67.5" />
</g>
</svg>
  </div>
  
  <ul class="chess-arrow-legend" aria-label="Arrow key">
  <li class="chess-arrow-legend-item chess-arrow-legend-highlight"><span class="chess-arrow-legend-swatch" aria-hidden="true"></span>Threat or idea</li>
</ul>
</div>
  <figcaption>The Italian Game: Knight Attack. We move our knight a second time to create a powerful threat on f7.</figcaption>
</figure>

<h2 id="the-polerio-defense">The Polerio Defense</h2>

<p>A common response to this double attack is to block our bishop’s vision of f7 by
advancing the pawn to d5, and attacking our bishop at the same time.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>Black uses their d-pawn to block our bishop's vision of f7.</figcaption>
</figure>

<p>We naturally capture this pawn with our pawn on e4, which removes the attack on
our bishop and counterattacks our opponent’s knight.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bP" role="presentation"></span></span>
  <span class="chess-material-advantage">+1</span>
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>We answer d5 by capturing the pawn with our own pawn and counterattacking their knight.</figcaption>
</figure>

<p>The most common response to this counterattack is for black to capture our pawn
with their other knight. However, there is another approach they could take.
They could simply move their attacked knight to safety on a5, where it also
attacks our undefended bishop. This is called the Polerio Defense.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bP" role="presentation"></span></span>
  <span class="chess-material-advantage">+1</span>
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark sq-last"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>Our opponent moves their knight to safety and counterattacks our undefended bishop.</figcaption>
</figure>

<p>The followup for white is quite simple, we will get out of the attack by using
our bishop to give a check.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bP" role="presentation"></span></span>
  <span class="chess-material-advantage">+1</span>
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>Move our bishop to safety and give a check to the king.</figcaption>
</figure>

<p>After this, your opponent may block the check with their bishop, their knight,
or a pawn. At this point, we have safely left the opening up a pawn. From here
on, by playing solid you can gain an advantage, but you will not have an
overwhelming tactical advantage as you might in many of the other lines.</p>

<h2 id="the-ponziani-steinitz-gambit">The Ponziani-Steinitz Gambit</h2>

<p>This is an unconvential way that black might respond to our dual threat on the
f7 square. They could instead take our pawn on e4 with the knight, entering the
gambit.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark sq-last"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-wP" role="presentation"></span></span>
  <span class="chess-material-advantage">+1</span>
</div>
  
</div>
  <figcaption>Rather than defending the f7 square, our opponent gambits the pawn by capturing our pawn on e4.</figcaption>
</figure>

<p>This seems like a mistake at first, because we could simply capture the knight
back. The problem is that we run straight into a fork when black pushes their d4
pawn.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bN" role="presentation"></span></span>
  <span class="chess-material-advantage">+2</span>
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    <svg class="chess-arrows" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360" aria-hidden="true">
  <defs>
  <marker id="chess-arrow-d6b3024947" markerWidth="3" markerHeight="3" refX="1.5" refY="1.5" orient="auto">
    <path d="M0,0 L3,1.5 L0,3 z" fill="#388e3c" fill-opacity="0.45" />
  </marker>
</defs>
<g class="chess-arrows-highlight" stroke="#388e3c" stroke-opacity="0.45" stroke-width="6" stroke-linecap="round" fill="none" marker-end="url(#chess-arrow-d6b3024947)">
  <line x1="157.5" y1="157.5" x2="112.5" y2="202.5" /><line x1="157.5" y1="157.5" x2="202.5" y2="202.5" />
</g>
</svg>
  </div>
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-wP" role="presentation"></span></span>
  
</div>
  <ul class="chess-arrow-legend" aria-label="Arrow key">
  <li class="chess-arrow-legend-item chess-arrow-legend-highlight"><span class="chess-arrow-legend-swatch" aria-hidden="true"></span>Threat or idea</li>
</ul>
</div>
  <figcaption>Capturing the undefended knight on e4 just allows our opponent to fork our knight and bishop. When the dust settles we end up down a pawn.</figcaption>
</figure>

<p>Similarly, if we continue with our plan of attacking with the knight on f7, our
opponent is able to simply move their queen to h4, and begin to threaten
checkmate.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bP" role="presentation"></span></span>
  
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark sq-last"></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark sq-last"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    <svg class="chess-arrows" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360" aria-hidden="true">
  <defs>
  <marker id="chess-arrow-864968d9dd" markerWidth="3" markerHeight="3" refX="1.5" refY="1.5" orient="auto">
    <path d="M0,0 L3,1.5 L0,3 z" fill="#388e3c" fill-opacity="0.45" />
  </marker>
</defs>
<g class="chess-arrows-highlight" stroke="#388e3c" stroke-opacity="0.45" stroke-width="6" stroke-linecap="round" fill="none" marker-end="url(#chess-arrow-864968d9dd)">
  <line x1="202.5" y1="202.5" x2="247.5" y2="292.5" /><line x1="337.5" y1="202.5" x2="247.5" y2="292.5" />
</g>
</svg>
  </div>
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-wP" role="presentation"></span></span>
  
</div>
  <ul class="chess-arrow-legend" aria-label="Arrow key">
  <li class="chess-arrow-legend-item chess-arrow-legend-highlight"><span class="chess-arrow-legend-swatch" aria-hidden="true"></span>Threat or idea</li>
</ul>
</div>
  <figcaption>Proceeding with our original plan will allow our opponent to threaten checkmate using their queen on h4.</figcaption>
</figure>

<p>To avoid all of these complications, we should simply offer a check to the king on f7, by capturing with our bishop.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-bP" role="presentation"></span></span>
  
</div>
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  <div class="chess-captured">
  <span class="chess-captured-pieces"><span class="chess-captured-piece piece-wP" role="presentation"></span></span>
  
</div>
  
</div>
  <figcaption>To prevent our opponent from castling, and win back the pawn that they took from us on e4.</figcaption>
</figure>

<h2 id="the-anti-fried-liver-defense">The Anti-Fried Liver Defense</h2>

<p>The final variation actually begins before we can even move our knight to
threaten the f7 pawn. This is called the Anti-Fried Liver Defense, so while not
part of the Italian Game: Knight Attack, it is certainly related. Essentially,
after entering the Italian Game our opponent pushes their pawn to h6 instead of
moving their second knight out to f6.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light sq-last"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark sq-last"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>Our opponent prevents the Fried Liver Attack altogether by preventing the knight move to g5 by pushing their pawn to h6.</figcaption>
</figure>

<p>Because our opponent has chosen to push a pawn rather than develop a piece, we
can choose to attack the center by pushing our pawn to d4. After this point,
much of the ideas of a standard Italian Game apply, so I would encourage you to
explore further there.</p>

<figure class="small-width chess-diagram">
  <div class="chess-diagram-board">
  
  <div class="chess-board-wrap">
    <div class="chess-board" data-piece-path="/assets/images/chess-pieces/cburnett">
      <div class="chess-square sq-light"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bQ" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bK" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bR" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-bN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-bP" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-dark sq-last"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark sq-last"></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wP" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wR" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wN" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wB" role="presentation"></span></div><div class="chess-square sq-light"><span class="chess-piece piece-wQ" role="presentation"></span></div><div class="chess-square sq-dark"><span class="chess-piece piece-wK" role="presentation"></span></div><div class="chess-square sq-light"></div><div class="chess-square sq-dark"></div><div class="chess-square sq-light"><span class="chess-piece piece-wR" role="presentation"></span></div>
    </div>
    
  </div>
  
  
</div>
  <figcaption>In response to the Anti-Fried Liver Defense, we attack the center with d4.</figcaption>
</figure>

<h2 id="parting-thoughts">Parting Thoughts</h2>

<p>As you can see, even with a niche opening like the Fried Liver Attack, there are
so many variations that can arise. It’s important to study all of the different
variations, especially by practicing them in actual games. When a new variation
arises, it’s important to analyze the best rebuttal and keep it mind for future
games.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="chess" /><summary type="html"><![CDATA[After writing my previous post about the Fried Liver Attack, I realized that I left out some more interesting lines that you might encounter. In this post, we will look at other positions you will likely encounter as you use this opening more often.]]></summary></entry><entry><title type="html">Long-running GPU-powered Jupyter notebooks</title><link href="https://pradyothkukkapalli.com/tech/vertex-ai-notebooks/" rel="alternate" type="text/html" title="Long-running GPU-powered Jupyter notebooks" /><published>2023-09-10T00:00:00+00:00</published><updated>2023-09-10T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/vertex-ai-notebooks</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/vertex-ai-notebooks/"><![CDATA[<p>With AI/ML hype at an all time high. Many people are interested in experimenting
with the latest models, learning how to train them, and learning how to deploy
them. But, the main stumbling block for most of the nouveaux arrivants is
getting their hands on an <a href="https://www.nvidia.com/en-us/geforce/graphics-cards/">NVIDIA GPU</a>. Essentially every ML library
uses <a href="https://en.wikipedia.org/wiki/CUDA">CUDA</a>, an API for running parallel computations on graphics cards,
which is available on every NVIDIA GPU. These days if you want an NVIDIA GPU, you have two options:</p>

<ol>
  <li><strong>Get a dedicated machine</strong> with an NVIDIA GPU installed (or install one
yourself) to allow your ML library of choice to use GPU acceleration. This
involves setting up and updating drivers and libraries to make sure your
machine is compatible with whatever model/code you are trying.</li>
  <li><strong>Use a cloud-based solution</strong> such as Colab, or Kaggle notebooks to do your
experimentaion in the cloud.</li>
</ol>

<table class="responsive-table">
  <thead>
    <tr style="background-color: ghostwhite">
      <th colspan="2">
        Having your own GPU
      </th>
    </tr>
    <tr>
      <th style="background-color: #b2edc1">Pros</th>
      <th style="background-color: #edb3b2">Cons</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>No recurring costs, just pay for GPU once</td>
      <td>Big upfront investment</td>
    </tr>
    <tr>
      <td>No internet connection required</td>
      <td>Need to use same (bulky) laptop wherever you want to work</td>
    </tr>
    <tr>
      <td></td>
      <td>Upgrading costs a lot more money, have to buy new card or machine</td>
    </tr>
  </tbody>
</table>

<table class="responsive-table">
  <thead>
    <tr style="background-color: ghostwhite">
      <th colspan="2">
        Using a cloud notebook
      </th>
    </tr>
    <tr>
      <th style="background-color: #b2edc1">Pros</th>
      <th style="background-color: #edb3b2">Cons</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Generous free tiers usually</td>
      <td>Generally requires paying money to do anything significant</td>
    </tr>
    <tr>
      <td>Always up-to-date on drivers, library, and hardware</td>
      <td>Must always be connected to the internet</td>
    </tr>
    <tr>
      <td>Usable from any device</td>
      <td></td>
    </tr>
  </tbody>
</table>

<p>Both have their advantages and disadvantages. While having your own dedicated
GPU might seem cheaper in the long-run, you may find that your machine quickly
becomes outdated, and now you’re just stuck with an expensive computer that does
not do its primary purpose well. It’s a problem I personally experienced when I
purchased my System76 Gazelle a few years ago. Now it just feels sluggish
compared to newer GPUs especially when working with language models. Not to
mention the noise that the fan makes when the GPU kicks in, and the annoying
process of install the proper libraries with conda, and keeping the NVIDIA
drivers up-to-date.</p>

<p>Cloud notebooks like Colab on the other hand remove the need to maintain
drivers, hardware, and library installations. In addition, the free tier is
usually generous enough for beginners to learn. However, you will almost
certainly run into problems if you want to try training/fine-tuning language
models. Given the fact that language models need to be able to predict the next
word in a sequence of words, the matrices that they train are quite large,
leading to long training times. You will soon discover with platforms like Colab
that the notebook will disconnect long before your training is finished, but
it’s not at all obvious from Googling what you can actually do to fix this
scenario.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/jupyter/meme.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/jupyter/meme.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/jupyter/meme.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/jupyter/meme.jpg?nf_resize=fit&amp;w=300 300w" alt="Runtime disconnected: the scourge of every ML engineer." />

  <figcaption>
      Runtime disconnected: the scourge of every ML engineer.
      
  </figcaption>
</figure>

<p>This is where Vertex AI notebooks from Google Cloud come in. Vertex AI lets you
start up a compute instance with a GPU, and then run a Jupyter notebook
connected to that instance. Because you have a dedicated instance, the notebook
will just keep running. The notebook may still disconnect when your computer
sleeps, because the websocket connection gets broken, but there are many
solutions to simply keep your computer awake, such as the
<a href="https://linuxgenie.net/how-to-keep-your-ubuntu-22-04-from-sleeping/">Caffeine</a>/<a href="https://apps.apple.com/us/app/caffeinated-anti-sleep-app/id1362171212">Caffeinated</a> apps.</p>

<p>I would just start with the g2-standard-4 machine, which comes with one GPU. If
that is not enough, then you can consider upgrading to the g2-standard-24
machine, which has two GPUs. For learning purposes, it is unlikely you will need
more than that, but the g2-standard-48 and the a2-highgpu-* and a2-megagpu-*
instances also exist. However, do keep in mind that the cost increases with the
power and number of GPUs you utilize.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[With AI/ML hype at an all time high. Many people are interested in experimenting with the latest models, learning how to train them, and learning how to deploy them. But, the main stumbling block for most of the nouveaux arrivants is getting their hands on an NVIDIA GPU. Essentially every ML library uses CUDA, an API for running parallel computations on graphics cards, which is available on every NVIDIA GPU. These days if you want an NVIDIA GPU, you have two options:]]></summary></entry><entry><title type="html">Why do the days fly by?</title><link href="https://pradyothkukkapalli.com/musings/why-do-the-days-fly-by/" rel="alternate" type="text/html" title="Why do the days fly by?" /><published>2023-06-25T00:00:00+00:00</published><updated>2023-06-25T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/musings/why-do-the-days-fly-by</id><content type="html" xml:base="https://pradyothkukkapalli.com/musings/why-do-the-days-fly-by/"><![CDATA[<p>Take a moment to consider this painting by Caspar David Friedrich. It’s called <em>Wanderer above the Sea of Fog</em>. The wanderer stands over a precipice, gazing into a rocky landscape shrouded in a dense fog. When I look at this painting I am captured by a sense of the difficult journey ahead, of all the obstacles that must be overcome to traverse the terrain below. Each step feels heavy and consequential, because you don’t know what lays under each rock, or whether your next foothold will be firm. Each second passes like an hour, as your mind expands to overcome each new obstacle. Every step is a journey of its own. If you’ve ever tried a new hobby, or a new sport, then you know what I’m talking about.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/fly-by/wanderer.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/fly-by/wanderer.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/fly-by/wanderer.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/fly-by/wanderer.jpg?nf_resize=fit&amp;w=300 300w" alt="Wanderer above the Sea of Fog by Caspar David Friedrich." />

  <figcaption>
      Wanderer above the Sea of Fog by Caspar David Friedrich.
      
      &mdash;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Caspar_David_Friedrich_-_Wanderer_above_the_sea_of_fog.jpg">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<p>So, if you find yourself wondering why time is flying by, ask yourself whether you’ve tried challenging yourself lately.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="musings" /><summary type="html"><![CDATA[Take a moment to consider this painting by Caspar David Friedrich. It’s called Wanderer above the Sea of Fog. The wanderer stands over a precipice, gazing into a rocky landscape shrouded in a dense fog. When I look at this painting I am captured by a sense of the difficult journey ahead, of all the obstacles that must be overcome to traverse the terrain below. Each step feels heavy and consequential, because you don’t know what lays under each rock, or whether your next foothold will be firm. Each second passes like an hour, as your mind expands to overcome each new obstacle. Every step is a journey of its own. If you’ve ever tried a new hobby, or a new sport, then you know what I’m talking about.]]></summary></entry><entry><title type="html">Install D2L beta library without errors</title><link href="https://pradyothkukkapalli.com/tech/d2l-library/" rel="alternate" type="text/html" title="Install D2L beta library without errors" /><published>2023-06-08T00:00:00+00:00</published><updated>2023-06-08T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/d2l-library</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/d2l-library/"><![CDATA[<p>If you’re doing the Dive into Deep Learning (<a href="https://d2l.ai">d2l</a>) course or
reading through the book yourself, you’ll have to eventually install the <a href="https://pypi.org/project/d2l/">d2l
library</a> (specifically the beta version).</p>

<p>For example, when you run the install command:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="o">!</span>pip <span class="nb">install </span><span class="nv">d2l</span><span class="o">==</span>1.0.0-beta0
</code></pre></div></div>

<p>You will most likely encounter an error similar to this:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="syntax"><code>  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ <span class="nb">exit </span>code: 1
  ╰─&gt; See above <span class="k">for </span>output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Preparing metadata <span class="o">(</span>setup.py<span class="o">)</span> ... error
error: metadata-generation-failed

× Encountered error <span class="k">while </span>generating package metadata.
╰─&gt; See above <span class="k">for </span>output.
</code></pre></div></div>

<p>I found the solution for this in a <a href="https://github.com/pypa/setuptools/issues/3801#issuecomment-1490841176">Github
issue</a>
for the setuptools library. To fix the issue, you need to revert your version of
setuptools, as well as the version of wheel to match:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="o">!</span>pip <span class="nb">install </span><span class="nv">wheel</span><span class="o">==</span>0.38.4 <span class="nv">setuptools</span><span class="o">==</span>57.1.0
</code></pre></div></div>

<p>Then, <strong>restart your Colab/Jupyter runtime</strong> in order to pick up the change.
Afterwards, if you run the following command again, it should succeed:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="o">!</span>pip <span class="nb">install </span><span class="nv">d2l</span><span class="o">==</span>1.0.0-beta0
</code></pre></div></div>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[If you’re doing the Dive into Deep Learning (d2l) course or reading through the book yourself, you’ll have to eventually install the d2l library (specifically the beta version).]]></summary></entry><entry><title type="html">Protecting your Python API with Firebase Auth</title><link href="https://pradyothkukkapalli.com/tech/firebase-auth-client-and-backend/" rel="alternate" type="text/html" title="Protecting your Python API with Firebase Auth" /><published>2023-04-28T00:00:00+00:00</published><updated>2023-04-28T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/firebase-auth-client-and-backend</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/firebase-auth-client-and-backend/"><![CDATA[<p>Suppose you’re using Firebase to authenticate users on your client webapp, but then you add a backend API that you would like to protect with Firebase authentication as well. In this article, I will show you how to protect your Python Flask API’s endpoints with Firebase authentication using the <a href="https://firebase.google.com/docs/admin/setup">Firebase Admin SDK</a>.</p>

<ol id="markdown-toc">
  <li><a href="#setup" id="markdown-toc-setup">Setup</a></li>
  <li><a href="#process-authorization-header-in-python" id="markdown-toc-process-authorization-header-in-python">Process Authorization header in Python</a></li>
  <li><a href="#pass-the-token-in-from-the-webapp" id="markdown-toc-pass-the-token-in-from-the-webapp">Pass the token in from the webapp</a></li>
</ol>

<aside class="warning-aside">
  <div class="warning-header">
    <span>Warning</span>
  </div>
  <div class="aside-content">
    
<p>This guide will show the code using a React webapp and a Python Flask API, but
the concepts will transfer to other languages and platforms.</p>

  </div>
</aside>

<h2 id="setup">Setup</h2>

<p>First, we install the firebase libraries using:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="syntax"><code>pip install firebase-admin
npm install firebase
</code></pre></div></div>

<p>Next, we need to setup the Firebase service account key that will allow our
backend API to make calls to Firebase. To do that, first we set up a service account, and download the service account key JSON file by following <a href="https://firebase.google.com/docs/admin/setup?authuser=0#initialize_the_sdk_in_non-google_environments">the instructions in the Firebase documentation</a>.</p>

<p>Then, you take the JSON file and place it somewhere on your computer and set the <code class="language-html highlighter-rouge">GOOGLE_APPLICATION_CREDENTIALS</code> environment variable. Finally, you initialize Firebase in your Python app, by adding the following line somewhere in you application:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="kn">from</span> <span class="n">firebase_admin</span> <span class="kn">import</span> <span class="n">initialize_app</span>

<span class="n">_FIREBASE_APP</span> <span class="o">=</span> <span class="nf">initialize_app</span><span class="p">()</span>
</code></pre></div></div>

<h2 id="process-authorization-header-in-python">Process Authorization header in Python</h2>

<p>When Firebase authenticates a user for you, it generates a user token that can
be used to make calls to Firebase on the user’s behalf. So, to check that a user
is authenticated on the API, we will pass the token from the webapp in the
<code class="language-html highlighter-rouge">Authorization</code> header of every request. To process the header in Python, we
will define a <code class="language-html highlighter-rouge">get_current_user</code> function:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="kn">from</span> <span class="n">typing</span> <span class="kn">import</span> <span class="n">Optional</span>
<span class="kn">from</span> <span class="n">flask</span> <span class="kn">import</span> <span class="n">request</span>
<span class="kn">from</span> <span class="n">firebase_admin.auth</span> <span class="kn">import</span> <span class="n">verify_id_token</span>

<span class="k">def</span> <span class="nf">get_current_user</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span>
  <span class="c1"># Return None if no Authorization header.
</span>  <span class="k">if</span> <span class="sh">"</span><span class="s">Authorization</span><span class="sh">"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">request</span><span class="p">.</span><span class="n">headers</span><span class="p">:</span>
    <span class="k">return</span> <span class="bp">None</span>
  <span class="n">authorization</span> <span class="o">=</span> <span class="n">request</span><span class="p">.</span><span class="n">headers</span><span class="p">[</span><span class="sh">"</span><span class="s">Authorization</span><span class="sh">"</span><span class="p">]</span>

  <span class="c1"># Authorization header format is "Bearer &lt;token&gt;".
</span>  <span class="c1"># This matches OAuth 2.0 spec: 
</span>  <span class="c1"># https://www.rfc-editor.org/rfc/rfc6750.txt.
</span>  <span class="k">if</span> <span class="ow">not</span> <span class="n">authorization</span><span class="p">.</span><span class="nf">startswith</span><span class="p">(</span><span class="sh">"</span><span class="s">Bearer </span><span class="sh">"</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">None</span>

  <span class="n">token</span> <span class="o">=</span> <span class="n">authorization</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="sh">"</span><span class="s">Bearer </span><span class="sh">"</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
  <span class="k">try</span><span class="p">:</span>
    <span class="c1"># Verify that the token is valid.
</span>    <span class="n">result</span> <span class="o">=</span> <span class="nf">verify_id_token</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
    <span class="c1"># Return the user ID of the authenticated user.
</span>    <span class="k">return</span> <span class="n">result</span><span class="p">[</span><span class="sh">"</span><span class="s">uid</span><span class="sh">"</span><span class="p">]</span>
  <span class="k">except</span><span class="p">:</span>
    <span class="k">return</span> <span class="bp">None</span>
</code></pre></div></div>

<p>Then, in any of the Flask endpoints that require authentication, we can simply check that <code class="language-html highlighter-rouge">get_current_user</code> returns a valid user ID:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="kn">from</span> <span class="n">flask</span> <span class="kn">import</span> <span class="n">Flask</span><span class="p">,</span> <span class="n">make_response</span>

<span class="n">app</span> <span class="o">=</span> <span class="nc">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>

<span class="nd">@app.route</span><span class="p">(</span><span class="sh">"</span><span class="s">/api/resource</span><span class="sh">"</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">run_endpoint</span><span class="p">():</span>
  <span class="n">user</span> <span class="o">=</span> <span class="nf">get_current_user</span><span class="p">()</span>
  <span class="k">if</span> <span class="ow">not</span> <span class="n">user</span><span class="p">:</span>
    <span class="k">return</span> <span class="nf">make_response</span><span class="p">(</span><span class="sh">"</span><span class="s">Unauthorized</span><span class="sh">"</span><span class="p">,</span> <span class="mi">401</span><span class="p">)</span>

  <span class="c1"># do something
</span></code></pre></div></div>

<h2 id="pass-the-token-in-from-the-webapp">Pass the token in from the webapp</h2>

<p>Now, we’ll discuss how to propagate the token from the React webapp to the API. When Firebase authenticates a user on your app, it will also issue an ID token. We will listen for this token, and maintain it in a Context so that we can always have an up-to-date token when we make the request to our Python backend.</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">initializeApp</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">firebase/app</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">getAuth</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">firebase/auth</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span>
  <span class="nx">ReactNode</span><span class="p">,</span>
  <span class="nx">createContext</span><span class="p">,</span>
  <span class="nx">useContext</span><span class="p">,</span>
  <span class="nx">useEffect</span><span class="p">,</span>
  <span class="nx">useState</span><span class="p">,</span>
<span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">react</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">const</span> <span class="nx">firebaseApp</span> <span class="o">=</span> <span class="nf">initializeApp</span><span class="p">({</span>
  <span class="c1">// Follow the instructions at</span>
  <span class="c1">// https://support.google.com/firebase/answer/7015592</span>
  <span class="c1">// to get your Firebase config object.</span>
<span class="p">});</span>

<span class="kd">const</span> <span class="nx">TokenContext</span> <span class="o">=</span> <span class="nx">createContext</span><span class="o">&lt;</span><span class="kr">string</span><span class="o">&gt;</span><span class="p">(</span><span class="dl">""</span><span class="p">);</span>
<span class="kd">const</span> <span class="nc">TokenProvider</span><span class="p">(</span><span class="nx">props</span><span class="p">:</span> <span class="p">{</span> <span class="nl">children</span><span class="p">:</span> <span class="nx">ReactNode</span> <span class="p">})</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">idToken</span><span class="p">,</span> <span class="nx">setIdToken</span><span class="p">]</span> <span class="o">=</span> <span class="nf">useState</span><span class="p">(</span><span class="dl">""</span><span class="p">);</span>

  <span class="c1">// Register a listener for the ID token.</span>
  <span class="nf">useEffect</span><span class="p">(()</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="kd">const</span> <span class="nx">auth</span> <span class="o">=</span> <span class="nf">getAuth</span><span class="p">(</span><span class="nx">firebaseApp</span><span class="p">);</span>
    <span class="nx">auth</span><span class="p">.</span><span class="nf">onIdTokenChanged</span><span class="p">(</span><span class="k">async </span><span class="p">(</span><span class="nx">user</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
      <span class="nf">setIdToken</span><span class="p">((</span><span class="k">await</span> <span class="nx">user</span><span class="p">?.</span><span class="nf">getIdToken</span><span class="p">())</span> <span class="o">??</span> <span class="dl">""</span><span class="p">);</span>
    <span class="p">});</span>
  <span class="p">},</span> <span class="p">[]);</span>

  <span class="k">return </span><span class="p">(</span>
    <span class="p">&lt;</span><span class="nc">TokenContext</span><span class="p">.</span><span class="nc">Provider</span> <span class="na">value</span><span class="p">=</span><span class="si">{</span><span class="nx">idToken</span><span class="si">}</span><span class="p">&gt;</span>
      <span class="si">{</span><span class="nx">props</span><span class="p">.</span><span class="nx">children</span><span class="si">}</span>
    <span class="p">&lt;/</span><span class="nc">TokenContext</span><span class="p">.</span><span class="nc">Provider</span><span class="p">&gt;</span>
  <span class="p">)</span>
<span class="p">}</span>

<span class="kd">function</span> <span class="nf">useToken</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="nf">useContext</span><span class="p">(</span><span class="nx">TokenContext</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The <code class="language-html highlighter-rouge">TokenProvider</code> will be used to make the token available anywhere in your app. To do so, you just need to wrap your app component with the <code class="language-html highlighter-rouge">TokenProvider</code> component, like so:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="p">&lt;</span><span class="nc">TokenProvider</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nc">App</span><span class="p">/&gt;</span>
<span class="p">&lt;/</span><span class="nc">TokenProvider</span><span class="p">&gt;</span>
</code></pre></div></div>

<p>Then, in any component that will make HTTP requests, you can get the latest context like so:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="kd">function</span> <span class="nf">SomeComponent</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">token</span> <span class="o">=</span> <span class="nf">useToken</span><span class="p">();</span>

  <span class="k">return</span> <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>component<span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>To make HTTP requests with our token, we just pass it in via the Authorization header as we discussed earlier. If we use something like <a href="https://axios-http.com/">Axios</a>, this is straightforward:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="nx">axios</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">axios</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">function</span> <span class="nf">SomeComponent</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">token</span> <span class="o">=</span> <span class="nf">useToken</span><span class="p">();</span>

  <span class="kd">const</span> <span class="nx">handleClick</span> <span class="o">=</span> <span class="k">async </span><span class="p">()</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="kd">const</span> <span class="nx">headers</span> <span class="o">=</span> <span class="p">{</span> 
      <span class="na">Authorization</span><span class="p">:</span> <span class="s2">`Bearer </span><span class="p">${</span><span class="nx">token</span><span class="p">}</span><span class="s2">`</span> 
    <span class="p">};</span>
    <span class="k">await</span> <span class="nx">axios</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="dl">"</span><span class="s2">/api/resource</span><span class="dl">"</span><span class="p">,</span> <span class="p">{</span> <span class="nx">headers</span> <span class="p">});</span>
  <span class="p">};</span>

  <span class="k">return </span><span class="p">(</span>
    <span class="p">&lt;</span><span class="nt">button</span> <span class="na">onClick</span><span class="p">=</span><span class="si">{</span><span class="nx">handleClick</span><span class="si">}</span><span class="p">&gt;</span>
      Click me!
    <span class="p">&lt;/</span><span class="nt">button</span><span class="p">&gt;</span>
  <span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[Suppose you’re using Firebase to authenticate users on your client webapp, but then you add a backend API that you would like to protect with Firebase authentication as well. In this article, I will show you how to protect your Python Flask API’s endpoints with Firebase authentication using the Firebase Admin SDK.]]></summary></entry><entry><title type="html">The Lion and the Fox: Chhatrapati Shivaji</title><link href="https://pradyothkukkapalli.com/history/shivaji/" rel="alternate" type="text/html" title="The Lion and the Fox: Chhatrapati Shivaji" /><published>2023-04-28T00:00:00+00:00</published><updated>2023-04-28T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/history/shivaji</id><content type="html" xml:base="https://pradyothkukkapalli.com/history/shivaji/"><![CDATA[<p>When we think of the history of India, most people think about various religious
figures, and a few large empires that spanned mostly the north of India. A brief
history that shows up in many textbooks might be that the Indus Valley
Civilization declined, the Mauryan Empire rose and fell 1500 years later, the
Mughals invaded another 1500 years later, and then the British Empire occupied
the country. Part of this is simply that large empires that battle with outside
forces generally have more written about them. For example, we know a great deal
about the Sakas even though they have produced little writing or history
themselves, due to their interactions with the Greeks, Persians, and Chinese.
So, to fill in some of these gaps in Indian history, in this article I will be
writing about Chhatrapati Shivaji Bhonsle (b. 1630; d. 1680), one of the most
energetic and successful leaders in recent memory. His actions and methods show
him to be a true <a href="/books/machiavellian-ethics/"><em>princeps</em></a>,
and after his death, his Maratha Empire would span all of India, acting as the
primary power on the subcontinent in between the dominance of the Mughals and
the British Raj.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/shivaji.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/shivaji.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/shivaji.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/shivaji.jpg?nf_resize=fit&amp;w=300 300w" alt="The statue of Chhatrapati Shivaji at Pratapgad." />

  <figcaption>
      The statue of Chhatrapati Shivaji at Pratapgad.
      
      &mdash;<a class="source-link" href="https://www.britishmuseum.org/collection/object/W_1974-0617-0-11-12">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="warriors-of-the-western-ghats">Warriors of the Western Ghats</h2>

<p>As Thucydides tells us, the climate and terrain of a land informs us greatly
about the nature of the people. Just as the Spartans’ military discipline, and
self-sufficient nature derives from the Laconian hills and mountains, so too can
we assert that the hardy and militaristic nature of the Marathas derived from
the rough terrain of the Western Ghat mountains.</p>

<p>In 1647, when Shivaji first began his campaign to establish his own state, India
was a divided land. Much of the north was controlled by the Mughal Empire ruled
by Shah Jahan. In the middle of the country there were two main powers, both
with Muslim rulers:</p>

<ol>
  <li>The Bijapur Sultanate in the west ruled by Muhammad Adil Shah.</li>
  <li>The Golconda Sultanate in the east ruled by Abdullah Qutb Shah.</li>
</ol>

<p>To the south, we see the remnants of the Vijayanagara Empire which began
fracturing into much smaller kingdoms.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/map.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/map.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/map.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/map.jpg?nf_resize=fit&amp;w=300 300w" alt="Map
  of India in 1692 by Giacomo Cantelli. This is the best map I could find that
  gave a lay of the land. As you can see, the large mass in the north is the
  Mughal Empire. The green bordered land to the southwest is the Bijapur
  Sultanate, and then you have the Golconda Sultanate to the east. David Rumsey
  Map Collection, David Rumsey Map Center, Stanford Libraries." />

  <figcaption>
      Map
  of India in 1692 by Giacomo Cantelli. This is the best map I could find that
  gave a lay of the land. As you can see, the large mass in the north is the
  Mughal Empire. The green bordered land to the southwest is the Bijapur
  Sultanate, and then you have the Golconda Sultanate to the east. David Rumsey
  Map Collection, David Rumsey Map Center, Stanford Libraries.
      
      &mdash;<a class="source-link" href="https://archive.org/details/dr_penisola-dell-india-di-qua-dal-gange-et-isole-intorno-ad-essa-adiacenti-de-11438154">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<p>Shivaji would grow up in the Bijapur Sultanate in the west. The region was part
of the Deccan plateau, a rocky terrain in between the Western Ghat and the
Eastern Ghat mountains which line the respective coasts of the Indian peninsula.
Shivaji’s father and his forefathers were all soldiers and officers in the
Bijapur army. The rough terrain of the Deccan and the Western Ghats meant that
upward mobility was easier to achieve through the military rather than
agriculture or commerce, which led to a simple society devoid of refinement, but
rich in equality.</p>

<p>So important was their equality that though Shivaji was considered by most
Brahmins (save the Pandit Gaga Bhatt) to be just a Shudra, he still rose to be
king. Similarly, the Brahmins who were generally considered to be priests,
produced some of the greatest generals and leaders in Maratha history, like
Peshwa Baji Rao I. This sense of merit earned by battle allowed the Marathas to
elevate men from every social class to the title of Maharaja, including the
Holkars of Indore, the Scindias of Gwalior, the Gaikwads of Baroda, and many
more.</p>

<p>This rough and rugged populace allowed the Bijapur Sultanate to form an army
that could fend off the powerful Mughals to the north. But, it was Shivaji, the
last <em>princeps</em> amongst the Hindus who would weld these mercenaries together
into a nation.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/census.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/census.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/census.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/census.png?nf_resize=fit&amp;w=300 300w" alt="Given their predeliction for serving in the armies of various kingdoms, the
British would later classify the Marathas as a military class in their 1891
Census" />

  <figcaption>
      Given their predeliction for serving in the armies of various kingdoms, the
British would later classify the Marathas as a military class in their 1891
Census
      
      &mdash;<a class="source-link" href="https://archive.org/details/cu31924023177268/page/n193/mode/2up">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="shivajis-luck">Shivaji’s luck</h2>

<p>In addition to the robust nature of his people, Shivaji himself was born into
circumstances that greatly aided his rise. First and foremost was the
advantageous terrain of his native land. The Western Ghat mountains with their
narrow paths and rugged terrain were excellent natural fortifications against
any enemy forces. It allowed small groups of Maratha warriors to withstand much
larger invading forces.</p>

<p>Moreover, Shivaji’s father, Shahaji, was a jagirdar (feudal lord) and military
officer in the Bijapur sultanate. This afforded him an excellent military
education. In addition, he also enjoyed a great deal of independence given that
Shahaji left his young son and wife, Jijabai, to marry a much younger woman. He
left the young Shivaji in Pune under the care of one of his Brahmin officers,
Dadaji Kond-dev. Shivaji spent much of his childhood in the company of soldiers.
becoming intimate with the hills, forests, and valleys of the Western Ghats.
This knowledge would prove crucial to his future military exploits.</p>

<p>The departure of Shahaji also brought Jijabai and Shivaji closer together. She
would be the one who imbued the future king with a deep passion for religion
that drove his reverance for holy men of any faith, and thrust his image in the
eyes of his subjects to mythic status. During the infancy of his realm, Shivaji
was faced with the surging Bijapuri army led by the famous general, Afzal Khan.
Local legend has it that when pondering whether to surrender, the goddess
Bhavani came to him in a vision, and urged him to fight, guaranteeing his
victory should he do so.</p>

<p>By the age of twenty, with Dadaji Kond-dev suffering an early death, Shivaji
became  independent with the land of Pune completely under his control. Without
the old Brahmin to hold him in check, and Sultan Muhammad Adil Shah falling into
a years-long illness, Shivaji had free reign to enact his plans for swaraj
(freedom).</p>

<figure class="small-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/bhavani.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/bhavani.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/bhavani.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/bhavani.jpg?nf_resize=fit&amp;w=300 300w" alt="The goddess Bhavani bestows Shivaji with a sword." />

  <figcaption>
      The goddess Bhavani bestows Shivaji with a sword.
      
      &mdash;&nbsp;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Shivaji_obtains_martial_blessings_from_Bhavani.jpg">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="shivaji-the-fox">Shivaji the fox</h2>

<p>According to Machiavelli, a ruler should be in equal parts “a fox to recognize
snares” and equal parts “a lion to scare the wolves.” The unforgiving terrain of
the Deccan, and the protection of Bhavani (herself astride a lion) imbued the
young king with his leonine heart. But, it was his unique vulpine mind that
would win him most of his early victories in decisive fashion.</p>

<h3 id="afzal-khan">Afzal Khan</h3>

<p>One of the most memorable incidents was Shivaji’s confrontation with Afzal Khan.
From 1647 to 1659, Shivaji diligently annexed land throughout the Konkan region,
the coastal area between the Arabian Sea and the Western Ghats. Most important
of his conquests was Javli, which gave him access to a highly disciplined Mavle
infantry. On the other side, Afzal Khan was a seasoned general with an
experienced army at his back. Neither side was interested in a head-to-head
clash. To cajole Shivaji into making a mistake, Afzal Khan attacked the temple
at Tuljapur and pulverized the idol of Bhavani, the family deity of the Bhonsle
clan. However, Shivaji did not take the bait, instead choosing to lure his enemy
closer.</p>

<p>Using a network of spies, Shivaji learned that Afzal Khan’s mission was to meet
with him on friendly terms in order to capture or kill him. So, Shivaji lures
the Bijapuri army through narrow mountain paths and dense jungle to have Afzal
Khan meet him near the Pratapgad fort. To the meeting held outside in a
luxurious tent, Shivaji came prepared wearing a steel cap under his turban,
chain mail under his clothes, steel claws (bagh nakh) hidden in his left hand,
and a dagger hidden in his right sleeve. As the two leaders embraced, Shivaji
waited for Afzal Khan to strike first, his dagger glancing off the Maratha’s
hidden armor. Then, still restrained in the tight embrace of the Khan, Shivaji
reaches around and disembowels the much larger Bijapuri general using the bagh
nakh hidden in his left hand.</p>

<p>With the Bijapuri general nearly dead, the Maratha army, which lay in waiting
all along the mountain paths, laid waste to the now scattered Bijapur army. In
just one day, Shivaji crippled the Bijapur Sultanate, and formally earned his
swaraj. This marked the decisive point in history when the Marathas became the
dominant force on the Western Deccan. In a show of his generosity, Shivaji freed
captured officers and soldiers, allowing them to return home with food and other
gifts. It would be this magnanimity that would win him allies throughout his
life.</p>

<figure class="small-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/afzal.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/afzal.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/afzal.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/afzal.jpg?nf_resize=fit&amp;w=300 300w" alt="Shivaji disembowels Afzal Khan at their meeting." />

  <figcaption>
      Shivaji disembowels Afzal Khan at their meeting.
      
      &mdash;&nbsp;<a class="source-link" href="http://www.columbia.edu/itc/mealac/pritchett/00routesdata/1600_1699/marathas/pratapgarh/pratapgarh.html">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h3 id="shaista-khan">Shaista Khan</h3>

<p>After the death of the Mughal Emperor Shah Jahan, Aurangzeb, his son through
Mumtaz Mahal, was crowned emperor following a struggle for the throne with his
older brother Dara Shikoh. Recognizing the threat of the young Maratha upstart,
Aurganzeb appointed the capable general, Shaista Khan, as his viceroy of the
Deccan. From 1661 - 1663, Shaista Khan harassed the Marathas, even capturing the
future Maratha capital of Pune. But Shivaji, ever the master planner, was just
waiting for the right moment to strike.</p>

<p>Shaista Khan and his army retired to Pune for Ramadan in April of 1663. Nearly
the entire Mughal encampment was asleep after a giant feast following the day’s
fast. Shivaji and a detachment of 400 soldiers snuck into the camp by pretending
to be Mughal Deccani soldiers arriving to take up their posts. Having spent his
entire childhood in Pune, Shivaji was able to lead half his soldiers discreetly
to the Khan’s quarters. By midnight the Marathas had begun making a hole in the
wall of the Khan’s harem, containing all his wives and female slaves. The other
half of band went to create a distraction by having the Khan’s musicians begin
to play as loudly as they could.</p>

<p>Soon, the women and the Khan roused from their slumber. In the ensuing skirmish,
many of Shaista Khan’s guards were killed, including one of his sons, and a
captain. The Mughal forces were thrown into disarray and forced to scatter as
Shivaji’s troops stationed outside of the encampment fell on the drowsy and
shocked Mughals. Shaista Khan would harass the Marathas no more as Aurangzeb
transferred him to the Bengal as punishment for his humiliating defeat. The
stunning and swift victory would elevate Shivaji to a hero in the eyes of his
people, and a demon in the eyes of the Mughals. The Mughals took him “to be an
incarnation of Satan; no place was believed to be proof against his entrance and
no feat impossible for him.”</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/shaista.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/shaista.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/shaista.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/shaista.jpg?nf_resize=fit&amp;w=300 300w" alt="Shivaji lunges at Shaista Khan as he makes his escape." />

  <figcaption>
      Shivaji lunges at Shaista Khan as he makes his escape.
      
      &mdash;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Shaistekhan_Surprised.jpg">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<p>Where so many kings might face large armies head-on in an open field, Shivaji
gladly played the part of the fox. He routed the Mughal viceroy in just one
night and lost only six men. Few kings are so remarkable for how little blood
their countrymen have shed to water the tree of their empire. Should anyone say
that Shivaji lacked the heart of a lion, let them know that he personally led
the raid on Pune that night, and injured Shaista Khan with his own blade, rather
than hang back in his fort while his soldiers carried out the deed. As General
Patton once said (or at least George C. Scott’s portrayal of him), “no bastard
ever won a war by dying for his country. He won it, by making the other poor
dumb bastard die for his country.” Patton famously believed in reincarnation,
and that he was a soldier in all his past lives. Perhaps his sentiment was
inspired by a former life as a Maratha soldier from the Western Ghats.</p>

<h2 id="shivajis-early-demise-and-his-legacy">Shivaji’s early demise and his legacy</h2>

<p>Shivaji would not become coronated as Chhatrapati (meaning the umbrella lord,
protector of his people) until 1674 under the auspices of Gaga Bhatt. It was
Shivaji’s secretary, Balaji Avji, who would engage Gaga Bhatt of Varanasi to
produce evidence of Shivaji’s kingly lineage and consecrate his throne. The
learned scholar, considered the Vyas of his age, delivered on his task and
declared Shivaji to be descended from the Maharanas of Udaipur in Rajasthan,
part of the solar dynasty of Ramachandra. With his coronation Shivaji hoped to
legitamize his realm, bring himself to equal status with the rulers of Dehli,
Bijapur, and Golconda, and draw those in the upper echelons of Maharashtrian
society to his side. He desired to transition from a marauding warlord to a
monarch.</p>

<p>From 1647 to 1674, Shivaji annexed territories, formed a powerful army, built a
large navy, and plundered the cities of his enemies. But, many a historian has
wondered whether Shivaji could bring a realm to prosperity during peactime, or
whether he had created a horde of pillagers and raiders like the Mongolic bands
of Timur and Hulagu? The speculation raged, due to Shivaji’s untimely death in
1680 at just 50 years of age. He was widely suspected to be poisoned by his
queen-consort, Soyra Bai, who had hoped to make her son Raja Ram the next
Chhatrapati, as opposed to Shivaji’s older son by his first wife, Sambhaji.
Nevertheless, the crown would pass to Sambhaji, who put Soyra Bai to death
either for her part in his father’s death or at her attempt to usurp the throne.
Ironically, Raja Ram would still become Chhatrapati when Sambhaji met his own
early demise.</p>

<p>Unfortunately, we can never know how Shivaji, the monarch, would realize his
vision for swaraj, because for the entirety of his short life he would be
embroiled in war. However, it is the fire that he lit in the hearts of every
Maratha soldier that would one day allow his grandson, Chhatrapati Shahu to grow
the Maratha Empire from the mouth of the Kaveri river to the sands of Peshawar.</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/empire.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/empire.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/empire.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/empire.png?nf_resize=fit&amp;w=300 300w" alt="The extent of the Maratha Empire at its peak." />

  <figcaption>
      The extent of the Maratha Empire at its peak.
      
      &mdash;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Maratha_Empire_in_1758.png">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="what-his-life-means-for-us-today">What his life means for us today</h2>

<p>In the age of democracy, one wonders what, if anything, can be learned from the
life of Shivaji. He was a man who grew up in a completely different time. He was
illiterate, his livelihood was killing, and he had eight wives. However, there
is in fact much that we must appreciate about his life even in the 21st century,
but not in the way that corporate middle managers think they can learn something
from Sun Tzu’s <em>Art of War</em>. Today, we must cope with the fact that world
leaders do not understand their people. In fact, most even show open disdain for
their own people, and gleefully plunder the public purse. Furthermore, we must
cope with the fact that they are not brave. They send the sons of the poorest
among their people to die for a war where there is no plunder, where there is no
end, and where there is no dignity upon return. And lastly, we must cope with
their imperfect morals. We must give a wide berth to their personal failings in
hopes that they may at least be competent.</p>

<p>This was not so with Chhatrapati Shivaji. His care for the common folk and
high-born alike is comparable to the Daanveer Karna. On his trip to Hyderabad in
1677 to form an alliance with the Golconda Sultan Abul Hassan Qutb Shah, Shivaji
strictly forbade his soldiers from robbing or harassing any inhabitants of the
realm, on penalty of death. For this march through the city of Hyderabad, he
distributed amongst his officers, strings of pearls, gold jewelry, and bright
armor. For the people of the city, Shivaji kept ample gold and silver on hand to
distribute to the masses, reciprocating the blessings of every household that
came to see the most feared man in the Deccan. And, his words were just as
honeyed and sweet as his gifts. His recounting of the Maratha conquests across
the country mesmerized the sedentary Sultan, who quickly accepted alliance.</p>

<p>Moreover, the evidence of the morality and godliness of Shivaji’s conduct is as
long as the evidence of military prowess. To honor his spiritual guru, Sant
Ramdas, Shivaji placed the deed to the Maratha realm at his feet. Pleased with
the gift, Ramdas accepted, and “appointed Shivaji as his vicar, and bade him
rule the realm thenceforth not as an autocratic owner, but as a servant
responsible for all his acts to a higher authority.” From that moment forward,
the Maratha standard was a plain saffron penant fashioned after the sannyasi’s
cloth, his bhagwe jhanda. A symbol of renunciation, and servitude to God, it
became an appropriate standard for the simple but reverant Maratha soldier.</p>

<p>So, I say again, what can we learn from the life of Chhatrapati Shivaji? We can
learn that victory in battle need not drench the soil with the blood of your own
people. We can learn that it is not too much to expect a leader to be as beyond
reproach in his private life as he is in his public life. We can learn that a
king who bows his head to the needs of his people, finds that his people bow
their heads even deeper in reverance. And most importantly, we can learn that
far from being a barbaric way of choosing a worthy ruler, battle is the
meritorious way of choosing a worthy ruler. The Marathas became successful on
their merit, a merit measured by their performance on the battlefield. Can we
say that democracy has chosen leaders in a more meritorious way? I think not.</p>

<figure class="small-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/shivaji/ramdas.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/shivaji/ramdas.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/shivaji/ramdas.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/shivaji/ramdas.jpg?nf_resize=fit&amp;w=300 300w" alt="Shivaji in audience with his guru, Ramdas." />

  <figcaption>
      Shivaji in audience with his guru, Ramdas.
      
      &mdash;&nbsp;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Dhurandhar_Shivaji_Ramdas_bhet.jpg">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="sources">Sources</h2>

<p>My main source is Jadunath Sarkar’s <em>Shivaji and His Times</em>.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="history" /><summary type="html"><![CDATA[When we think of the history of India, most people think about various religious figures, and a few large empires that spanned mostly the north of India. A brief history that shows up in many textbooks might be that the Indus Valley Civilization declined, the Mauryan Empire rose and fell 1500 years later, the Mughals invaded another 1500 years later, and then the British Empire occupied the country. Part of this is simply that large empires that battle with outside forces generally have more written about them. For example, we know a great deal about the Sakas even though they have produced little writing or history themselves, due to their interactions with the Greeks, Persians, and Chinese. So, to fill in some of these gaps in Indian history, in this article I will be writing about Chhatrapati Shivaji Bhonsle (b. 1630; d. 1680), one of the most energetic and successful leaders in recent memory. His actions and methods show him to be a true princeps, and after his death, his Maratha Empire would span all of India, acting as the primary power on the subcontinent in between the dominance of the Mughals and the British Raj.]]></summary></entry><entry><title type="html">Abortion and Hinduism</title><link href="https://pradyothkukkapalli.com/religion/pro-life-hinduism/" rel="alternate" type="text/html" title="Abortion and Hinduism" /><published>2023-04-10T00:00:00+00:00</published><updated>2023-04-10T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/religion/pro-life-hinduism</id><content type="html" xml:base="https://pradyothkukkapalli.com/religion/pro-life-hinduism/"><![CDATA[<p>When people discuss the issue of abortion and stem-cell research, the issue is
often seen as one that pertains to Christianity. As a Hindu, I was curious what
the classical Hindu literature has to say on the subject. One of the things that
stood out in my exploration was how explicitly they are against the practice of
abortion, but moreover how little time is spent justifying that claim. The
belief that abortion is wrong comes across as a given, like stealing is wrong,
or murdering is wrong.</p>

<ol id="markdown-toc">
  <li><a href="#the-upanishads" id="markdown-toc-the-upanishads">The Upanishads</a>    <ol>
      <li><a href="#brihadaranyaka-upanishad" id="markdown-toc-brihadaranyaka-upanishad">Brihadaranyaka Upanishad</a></li>
      <li><a href="#kaushitaki-upanishad" id="markdown-toc-kaushitaki-upanishad">Kaushitaki Upanishad</a></li>
    </ol>
  </li>
  <li><a href="#the-mahabharata" id="markdown-toc-the-mahabharata">The Mahabharata</a></li>
  <li><a href="#when-does-life-begin" id="markdown-toc-when-does-life-begin">When does life begin?</a></li>
  <li><a href="#incidence-of-abortion-in-hindu-nations" id="markdown-toc-incidence-of-abortion-in-hindu-nations">Incidence of abortion in Hindu nations</a></li>
  <li><a href="#parting-thoughts" id="markdown-toc-parting-thoughts">Parting thoughts</a></li>
  <li><a href="#bibliography" id="markdown-toc-bibliography">Bibliography</a></li>
</ol>

<h2 id="the-upanishads">The Upanishads</h2>

<p>First, let’s start by looking at the Upanishads, which expound many of the core
principles of the philosophy underlying Hinduism.</p>

<h3 id="brihadaranyaka-upanishad">Brihadaranyaka Upanishad</h3>

<p>In the chapter 4, section 3 of the <em>Brihadaranyaka Upanishad</em>, the oldest of the
Upanishads, Janaka, the king of Videha, is in discussion with the sage,
Yajnavalkya, about the <em>atman</em>, the self or the soul. When describing the state
of shedding all desires and only knowing the <em>atman</em>, Yajnavalkya says:</p>

<blockquote>
  <p>Here a father is not a father, a mother is not a mother, worlds are not
worlds, gods are not gods, and Vedas are not Vedas. <strong>Here a thief is not a
thief, an abortionist is not an abortionist, an outcaste is not an outcaste, a
pariah is not a pariah, a recluse is not a recluse, and an ascetic is not an
ascetic.</strong> Neither the good nor the bad follow him, for he has now passed
beyond all sorrows of the heart.</p>
</blockquote>

<p>Yajnavalkya describes that in this state, you are free from both the good and
bad of life. He begins by listing good things, such as fathers, mothers, gods,
etc. But then, he lists things that are bad, one of which is <q>an
abortionist</q>. Clearly, Yajnavalkya has a low opinion of the abortionist.</p>

<h3 id="kaushitaki-upanishad">Kaushitaki Upanishad</h3>

<p>Next, we turn our attention to the third chapter of the <em>Kaushitaki Upanishad</em>.
Here, Indra asks Pratardana, a king, to request a boon. When Pratardana refuses
a gift, Indra instead asks Pratardana to simply perceive Indra:</p>

<blockquote>
  <p>When a man perceives me, nothing that he does—<strong>whether it is stealing,
or performing an abortion, or killing his own father or mother</strong>—will
ever make him lose a single hair on his body. And when he has committed a sin,
his face does not lose its colour.</p>
</blockquote>

<p>Here Indra, similar to Yajnavalkya, lists abortion among things that are
obviously bad, such as theft and patricide. He shows the extent of his power, by
showing he is able to wipe away sins of any degree, and Indra certainly believes
that abortion is among those sins.</p>

<figure class="small-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indra.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indra.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indra.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indra.png?nf_resize=fit&amp;w=300 300w" alt="Indra, king of the &lt;i&gt;devas&lt;/i&gt; and &lt;i&gt;svarga&lt;/i&gt;" />

  <figcaption>
      Indra, king of the <i>devas</i> and <i>svarga</i>
      
      &mdash;&nbsp;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Indra.png">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="the-mahabharata">The Mahabharata</h2>

<p>One of the most important stories in the <em>Mahabharata</em> has to do with
Ashwatthama attempting to kill Parikshit, a fetus in the womb of Uttara.
Ashwatthama, along with Kripa and Kritavarma, attacks the Pandava camp and kills
most of the warriors on the Pandava side in their sleep. With all the sons of
the Pandavas murdered, the only viable heir to the Kuru lineage remaining was
the Parikshit, still just a fetus in the womb of Abhimanyu’s widow, Uttara. To ensure that the Pandavas have no heirs remaining, Ashwatthama directs a <em>bhramastra</em> at her womb, declaring:</p>

<blockquote>
  <p>this weapon of mine shall fall on the foetus that is in the womb of Virata’s
daughter, upon that foetus which thou, O Krishna, art desirous of protecting.</p>
</blockquote>

<p>In response to Ashwatthama’s declaration, Krishna declares that he will not succeed:</p>

<blockquote>
  <p>The fall of this mighty weapon will not be fruitless. The foetus will die. But
being dead, it will live again and have a long life! As regards thyself, all
wise know thee for a coward and a sinful wretch! <strong>Always engaged in sinful
acts, thou art the slayer of children. For this reason, thou must have to bear
the fruit of these thy sins.</strong></p>
</blockquote>

<p>Ashwatthama is condemned in the harshest terms for his act. He is not condemned
by an ordinary man. He is not even condemned by a sage, or king. He is condemned
by Krishna, who revealed to Arjuna on the fields of Kurukshetra that he is the
incarnation of Vishnu, the lord of the universe himself. As punishment for his
act, Krishna afflicts him with the most ghastly curse:</p>

<blockquote>
  <p>For 3,000 years thou shalt wander over this earth, without a companion and
without being able to talk with anyone. Alone and without anybody by thy side,
thou shalt wander through diverse countries, <strong>O wretch, thou shalt have no
place in the midst of men. The stench of pus and blood shall emanate from
thee, and inaccessible forests and dreary moors shall by thy abode!</strong> Thou
shalt wander over the Earth, O thou sinful soul, with the weight of all
diseases on thee.</p>
</blockquote>

<p>Much like Indra, it is safe to say that Krishna, through his punishment of
Ashwatthama, condemns in no uncertain terms the act of abortion.</p>

<figure class="small-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/uttara.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/uttara.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/uttara.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/uttara.jpg?nf_resize=fit&amp;w=300 300w" alt="Krishna revives Uttara's stillborn child, Parikshit" />

  <figcaption>
      Krishna revives Uttara's stillborn child, Parikshit
      
      &mdash;&nbsp;<a class="source-link" href="https://commons.wikimedia.org/wiki/File:Krishna_give_life_to_dead_child_of_Uttara.jpg">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<h2 id="when-does-life-begin">When does life begin?</h2>

<p>The question of when life begins is a complicated one as well. Many who consider
themselves pro-life say that the only consistent position is that life begins at
conception. There is actually some Upanshadic literature that comments on this
topic. In one of the minor Upanishads, the <em>Garbha Upanishad</em>, literally the
Upanishad of the womb, we see a description of the development of the fetus. The
Upanishad tells us that the fetus becomes united with the <em>atma</em> in the seventh
month:</p>

<blockquote>
  <p>… it (the embryo formed in the womb) is like water in the first night;
in seven nights, it is like a bubble; at the end of half a month, it becomes a
ball. At the end of a month, it is hardened; in two months, the head is
formed; in three months, the region about the feet; and in the fourth month,
the region about the stomach and the loins and also ankle is formed; in the
fifth month, the back (or spinal) bone; in the sixth, the face of the nose,
eyes, and ears; <strong>in the seventh, it becomes united with Jiva (Atma)</strong>; in the
eighth month, it becomes full (of all organs); in the ninth, it becomes fatty</p>
</blockquote>

<p>Does a fetus without an <em>atma</em> constitute a human life? Does the absence of the
<em>atma</em> in the body mean that abortion before the seventh month is fine? To help
answer this question, I attempted to determine at which month of the pregnancy
Ashwatthama attempted to kill Parikshit. However, the best we could do is say
that Parikshit was no older than seven months. There is no direct evidence of
this, but we could infer it from the fact that Abhimanyu and Uttara were married
for a mere seven months. After his death, Uttara lamenting the loss of Abhimanyu
tells us:</p>

<blockquote>
  <p>Thy union with me in this world had, it seems, been ordained for only six
months, <strong>for in the seventh, O hero, thou hast been bereft of life!</strong></p>
</blockquote>

<p>There was no definitive guidance that I was able to find on this matter during
my search. However, I will say that even though the <em>atma</em> unites with the fetus
in the seventh month, there is still no definitive time during the seventh month
that this happens.</p>

<h2 id="incidence-of-abortion-in-hindu-nations">Incidence of abortion in Hindu nations</h2>

<p>So, why is this issue of importance. Why should we care? Despite the injunctions
from classical Hindu literature, when we look at the two largest Hindu-majority
nations in the world, India and Nepal, we see that abortion is rampant. India
has <a href="https://data.worldbank.org/indicator/SP.POP.TOTL?locations=IN">1.38 billion people</a>, out of whom about <a href="https://www.pewresearch.org/fact-tank/2021/09/21/key-findings-about-the-religious-composition-of-india/">80% are
Hindus</a>. Yet, according to <a href="https://www.thelancet.com/journals/langlo/article/PIIS2214-109X(17)30453-9/fulltext">an article in <em>The
Lancet</em></a>, it is estimated that 15.6 million abortions
were performed in the year 2015 based on data from six Indian states. This meant
<strong>one in three pregnancies in India ended in abortion.</strong></p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indian-abortions.jpg?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indian-abortions.jpg?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indian-abortions.jpg?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/pro-life-hinduism/indian-abortions.jpg?nf_resize=fit&amp;w=300 300w" alt="Pregnancies by outcome in India 2015" />

  <figcaption>
      Pregnancies by outcome in India 2015
      
      &mdash;<a class="source-link" href="https://www.thelancet.com/journals/langlo/article/PIIS2214-109X(17)30453-9/">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<p>Nepal has 26 million people, out of whom <a href="https://mofa.gov.np/about-nepal/nepal-profile/">81% are Hindus</a>. Yet,
according to an <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5568822/">article published with the NIH</a>, in 2014, Nepalese
women had 323,100 abortions with 56 abortions per 100 live births. In other
words, just like in India, approximately <strong>one in three pregnancies that year
ended in abortion</strong>.</p>

<p>These are staggering numbers. So, how can two nations with about 1.1 billion
Hindus between them do this, despite the words of Yajnavalkya, Indra, and
Krishna?</p>

<h2 id="parting-thoughts">Parting thoughts</h2>

<p>This evidence is presented to the reader to inform them about the true
prevalence of abortion among Hindus, as well as relevant theological material on
the matter. From there, we can make a conscious decision about how our actions
affect our <em>karma</em>. Whether you think abortion should legal or illegal, it is
without a doubt that we should at least find a way to decrease the need for all
of these abortions.</p>

<p>I also understand that this analysis is not perfect, because I have read these
works in translation. Translators are often not perfect, but learning Sanskrit
and reading the original source just means that now I become the imperfect
translator. I might try reading the original Sanskrit in the future, but for now
I trust that the translators, Patrick Olivelle and Kisari Mohan Ganguli, have
done an honest job.</p>

<h2 id="bibliography">Bibliography</h2>

<ul>
  <li>Olivelle, Patrick. <em>Upanisads</em>. Oxford University Press, 2008.</li>
  <li>Ganguli, Kisari Mohan, translator. <em>The Mahabharata of Krishna-Dwaipayana Vyasa, Volume 3. Pratap Chandra Roy</em>, <em>Sacred Texts</em>, <a href="https://sacred-texts.com/hin/maha/index.htm">sacred-texts.com</a>, Accessed 2021.</li>
</ul>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="religion" /><summary type="html"><![CDATA[When people discuss the issue of abortion and stem-cell research, the issue is often seen as one that pertains to Christianity. As a Hindu, I was curious what the classical Hindu literature has to say on the subject. One of the things that stood out in my exploration was how explicitly they are against the practice of abortion, but moreover how little time is spent justifying that claim. The belief that abortion is wrong comes across as a given, like stealing is wrong, or murdering is wrong.]]></summary></entry><entry><title type="html">Building code for a utility process with Electron Forge and Webpack</title><link href="https://pradyothkukkapalli.com/tech/electron-utility-process/" rel="alternate" type="text/html" title="Building code for a utility process with Electron Forge and Webpack" /><published>2023-02-20T00:00:00+00:00</published><updated>2023-02-20T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/electron-utility-process</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/electron-utility-process/"><![CDATA[<aside class="danger-aside">
  <div class="danger-header">
    <span>Danger!!!</span>
  </div>
  <div class="aside-content">
    
<p>I would no longer recommend this approach as you will still run into problem when running <code class="language-html highlighter-rouge">forge make</code> or <code class="language-html highlighter-rouge">forge package</code>. Instead please use the <a href="https://www.electronforge.io/config/plugins/vite">vite plugin</a> instead.</p>

  </div>
</aside>

<p>When developing an <a href="https://electronjs.org">Electron</a> app, you will often want to run
expensive or long-running operations in a different process. In the past, this
might have been done using the <a href="https://nodejs.org/api/child_process.html"><code class="language-html highlighter-rouge">child_process</code></a> module. But,
Electron has recently introduced a new <a href="https://www.electronjs.org/docs/latest/api/utility-process"><code class="language-html highlighter-rouge">utilityProcess</code></a> that
uses the Chromium <a href="https://chromium.googlesource.com/chromium/src/+/main/docs/mojo_and_services.md">Services API</a>. This article outlines how to compile the
code for your <code class="language-html highlighter-rouge">utilityProcess</code> using your existing Webpack config.</p>

<ol id="markdown-toc">
  <li><a href="#the-problem-how-to-compile-the-utilityprocess-code-with-webpack" id="markdown-toc-the-problem-how-to-compile-the-utilityprocess-code-with-webpack">The problem: how to compile the <code class="language-html highlighter-rouge">utilityProcess</code> code with Webpack?</a></li>
  <li><a href="#electron-forges-webpack-config" id="markdown-toc-electron-forges-webpack-config">Electron Forge’s Webpack config</a></li>
  <li><a href="#the-solution-write-our-own-electron-forge-plugin" id="markdown-toc-the-solution-write-our-own-electron-forge-plugin">The solution: write our own Electron Forge plugin</a></li>
  <li><a href="#appendix-getting-a-first-party-plugin" id="markdown-toc-appendix-getting-a-first-party-plugin">Appendix: getting a first-party plugin</a></li>
</ol>

<aside class="warning-aside">
  <div class="warning-header">
    <span>Warning</span>
  </div>
  <div class="aside-content">
    
<p>The rest of this article will be written with Typescript in mind, but the code
snippets should be roughly the same in Javascript.</p>

  </div>
</aside>

<h2 id="the-problem-how-to-compile-the-utilityprocess-code-with-webpack">The problem: how to compile the <code class="language-html highlighter-rouge">utilityProcess</code> code with Webpack?</h2>

<p>To initialize the <code class="language-html highlighter-rouge">utilityProcess</code>, you must provide a node module path, like so:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">utilityProcess</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">electron</span><span class="dl">"</span><span class="p">;</span>

<span class="k">this</span><span class="p">.</span><span class="nx">child</span> <span class="o">=</span> <span class="nx">utilityProcess</span>
  <span class="p">.</span><span class="nf">fork</span><span class="p">(</span><span class="dl">"</span><span class="s2">./utilityCode</span><span class="dl">"</span><span class="p">)</span>
  <span class="p">.</span><span class="nf">on</span><span class="p">(</span><span class="dl">"</span><span class="s2">spawn</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">spawned new utilityProcess</span><span class="dl">"</span><span class="p">))</span>
  <span class="p">.</span><span class="nf">on</span><span class="p">(</span><span class="dl">"</span><span class="s2">exit</span><span class="dl">"</span><span class="p">,</span> <span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">existing utilityProcess</span><span class="dl">"</span><span class="p">));</span>
</code></pre></div></div>

<p>This code assumes that you have a <code class="language-html highlighter-rouge">utilityCode.js</code> file that is a Node module.
But, this doesn’t work so well if you’re building all of your other code with
Webpack. You might be using Typescript, and integrating other compilation steps.
Naturally, you would want all of your <code class="language-html highlighter-rouge">utilityProcess</code> code to also run through
Webpack first.</p>

<h2 id="electron-forges-webpack-config">Electron Forge’s Webpack config</h2>

<p>When you initialize an Electron project with <a href="https://www.electronforge.io/">Electron Forge</a>,
it initializes a Webpack config for you. This configuration consists of the
following files:</p>

<ul>
  <li><code class="language-html highlighter-rouge">webpack.rules.config.ts</code>: which Webpack loaders to use for this project.</li>
  <li><code class="language-html highlighter-rouge">webpack.main.config.ts</code>: the Webpack config for the main process.</li>
  <li><code class="language-html highlighter-rouge">webpack.renderer.config.ts</code>: the Webpack config for the renderer process.</li>
  <li><code class="language-html highlighter-rouge">webpack.plugins.ts</code>: contains plugins for the renderer process.</li>
  <li><code class="language-html highlighter-rouge">forge.config.ts</code>: passes the main and renderer process configs to Forge.</li>
</ul>

<p>The <a href="https://www.electronforge.io/config/plugins/webpack"><code class="language-html highlighter-rouge">WebpackPlugin</code></a> is used by Electron Forge to run Webpack
for the code of each process, but there’s no API for adding a <code class="language-html highlighter-rouge">utilityProcess</code>.</p>

<h2 id="the-solution-write-our-own-electron-forge-plugin">The solution: write our own Electron Forge plugin</h2>

<p>First, we create a new plugin called <code class="language-html highlighter-rouge">UtilityProcessPlugin</code> in a separate file called <code class="language-html highlighter-rouge">utility.plugin.ts</code>:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">webpack</span><span class="p">,</span> <span class="nx">Configuration</span> <span class="kd">as </span><span class="nx">RawWebpackConfiguration</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">webpack</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">PluginBase</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@electron-forge/plugin-base</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">ForgeHookMap</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">@electron-forge/shared-types</span><span class="dl">"</span><span class="p">;</span>

<span class="k">export</span> <span class="k">default</span> <span class="kd">class</span> <span class="nc">UtilityProcessPlugin</span> <span class="kd">extends</span> <span class="nc">PluginBase</span><span class="o">&lt;</span><span class="nx">RawWebpackConfiguration</span><span class="o">&gt;</span> <span class="p">{</span>
  <span class="nx">name</span> <span class="o">=</span> <span class="dl">"</span><span class="s2">utility-process</span><span class="dl">"</span><span class="p">;</span>

  <span class="nf">getHooks</span><span class="p">():</span> <span class="nx">ForgeHookMap</span> <span class="p">{</span>
    <span class="k">return</span> <span class="p">{</span>
      <span class="na">generateAssets</span><span class="p">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">generateAssets</span><span class="p">.</span><span class="nf">bind</span><span class="p">(</span><span class="k">this</span><span class="p">),</span>
    <span class="p">};</span>
  <span class="p">}</span>

  <span class="k">private</span> <span class="k">async</span> <span class="nf">generateAssets</span><span class="p">():</span> <span class="nb">Promise</span><span class="o">&lt;</span><span class="k">void</span><span class="o">&gt;</span> <span class="p">{</span>
    <span class="k">return</span> <span class="k">new</span> <span class="nc">Promise</span><span class="p">((</span><span class="nx">resolve</span><span class="p">,</span> <span class="nx">reject</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
      <span class="nf">webpack</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">config</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">stats</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
        <span class="k">if </span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
          <span class="nf">reject</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
          <span class="k">return</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">if </span><span class="p">(</span><span class="nx">stats</span><span class="p">?.</span><span class="nf">hasErrors</span><span class="p">())</span> <span class="p">{</span>
          <span class="kd">const</span> <span class="nx">json</span> <span class="o">=</span> <span class="nx">stats</span><span class="p">.</span><span class="nf">toJson</span><span class="p">();</span>
          <span class="k">for </span><span class="p">(</span><span class="kd">const</span> <span class="nx">error</span> <span class="k">of</span> <span class="nx">json</span><span class="p">.</span><span class="nx">errors</span> <span class="o">??</span> <span class="p">[])</span> <span class="p">{</span>
            <span class="nf">reject</span><span class="p">(</span><span class="k">new</span> <span class="nc">Error</span><span class="p">(</span><span class="s2">`</span><span class="p">${</span><span class="nx">error</span><span class="p">.</span><span class="nx">message</span><span class="p">}</span><span class="s2">\n</span><span class="p">${</span><span class="nx">error</span><span class="p">.</span><span class="nx">stack</span><span class="p">}</span><span class="s2">`</span><span class="p">));</span>
            <span class="k">return</span><span class="p">;</span>
          <span class="p">}</span>
        <span class="p">}</span>
        <span class="nf">resolve</span><span class="p">();</span>
      <span class="p">});</span>
    <span class="p">});</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>This plugin takes a Webpack config and runs the Webpack compiler on it. Then, we create a Webpack configuration for the <code class="language-html highlighter-rouge">utilityProcess</code>:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">Configuration</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">webpack</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">path</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">path</span><span class="dl">"</span><span class="p">;</span>

<span class="k">import</span> <span class="p">{</span> <span class="nx">rules</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./webpack.rules</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">const</span> <span class="nx">modulePath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nf">resolve</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">,</span> <span class="dl">"</span><span class="s2">dist_utility/utility_process</span><span class="dl">"</span><span class="p">);</span>

<span class="k">export</span> <span class="kd">const</span> <span class="nx">utilityConfig</span><span class="p">:</span> <span class="nx">Configuration</span> <span class="o">=</span> <span class="p">{</span>
  <span class="na">entry</span><span class="p">:</span> <span class="dl">"</span><span class="s2">./src/utility.ts</span><span class="dl">"</span><span class="p">,</span> <span class="c1">// Change to your own entry point</span>
  <span class="na">target</span><span class="p">:</span> <span class="dl">"</span><span class="s2">node</span><span class="dl">"</span><span class="p">,</span>
  <span class="na">module</span><span class="p">:</span> <span class="p">{</span>
    <span class="nx">rules</span><span class="p">,</span>
  <span class="p">},</span>
  <span class="na">output</span><span class="p">:</span> <span class="p">{</span>
    <span class="na">path</span><span class="p">:</span> <span class="nx">modulePath</span><span class="p">,</span>
    <span class="na">filename</span><span class="p">:</span> <span class="dl">"</span><span class="s2">index.js</span><span class="dl">"</span><span class="p">,</span>
  <span class="p">},</span>
  <span class="na">resolve</span><span class="p">:</span> <span class="p">{</span>
    <span class="na">extensions</span><span class="p">:</span> <span class="p">[</span><span class="dl">"</span><span class="s2">.js</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">.ts</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">.jsx</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">.tsx</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">.css</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">.json</span><span class="dl">"</span><span class="p">],</span>
  <span class="p">},</span>
  <span class="c1">// TODO: find a way to infer this based on whether we run electron-forge start</span>
  <span class="c1">// or package.</span>
  <span class="na">mode</span><span class="p">:</span> <span class="dl">"</span><span class="s2">development</span><span class="dl">"</span><span class="p">,</span>
<span class="p">};</span>
</code></pre></div></div>

<p>This configuration will look for a <code class="language-html highlighter-rouge">src/utility.ts</code> file as the entrypoint. Feel free to change this to whatever file is your entrypoint. Then, it will compile the code and output it to a <code class="language-html highlighter-rouge">dist_utility/utility_process</code> directory. Then, we need to tell Electron Forge about our plugin, by modifying <code class="language-html highlighter-rouge">forge.config.ts</code>:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="c1">// ... other imports</span>
<span class="k">import</span> <span class="p">{</span> <span class="nx">utilityConfig</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./webpack.utility.config</span><span class="dl">"</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">UtilityProcessPlugin</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">./utility.plugin</span><span class="dl">"</span><span class="p">;</span>

<span class="kd">const</span> <span class="nx">config</span><span class="p">:</span> <span class="nx">ForgeConfig</span> <span class="o">=</span> <span class="p">{</span>
  <span class="c1">// ... other configuration</span>
  <span class="na">plugins</span><span class="p">:</span> <span class="p">[</span>
    <span class="k">new</span> <span class="nc">UtilityProcessPlugin</span><span class="p">(</span><span class="nx">utilityConfig</span><span class="p">),</span>
    <span class="c1">// ... other plugins</span>
  <span class="p">],</span>
<span class="p">};</span>

<span class="k">export</span> <span class="k">default</span> <span class="nx">config</span><span class="p">;</span>
</code></pre></div></div>

<p>Next, to make sure our main process knows whether this code has been compiled
to, we use the Webpack <a href="https://webpack.js.org/plugins/define-plugin/"><code class="language-html highlighter-rouge">DefinePlugin</code></a> to define a global
variable in the main process that contains the location of the compiled
<code class="language-html highlighter-rouge">utilityProcess</code> code. In the <code class="language-html highlighter-rouge">webpack.main.config.ts</code> file, we add:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">Configuration</span><span class="p">,</span> <span class="nx">DefinePlugin</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">webpack</span><span class="dl">"</span><span class="p">;</span>
<span class="c1">// ... other imports</span>

<span class="kd">const</span> <span class="nx">modulePath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nf">resolve</span><span class="p">(</span><span class="nx">__dirname</span><span class="p">,</span> <span class="dl">"</span><span class="s2">dist_utility/utility_process</span><span class="dl">"</span><span class="p">);</span>

<span class="k">export</span> <span class="kd">const</span> <span class="nx">mainConfig</span><span class="p">:</span> <span class="nx">Configuration</span> <span class="o">=</span> <span class="p">{</span>
  <span class="c1">// ... other configuration</span>
  <span class="na">plugins</span><span class="p">:</span> <span class="p">[</span>
    <span class="k">new</span> <span class="nc">DefinePlugin</span><span class="p">({</span>
      <span class="na">UTILITY_PROCESS_MODULE_PATH</span><span class="p">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">stringify</span><span class="p">(</span><span class="nx">modulePath</span><span class="p">),</span>
    <span class="p">}),</span>
  <span class="p">],</span>
<span class="p">};</span>
</code></pre></div></div>

<p>Finally, we can modify our code in the main process to load our compiled
<code class="language-html highlighter-rouge">utilityProcess</code>:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">utilityProcess</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">electron</span><span class="dl">"</span><span class="p">;</span>

<span class="kr">declare</span> <span class="kd">const</span> <span class="nx">UTILITY_PROCESS_MODULE_PATH</span><span class="p">:</span> <span class="kr">string</span><span class="p">;</span>

<span class="k">this</span><span class="p">.</span><span class="nx">child</span> <span class="o">=</span> <span class="nx">utilityProcess</span>
  <span class="p">.</span><span class="nf">fork</span><span class="p">(</span><span class="nx">UTILITY_PROCESS_MODULE_PATH</span><span class="p">)</span>
  <span class="p">.</span><span class="nf">on</span><span class="p">(</span><span class="dl">"</span><span class="s2">spawn</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">spawned new utilityProcess</span><span class="dl">"</span><span class="p">))</span>
  <span class="p">.</span><span class="nf">on</span><span class="p">(</span><span class="dl">"</span><span class="s2">exit</span><span class="dl">"</span><span class="p">,</span> <span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="nx">console</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">existing utilityProcess</span><span class="dl">"</span><span class="p">));</span>
</code></pre></div></div>

<h2 id="appendix-getting-a-first-party-plugin">Appendix: getting a first-party plugin</h2>

<p>I have opened a feature request with the Electron Forge team to help push this
proposal into the <code class="language-html highlighter-rouge">WebpackPlugin</code>. Please see
<a href="https://github.com/electron/forge/issues/3169">https://github.com/electron/forge/issues/3169</a> for progress.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[Danger!!! I would no longer recommend this approach as you will still run into problem when running forge make or forge package. Instead please use the vite plugin instead.]]></summary></entry><entry><title type="html">Open external URLs from an Electron app</title><link href="https://pradyothkukkapalli.com/tech/open-external-urls-electron/" rel="alternate" type="text/html" title="Open external URLs from an Electron app" /><published>2023-01-15T00:00:00+00:00</published><updated>2023-01-15T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/open-external-urls-electron</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/open-external-urls-electron/"><![CDATA[<p>Oftentimes in an Electron app, you’ll want to open a URL that points to a page
outside of your app. By default, the app will open the URL directly in your app
rather than the user’s browser. To change this behavior, we first have to
register a window open handler on your app’s <code class="language-html highlighter-rouge">BrowserWindow</code>:</p>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">shell</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">"</span><span class="s2">electron</span><span class="dl">"</span><span class="p">;</span>

<span class="nx">mainWindow</span><span class="p">.</span><span class="nx">webContents</span><span class="p">.</span><span class="nf">setWindowOpenHandler</span><span class="p">((</span><span class="nx">details</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">shell</span><span class="p">.</span><span class="nf">openExternal</span><span class="p">(</span><span class="nx">details</span><span class="p">.</span><span class="nx">url</span><span class="p">);</span> <span class="c1">// Open URL in user's browser.</span>
  <span class="k">return</span> <span class="p">{</span> <span class="na">action</span><span class="p">:</span> <span class="dl">"</span><span class="s2">deny</span><span class="dl">"</span> <span class="p">};</span> <span class="c1">// Prevent the app from opening the URL.</span>
<span class="p">})</span>
</code></pre></div></div>

<p>This handler prevents all window open requests from changing the URL inside your
app, and instead causes the URL to open in the user’s browser. However, this
only works if your links open new windows/tabs. You can have anchor tags with
<code class="language-html highlighter-rouge">target="_blank"</code>, or call <code class="language-html highlighter-rouge">window.open</code> with a <code class="language-html highlighter-rouge">_blank</code> target:</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="c">&lt;!-- Allow the user to click and open a link. --&gt;</span>
<span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">"http://example.com/abc"</span> <span class="na">target=</span><span class="s">"_blank"</span><span class="nt">&gt;</span>Some link<span class="nt">&lt;/a&gt;</span>
</code></pre></div></div>

<div class="language-typescript highlighter-rouge"><div class="highlight"><pre class="syntax"><code><span class="c1">// Open a URL programmatically.</span>
<span class="nb">window</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="dl">"</span><span class="s2">http://example.com/abc</span><span class="dl">"</span><span class="p">,</span> <span class="dl">"</span><span class="s2">_blank</span><span class="dl">"</span><span class="p">);</span>
</code></pre></div></div>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[Oftentimes in an Electron app, you’ll want to open a URL that points to a page outside of your app. By default, the app will open the URL directly in your app rather than the user’s browser. To change this behavior, we first have to register a window open handler on your app’s BrowserWindow:]]></summary></entry><entry><title type="html">The Future of Search</title><link href="https://pradyothkukkapalli.com/tech/future-of-search/" rel="alternate" type="text/html" title="The Future of Search" /><published>2022-12-22T00:00:00+00:00</published><updated>2022-12-22T00:00:00+00:00</updated><id>https://pradyothkukkapalli.com/tech/future-of-search</id><content type="html" xml:base="https://pradyothkukkapalli.com/tech/future-of-search/"><![CDATA[<p>I recently came across DKB IO’s post called <a href="https://dkb.io/post/google-search-is-dying">Google Search is Dying</a> on
Hacker News. It’s definitely good food for thought, and really gets at some of
the problems that make search a difficult space. In particular, the post brings
up how people often search for things in Google by adding <q>reddit</q> to the end of
their search queries. They may also append <q>amazon,</q> <q>stackoverflow,</q> or
<q>stackexchange</q> depending on what they’re searching for.</p>

<h2 id="google-as-a-forum-search">Google as a forum search</h2>

<p>Once we dig a little deeper, it makes sense why people are doing this. There are
essentially three categories of search queries.</p>

<ul>
  <li><strong>Facts:</strong> examples are “temperature outside,” “NFL scores,” “height of
Michael Jordan,” etc. In other words, queries that have a clear 1:1 query and
answer. Google is amazing at these.</li>
</ul>

<figure class="medium-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/michael-jordan-height.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/michael-jordan-height.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/michael-jordan-height.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/michael-jordan-height.png?nf_resize=fit&amp;w=300 300w" alt="The Google search infographic when you lookup Michael Jordan's height. The
answer is right there, and there isn't even a need to look into one of the
search results." />

  <figcaption>
      The Google search infographic when you lookup Michael Jordan's height. The
answer is right there, and there isn't even a need to look into one of the
search results.
      
  </figcaption>
</figure>

<ul>
  <li><strong>Objective information:</strong> examples are “George Washington,” “Nelson Mandela,”
“The Seven Years War,” etc. These are queries that have objective information
attached to them. Usually for these types of queries the Wikipedia link is a
good starting point, and the user might have to jump to the external links
inside to get some in depth information. In many cases, Google will also
present other information about these queries in the other search results, but
these are “low trust” results, or worse versions of Wikipedia such as
Britannica. They have a lot of ads, they are possibly unmaintained, and they
have questionable veracity.</li>
</ul>

<figure class="medium-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/seven-years-war.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/seven-years-war.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/seven-years-war.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/seven-years-war.png?nf_resize=fit&amp;w=300 300w" alt="When you Google
&lt;q&gt;the seven years war&lt;/q&gt; the top hit you get is Wikipedia." />

  <figcaption>
      When you Google
<q>the seven years war</q> the top hit you get is Wikipedia.
      
  </figcaption>
</figure>

<ul>
  <li><strong>Subjective information:</strong> examples are “What’s the best programming
language,” “how to get into Harvard,” etc. These are queries which are handled
even worse by Google. And, these are the queries that people often append
“reddit” for. They do this, because that will lead to a place where the topic
is discussed, multiple inputs are provided, and there is feedback on those
inputs so that you can judge all of the info before making a decision.</li>
</ul>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/how-to-get-into-harvard.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/how-to-get-into-harvard.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/how-to-get-into-harvard.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/how-to-get-into-harvard.png?nf_resize=fit&amp;w=300 300w" alt="&lt;q&gt;how to
get into harvard&lt;/q&gt; yields subpar results compared to the previous two.
goingivy.com is a blog post to advertise for the company's consulting services.
People would usually prefer information from former students and parents, hence
they may try appending &lt;q&gt;collegeconfidential&lt;/q&gt;." />

  <figcaption>
      <q>how to
get into harvard</q> yields subpar results compared to the previous two.
goingivy.com is a blog post to advertise for the company's consulting services.
People would usually prefer information from former students and parents, hence
they may try appending <q>collegeconfidential</q>.
      
  </figcaption>
</figure>

<p>Ultimately, if there is no authoritative source on a matter, people want a
<em>democratic</em> answer, hence the desire to search on a forum. If there’s no
factual result, they want to see a discussion involving real people so they can
weigh the many sides of an argument themselves. Google is heavily optimized for
the first category of queries, and partly optimized for the second category of
queries. The third set usually surfaces untrustworthy results, such as random
blog posts, or SEO spam sites.</p>

<p>If Reddit, StackOverflow, and other forums have the information that people are
really looking for, why do people still use Google? Unlike Google, all of these
disparate forum sites have lackluster search. Google unsurprisingly has
best-in-class search.</p>

<h2 id="democratized-information">Democratized information</h2>

<p>Implicitly, people are looking for expert opinions on topics. They want to
solicit the thoughts of someone who has already looked into it, and let other
people give their thoughts. Of course they could pose their own question on a
forum, but that would take time for the question to be answered (if it is even
popular). Forum search also accounts for the long tail of information.
Information that is sufficiently niche that Google cannot serve anything useful
or trustworthy. For example, if you search for “Guliga daiva” after watching
<em>Kantara</em> (extremely niche subject), you get a bunch of surface level news
articles and blog posts. There is nothing authoritative or democratic.</p>

<figure class="medium-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/guliga-daiva.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/guliga-daiva.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/guliga-daiva.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/guliga-daiva.png?nf_resize=fit&amp;w=300 300w" alt="Searching for
&lt;q&gt;guliga daiva&lt;/q&gt; just leads you to some obscure blogs." />

  <figcaption>
      Searching for
<q>guliga daiva</q> just leads you to some obscure blogs.
      
  </figcaption>
</figure>

<p>Recently, there have been great strides in large language models. ChatGPT has
gone viral. If what people really want is an expert opinion on topics, why can’t
we make a ChatGPT for all of the “experts” we trust? For example, if you want to
know what Mahatma Gandhi would think about the “antifa” riots, we could fine
tune a ChatGPT style LLM on Gandhi’s writings and sayings, and generate
something plausible.</p>

<p>However, the main issue that we currently see with ChatGPT and others is that
they struggle with surfacing actual facts. For example, if you have never read
William Faulkner’s <em>Absalom, Absalom!</em> then you would not be able to tell that
while ChatGPT’s synopsis of the novel sounds plausible, it’s actually
inaccurate. Thomas Sutpen does have a son named Henry, but Quentin is not his
grandson.  He is the narrator of the story and belongs to the Compson family.</p>

<figure class="medium-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/absalom-absalom.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/absalom-absalom.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/absalom-absalom.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/absalom-absalom.png?nf_resize=fit&amp;w=300 300w" alt="ChatGPT attempts to give a synopsis of &lt;i&gt;Absalom, Absalom!&lt;/i&gt;, but gets some
facts incorrect." />

  <figcaption>
      ChatGPT attempts to give a synopsis of <i>Absalom, Absalom!</i>, but gets some
facts incorrect.
      
  </figcaption>
</figure>

<h2 id="explainable-ais">Explainable AIs</h2>

<p>Solving the accuracy problem is the main issue that prevents us from using LLMs
for information retrieval. Some models such as <a href="https://www.deepmind.com/publications/gophercite-teaching-language-models-to-support-answers-with-verified-quotes">GopherCite</a>,
<a href="https://openai.com/blog/webgpt/">WebGPT</a>, and <a href="https://ai.googleblog.com/2022/01/lamda-towards-safe-grounded-and-high.html">LaMDA</a> attempt to do this by essentially composing
the answers by augmenting the response with search engine results. However, if
people do not trust many search results for most opinionated topics, then using
search results to provide post facto justification for the responses would not
give users any confidence.</p>

<p>Instead what we really want is to have an explainable AI that can cite how it
arrived an answer using the resources that were used to <em>train</em> it. This would
hit several birds with one stone. It would give users confidence that the
training was used with data that did not violate anyone’s privacy, that the data
is from trustworthy sources, and that the response was formed sensibly.
Obviously this is an extremely hard problem to solve, but it’s absolutely
essential for us to be able to use LLMs widely.</p>

<p>As <a href="https://arxiv.org/abs/2010.00711"><em>A Survey of the State of Explainable AI for Natural Language Processing</em>
(arXiv:2010.00711)</a> explains, we are looking for a global
self-explaining model. Many explainable language models are <em>local</em>, meaning
they explain what parts of your input were most important. What we care about is
<em>global</em> explainability, which means we want an explanation of the output
regardless of the input. We want an explanation based on what the model actually
learned.</p>

<figure class="medium-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/realm.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/realm.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/realm.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/realm.png?nf_resize=fit&amp;w=300 300w" alt="A high-level overview of
the  Retrieval Augmented Language Model (REALM)." />

  <figcaption>
      A high-level overview of
the  Retrieval Augmented Language Model (REALM).
      
      &mdash;<a class="source-link" href="http://proceedings.mlr.press/v119/guu20a.html">Image&nbsp;Source</a>
      
  </figcaption>
</figure>

<p>One interesting approach is <a href="http://proceedings.mlr.press/v119/guu20a.html">REALM</a>, which trains a knowledge retrieval
model that sits in front of a masked language model. The knowledge retrieval
model provides documents that can be used to fill in the masked tokens in the
language model’s response. Because the knowledge retrieval model is essentially
a function that given a query and a document generates a relevance score, we
can use the model to interpret which documents were used to inform the response
you received. Breaking down the documents into paragraphs or sections could also
help us rate the relevance of each part of a document.</p>

<h2 id="parting-thoughts">Parting thoughts</h2>

<p>No matter how well an LLM can formulate answers, or how well it’s able to
explain its answers, many humans will always prefer to see the thoughts and
opinions of real people. But, LLMs can help you summarize long threads, and cite
the most important comments in a thread.</p>

<p>There is also a long tail of information buried in
sources that are extremely hard to surface through regular Google search
results. Often, if you have an obscure topic, you can try looking up the
information in Google Books. For example, we could try looking up Guliga daiva:</p>

<figure class="full-width">
  
  
  <img src="https://pradyothkukkapalli.com/assets/images/future-of-search/google-books.png?nf_resize=fit&amp;w=600" srcset="https://pradyothkukkapalli.com/assets/images/future-of-search/google-books.png?nf_resize=fit&amp;w=600 600w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/google-books.png?nf_resize=fit&amp;w=450 450w,
          https://pradyothkukkapalli.com/assets/images/future-of-search/google-books.png?nf_resize=fit&amp;w=300 300w" alt="Some high quality
sources if you look up &lt;q&gt;Guliga daiva&lt;/q&gt;." />

  <figcaption>
      Some high quality
sources if you look up <q>Guliga daiva</q>.
      
  </figcaption>
</figure>

<p>These searches will often surface some high quality sources, but you might have
to do quite a bit of reading to get the information you’re looking for. The same
is true for scientific topics where relevant answers are only in dense research
papers. An LLM that explains itself can be used to present the user with the
paragraphs in books, papers, and long forum threads that are most relevant,
along with an easy to understand summarization. In short, LLMs will not replace
search, but will help to create a more useful <em>interface</em> for search.</p>]]></content><author><name>Pradyoth Kukkapalli</name></author><category term="tech" /><summary type="html"><![CDATA[I recently came across DKB IO’s post called Google Search is Dying on Hacker News. It’s definitely good food for thought, and really gets at some of the problems that make search a difficult space. In particular, the post brings up how people often search for things in Google by adding reddit to the end of their search queries. They may also append amazon, stackoverflow, or stackexchange depending on what they’re searching for.]]></summary></entry></feed>