Archive for the ‘Linux’ Category

Save multiple images to a PDF in Linux

Friday, December 4th, 2009

Place all the images you want in the PDF into a new directory and in the console run the following from within that directory:

convert * mynewfile.pdf

The powerful convert command uses the ImageMagick library which can be installed (in Ubuntu) with the following console command:

sudo apt-get install imagemagick

How to delete all .svn directories

Thursday, July 30th, 2009

In Linux, if you want to remove all .svn files and folders within a directory, navigate to the directory in your terminal and use:

find . -name ".svn" -type d -exec rm -rf {} \;

Credit

Programming with VIM

Tuesday, July 28th, 2009

vim

For years now I’ve used IDEs like Visual Studio and Eclipse occasionally falling back to plain text editors like GEdit or Notepad2 when making quick changes. I’ve been running Linux for almost three years now and, as you do when dealing with remote servers, have sometimes had to edit text files via the console using VIM.

VIM has been around for 18 years and is an extended version of VI which has in turn been around for 33 years. VIM = VImproved. It’s a console-based text editor designed on the assumption that you will only ever be using your keyboard (kiss your mouse goodbye) which means that much of the most common functions are based around the home keys (‘asdf’ and ‘jkl;’) and it’s packed with great programming features.

But the learning curve is about the steepest I’ve ever come across.

I decided a couple of months ago to make an effort to get to grips with it and it took a good four weeks before I was matching the programming speed I was used to with Eclipse. But now I’m finding that my speed is continuing to increase and there is no way I can go back now. It’s not the be-all-and-end-all though; if you are writing a document from scratch (like this blog entry) then VIM doesn’t really have much to offer but if you are editing an existing document (as you often are when programming) it’s streets ahead of IDEs and text editors.

One of the hardest things to get your head around is the fact that VIM is modal which means that you switch between typing stuff and doing stuff to existing text. By default you are not in ‘typing stuff’ mode and so when you type the letter w it’ll skip to the next word. If you want to add text you have to press i and then press Esc after you’ve finished to go back to ‘doing stuff’ mode. For example, to copy an entire line, paste it below, move to the new line, skip three words along, delete the remaining text on the line and start typing, in VIM you would type yy, p, 3w, c$ but the equivalent in a text editor would be to press Shift-End, Ctrl-C, End, Return, Ctrl-V, Home, Ctrl-Right, Ctrl-Right, Ctrl-Right, Shift-End, Delete and then start typing. Those key combinations may seem strange but, once you are used to them, they make a lot more sense than having to constantly move your hands away from the home keys. Especially on a laptop!

VIM is free, open source and is available for AmigaOS, Atari MiNT, BeOS, DOS, MacOS, NextStep, OS/2, OSF, RiscOS, SGI, UNIX, VMS, Windows, FreeBSD and Linux. If you are a programmer or edit plain text on a regular basis I recommend you give it a go but be aware that the curve is about as steep as curves get. If you decide to try it out I can also recommend this website to get you on your feet.

Preload to make Linux faster

Wednesday, February 27th, 2008

If you’re running Linux you’ll be aware that it’s crazyfastâ„¢ already. Want even more speed? Get Preload. If you’re running Ubuntu you can get it by opening your console and typing sudo apt-get install preload.

Time For a Cool Change

Friday, January 25th, 2008

Tonight I set myself a challenge to redesign the look and feel of this blog without using any images. Lots of grey, lots of white space and all typography. And if you are viewing this on Linux it’s likely you’ll be treated to an eyeful of Deja Vu Sans+Serif Condensed – the sweetest open source font IMHO. Windows and Mac users get Helvetica, Arial and Trebuchet.

Search and Replace text in files with Python

Thursday, November 29th, 2007

#!  /usr/bin/python2.5
import os

mydir = "/path/to/directory"
mysearch = "text to find"
myreplace = "Text to replace"

def doReplace(filePath):
    fin = open(filePath, "r")
    s = fin.read()
    fin.flush()
    fin.close()
    fout = open(filePath, "w")
    s = s.replace(mysearch, myreplace)
    fout.write(s)
    fout.close()

for root, dirs, files in os.walk(mydir):
    for f in files:
        name, ext = os.path.splitext(f)
        if ext == '.html':
            doReplace(root + '/' + f)

Explanation: This will find all files ending in .html in the directory specified in mydir along with all matching files in any subfolders and will replace the text specified in mysearch with the text in myreplace. It’s only been tested on Linux but with a bit of tweaking will run on Windows and Mac.

Never Botch an Email Attachment Again

Wednesday, October 31st, 2007

Ever accidentally hit ’send’ when composing an email before you’ve attached whatever file you were intending to send? And then you have to send a quick “DOH!” follow-up email with the forgotten attachment.

I do this all the time and it makes me look like a flaming eejit.

Well, a couple of weeks ago I upgraded from Ubuntu 7.04 to 7.10 and with it came an updated version of Evolution (the Linux equivalent of Outlook). They’ve added a feature that detects if you’ve typed the word ‘attached’ but not attached any files and gives you a warning. Brilliant!

attachment message

ATI vs NVidia on Ubuntu

Tuesday, October 23rd, 2007

For the last few months I have spent countless hours battling with the proprietary (and open source) drivers for my ATI Radeon X700 card under Ubuntu. Yesterday I upgraded to Ubuntu 7.10 Gutsy Gibbon and spent a good four hours trying to get my dual screen setup working again but without any luck.

So, this morning I decided to give NVidia a go and went and purchased a new Asus EN7200GS card for a miserly NZ$80. Success! Straight off the bat too. Well, almost. I plugged it in, enabled the restricted driver, restarted and enabled the second monitor and it’s all working perfectly apart from the fact that I can’t run the ge-whiz Compiz Fusion fancy interface. Everything else is nice though – I’m finally running Google Earth and Stellarium smoothly too.

