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.

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…

Floating point number standards

November 28, 2010

I got an interesting task to interpret a binary file. The problem was that, in the file, they didn’t use the same standard for the floating point number architecture.

The most widely used standard for binary floating point numbers is IEEE 754-1985. For single precision (32 bits), bit 0-22 is the fraction, 24-30 is exponent and bit 31 is the sign. The floating point value is then: (-1)^sign * 2^(exponent-127) * 1.fraction. 1.fraction is a binary fractional number (1.11 is 1 + 2^(-1) + 2^(-2) or something). It was confusing since I never used that before.

Anyway, this did not comply with the floating point numbers in my file. However, the fraction (might also be called mantissa?) was always the same. And after a little guessing and fiddling around with bits, I came to the conclusion that:

Bit 0-23 is the fraction, bit 24 is the sign bit and 25-31 is the exponent. The floating point value is then (-1)^sign * 2^(exponent-129) * 1.fraction. So the exponent offset is different and the sign and exponent bit switched places. This has worked with all the numbers I tried to far.

What is so annoying is that I don’t find this architecture anywhere! I don’t know where to look, google gives me nothing! According to a document I got with the file the numbers are in the CPM format. What is that?? Anybody?

Ubuntu 9.04 + Firefox 3.6.8 + WMware server 2.0.2 + Web access + Remote Console –> Not so fun to get back from vacation

August 2, 2010

It’s always exciting to get back from vacation! Logging in to an old system, running the upgrades, getting your DE up and running.. today the problem was: vmware and firefox compatibility. Apparently my ubuntu decided this was a good time to upgrade ff to 3.6. Wmware however reacted not so well by.. stop working! https://127.0.0.1:8333/ took me to a blank page. http://127.0.0.1:8222/ allowed me to log in and start the virtual machine, but when I wanted to open the vmware console it responded “Cannot access virtual machine console. The request timed out.”

A couple hours spent searching and troubleshooting (installing vmware-player was not helpful at all) finally provided me with a working solution (the post by Mike Masseo): running vmware console directly from command line. The command line essentials:

1) cd /home/myusername/.mozilla/firefox/0qgd98ep.default/extensions/VMwareVMRC@vmware.com/plugins/
2) ./vmware-vmrc

The 0qgd98ep will probably differ, I used tab to auto-complete after /firefox/.

Up and back to work I am!

What’s a bug like?

August 1, 2010

Today I decided to add a subversion repository to my newly upgraded Ubuntu 9.10 fit-pc according to this guide. When I was creating the new subversion-group it suggested the id to be 0. I didn’t think it mattered so I happily pressed ok. Without checking that the group was created properly, I logged out and back in. The group had not been created so I tried again, and got some error message. I rebooted the computer to get a fresh start..

On my next svn-instruction-command I got the exciting message that my user was not in the sudoers list! When checking through the users and groups, I saw that the subversion group had been created but that my password did not work as root password anymore!

To fix this I had to restart in recovery-mode and open a root terminal (hold/push shift during restart, choose recovery mode, press any button after text messages, choose “root” in the menu). I had found this helpful thread, and tried:

sudo adduser myuser admin

And got told that group admin does not exist! Some more searching took me to this place. I looked at the /etc/group file and saw that, indeed, the admin group was nowhere to be seen. I added the group with my username and finally I was root again.

So.. is this a bug I ought to report? I always assume that it’s a user problem (me). I checked the “add group” function again. Sometimes it suggested the group id 0, sometimes not.

How to create a csv file in javascript and get the “save as”-dialog

June 17, 2010

Long headline! Anyway, this is a problem I’ve encountered more than once. When exporting data from a webpage to a .csv file I usaually create it on the server side using a servlet.

However, If the data is already stored in the browser, you don’t want an extra server request (especially if you’ve manipulated the data on the client).

The first lead came from this post. It explains how to open a separate window with csv content. But how to get the “Save As” dialog? After some searching I found tips about using “data URL” and finally found the solution.

The essentials of my test code:

function loadLinkButton(){
  var btn = document.getElementById("linkButton");
  var axx = document.getElementById("ax");
  // I used this online encoder to create the data url.
  // axx.href = 'data:text/csv;base64,MTsyOzQ=';  // This was my first test, not having the encoder. 
  axx.href = 'data:text/csv;base64,'+Base64.encode("3;2;1");} // I used the javascript encoder from this page.
}

<body> 
<a id="ax" href="">test</a>
<button id="linkButton" onclick="loadLinkButton();">asdf</button>
</body>

