Archive for October, 2011

How to put a semicolon at the end of each line ;

October 11, 2011

I’m not very fond of copy-paste programming, or copy any large chunk of text into my program and make code out of it.

However, sometimes I have to. When it’s not defendable to write a file parser to parse one file once.. It’s usually when validating something and it’s necessary to get a set of test-data into your program with the least possible effort.

Have you ever gone through a 100-rows or more file and put [ ] ; – { } ( ) \ / in the beginning or end of each line? I have. Lots and lots of times. Until I discovered gvim.

Now I write nice little commands like

%s/asdf/ghij/g	- Replace asdf with ghij in entire file.
%s/$/;/g	- Add semicolon to the end of each line
%s/^ ;//g	- Delete semicolons from previously empty lines..
%s/^/\t/g	- Add tab to beginning of each line
g/asdf/d	- Delete all lines containing asdf
g/asdf/d2	- Delete 2 lines from every line containing asdf.

I don’t remember all pages I read to create these macros but this was probably one of them.

Advertisements

Virtual machines, vmware and VirtualBox

October 10, 2011

A while ago I was migrating from VMware Server (the free version) to VirtualBox (which is also free). In order to convert my vmdk to vdi I started out using this guide.

It is nowadays possible to directly use the vmdk in VirtualBox, but for some reason I wanted all my disks as vdi.

Some of my drives where devided into 2GB chunks. First I created a single file out of them using:

vmware-vdiskmanager -r vm.vmdk -t 0 hardrive-name.vmdk

(vm.vmdk is my source disk and harddrive-name is the destination disk)

Then I installed qemu (sudo apt-get install qemu)

..in order to convert the disk to a bin file (I figured it’s always good to know how to do this in case I want a hardware drive later on..):

qemu-img convert harddrive-name.vmdk raw-file.bin

And then to convert to vdi I use VBoxManage:

VBoxManage convertdd raw-file.bin new-file.vdi

Tadaa.. Then I created a new virtual machine using VirtualBox. Since I’m speaking of virtual boxes ¬†anyway, here are some notes-to-self about creating it:

  1. Create the network adapters, I use one to bridge my wireless and one to bridge my LAN. (TODO: Learn how NAT is working in VirtualBox)
    1. I have a DELL PRECISION M90 and the “Advanced” “Adapter type” “INTEL PRO/1000 MT Desktop” works better for me.
  2. Share a folder. I share the same folder in all my virtual machines and has it setup as a network harddrive in windows. Works like a charm! One of the reasons I migrate from VMware, there I use ftp.. (with my host as ftp-server).
  3. Add the USB-device filters I want.
[Update]
This did not work, my vm was not bootable. To be continued…