ATI have been making noises for a while now that they are going to release open source drivers but I say too little too late. I won’t be going back to ATI for a loooooong time.

If you’re running Ubuntu, have two screens and don’t want to ever have to type sudo vim /etc/X11/xorg.conf again then I recommend NVidia.

Windows Vista Popup

Tuesday, September 18th, 2007

User Account Control

9 Months of Ubuntu

Monday, August 27th, 2007

Nine months ago I downloaded the Live CD of Ubuntu 6.06 (aka Dapper Drake), burnt it to a CD, popped it into my CD drive, rebooted my PC and had my first experience with Linux.

My background is in graphic design. Originally in print but in the last seven years it’s been mostly new media and in the last two years I’ve moved almost exclusively to web development. I’d spent a little over a year working heavily in Visual Studio developing web applications and used Macromedia (now Adobe) Studio 8 Suite (especially Fireworks, Dreamweaver and Flash) for all things graphical.

I’ve always preferred Fireworks over Photoshop for web graphics. I like the ability to work with vectors and the amount of control you get for rendering them as images. I know plenty of other designers who love to use Photoshop for web graphics though and they seem to get on just fine with it.

For the times that I’d occasionally take on a bit of print work I’d use either Freehand or CorelDraw. Yes, yes, I realise that Corel doesn’t hold much esteem in the print design community but in my opinion it’s the best all-rounder for the PC. In my Mac days I used Quark and then later InDesign with Illustrator and Photoshop and while they’re a brilliant groups of products they’re not all they’re cracked up to be.

I became a registered Microsoft Partner a couple of years ago and benefited from the plethora of CDs with just about every Microsoft application. I used Project, Office, Visio, InfoPath, OneNote and Visual Studio on both XP and Vista. I also ran Virtual PC with various configurations of Windows Server 2003 and SQL Server.

I think what initially annoyed me about Microsoft was that I began to get into developing standards-based websites (X/HTML + CSS) and grew increasingly frustrated with Internet Explorer’s (and Visual Studio’s) blatant disregard for standards. If you’ve ever developed a website using standards-based CSS you’ll know exactly what I mean. This frustration pushed me towards the concepts of open source and before I knew it I had gone from being a strong Microsoft advocate to a rabid hater. And that was even before I discovered Slashdot!

So, back to Ubuntu.

After trying the Live CD (which I contend has got to be one of the greatest selling points – it embodies the open source ethic perfectly, you can give it a go and it won’t go messing up your entire system) I decided to install it onto a spare drive I had lying around. It was a rather steep learning curve and I came close to throwing the towel in on a number of occasions. I’ve worked with dual screens for years and there was no way I was going to even consider doing any productive work without them. I’ve got an ATI dual head card and had to quickly learn my way around gedit and vim with the xorg.conf file whilst looking for technical support on the web via my intact laptop.

On a positive note, I loved the way you could quickly download free software via the simple Add/Remove button on the menu and felt quite special when I learned to use the terminal and sudo apt-get install. I was generally impressed with the quality of much of the free software available but many of them weren’t quite as good as the applications I’d been using in Windows.

I trialled – and subsequentially purchased – VMware Workstation which I then built a nice, clean install of XP (is that an oxymoron?) plus all my favourite applications on. At least this felt safe. I could go back to the ‘old familiars’ any time I wanted and do away with my anti virus applications at the same time (that’s the beauty of snapshots!).

At first I tried to use gedit for hand-coding all my ASP.NET applications and continued to run and test them on an instance of Windows Server but after the unadulterated beauty that is Visual Studio’s Intellisense (I’m not kidding) this seemed a huge step backwards. I had had a little experience with Python and so tried a couple of frameworks like TurboGears, Django and Pylons using the excellent Wingware IDE but couldn’t find a reliable hosting company and lacked the knowledge to set up my own Python+Apache-based server. I then tried PHP and found that it was far better supported by the hosting companies. It’s an ugly, ugly language but it’s widely used and there are a ton of PHP-based apps out there. My first website in PHP was pretty horrid but it’s been reworked a couple of times now and I’m using Smarty templates and a nice MySQL class along with URL rewriting (which is a pain to get working in .NET if you’ve ever tried). Recently I’ve started using Eclipse rather than gedit for my PHP website too. Oh, and I’ve also used Texy for the family forum.

So, where am I at with Ubuntu these days? I’ve rebuilt my PC once and upgraded twice. I’ve overwritten my old XP hard drive and am using it as my work drive along with a separate partition for my home directory. I’m now only occasionally starting up my VMware instance of XP to use Macromedia Flash or Firework and I have an instance with all the versions of browsers for testing my websites. I’m occasionally using the Gimp in lieu of Photoshop but it’s still got a long way to go. I recently discovered Inkscape and used it to design a logo for a fairly substantial customer – it’s a very nice application and I look forward to the day it’s able to handle print-quality tasks and perhaps even the vector-to-bitmap tasks that I love so much in Fireworks.

I’m happy with Linux. I may try a different distribution when I’m a little more confident as well. My experience has been much better than I was anticipating but there are still a lot of areas that need improvement before I recommend it to anyone else who isn’t willing or able to edit configuration files.

One thing that I’ve noticed is that the Linux community is over-represented by bad logos and stupid application names (having a K on the front of every KDE app is lame and recursive acronyms will never, ever be cool). I guess that’s the price of freedom. There’s not the same pressure from the market to enforce the survival of the fittest in the open source community.

Long live open source and all the splendid mutations it spawns!