Lain weather widget : “Service not available at the moment”.

On my Arch system I use copycat-killer’s awesome themes. One of my favorites is the “multicolor” theme because it gives me a ton of info and it looks snappy and nice overall. One thing I was most happy about was the weather widget that came along with the themes. Anyway, here’s a pic of it in action during happier times.

2016-03-29-003232_1366x768_scrot.png

But since the past few days, the weather indicator on top was annoyingly showing “N/A” and the weather widget was giving me a “Service not available at the moment.” message.

3mpryRs

I googled around a bit and found out that the lain weather widget uses the Yahoo Weather API and that the devs at Yahoo decided that after 15th March, their weather API would give out data only to requests which were upgraded to Oauth 1, whatever the hell that is.

One of the answers here, however, suggested to simply replace “http://weather.yahooapis.com/” with “http://xml.weather.yahoo.com/” and I decided to do just that in the lain weather widget.

The init.lua file for the lain widgets which were part of the “yawn” library was at

/home/kody/.config/awesome/lain/widgets/yawn/init.lua

In that, I replaced the line

local api_url = 'http://weather.yahooapis.com/forecastrss'

to

local api_url = 'http://xml.weather.yahoo.com/forecastrss'

And then restarted awesome with Modkey+Ctrl+r, which resulted in my pretty looking working weather panel again. 🙂

UPDATE 12/04/16 : The weather widget stopped working again. Yahoo used to be cool! 😦

UPDATE 24/04/16 : After tinkering again, I realized that my current config files were not up to date with Copycat-killer’s github ones. He’s not using Yahoo Weather API anymore, but is using the OpenWeatherMap API. I used the new weather.lua widget of his and things are up and running once more.

 

How do I into GNU Privacy Guard?

I’ve asked myself the above question a ton of times and this guide here is the product of my struggles.

First of all, install the GPG package. If you are on Arch, you can use

# pacman -S gnupg

Also install rng-tools. This gives a random number generator which helps to add entropy quicker when generating your keys. (I have read that this results in insecure keys, but I think it should be pretty okay.)

# pacman -S rng-tools

Start the random number generation dump.

# rngd -r /dev/urandom

Then generate your keys.

gpg --gen-key

The process should be relatively painless. The defaults for everything should be good enough. Enter your name, comment and email-ID, secure your private key with a very strong passphrase. After enough entropy is created, you should be done. Now

 gpg --list-keys

Should show you your freshly generated key! Now your private key should be kept secret at all costs. Lock it away as if your life depended on it. If someone gets access to it, you’re screwed.

The next thing you need to do is to share your public key with people you want to communicate securely with. Most people just put their public keys on keyservers like the MIT keyserver and people who want a particular person’s public key can get their public key from the keyserver directly.

In order to put up your key on the MIT keyserver, create an ASCII-armored version of your public key :

gpg --export -a "KEYNAME" > public.key

Now copy and paste the contents of ‘public.key’ in the text box on the MIT keyserver page, it’ll take care of the rest.

Okay good. You have now created a public-private key pair and you have set up your public key for display. If you now find someone who you want to send an encrypted message to, first get ahold of their public key. Copy and paste their ASCII public key block into a file (I’m going to call it FRIENDS_PUB_KEY) and put it on your system. Next, you need to IMPORT that key of theirs.

gpg --import FRIENDS_PUB_KEY

The first thing you need to do after creating (or importing other public keys ) is to check your key’s fingerprint.

 gpg --edit-key FRIENDS_PUB_KEY

Now enter the following.

 gpg> fpr

This should output the key’s fingerprint.

This next step is very important. Once you have your friend’s key’s fingerprint, you need to verify that you and him have the SAME fingerprint (either over the phone, or snail mail or pigeon post). This ensures that the key has not been tampered with and that you will really be sending your encrypted messages to your friend and not to a man-in-the-middle. If your fingerprint and your friend’s fingerprint don’t match, then that means that someone has tampered with your friend’s public key and is probably waiting for you to send all of your messages to him instead of your friend.

