<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rahul Pillai on Medium]]></title>
        <description><![CDATA[Stories by Rahul Pillai on Medium]]></description>
        <link>https://medium.com/@thegeekylad?source=rss-e799cb1226eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lwn7WepZibZm3qWo.</url>
            <title>Stories by Rahul Pillai on Medium</title>
            <link>https://medium.com/@thegeekylad?source=rss-e799cb1226eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:11:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thegeekylad/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Wearboard — Truly Remote Input for WearOS]]></title>
            <link>https://thegeekylad.medium.com/wearboard-truly-remote-input-for-wearos-124aae396040?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/124aae396040</guid>
            <category><![CDATA[wearables]]></category>
            <category><![CDATA[wear]]></category>
            <category><![CDATA[wear-os]]></category>
            <category><![CDATA[gboard]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Tue, 26 Sep 2023 07:00:02 GMT</pubDate>
            <atom:updated>2023-09-26T07:03:34.331Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Wearboard — Truly Remote Input for WearOS</strong></h3><p>HelloWorld!</p><p>It’s interesting how some intellectual conversations over a cup of coffee precipitate in something concrete and tangible.</p><p>The other day, my mentor, Gonzalo, and I were catching up at lunch during my internship at TuneIn when we couldn’t help but chat about the “search bar” widget from the TuneIn watch app Figma file. I mean, what’s a media app without search! Indeed, but imagine using the Gboard standard QWERTY layout to key in the words “Padal Varigal” on a 40mm watch screen — and that too without swipe-to-type support! Sounds like Nightmare on “Droid” Street; I’m better off pulling up my phone to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFi1IAxpOSd9JGJOO5ZRoA.png" /><figcaption>Gboard for touch typing on the Pixel Watch</figcaption></figure><p>But then again, I’d beg the question, what’s a dedicated watch app if users can’t really derive the full experience? Frankly, even I’m team Google in frowning at the idea of touch typing on ant-sized watch screens just because how cumbersome the process is. Pretty much explains the absence of the `TextField` composable for WearOS apps and instead why developers are encouraged to create a `RemoteInput` intent and `startActivityForResult(…)` to show up a dedicated keyboard on watch apps for input. Fair, but for certain use cases, touch typing on watches is nearly impossible, such as while entering a WiFi password.</p><p>Google has this edge case covered with an `AlertDialog` that pops out of nowhere on the phone when you try to input a WiFi password on the watch. This seems to be something hardwired into the OS without a public API that developers can bake into watch apps that can launch that very input dialog on the phone as requested by the watch.</p><p>This, essentially, sets the stage for Wearboard — an SDK that can be “plugged” into any Android / WearOS app codebase that lets users decide whether they want to type on their phone or watch to populate a text box on watch apps. Wearboard enforces an intermediate `Activity` on click of a text box widget on their watch that then asks the user to make a decision on how they’d like to fill that text box. If the user chooses “watch” then they’d see a keyboard popup on the watch and if they choose “phone”, a nice input dialog appears on the paired phone app to grab input and then send it over to the watch app. The SDK is flexible enough to let the developer decide how they’d like to implement the “watch” input method — maybe it’s Gboard, maybe it’s something proprietary (like a custom low-profile keyboard, I don’t know). Wearboard’s implementation is tied only to the “phone” input method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJxLZe2sP0YI7EeVc20_HA.png" /><figcaption>Wearboard input method selection activity</figcaption></figure><p>Internally, Wearboard makes use of the Wear DataLayer APIs that stage communication between phones and watches under the Android hood. When a watch app requests for phone input, a blank `Activity` with an input `AlertDialog` appears on the phone app. The developer is free to customize the title of the dialog box from the watch app, which then instructs the phone app to show a customized title. Everything that you see on here is from the Material world through Jetpack Compose. At present, Wearboard uses a custom `MaterialTheme` but I let out dynamic color support in favor of a unified theme for a given watch-phone app pair. Open to discussion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9azSTNt1vb7_ots59wAYQ.png" /><figcaption>Text input on the phone for search box on a watch app</figcaption></figure><p>Why’s it that the phone app should be in foreground for the dialog to appear? A ubiquitous dialog is technically possible with a custom window to draw the dialog on but all of this requires the explicit `SYSTEM_ALERT_WINDOW` permission. Sounds more like an unrelated permission for, maybe, a media player app! Achieving something like the default WiFi password input on the phone from the watch would’ve, ideally, been the best from a UX perspective as. Perhaps, dropping the input dialog entirely in favor of a pop-up notification on the phone is a better alternative? Food for thought.</p><p>Finally, thanks to my mentor, <a href="https://www.linkedin.com/in/gonzalo-alsina-b5548a25/">Gonzalo</a>, for this awesome idea! An <a href="https://www.linkedin.com/posts/thegeekylad_tunein-tuneininternship-gratitude-activity-7104032714558738432-9LBG?utm_source=share&amp;utm_medium=member_desktop">internship at TuneIn</a> was, indeed, a great starting point for exploring the WearOS world. Wearboard turned out to be a nice weekend-long hobby project. Do check out the source and sample phone / watch apps on <a href="https://github.com/theGeekyLad/wearboard#keyboard-wearboard--truly-remote-input-for-wearos">my GitHub</a> and a quick minute’s worth of demo on <a href="https://youtube.com/shorts/rXEaJjPUv4A">my YouTube</a>. I’d love to know your thoughts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=124aae396040" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can programming languages talk to each other? — A Java fanatic’s perspective]]></title>
            <link>https://thegeekylad.medium.com/can-programming-languages-talk-to-each-other-a-java-fanatics-perspective-eb80b85b6640?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb80b85b6640</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 07:01:04 GMT</pubDate>
            <atom:updated>2021-06-29T07:01:04.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8JpD8ud1wILKy7jcVlB3A.png" /><figcaption>Dogs and cats may be good with with each other, but what about programming languages?</figcaption></figure><h3>Can programming languages talk to each other? — A Java fanatic’s perspective</h3><p>Hello readers, hope this pandemic has been treating you all well! It’s been a while since I’ve written and here I’m back at it.</p><blockquote><strong>Note:</strong> In course of this article, you’d find a bunch of occurrences of the term <a href="https://www.gtk.org/">GTK</a> which isn’t NASA’s new spacecraft but a framework that exposes a rich set of APIs to build modern user interfaces (typically on Linux).</blockquote><p>More often than not, I’ve found the need to interface with another disparate programming language from my current application. Very succinctly, every language shines bright in it’s territory and is preferred to another for easily and efficiently completing tasks that other languages would likely have you run around for. Incidentally, writing a GTK application in Java — one of the most powerful languages with excellent innate GUI support — is, at best, horrendous primarily because there aren’t official GNOME bindings for for it. Meanwhile, Python is the showstopper in this department and your Java program had better interface with a Python script for seamless interplay with GTK. Moreover, even my colleague at workplace had recently asked me if it’s possible to integrate a Python function within her Vue.js web application. While there’s more than one way to get there, we’ll take a look at two broad approaches.</p><h3>RESTful Web Services</h3><p>Though the title might not sound quite germane to the context we’re operating in, you might be surprised to know that this is one of the most candid take on the subject. This could be the de facto solution to web developers hoping to interface with other programming languages. With support from versatile frameworks, it barely takes 3–4 lines of code to build a simple RESTful web service that would accept GET requests and return JSON responses. For instance, <a href="https://javalin.io/">Javalin</a> is a straightforward library that allows setting up a web service with just a few lines of code. What Javalin is to Java, is <a href="https://flask.palletsprojects.com/en/2.0.x/">Flask</a> to Python and <a href="https://nodejs.org/api/http.html">HTTP</a> to Node.js. Regardless of the nomenclature, in all cases, we’re talking about setting up a simple API endpoint at localhost that would be consumed by the primary application in question.</p><p>More generally, this is how web applications interact with resources outside the browser’s sandbox to achieve whatever a <em>puny</em> web app alone cannot. Lets say you’re working on one such web app that promises to cleanup config files on a user’s computer. Surmising from above, given the limited access bestowed on browsers, we’d take the web service route and setup one with Javalin as follows. The web app will then only have to make a GET request at <a href="http://localhost:7000/">http://localhost:7000</a> to get the job done:</p><pre>// Java<br>Javalin app = Javalin.create().start(7000);<br>app.get(&quot;/&quot;, new Handler() {<br>    @Override<br>    public void handle(@NotNull Context context) throws Exception {<br>        // Do cleanup activity ...<br>        context.result(&quot;Cleanup success!&quot;);<br>    }<br>});</pre><p>Thus, a successful cleanup operation precipitates in a message echoed back to our web app which can then present it nicely to the user.</p><p>To the full-stack developers out there, this idea might’ve sounded rather banal since, come on, who doesn’t know about client-server communication through RESTful web services? Well, what’s less obvious, though, is that this well established architecture doesn’t really ring a bell to many of us since it doesn’t directly address the question “hey, how should I call this Python OCR function in my web app?” as much as it addresses “yo, how could I save input from this questionnaire form?”.</p><p>Ultimately, this is definitely one of the more commonplace approaches to achieve interaction between distinct programming languages.</p><h3>Processes</h3><p>The term might sound quite familiar to the operating system zealot in you. The big idea here is that most high level programming languages can create and manage processes quite efficiently. For instance, while Java brandishes the <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runtime.html">Runtime</a> sword, Python aces it with <a href="https://docs.python.org/3/library/subprocess.html">subprocess</a> and Node.js slays it with <a href="https://nodejs.org/api/child_process.html">ChildProcess</a>. While the names are evidently different, their purpose of existence is unilateral. They are all about spawning command-line sessions on the underlying operating system and issuing commands. Now, here’s where the true power of CLI and args can be potentially exploited since, technically, everything on a computer finds its inception in the command-line — that’s where every piece of software — including the browsers, games, etc. — starts! More simply put, we run all our Java, Python, etc. programs from the command-line. For starters, <strong>PowerShell</strong> for Windows, <strong>Bash</strong> for Linux and <strong>Terminal</strong> for MacOS are incarnations of the “command-line”. Therefore programming language support for command-line integration is all we need to run a piece of code in another language from our program.</p><p>While it’s not starkly different across languages, lets take a look at a Java code snippet that would run my show-gtk-dialog.py Python script that, well, opens a simple GTK dialog:</p><pre>// Java<br>String msg = &quot;HelloWorld! I&#39;m from Java and Python.&quot;;<br>Process process = Runtime.getRuntime().exec(&quot;python show-gtk-dialog.py \&quot;&quot; + msg + &quot;\&quot;&quot;);<br>process.waitFor();  // waits until the dialog is closed by the user<br>System.out.println(&quot;Dialog closed!&quot;);</pre><p>Very simply put, this snippet passes a <em>command-line argument</em> — the message to be displayed inside the GTK dialog — to the Python script which would then read it using sys.argv and use the GTK APIs to inflate a simple dialog with the message.</p><p>While the above example might appear inchoate, it illustrates the idea that processes and more specifically the <em>command-line</em> can, indeed, stage communication between programming languages.</p><p>Finally, it’s worth noting that neither approach is a one-size-fits-all as they have their respective preconditions, discussing which is beyond the scope of this article. Nevertheless, I hope this article aids in ideation of your <em>cross-language</em> project! Happy coding and take care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb80b85b6640" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Android PC —sauce to sugar?]]></title>
            <link>https://thegeekylad.medium.com/the-android-pc-sauce-to-sugar-c47c33f26978?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c47c33f26978</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Fri, 04 May 2018 22:36:52 GMT</pubDate>
            <atom:updated>2018-05-04T22:36:52.271Z</atom:updated>
            <content:encoded><![CDATA[<h4>A walk-through the relative merits of Android x86</h4><p>Android has been the go-to platform of choice for not only cellular handsets but also other devices such as TVs and even in-car infotainment systems, in the present day and age.</p><h4><em>A Favorite</em></h4><p>Android is open source, hence a bunch of developers working on incorporating new features, porting it for newer hardware and yeah, all that for free. That’s how open source works! And that’s how <strong>Android x86 </strong>was born. Android x86 is essentially “Android for x86”. For all newbies,<em> x86 </em>refers to the 32-bit architecture of Intel’s CPU line-up while <em>x64</em> or sometimes <em>amd64 </em>refers to the 64-bit instruction set counterpart. Yet Android x86 is a generalization for Android on all of Intel’s CPU line-up.</p><h4>Android PC</h4><p>So if you’ve got a computer with an Intel CPU at it’s heart, which is true in most cases, you’re good to go! You can run Android on your PC. But then question arises, why would you even want to do that? Just because you can and you’re cool. Android’s got a huge market of apps — apps that you use on a routine basis for work and play — apps that sometimes look and feel better than their corresponding websites and Windows counterparts. It’s just too cool to run Android on your PC with those apps that you love — all on a large playground. And if you’ve got a touchscreen say on a Windows tablet — all the more better.</p><h4>The Goods</h4><p>The experience of Android on the PC is <em>almost</em> as good as it is, on an Android phone or a tablet. All that huge screen shapes into a typical Android tablet with a reasonable screen pixel density which can be further tweaked to suit your needs — it’s all perfect when it comes to the interface. All apps that are tablets-natives work, except for a few that are buggy thanks to the lack of libraries and optimization on the x86 platform. Off late, Android’s quite optimized for non-touch-based input methods and allows efficient control with a keyboard and mouse. This is what essentially makes Android x86 possible and practical to some extent. Most laptop touchpad (generic) drivers are bundled along, which makes all gestures like swipe and pinch that you’d perform on a typical Android tablet possible with no jitters and lag. All animations are just too smooth to deny. WiFi now supports a bunch of more network cards out-of-the-box and the Killer powered card on my Alienware finally works legit. Brightness control is seamless and apps that support landscape orientation take advantage of the entire display — things just come alive!</p><p>Fire this thing up on your ultrabook at an airport and let the bystanders ween, “hey, this guy’s no mainstream.” Talk about gaming and you’ll be amazed to know that all (most) games work seamlessly as those Intel GPUs are definitely better than their tablet chipset counterparts for the most part. Wading through Temple Run or racing through the streets — it all makes sense on that huge 15.6&quot; screens. Android gamers definitely stand to gain here, especially the ones who’re fond of strategy titles such as Clash of Clans and so on. Things are just more bigger and better.</p><p>Sounds convincing huh? <em>(Smirks)</em> — wait for it.</p><h4>The Bads —Installation | GRUB</h4><p>The installation factor kind of held me back at the beginning as it’s a wee more complex than you’d fathom, to get this thing running on your machine. Not as simple as firing up a <em>setup.exe</em> and tapping the <em>next </em>a couple of times until it says, “Bingo, setup complete. Tap here to run Android.” Only if it were that simple! I’d rate the difficulty level as semi-pro for someone who’s setup Ubuntu on his machine in the past. Off topic though, if you’ve ever setup Arch on your system in the past from scratch, this thing’s a cake walk for you pal, trust me. There are a couple of guides on the web that walk you through the steps though I didn’t find everything in one place and requires a bit of digging around especially for a few post-installation steps.</p><p>I’m keeping the language as non-technical as possible, though the handful of geeks reading this can note — the post-installation steps require you to install GRUB all by yourself and add the menu entry manually due to the faulty installers on all versions of Android x86 after g(old) <em>Kitkat</em>. This is insane if you’ve not got a flavor of Linux already installed on your machine! Nevertheless as a newbie to Linux, you’re definitely not doing this on your own unless you understand bootloaders, filesystems and formatting on a very basic note. That’s worth mentioning as everything on Linux installers is menu-based for the most part, duh.</p><h4>The Bads — Audio</h4><p>Now let’s talk about the more tangible stuff. One of the most common bugs faced is bad audio. This is mostly tied to the audio cards per se without Android x86 to blame. As such the optimization levels are terrible, which applies collectively to most Linux distros. Who’s to blame? — the kernel drivers for certain cards such as the one for the <em>SoundBlaster </em>on my rig which by default sets headphone out to mute. Headphones thus <em>may not </em>work on your machine.</p><h4>The Bads — Power + Thermal Management</h4><p>Another one being power management which has always been a losing battle for Linux. Lack of good thermal and power management can turn your Android x86 machine into a hotpot with about an hour of juice depending how healthy your battery is. My Alienware running Android x86, gives me less than 2h of screen-on with WiFi connected. (Psst. for you geeks — don’t trust Doze). That’s silly on a machine that gives me close to about 3.5–4h on a full charge with video playback and WiFi. Now here, Linux as a whole is to blame and not Android x86 alone as what’s below is essentially the Linux kernel.</p><p>Good thermal and power management comes with good drivers, the goodness which Linux infamously lacks. And if you by chance are running Android x86 on a quad core laptop with an HQ series processor or the like, note that it replicates as a cheaper alternative to an egg boiler.</p><h4>The Bads — Lock Screen</h4><p>We lock our Android phones to switch screens off, right? Doing it on your Android x86 machine is going to annoy you for what follows while resuming. Most laptop keyboards aren’t equipped with a dedicated <em>context menu </em>button which though, is found on most fully-blown desktop keyboards and sits right next to the space bar. For understanding purposes, this button works similar to the mouse right click when performed on the Windows desktop screen. Android x86’s official guide requires you to hold down a few buttons which includes the Esc, context menu and the arrow keys to resume from the locked screen. I, along with most of you out there, don’t have a context menu key on my keyboard — so what? No waking up. It’s the blessed sleep of death once locked. Consider doing an emergency restart if you accidentally lock your Android x86.</p><h4>The Bads —Drivers</h4><p>Chances are quite high that the WiFi, Bluetooth or for that matter even the display card on your machine may not work with Android x86. You can’t blame the community for that! Porting drivers is done for free and it requires quite a lot of knowledge to get these things running flawlessly. The Killer Networks WiFi card on my rig remained dysfunctional for over a year after which there was a fully-functional driver module released. Yet the <em>ath10k </em>driver that’s concerned with Bluetooth on my Alienware is still buggy at moment which leaves me with no Bluetooth. You’d face similar issues if your hardware is not (yet) supported. It’s a matter of time and time heals (theory of life).</p><h4>Conclusion</h4><p>Don’t count the headers as you’d possibly find the bads taking lead. Nevertheless, this article isn’t luring you out of Android x86 as it’s all about your perspective, what you want at the end of the day and what floats your boat! Despite all the odds, I’m definitely enjoying my time typing this article out on the official Medium app for Android on my Alienware 15 running Android 7.1. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c47c33f26978" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A walkthrough shrinking partitions in Linux]]></title>
            <link>https://thegeekylad.medium.com/a-walkthrough-shrinking-partitions-in-linux-743a51efa804?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/743a51efa804</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[partitioning]]></category>
            <category><![CDATA[filesystem]]></category>
            <category><![CDATA[arch-linux]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 21:09:16 GMT</pubDate>
            <atom:updated>2018-04-22T21:09:16.420Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding 4k and 512B blocks</h4><p>So it’s been a great weekend and I finally got some time off studies amidst those final examinations at college. The devil in my mind popped a random thought from nowhere — ”Let’s dual boot Android x86!” Well well, and it began.</p><p>I’m running Arch Linux with KDE on my Alienware 15 on a dual boot with Windows 10 Pro and the system’s got a handsome disk configuration that looks like this — 2 M.2 SSDs and a SATA SSD. I’ve kept the M.2s aside just for operating systems and am running Windows on the bigger 250GB and Arch on the smaller 128GB, the SATA is but a data pool. Now that I’m set on installing Android, the debatable question arises — where am I going to even put it? I need a partition and I’m going to have to create it. Logically speaking, I’ve kept the 128 gig M.2 only for Linux OSes and since Android kernel is Linux so deductive logic has it — that’s where Droid’s going!</p><h4>The Partition</h4><p>Getting the partitions right is what makes the game enduring. Creating a partition off Windows is a piece of cake — make a few taps here and there and poof, you’ve got a new shiny partition ready to be put to work! Only if it was that simple with Linux, duh.</p><p>Since I’m going to have to create an ext4 partition, I can’t do that natively off Windows and wouldn’t recommend using third party tools either. What am I left with? A bootable media running a live Linux system that would let me accomplish that. There are a bunch out there to choose from but I’d stick to the Arch Live system as it just gives me the degree of manual control that’s arguably safe when it comes to playing around with disks and partitions where you’re solely responsible for your deeds and can’t blame the system like, “hey why’d you rip that EFI volume off?”</p><p>So with Arch Linux running of a live media, I’m presented with that monotonous, monochrome zshell prompt. Go ahead and run `fdisk -l` and you’ll see a list of disks connected to your PC and their partitions. I’m looking at /dev/sdc which is my 128GB SSD, right now containing just one volume with Arch installed. I need to squeeze about 16GB off this volume and create a new partition for throwing in Android and that’s the plan on paper.</p><p>Running `e2fsck -f /dev/sdc1` on the only volume in that SSD shows me no errors on the filesystem — a great place to start. If you’re coming from Windows, you’ll be perplexed to know that shrinking a volume to create a partition is trifold in Linux! Yeah, you’ve got to shrink the filesystem first, then shrink the volume and finally ‘inform’ the kernel of all changes. Why do you think the laymen prefer Windows? Let’s go ahead and do all that.</p><h4>Resizing the Filesystem</h4><p>Since I need to pull 16GB off, I’ve got to shrink the volume to (128–16)GB = 112GB, let’s go ahead and run `resize2fs /dev/sdc1 112G`. Another thing here that a lot of newbies-to-Linux miss — G and GB aren’t the same! A quick detour, for instance 5G converts to bytes as 5*(1024)*(1024)*(1024)B, whereas 5GB converts to bytes as 5*(1000)*(1000)*(1000). This renders the unit GB entirely inaccurate and not beyond a simple cue. Part one, done.</p><h4>Shrinking the Volume</h4><p>Now to resize the volume itself (what actually matters to me, us). I’m going to run GNU Parted in interactive mode as `parted` and use the resizepart command for the rest. Use the `print` in the current parted shell session to view all volumes on the current drive and their corresponding IDs — the volume in concern in my case is marked 1.</p><p>What matters to me is as simple as getting a 112GB volume at the end of the resizepart command’s execution. But it’s not as simple as running `resizepart 1 112GB` as we just learnt how GB is different from G. Exploring GNU Parted’s unit command, we see that it allows interchangeability of units but let me tell you one thing, things are going to mess up even when the units are in G. Digging in deeper goes beyond the scope of this article so let’s stop here and cut right to the chase.</p><p>It’s best to keep things at their lowest complexity and hence let’s shift everything to the blocks unit. (lowest complexity and blocks — is that an oxymoron?) Run in parted interactive `unit s`. Run `print` and you’d see how GNU Parted displays all the start, end sectors and volume size in blocks of 512-byte size. Now I’ve got to convert 112GB to 512B blocks and can do that as,</p><p>size_in_512B_blocks = size_in_GB * 2 * 1024 * 1024</p><p>Do the math for 112GB in 512B blocks and run in parted interactive `resizepart 1 new_end_value` where,</p><p>new_end_value = start_sector (as seen from the print command’s output for the volume) + size_in_512B_blocks_for_112GB</p><h4>Informing the Kernel — The 4k and 512b block conflict!</h4><p>Yeah, now for accounting everything to the kernel just as the whining school boy informed his mum everyday. Exit parted interactive by `quit`.</p><p>The new resizepart command (from util-linux package) I’m going to be using to inform the kernel is quite different from what we saw in GNU Parted. The third parameter here, isn’t the end sectors but the size of the new shrunken partition (112GB) ‘in blocks’. You’d ask me how’s that so different?</p><p>Blocks. Blocks not of 512B that we’d seen. Blocks of 4k sectors as the manual says.</p><p>Here’s where a good understanding of the above seen formula is required. The multiplication factor 2 is introduced for standardization. The standard says 1024B for every 1MB, 1024MB for every 1GB and so on. Hence the 512B blocks are standardized by introducing the multiplication factor.</p><p>Now we need 112GB in 4k blocks! The manual would leave a layman wandering to understand what 4k really boils down to. But it’s as simple as 4096 and not 4000. That’s the catch.</p><p>size_in_4k_blocks = size_in_GB * 1024 * 1024 / 4, since 4096 is 4 times 1024. Now we’ve got the whole thing clear!</p><p>I’d inform mother kernel now, by running `resizepart /dev/sdc1 size_in_4k_blocks_for_112GB` and we’re done! Cross check for errors by running `fsck /dev/sdc1` and if you’ve got no errors, bingo.</p><h4>The Conclusion</h4><p>It’s already been a documentary of an article for you I suspect, yet I hope this article gives you a grip on how filesystems roughly work in Linux, the trifold method to resize partitions and in the process how to not get lost when resizepart says, “buddy, no…not 512B blocks. It’s 4k…4k-byte blocks. Lost? That’s Linux.”</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=743a51efa804" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Light — Data Transfer on Android, cool theory!]]></title>
            <link>https://thegeekylad.medium.com/light-data-transfer-on-android-cool-theory-b57045f2a6f8?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b57045f2a6f8</guid>
            <category><![CDATA[light]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 08:21:15 GMT</pubDate>
            <atom:updated>2017-08-06T08:21:15.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>Light — Data Transfer on Android, cool theory!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYkYLfZ9OTp5sXSIUccb3g.jpeg" /><figcaption>Data over light in Android</figcaption></figure><h3><strong>Background</strong></h3><p>It all started with wires, slipped into wireless over Bluetooth, then dived into WiFi and that’s where we are now! An unexplored field is direct light — don’t mess it up with fiber optics which ends up converting light to radio waves (simply routers) and propagate it over the good ol’ WiFi. What’s up about light?</p><p>The theory just drives me back to Morse Code. Those days were cool when simple torches were deployed to relay messages — trust me we’ve tried that in college. Impulses of light that just represent the 1’s and 0’s with two simple states — ON and OFF. But we’re no longer in the comfort zone!</p><p>The whole thing is just a theory as it’s quite impractical to implement at the moment. It could definitely be bettered down the lane of time! Also the concept isn’t quite similar to LiFi but can be thought of on similar lines.</p><h3><strong>Scenario</strong></h3><p>Lets take an example. I’ve got a 1 MB file that I’d like to send across to my buddy Sid. Cross-platform, data, regardless of its type / extension is represented as a file. A file can be represented as an array of bytes in any programming language say Java. What’s within that byte-array is just a sequence of bytes, each element ranging between 0 and 127 since that’s how a byte is define in Java at least. If you’d consider converting 1 MB into bytes, just multiply it by 1024 twice. That’s precisely 1048576 bytes. So the byte-array representing my 1 MB file is 1048576 elements (bytes) in length — each element being a number (byte) within the 0 ~ 127 bracket. Now let’s get into the theory behind transmitting this byte array!</p><h3><strong>Representation</strong></h3><p>We’ve now got to deal with representing each element in the array uniquely to Sid’s Android device such that it’s able to precisely understand what’s the number in the array that my phone’s trying to broadcast. Before that, we’ve got to grasp the characteristics of our source and receiver. Our base is light and our source of light is simply the display / screen of my Android phone. Our target is surprisingly the ambient light sensor of Sid’s Android phone. Hands down, our target can’t understand color (an ambient light sensor after-all!) but on the flip side, it can understand the intensity of light. We’ve got to accordingly tune our source. Since an element in our byte array can be anything between 0 and 127, we could divide the intensity (brightness) of the source white light from my device’s screen into levels such that say for instance, 0 to x lux (SI unit of light as understood by Android) corresponds to byte 1, x+d to y lux corresponds to byte 2 and so on till 127. Thus, we’ve mapped our source light levels with each of the 128 bytes (0 ~ 127). Now we’re set to transmit.</p><h3><strong>Transmission + Reception</strong></h3><p>I’m not delving too much into the technicalities since this post is merely theory (maybe just impractical theory but fun to know) ! Handlers in Android can be used to schedule code that runs after a specified amount of time. Say my phone is programmed to transmit a given intensity of light from its screen for 1 ms for each number in the byte array, Sid’s device can be programmed such that its ambient light sensor fishes for light every 1 ms and maps that intensity (lux) into a number between 0 and 127 as programmed (may sound complicated but it’s actually pretty simple under the hood) and stores it into it a new byte array. This process continues iteratively until all the 1048576 elements of my 1 MB byte array are transmitted!</p><p>At Sid’s device, this byte array is assembled back to a unit called file (as understood by, say Java) and is saved onto the internal storage in his phone. Transfer complete!</p><h3>Challenges</h3><p>Let’s take a break! Now we’re cool. Ever wondered how fast this process is? Let me spoil it for you — it’s insanely slow. That’s exactly why the title says, it’s just a theory! Let’s understand the math behind the speed. Heading back to my 1 MB file transfer, 1 MB is precisely 1048576 bytes and if a byte is transmitted for 1 ms as we saw above, unitary method has it that it would take ( 1048576 * 1 ) / 3600 minutes which is roughly 17 minutes to transmit an MB. Holy 17 minutes for an MB! Insanely impractical.</p><p>In addition to the speed constraint, we also have a couple of challenges at hand! Since we’re taking a ms to transfer a byte, did we ever wonder if Android can really go as fast? Let me tell you, 1 ms is technically the fastest that you schedule code in Android. Based on CPU speed and the OS optimization itself, perhaps it’s not really flipping light at 1 ms in my phone (the source) ! So that means, it’s technically going to take longer that 17 minutes — crazy again! Another technical issue could be clock synchronization. Mine as well as Sid’s phone would have to be synchronized to start transmitting as well as receive data at the same time — that’s when the 1 ms (the impractically chosen time interval) gap wouldn’t overlap (I’m sorry if that’s too complex) !</p><h3>Conclusion</h3><p>Just taps into one’s imagination, yet too complex for a few to grasp I assume as I tried my best to simplify the text keeping it concise at the same time! Though the concept is far too impractical to implement at the moment, maybe someone could come up with a smarter solution without hardware extensions! Cheers, I sign off.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b57045f2a6f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to interface with your car?]]></title>
            <link>https://thegeekylad.medium.com/how-to-interface-with-your-car-8adcee8a7085?source=rss-e799cb1226eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8adcee8a7085</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rahul Pillai]]></dc:creator>
            <pubDate>Mon, 05 Jun 2017 19:07:24 GMT</pubDate>
            <atom:updated>2017-06-05T19:07:24.951Z</atom:updated>
            <content:encoded><![CDATA[<p>OBD-II protocol has been around for quite some time now and it’s been a great breakthrough in communicating with vehicle ECUs and vehicular data analysis. While this protocol opens doors for innovators to work on h/w and s/w that can help troubleshoot vehicles, it also can lead to apps that make driving fun! Whatever be the end product, it all starts with the OBD-II based adapter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kaIzopQ-pn_BjvMbHC8M-w.jpeg" /><figcaption>Vgate VLINK OBD-II ELM327 Adapter</figcaption></figure><p>A heads on the adapter, it’s based on the OBD-II ELM327 protocol and works with most cars manufactured post the ’96 era. So it ought to work with your car unless you’ve got a Herbie. Yeah, that’s a laugh. This piece of writing isn’t focussed on setting up, but on how to send/receive data to/from this adapter. Let’s get started in Android!</p><h3><strong>The OBD Terminal Design</strong></h3><p>Messing with your Android Terminal without really firing up one physically is a feat made possible through an Android app, voila. This piece of writing again, assumes that you’ve got a rough idea about the Java behind the execution of simple terminal commands. Nevertheless, the OBD terminal is quite simple and wouldn’t necessitate this requirement. Let’s get started from scratch.</p><p>OBD-II adapters are bluetooth powered devices that communicate with their Android hosts through sockets. A socket for a particular adapter can be opened (connected) facilitating data exchange through IO streams. An adapter is identified by your Android device by virtue of it’s unique MAC or hardware ID. The MAC address can be viewed under Bluetooth settings -&gt; paired devices -&gt; your adapter’s properties on your Android phone. The MAC address is coupled with UUID (a universal identifier which (assume for the moment) is constant). With these details, you create your RFCOMM socket to interface with your car’s ECU. Now that you’ve created your socket, get the input and output streams linked with this socket to write commands directly to your car and get its response. That’s what’s shown here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*rHniZ_hXB6pb57M-jXjmhQ.png" /><figcaption>Connecting to your adapter and getting the linked IO streams</figcaption></figure><p>Now you’re set and what’s left is to send commands and receive their outputs and in order to process that, we bind the IO streams objects to their character-oriented stream classes’ objects. This makes communication easier. Now here’s our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*nCP9Kk_8gP0tdzvcYQFeqg.png" /><figcaption>Binding byte-oriented to character-oriented IO streams</figcaption></figure><h3>Writing Commands</h3><p>Now that’s how our framework looks for the most part! Now let’s go ahead and <strong>write some commands</strong> directly to the car and analyse the replies. Oh wait, what commands? Let’s take a deeper look into the OBD-II protocol.</p><p>Commands are understood as PIDs or process IDs which are basically hex numbers. They conveniently cover all possible commands designed to be handled by the protocol. A <strong>list of these commands</strong> can be found up here — <a href="https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01">https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01</a>.</p><p>Every command skeleton looks something like <strong>XX YY</strong>. The <strong>XX </strong>refer to the mode bits (<em>Mode 01 </em>in the aforementioned chart) and the <strong>YY </strong>refer to the command or PID bits (The first column in the aforementioned chart).</p><p>Let’s take a scenario where you’d wish to know your vehicle’s current RPM. Now let’s look up the list of commands to find the one that matches our motive. We see that the command <strong>01 0C</strong> could accomplish this. Bingo! Now let’s write this command using our <em>DataOutputStream</em> object and fetch the reply from our car.</p><p><strong>Now we have our completed code here.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*UQUd4EYJZ1B_fdCl8HKfvQ.png" /><figcaption>Sending a command to your car and receiving the response</figcaption></figure><p>Now that we’re done, I’d like to explain why the first occurrence of the <em>readLine() </em>method gives the command itself and now the output for which we write it once more (in the next line). This is because the android terminal in the backyard, looks something like this when we execute our command <strong>01 0C</strong>.</p><p>&gt;01 0c<br>41 0C 0D 4C</p><p>Now, our <em>BufferedReader </em>object captures both the lines — the first line that holds our command and the second that holds the output.</p><p>Voila! We’re done with a simple program that measures the RPM of our car at a given time using the OBD-II protocol. Ain’t it as simple? This is the crux of every killer vehicle diagnostics app. The most famous app that hits my mind right now is <strong>Torque </strong>— <a href="https://play.google.com/store/apps/details?id=org.prowl.torque&amp;hl=en">https://play.google.com/store/apps/details?id=org.prowl.torque&amp;hl=en</a>.</p><p>Hope this works alright for you, cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8adcee8a7085" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>