Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 11, 2024
1 parent 58c3120 commit da055d8
Show file tree
Hide file tree
Showing 1,356 changed files with 1,999 additions and 1,561 deletions.
34 changes: 34 additions & 0 deletions 2015/01/03/sublime-input/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html><html><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>STDIN inputs via Sublime Text (sort of) · Sid Verma</title><link rel=stylesheet href=/css/rocinante.css><link rel=stylesheet type=text/css href=https://sidverma.io/css/style.e8c845c8956e7f770f3b1f26851fe7de52e1acda821d60445afa03b5f3ccdbf9.css><link rel="shortcut icon" href=/icons/favicon.ico><body><header><h2><a href=https://sidverma.io/>‹ Sid Verma</a></h2></header><main><div class=post><div class=title-group><div class=title><h1>STDIN inputs via Sublime Text (sort of)</h1></div><div class=date><h5>Jan 03, 2015</h5></div></div><article class=content><p>I love Sublime Text. I really do. I can put a ring on it if it had any corporeal form. I&rsquo;ve been using it so much, that trying to work on anything else is kind of a pain. And yet, when dealing with STDIN inputs, the magic falters. This method describes a workaround to give inputs without a prompt.</p><p>Recently, I tried my hand on Competitive Programming, and though I didn&rsquo;t get really good at it, I did encounter a frustation. Entering the same input again and again after every change I make to the code. I wanted a simpler method.</p><p>Here&rsquo;s what a friend of mine came up with: Enter the input in comments.</p><div class=highlight><pre style=color:#272822;background-color:#fafafa;-moz-tab-size:2;-o-tab-size:2;tab-size:2><code class=language-cpp data-lang=cpp><span style=color:#75715e>/*input
</span><span style=color:#75715e>2
</span><span style=color:#75715e>foo
</span><span style=color:#75715e>bar
</span><span style=color:#75715e>*/</span>