Now if you want to encrypt a text file, a picture etc. this is how you do it.

gpg -e -u "YOUR_KEY_NAME" -r "RECEIPIENT_KEY_NAME" somefile 

This will create a file called ‘somefile.gpg’. You can now send this file over to your friend and be confident that he and only he will be able to decrypt it’s contents (unless ofcourse you’re in deep shit).

In order to decrypt a file you have got from a friend, here is what you do.

gpg -d somefile.gpg

GPG will automatically search for the relevant secret key to do the decryption with, if it finds the key, your file will be sucessfully decrypted. If the secret key doesn’t exist, it’ll complain saying that it can’t find the secret key.

Geeky shit with SAGE, notify-send and XKCD!

I came across this xkcd comic a while back and have practicing that every time I was bored and had nothing to do. (Pro tip : This kills a helluva lot of time while travelling!)

Now this semester I am taking a course on Algebraic Number Theory and some of the take home assignments required me to compute the class number of certain number fields. Instead of doing this the hard way, I decided to cheat and use SAGE,which is a computer algebra system for mathematicians to do fancy stuff. I haven’t explored it fully yet and I intend to do so during the summer. It’s really powerful because it integrates existing math software into it instead of “reinventing the wheel”.

One day when I was bored I decided to write a simple bash script to factor the time and display the result as a notification. The idea of the code was simple : get the time as a four digit number HHMM, pass that number to sage, ask it to factorize, store everything as a variable and push the factorization as a notification to the home screen.

After a bit of searching, I found out about notify-send, which is a cool little package which helps in displaying notifications.

Putting all these together, I came up with the following script.

#! /bin/sh
#
# factor.sh
# Copyright (C) 2016 kody <kody@kodyarch>
#
# This short script computes the prime factorization of the time considered
# as a four digit number. For example, it looks at 20:04 as 2004 and computes
# it's prime factorization.
#

TIME=$(date "+%H%M")
echo 'factor('$TIME')' | sage > ~/test1

FACTOR1=$(awk 'FNR==6 {print}' ~/test1 | cut -d ' ' -f2-)
FACTOR2=$(echo "$FACTOR1")

notify-send -t 10000 "The current time is $TIME." "And it's factorization is $FACTOR2."

rm ~/test1

Here is a picture of it in action!

screenFetch-2016-03-01_12-57-14

To send desktop notification from a background script, say via cron, running as root (replace X_user with the user running X):

 
# sudo -u X_user DISPLAY=:0 notify-send 'Hello world!' 'This is an example notification.'

 

O ye with silken hair.

A little something I just thought of writing on the spur while gazing hard at the hair of the girl sitting in front of me in a really really boring class.

O ye with silken hair,
Looking at you I despair.
For your locks, soft and meek
Seem like a mollified fractal, so to speak.

Just as in Mandelbrot’s set,
Your hair has a main bulb, where the bun has met
At a point, so near, so far and so light
Inaccessible but within sight.

From here, O maiden fair,
Emerge taut strands of hair
Like geodesics from infinity to and fro,
How perfect they go!

Your tresses, maiden fair, I recall
Seem like a tangent vector field
on the wedge sum of two spheres, big and small.

Brouwer was surely high,
when he proved the following lie:
“One cannot comb a hairy ball!”

O maiden fair, show Brouwer he is wrong,
His “proof” has stood for long,
Far too long!

As I write these lines, my conscience does prick,
People might whack me with a stick:
Brouwer’s theorem holds for a ball,
Not for the wedge sum of two spheres, big and small!

Alas, maiden fair, I was wrong.
But I’m not sad, for I have this song.
And now, I thank you, maiden fair,
For letting me write about your hair.

Fastest (and upto date) pacman mirrors.

We’ve all faced this problem sometime or the other : Installing/upgrading packages takes forever because the pacman mirrors are slow.
Thankfully, as always, the Arch wiki and pacman have us covered. Pacman itself comes with a bash script which is at

