Awful programming tip

March 19, 2013

When working in project with many collaborators and a gigantic code base, define global functions with names very similar to standard library functions. Oh, and of course use the same inputs and return type.

Implement the function to do the same thing as the corresponding library function. Then, after a while, change the implementation to something similar but not quite the same as the original function.

May I suggest strpcy?

Why is this so hard to fix?

September 30, 2012

It started with the error stating that the file clfs.sys was missing or corrupted. Maybe something about 0xc000000f as well. It was (is) a Windows Vista Home Premium (Swedish only), pre installed on a DELL Inspiron 530S.

The recovery DVD did not help at all, even though it seems like a common problem when searching for solutions.

CLFS.sys is related to logging according to answers on some tech support forums. One solution tip was to boot into a linux distribution and remove some hidden $TxfLog file.

I did that, using a live ubuntu cd, but it did not work.

Then I tried using the Ultimate Boot Cd to check the hard drive for failures, but it passed all the tests.

I had already made backups of all data, but since there was so much space left I thought I might shrink the partition and recover the system to a new one.

Anyway, I started Parted Magic and promped it to test the file system using GParted. It said that “Cluster accounting failed at …: extra cluster in $Bitmap”

Totally 1 cluster accounting mismatches! GParted suggests that I run chkdsk /f and then reboot windows twice (is that the standard way of handling all NTFS problems?)

So the next natural step is to run chkdsk. Chkdsk is a windows tool, but the windows system won’t boot. I don’t want to pull the hard drive and connect it to a working windows system just to run chkdsk. Fortunately, there is a tool called ubcd4win which creates a live windows cd using the files from an original windows cd.

To be continued…

Dual boot Windows 7 and Ubuntu with EFIT and 64 bit system

July 23, 2012

I recently got a new laptop, an N56V from ASUS. It shipped with windows 7, but I didn’t want to abandon Linux so I decided to dual boot with ubuntu.

After I installed ubuntu, my windows refused to boot with the error message “invalid efi path”. I checked it out and apparently there is some new bios boot system called EFIT (?). I did not find an easy solution to this problem.

  • There is a project called rEFIt which looks a bit like it might do the trick, but it seems to be used primary with MAC (?).
  • There were also some other threads, but the instructions involved recompiling grub and/or manually moving partitions and I don’t want to do that.
  • Maybe something like boot camp would do the trick? I havn’t had the time to try, and I needed to get my system up and running (there are only so many times I want to recover my windows installation or switch hard drives..)

I followed this manual to setup the dual boot (which resulted in the EFI error message)

I couldn’t run only ubuntu mainly because:

  • The wirless mouse (Logitech Laser Nano M505) didn’t work properly. My (not so qualified) guess is that it’s got something to do with USB 3.0 compatibility/drivers. This computer only has USB 3 slots.
  • Ubuntu did not find my wired network card (Atheros AR8161/8165 PCI-E Gigabit Ethernet Controller (NDIS 6.20)). I expected it to show up as eth0, but there was no sign of it. The wireless worked right away.

I don’t have time to look into these issues right now – I am back to work and need a working system. And it’s summer and the sun is shining..

my strategy is to wait a few months, checking ubuntu with the live cd every now and then. I really miss ubuntu. When/if the mouse and network card issues have been resolved I’ll try to run with ubuntu as the single operating system.

Anyway, I figured I’d put this post on the internet to see if it turns up in any search results :) Anybody experiencing the same problems as me? Anybody found a [not too complicated or time consuming] solution? Please comment!! I would very much appreciate it.

Update: 

Maybe I’ve been affected by this bug. Hope it’s fixed soon..

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.


Follow

Get every new post delivered to your Inbox.