All sorts of nitty-gritty technical things.

Light Weight Logger in C++

I came across this interesting article in Dr. Dobbs that details the implementation of a light weight logging framework in C++ that uses policy classes:

http://www.drdobbs.com/cpp/a-lightweight-logger-for-c/240147505?pgno=1

I reckon that it could be of special of interest for use with embedded systems.

Visual Studio 2010, TFS – The associated source control plug-in is not installed or could not be initialized.

I recently started getting the following error when opening a solution in Visual Studio 2010:

“The associated source control plug-in is not installed or could not be initialized. Common causes for this error include server unavailability and/or incorrect workspace mappings”

I had just installed Visual Studio 2012 and was worried this had caused the problem in VS2010, but now thankfully I think that it was just a coincidence, from my research this error seems to pop up frequently enough all on its own.

So, more information on how to fix the problem can be found here:

http://stackoverflow.com/questions/5081405/tfs-error-source-control-unable-to-access-database

But in summary the way I was able to fix it was to edit the solution file by hand and remove the following section:

 #
	GlobalSection(TeamFoundationVersionControl) = preSolution
		SccNumberOfProjects = 99
		SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
		... Blah Blah Blah.....
	EndGlobalSection
#

Once I had changed the solution file, I loaded it up in Visual Studio and put it on-line with TFS by choosing the File -> Source Control -> Go Online menu item.

Now my solution was back to normal and happily reconnected to TFS.

I was mightily relieved to get rid of that annoying problem, so many thanks to all at stackoverflow!

Xilinx Zynq Linux – Mount NFS Volume, Connection Refused, failed to register lockdv1 RPC service (errno 111)

You may have been having problems mounting an NFS volume on a Xilinx Zynq kernel build, perhaps mount fails with a ‘Connection Refused’ error message. If you check the /var/log/messages

cat /var/log/messages

Then you may see some entries like this:

Jan 10 21:22:34 zynq-zx3-starter user.warn kernel: svc: failed to register lockdv1 RPC service (errno 111).

If this is the case, then you may have to provide some extra option arguments to mount to get things working as follows:

 
mount -o port=2049,nolock,proto=tcp 192.168.0.11:/export /mnt/mymountpoint
 

I was having huge problems getting mount to work but this fixed things for me, thanks to all here for the tip!.

 

web2py – External connections to your Web App from the network on port 80

If you don’t want to use apache or the like to publish your web2py app then you can use web2py’s own little web server (rocket) by running web2py.py like this:

python web2py.py
 

This won’t accept external connections however, and it also listens on port 8000 rather than port 80.

 

So, to allow external connections from web clients on port 80, run web2py.py as follows:

python web2py.py -i  0.0.0.0 -p 80

I keep forgetting this, so it’s getting written down for once and for all!

 

Ubuntu running slowly on Oracle VirtualBox Virtual Machine

It is quite easy to get up and running with Ubuntu on Virtual Box, however a few tweaks will help you get the best out of your Linux installation. You might notice that your Ubuntu VM appears to run quite slowly, recent Ubuntu releases involve quite a lot of fancy visual effects on the desktop – these can really grind along very slowly on Virtual Box unless the ‘Enable 3D Acceleration’ setting is checked.

 

To enable this setting, first shut down your VM, then right-click on it and choose ‘settings…’, click ‘Display’ (on the left), and check the ‘Enable 3D Acceleration’ check box – The Ubuntu desktop should now be much snappier.

 

While you are at it it is probably a good idea to allow virtual box to use more Video Memory (why not 128Mb?!), also let it allocate it more base memory on the ‘System’ settings tab (set this to a few Gigs!).

 

To get the best out of your Ubuntu installation you will probably want to increase its screen resolution from the poky 1024×768, to do this you must first install the ‘Guest Additions’, once you have these installed you will be able to increase the screen resolution and also auto-mount directories on your host system for sharing files between the host and guest.

 

Here is a a short tutorial on installing Guest Additions. if you find that the guest additions don’t install or work properly with Ubuntu, it may be worth upgrading your installation of Open Box, I had problems getting them to work with v4.1.x, but they installed perfectly with v4.2.8.

 

Once they are installed you can drag the screen to the size you want and the choose the ‘View’ / ‘Auto-size Guest Display’ menu item, this will change your screens resolution to match the screen size.

 

Drupal 7 – Filter form not displaying in Views Block Display

