A simple script to list s3 bucket sizes

This script uses the excellent s3cmd to provide a list of all buckets in an account along with their sizes rounded down to the nearest GB MB and Byte. Amazingly there doesnt seem to be an easy way to do this within the s3 web interface.

#!/bin/sh
buckets=`s3cmd -c .s3cfg_onespot ls | awk '{FS=" ";print $3}'`
for bucket in $buckets
do
size=`s3cmd -c .yours3cfgfile du "$bucket" |awk '{FS=" ";print $1}'`
sizemb=`expr $size / \\( 1024 \\* 1024 \\)`
sizegb=`expr $sizemb / 1024`
echo "$bucket ${sizegb} GB ${sizemb} MB ${size} bytes"
done

Hope someone finds this useful.

Netflix Ireland Review

So I recently signed up for the Netflix’s service which has just launched here in Ireland and I thought I’d share my experience in a concise review.

My first impression was that there is a lot of stuff on it, albeitt not exactly up to the minute with regard to new seasons of currently running shows. for example there are early seasons of Dexter, 24, Shameless among others. They generally have the first few seasons of a show but not the latest 1 or 2. I was pleasantly surprised to see that the full series of Arrested Development is there which I will happily re-watch. In truth there is a lot of crappy b movies and shows you have never heard of in the Netflix library but there is more than enough good stuff there to be well worth my €7 per month.

The most imprssive thing about Netflix in my view is the quality of the streaming. My internet connection while claiming to be 6 megabit is patchy at best and even youtube videos stutter and stop to buffer regularly. I have watched loads of Netflix in the couple of weeks that I have had it and it has yet to stop to buffer or stutter. Very impressive. This appears to be because they dynamically adjust the bitrate of the video as you watch it so if your connection gets a bit congested it reduces the bitrate so the video quality may degrade slightly (most of the time not even noticable on my 46inch tv) but your viewing is not interrupted.

I hope that going forward Netflix keep adding more content and some newer tv shows would be great.
If so I will happily keep paying my €7 as its really great value for money.

Click here to sign up for the free months trial, you need to enter your credit card details to get the free month but I think Netflix are relatively trustworthy ;)

TLDR – Get it, its great.

Mounting a Windows 7 Share in Linux

I run an Ubuntu VM using VMware on my windows 7 machine and I find it very useful to be able to access files on the windows machine from inside of linux. This is actually quite easy to achieve and you can be up and running in about five minutes if nothing goes wrong.

First, in windows, share the folder that you are trying to access from your linux box. Make sure that the user you want to grant access to has read and write permissions (by default this the the current admin user so most likely you wont have to worry about this)

Now create an .smbcredentials file somewhere on your linux machine. I just used :

/home/andrew/.smbcredentials

but you can put it wherever floats your boat.

Now edit the .smbcredentials file and add the username and password for the windows machine in this file in this format :

username=andrew
password=andrewspassword

Next you need to create the entry in your /etc/fstab which will mount the directory on startup.
Add this line to your /etc/fstab file (filling in your details where necessary) :

//<windows machine name>/dev /mnt/<mount folder name> smbfs iocharset=utf8,credentials=/path/to/.smbcredentials,uid=1000 0 0

Next you need to create the mount point and make sure you can access it as a non root user :

sudo mkdir /mnt/<mount folder name>
chmod -R 775 /mnt/<mount folder name>
chown -R <your linux username>:root /mnt/<mount folder name>

Finally ensure that smbfs is installed on your system. In Ubuntu just use :

sudo apt-get install smbfs

Now just mount it

sudo mount -a

If you get an error like this :

mount: wrong fs type, bad option, bad superblock on ⁄⁄mywindows⁄myshare,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might....

You probably havent installed smbfs correctly so run :

sudo apt-get install smbfs

again.

A simple “treesize” shell script for Linux

One of my favorite pieces of software on windows is a little app called treesize free by Jam Software. It basically gives you a simple list of how much disk space each directory is taking up. This is really useful when you are trying to work out where all the space on your 500gig disk is gone.

I am always finding myself looking for similar piece of software for linux which can be run simply from the command line, but alas none exists so i decided to create a simple shell script to do a similar job, and here it is :

#/bin/sh
du -k --max-depth=1 | sort -nr | awk '
     BEGIN {
        split("KB,MB,GB,TB", Units, ",");
     }
     {
        u = 1;
        while ($1 >= 1024) {
           $1 = $1 / 1024;
           u += 1
        }
        $1 = sprintf("%.1f %s", $1, Units[u]);
        print $0;
     }
    '

Just put this code into a file /bin/treesize and make it executable. Then any system user can get a list of directory sizes within a directory by just running treesize from any directory.

Pro Tip : PHP has built in functions for reading and writing csv files

Just discovered this and I am mighty impressed. It seems that in PHP 5.1 and higher there are the functions fgetcsv() and fputcsv(). They make it pretty simple to read and write a csv file.

Here is a simple example which reads a csv file, adds a couple of fields and writes it to a new file.