/usr/bin/rankmirrors

. This script ranks mirrors according to their connection and opening speeds.
First make a backup of your existing mirrorlist.

# cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup

Edit the mirrorlist and uncomment all mirrors for testing.

# sed -i 's/^# Server/Server/' /etc/pacman.d/mirrorlist.backup

Finally rank the mirrors. The ‘6’ below outputs the 6 fastest mirrors.

# rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist

Note that it is good practice now to run the following.

# pacman -Syyu

This forces a redownload of the package lists and upgrades the packages. Passing two
–refresh or -y flags will force a refresh of all package lists even if they appear to be up to date.

How to transfer an existing Arch install onto a new laptop.

Quite recently I realized that I needed  a new laptop because my old one  was in pretty bad shape. It had been through 4 years of constant abuse and as a result it had busted speakers, a faulty touchpad and non-responding keys.

But I faced a daunting task. All of my work over the past one year and a half had gone into the Arch install on my old laptop. How was I supposed to ensure that the whole thing remained as it was on the new laptop? I looked at a few pages on the Arch wiki such as this one here, which dealt with this exact issue. I finally decided that I needed to take this plunge and so I went ahead with that article’s instructions.

Step 1 :

First, I followed this page and backed up my entire root tree onto my external hard disk with the command

# rsync --info=progress2-aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder

The contents of /dev, /proc, /sys, /tmp and /run were excluded because they are populated at boot (while the folders themselves are not created), /lost+found is filesystem-specific. If you are running this on the same folder, you may want to include the –delete option to keep the two folders in sync.

Step 2 :

In your old system, enter the following.

$ pacman -Qqe | grep -vx "$(pacman -Qqm)" > Packages
$ pacman -Qqm > Packages.aur

This creates a list of all installed packages on your system via pacman and also those from the Arch User Repository.

Step 3 :

Next, I installed Arch all over again on the new laptop, following the Beginner’s guide. Edit the pacman mirrors as you deem them fit.

Step 4 :

Plug your external hard disk into the new laptop, mount it and copy the old pacman cache (/var/cache/pacman/pkg) onto the new install. Now, the next command

# xargs -a Packages pacman -S --noconfirm --needed

Was not working for me as just read the existing package names and said it was skipping them as it was already installed. I didn’t figure out why that was exactly, and proceeeded as follows. I made a new list of installed packages on the new system ;

$ pacman -Qqe | grep -vx "$(pacman -Qqm)" > Packages-new

Next, get the old “Packages” file which you made on the old system and now sort the two files.

$ sort Packages-new > 1
$ sort Packages > 2

And finally.

diff 1 2 | grep "\>" | sed -e 's/> //' > final

The file “final” now contains File2 – File1, that is, the list of packages which are not in the new system. Now do the following.

for x in $(cat final); do pacman -S $x --noconfirm; done

Actually, this whole sorting and subtracting thing could have been avoided with an additional flag “–needed” for pacman, but somehow that wasn’t working for me. Hence this. Repeat the same process for AUR packages. If you use yaourt, replace “pacman” by “yaourt” in the last command and feed in the AUR package list.

Step 5 :

Create a non-priviledged user, and make sure you’re able to execute startx as that user. Once you do, X creates an .Xauthority file in the home directory. Preserve that file somehow, say by changing it to .Xauthority-old temporarily. The reason I did this was before, I pulled in everything and it was using the .Xauthority file of the backup when I executed startx. This resulted in a “timeout in locking authority file” error and X wouldn’t start. I did the following for a fix.
Next, pull in your entire home directory from the backup.

rsync --info=progress2 -avh /path/to/backup/home/user /home/user

After this is done, make sure to delete the old .Xauthority file and rename the .Xauthority-old file to .Xauthority. Now startx should work normally.

I found it pretty amazing that in essence, it’s just your home directory and your packages which control your entire system. Even though this might sound a little trivial, it still amazed me when everything worked perfectly finally. I even recovered my open tabs in firefox!