If you’re on a Desktop browser, it is easy enough to see the Mobile version of a Facebook Link. All one has to do is replace the ‘www‘ in the URL with ‘m‘ and press Enter. However, if one is sent the mobile version of a Facebook link, it is not that straight forward to convert it into the desktop format if you’re surfing on a Desktop browser. The default format of the mobile link that Facebook generates is as follows:

https://m.facebook.com/story.php?story_fbid=10154615255996455&substory_index=0&id=13527056454

Unfortunately, just changing ‘m’ to ‘www’ will not get you to the desktop version of this Facebook link. Instead, it will give you “This page isn’t available” error. To actually get to the desktop link, it has to be converted into the following format:

https://www.facebook.com/13527056454/posts/10154615255996455

The ‘id’ portion of the link became the first number in the above URL, while the ‘story_fbid’ portion of the link became the second number. However, it is painful to do this manually every single time. Since the time I started working on Alt News, I have had to do this exercise numerous times. To make it easier for me and everyone else out there, I created a small bookmarklet that can be dragged to the Bookmark bar.

M2D-FB

Drag the above link to your Bookmark bar, and whenever you are stuck with the mobile version of a Facebook post on a Desktop browser, click the above link to instantly convert it into a Desktop Facebook post.

The code for this bookmarklet is as follows:

function getParam(param) {
  var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for (var i=0;i<url.length;i++) {
         var params = url[i].split("=");
         if(params[0] == param)
          return params[1];
  }
  return false;
}

location.href='http://www.facebook.com/'+getParam("id")+'/posts/'+getParam("story_fbid")

The getParam function has been borrowed from here.

Bookmarklet creator at http://mrcoles.com/bookmarklet/ was used to convert the Javascript code into a Bookmarklet.

Using the Mac Address of Network Interfaces in programs is a common requirement. The old age way of getting the mac address programatically on linux was to parse the not-so-machine-friendly ifconfig output. However with the sysfs file system mounted under /sys, accessing information from kernel sub-systems has become very easy.

e.g. The Mac Address of eth0 interface can be accessed by reading the /sys/class/net/eth0/address file.

Wlan0-Eth0-Address-Programatically-sysfs

The code below is an example of how to use parse this information from within a C program.

#include <stdio.h>
#include <string.h>
#include <stdint.h>

int mac_get_ascii_from_file(const char *filename, char *addr) {
  FILE *fp;
  int i = 0;
  char c;
  fp = fopen(filename, "r");
  if (fp != NULL) {
    while (!feof(fp)) {
      c = fgetc(fp);
      if (c == ':')
        continue;
      if (c == '\n')
        break;
      addr[i++] = c;
    }
  }
  fclose(fp);
  return 0;
}

int mac_get_binary_from_file(const char *filename, uint8_t * mac) {
  int status = 1;
  char buf[256];
  FILE *fp = fopen(filename, "rt");
  memset(buf, 0, 256);
  if (fp) {
    if (fgets(buf, sizeof buf, fp) > 0) {
      sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mac[0],
             &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
      status = 0;
    }
    fclose(fp);
  }
  return status;
}