<?php
 
// Open the output csv file
$outputfp = fopen('output.csv', 'w');
 
// Read from the input csv file
if (($inputfp = fopen("input.csv", "r")) !== FALSE) {
 
    while (($data = fgetcsv($inputfp, 1000, ",")) !== FALSE) {
 
        // Declare an array which will be used to hoe the new csv line
        $line=array();
 
        // Add the data from the read csv file to the output array
        $line[]=$data[0];
        $line[]=$data[1];
 
        // Add some more data, just because we can
        $line[]="another param";
        $line[]="yet another extra param";
 
        // Write the line to the file
        fputcsv($outputfp, $line);
    }
 
    // Clean up
    fclose($inputfp);
    fclose($outputfp);
}
 
?>

Introducing 33mail.com – Unlimited Disposable Email Addresses

I’ve just launched my latest project 33mail.com. Its a solution to the ever increasing problem of spam and the fact that you really can’t trust anyone with your email address anymore. The system is pretty simple, you sign up to 33mail with a username, say testing123, and you give 33mail your real email address, you can then create alias addresses using 33mail, such as blog.aclarke.eu@testing123dhy66s.kjjss33djjhsda2mail.com which will then be forwarded onto your real address. The kicker is that at any time you can kill the alias addresses you create, and because you can create unlimited addresses you can give a different one every time you need one.

The site is built with codeigniter and the email server backend is pure java.

I’d love to hear any feedback on the site design, functionality and the service as a whole.

Laser card custom payment module for Magento

While helping my brother out with bringing his sports shop online, I discovered Magento which is a pretty kick ass piece of php. One thing that Magento doesn’t have at the moment is a payment module for Irish Laser Debit cards, so I decided to write my own.

Some resources that I found useful were this and this, The first being from the Magento wiki and the second from a forum post.

The process is pretty straight forward once you get your head around all the config files, there are basically 10 files needed for the module (Coolbreeze is just the package name I gave the modules akin to the Mage group in magento) :

app/code/local/Coolbreese/LaserPayment/Block/Form.php
the controller for displaying the input form in the store and admin

app/code/local/Coolbreese/LaserPayment/Block/Info.php
the controller for displaying the card details in the store and admin

app/code/local/Coolbreese/LaserPayment/etc/config.xml
config stuff

app/code/local/Coolbreese/LaserPayment/etc/system.xml
more config stuff

app/code/local/Coolbreese/LaserPayment/Model/Laser.php
where the validation etc happens

app/design/adminhtml/default/default/template/laserpayment/form.phtml
the form template for the admin interface

app/design/adminhtml/default/default/template/laserpayment/info.phtml
the details display template for the admin interface

app/design/frontend/default/default/template/laserpayment/form.phtml
form display in the store

app/design/frontend/default/default/template/laserpayment/info.phtml
details display in the store

app/etc/modules/Coolbreeze_LaserPayment.xml
the main config file which tells magento that this module exist.

Here for your viewing pleasure is the module code to download.

To install it in a Magento installation just copy the app folder into the magento root and all the files will be put in the right place. Then go to admin -> System -> Configuration -> Payment Methods and enable the module.

Some cavaets :

I take no responsibility for breaking anything whatsoever so install this at your own risk or better yet look at the code and improve it.

The Laser number validation is pretty simple at the moment with no modulus checks. Something like this would probably be useful also as there is no client side validation just server side which works ok but is not ideal.

I’d love to hear feedback from anyone who uses this or finds it useful.

Windows 7 first impressions

The first surprising thing about the Windows 7 beta is that it works great running in VMware, so if you have a relativly new vesion of VMware installed then it is well worth installing the beta to have a look.

The UI is distinctly vista like with the the round start buton and start menu, and similar dialogs, but for some reason it doesnt give off that hateful vibe that Vista does (having installed vista and immediatly removed it reverting back to trusty XP, Im no fan).

The beta comes with some nifty little apps like sticky notes and a great snipping tool for taking screen shots along with the usual games, calculator and of course paint (which is a nicely updated version in the vein of office 2007). It also comes with an IE 8 beta which may be of interest to some.

Overall i like the feel of Windows 7 and after seeing this beta I have high hopes of eventually upgrading my Windows XP machine to it.

So Microsoft, please dont f*$k it up before release.

Crop and resize an image using MiniMagick

During my dealings with twitter avatars (see here) I discovered how to resize and crop an image using MiniMagick. This is useful when dealing with twitter avatars as the large size ones that the twitter api provides are not always square and the smaller ones may be too small for some applications. Below is the simple function :

def resize_and_crop(image, size)         
  if image.width < image.height   
    remove = ((image.height - image.width)/2).round 
    image.shave("0x#{remove}") 
  elsif image.width > image.height 
    remove = ((image.width - image.height)/2).round
    image.shave("#{remove}x0")
  end
  image.resize("#{size}x#{size}")
  return image
end

Professor Farnsworth mindgames