Random things, I think I know

RSpec `let` gotcha! Plus assignment

Recently I tried something like
```ruby
let(:array_of_numbers) { [1, 2, 3, 4, 5] }

it 'should have a description' do
  expect([1, 2, 3, 4, 5, 6]).to eql(array_of_numbers += [6])
end
```
It did not work, as in the plus assignment statement ruby expects `array_of_numbers` to be a variable not a method call.
Continue Reading

Run OpenVPN in background.

**TL;DR** Run it in daemon mode: `openvpn --config Windscribe-Japan.ovpn --daemon`

Passing the configuration (.ovpn) filename to `openvpn` command works only if no other options are specified. If I specify `--daemon` option then openvpn tries to parse the filename as an options parameter and throws **Options error: I'm trying to parse "Windscribe.ovpn" as an --option parameter but I don't see a leading '--'**.

**Answer:**

To avoid this, the file name has to be specified with `--config` option. For example, `openvpn --config Windscribe.ovpn --daemon`. Then tail the syslog with `tail -f /var/log/syslog`, for further inspection.

You can also check the before and after output of this curl command `curl ifconfig.co` to make sure that VPN is connected.

Note: This will keep the daemon running even after you logout from the SSH session.
Continue Reading

Removing recent network playlist in VLC media player.

If you have used VLC to stream videos online, then you might have noticed that there is no way for you to clear the recently played URLs from the dropdown list. This list will persist even if you clear the recent media by Media -> Open Recent Media -> Clear.

It took me 2 hours to find it, by digging through the source code. That is the beauty of open source.

The solution, on Linux, VLC stores the list of recently played files in path, /home/<USER>/.config/vlc/vlc-qt-interface.conf where <USER> is the name of your user name.

Open the vlc-qt-interface.conf file and search for netMRL, there will be comma separated list of URLs assigned to the netMRL variable. Remove everything after the equal sign till the end of line. Or you can remove particular URLs from the CSV.

Similary, you will also find the recentMRL in the same file. You can edit that as well.
Continue Reading

Configure sudo to set $HOME to the home directory of the target user.

According to the documentation if the Defaults        env_reset is set, the $HOME will be set to the home directory of the target user. On the surface it might look straight forward, but if you read carefully, you might notice that the contents of env_keep and env_check also affects this behavior.

The problem is, even if you don't see env_keep configured in your sudoers file, there is a default list that comes when you install sudo. To check the default env_keep variables, login as root sudo su and run sudo -V. Under the section Environment variables to preserve: you will see the list of environment variables that get preserved when you run a sudo command.


So, even though the $HOME is set to the home directory of the target user initially, it gets over-written by these default env_keep variables.

To avoid this, you can configure the Defaults with always_set_home. So setting Defaults        always_set_home will set the $HOME to home directory of the target user despite the list of env_keep variables.
Continue Reading

Replacing old style ruby hashes in Vim. (Updated)

You can use the following command in Vim, in normal mode to replace old style Ruby hashes into new style ruby hashes.


%s/:\(\w\+\)\(\s\==>\)/\1:/gc

Update, a slightly better substitution command, which adds a space after `key:` regardless of the source string.
%s/\V:\(\w\+\)\(\s\*\)\(=>\)\(\s\*\)/\1: /gc
 


Continue Reading