Linux


13
May 11

Frigging Huge PDFs

Turns out this is how you fix up a frigging huge pdf that probably came out of photoshop or some such beast with all of the layers and history that is mostly useless to you. It seems to work quite well, 230 MB down to 6MB.

Of course you can do some tweaking to reduce the size even more if you want to (take a look at the ghost script manual).

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf


3
Mar 10

Finding corrupted images

As zoe kindly pointed out, two Wednesdays have passed since I last posted. I blame the Olympics (I was in Vancouver for the first week, and I was still recovering from it the second week Go Canada!). You can see my photos on flickr.com as I post them here. Apparently you can only post 100 mb/month, so it might take a while.

DSCN0543

Anyway, onto the post:

This month at work, one of our servers decided to act up and corrupt quite a few things. We had about 10000 images on that server, many of them were corrupted, many of them were not. Instead of going through all of the images one by one, opening them and checking if they were corrupted, I was tasked with writing a php script to find them. My first instinct was to do something like this:

 
<?php
 
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";
 
    /* loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        if(@getimagesize($file) === false){
            echo "$file\n";
        }
    }
}
 
?>

Unfortunately, getimagesize only looks at the start of a png file to get the information, meaning that if the file was corrupted after those first few bits of information it would not show up on the list.

The second idea was to use this method:

<?php
 
if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Files:\n";
 
    /* Since they are all png files, this will work: */
    while (false !== ($file = readdir($handle))) {
        if(@imagecreatefrompng($file) === false){
            echo "$file\n";
        }
    }
}

Which, in theory, should have worked because it reads the whole file in and then returns false if the image could not be created. Unfortunately there was (is) something wrong with the libpng library so I kept getting errors like this locally:

libpng warning: Ignoring bad adaptive filter type
libpng warning: Extra compressed data.
libpng warning: Extra compression data

Which would be fine if they were php errors. I could have ignored them because the script worked properly and listed all of the files that had problems. Unfortunately for what ever reason, the server was dying on these errors instead of continuing like it was doing locally.

In comes imagemagick to the rescue. Using the identify command (at the command line) it reads in the whole image file and then tells you what it is. Since you might have 10000 images like we did, it is probably also a good idea to send the output to a file instead:

    identify "./path/to/files/*" >badImages.txt 2>&1

You will also want to make sure that the path has ” ” around it, because otherwise you will end up with an “Argument list too long” error. In the badImages.txt file you will have a list of images that are in the folder you specified. Any of the lines that start with identify are no good.


14
Mar 09

jQuery bsod plugin

So I was checking up on my twitter feed yesterday and saw a tweet that direceted me to this: http://devthought.com/wp-content/projects/mootools/BSOD/:

The script BSOD.js provides an easy-to-use class to boost the error reporting user experience of your websites.

To fully understand the characteristics of this technique please refer to this external article

I thought to myself… I can do that. I will use jQuery. So I spent most of yesterday after work learning up on how to make a jQuery extension (I wanted to be able to call it the same way as the moo-tools one)

$.bsod();

I got a bit carried away. I didn’t want just a bsod, I wanted each user to feel like the error was specifically made for them, so I added in os detection and os specific styles. I liked the way that he incorporated Spyjax (ajax for evil!), so I added that by default (you can turn it off of course if you want, it will blame a random site that is in the list). I also liked the colour changing, so that is in there too (it works only for the windows bsod though because linux and mac have images). Here are the options:

  • color: the background colour (win only, others are all black)
  • font_color: the font colour
  • error: the error message you want to display
  • os: the os (default is to guess the user’s os)
  • blame_url: boolean – true = blame a specific url
  • url_array: an array of urls you are looking to blame
  • error_array: a bunch of errors that you would like to use (one is randomly choosen)

Dependencies

Right now, the images and jQuery (tested with 1.3.1).

There is also a style that is compressed using cssTidy and inserted with the bsod.

