How to install Bazel

Here is how I installed Bazel on Ubuntu 16.04:

$ sudo apt-get install openjdk-8-jdk
$ echo "deb [arch=amd64] stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
$ curl | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install bazel

How to play ARF file on Linux


Cisco Webex stores its video recordings as ARF files with extension .arf. I wanted to play such recordings on Linux.


No solution is working right now

There is a converter to MP4 provided by Webex here. I downloaded the nbr2mp4.tar file and unpacked it.

  • I ran the script to unzip the files.
$ cd nbr2_mp4
./nbr2mp4 file.arf

This did not output any MP4 file.

  • The NBR player too did not work:
$ ./nbr_play file.arf
nbr_play: error while loading shared libraries: wrong ELF class: ELFCLASS64

Perforce cheatsheet

Perforce is a version control system. p4 is its primary commandline tool. p4g is its GUI tool. The reference for all this is the p4 command reference.

  • To get help on any p4 command named foobar:
$ p4 help foobar
  • To list all depots:
$ p4 depots
  • To view info about your workspace:
$ p4 info
  • To view all workspaces of all users:
$ p4 clients
  • To view or change the specification of your current client:
$ p4 client

You typically use this command to add new branches or paths from the depot to your directory view.

  • To sync all the latest branches and paths of your client from the depot:
$ p4 sync
  • To list (and not actually sync) the unsynced files between workspace and depot:
$ p4 sync -n
  • To sync only a specific directory or file use its depot path:
$ p4 sync //dev/foo/some.cpp


A changelist is similar to a commit in other version controls systems. The commit message is known as description in p4.

  • To create a changelist with the currently open files:
$ p4 change

This opens your default editor to a temporary text file showing the changelist description (empty) and the list of files that will be added to the changelist. You can edit in the editor to add a description and optionally remove any of the files. Once you save the file, the changelist is created.

After a changelist is created, p4 prints out its changelist number, say 123456.

  • To add a new file to an existing changelist 123456:
$ p4 reopen -c 123456 joe/foobar.cpp
  • To edit the description of an existing changelist 123456:
$ p4 change -u 123456
  • To view the description of a changelist:
$ p4 describe 123456
  • To view all the details of an existing changelist 123456:
$ p4 change -o 123456
  • To shelve a changelist 123456 in central repository:
$ p4 shelve -c 123456
  • To update a shelved changelist 123456 with newly updated files from disk:
$ p4 shelve -f -c 123456
  • To delete a shelved changelist 123456:
$ p4 shelve -d -c 123456


  • To view all the changelists from the server:
$ p4 changes

This will list all changelists of everybody, so it is pretty much useless. You want to filter it down using other criteria, like shown below.

  • To view all the changelists of a particular depot:
$ p4 changes //somedepot/
  • To view all the changelists of a particular branch in a depot:
$ p4 changes //somedepot/somebranch/
  • To view the most recent 5 changelists added to the server:
$ p4 changes -m5
  • To view the changelists added by a particular user:
$ p4 changes -u joe
  • By default, a single truncated line of information is shown for each changelist. To view a more detailed description of each changelist:
$ p4 changes -l
  • To view the changelists of a particular status, say pending:
$ p4 changes -s pending
  • To add a new file, either cause you want to create a new file or add an existing file to be tracked by version control:
$ p4 add foobar.txt

If it is a new file, then you will need to create the file yourself after this command. This command just indicates to p4 to start tracking such a file.

  • To delete a file:
$ p4 delete foobar.txt
  • To open a file for editing:
$ p4 edit foobar.txt
  • To overwrite your local untracked changes to file by reverting to its version from depot:
$ p4 revert foobar.txt
  • To revert back opened files if they are unchanged:
$ p4 revert -a
  • To view the currently changed files as seen by p4:
$ p4 opened

You can think of this as similar to git status.

$ To submit the open files as a changelist to depot:

$ p4 submit

This is a combination of creating a changelist and submitting it to the depot.

File information

  • To view the changelist of a file:
$ p4 changes //somedepot/somepath/foobar.txt
  • To view the log of a file:
$ p4 filelog //somedepot/somepath/foobar.txt
  • To see a beautiful timelapse view of file history, it is better to view it in p4g by right-clicking the file and choosing Timelapse view. The color of the lines show their age and the slider can be used to move through history.

  • To print all the lines of a file:

$ p4 print //somedepot/somepath/foobar.txt
  • To print the revision numbers of every line of a file:
$ p4 annotate //somedepot/somepath/foobar.txt
  • To print changelists for every line of a file:
