Allgemein

How to use BIOS instead of UEFI firmware for a VMWare virtual machine

Recent versions of VMWare’s VMPlayer use UEFI firmwares by default if you select a UEFI-compatible operating system during VM creation.
There are some cases, however, in which you have to change the VM to a classical BIOS firmware afterwards, for example if you have your operating system installed without UEFI support or if you selected the wrong operating system.

Currently, it seems to be impossible do change the firmware setting in the GUI, therefore you first have to find the .vmx file corresponding to the virtual machine. Usually it is located at ~/vmware/<Name of VM>/<Name of VM>.vmx.

After stopping the VM , open that file in your favourite text editor and look for this line:

firmware = "efi"

Change it to

firmware = "bios"

After that, save the file, restart VMPlayer and start your VM.

Posted by Uli Köhler in Allgemein

Downloading & reading a ZIP file in memory using Python

Problem:

You want to retrieve a ZIP file by downloading it from an URL in Python, but you don’t want to store it in a temporary file and extract it later but instead directly extract its contents in memory.

Solution:

In Python3 can use io.BytesIO together with zipfile (both are present in the standard library) to read it in memory.
The following example function provides a ready-to-use generator based approach on iterating over the files in the ZIP:

import requests
import io
import zipfile

def download_extract_zip(url):
    """
    Download a ZIP file and extract its contents in memory
    yields (filename, file-like object) pairs
    """
    response = requests.get(url)
    with zipfile.ZipFile(io.BytesIO(response.content)) as thezip:
        for zipinfo in thezip.infolist():
            with thezip.open(zipinfo) as thefile:
                yield zipinfo.filename, thefile

 

Posted by Uli Köhler in Allgemein

Fixing VTiger “Illegal request” for links from other domains

Problem:

You’ve got a link to your VTiger installation from another domain, but any time you open it, you get an Illegal request error message, even though you are logged in correctly.

Solution:

The reason for this error message is that vtiger validates the Referer (i.e. source URL of the request) as a protection layer against certain security issues, for example CSRF (cross-site request forgery). We will disable the referer check. Be sure to understand the implications before you do as suggested.

Disabling involves only editing a single code line. I tested this with VTiger 6.5.0, but likely only minor adjustments have to be made for other versions.

Steps to fix:

  • Open <your vtiger directory>/includes/http/Request.php in a text editor
  • In the editor. search for Illegal request. You will see a code block like this:
protected function validateReferer() {
$user=  vglobal('current_user');
        // Referer check if present - to over come 
        if (isset($_SERVER['HTTP_REFERER']) && $user) {//Check for user post authentication.
                global $site_URL;
                if ((stripos($_SERVER['HTTP_REFERER'], $site_URL) !== 0) && ($this->get('module') != 'Install')) {
                        throw new Exception('Illegal request');
                }
        }
        return true;
}
 
  • Comment out throw new Exception('Illegal request'); with // (results in //throw new Exception('Illegal request');)
  • The code block should now look like this:
protected function validateReferer() {
$user=  vglobal('current_user');
        // Referer check if present - to over come 
        if (isset($_SERVER['HTTP_REFERER']) && $user) {//Check for user post authentication.
                global $site_URL;
                if ((stripos($_SERVER['HTTP_REFERER'], $site_URL) !== 0) && ($this->get('module') != 'Install')) {
                        //throw new Exception('Illegal request');
                }
        }
        return true;
}
 
  • Save the file
  • The fix should be in effect immediately, else restart your webserver.
Posted by Uli Köhler in Allgemein

Script user input

Problem

You want to remote control a program but unfortunately this program has only a “klick&gaudy”(*) interface.
(*) Okok – only has a graphical user interface (short GUI).

Solution

You may use xdotool in order to script user actions. To install this tool, use:

sudo apt-get install xdotool

Now you can get the position of the mouse pointer with:

xdotool getmouselocation

or set it via:

xdotool mousemove 400 300 (This means set the mouse to position x=400, y=300; Point of origin is the top left corner of the screen.)

In order to click use:

xdotool click 1

And in order to type a text (e.g. into a control field of the GUI)

xdotool type 'Hello World'

(P.S.: xdotool has much more options … Once this tool got installed type man xdotool in order to see them all.)

Posted by Yann Spöri in Allgemein

Play a sound in a Webbrowser

Problem:

You want to play some sounds in a webbrowser.

Solution:

Modern Browsers have a fancy integrated AudioContext that allows you to play sounds. Here is an example (JavaScript Code):

// get the AudioContext
window.AudioContext = window.AudioContext || window.webkitAudioContext;

// Initialize audio context
var context = new AudioContext();

