Compiling & Installing LevelDB on Linux

Update: Please also take a look at this followup article for an automatic compilation script that builds Ubuntu DEB packages!

Problem:

You want to compile and install LevelDB (including development headers) on your Linux computer. ./configure && make && make install does not work so you don’t know how to do this.

or:

You have successfully compiled LevelDB, but make install doesn’t work (there is no official installation procedure yet) and you don’t know how to install it to your system

Continue reading →

Posted by Uli Köhler in Databases

Scalar vs packed operations in SSE

If you look at any SSE instruction table, you might notice that there are two basic types of operations:

  • Packed instructions (the assembly instruction ends with PS)
  • Scalar instructions (the assembly instruction ends with SS)

For most operations, there are two versions, one packed and one scalar.

What’s the difference between them? It’s pretty simple:

  • Scalar operations operate on only one element, for example a single integer.
  • Packed operations operate on any element in the vector in parallel, e.g. they multiply 4 32-bit integers in a single instruction.

SSE gains it performance from using packed operations implementing the SIMD paradigm (using a single instruction, multiple values are processed). However, it is occasionally useful to avoid expensive copying by using scalar operations operation on the SSE registers.

Also see the Original source

Posted by Uli Köhler in Performance

Shell: Strip directory from path

Problem:

In the Linux shell, you have  a file path and you want to strip everything but the filename, for example  you have the path ../images/photo.jpg  and want only photo.jpg

Continue reading →

Posted by Uli Köhler in Shell

Basic Tutorial on Bitfield Arithmetic

This article describes basic operations in manipulating bitfields using boolean operations. Although this article focuses in Java, most programming languages use the same syntax.

What is a Bitfield?

All modern computers use binary arithmetic – that means, the most basic unit of information is a bit – it’s value can either be 0 or 1. On almost all hardware implementations of binary arithmetic, you can’t adress and modify bits directly, but you have to use bytes (= 8 bits). Bitfields are vectors of  bits where each bit expresses a specific piece of information that can either be true or false. Depending on the application the bitfield can occupy more or less space.

Possible applications for bitfields include, but are not limited to Bloom Filters and Game artificial intelligences. In the latter case they are called bitboards if they represent a specific state in a game board.

You might also use words (2 bytes = short in most configurations), double words (4 bytes = int  in most configurations) or quad words (8 bytes = long in most configurations) instead of single bytes for addressing. On 64-bit platforms, double words or quad words are usually most efficient but anything beyond quad words (i.e. 64 bits) needs more than one instruction in the CPU, which usually makes computation inefficient (there are some tricks involving SIMD, but this is beyond the scope of this article).

Continue reading →

Posted by Uli Köhler in Allgemein

Othello in Java: Part 1: Data structures

You’ve got a big problem. Someone forces encourages you to implement a complete Othello UI+AI in Java, but you don’t have any idea how to do that. If you already know how to implement the basics and you are interested in more advanced strategy concepts, you might be interested in the other parts of this series (yet to come).

In this multi-part series I will not provide any complete solution to any of the standard Othello tasks. Instead, I will provide (hopefully) helpful hints how to get your coding going and explain how your code works.

Continue reading →

Posted by Uli Köhler in Java

HackThisSite Programming Challenge 1 Algorithm (Unscrambling)

Recently hackthissite.org was recommended to me — it’s really fun to play around with, even if I think some of the challenges are not that realistic any more.

I thought it would be just as much fun to post some of my solutions to the programming challenges here. If not absolutely neccessary for understanding the underlying algorithm, I won’t post any information about how to use the programs, because the purpose of these posts shall be to understand it, not to use it in order to solve the HTS challenges.

Continue reading →

Posted by Uli Köhler in Algorithms

VNC: Scale VNC window

Problem:

You want to view a VNC on a screen with a different resolution than the screen you’re viewing (e.g. you want to view your Full HD desktop display on your Notebook).

Usually VNC viewers show scroll bars, but in some cases you need to view the entire screen at once.

Continue reading →

Posted by Uli Köhler in Linux

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(System.in);
    while (true) {
        System.out.print(msg);
        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

Problem:

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