LaTeX Tabular Column with specific font type


You want to use a custom column type for your LaTeX tabular that has a specific font attribute (we’ll use the font family for this example).

Continue reading →

Posted by Uli Köhler in LaTeX

How to include Java sources in Maven JAR


You’re using Maven as build system but you need to include your Java sources into your JAR file generated by mvn package.

Continue reading →

Posted by Uli Köhler in Java

Check Scanner number input boundary in Java

In many cases if you want to create an interactive command line interface, you need to check if a number entered by the user is valid and – if it isn’t – you want the user to re-input it.

Here’s a simple static method to check if a number typed by a user is within a given boundary:

 * Lets the user input an integer value until it satisfies the given
 * conditions
 * @param msg The prompt to ask the user for the value.
 * @param lower The lower boundary, inclusive
 * @param upper The upper boundary, inclusive
private static int guardedInput(String msg, int lower, int upper) {
    Scanner scanner = new Scanner(;
    while (true) {
        int val = -1;
        try {
        val = scanner.nextInt();
        } catch (InputMismatchException ex) {
        System.out.println("Illegal value: Please type a number!");
        if (val < lower) {
        System.out.println("Illegal value: Must be greater than " + (lower - 1));
        } else if (val > upper) {
        System.out.println("Illegal value: Must be smaller than " + (upper + 1));
        } else {
        return val;


Posted by Uli Köhler in Java

How to fix npm “Cannot find module ‘graceful-fs'” error


When running any npm command, you get a stacktrace similar to the following:

Error: Cannot find module 'graceful-fs'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/usr/share/npm/lib/utils/ini.js:32:10)
   at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)

Continue reading →

Posted by Uli Köhler in NodeJS

How to fix node-waf “ImportError: No module named Scripting” on Linux


When executing node-waf, you get the following error message:

Traceback (most recent call last):
File "/usr/local/bin/node-waf", line 14, in <module>
import Scripting
ImportError: No module named Scripting

This also prevents node modules with native components to be built.

Continue reading →

Posted by Uli Köhler in NodeJS

How to program Nexys3 FPGA board on Linux using Digilent Adept software: A guide for beginners

Instead of having to buy expensive JTAG adapters like the Xilinx Platform Cable USB, Digilent FPGA boards like the Nexys3 support programming by using the Adept protocol being translation into JTAG internally. The Adept software is pretty easy to use if you know the basics of how to use the executables.

This is a beginner’s tutorial, so if you already have some experience with FPGAs, you might want to skip some parts. Still you need to have some knowledge about how to use the shell.


  • You got a .bit file compiled for your specific FPGA model. To generate this from VHDL or Verilog code, you should use the Xilinx ISE (WebPack is free, but you need to register!) – if you use third-party software the calls to the Xilinx Toolchain may also be encapsulated in a Makefile or similar.
  • You got your Nexys3 plugged into your computer using a standard micro-USB cable. Note that there are two micro USB ports on the Nexys3 board: One labeled UART and one labeled USB PROG. You need to insert the USB cable into the port labeled  USB PROG
  • The Nexys3 is turned on: You can turn it on and off using the switch adjacent to the USB PROG port. If the board is turned on, a red light will appear. Actually the switch doesn’t turn the board off but sets it to receive power from the 5.5×2.1mm barrel adapter adjacent to the switch.

Continue reading →

Posted by Uli Köhler in FPGA

C++11 : Iterate over smart pointers using foreach loop


In C++11 you want to iterate over a smart pointer (auto_ptr, shared_ptr, …). collection, say a std::vector, using the new for loop syntax.

Let’s try it out:

using namespace std;
shared_ptr<vector<int> > smartptr(/* A ptr to your vector */);
for(int s : smartptr) {
    /* do something useful */

When trying to compile this code, GCC emits the following error message (other lines are omitted for the sake of simplicity)

error: no matching function for call to 'begin(std::shared_ptr<std::vector<int> >&)'
error: no matching function for call to 'end(std::shared_ptr<std::vector<int> >&)'

or, when LANG=de is set:

Fehler: keine passende Funktion für Aufruf von »begin(std::shared_ptr<std::vector<int> >&)«
Fehler: keine passende Funktion für Aufruf von »end(std::shared_ptr<std::vector<int> >&)«

Continue reading →

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

Automatically format size string in Node.js


In NodeJS, you got a size of a file in bytes, but you want to format it for better readability.
For example, if your size is 10000 bytes, you want to print 10 kilobytes, but if it is 1200000, you want to print 1.20 Megabytes.

Continue reading →

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

How to get filesize in Node.js

To determine the size of a file in NodeJS (e.g. to get the size of myfile.txt) use fs.stat() or fs.statSync() like this:

const fs = require("fs"); //Load the filesystem module
const stats = fs.statSync("myfile.txt");
const fileSizeInBytes = stats.size;
//Convert the file size to megabytes (optional)
const fileSizeInMegabytes = fileSizeInBytes / 1000000.0;

Another option is to use the following function:

function getFilesizeInBytes(filename) {
    const stats = fs.statSync(filename);
    const fileSizeInBytes = stats.size;
    return fileSizeInBytes;


Posted by Uli Köhler in NodeJS
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPTPrivacy &amp; Cookies Policy