India is No Longer India

Aatish Taseer writes:

By the time I was an adult, the urban elites and the “heart of the nation” had lost the means to communicate. The elites lived in a state of gated comfort, oblivious to the hard realities of Indian life—poverty and unemployment, of course, but also urban ruin and environmental degradation. The schools their children went to set them at a great remove from India, on the levels of language, religion, and culture. Every feature of their life was designed, to quote Robert Byron on the English in India, to blunt their “natural interest in the country and sympathy with its people.” Their life was, culturally speaking, an adjunct to Western Europe and America; their values were a hybrid, in which India was served nominally while the West was reduced to a source of permissiveness and materialism. They thought they lived in a world where the “idea of India” reigned supreme—but all the while, the constituency for this idea was being steadily eroded. It was Bharat that was ascendant. India’s leaders today speak with contempt of the principles on which this young nation was founded. They look back instead to the timeless glories of the Hindu past. They scorn the “Khan Market gang”—a reference to a fashionable market near where I grew up that has become a metonym for the Indian elite. Hindu nationalists trace a direct line between the foreign occupiers who destroyed the Hindu past—first Muslims, then the British—and India’s Westernized elite (and India’s Muslims), whom they see as heirs to foreign occupation, still enjoying the privileges of plunder.

https://www.theatlantic.com/magazine/archive/2020/05/exile-in-the-age-of-modi/609073/

Fire and Ice

This is a flame graph:

Source: https://blog.codecentric.de/en/2017/09/jvm-fire-using-flame-graphs-analyse-performance/

Turn it upside down, and you get an icicle graph:

Source: https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference

This means the flame graph view in the Firefox and Chrome profilers is actually an icicle graph view. Who knew?

I learned this tidbit of trivia when I was trying to figure out whether it’s practical to implement a flame graph in the browser using SVG.

Turns out SVG gets too slow if you have a few thousand elements on the screen. You probably want to use <canvas> if you need to visualize a ton of data at once. For this reason, both Firefox and Chrome use <canvas> for their flame graph views. Here is Firefox’s implementation, and here is Chrome’s.

Week of 20 April, 2020

  • Anxiety was bad this week. I was up until 3AM on Tuesday night because I couldn’t turn off my brain, no matter how much I tried. I don’t know what triggered it, but getting off social media and news websites seems to have fixed it.
  • I’ve started spending a bit of time each morning reading short stories in Punjabi. I no longer struggle with the grammar or the script — I’ve already been reading the news in Punjabi for a few months — but a lot of the words are new to me. Having to constantly look up words slows me down, but I’m building a lot of vocabulary very fast.
  • I’ve given in and ordered a Roomba for the house.
  • Our girl kitten turned out to be a boy kitten, which explains the constant fights. The older cat doesn’t like this new roommate at all.
  • Not much progress with Crafting Interpreters this week, but I did add a way to convert an AST into a Graphviz diagram. Very proud of this one.

Week of 13 April, 2020

  • The cats have stopped fighting! Minor squabbles still break out once or twice a day, but for the most part they’ve settled into an uneasy truce.
  • Found a contract for the next six weeks. It’s not a Rust gig as I had hoped, but it involves some heavyweight data visualization in the browser that will call for a lot of cleverness. I expect to enjoy this thoroughly.
  • Eating a lot of cheese this week. No regrets.
  • Working through Crafting Interpreters at a decent pace, though I could probably be going faster. Instead of just translating the Java code in the book, I’m trying to write idiomatic Rust as far as possible. This takes longer and makes my design totally different from what’s in the book, but I’m learning far more this way. I’ve also added a few additional features to my implementation, like proper line editing in the REPL using rustyline.
  • My fitness trainer now has an online lesson plan, so I’m back to working out. Feels good to be doing something with this bag of meat.
  • Still irritated at how much pointless detail that Gandhi book has. But I’m going to get through this thing one way or another.
  • Still playing Radiant Historia and Into the Breach, still loving the hell out of both games.
  • Album highlight of the week is Cha Cha Palace by Angelica Garcia.

Perpendicular

Years ago, when going outside was legal and I still believed in Pitchfork scores, I started a music blog with a couple of friends. We eventually shut it down because reasons, but thankfully The Wayback Machine managed to capture a few snapshots.

Here it is in all its glory, minus the CSS and media.

GoAccess

CloudFlare recently informed me that this website was getting thousands of hits every day, which is an unusual occurrence. I pulled up Google Analytics to figure out where all that traffic was coming from, only to be informed that I was getting three to four hundred daily visitors at most.

This felt a bit suspicious, so I dug into my Nginx logs to see if something was up. I pulled up the logs in Vim, but it was too hard to make sense of any of the raw data by reading it line-by-line. I needed something that could help me visualize my logs. I asked around and found a little tool called GoAccess.

GoAccess is an open-source log analyzer that can help you visualize your server logs in the terminal or use them to produce an HTML report. I installed it from the Ubuntu repositories and ran it:

goaccess /var/log/nginx/access.log

I was greeted with a dialog listing a bunch of popular log formats, asking me which one my file conformed to. After searching the Web for a bit, I figured out that Nginx uses something called the NCSA Combined Log Format for its messages. I picked that in the dialog and was on my way.

After a few minutes of looking at the aggregated data, I felt that analyzing just one file wasn’t telling me the entire story. I wondered if I could analyze all the logs produced by Nginx in the last month at once. After searching the Web a bit more, I found that I could use zcat to unzip the older logs and print them to stdout, and then pipe that into GoAccess. So I did this:

zcat -f /var/log/nginx/access.log* | goaccess --log-format=COMBINED

Turns out someone was trying to exploit my website by by sending malicious inputs to WordPress’s xmlrpc.php. From the access patterns, it looked more like a drive-by automated attack than a human trying to break in. Since I didn’t need any of the features enabled by the WordPress API, I blocked access to xmlrpc.php entirely:

location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
}

The downside to this is that I can’t post to my website from the WordPress app on my iPhone. But that’s not something I do often, so losing that feature is not a big deal.

After this incident, I also removed Google Analytics from my website. I’m fundamentally opposed to business models that are based on surveillance-based advertising, which is why I try to stay away from Google products as much as possible. My server logs give me enough data to judge how well my posts are doing, and with GoAccess I now have a reasonable way of querying and visualizing that data. That’s pretty much all I need.

The Expression Problem

While reading Crafting Interpreters, I learned about something called the expression problem. It’s a problem I’ve run into countless times, especially in larger projects, but I never knew it had an actual name. As usual, Eli Bendersky has an in-depth article about the problem and its solution in C++ and Clojure.

After reading Eli’s article, I wondered how the problem would manifest in Rust and what the solution would be. Turns out it’s not too complicated. Want to add a new type? Just add it and implement all the traits you care about. Want to add a new operation? Define a new trait and implement it on all the types you care about. This article goes into more detail on what that looks like.