If you have a view that exports a filter form, you may find that the form is not displayed when the view is rendered in a block as a ‘block display’, even though it may display perfectly in a ‘page display’ as part of the same view.

 

This problem had me rather worried until I came across this post, simply changing the ‘Use AJAX’ view setting to ‘Yes’ seems to solve the problem (at least it did for me! ;-))

 

To change this setting, click on the ‘Advanced’ area in the view’s settings, and in the section called ‘OTHER’ you will see a setting called ‘Use AJAX’, change this to ‘Yes’ and hopefully your filter form will now display as part of your block view!

 

Raspberry Pi – Restart / Shutdown your Pi from Python code

Here’s something that you probably won’t want to do, but how can you restart or shut-down your Pi from software in python code?

 

Well it’s both quite simple and quite tricky all at the same time, but in summary you can run some python code like this to shell out to the shutdown command:

 
def restart():
    command = "/usr/bin/sudo /sbin/shutdown -r now"
    import subprocess
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
    output = process.communicate()[0]
    print output
 

Executing this python code is like running the following in bash:

 
sudo shutdown -r now
 

Which will reboot the system. Note that the shutdown command is sudo’d and that the full paths to sudo and shutdown are specified.

 

Now for this code to work it must be run in the context of a user that has sufficient privileges (e.g. the pi user). If the python code is being executed by a user that does not have the necessary permissions then the it will not work – for example when running this code as part of my Web2py application the code initially had no effect as it was being run as the apache www-data user.

 

To fix this problem you need to add the user in question (in my case www-data) to the sudoers file (for the shutdown command). Edit the sudoers file by issuing the following command in bash:

 
sudo visudo
 

Then add the following lines to the end of the file remembering to ‘www-data’ to your target user:

 
 
www-data ALL=/sbin/shutdown
www-data ALL=NOPASSWD: /sbin/shutdown
 
 

And hopefully that should do it!

 

Web2py – Make your app the default web application.

There are multiple ways of making your app the default web2py application, they are detailed here in the section called ‘Application Init’. When an app is the default web2py app, you don’t have to specify its name in its url when you visit it in your browser.

 

Here is a summary of the method that I prefer.

 

First create a file in your web2py directory called routes.py, you can rename routes.example.py to routes.py but if you do, remember to delete any example code that it may contain.

 

Add the following code to routes.py:
[crayon]
routers = dict(
BASE = dict(
default_application=’your_app_name_here’,
)
)
[/crayon]
Replace your_app_name_here with the name of your web application, and the restart web2py. How you restart web2py depends on how you run it, for example in my case I restarted apache.

 

When web2py has restarted you should now be able to access your app via a naked url.

 

Twitter Bootstrap programmatically open or close an Accordion with javascript

Q: I have a nice accordion in my web app set-up in twitter bootstrap but how can I programmatically open or close a section using javascript?

A: Use the .collapse() function to open, close or toggle a collapsible accordion section.

Consider this 2 section accordion:

[crayon]

The camera settings

The acquisition settings.

[/crayon]
Then, as an example, to automatically open the second accordion section (identified by ‘#category-2’) when the page loads you could do the following:

[crayon]

[/crayon]
This technique can be used to automatically re-open a previously open accordion section on page refresh, to do this first use the history api to update the current page location whenever a user clicks to open an accordion section – store an id to the open section in the page arguments.

Then when the page loads, for example on a refresh, if this argument exists parse it from the page loaction and then call collapse(‘show’) to open the section…

More details on .collapse() can be found here.

 

Web2py and python – Change to model definition may break web site

In Web2py if you want to change a model’s definition, you can first of all change the model’s software definition via its python code and then, (depending on your migration settings), the next time you launch your web app, web2py will attempt to alter your database structure to match your updated model.

 

If this works, then it works and your database will reflect your new model, however sometimes web2py can’t make the necessary changes and your app may not subsequently load any more at all. If this happens then I have found the best way to fix the app is to delete all of the files in the app’s database directory – the next time you launch your app web2py will recreate your DB from scratch and it should launch again.

 

Now this is fine assuming that your database didn’t have loads of important data in it that you didn’t want to loose. So, to get around this problem, before trying to change a model’s definition I export all of the data in the database to a file (using a tool like this) so that if the problem happens and I have to get web2py to recreate the database ‘in its own image’ I can later reimport the previously saved data…