Firefox – prevent websites from refreshing

Fed up with websites and tabs continuously reloading themselves and using resources unnecessarily? Me too!

In Firefox, you can disable this from the about:config page. Type about:config in the address bar, accept the warning, and search for:

accessibility.blockautorefresh

Set it to true. Problem solved — pages can no longer auto-refresh without your permission.

You can also keep an eye on which tab uses the most resources by typing about:performance in the address bar. Firefox shows a list of open tabs with their CPU and memory usage, making it easy to find and close the resource hogs.

Enjoy!

How to update all docker base images with one command

To pull the latest version of all your Docker images at once:

for docker in $(docker images | awk '{print $1,$2}' | sed 's/ /:/g' | grep -v REPOSITORY); do docker pull $docker; done

This lists all images, extracts repository and tag, formats as repository:tag, and pulls each one.

After updating, old image versions stay on disk. To clean them up:

docker image prune -a

This removes all unused images and frees up space.

Enjoy!

How to update all pip python packages with one command

To update all your pip-installed Python packages at once:

sudo pip install -U `pip list -o | cut -d ' ' -f1 | tr '\n' ' '`

This lists outdated packages with pip list -o, extracts their names, joins them with spaces and passes them to pip install -U. A one-liner that saves you from updating each package individually.

NB: One-liners like this are potentially destructive. Read what they do before running them, especially with sudo.

For a safer alternative on modern systems, use pip-review:

pip install pip-review
pip-review --auto

This prompts you before each update.

Enjoy!

Test email from command line

When you set up email forwarding or configure a new MTA, you will want to confirm it is working before relying on it for alerts. A quick test is all you need.

Send a test message

mail -s Test myEmail@gmail.com

If the mail command is not available, install it with apt-get install mailutils. Then check your inbox.

If it does not arrive

Run mailq to see if the message is stuck in the queue. The mail log at /var/log/mail.log will also show the delivery attempt and any errors.

Enjoy!

PHP: remove duplicate elements from a multi-dimensional array

This post is over 3 years old, so please keep in mind that some of its content might not be relevant anymore.

PHP’s array_unique() is great for removing duplicates from a flat array, but it chokes on multi-dimensional arrays. If you have nested data and need to remove duplicates, here’s a clean one-liner that does the job.

The trick: serialize, unique, unserialize

The idea is straightforward: flatten the array temporarily by serialising each element, let array_unique() do its thing on the flat list, then unserialise everything back to its original structure.

$uniqueArray = array_map("unserialize", array_unique(array_map("serialize", $array)));

Working from the inside out:

  • array_map("serialize", $array) — turns each nested element into a string representation
  • array_unique() — removes duplicate strings (which means duplicate nested structures)
  • array_map("unserialize", ...) — restores each string back to its original PHP value

The result is a multi-dimensional array with all duplicate entries removed, regardless of how deep the nesting goes. You keep the original structure and no external libraries needed.

Hope it helps!

How to shred/wipe disks/partitions

When you delete a file normally, the data stays on the disk — the filesystem just marks the space as available. The data can be recovered with the right tools. If you need to make sure it is really gone, you can overwrite it securely.

shred -vzf -n 5 /dev/sdb

The -v flag shows progress, -z adds a final overwrite with zeros to hide the fact that shredding took place, -n specifies the number of passes (5 in this example), and the device is the disk or partition you want to wipe.

Be careful with this command — there is no undo. Double-check the device name before running it.

Shredding a single file

If you only need to destroy a specific file rather than an entire disk, use shred on a file directly:

shred -vzu sensitive-file.pdf

The -u flag tells shred to delete the file after overwriting it. Without -u the file remains in place but with its content overwritten.

Wiping with dd for more control

If you want to see exactly what is being written and you know the disk size, dd gives you more control:

sudo dd if=/dev/urandom of=/dev/sdb bs=4096 status=progress

This writes random data in 4K blocks and shows a progress indicator. Replace urandom with zero (if=/dev/zero) for a faster but less thorough wipe. The trade-off is that a single zero pass is detectable — someone with specialised equipment can still read the residual magnetic signature.

Verifying the wipe

After wiping a disk, you can verify that no readable data remains:

sudo xxd /dev/sdb | head

If the output shows consistent patterns (all zeros or all random bytes), the wipe was successful. If you see fragments of old filesystem structures, you might need another pass.

