For Freedom's Sake

A blog about free software, my coding adventures etc.

I put together a small script to extract highlights from the Kindle and put them into separate files for each title. Keep in mind that the code expects no empty end of line. Create a highlights directory in the project root where the files will be stored.

#clip.py

class Clip:
    def __str__(self):
        return self.title + " " + self.text

    def __repr__(self):
        return self.__str__()
    
    def __init__(self, title, text):
        self.title = title
        self.text = text
# parse.py
import os
from os import walk
from clip import Clip

def parse_and_generate_notes():
    clips = []
    with open("clippings.txt", 'r') as data:
        highlights = data.read().split("==========\n")
        for highlight in highlights:
            tokens = highlight.split("\n")
            print("\n".join(tokens))
            text = tokens[3].strip()
            title = tokens[0]
            clips.append(Clip(title, text))

    titles = set([clip.title for clip in clips])
    clips_by_books = {}

    per_title_files = []
    for (dirpath, dirnames, filenames) in walk("./highlights"):
        per_title_files.extend(filenames)
        break
    

    for title in titles:
        clips_by_books[title] = [clip for clip in clips if clip.title == title]
        if(title == ""):
            filename = "highlights/untitled.md"
        else:
            filename = "highlights/" + title.replace("/","_").replace(" ","_").replace("(","").replace(")","") + ".md"
        if os.path.exists(filename):
            append_write = 'a' # append if already exists
        else:
            append_write = 'w' # make a new file if not

        with open(filename, append_write) as file:
            file.write("\n\n".join([clip.text for clip in clips_by_books[title]]))

if __name__ == "__main__":
    parse_and_generate_notes()
    

The Back Story

One of my aims for this year is to get a phone that will work without having a Google account on it. The reason for that is having better privacy controls, and using that device as my main means of communications. Finding out that Google tracks everything I do on my phone is definitely a reason for that. However, is it really possible to not have to log in to a Google account to use an Android phone?

What is Play Services?

Many apps on our phones rely on an underlying service that makes it easier for those apps to leverage several functionality. This service includes the Location feature, Maps, Ads etc. If this underlying service didn't exist, the app developers would have to include all the code in each of their packages to make use of these features instead of just a reference to what Google already ships under the hood. They also provide updates on a periodic basis to bring in the latest features that they have developed.

Why should I care if Play Services exists on my phone?

It's Google, they gather all the data about you, including your application usage patterns, your notifications(probably from applications that don't even belong to the Google suite) etc.

The answer to the question.

It's definitely possible to run an Android device without Google Play Services. There is an alternative application store called f-droid which has applications that are completely free and open source. They usually need just enough permissions to run the application, and also do not expect you to run Google Play Services on your phone to be able to use them. When I finally have the device, I'll make another post about how much or how little I have to use the phone with Google Play Services for my essentials.

A few days ago, there was a query in one of the Slack channels about how to use our custom AWS login mechanism work from the CLI for India based employees because our OU in LDAP was different and therefore, we had to enter our usernames differently while using that tool. I responded to it because I'd struggled my way around making it work, and as a suggestion I also told them that I have an alias created so that I don't have to type that long winded command every time.

One of the responses to that was from an individual who said creating an alias takes away the ability to pass in CLI flags to mix and match the options, therefore should be discouraged.

I've been pondering about this for a while now and am convinced that I'd still try to create multiple aliases for the options I commonly use in my daily workflow. And if that is difficult to achieve, I'd at least try to create an auto-completion script on my shell environment for this command so that I have assistance while typing it in.

I get annoyed when I see my colleagues not have Git auto completion on their computers and struggle with typing in commands which should ideally be git fet<tab> or<tab> or some such.

One of the key takeaways from the book The Pragmatic Programmer for me has been to reduce the number of keystrokes I have to make. Because the more humans are involved, the more error prone the end result is.

Having installed two GNU/Linux OSes on my laptop(a mid-2012 Macbook Pro), I'd planned on using KDE Neon as my daily driver, and using the other partition for distro hopping. I currently have Ubuntu 18.04 on it, but I plan on other OSes go in there to try out, and get a feel for. I ran a poll on Mastodon the other day to get others' opinion on what I should try next. It was three way tie between Elementary, Manjaro, and Arch (2 votes each). The only other vote went to Fedora, which I'm not keen on trying anyway.

I'm planning to do Elementary first. I downloaded the ISO and made into a bootable USB disk with Rosa Image Writer. The challenge came after that. I booted with the USB inserted, but Grub apparently doesn't detect USBs unless it is told to. So here's what I found from a Super User thread. This is what worked for me. The other answers were throwing all over the place and I'm glad I didn't brick the laptop doing something foolish.

Let me document the steps I ran for posterity.

  • While booting, press C on the Grub menu to get into the Grub console.
  • Do an ls, and run ls with all the results from the first ls to figure out which one is your bootable USB. For me, it was(hd0).
  • Run chainloader (hd0)/EFI/grubx64.efi.
  • Run boot to boot from the USB.

When you remove the USB and reboot again, Grub works as usual and gives you the options for the installed OSes.

The Back Story

I'd known about Dotfiles and their importance for the longest time, yet took no effort to manage them through a repository of any kind. What this meant was that my workflow for moving to a new machine at work (when I moved from a PC with a CentOS VM) to a Macbook, and then from that Macbook to a newer version of it was to copy the entire home directory, including files I didn't need anymore. There was always the constant worry that I'd lose my aliases, prompt alterations etc and would have to set them up again from scratch if the hard disk crashed overnight.