<span style=color:#75715e>#include</span> <span style=color:#75715e>&lt;stdio.h&gt;</span><span style=color:#75715e>
</span><span style=color:#75715e></span><span style=color:#00a8c8>int</span> <span style=color:#75af00>main</span><span style=color:#111>()</span> <span style=color:#111>{</span>
<span style=color:#00a8c8>int</span> <span style=color:#111>n</span><span style=color:#111>,</span><span style=color:#111>i</span><span style=color:#111>;</span>
<span style=color:#00a8c8>char</span> <span style=color:#111>s</span><span style=color:#111>[</span><span style=color:#ae81ff>10</span><span style=color:#111>];</span>
<span style=color:#111>scanf</span><span style=color:#111>(</span><span style=color:#d88200>&#34;%d&#34;</span><span style=color:#111>,</span><span style=color:#f92672>&amp;</span><span style=color:#111>n</span><span style=color:#111>);</span>
<span style=color:#00a8c8>for</span><span style=color:#111>(</span><span style=color:#111>i</span><span style=color:#f92672>=</span><span style=color:#ae81ff>0</span><span style=color:#111>;</span><span style=color:#111>i</span><span style=color:#f92672>&lt;</span><span style=color:#111>n</span><span style=color:#111>;</span><span style=color:#111>i</span><span style=color:#f92672>++</span><span style=color:#111>)</span> <span style=color:#111>{</span>
<span style=color:#111>scanf</span><span style=color:#111>(</span><span style=color:#d88200>&#34;%s&#34;</span><span style=color:#111>,</span><span style=color:#111>s</span><span style=color:#111>);</span>
<span style=color:#111>printf</span><span style=color:#111>(</span><span style=color:#d88200>&#34;%s</span><span style=color:#8045ff>\n</span><span style=color:#d88200>&#34;</span><span style=color:#111>,</span><span style=color:#111>s</span><span style=color:#111>);</span>
<span style=color:#111>}</span> <span style=color:#111>}</span>
</code></pre></div><p>gives the output:</p><pre><code>foo
bar
</code></pre><p>I wrote up a <a href=http://gist.github.com/mavidser/83d50803622ae70895ce target=_blank>quick and really dirty plugin to do it</a> for Python, and though it was rather clunky, I had a rough idea of what I wanted, and how to do it. Pipes! Good ol&rsquo; pipes!</p><p>Now, what I had was a clunky implementation which just executes the following command:</p><div class=highlight><pre style=color:#272822;background-color:#fafafa;-moz-tab-size:2;-o-tab-size:2;tab-size:2><code class=language-bash data-lang=bash><span style=color:#111>echo</span> <span style=color:#d88200>&#34;input&#34;</span> <span style=color:#111>|</span> python program.py</code></pre></div><p>I started jotting down a list of things I needed to add to the plugin. The first thing was to make the execution asynchronous. I couldn&rsquo;t let the whole editor hang when a program&rsquo;s under execution. Also, to be able to kill programs. And proper error reporting, platform independency, etc.</p><p>It turns out all these things were already implemented, in the default build system of Sublime Text itself. I decided to merge my plugin it.</p><p>Apart from things like input extraction, handling filenames, the behavious of things in Windows, etc, the main trick was changing</p><div class=highlight><pre style=color:#272822;background-color:#fafafa;-moz-tab-size:2;-o-tab-size:2;tab-size:2><code class=language-python data-lang=python><span style=color:#111>self</span><span style=color:#f92672>.</span><span style=color:#111>proc</span> <span style=color:#f92672>=</span> <span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>Popen</span><span style=color:#111>([</span><span style=color:#d88200>&#34;/bin/bash&#34;</span><span style=color:#111>,</span> <span style=color:#d88200>&#34;-c&#34;</span><span style=color:#111>,</span> <span style=color:#111>shell_cmd</span><span style=color:#111>],</span>
<span style=color:#111>stdout</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>PIPE</span><span style=color:#111>,</span>
<span style=color:#111>stderr</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>PIPE</span><span style=color:#111>,</span>
<span style=color:#111>startupinfo</span><span style=color:#f92672>=</span><span style=color:#111>startupinfo</span><span style=color:#111>,</span>
<span style=color:#111>env</span><span style=color:#f92672>=</span><span style=color:#111>proc_env</span><span style=color:#111>,</span>
<span style=color:#111>shell</span><span style=color:#f92672>=</span><span style=color:#111>False</span><span style=color:#111>)</span></code></pre></div><p>to</p><div class=highlight><pre style=color:#272822;background-color:#fafafa;-moz-tab-size:2;-o-tab-size:2;tab-size:2><code class=language-python data-lang=python><span style=color:#111>echo_input</span> <span style=color:#f92672>=</span> <span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>Popen</span><span style=color:#111>(</span><span style=color:#d88200>&#39;echo &#34;&#39;</span> <span style=color:#f92672>+</span> <span style=color:#111>user_input</span> <span style=color:#f92672>+</span> <span style=color:#d88200>&#39;&#34;&#39;</span><span style=color:#111>,</span>
<span style=color:#111>stderr</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>STDOUT</span><span style=color:#111>,</span>
<span style=color:#111>stdout</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>PIPE</span><span style=color:#111>,</span>
<span style=color:#111>shell</span><span style=color:#f92672>=</span><span style=color:#111>True</span><span style=color:#111>)</span>

