A “read it later” add-on for Firefox

September 29, 2016 Leave a comment

Problem
At my workplace I found two interesting links that I decided to read at home. I didn’t want to save their URLs and e-mail them to me, so I made a search if there is a good “read it later” add-on for Firefox. And then I got surprised.

Solution
It turned out that Firefox has such an add-on by default! That is, such an add-on is included in Firefox and it is called Pocket. Read more about it here.

So I put its icon next to my search bar and started to use it. It’s awesome! It also has a mobile app. so I can read the saved articles anywhere.

Hmm, I’m sure there are lots of other gems in the softwares that we use on a daily basis and we have no idea about them…

Categories: firefox

Konsole: highlight the current tab

September 19, 2016 Leave a comment

Problem
Holy shit, this problem has been bugging me for years… But at last I found a solution.

So, I use the terminal emulator Konsole, which is very nice, I love it, but the current tab is not highlighted enough. Thus, if you have several tabs opened, it’s always difficult to figure out which is the current one.

konsole_off

Solution

It turns out that Konsole can be customized via a CSS stylesheet file. Here is an example (konsole.css) that you should save somewhere:

QTabBar::tab:selected {
    background: lightgreen;
    color: black;
    font: bold;
}

Then, in Konsole, go to Settings -> Configure Konsole… -> TabBar, and there specify this CSS file:

konsole_settings

And here is the result:

konsole_on

Links

Categories: linux Tags: , , , ,

git: revert “git add .”

September 7, 2016 Leave a comment

Problem
You run “git add .” and you manage to add 100+ files :( How to “unadd” them with one command?

Solution

git reset HEAD --

I found it here. Click on it for a detailed explanation.

Categories: bash Tags: ,

Ubuntu: assign a better screenshot tool to the Print button

September 5, 2016 Leave a comment

Problem
The Ubuntu default screenshot tool (gnome-screenshot) is lame. In Manjaro there is a better tool called xfce4-screenshooter, which allows you to select a region, open it with Gimp, upload to Imgur, etc.

How to assign xfce4-screenshooter to the Print button?

Solution
First, install the software (sudo apt install xfce4-screenshooter). Then, open System Settings, select Keyboard, and go to the Shortcuts tab. Here ignore the “Screenshots” entry and select Custom Shortcuts. Click on the “+” sign and add the command xfce4-screenshooter. As a result, a new entry will appear. Click on its right side and assign the Print button to it. It’ll complain a bit but click on Re-assign. Done.

I found this nice solution here: http://askubuntu.com/a/609060/53599 . Click on this link for screenshots.

Categories: manjaro, ubuntu Tags: ,

MongoDB: reduce file size

August 23, 2016 Leave a comment

Problem
I have a small Digital Ocean VPS with MongoDB with 20 GB storage. The database dump is 1.7 GB, but the directory /var/lib/mongodb occupies about 7 GB disk space. If it goes on like that, I will run out of free space.

Solution
MongoDB 3 uses the WiredTiger storage engine, but before that the mmapv1 engine was the default. The mmapv1 has two options to reduce file size but WiredTiger doesn’t support these options :(

So I switched back to mmapv1. Here is my /etc/mongod.conf file that enables file size reduction:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
  engine: mmapv1
  mmapv1:
    preallocDataFiles: false
    smallFiles: true
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

Notice preallocDataFiles and smallFiles. Keep in mind that they may have negative impact on the performance. In my case I was just collecting a lot of data and not running out of free space was more important.

My new /var/lib/mongodb is 4 GB now, not 7 GB.

To figure out if Mongo uses WiredTiger or mmapv1, execute this in the mongo shell:

> db.serverStatus().storageEngine

MongoDB: connect remotely

August 8, 2016 Leave a comment

Problem
I have a Digital Ocean VPS running MongoDB. There is a web application on this machine that is on port 80. MongoDB is hidden from the outside world and can only be accessed internally. There is also an SSH port where I can log in.

How to connect to my MongoDB server from home? Say I want to use a graphical client, e.g. MongoChef. The client runs on my home machine and I want to connect to MongoDB with it on my DO VPS. How to do that?

Solution
I found the solution here. In short: we connect securely to our database through an SSH tunnel.

Make sure that:

  • you can SSH into your Mongo droplet
  • your MongoDB is bound to localhost

For connecting, I use this script:

REMOTE_SSH_PORT=1234
LOCAL_PORT=2345
REMOTE_MONGO_PORT=27017
cmd="ssh -p ${REMOTE_SSH_PORT} -L ${LOCAL_PORT}:localhost:${REMOTE_MONGO_PORT} user@your.remote.ip"
echo "#" $cmd
echo "# connect on your home machine to port ${LOCAL_PORT}"
echo "# example:    mongo --port ${LOCAL_PORT}"
$cmd

The default SSH port is 22, but it’s a good idea to change it. With the command “ssh -p ${REMOTE_SSH_PORT} user@your.remote.ip” I could log in to my VPS. However, MongoDB was not accessible from outside, thus executing “mongo --host your.remote.ip --port ${REMOTE_MONGO_PORT}” failed.

The SSH tunneling above works as follows. On your home machine you open the port ${LOCAL_PORT} that is connected to your remote machine via the SSH port ${REMOTE_SSH_PORT}, and the connection is tunneled to localhost:${REMOTE_MONGO_PORT}, where localhost means the remote machine where we logged in with SSH.

So, when you execute the script above, you’ll have to log in to your remote machine via SSH. Then open a new terminal and type “mongo --port 2345” and voilá, you are connected to MongoDB on your remote machine!

If you use a Mongo client (e.g. MongoChef), then simply create a new connection and specify localhost with port 2345. Connect, and you are in.

It works as long as you are logged in in a terminal via SSH. When you log out, the local port closes that is tunneled to your remote machine.