Comment Multiple Lines in Vim

January 5, 2010 No comments »

Oh Look - The Vim LogoEarlier today I was asked how to comment out multiple lines in Vim. Unfortunately I wasn’t too sure what the best way was and the only one I knew felt less than friendly. Anyway – after some research I’ve nailed a few different methods and thought I’d post them here for people to choose their favourite one.

1. Visual Insert

This is the simplest method by far. Quick fire steps are:

  1. Ctrl + V (enter block-visual selection mode)
  2. Select the first character of the lines you want to comment out using “hjkl” or cursor keys
  3. Shift + i
  4. Type your comment marker: “//”, “#”, etc.
  5. Escape
  6. The end – there is a tiny delay as the comments are now put into your other lines.

2. Visual Search/Replace

This is similar to the above but has a slightly more arcane method to adding the comments.

  1. Shift + V (enter line selection mode)
  2. Select the lines you want to comment out.
  3. Type:
:s/^/# [Return]

or

:s/^/\/\/ [Return]

The first will replace the the beginning of the line (^) with a hash (#) and the second will do the same with a double slash (//). Note the extra slashes to escape.

3 Line Number Range

Similar to above this is the only method I could think of and its hardly very friendly but it gets the job done.

Pick the line numbers of the first and last lines you want commented – this is rarely simple.

Type:

:2,10s/^/#

That will put hash comments at the start of lines 2 to 10.

4. Using Markers

I’m not fond of this method as I’m still not 100% on markers. In fact I’m around about…..0% on markers as I’d not heard of them until now!! Woo for learning!

Anyway – markers. Oh yes, I’ll do a nice list of steps again:

  1. On the first line while in command mode type “ma” (no colon required here)
  2. Go to the last line of your intended block.
  3. Type:
:'a,. s/^/# /

In English that means: Form marker “a” to here (.) perform this command: s/^/# /

5. Plugins

You could just skip all that and install a Vim plugin. The advantage being they have more features. The disadvantage being you’d have to make sure all the servers you use have this plugin otherwise you’re stumped.

Chrome Extension: Shiny MPs

January 3, 2010 No comments »
Chrome Extension Screenshot - Shiny MPs

Chrome Extension Screenshot - Shiny MPs

Writing extensions for Chrome is so refreshingly simple it’s exciting. So as a result I produced another one and this time for a slightly more specialised use. If you’re UK-based and interested in politics then this plugin will enable you to keep tabs on your MP with their latest parliamentary updates and links to further info.

If anyone had suggestions I’d love to hear them.

The extension: Shiny MPs

The Source: Bitbucket Hg Repo

The API used is developed by the great TheyWorkForYou.com

Chrome Extension: Augment Search

December 29, 2009 1 comment »

Augment Chrome ExtensionJust released first Chrome Extension: Augment Search.

Its been heavily inspired by BetterSearch which is available on Firefox. I wanted this mainly for myself nut thought it’d be worth releasing to. Will hopefully be the first of many.

Get It

Download from Google

What It Does

  • Adds links to other search results pages for: Google, Yahoo, Bing, Ask, Reddit, Digg, Technorati.
  • Adds extra info links to each result: Alexa, Robotex DNS info, Web archive

Problems

If you have any problems with the extension leave a comment.

To Come

Much more goodies including an options page to customise what is shown.

Tabs vs. Spaces

December 1, 2009 No comments »

Every time I’ve seen one of these “vs” posts its gone into great length about the philosophy behind such and such.  You’ll never convince someone based on ‘religious argument’. So I’m going to take a different approach here and state who does what and hopefully the weight of ‘who does what’ will make the point quite clear.

Screw the Scientific Method!!

Language/Organisation Spaces Tabs Reference
PHP Pear * [1]
Zend (PHP) * [1]
Python * [1]
Ruby * [1]
Java * * [1]
.Net * [1]
C# * [1 Philips (PDF)] [2 - Microsoft]
Lua * [1]
Erlang * * [1]
Object Pascal * [1]
Adobe Flex * [1]
Ada 95 * [1]
Mozilla (Javascript) * [1]
Mozilla * [1]
Google * [1] [2]
Mono Project * [1]
Webkit * [1]
NASA * [1]
Apache (C) * [1]
Linux Kernel * [1]
Gnome * [1]
KDE Libs * [1]
Joomla * [1]
Wordpress * [1]
Zope * [1]
Django * [1]

Notes:

  • Tabs may be rendered differently on different editors and systems.  So they make for less friendly code sharing.
  • Its interesting to note that the ones using tabs all have histories of mental instability, cannibalism, Morris Dancing, witchcraft and heresy.

Clear win for Spaces, which happens to be what I use.

Epic Self Documenting Code

October 9, 2009 1 comment »

This is the best:

switch (mIntegrationDirection)
{
   case InventoryIntegrationDirection.DoTheSameChangeInShop:
      DoTheSameChangeInShop(GetChangedDataFromInventory(mLastSynchDate));
      break;

   case InventoryIntegrationDirection.DoTheSameChangeInInventory:
      DoTheSameChangeInInventory(GetChangedDataFromShop(mLastSynchDate));
      break;

   case InventoryIntegrationDirection.DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory:
      DoTheSameChangeInShopThenDoTheSameChangeInInventoryForNotChangedDataInInventory(
	   GetChangedDataFromInventory(mLastSynchDate),
	   GetChangedDataFromShop(mLastSynchDate));
      break;

   case InventoryIntegrationDirection.DoTheSameChangeInInventoryThenDoTheSameChangeInShopForNotChangedData:
      DoTheSameChangeInInventoryThenDoTheSameChangeInShopForNotChangedData(
	   GetChangedDataFromShop(mLastSynchDate),
	   GetChangedDataFromInventory(mLastSynchDate));
      break;

   default:
      break;
}

Read how this travesty occurred at DailyWTF

GMail Downtime: Affected Small Subset of Users?

September 25, 2009 No comments »

goog_mail_logo.pngNo it didn’t. According to a quote on the Telegraph website the GMail downtime affected only a small subset of users but if you look at the comments on the story it was hitting people in Florida, France, UK and Canada. That’s quite a big, “small subset”!

This is the second time this month – not good.

Django CMS

5 comments »

New Django CMSFinally a Django CMS that looks stable and well built has been released at: http://www.django-cms.org. It’s sponsored by a Swiss compay which doesn’t bother me one bit (I love ….cheese and chocolate?) but the Americans seem obsessed with the idea of everything being American, tariff charges, protectionism, etc, etc, etc.

Anyway – this isn’t a political post so here’s a quick summary of the important points about the new Django CMS project:

  • BSD License
  • Hosted on GitHub
  • Original name: Django CMS
  • Features Summary:
    • Publishing workflow
    • Versioning
    • Multilanguage
    • Application architecture – similar to Joomla Components & Modules
    • Media management
    • SEO friendly
    • Flexible plugin architecture

All in all it looks promising so give it a go. I’m planning on setting up a few sites using it as I need something quick and dirty to use but also the ability to extend it. Being a young project this should be pretty easy. Django CMS

Seskelohots is Lonely

August 18, 2009 No comments »

I have no idea who this is but they commented about 4 months ago claiming to be lonely. They need a hug.

I’m the only one in this world. Can please someone join me in this life? Or maybe death - Seskelohots

With no spammy links posted I can only assume its one of the lonely racoons I mentioned that’s currently lost in Yorkshire.

shy-racoon.jpg

Is this Seskelohot?

Here:
Hug Seskelohot

Best Linux Filesystem?

August 2, 2009 3 comments »

The executive summary in my own words of which filesystem to pick if you’re wondering which is best. I’m avoiding jargon or anything overly technical. I also provide some made-up* graphs to help with quick decision making.

Overview

  • Ext2 – Old. Don’t bother.
  • Ext3 – Lacking in performance though very solid and reliable with a huge number of tools to fiddle with.
  • Ext4 – More reliability and a little extra speed over ext3.
  • XFS – Sci-fi name and also very fast but lacks the same level of error protection as some others. Undelete is almost impossible. Doesn’t like powercuts.
  • JFS – Like XFS but more reliable after a powercut. Very fast and low CPU usage making it ideal for old PCs and new alike.
  • ReiserFS – Was good, but showing its age and no longer actively developed.

What do you want?

Speed

  1. XFS
  2. JFS
  3. ReiserFS
  4. ext4
  5. ext3
  6. ext2

Reliability

  1. ext3
  2. ext4
  3. JFS
  4. ReiserFS
  5. ext2
  6. XFS

Epic Graphs

Linux Filesystem Speeds


The effects of a powercut on the filesystems


JFS Speed-o-meter

* when I say made-up I mean that. They’re from my own experiences and reading various contradictary benchmarks. There are so many contradictions on speed and reliability out there that I think a rough guide is just as good as any of the other meticulously biased graphs out there. They can be argued as innacurate. But this is my blog – my goddamn rules! If I want pretty graphs I will HAVE pretty graphs!

Python’s Beards and Ruby’s ‘Cool’ Guys

July 30, 2009 20 comments »

I was having a chat on the MicroSoft Networks fancy comms protocol. Aka: MSN. Along came someone with an opinion. As is customary I shot it down with wild abandon!!

The quickie backstory:

  • I suggested Python is better than Ruby.
  • They argued using two example pictures – see below.

Rubyists

ruby_programmers.jpg



I Said:

The Ruby pic: The guy on the right has his eyebrow raised as if to say: “I’m fucking amazing”. The rest of them are all geeks who are using Ruby as their way to be cool in a world that rejected them at high school age for being geeks. Little do they realise (maybe deep down they do) but the only people who may think they’re cool is a small fringe group of other Ruby-ists and beginner coders. The other Ruby-ists will be consumed by an undertone of competitiveness. The Python coders will think they’re rubbish fanboys. The hot girl who rejected them at high school will think they’re just like any other geek.

Pythonistas

504x_Picture_2_23-18-44.png



I Said:

The good thing about the Python coders is they’re not bothered. They’re just not even trying. They’re so past giving a shit about being cool that they’ve all grown ugly facial hair.

This piercing psychological insight into the programmers of Python and Ruby is just the tip of the iceberg. For $200 I’ll furnish you with a graph showing my facts in a nice way that will go well in a professional report.