Without further ado:

The demo (click on a word to see the bsod)

bsod.1.0.zip (with the dependencies included so you can use it right away!)

And some screen shots:

screen1 screen2 screen3 screen4

Tested in:

  • IE 8, IE 7
  • Firefox 3
  • Opera 9.63
  • Chrome 1.0.154.48

In case you missed it:

The demo (click on a word to see the bsod)

bsod.1.0.zip (with the dependencies included so you can use it right away!)


21
Feb 09

Backing things up a la Crashplan

Backing things up is very important… your hard drive will fail one of these days, and when it does you will lose everything (trust me, my laptop hard drive failed once…).

bit of HDD failure

You are backing important things up right? Oh…

Enter Crashplan. It seems like a simple way to set up your important things to be backed up elsewhere, either on another hard drive, another computer (maybe a family member’s or maybe even on their servers (don’t worry… it is encrypted quite well).

The first thing you have to do is get it (down in the right corner):

Getting Crashplan part 1

Then you have to chose the version you want to get (Linux for me obviously):

Getting Crashplan part 2

Unzip it and install it:

Welcome to The Crashplan installer

You will notice that I am installing as root, that is because of this notice:

NOTE: You are apparently not installing as root. While it is recommended to
install as root it is not required. If you continue to install as seanja
then Crashplan will only be able to back up files readable by seanja.

You can install it as a non-root (admin) user if you only want to backup files that are yours, but I have files that I would like to backup elsewhere. I just installed it using the defaults:

Crashplan Defaults

Ah… I had to install this twice because I messed it up the first time… make sure that you are in the directory that you unzipped crashplan to so that you can just run:

sudo ./install.sh

Then start Crashplan (which will auto start at the end if you told it to), and signup for an account:

Sign up for Crashplan

And if it all went well, you will now have Crashplan up and running, you can now install it on another computer using the same account, and it will recognize it as another one of your computers and let you backup to it for free.

3-backing-up


25
Jan 09

Launchy

vistastart

The keyboard has been proven to make you much faster at performing tasks. At least it has been said to be much faster, some people like your grandma may not be fast on the keyboard, but I am not sure that she really counts in the metric, she probably doesn’t use the computer to the extent that you do.

One thing that is annoying to have to do is look through the start menu for the application that you want to open to do what ever it is you want to do. That is why your desktop ends up looking like a kmenucluttered mess, you have folder shortcuts, application shorcuts, stuff you just downloaded (shame on you for not having a downloads folder set up!), and temporary files that you create for something and then forget to delete. It all adds up to create a jumble that is at least as bad if not worse than looking through the start menu for that application that you want to open. In comes the quick start bar. That group of icons beside your start menu (in Windows, KDE, and Gnome), but what is the point of that if you end up filling it to the point of your start menu? You might as well not have it at all. Fortunately the people who designed the Windows Vista start menu realised this and added in a Search box, and fancy that, so did the guys in KDE land. The only problem with those search functions is that they attempt to do too much, first they search the start menu (which takes way too long in my opinion), and then if they find nothing, they offer to search the entire computer (at least Vista does, I am assuming that KDE does too). This takes even more time.

 

launchy

Enter Launchy. Launchy is a small program that runs in the background waiting for you to press the key combination that you set up (mine is win + space) it has already scanned the contents of your start menu, and/or any other location that you specify (it doesn’t have to look at your start menu… it could just be a specific folder on your computer) and it guesses, based on what you type, what program you want to run. If it can’t find what you want, you type in gibberish, or mistype, or specifically type in something you don’t have, you can make it default to searching google for what ever it was that you typed (by enabling the weby plugin and making the default search to be google). launchy-weby Launchy will then open up your default browser and enter the search term into google and google will give you the results that you are looking for. The best part is that Launchy is free OS software that runs in Windows or Linux. So go get it now, you have nothing to lose by at least trying it out.