sábado, 13 de octubre de 2018

Haskell: some notes about strictness

The exclamation mark is a strictness declaration: "it means that it must be evaluated to what's called "weak normal head form" when the data structure value is created" (see https://stackoverflow.com/a/993326/328616)

On Weak Head Normal Form: check this amazing post https://stackoverflow.com/a/6889335/328616.

domingo, 27 de enero de 2013

Awesome explanation of how Android ListView works

Ever run into the problem of adding checkboxes to a ListView and trying to check/uncheck the checkbox assuming that its state was stored in the checkbox itself?

It turns out that Android maintains a pool of views (in the "recycler") and reuses those views when we scroll the list until new items are seen. These new items are actually the old ones with their values set to those of the new ones, so never save state in the views held by a ListView! Save them in the adapter instead, for example.

Assume you have this code in an Adapter (and assume that creating checkbox like this works...):

public View getView(int position, View convertView, ViewGroup parent) {
    CheckBox checkBox;

    if  (convertView == null) {
       checkBox = new CheckBox(mContext);

       checkBox.setOnClickListener(new OnClickListener() {
          void onClick(View v) {
              CheckBox checkBox = (CheckBox) v;

              checkBox.toggle(); // NOT GOING TO WORK AS EXPECTED!
          }
       }
    } else {
       checkBox = (CheckBox) convertView;
    }

          

    return checkBox;
}

There's an awesome explanation here:
http://android.amberfog.com/?p=296

viernes, 25 de enero de 2013

Windows always on top (Windows)

I just found this awesome utility called Filebox Extender that allows you to make windows stay on top when they dont' have the focus.

On top of that, it's open source!

martes, 19 de junio de 2012

Understanding the gimbal lock

After reading the gimbal lock sections in several books and watching a few videos, what really made it clear to me was this explanation at gamedev.net by Atash:
think about having two sets of coordinate axis. One set can be considered 'local', as in local to the orientation of what you're rotating. The other set can be considered 'global', as in, the world's natural axis (just for a moment, think of it that way. The world is flat right now >_<)

Now, when you have those two sets of axis, imagine that they are standing up aligned, perfectly without an issue. If you take the local axis, and rotate it around 90 or -90 degrees around it's local y-axis, you'll find now that the x-axis is aligned perfectly with the z-axis. Now, the problem is now that if I continued to rotate the object by euler angles (rotating around the global axis) while the local x-axis are aligned with the z-axis, then when I rotate around the global z-axis, I am in fact rotating around the local x-axis, thus having no influence on which way the local x-axis is pointing! (remember that when you rotate around a certain axis, that axis doesn't move. The contra of that statement is true as well.) Okay, now we have a problem... One of our rotational axis has gone caput! Gimbal Lock has totally screwed us over.
It all makes sense now!

lunes, 4 de junio de 2012

C++ std::min/std::max compilation issues

I just came across this issue today: http://support.microsoft.com/kb/143208

Basically, if you have code like this:

#include "windows.h"

...

int minimum = std::min(a,b);

it's going to blow up in your face.

Notice this at the bottom of that page: "This behavior is by design" . Seriously???

I solved the issue using extra parenthesis to prevent macro expansion thanks to stackoverflow:

int minimum = (std::min)(a,b);

And by the way... "windows.h" redefines lots of other stuff, beware! e.g. try to define the function DeleteFile and see what happens!

domingo, 27 de mayo de 2012

Good explanation of the Levenshtein distance: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic/Edit/

And a good implementation: http://stevehanov.ca/blog/index.php?id=114

domingo, 20 de mayo de 2012

Very good generic game action framework software engineering discussion here:
http://www.gamedev.net/topic/624995-am-i-over-engineering-a-generalized-game-action-framework/page__view__findpost__p__4940963