Yet another Atom Arduino blinker

While experimenting with Atom I produced a minimal example for making my old Arduino Uno blink its LED periodically.

Although there are plenty of examples out there (some of them even work!) I didn’t want to introduce any dependency to the Arduino libraries. Besides making it harder to build (even if arscons is quite nice) it increases the object size and Arduino only supports a limited range of processors. I need the flexibility to use the code on controlles like the ATTiny45

Continue reading →

Posted by Uli Köhler in Allgemein, Embedded

Using QuasiQuotation for more readable Atom code

Lately I’ve been experimenting with using Atom to generate intrinsically reliable embedded software.

In contrast to alternatives like Copilot in Atom you include the surrounding C code as Haskell strings whereas other concepts just generate a set of C files to include in your main code.

Continue reading →

Posted by Uli Köhler in Haskell

How I solved my Toshiba Linux backlight issues

Symptomatics:

I have both the Toshiba Z830 and R850 for a couple of years now. On both, I’m using the current LTS versions of KUbuntu (at the time of writing this, 14.04). Although, I’m absolutely satisfied with them, there’s a little issue regarding the backlight:

On startup, the backlight works perfectly well. I can change the settings using FN+F6/F7 without any issues. However, after putting the device into standby and waking it up again, pressing said hotkeys shows the backlight percentage dialog, but does not change the brightness.

Because Ubuntu’s SSD reboots are pretty fast Iimply didn’t care about the issue for the past few years. However, out of curiosity, I successfully fixed the issue today.

Continue reading →

Posted by Uli Köhler in Linux

Converting zhash_t to std::map

Problem:

You have a hash data structure represented by CZMQ’s zhash_t (see the zhash_t documentation for further information).

In order to be able to use it more conveniently in C++, you intend to convert said zhash_t to a std::map<std::string, std::string>.

Continue reading →

Posted by Uli Köhler in C/C++

Parsing the OUI database in Haskell

In this post, we will show a method and provide a Haskell module capable of parsing both the IEEE OUI list and the IEEE IAB list.

While our code only parses the databases into an object form and doesn’t insert them into a tree capable of fast MAC address -> vendor lookup, it is based on Attoparsec, providing good performance and high flexibility for changes.

Continue reading →

Posted by Uli Köhler in Haskell

How to resolve ‘Can’t perform this operation for unregistered loader type’

Problem

Recently I started to add unit tests using setuptools to one of my packages.

In order to do this, I added a test directory containing MyUnitTest.py. setup.py was properly setup using the

test_suite="tests"

option.

However, when running

python setup.py test

I got this error message:

running test
running egg_info
writing MyPackage.egg-info/PKG-INFO
writing top-level names to MyPackage.egg-info/top_level.txt
writing dependency_links to MyPackage.egg-info/dependency_links.txt
reading manifest file 'MyPackage.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MyPackage.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 29, in <module>
    'Topic :: Scientific/Engineering :: Information Analysis'
  File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 135, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 116, in with_project_on_sys_path
    func()
  File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 160, in run_tests
    testLoader = cks
  File "/usr/lib/python3.4/unittest/main.py", line 92, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.4/unittest/main.py", line 139, in parseArgs
    self.createTests()
  File "/usr/lib/python3.4/unittest/main.py", line 146, in createTests
    self.module)
  File "/usr/lib/python3.4/unittest/loader.py", line 146, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.4/unittest/loader.py", line 146, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.4/unittest/loader.py", line 117, in loadTestsFromName
    return self.loadTestsFromModule(obj)
  File "/usr/lib/python3/dist-packages/setuptools/command/test.py", line 26, in loadTestsFromModule
    for file in resource_listdir(module.__name__, ''):
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 954, in resource_listdir
    resource_name
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1378, in resource_listdir
    return self._listdir(self._fn(self.module_path,resource_name))
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1415, in _listdir
    "Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type

Continue reading →

Posted by Uli Köhler in Python

Haskell: Invert filter predicate

Problem: In Haskell, you intend to filter with an inverted filter operator.

For example, your code is (GHCi):

Prelude> import Data.List
Prelude Data.List> filter ( isPrefixOf "a" ) ["a","ab","cd","abcd","xyz"]
["a","ab","abcd"]

The list you need is ["cd","yz"]. In some cases, the easiest solution would be to use for example <= instead of >, but there isn’t a literal complement for all functions, like for example isPrefixOf, which is being used in the example.

Continue reading →

Posted by Uli Köhler in Haskell

Buffer-overflow safe readlink() in C++

Problem:

You want to use readlink() to get the file or directory a symbolic link points to, but you don’t know the buffer size that is required to store the symlink destination. You don’t want to allocate an incredibly large amount of memory (whatever amount you choose, it could always be insufficient), but you won’t risk buffer overflows.

Continue reading →

Posted by Uli Köhler in C/C++

Accessing NCBI FTP via rsync

A little-known way of accessing data on the NCBI FTP servers is by using rsync. This method was first mentioned in this mailing list post in 2004.

Using rsync instead of ftp has a few key advantages

  • Fully incremental downloads
  • Resumable downloads
  • Faster than FTP
  • Only a single connection, no problems with FTP active/passive ports (e.g. important for dual-stack lite, e.g. see this excellent post in german )

Continue reading →

Posted by Uli Köhler in Bioinformatics

Solving ‘invalid multibyte escape: /^\xFE\xFF/’ in ruby vpim

Problem:

When using Ruby 2.0/2.1 with the vpim gem (tested with version 0.695), you get an error message similar to this:

/usr/local/rvm/gems/ruby-2.1.0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': /usr/local/rvm/gems/ruby-2.1.0/gems/vpim-0.695/lib/vpim/vcard.rb:678: invalid multibyte escape: /^\xFE\xFF/ (SyntaxError)

Continue reading →

Posted by Uli Köhler in Allgemein

A simple GFF3 parser in Python

Problem:

You need to parse a GFF3 file containing information about sequence features. You prefer to use a minimal, depedency-free solution instead of importing the GFF3 data into a database right away. However, you need to have a standard-compatible parser

Continue reading →

Posted by Uli Köhler in Bioinformatics, Python