Newer Posts Older Posts

Four C Constructs That Need To Die

2015-10-19

 

C++'s compatibility to C is the key feature that got it off the ground. It also makes integrating C libraries into C++ astoundingly easy; which again is key, because all the really interesting libraries are written in C. But if you program C++ there are a few constructs that just need to be purged from any code base. Here are four constructs that have no place in proper hight level C++ code.

Linked Lists

Bad Code:

struct FooNode
{
    Foo      value;
    FooNode* next;
};

FooNode* foos = new FooNode;
foos->next = nullptr;

When learning basic algorithms and data structures, the linked list is one of the first construct you learn. The linked list is also the backbone of many containers. The key problem here is, that using it directly is error prone. Unless wrapped in clear access functions, adding and removing items quickly become problematic code. For example, since you are always holding single elements, you never know if you are actually holding the root element and can never be sure if you can just delete the element.

read more

Resize Canvas Update

2015-08-18

 

A while back I made an article about resizing a canvas automatically. Well I made a mistake, the canvas element does not have a resize event; something I completely missed. Here is an update on how to solve the problem.

After searching the internet, I did not find a good solution. The best solution I found was a stackoverflow question, but they also made some mistakes.

So here is my revised solution, that actually works with the canvas:

function onResize(element, callback) {
  var height = element.clientHeight;
  var width  = element.clientWidth;

  return setInterval(function() {
      if (element.clientHeight != height || element.clientWidth != width) {
        height = element.clientHeight;
        width  = element.clientWidth;
        callback();
      }
  }, 500);
}

read more

A Day of Work with Swipes

2015-07-10

 

So I was asked what my routine was? Well I wanted to write this post for a good while now, so here it is.

I am one of the people who consider to do lists harmful. So I start my day thinking about the pig picture things I want to do today. Commonly I do this over a cup of espresso and today I want to clean up the house, since Friday is may "day off" from my day job and continue working on fedz.me, specificity I want to finish porting it to angular.js.

read more

Swipes - the Procrastinator's To Do List

2015-07-09

 

For a while now I have been using Swipes. On the surface it looks like a run of the mill to do list, but there is a small twist to it. The way you "schedule" tasks is ingenious.

I don't need a to do list for the important things. Each morning I sit down and think about the three most important things I need to to today and I do them. Where things get lost along the way are all the small tasks. You know those tasks that are small, not really important, but hurt when not done. Tasks like cancelling a subscription, checking why Amazon is complaining about your IAM policies, you know those many 5 minutes tasks.

read more

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

Newer Posts Older Posts