Month: April 2015

Clean build with ninja

When building the Chromium project I was looking for a way to restart the entire build. This means removing all output files, so that every buildstep is executed again. When a build is started the need to recompile the files is normally determined automatically (by date for example).

The build tool used by chromium is called ninja. After some searching I found that there is an option to execute so-called sublevel tools via the -t option. It turns out that there is a subtool called clean which will remove all output files.

ninja -t clean

Leave a Comment

Make image clickable without using jQuery

For a secondcrack blog I found myself needing to be able to make the images in the post clickable so that they could be opened in a bigger size. It was a simple use case, so I did not feel like including external libraries to accomplish this (jquery or other image libraries). As it turns out, all images are available via the document attribute images. The solution posted below iterates over all the images, filters them based on the fact that they have /media in the source (only those needed to be clickable) and sets an onclick event.

//open images in a new window
var images = document.images;
for(i = 0, imagesLength = images.length; i < imagesLength; i++) {
    if (images[i].src.indexOf('/media') !== -1) {
        images[i].setAttribute('onclick', 'window.location.href = \'' + images[i].src + '\';');
}
}

Leave a Comment

Two ways to delete files based on age in Linux

I have found that there are two different ways to clean up a folder, by removing older files. One methods removes the files or folders based on their age, regardless of how many there are. I use this for example to delete backup folders, beyond their age.

Remove using tail

This method assumes that there is one file for every day, for example for backups. The command below removes all files order than 30 days. It is important there is only file per day, because else the tail results would not be correct. The advantage here is that if the backup fails, the older backup files will not be removed because of their age.

ls -1c ./ | tail -n +30 | xargs rm -rf

Remove using find

This command selects all files with a modification time older than 2 days and removes them.

0 15 * * * find ~/files/* -mtime +2 -exec rm {} \;

Leave a Comment