How in the name of all that is Holy, do I cut and paste in Vi?

That’s a rather long title to this post, but one that is deserved I feel. I must have been using vi (or vim or even elvis I suspect) for about 23 years now and I’ve never bothered working out how to cut and damn paste in it. Usually I just highlight the text I need (to store it in the local PCs clipboard), then delete it and then paste it back in with a right click. But it’s high time I learnt how to do it properly.

Quite embarrasingly I’ve been doing it half right all this time because whenever you delete lines in Vi, it stores them in a little buffer. All you need to do to stick the contents of this buffer into your document is to press “p” or “P” in command mode. “P” probably works how you’re expecting it to.

For example, type in “5dd” to delete the five lines starting from your cursor posisiton and then move to where you need the text and press “P” to put it there.

Copying is another bucked of cod. You need to “yank” the text you need using either a double lowercase y or a single uppercase one. As usual with Vi there’s a million modifers you can use, such as yw to copy just to the end of the current word. But I think I’ve typed enough on the subject now…

Technorati Tags: ,

Using regular expressions in mysql

I’ve used regex in postgres a lot, but I’ve got a mysql database with a lot of fields that need updating. They’re in the form of “http://url/?page=keyword” and I want to change that to “http://url/page/keyword/”. So I experiment, but yield no results, in fact errors:

SELECT *
FROM `domain`
WHERE redir REGEX `^http`

Continue Reading »

Converting a unix timestamp for use in Excel

So, I’ve got this cron job running to log the results of the uptime command every 5 or 10 minutes. Well, it does a timestamp and then adds in the three load values in a tab separated format. Then I can load this into excel for pretty graphs and stuff and see why over night jobs slowed down at certain points.

It is the loading into Excel point where I come a cropper. After all, windows and unix timestamps differ wildly. Although luckily for us not is a cryptic way. So that leaves two options. Store the values in the csv file as a windows value, or simple apply the following formula:

=(A1 / 86400) + 25569

And here this post comes to a sudden end…

Technorati Tags: , , , ,

Simple rsync guide

It amazing me how little I know when I set about tasks. So I’ve got a folder on one web server (the dev box) and I want it to update a folder on another server (the live site). In the verge of writing a script to do it, I’m told “why don’t you just use rsync?”. Yes indeed, why not.

So then. I need to to it over ssh do the -e flag needs telling that. Plus we’re essentially archiving so the -a flag brings together the -rlptgoD functionality (recurse, links, permissions, times, groups, owners, devices). Add in -v to show what it’s up to, and -z to compress the data, hopefully speeding things up and we’re left with something like:

rsync -e ssh -avzn /path/to/source username@serveraddress:/path/to/source

And this produces the error:
ssh: connect to host xx.x.xx.xxx port 22: Connection refused

Ah, well, yes. I think there firewall isn’t configured in that direction. So I’ll try it the other way round on the destination server.

Yes, it works, yay! :)

Technorati Tags: ,

Ranking well in Google

I meant to post this on this site, but ended up posting it on another one of mine. Anyway, in short, the post is aimed at people who claim ranking is simple in lesser engines but not in Google. Surely, if you can rank well in the other search sites then people WILL find you and and WILL link to you and you WILL rank well in Google. Anyway, I’m repeating myself now. The post can be found here:

The way to rank in Google is not to try and rank in Google

Technorati Tags: , , ,