So basically, pressing the “asdf” button creates the data URL and then the link “test” opens the csv (with save-as dialog). Havn’t tried it in IE, but I’ve read that it’s not going to work.

Questions? Feedback? Feel free to comment!

silent computer – tyst stationär dator

June 8, 2010

For quite some time I have been searching for a new computer. I wanted it to have decent performance and be quiet but none of the stores I checked had any sound-preferences whatsoever. I didn’t want to build it myself so I went to a local store in Lund called itel and had them build me one. We chose the components together, after two days it was ready and the pricing was good. This is what I got:

  • Fractal Design Define R2 Black Pearl
  • Scythe 450W power supply
  • Asus P7H55, S-1156 DDR3 GbLAN HD-Audio
  • Intel Quad Core i5 2,66 GHz, S1156, 8Mb 14250
  • Noctua NH U12P SE1366 (CPU cooler)
  • Corsair Dominator DHX+ DDR3 1333MHz 4Gb(2*2Gb) XM
  • Seagate Barracuda 500Gb 16MB Cache S-ATA2
  • Asus Radeon HD 4350 512Mb Silent

Maybe all computers are fairly silent by now but I am really surprised by how quiet it is! I can really recommend this store! (Now I feel silly writing in English, clearly addressing Swedish people). Anyway, these are quiet components and they work good together (had the computer almost a week now, running Ubuntu Studio).

For a perfectly silent HTPC however, I can recommend the fit-PC2. It’s more like an industrial computers I work with. Slow, reliable, fanless, energy saving.. and it plays HD! I run ubuntu 8.04, but I hope for 10.40 support soon.

About EMU 0404 USB support for Ubuntu

June 7, 2010

For a few weeks I was searching for evidence that this particular sound card was supported in Ubuntu Studio 10.04. I found some evidence and clues, like this extensive thread and the ALSA page with beta drivers. I was still suspicious though, but since we (me and my boyfriend, he’s using the sound card for recording) really wanted to avoid windows, we decided to try.

So we downloaded Ubutu Studio 10.04 and installed it with all the suggested software bundles. We did the modprobing for drivers:

modprobe snd-emu10k1 ; modprobe snd-pcm-oss ; modprobe snd-mixer-oss ; modprobe snd-seq-oss

And then we started Audacity, chose EMU 0404 as playback & recording device in the preferences and we were up and running! Much faster than we would have been with windows. Just so awesome!! I’m not even sure I needed the modprobing. The quality was ok and recording and playback worked on both input channels (connected to a digital piano).

Enter key hangs

June 3, 2010

This is driving me crazy so I need to write it off!

A few days ago, a new problem started to interfere with my daily work. Every now and then the Enter- key keeps pressing itself (hangs) for no apparent reason. And  it stops when I press F2!

Of course I assumed it was a hardware problem, since several people around me had that problem with laptop keyboards (and solved it by replacing them). I’ve never been violent to my keyboard and don’t remember ever spilling liquid on it (I know, it’s a miracle since most of the stuff on my desk have been swimming in coffee at least once).

Anyway, I started looking into Linux forums and disabled my keyboard according to this post. I connected a usb-keyboard and started working again.

15 minutes later the same thing happened again! By pressing F2 on the usb-keyboard it stopped! So maybe it’s a software problem in Ubuntu?

I’ll get back when I’ve upgraded my OS. It’s time anyway, I’m running 9.04 and want to try 10.04 asap. Unfortunately I need a decent time span with low workload. If VMware (Server 2.0) fails me I can’t work.

Btw, I’m using a Dell Precision M90 anybody seen a similar problem with this laptop?

[update]

It seems like the problem is caused by Terminal Server Client. I stopped using it for VNC (connected to my virtual machine) and havn’t had the problem since.

Yet another missing irl feature

February 22, 2009

So, I’ve been through the ctrl-z feature and the stop, rewind and analyze feature. What else is missing in my life? A robot to take care of all house hold work? An index to the CD collection? To be able to search for quotes in all my books? Yes, all of that of course, but my whining today will be about the saving ability. Why can’t I record my memory and save it on a USB-stick for later? How come it’s so hard for me to put the cool dream I had out on youtube? There is so much media I’m just missing by forgetting!!

Dreams, memories, books that are like movies in my head. Lately, I’ve been reading a lot of Terry Pratchett novels. Each one of them makes such a great hollowood-production movie in my head. It makes me wanna change career into a film maker!

But nooo, I can’t even get a screenshot out of my head. That totally sucks.


Follow

Get every new post delivered to your Inbox.