Archive for the ‘Uncategorized’ Category

Vim: highlight repeated properties of property file

While refactoring some localization property files I found that many messages and properties were repeated. This might be due to the lack of a naming convention for the strings or maybe because the properties were not sorted alphabetically.

For example, in one of the files the string Upload was repeated in three different places:


After normalizing the file I ended up with:


Before deleting the duplicated properties I wanted to check if the string they had was the same in all occurrences. With that in mind, I decided to make a little vim function that would highlight all the duplicated property names. For that you have to write the following in your .vimrc file:

function! HighlightRepeatedProps() range
let propCounts = {}
let lineNum = a:firstline
while lineNum <= a:lastline
let lineText = getline(lineNum)
if lineText != ""
let propName = matchstr(lineText, "^[^=]*")
let propCounts[propName] = (has_key(propCounts, propName) ?
propCounts[propName] : 0) + 1
let lineNum = lineNum + 1
exe 'syn clear Repeat'
for propName in keys(propCounts)
if propCounts[propName] >= 2
exe 'syn match Repeat
"^' . escape(propName, '".\^$*[]') . '=.*$"'

command! -range=% HighlightRepeatedProps <line1>,<line2>call HighlightRepeatedProps()

After saving your changes on .vimrc open your .properties file and type :HighlightRepeatedProps, if you have any repeated property names vim will highlight them in a different colour.

Useful, right?

Categories: Uncategorized

Rescue data from disk in Ubuntu

I was asked to audit a disk in order to see any deleted file. For this task, I used Ubuntu Rescue Remix, an Ubuntu live CD customized with lots of applications for data recovery and forensics. Using a live CD for data rescuing is really useful, as you won’t be writing any data on the disk, and therefore you won’t overwrite anything you want to rescue. On the other hand, using a live CD you’ll be able to turn on the computer, even if the disk is physically damaged.

Once you’ve loaded the live CD, you’ll be ready to start typing Linux commands as usual. Yet, if you are not using an English keyboard, you’ll probably be interested in changing the keyboard layout. Just type loadkeys and your keyboard’s layout code. For example, if you have a Spanish keyboard execute:

loadkeys es

Remember that these commands must be run with root privileges, so type sudo before every command if the systems complains about permissions.

You may want to store the image in a remote server. Let’s use samba to mount a remote folder.

apt-get install smbfs
mkdir /mnt/recovery
smbmount //SERVERIP/recovery /mnt/recovery/ -o user=sambausername
cd /mnt/recovery

Finally, we create the image using ddrescue. Remember that you will need at least as much room as the capacity of the disk you want to rescue.

ddrescue --no-split /dev/sda image_file log_file

If the disk is damaged you might get better results running successive passes.

sudo ddrescue -r 3 -C /dev/sda image_file log_file

Once you have the image done, you can use Autopsy to recover any data from the disk.

Categories: Uncategorized Tags:

Batch processing of images using Photoshop

Sometimes you have a bunch of images or photos and you want to apply the same filters or changes to all of them. Changes or filters like resizing, rotating, cropping or increasing the contrast of the image. So why waste time doing this manually with each image if you can automatize all the work with a batch process and tell photoshop to apply this changes to all the files in a folder with just one click.

Photoshop’s batch processes are defined in a similar fashion as Microsoft Office’s macros. You tell Photoshop to start recording your actions so that the application knows which steps to follow, and when you’re done you just push stop to end the thing.

Let’s say I want a batch process to resize the photos of last night’s party because my friend’s brand new camera takes pictures of 14Mpx and I’m happier with a 5Mpx size.

Open one of the aforementioned photos using photoshop. Go to the Window menu and select Actions. A small window should appear.

In that window click on the Create new action button (the one beside the trash can) give a meaningful name to your custom batch process (Photo resizing) and store it under the Custom category. From this point on until you click the stop button in the actions window, all the actions you perform to the image will be recorded.

We want to resize the image so we choose Image and then Image size… There we enter the desired size and tick the Restrict proportions option. Finally, we choose File and Save as… (in this step you can choose to save the file in a different format from the original or even change the compression ratio applied to your jpg images) and we’re done.

Once you’ve recorded all the actions of your batch process click on the stop button. If you click in your custom batch process you can review the sequence of actions that’s recorded in the process and modify them if you want so.

Now that we have our custom batch process how do we apply it?

Go to File and then choose Automatize > Batch… a new window should appear. There you must select the action set you will be using and the batch process you want to repeat. Choose the folder in which you left those weighty party photos and another folder to leave the resized results. Click OK and relax while Photoshop saves you lot’s of time in resizing tasks.