Search...

20 September 2012

Passing Arrays Between Contexts In Javascript

Today I have found a nasty gotcha that stumped me for some time while creating a snippet of JavaScript which called a function that included an Array as a parameter.

I was trying to call a function on an object bound to the window which contains some utility classes. I created my Array, populated the values and sent it to the function. However, it didn't work as expected. After some head scratching and debugging in Chrome I found that the receiving code was not seeing the Array parameter as an instance of Array. Instead it was seeing it as an object.

After checking my calling code to ensure I was not having a daft moment, and after much trial and error I hit Google. The answer was actually rather obvious once I found it. The problem I was having was that the calling code was in an iframe in my page. When you create an Array you are actually creating a window.Array object. This of course means that the object's prototype is not available to in the window context (i.e. the parent page) and so the receiving function was treating it as an object.

The answer, as I realised while talking to my co-developer, was that in order for the parameter to be seen in the receiving code as an Array, it needed to be declared as new parent.Array(). Once this change was made everything worked as expected.

20 August 2012

Ruby on Rails Arch Linux Basic Instal

I have been playing with Ruby on Rails for a while after completing a Coursera based SaaS course recently. While undertaking the course I worked on an Ubuntu VM which was provided by the course. However, as in all things I hack around with on Linux I really wanted to set up a basic Rails development environment on my main Arch Linux machine.

While the guide on the Arch wiki was fine when I reached the point of testing my environment I got the following output in bash ....

/usr/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

A quick hunt around the forums did not help me!

Following the link in the above error message I read up on execjs and found that you need a supported runtime. I opted for therubyracer, an implementation of the Google v8 javascript runtime.

In bash I ran gem install therubyracer which installed the runtime. I then added the following line to my test applications Gemfile :

gem 'therubyracer', :require => 'v8'

Running rails server now served up my test app on the default port (using WEBrick).

8 August 2012

Arch Linux glibc Update

Arch Linux has made a rather big change to the file system recently and has moved the files in the /lib directory to the /usr/lib directory and /lib is now a symlink to usr/lib. You can get an overview of the change here and here. Both of these pages give instructions and possible issue resolutions for most case's.

However, as searching the Arch Forums on glibc will show, the resolutions outlined in the above documents do not always work. There are a large number of users that have had problems due to various files that are left in the /lib directory. To quote Zamboniman from the Arch Forums "This has been one of the more frustrating upgrades in my history with Arch." After running pacman -Syu recently I discovered I was one of these people!

I have now resolved my issue and wanted to detail it incase it is any help to anyone else still struggling with the issue. For a little background I am running Arch 64bit.

NOTE DO NOT USE --force WITH pacman IN ANY FORM TO RESOLVE THIS ISSUE AND DO NOT DELETE OR MOVE ANY FILES MANUALLY.

First, I followed the recommended update method and ran pacman -Syy and then pacman -Syu --ignore glibc. This brought the system up to date and I then ran pacman -Su which will update glibc. However, like so many others, I got the following error output :

error: failed to commit transaction (conflicting files) glibc: /lib exists in filesystem

This, apparently, is caused by files remaining in the /lib directory. As per a number of the suggested solutions I then ran find /lib -exec pacman -Qo -- {} + which lists who owns the files left in the /lib directory. As recommended in one forum post I started to look for files not owned by glibc. There was one file and that was lib32-glibc. A lot of the solutions suggested at this point to just delete the file or uninstall the program that it is installed by however, looking at the file version (2.15-10) I noticed that there was a newer version available. The file is installed from the Multilib repository and I was at a loss as to how it was not being updated. After a little more digging I found that the Multilib repository was commented out in the /etc/pacman.conf file. I uncommented the repository entry in the file and ran pacman -Syy and then pacman -Syu --ignore glibc and then ran pacman -Su.

This all appeared to work. As a final check I ran ls -ld /lib which should output lrwxrwxrwx 1 root root 7 Jul 7 11:09 /lib -> usr/lib which denotes that everything has worked.

This solution will probably not fix everyone's issue with regard to this update and the links below are to forum threads that helped me track down the solution to my problem

  • https://bbs.archlinux.org/viewtopic.php?id=145006&p=1
  • https://wiki.archlinux.org/index.php/DeveloperWiki:usrlib
  • https://bbs.archlinux.org/viewtopic.php?pid=1129890 - This thread contains Zamboniman's excellent advice which appears to have helped a number of people with slightly different issues to mine.
  • https://bbs.archlinux.org/viewtopic.php?id=109765 - Multilib related.
Now, to get on with playing with KDE 4.9!

23 May 2012

Visual Studio 2012 Missing Project Templates

Since I set up my new work machine I have been working on existing projects. However, today I wanted to start work on a little utility application and so fired up Visual Studio. On clicking new project I found I had no templates installed by default.

After some digging on the interweb I found the answer is to close Visual Studio and then navigate to your Visual Studio install directory (c:\Program Files\Microsoft Visual Studio 10.0\) and then locate the devenv.exe. For me the full path was c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE.

Once there in a Visual Studio Command Prompt you need to run the following :

devenv /installvstemplates

It will take a couple of minutes to finish but once done you can fire up Visual Studio and all the default templates will be available.

16 April 2012

Arch Linux Qt Package Issue (KDE)

For the first time in all the time I have been using Arch I have experience my first major package breakage.

The night before last I ran pacman -Syu and one the packages upgraded was the Qt package. It was upgraded to qt-4.8.1-2. Next time I booted up I was getting a KDE Crash dialog appear noting an error with KRunner. Trying to run krunner from the shell I was presented with a host of errors.

A quick search of the Arch forums I found this post reporting similar problems. Following the advice in the post I downgraded the Qt package and my problems where resolved.

To find out if you can downgrade your package you will need to search the /var/cache/pacman/pkg directory to ensure you have a package to downgrade to. If you do then you can run pacman -U /var/cache/pacman/pkg/qt-4.8.0-6-x86_64.pkg.tar.xz (or whatever version you have). If you can not find an earlier package in your cache then you will have to refer here (the Arch wiki) which will provide further details.

(I should mention that I am running 64bit although I have no idea if this effects 32bit).

15 April 2012

KDE 4.8 Task Manager Launcher Issue.

Of all the great new things that arrived in KDE 4.8 one of the most annoying to me was the inclusion of a browser and file manager launcher in the Task Manager. These are the little icons that appear when the said application is not running.

I tried to remove the launchers with the usual right mouse menu option but everytime I re-booted I ended up with the icons back again.

I have finally figured it out though. For some reason you need to remove the Task Manager from the panel and add a new instance of Task Manager and that seems to solve the problem.

While it is a 2 minute fix it is something that should just work by default I think.

22 March 2012

Arch Linux - i3 Graphics Setup

Gonzo has been reborn!

My trusty old Thinkpad has finally died and so I have brought a Fujitsu A531 to replace it. Its not a bad spec for the money I paid (i3 2.2, 8gb, 750gb HDD all for £419).

I have just installed Arch 64 bit on it and had KDE up and running in less than an hour and a half. The first thing I noticed was the graphics acceleration was not enabled and I seemed to be suffering poor framerates. I found that by adding a file called 20-intel.conf to the /etc/X11/xorg.conf.d directory and adding the following solved my issues :


Section "Device"
Identifier "Card0"
Driver "intel"
Option "DRI" "true"
Option "SwapbuffersWait" "false"
EndSection


Reboot and 3D effects and a good framerate where restored.