Page 3 of 6

Winter hikes are the best

image

Reblog: Python Minidom and Whitespace

A good tutorial providing fixes for printing of XML using Python and Minidom. Specifically fixing added whitespace and the conversion of characters into HTML entities.

The Python Subprocess module is a highly flexible way of running background processes in Python. Here are two functions that show how to run external shell commands, one will wait for the command to return and the other runs in the background allowing the controlling script to stop it as required.

Passing unsanitized input to these functions will not end well.

 

Monit: Failed to change UID

Monit is an excellent monitoring and process management tool, it has a huge array of features in its custom syntax, one option is to run programs as a specific user, for example –

I recently had trouble getting Monit to correctly change the UID and GID of an application, there was very little error messages available but restarting it with the -v flag showed me ‘Failed to change UID’.

It took much guess work to find the solution to this problem which turned out to be that SELinux was enabled. Disabling SELinux in /etc/selinux/config solved it. I assume there could be some better way of configuring SELinux to handle Monit’s requests to change UID but as this is an internal test system it doesn’t matter.

Generic CSV to Plot With Numpy and Python

Given multiple CSV files containing a timestamp column and some plottable values (int or float) this script will plot multiple columns of data by time.

Usage is as such – ./CSVPlot.py first.csv second.csv third.csv

 

 

Compare Lists in C# Unit Tests

A small thing that caught me out today, while writing a unit test for C# I wanted to check that a list was returned in the expected order and used Assert.AreEqual to compare them, this kept failing despite the two lists being exactly the same.

It turns out that there is a separate CollectionsAssert class that is to be used for lists or any form of C# collection and that is due to the List<T> class not overriding the Equals method, the AreEqual function will just check the references instead.

Here is an example of a working unit test comparing two lists.

 

 

Time Bound Python Queue

An extension of the standard Python queue that only stores elements for a given number of seconds before being removed. Useful if you don’t know the volume of data being added to the queue but need to limit it in some way.

There is no decrease in performance when removing items.

Without item removal 

Queue size: 10000

real 0m10.771s
user 0m0.217s
sys 0m0.028s

With item removal 

Queue size: 4659

real 0m10.765s
user 0m0.203s
sys 0m0.028s

 

SQLite Database to CSV

Wrote a Python script that can dump a SQLite database to CSV, it takes the column names as the header and then writes values below. It also has a –sumarise option that can create a one line CSV file of multiple lines in a database.

Does have the option to support XML output in the future but a format would need to be defined by the user.

 

Unit Testing and Code Coverage Results in Jenkins CI

Unit testing is great, code coverage is great and continuous integration servers are great; but what isn’t great is combining all three into something useful!

If you are coding in Java then code coverage is fantastically simple but what if you use C++ and GoogleTest and want the same level of graphification? Luckily it is also simple if you know how – so you’re in the right place.

The scenario here is that you have a C++ project being built on a Jenkins/Hudson continuous integration setup and you also use Google Test for your unit tests. The software required for this is GCC 4.7 which should contain a tool called gcov, this will create the actual coverage files for your executable but will require some additional linker and library options to be added to your build scripts or make files. The final piece of software required is called gcovr, this is a Python script that is designed to read the output files from gcov linked executables and convert it into an XML format that can be read by the Cobertura plugin in Jenkins/Hudson.

It is a good idea to add a separate make target for coverage as it requires the executables to be built with no optimisation and a lot of debug symbols, so not very useful for production environments.

Add the following to your CPPFLAGS –

And this to your LDFLAGS

So for example you could have a section in your makefile that looks like this (assuming the test target builds your unit test.) –

After you have run the coverage build target you then have to run the test executable, this generates .gcov files that describe which lines of code are covered and by what functions.

Then ensure that you can access the gcovr script and run it with the following arguments –

The –gcov_exlcude will remove any unnecessary parsing of files from the GoogleTest framework. The output is placed into the coverage.xml file which can then be accessed from Jenkins by adding a new Post-Build Action from the job configuration page.

