Fixing headphone jack in Ubuntu 20.04

Posted on Leave a comment

As weird and funny as it may sound, Ubuntu isn’t able to play sounds on my laptop‘s 3.5mm headphone jack. Yes, the gentle, innocuous, innocent headphone jack that we all love and use. And mine’s not even a super-fancy laptop with uncommon hardware. It’s a Dell Inspiron 7000 series laptop with an Intel chipset. How more commonplace can things get than this?

After fiddling around for quite a bit, I was finally able to get it to work. I guess the issue has something to do with (the notorious?) PulseAudio.

Anyway, the trick for me was to use a little utility called hdajackretask. It’s part of the alsa-tools-gui package and helps you retask (remap or whatever) your PC’s audio ports (including internal speakers and HDMI). Read the documentation here (simple and fun): https://fossies.org/linux/alsa-tools/hdajackretask/README

Install it using this command:

sudo apt install alsa-tools-gui

Next, open the app from either command line (hdajackretask) or menu. Here’s my overriden configuration for reference (headphone, right side):

Hit Apply Now, and boom! Headphones are finally working. It’s important to note that this is not a silver bullet that will fix all jack-related sound issues. It just so happened in my case that retasking was necessary. I have to do it every time I plug in my headphones (even with the boot override installed). Weirdo, I know, but at least it works.

You may receive this error when you apply the overrides. I guess it’s totally fine to ignore it. It’s probably because of a restart of pulseaudio system. Things work despite the error.

Feels to weird that it’s 2020 and such retasking has to be done manually!

Note that getting my Bluetooth audio devices to work – especially my AirPods – remains a pain in the you-know-what.

Made the switch back from Mac to Linux

Posted on 2 Comments

After serving me dutifully for more than 4 years, my MacBook Pro 13″ (early 2015)’s battery died. It was a terrible sight. I was in the mid of a programming spree when that happened. There was a powercut and, whoosh, everything disappeared from the screen. It was puzzling at first. I thought my laptop had shutdown under the strain of my app’s build process. On powering it on again, my Mac appeared to behaved normally. That was until I noticed the battery health icon in system tray. All of a sudden, it was asking me to service the battery and power source was set to power adapter.

CreditMake Tech Easier

I was stunned, to say the least. I immediately googled around and found a few things to try and fix the situation, like tips mentioned in this article (reset SMC and all). Unfortunately, nothing worked for me. I was left with no option but to accept that my MacBook was not going to be the same.

During the next few days, I continued to use my Mac with adapter as power source. With frequent power cuts, it was annoying to see the laptop shutdown suddenly and then waste precious time restore everything. For a while, I considered getting a new battery. What held me back was its prohibitive cost (Rs. 10-12k) and lockdown due to COVID-19. To make matters worse, my MacBook strangely got slow and sluggish. I could feel a noticeable 20-30% reduction in speed and power. Software builds took more time, browsing and scrolling web pages were janky, etc.

For the next couple of weeks, I resorted to using my wife’s old, insanely under-powered laptop. It was hard at first, but when I had set it up with Ubuntu Linux things got a lot better. I could run VS Code, Docker, Firefox, all at once. It took some time and patience to get used to the new speed standards, but at least this thing was presently more reliable than my no battery MacBook.

Days passed by. I continued to do my daily work on the oldie, and found myself not touching my MacBook for days at a stretch. It was a weird feeling – I had never not opened my Mac at least once a day in all of its four years.

In the following days, I started feeling like getting a new laptop. For a professional programmer like me, a laptop was his “tool of the trade”, and it was not wise to keep using an old tool on the cost of productivity. After a couple of days research I settled on Dell Inspiron 7591. It was a far cry from the premium world of Apple laptops, but it was respectably ahead in terms of sheer performance.

I’m typing this post from my new laptop, running Ubuntu side-by-side with Windows. Linux is my primary OS once again, and I’m happy to be back. Although, to be honest, I will certainly miss my Mac’s convenience and premium feel. But the new thing has a lot of good stuff to offset that:

  • way more power*
  • larger screen
  • decently lightweight
  • a nice keyboard
  • I can finally play games again 😎

Intel Core i5-9300H
16 GB DDR4 2666 MHz RAM
512 GB SSD
NVIDIA GeForce 1050 GTX

* My Dell Inspiron 7591’s configuration

Here’s the customary desktop screenshot:

Ubuntu 20.04 running on my new Dell Inspiron 7591

How to deal with node_modules in a Dockerized Node application?

Posted on Leave a comment

There are tens of thousands of blogs, articles and forum threads out there on containerizing a Node.js application. We have everything from outright bad advices to informed and tested opinions. This short post is about a very specific aspect of Dockerinzing a Node app, something that is usually not addressed or given as an after-thought in these articles.

Once you have a Node app up and running in Docker, things are well until you – like all good developers – start adding or removing NPM packages. Nasty things happen, such as:

  • packages get installed on your local (host) filesystem but are not available inside the container
  • packages get installed on your container’s filesystem but are not available on your local
  • there’s a mismatch between versions of the same package in host and container
  • permission issues while installing or removing packages

All these can be solved by correctly using Docker volumes. A volume is basically a way to make parts of container’s filesystem available to host and vice-versa. Not understanding volumes properly may also lead to one of the issues listed above.

I had a similar experience in one of my projects. See the fix:
https://github.com/universalnative/un-website/commit/0eaaca98adac46bf9b1553e66d6acd9d731db43d

As noted in the stackoverflow answer cited in the commit:

When docker builds the image, the node_modules directory is created within the worker app directory, and all the dependencies are installed there. Then on runtime the worker app directory from outside docker is mounted into the docker instance (which does not have the installed node_modules), hiding the node_modules you just installed. You can verify this by removing the mounted volume from your docker-compose.yml.

https://stackoverflow.com/a/32785014/1775160

This is a powerful thing to remember. Once you know how volumes work, you’ll be able to better troubleshoot your Node app when things are wrong. For example, when I recently installed a new NPM package in my local I knew I had to do something like this to make it available inside the container as well:

https://github.com/universalnative/un-website/commit/3fa9c9a79c35a3ddbf39079d16b7dbca12105c0d#diff-4e5e90c6228fd48698d074241c2ba760

Why didn’t I just mount my host node_modules to container’s node_modules? Here’s the explanation:

An alternative approach is to mount host node_modules as a volume in container, but that will override container’s own node_modules folder with host’s. Keeping things independent allows for cleaner and easier troubleshooting of installed/missing packages.

This the approach I prefer, which of course is not certified gold. I works for me well. Besides, yarn installing packages each time container comes up does so incrementally (only new packages are fetched and installed). A win-win 🙂

Hello, Deno

Posted on Leave a comment

Deno v1 is here, and so is my experiment. Unlike my usual first programs, this one is a bit better than a pure “Hello, world”. So not only it is a meaningful program (does not literally print out “hello world”), it also has data models, unit tests and CI integration (Travis).

From its documentation:

A super-simple Deno app that pulls (from an API) national COVID-19 stats for India, and displays the total count of people who have recovered from the disease till yesterday.

What else did you expect? Let’s spread some positivity in tough times!

Check it out here and let me know your thoughts (if you exist):

https://github.com/anuragbhd/hello-deno

Btw, this is the best damn geeky one-liner code to explain what is Deno. Totally cool.