int main(void) {
  char macaddr[13];
  uint8_t mac[6];
  memset(macaddr, '\0', 13);
  mac_get_ascii_from_file("/sys/class/net/eth0/address", macaddr);
  printf("My Mac Address - %s\n", macaddr);
  mac_get_binary_from_file("/sys/class/net/eth0/address", mac);
  printf("My Mac Address - %hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  return 0;
}

The sample output of the above program is shown below.

Output-of-macaddr-program

Gatttool is a tool distributed along with Bluez, the default linux bluetooth stack, to interact with Bluetooth Low Energy (BLE) devices. Currently I have a TI SensorTag with me for a project I’m working on and I’m playing around with it. Most of the examples on the internet which show how to use gatttool to read the TI Tag have shown how to use gatttool in its interactive mode (-I). For eg, to read the temperature sensor, you’d do the following using gatttool’s interactive mode

@~ $ sudo gatttool -b BC:6A:29:AE:CC:23 -I
[   ][BC:6A:29:AE:CC:23][LE]> connect
[CON][BC:6A:29:AE:CC:23][LE]> char-read-hnd 0x25
[CON][BC:6A:29:AE:CC:23][LE]> 
Characteristic value/descriptor: 00 00 00 00 
[CON][BC:6A:29:AE:CC:23][LE]> char-write-cmd 0x29 01
[CON][BC:6A:29:AE:CC:23][LE]> char-read-hnd 0x25
[CON][BC:6A:29:AE:CC:23][LE]> 
Characteristic value/descriptor: f0 fe 88 0e 
[CON][BC:6A:29:AE:CC:23][LE]> exit

However gatttool also offers a non-interactive mode which hasn’t been documented. To achieve the above result in manual, non-interactive mode, you would do the following;

@$ sudo hciconfig hci0 down; sudo hciconfig hci0 up
@$ sudo gatttool -b BC:6A:29:AE:CC:23 --char-read -a 0x25; sleep 1; sudo gatttool -b BC:6A:29:AE:CC:23 --char-write -a 0x29 -n 01; sleep 1; sudo gatttool -b BC:6A:29:AE:CC:23 --char-read -a 0x25; 
Characteristic value/descriptor: 00 00 00 00 
Characteristic value/descriptor: 36 ff 68 0e

During the course of development, sometimes one needs to load a specific library from a specific path instead of the stock library that comes installed with the linux operating system. In such cases, LD_PRELOAD is a useful tool.

For example, my Ubuntu 14.04 laptop has the Bluez (linux bluetooth stack) version 4.101-0ubuntu13 installed by default. Thats a pretty old one. Since I wanted to use a newer version of the library for a project of mine and I didn’t want to overwrite my stock library, I installed the newer version (5.19) in a dedicated directory i.e. /home/pratik/Developer/CL/bluez-5.19-install. As a result, the newer version of the library resided at /home/pratik/Developer/CL/bluez-5.19-install/lib/libbluetooth.so.3. So now how do I explicity make a binary which is dependent on the bluetooth library use the one installed at the above mentioned location?

Trick is to use LD_PRELOAD. For eg. If I’m running a program called ‘a-bluetooth-program’ and I want to run it against the new library, this is what I do.

LD_PRELOAD=/home/pratik/Developer/CL/bluez-5.19-install/lib/libbluetooth.so.3 a-bluetooth-program

How do I know the trick is working? Of course by using ldd.

@$ LD_PRELOAD=/home/pratik/Developer/CloudLeaf/bluez-5.19-install/lib/libbluetooth.so.3 ldd st
	linux-vdso.so.1 =>  (0x00007fffe1ee9000)
	/home/pratik/Developer/CloudLeaf/bluez-5.19-install/lib/libbluetooth.so.3 (0x00007f1b5286f000)
	libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f1b52628000)
	libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f1b523fe000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1b52038000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1b51e34000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f1b52a90000)

If you look at the output of ldd command which is used to print the shared libraries required by a command, you will see that st is now linking to the newer version of the library.

Every since Microsoft bought off Skype, they have decided that they are NOT going to let you go offline. Thats how much they love you being online. So well, you have to knock off Microsoft from your Skype account to be able to go offline.

  • Log on to your Skype online account settings => https://secure.skype.com/portal/account/settings
  • Unlink the Microsoft Account. Once unlinked, your Account settings page will look like the screenshot below.
    Skype-Always-Online-Problem
  • In a few seconds, knocking Microsoft out of your Skype account should bear results.
  • Follow suit for other (IT) problems in your life. Say no to Microsoft.

Usually wireshark is used to sniff packets traversing a network. But how does one sniff a unix domain socket? Using socat as a proxy is a neat trick to capture packets traversing a unix socket.

In the below command, /tmp/originalsocket is the socket the Unix Socket Server is listening on, while /tmp/duplicatesocket is the socket that the unix client should connect to. socat will dump all the transactions that go on in a hexadecimal format

sudo socat -t100 -x -v UNIX-LISTEN:/tmp/duplicatesocket,mode=777,reuseaddr,fork UNIX-CONNECT:/tmp/originalsocket

Besides my regular Github freethinker account, I had to create a new github account for my new job. Problem was how to manage different ssh keys for different github accounts as Github doesn’t allow the same key for more than one account. The Solution is:

1) Create a new alias for github.com in the ~/.ssh/config file.

Host GitHub-readme
  Hostname=github.com
  IdentityFile=~/.ssh/id_rsa_alt

This alias still points to github.com but when you ssh into github using the new alias, it will use the alternative SSH key. It should be noted that Github recognizes you not by your username but by your ssh key.

Before you go on, do remember to ssh-add the key.

ssh-add ~/.ssh/id_rsa_alt

To verify whether the ssh key has been added or not

ssh-add -l 

2) Next, lets verify if our new configuration works with github. To do so, execute ssh -T git@GitHub-readme, where GitHub-readme is the new alias we created in step one with an alternative ssh key.

@~ $ ssh -T git@GitHub-readme
Hi pratikreadmesys! You've successfully authenticated, but GitHub does not provide shell access.

3) Finally either clone a new repository or edit the .git/config of your present repository. Use the new alias that we created in step 1 instead of ‘github.com’ in the command line.

git clone git@GitHub-readme:ReadmeSystemsInc/testrepository.git

Alternatively if you have already checked out the repository, update the remote URL.

[remote "origin"]
  url = git@GitHub-readme:ReadmeSystemsInc/testrepository.git
  fetch = +refs/heads/*:refs/remotes/origin/*