<span style=color:#111>self</span><span style=color:#f92672>.</span><span style=color:#111>proc</span> <span style=color:#f92672>=</span> <span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>Popen</span><span style=color:#111>([</span><span style=color:#d88200>&#34;/bin/bash&#34;</span><span style=color:#111>,</span> <span style=color:#d88200>&#34;-c&#34;</span><span style=color:#111>,</span> <span style=color:#111>shell_cmd</span><span style=color:#111>],</span>
<span style=color:#111>stdin</span><span style=color:#f92672>=</span><span style=color:#111>echo_input</span><span style=color:#f92672>.</span><span style=color:#111>stdout</span><span style=color:#111>,</span> <span style=color:#75715e>#Input</span>
<span style=color:#111>stdout</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>PIPE</span><span style=color:#111>,</span>
<span style=color:#111>stderr</span><span style=color:#f92672>=</span><span style=color:#111>subprocess</span><span style=color:#f92672>.</span><span style=color:#111>PIPE</span><span style=color:#111>,</span>
<span style=color:#111>startupinfo</span><span style=color:#f92672>=</span><span style=color:#111>startupinfo</span><span style=color:#111>,</span>
<span style=color:#111>env</span><span style=color:#f92672>=</span><span style=color:#111>proc_env</span><span style=color:#111>,</span>
<span style=color:#111>shell</span><span style=color:#f92672>=</span><span style=color:#111>False</span><span style=color:#111>)</span></code></pre></div><p>A few other fixes, and the whole thing was running smooth as butter. No more rapid switching between the Console and Sublime Text to execute a program.</p><hr><p>The plugin has now been nicely packaged and uploaded. It can easily be installed via <a href=http://packagecontrol.io/packages/Sublime%20Input target=_blank>Package Control</a>, and the source is available on <a href=http://github.com/mavidser/SublimeInput target=_blank>Github</a>.</p></article><div class=tags><span title=Tags>🏷</span><div class="horizontal-links links"><a href=/tags/programming/>Programming</a></div></div></article></main><footer><div class=content-container><div class=content><p>Hi friend. I&rsquo;m <strong>Sid</strong>!</p><p>This is my home on the internet. Come, have a tour. Please leave your shoes at the door.</p><p>I work with technology for a living - mostly as a software engineer. Some details are available in the resume below. In addition, I&rsquo;m interested in filmmaking, tinkering with electronics, and building a decentralized internet. <em>Feel free to reach out if you&rsquo;d like to work together.</em></p><p>I also like trees.<br></p><p class=horizontal-links><a href=/resume>Resume</a><a href=/contact class=email-hook id=about-email title="Click to show email">Email</a></p><p class=horizontal-links><a href=/posts>Posts</a><a href=/photos>Photos</a><a href=https://github.com/mavidser target=_blank>Github</a><a href=https://twitter.com/mavidser target=_blank>Twitter</a></p></div></div></footer><script>const emailId=atob("bWVAc2lkdmVybWEuaW8=");</script><script src=/js/rocinante.min.js></script></body></html>
1 change: 1 addition & 0 deletions 2017/07/12/wifi-positioning/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Wi-Fi positioning woes · Sid Verma</title><link rel=stylesheet href=/css/rocinante.css><link rel=stylesheet type=text/css href=https://sidverma.io/css/style.e8c845c8956e7f770f3b1f26851fe7de52e1acda821d60445afa03b5f3ccdbf9.css><link rel="shortcut icon" href=/icons/favicon.ico><body><header><h2><a href=https://sidverma.io/>‹ Sid Verma</a></h2></header><main><div class=post><div class=title-group><div class=title><h1>Wi-Fi positioning woes</h1></div><div class=date><h5>Jul 12, 2017</h5></div></div><article class=content><p>Alice lives in India. She has super-cheap cellular internet (less than $0.2/GB on some networks). Cheap enough for it to be her daily driver, using <a href=http://www.amazon.in/D-Link-DWR-720-HSPA-Mobile-Router/dp/B00PVD1RV2 target=_blank>a</a> <a href=https://www.amazon.com/Hotspot-Unlocked-Worldwide-Huawei-E5220s-6/dp/B06XJ5NF8W/ target=_blank>number</a> <a href=https://www.amazon.com/Verizon-Wireless-LTE-Prepaid-Smartphone/dp/B014RJJXUW/ target=_blank>of</a> <a href=https://www.amazon.com/Hotspot-Unlocked-MF65-Router-Mobile/dp/B01KGCMUQ8/ target=_blank>portable</a> Wi-Fi routers, which just sit on her desk. And since it is so cheap and portable and convenient and long-lasting, she just carries it everywhere in her purse, wherever she travels.</p><p>Alice also faces an a peculiar amount of problems with her GPS. She could be at a crowded bus station, trying to get an Uber, or stuck in a storm, again trying to get a cab, her phone just fails to locate her correctly long enough for the app to work. Either it&rsquo;ll just be showing her previous location at the far away house, or it will keep fluctuating and jumping between her actual position, and her house. People around her sometimes get affected too. Maybe it&rsquo;s a curse.</p><p>For most people, device positioning is synonymous with GPS. But these days, GPS is the last thing a smartphone checks when trying to locate itself. GPS takes some time to obtain a good fix, and drains a lot of battery. In contrasts, a lot of your phone radios are less power-hungry and always on. Mostly, it&rsquo;s a combination of cellular, bluetooth and Wi-Fi. Basically, the signal strength from different cell towers help triangulate your approximate location. Some BLE devices can also advertise their location to nearby devices.</p><p>Apart from these, Companies like Google/Apple/Microsoft/Skyhook maintain a huge list of <code>(Wi-Fi SSID + MAC) => Location</code> combinations to find your location. You might have noticed your phone telling you to switch on Wi-Fi for more accurate positioning at some point. This is why. This method quite is power efficient, and quick. And in most cases, very accurate.</p><p><em>Note: This is one of the primary uses of <a href="https://support.google.com/accounts/answer/6179507?hl=en" target=_blank>Google Location Service</a> on Android.</em></p><p>In our character&rsquo;s case though, Alice&rsquo;s wifi router normally always resides on her desk, at her home. The device has the MAC Address <code>AB:CD:EF:GH:IJ:KL</code>. It&rsquo;s boring SSID is <code>Alice's Wifi</code>. Now, a lot of smartphones around her will be reporting this MAC+SSID combination to some server, along with their location. Alice, her guests, her neighbours, almost everyone around her. They don&rsquo;t need to be connected to the network. Her router getting scanned is enough.</p><p>So, when travelling with the said hotspot on in her purse, if she tries using some location-requiring app, her phone gets wrong/conflicting location data. Depending on the neighboring conditions (the GPS strength, other Wi-Fi networks nearby, etc), she may see her actual location, or her far-away home, or even jumping between the currnt position and her home.</p><p>If you find yourself in such a situation and own the culprit router, just change the network name. This should solve the problem for you and people around you. Also, if you don&rsquo;t have control over the router, try switching your phone from from A-GPS to GPS-only temporarily. It might be slow and power-hungry, but is accurate. Disabling your Wi-Fi doesn&rsquo;t always prevent it from scanning for networks.</p><figure><img src=/images/location-settings.jpg alt="Example of Android&amp;rsquo;s location settings"><figcaption><p>Example of Android&rsquo;s location settings</p></figcaption></figure><p>BTW, this is also how your PCs sometimes know their location. Eg— when you visit <a href=https://maps.google.com target=_blank>Google Maps</a> on the desktop.</p></article><div class=tags><span title=Tags>🏷</span><div class="horizontal-links links"><a href=/tags/technology/>Technology</a></div></div></article></main><footer><div class=content-container><div class=content><p>Hi friend. I&rsquo;m <strong>Sid</strong>!</p><p>This is my home on the internet. Come, have a tour. Please leave your shoes at the door.</p><p>I work with technology for a living - mostly as a software engineer. Some details are available in the resume below. In addition, I&rsquo;m interested in filmmaking, tinkering with electronics, and building a decentralized internet. <em>Feel free to reach out if you&rsquo;d like to work together.</em></p><p>I also like trees.<br></p><p class=horizontal-links><a href=/resume>Resume</a><a href=/contact class=email-hook id=about-email title="Click to show email">Email</a></p><p class=horizontal-links><a href=/posts>Posts</a><a href=/photos>Photos</a><a href=https://github.com/mavidser target=_blank>Github</a><a href=https://twitter.com/mavidser target=_blank>Twitter</a></p></div></div></footer><script>const emailId=atob("bWVAc2lkdmVybWEuaW8=");</script><script src=/js/rocinante.min.js></script></body></html>
Loading

0 comments on commit da055d8

Please sign in to comment.