limit the CPU usage of Firefox / Dropbox / etc.

June 24, 2016 Leave a comment

Problem
I have an older dual core laptop where Firefox sometimes uses 120%-130% CPU and slows down the machine completely. Restarting Firefox solves the problem for a few minutes but then again, it eats up the CPU. What to do?

Solution
I don’t have many tabs open but I still have this problem. I also uninstalled the Flash plugin but it didn’t solve the problem.

However, I found a nice tool called cpulimit:

Cpulimit is a tool which limits the CPU usage of a process (expressed in percentage, not in CPU time). It is useful to control batch jobs, when you don’t want them to eat too many CPU cycles. The goal is prevent a process from running for more than a specified time ratio. It does not change the nice value or other scheduling priority settings, but the real CPU usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly. The control of the used CPU amount is done sending SIGSTOP and SIGCONT POSIX signals to processes. All the children processes and threads of the specified process will share the same percentage of CPU.” (from the README of the project)

The following setting worked for me:

$ cpulimit -l 80 firefox

Firefox uses several threads but as mentioned in the documentation, they will will share the same percentage of CPU.

The CPU usage may jump higher than the specified value, but cpulimit will push it back in a few seconds.

My old laptop has become useable again :)

Update (with Dropbox)
I noticed that Dropbox also loves my CPU. Here is how I could limit this greedy beast. Originally, I started “$HOME/.dropbox-dist/dropboxd” automatically at each startup. Create the file “$HOME/bin/cpulimit_dropboxd.sh” with the following content:

#!/usr/bin/env bash

cpulimit -l 50 $HOME/.dropbox-dist/dropboxd

Make it runnable (chmod u+x cpulimit_dropboxd.sh) and call this script (cpulimit_dropboxd.sh) when your system comes up. Here I give 50% CPU for Dropbox but you can play with that value.

Categories: bash, firefox Tags: ,

Linux: install Windows fonts

June 24, 2016 Leave a comment

Problem
I wanted to create a meme image manually in Gimp but I didn’t have the required font (Impact). What now?

Solution
The remedy is here: https://wiki.archlinux.org/index.php/Microsoft_fonts. I have a dual boot machine with Windows and Linux, so I decided to put a link on Windows’ Fonts folder (I didn’t want to copy 550+ MB fonts).

# ln -s /mnt/Windows/Fonts /usr/share/fonts/WindowsFonts
# fc-cache

The prompt “#” means a root shell. Restart Gimp and the Windows fonts will be available.

Categories: gimp, windows Tags:

show my position on the map

June 21, 2016 Leave a comment

The site http://ipinfo.io/ gives you back not only your IP address, but your geolocation too. Example (with a fake IP):

$ curl http://ipinfo.io/
{
  "ip": "734.675.653.542",
  "hostname": "No Hostname",
  "city": "Debrecen",
  "region": "Debrecen",
  "country": "HU",
  "loc": "47.5333,21.6333",
  "org": "...",
  "postal": "..."
}

Let’s visualize my location:

<img src="https://maps.googleapis.com/maps/api/staticmap?center=47.5333,21.6333&zoom=9&size=480x240&sensor=false">


Debrecen, Hungary, center of the world :)

Categories: Uncategorized Tags: , , ,

email notification from a script

June 15, 2016 Leave a comment

Problem
I have a Digital Ocean VPS box where several scripts are running. Some of them run for a day. I would like to get an email notification when a particular script starts / ends, or when something happens.

In short: how to send an email from the command line?

Solution
First, do the necessary configuration to be able to send emails from the command line (more details here).

Sending email without a body:

mailx -s "subject" < /dev/null "to@email.com" 2>/dev/null

Sending email with a body:

echo 'this is the body of the email' | mailx -s "subject" "to@email.com" 2>/dev/null

I also made a Python wrapper for it that you can find here.

Categories: bash, python Tags: ,

How to update Windows 7 SP1

June 13, 2016 Leave a comment

Problem
A friend of mine asked me to install Windows 7 on his laptop. I installed Windows 7 SP1, but something changed because when I tried to search for updates, it didn’t want to finish! I waited for 12 hours but it was still looking for… Damn, how to do an update?

Solution
Download manually these updates: KB3050265, KB3102810, and KB3125574 (this last one is a big one, a convenience rollup update). Do the following with each update:

  • Start an admin terminal and stop the Windows Update service: “net stop wuauserv”.
  • Install the update. Restart the machine if you are asked to.
  • Take the next update and repeat.

There is no need to restart the WU service manually since it is started automatically after a reboot.

When these three updates are installed, the Windows Update will find the updates “quickly” (“quicly” is relative; for me it was about 15 minutes).

Windows: convert .docx files to .pdf in batch mode

Problem
I had 60 .docx files that I had to convert to .pdf. How to do it in batch mode? One thing was sure: there is no way that I’d do it manually…

Solution
I found the solution here.

The necessary scripts are collected here.

Usage: collect the .doc(x) files in a folder, put the two scripts next to the documents and launch the .bat file.

Note: this solution also works with .doc files (but then modify “docx” to “doc” in the sources). I tried it with Word 2007.

Categories: windows Tags: , ,

Firefox: disable detach tab

Problem
Clicking on a tab and then moving your mouse in a downward motion causes a new window to open.

Solution
Install this patch: https://addons.mozilla.org/en-US/firefox/addon/bug489729-disable-detach-and-t/ and in its GUI select “Disable detach tab”.

Frankly, this FF “feature” was driving me crazy.

Categories: firefox Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 90 other followers