Write your first Firefox extension

November 20, 2017 Leave a comment

 

Advertisements
Categories: firefox, web Tags: , ,

[mysql] rows are deleted but the database still has the same size

October 24, 2017 Leave a comment

Problem
Our cache grew too big, so we wanted to remove rows that are older than X days. However, after removing the majority of the rows, the database still had the same size.

Solution
I found the solution here. Use the command “OPTIMIZE TABLE <tablename>;“. You can also do that with the graphical interface of phpMyAdmin (“tick the checkbox next to the table name you want to decrease, and in the ‘With selected’ drop-down under the list of tables, choose ‘Optimize’“).

Categories: mysql Tags: ,

How to convert a PDF to a “2 pages per sheet” PDF?

October 24, 2017 Leave a comment

Problem
Having a “1 page per sheet” PDF, how to convert it to a “2 pages per sheet” PDF?

Solution
I found the solution here. The answer is here. In short: install the package “pdfjam“, and use “pdfnup“, which is part of the package.

$ pdfnup input.pdf
Categories: bash Tags: , , ,

How to download files in parallel?

October 10, 2017 1 comment

Problem
So far I’ve mostly used wget to download files. You can collect the URLs in a file (one URL per line), and pass it to wget: “wget -i list.txt“. However, wget fetches them one by one, which can be time consuming. Is there a way to parallelize the download?

Solution
Use Aria2 for this purpose. It’s similar to wget, but it spawns several threads and starts to download the files in parallel. The number of worker threads has a default value, but you can also change that. Its basic usage is the same:

aria2c -i list.txt
Categories: bash Tags: , , , ,

How to extract .7z files?

October 10, 2017 Leave a comment

Problem
You have a .7z archive and you want to extract it.

Solution

7za e archive.7z
Categories: bash Tags: ,

How to randomize the lines of a file?

October 10, 2017 Leave a comment

Problem
You have a text file and you want to mix up its lines, i.e. you want to randomize the order of lines.

Solution

sort --random-sort input.txt
Categories: bash Tags: ,

Exctract the significant parts of a web page

October 1, 2017 Leave a comment

Problem
From a web page you want to extract the significant parts: title, author, date of publication, body, etc.

Solution
Mercury Web Parser does exactly this. It’s free. After registration you get an API key. Their web service returns a structured JSON response. I tried it with my previous post:

curl -H "x-api-key: <my_api_key>" "https://mercury.postlight.com/parser?url=https://ubuntuincident.wordpress.com/2017/10/01/re-run-a-command-in-the-terminal-every-x-seconds/" | python3 -m json.tool

Output:

{
    "title": "Re-run a command in the terminal every X\u00a0seconds",
    "author": "Jabba Laci",
    "date_published": "2017-09-30T22:02:19.000Z",
    "dek": null,
    "lead_image_url": "https://secure.gravatar.com/blavatar/db6c398dc21dc8e8f82d7bc83130c0ab?s=200&ts=1506809436",
    "content": "<div class=\"content\"> <p><strong>Problem</strong><br>\nYou want re-execute a command in the terminal every X seconds. For instance, you copy a lot of big files to a partition and you want to monitor the size of the free space on that partition.</p>\n<p><strong>Solution</strong><br>\nA naive and manual approach to the problem mentioned above is to execute the commands “<code>clear; df -h</code>” regularly, say every 2 seconds.</p>\n<p>A better way is to use the command “<code>watch</code>“. Usage:</p>\n<pre> watch -n 2 df -h </pre>\n<p>That is: execute “<code>df -h</code>” every two seconds. <code>watch</code> will also clear the screen and print the result to the top. You can quit with <code>Ctrl + c</code>.</p>\n<p>Tip from <a href=\"https://askubuntu.com/questions/430382/repeat-a-command-every-x-interval-of-time-in-terminal\">here</a>.</p> </div>",
    "next_page_url": null,
    "url": "https://ubuntuincident.wordpress.com/2017/10/01/re-run-a-command-in-the-terminal-every-x-seconds/",
    "domain": "ubuntuincident.wordpress.com",
    "excerpt": "Problem You want re-execute a command in the terminal every X seconds. For instance, you copy a lot of big files to a partition and you want to monitor the size of the free space on that partition.\u2026",
    "word_count": 108,
    "direction": "ltr",
    "total_pages": 1,
    "rendered_pages": 1
}

Pretty impressive.

Categories: web Tags: , ,