$ p4 annotate -c //somedepot/somepath/foobar.txt
  • To print the user who last changed every line of a file:
$ p4 annotate -u //somedepot/somepath/foobar.txt


  • To view the diff of all currently open files:
$ p4 diff

This prints a text diff at the shell by default. If you set the P4DIFF environment variable to a GUI program, like Meld, it will use that to show the diffs.

  • To view the diff of opened files that are actually changed:
$ p4 diff -sa
  • To diff two files in the depot:
$ p4 diff2 //branch1/some.cpp //branch2/some.cpp

This prints a diff at the shell. Set the P4DIFF2 environment variable to a GUI diff program to view the diff using that.


To create a new branch from an old branch, there are typically 3 steps:

First, create the branch:

$ p4 integrate //foo/old_branch/... //foo/new_branch/...

Now the branch is created, but you cannot yet view the files in the new branch in your filesystem.

Second, change the client specification add the new branch files to your view and sync:

$ p4 client
$ p4 sync

Finally, submit the new branch to depot:

$ p4 submit //foo/new_branch/...

Perforce sync clobber writable error


I was trying to sync a Perforce client and got this error:

$ p4 sync
Can't clobber writable file: /home/joe/p4_workspace/foobar.txt


Perforce keeps its files read-only until they are opened for editing. I had for some reason made this file writeable and Perforce was complaining about that with this error message.

The error was fixed and the sync worked once I made the file read-only:

$ chmod -w /home/joe/p4_workspace/foobar.txt

Perforce sync write permission error


I tried to sync a Perforce client and got this error:

$ p4 sync
open for write: /home/joe/p4_workspace/foobar/tmp.30935.46: Permission denied

The strange thing is that there is no tmp.30935.46 in this repository!


Turns out that Perforce writes some temporary files to subdirectories during the sync operation. This error indicates that it is failing in this write because the directory does not have write permissions.

The error went away and the sync worked once I added write permissions to that directory:

$ chmod +w /home/joe/p4_workspace/foobar

How to enable hibernation in Windows 10

You can see that the Shutdown options in Windows 10 does not include Hibernate. But it can be enabled easily.

  • Open the Additional Power Settings dialog by pressing Win + R and using powercfg.cpl.

  • Click the Choose what the power buttons do option on the left and choose Change settings that are currently unavailable.

  • Enable the Hibernate checkbox. It will be added to your Shutdown options immediately.

How to find size of file in C++

A common trick to find the size of a file in C++ is to open it as a stream and seek to the end. You can then ask the stream to tell you the current position in the stream and that would be the number of bytes in the file.

Solution 1

Open a file in binary mode and immediately move to the end. Then ask for the position:

std::ifstream in_file("foobar.bin", std::ios::binary | std::ios::ate);
int file_size = in_file.tellg();

Solution 2

std::ifstream in_file("foobar.bin", std::ios::binary);
in_file.seekg(0, std::ios::end);
int file_size = in_file.tellg();

How to enter international phone number in Google Sheets


I was trying to enter an international phone number of the format +65-12345678 into a cell in Google Sheets and it would turn into ERROR. I changed the formatting of the cell using Format → Number → Plain text. But this error still persisted.


Because the + sign is treated specially when it appears as first character, there is no standard formatting that will work. We need to create a custom formatting to enter this phone number.

Click the cell where you want to enter phone number and choose Format → Number → More formats → Custom Number Format. Enter this format: +##-########. This tells Google Sheet that we will enter 10 digits, represented by the hash characters and it should show up as shown in the format.

Now paste 6512345678 into the cell and it will be displayed as +65-12345678

How to reset Xiaomi phone without unlocking it


I had forgotten the unlock pattern, PIN and other unlocking credentials for a Xiaomi Mi Max 2 phone. I did not care about the data and settings on the phone, I just needed to factory reset this Android smartphone, so that I could create a new Google account on it.


Thankfully, Xiaomi provides a way to hard reset the phone without unlocking it:

  • Power off the phone.
  • Keep Volume Up and Power button pressed together, until the Mi logo appears.
  • You will be led to the recovery menu. Here you can choose to Clear Data, which will effectively factory reset the phone.

Reference: Hard reset Xiaomi Mi Max 2


Corebird is a Twitter client for Linux. It has a UI that I find to be clean and modern.

  • Installing it is easy:
$ sudo apt install corebird
  • Adding a Twitter account is easy and multiple accounts are supported.

  • Configuration can be done by clicking the ⚙ icon at the top-right. These settings are very minimal though. For example, I could not find an option to set the number of tweets to show is not provided.

Tried with: Corebird 1.1 and Ubuntu 16.04