Note on SSDs

Shred relies on overwriting the same physical sectors multiple times. On modern SSDs, wear-levelling and TRIM make this unreliable — the drive may remap sectors and leave old data in place. For SSDs, use the ATA Secure Erase command built into the drive firmware instead. Most Linux distributions include the hdparm or nvme-cli tools for this:

sudo hdparm --user-master u --security-set-pass p /dev/sdb
sudo hdparm --user-master u --security-erase p /dev/sdb

Or for NVMe drives:

sudo nvme format /dev/nvme0n1 -s1

The best defence against needing to wipe a disk securely is full-disk encryption. If the drive was encrypted from day one, a single pass of zeros is enough to make the data unrecoverable — the encryption keys are gone, and the rest is ciphertext.

Enjoy!

Drush intro – Drupal

Drush is a command-line shell interface for Drupal. It lets you do almost anything you would do through the Drupal admin interface — enabling modules, clearing caches, running cron, backing up the site — all from the terminal.

Installation

The preferred way to install Drush is via the official PEAR channel, but it can also be installed manually on a shared server.

Backup and restore

archive-dump backs up the codebase, files, and database into a single file:

drush archive-dump
drush archive-restore

Common commands

drush pm-download 
drush pm-enable 
drush pm-disable 
drush cc all
drush cron
drush sql-dump
drush uli

Enjoy!

Accelerate downloads with lftp

lftp is a versatile command-line file transfer tool. What makes it stand out is its ability to open multiple connections for a single download, which can significantly improve transfer speeds on servers that limit bandwidth per connection.

Parallel downloads with pget

The command I use most is pget with the -n option for parallel connections:

lftp -e 'pget -n 3 http://example.com/file.zip'

If the server limits each connection to 100KB/s, three connections will give you roughly 300KB/s.

Resuming interrupted downloads

If a download fails halfway through, pget continues from where it left off when you run the same command again:

lftp -e 'pget -c -n 3 http://example.com/file.zip'

Mirroring directories

lftp can mirror entire directory structures:

lftp -e 'mirror --parallel=3 /remote/path /local/path'

Queue management

lftp http://example.com
queue pget file1.zip
queue pget file2.zip
run

Enjoy!

jQuery shorthand for the document ready wrapper function

If you use jQuery, you know the $(document).ready() wrapper is the standard way to make sure the DOM is fully loaded before your JavaScript runs. But writing it out every time gets repetitive. There’s a shorthand that does exactly the same thing with fewer keystrokes.

The long version

$(document).ready(function() {
  // your code here
});

The shorthand

$(function() {
  // your code here
});

That’s it. $(function() { ... }) is equivalent to $(document).ready(function() { ... }). jQuery internally maps the shortcut to the same event handler, so there’s no performance difference — it’s purely a readability and typing convenience.

What about the arrow function?

If you’re writing modern JavaScript, you can also use arrow functions:

$(() => {
  // your code here
});

All three forms do the same thing. Pick whichever you find easiest to read.

Enjoy!

Re-open last tab/tabs closed on Google Chrome/Chromium

We’ve all done it. You’re flicking through tabs, your hand moves faster than your brain, and bam — you closed a tab you still needed. You stare at the screen for a second before remembering there’s a keyboard shortcut for that.

Ctrl + Shift + T (or Cmd + Shift + T on a Mac).

That’s it. Press it once and the last tab you closed comes back. Press it again and the one before that comes back. Chrome and Chromium keep a stack of your recently closed tabs in memory, so you can walk backwards through your mistakes as far as you need.

It works across sessions

If you close Chrome entirely and reopen it, Ctrl + Shift + T will restore the last window you had open with all its tabs. This is separate from the “Continue where you left off” startup setting — it’s a one-time restore that works even if you have Chrome set to start on a blank page.

Right-click also works

If you prefer the mouse, right-click on any tab and select “Reopen closed tab” from the menu. Same result, one extra click.

What about the History panel?

For tabs you closed a while ago (not just the last few), go to Menu > History or press Ctrl + H. You’ll see a full chronological list — the “Recently closed” section at the top shows your last few tab closures with their full titles, making it easier to find the one you actually want.

The shortcut is one of those things you don’t think about until you need it. And once you know it, you’ll use it more often than you’d expect. :-)