Creating An RPM From Tar File

RPM packages are a great way of packaging and distributing software, unfortunately some stand alone software is distributed as a zip or tar file to be installed that way. By converting these into an RPM you can use your package manager as a distribution and removal tool. For this example we will be creating an RPM for the Example Software.

  • The first thing to do is install the RPM development tools, you should only require rpmbuild.
  • Create a folder to be used as a RPM development area and then create a file called .rpmmacros in your home folder that contains the following line: %_topdir <your build folder>
  • Set up your RPM build area by creating the following folders – BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
  • Get a copy of your tar.gz or zipped software and place it in the SOURCES directory.
  • Now the key part of this is to create the .spec file as this describes the build and installation part of the RPM.
  • Create a new file in the SPECS folder called example.spec, fill it out with the following information –

  •  After your spec file is created run rpmbuild -bb ./SPECS/example.spec – fix any errors that are produced, most likely problems will come from getting the correct version/name and target architecture.
  • Find your completed RPM in ./RPMS/<ARCH>

Done!

 

Offshore Expedition May 2013

I am lucky enough to be a programmer who doesn’t have to spend his whole life in an office churning out software, sometimes if the software isn’t good enough we get to venture out to sea and apply some frontline support!

I’ve been on several trips and they have been a great experience, if extremely tiring. Here’s a selection of photos from my most recent trip to the cold north (it’s actually very nice).

HTC One X and Jawbone Up Problems

I got quite excited about the recent push into wearable computers and bought a Jawbone Up to keep track of everything I do. It is a neat system that tracks sleep and movement during the day, it also comes with an excellent mobile application for keep track of this data. Data is transferred from the band using the 3.5mm headphone jack which I thought was quite smart. Only problem? It doesn’t work with the HTC One X, pretty much the only phone it doesn’t work with.

I have tried pretty much everything to get it working and also got in touch with Jawbone to find out what was going on (complete lack of communication and information regarding this issue). After a month they decided to get back to me. The emails are at the bottom of this post.

It looks like I will have to replace either the phone or the band. I was looking at getting the Fitbit Flex as it transfers over Bluetooth which is a much better system. Although I’ve heard there are issues with various Android phones and that also!

 


Jack Concanon 

Apr 05 00:36 (PDT)

Hello there,

I was just wondering on the state of support for the HTC One X and whether
it is dependant on hardware or software of the phone? I am currently
running a custom jellybean ROM with no sound equalising software installed,
when I connect the band to the phone and attempt to sync it does flash
red/green as though it is transferring but it always fails. It does work
fine on a Nexus 4.

I have tried checking logging output and can’t see anything obvious from
the phone.

Anyway, great product just wondering if there is a problem with the phone
hardware itself or if I can just install a different rom? I see on the
supported device list the American HTC One X+ is unsupported but there are
some hardware differences between the two phones and the European models.

Many thanks,
Jack Concanon


Peter (Jawbone Support) 

May 09 05:14 (PDT)

Hello Jack,

Thanks for your email and apologies for the delay in correspondence.

As far as we know – this is not dependant on the ROM installed, although custom ROMs can run into various issues, this HTC ONE X issue seems to be more hardware-related.

You can however try (if you haven’t done so already)
– Uninstalling the App
– Check that Bluetooth is off (has affected some Android models)
– Check that the volume it turned on for ringtone, media, notifications and system (usually accessed by pressing a volume up/down button, hen pressing the gear icon beside the volume control – as we were looking at earlier, this can affect sync on iOS, so it’s worth exploring on Android)

– power cycle the phone

 

Kind regards,

Peter
Jawbone EU Support Team
www.jawbone.com

Phone: +44 (0) 203 027 2094
Fax: +44 (0) 141 248 8142

UK HOURS OF OPERATION
Weekdays 8AM-5PM (UK Time)


© 2025 Acodemics

Theme by Anders NorénUp ↑