What put me off using a repository for managing these files was that the learning curve seemed really high, having to write scripts to create links to them, or start by using publicly available dotfiles repositories. The issue with the last approach is that I'd end up with things I don't need, having no support as such for anything that goes wrong etc. Looking back, I missed out on opportunities to learn advanced shell scripting by doing something like that.

In comes YADM

After deciding on moving to free software, and subscribing to some podcasts, I came across YADM, which stands for Yet Another Dotfile Manager.

The premise of YADM is simple. The home directory is treated like a git repository and we can execute git commands to manage the files. Instead of git, one has to use yadm to do so, and yadm takes care of the rest.

The Process

Installing YADM is simple. For Ubuntu based distros, the package is available on the standard apt repositories, though it's outdated like I learned yesterday trying to play around with the bootstrap command which expects an executable at a documented path. The old package expects the file at a different location to what's in the latest documentation.

After installing YADM, keep adding the files like .bashrc, .bash_profile, .gitconfig, .gitignore etc using yadm add, add a remote using yadm remote add <url_of_remote_repository>, yadm commit etc.

The tool also supports templating,, secrets management etc though I haven't had a need to use them yet.

First Impressions

This tool takes away the procrastination and learning curve factor from those who want to start maintaining their dotfiles. Having the safety net of a git system means that I can experiment with different configurations with the option of reverting to the original without much effort.

Gotchas

Like I mentioned before, the package in the apt repository is outdated. I would have been better off installing it from source instead.

The Back Story

It must come as a surprise that a blog that's about free software has its first post on installing a free OS on very proprietary hardware. When I look back on my own journey with software, it has been one of running licensed software (original and pirated), installing Fedora on a laptop that was getting to the end of its life because I wanted to learn what GNU/Linux was all about, and then having to work on a laptop running Linux at work. When it was time to get a new laptop 7 years ago, I decided to go for a Macbook Pro because the specs looked good and I was told great things about the operating system by some of my friends. Very soon, I had changes of jobs, and ended up with a Macbook at work as well. OS X looked very neat in the beginning. I purchased some software which made my life easier by improving my productivity through keyboard shortcuts, having system metrics displayed on the system tray etc.

Over the years, I started getting annoyed with the OS except for the conveniently placed Cmd key which made the said shortcuts a pleasure to work with, instead of having to use the Ctrl key which is placed at a position where one has to take their hand(s) off the home row to trigger shortcuts, at which point I'd rather use the mouse to do the same actions.

Fast forward to the later months of last year, there was the great exodus from Twitter to Fediverse, which opened my eyes to the world of free software and also reignited the love in me for looking at software dabbling as a hobby. I also gained enlightenment on the perils of being inside walled gardens, and have been trying to get out of those step by step. One such step was installing a free OS on my old Macbook Pro. The reason I did that instead of buying a more compatible device was that I wanted to upcycle my device because the hardware is still pretty good on it.

The Choices

I explored various options for desktops on virtual machines, and liked the looks of KDE on Ubuntu. However, there are two options for those who want to take that route. There's Kubuntu, which is a stable desktop engine on top of a very stable OS. Then there's KDE Neon which is a rolling desktop engine on top of a very stable OS. I decided to take the risk of having KDE Neon on my machine because it felt interesting to be able to get upgrades to the UX features more regularly while the underlying software remained stable and supported. I did inadvertently create a playground for a second OS, but I'll get to that in the next section.

The Process

Armed with a bootable USB, I sat down to create a partition for the new OS on my disk. I still didn't know if I was still ready for a total GNU/Linux experience yet, so I had planned on preserving OS X in one partition. I then found that installing KDE Neon wasn't working well with it getting stuck on os-probe during the installation process (I found what it was doing by looking at the logs by running live OS first and then running the installer from inside that environment). I wondered if installing a vanilla Ubuntu would solve it, so I created a bootable disk with that instead. While booting the system up, I realized I'd messed up the boot loader for good, so I decided to go ahead and wipe out the entire disk. However, I still wasn't satisfied because I couldn't install what I really wanted. So the next thing I did after installing the OS was downloading the KDE Neon ISO and creating an installer for that.

I also realized that I could actually have two OSes sitting side by side, so I used the partition utility to create a larger partition for installing KDE Neon and this Ubuntu partition for any distro hopping I'd wish to do going forward.

This time though, the process was smooth, and I was able to install KDE Neon without much effort. After a day of fighting things I didn't have any idea about, I had what I wanted on the Macbook.

First Impressions

Dual screen setup works great. I do wish there was way (maybe there is one, I just haven't found it yet) to open a new window/app in the screen on which the focus currently is.

KRunner is great. It does most of the things I used to do with Alfred on OS X. Klipper app takes care of my second favourite feature on Alfred, which is multi-clipboard.

Customizability of almost everything is nice to have. I particularly enjoyed changing the look and feel of the login screens.

Gotchas

  • Ubuntu detected WiFi during the installation process, but didn't after the process had finished.
  • Always back up your system.
  • Keep a network cable handy for when WiFi doesn't work.
  • Colemak layout with English (UK) makes several keys misbehave, including the pipe “|” key which is essential on a shell, so stick to English (US).

Conclusion

I'm in love with operating systems again and what they can do for me. I'd love to go over some of the things I've set up on this machine in some follow up posts, what works for me, what doesn't etc.