Newer Posts Older Posts

The Dip

2015-07-01

 

The Dip

The Dip by Seth Godin is an interesting small book about quitting. At least that is how Seth Godin describes it and purposely undersells the depth of message.

By quitting he means, quitting the fruitless undertakings, quitting the hopeless quests before ever embanking on them and not quitting the worthwhile endeavours, even when it currently hurts.

The Dip is a really short book and worth the read. Seth Godin writes in his simple, yet though provoking way. I enjoyed reading it and thinking about it. It shows you that you need to pick your fights and persevere.

read more

Artificial Intelligence and The Travelling Salesman

2015-06-24

 

HAL 9000

The near future holds many interesting development, some of which we don't comprehend yet. But a general artificial intelligence or super artificial intelligence won't be part of it.

The notion of the singularity is not new. But recently I have seen more and more articles discussing artificial intelligence. These either spell the doom of humanity or it's salvation. The problem is that a real artificial intelligence is very hard to realize and I will try to explore how hard it is.

read more

Building your own Hash Router

2015-06-21

 

For fedz.me I recently wrote a simple hash router. Initially I wrote fedz.me with only jquery and swig. It worked, but hash routing was slightly hacky. So I decided to write a proper hash router.

Usage

To use the router you instantiate it and set routes. Here I have 4 distinct routes, the tags route (#!tags), the single post route (#>123), the tag filter route (#yolo) and default fallback route. You can defined the route patterns either as sting or regular expression.

var router = new Router();

router.route('#!tags', showTags);

router.route(/#>([0-9]+)/, function (hash) {     
  showPost(hash.substr(2));
});

router.route(/#([a-zA-Z0-9]+)/, showPosts);

router.fallback = showPosts;       

If you want to track hash changes you can hook the onnavigate event. Here I use Google Analythics to track the navigations.

router.onnavigate = function (hash) {
  var title = hash ? hash : 'fedz.me';
  ga('send', 'pageview', {
    'page': '/' + hash,
    'title': title 
  });
}

If the page is loaded with a hash and need the navigation code to be executed, you should to call the navigate function when the document is ready.

router.navigate(location.hash);

read more

Legal Perils of Fan Art

2015-05-24

 

After reading yet an other misinformed opinion on the legal status of fan art, I want to clear up the station a bit.

If you are creating fan art, you are violating up to three areas of the law. These are copyright law, trademark law and personality rights.

read more

Three.js: Resize and Canvas

2015-04-19

 

As promised, resizing and attaching to a custom canvas in Three.js.

We will start with code from the getting started post and simply add event handlers for resizing the window:

window.addEventListener('resize', function () {
  renderer.setSize(window.innerWidth, window.innerHeight);
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
});

Calling the setSize function on the renderer will resize the underlying canvas. Since the canvas is fullscreen, here we simply use the window's client area. The camera also need to be notified of the changed aspect ratio. This is important or everything looks squashed. Since the camera can not detect that one of it's properties changed, we need to call updateProjectionMatrix function.

Here is how it looks and here is the code.

read more

Getting Started with Three.js

2015-04-12

 

I think WebGL is an awesome idea; you can use accelerated 3D graphics within a browser. This is totally game changing and opens the gate to games serves directly to your browser.

Working with OpenGL primitives is somewhat annoying. (One of the reason why I build wrappers for C++.) But for javascript there are already quite usable libraries, one of these is Three.js. Today I will show the relative easy with which you can start to use WebGL. (Easy to learn hard to master.)

I will show you how implement the following:



full screen

read more

Agile Spices for Classical Process

2015-03-08

 

In this day and age every programmer and his dog know that well implemented agile processes are more efficient and create an environment where you actually want to work. Unfortunately many organisations are not ready to implement agile processes. This resistance unfortunately is somewhat well founded, when you need to comply with regulations, it is really hard to explain how traceability is implemented when all you have to document your requirements are index cards. Although it is possible to implement traceability in an agile process, such as Scrum, that even the FDA will approve of, getting the upper rungs of management to agree, can be an impossible task.

But not all hope is lost, there are a few things you can take from the agile play book and seamlessly integrate into a classical model, like waterfall or the V-model.

read more

Compose (Variadic Template Function)

2015-02-06

 

I have used a string composition function for quite some while. It is a reimplemented and simpler version of the String Composition Library.

std::cout << compose("Wrote %0 objects into %1.", objects.size(), filename) << std::endl;

"Wrote 548 objects into level1.jsn."

The problem with C++'s stream library is that is almost impossible to localize strings with the stream insertion operators. The core of the problem is that they chop up the sentence into fragments, such as:

std::cout << "Wrote " << objects.size() << " objects into " << filename << ":" << std::endl;

When you use something like gettext the strings that may be translated are:

"Wrote "
" objects into "
"."

Not only is it really difficult for translators to understand what is meant (they see the strings within hundred others), but it also does not allow them to reorder the sentence, as it may be necessary. For example in German I would reorder to to be:

"%0 Objekte wurden in %1."

So it makes sense to keep the string together. This is one of the reason why the printf family of functions still is so popular when it comes to localisation.

read more

Worker Pool

2015-01-26

 

I have recently been asked to write a worker pool and that is what I did. The goal is to have a thread pool, that you can throw at arbitrary functions and they will be executed as resources allow.

The worker pool has the following interface:

class WorkPool
{
public:

    WorkPool(unsigned int concurency = std::thread::hardware_concurrency());

    ~WorkPool();

    template <typename Res, typename ... Args, typename Fun>
    std::future<Res> enqueue(Fun func, Args... args);  

private:
    // ...
};

To use the worker pool you would use the following code:

WorkPool pool;

addrinfo* google_com  = nullptr;

std::future<int> fgcom = pool.enqueue<int, PCSTR, PCSTR, const ADDRINFOA*, PADDRINFOA*>(getaddrinfo, "google.com", NULL, NULL, &google_com);

if (fgcom.get() == 0)
{        
    // do something with the result
}
else
{
    // print error message
}

See the full example code.

But you can enqueue anything function like into the work pool; basically anything that goes into a std::packaged_task. Like with std::async, it is important to capture the future, even if it is void. The problem is that the call will hang at enqueue until the function finishes, which renders the entire concept of a worker pool moot.

read more

User Stories are Half the Story

2015-01-21

 

There are many ways in which you can capture requirements. The current "en vogue" method is to writ down user stories on index cards and stick them on a white board. A structured approach to requirements is key if you want to ever finish your project, unfortunately user stories fail to capture all aspects that define a piece of software.

The first and obvious contender to missed requirements are the non functional requirements. Non functional requirements are the ephemeral requirements that encompass maintainability usability, performance and memory footprint. Many methodologies try to skirt the issue by defining "quality metrics" or "common values". The idea here is, that by creating the cleanest and optimal code you actually implement the non functional requirements because the code is is such an awesome state. The problem is that the optimal solution solution for ten elements is not the optimal solution for one million elements.

read more

Newer Posts Older Posts