// Create an oscillator ... via this oscillator we can then play different sounds
var oscillator = context.createOscillator();
oscillator.frequency.value = 440; // this is an "A"
oscillator.type = "square";

// attach the oscillator to the sound output
oscillator.connect(context.destination);

oscillator.start(0); // start the oscillator (0=now) ...
oscillator.stop(1);  // stop playing this sound after 1 second
Posted by Yann Spöri in Allgemein

Graph layouting via Graphviz

Problem:

You want to display a Graph.

Solution:

Create a simple text file describing your graph and save it with a .dot file extension:

graph {
node1 -- node2;
node2 -- node3;
node3 -- node4;
node4 -- node1;
}

Afterwards you can use a program of the graphviz package (sudo apt-get install graphviz) in order to visualize the graph. This package contains different layouting programs like dot, neato, fdp (all from the GraphViz project) etc. Simply call one of these programs in order to visualize the graph:

neato -Tsvg yourFile.dot -o outputFile.svg

Output from this command:

Posted by Yann Spöri in Allgemein

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

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

Mapping STRING aliases to UniProt IDs

In a recent project, I needed to compare STRING records to other PPI databases. However, this is not always as easy as it sounds, because STRING uses KEGG protein identifiers. Fortunately, at the STRING download page, a list of alias mappings is freely downloadable.

There’s still one major problem left, though: I couldn’t find any documentation about the format. It seems to be somewhat easy once you’ve figured out the basics, but I created a reusable Python function that filters a given organism and outputs a STRING ID, UniProt ID CSV:

Continue reading →

Posted by Uli Köhler in Allgemein

Filtering STRING PPI dumps by taxonomy

Recently I needed to filter a STRING protein-view database dump (e.g. protein.links.full.v9.05.txt.gz) by taxonomy ID. The original dataset was way too large (it had more than 670 million records).

In order to filter with constant memory (After all, the full STRING dump is 47GB large), I created this script that allows to filter for binary PPIs both matching the given organism (NCBI taxonomy ID), but also allows to filter for binary PPIs with at least one interacting protein of the given organism. Usually this doesn’t really make a difference for STRING.

Continue reading →

Posted by Uli Köhler in Allgemein

Bash: TCP/Internet connection handling

There’re many problems nowadays, which could easier be solved through the internet. In this post I descripe how to address these problems by bash alone.

The standard way to connect to a server in the internet, is to embed the connection stream

exec 3<>/dev/tcp/$server/$ircPort || echo "Some text or doing, if connecting failed"

Continue reading →

Posted by Yann Spöri in Allgemein

Installing Konsole Solarized Theme

Problem:

You’re using the KDE4 Konsole and you want to install the Solarized color scheme plugin. However, you are way too lazy to figure out how to do that manually.

Continue reading →

Posted by Uli Köhler in Allgemein

gtf2gff.py: A replacement for gtf2gff.pl

Recently we had to work with the gtf2gff.pl tool to convert CONTRAST and TwinScan GTF output to the GFF format which can be read by many annotation tools.

Working with that script was really hard, it did not report errors at all, plus it is not programmatically reusable at all. There are different versions of the perl script on the internet, but what we needed was a standardized, short, readable version that does proper command line parsing using a standard tool like argparse and a conversion function that is usable from other scripts.

Continue reading →

Posted by Uli Köhler in Allgemein

Java FX: How to set the column constraint property using FXML

Problem:

You have a Java FXML file document with a TableView and want to set the columnResizePolicy of this TableView in the fxml document.

Continue reading →

Posted by Yann Spöri in Allgemein

Building LevelDB Debian (.deb) packages

Problem:

You intend to install LevelDB, but you don’t want to manually install & compile it as described here.

Instead, you just want to use the debian packaging system and some reproducible method of creating a DEB package from LevelDB.

Reasons for preferring not to compile & install manually could be:

  • You want to deploy LevelDB to one ore more environments that don’t have a complete build environment
  • You prefer a clean install-uninstall-purge package lifetime management
  • You need a reproducible process to deploy LevelDB

Continue reading →

Posted by Uli Köhler in Allgemein

ffmpeg / avconv : List supported codecs

You can list all codecs supported by libavconv (the library used by ffmpeg / avconv) by using this command:

ffmpeg -codecs

If you don’t have the ffmpeg executable simply use

avconv -codecs

Note that avconv and ffmpeg are essentially the same, but the projects split at some time and then re-merged. Starting from Ubuntu 15.04, ffmpeg is available in the repositories again, whereas previously, ffmpeg was replaced by avconv.

For details, see this StackOverflow thread and this detailed post about the ffmpeg/libav situation.

Posted by Uli Köhler in Allgemein