2099-01-01

Curriculum Vitae

I have made a CV so yee guys can get a better view of who I am...
bzr branch lp:~gustav-hartvigsson/+junk/CV
English version here (Updated 2014 04 20)
or Swedish version here (Updated 2014 04 20)

2015-11-19

Papperstranan och det Atlantiska Havet

"Mamma, kolla ett spöke."
-- Femåringen som såg en kvinna i heltäckande slöja.


Fan vad osammanhängande jag kan skriva... Hänger inte ens med själv. ^_^

Europa Överger Sina Ideal

Sverige har endast ansvar för att hjälpa svenska medborgare och de med uppehållstillstånd.

Är de inte medborgare i något EU land så har de inte något att göra här.

Visst vi har en extraordinär situation I Europa och Mellanöstern men det är inte vår skyldighet att hjälpa, men det är nog det mest humana att göra.

Men begår de något brott skall de kastas ut ur EU och bli målade med genetiska markörer så att de inte kan återvånda.

Vi har exempel på våldtäkter på barn på asylboendes som inte rapporteras till polisen utan mörkas av personalen[1]. Sådana här saker måste uppmärksammas.

Och om vi tar en avstickare från Flykting frågan så måste vi nog ta tag i problemen som det multikulturella samhället har skapat. Där vi tillåter de som kommer hit att välja att inte assimileras, där vi ser mellan fingrarna när det gäller den icke acceptabla människosynen som vissa individer har.

Antingen står vi upp för den västliga civilisationen eller så låter vi oss bli överkörda av de som inte delar våra värderingar när det gäller synen på människa liv eller vad som utgör ett samhälle.

Att luta sig tillbaka och tycka bra om oss själva bara för att vi hjälper de som kommer hit och inte hjälpa dem med att komma ur sin egna kulturella bubbla hjälper ingen. Och skapar bara problem framöver.

Vill vi ha ett segregerat samhälle eller ett samhälle som är byggt på rättssäkerhet? Vill vi att den generationen som efterträder oss inte vågar ta tag i problem för att inte de skall råka såra någons känslor. Nej, det tror jag inte. Vi måste stå upp för våra demokratiska ideal till vilket pris som helst. Vi skall inte tro att vi kan vara tillmötesgående till alla, vi måste stå upp för de sekulära idealen som det västerländska civilisationen bygger på! Vi skall inte bry oss om hudfärg, kön, religion, bara om individens välstånd i samhället, trotts vad den regressiva vänstern tycker.

Så... Var var jag? Err... Vad fan? Detta får duga.

Källor:

[1] http://sverigesradio.se/sida/artikel.aspx?programid=106&artikel=6283519

2015-11-14

The Papercrane and the void pointer to nothing

"..."

Giving up SSTS (for now? for ever?)

So I have been working on this project that I called "SSTS" or Super Simple Type System. It is neither a "Type System" or "Simple".

I have been working on this on and off for two-three years. I started it on a whim, I wanted to learn what makes GLib and GObject tick, so I set out with the simple goal of implementing something like GObject but without all the nasty type-tracking and what not. It started out well, with a base object type that I could use to implement other stuff and call methods using the base object's interface.

"This is easy!" I thought to my self, it was easy, cus' it was nothing special. Then I wanted to add something like the GObject's notify system. But for that I needed some sort of map structure... But to implement a Map structure I needed a Dynamic Array and a Linked List...

It is now almost two years since I started faffing about with this, and get lots of help from the guys over at the C Programmers community on G+, and now I had hit a road block. I got double frees... And I just could not figure out what was wrong.

I posted a query to the community page, but got told I needed more tests. At this point I just give up. I am sick of this. Not of the people trying to help, but at my self, I have spent two years on some code that no one will ever care about. And I just do not care enough to write test cases, the code is not written in a "test friendly" way.

Sure, I have learned a lot by the experience but I just see no end in sight for the project. If I were to implement the object notify system I would start with the next thing (Streams), which would require something else(an Event Loop).

At this point I see nothing but an other two years till I would be finished, and I just do not want to care about it any more.

Design and good intentions

I like how I have focused on making the function calls not feel to "C"-y. I wrote wrappers for string functions to return strings, so if feels like something like Java or something. And this philosophy is everywhere. "Make it not feel too much like C."

I did not want any of the internals leaking out like some kind of horror show. I did not want the user to have to deal with checking if a function returns a positive or negative value. That is scuff that the user can be without.

This good intentions makes for code that is harder to test than "normal" C code where you get some error value from a function when it fails. It can not just check "is this negative" over and over again and see it go through. No to test these things I have to go through and write complex tests for edge cases that I never thought of when writing it.

I just no not want to deal with that.

I give up... I have had enough of my ineptitude.

2015-09-13

The Paper Crane and the Endless Struggles of a Man in a System of Endless Struggle.

"So what you are saying is that the sky will not fall?"

ForEach in C

In C we do not have iterators in any sane fashion (C++'s iterators are not sane either, btw �� ) nor do we have a standard array_for_each (how would that even work?). So when implementing a C data structure that may need for_each capabilities it is best to do it. Relying on for loops can be problematic if you are not careful.

In these example I will use a DynamicArray as the data structure. With functions to get items at an index and the length of the array. When it comes to LinkedLists you must use linked_list_next, linked_list_prev and linked_list_get_current, but that is outside this discussion.

First things firts: typedef:ing a standard ForEach function pointer

The signature for a good for each function in any implementation is as follows:


typedef void (ForEachFunc *)(void * self, void * item, void * user_data);

The self here should be a pointer to the data structure you are doing the for each on. No operations should de done on this structure.

The item is the current item, the item that the for each function should operate.

The user_data is any user data you can think of. It may be used as a out value or as some other data that is used inside the for each function.

Implementing dynamic_array_for_each

In this example I will not rely on any internals of the data structure, instead I will use dynamic_array_get() and dynamic_array_len() this means that you can implement this even if you do not have accesses to the underlying structure.

To begin with you must understand that this relies on a for loop, so it is not more efficient that just writing a for loop your self. It just provides a little bit safer way of coding, where you do not have to keep track of variables to much.

The signature of the function is as follows:

void
dynamic_array_for_each (DynamicArray * self, ForEachFunc func, void * user_data) {}

The self here is the dynamic array to perform the for-each function on.

The func here is the function that we are to execute on each iteration.

The user_data is the data to passed to the function. This may be used as an "output" of sorts.

void
dynamic_array_for_each (DynamicArray * self, ForEachFunc func, void * user_data) {
  // First me get the length of the array, This should be the last item in the array.
  size_t len = dynamic_array_len (self);
  for (size_t i = 0; i <= len; i++) {
    // Check if the item is there.
    void * item = dynamic_array_get (self, i);
    if (item) {
      func (self, item, user_data);
    }
  }
}

And that is it, folks!

Using it

So now it is now time to use the this for-each thingy. So lets define a function to use in the for-each.

void
for_each_print (SDynamicArray * self, int item, int * itt) {
  fprintf (stdout, "The number is: %d on iteration: %d\n", item, (*itt));
  (*itt)++;
}

This function prints the number stored in the array and prints it out. as user data it takes a pointer to an int, this is that is incremented each time the function is called.

Lets now put this into a context:

int
main (int argc, char ** argv, char ** argp) {
  /* create the array */
  DynamicArray * arr = dynamic_array ();
  /* ... Code to fill the array with numbers. */
  int itt = 0;
  dynamic_array_for_each (arr, (ForEachFunc)for_each_print, &itt);
  fprintf (stdout, "The last itt number is: %d", itt);
  /* ... Code to free the array and what not ... */
}

As you can see it is not too much work to implement or use.

Conclusion, or something.

So as we have seen it is not magic, it is actually easy to use, and it promotes code-re-use. One downside of this is that it does a lot of calls, and thus uses the call stack, this might be problematic if you you already are hitting the maximum call stack size.

But I firmly believe that this is the best way of doing things like this.

2014-02-22

The paper crane and the pile of video tape

"I am sorry, future self."
-- A comment in some code

Help Pitivi!



Click here to get to the fundraiser.

2013-10-21

The Paper Crane and the Fragile Crystals

"What is love? baby don't hurt me, don't hurt me, no more"
-- Haddaway

On love and the low birthrates

Reference to this post: https://plus.google.com/u/0/100647702320088380533/posts/4f1DuFuVfoz

After reading that I the article above I started to think about what the people in the article above actually thought about long term relationships. This is my POW on love and sex.

If you ask me, I would rather have a long-term relationship than a one-sight-stand with some stranger. I do like to feel that I am loved rather than something shallow, untrue (as a one-night-stand is).

I do not want children though (for reasons that I am not going to discuss here).

Back to the article!

They say that long-term relationships are "Too troublesome" , but I think that this is just an excuse. They rely do want a relationship, it is just that they are afraid of loosing what they have.


It might be by Gaijin-white mindset but the statement that Kishino made seems weird: "I don't earn a huge salary to go on dates and I don't want the responsibility of a woman hoping it might lead to marriage."

I do not think that I have ever heard of anyone here engaging in a relationship because they think they will marry there partner. That is not to say that they will not get married, though.

And this might be due to my cheap-asrsery but if you are in a relationship with someone who loves you, why does the male have to present dough as a token of offering to the female?

Cheeses! I thought that you loved each other! NO! It seems that you are her sugar-daddy now!

Of course I would present gifts to my girl, but I hope that she would not expect me to do so. After all, is she after love or my coin? I want to live in a equal relationship, where we see each other as equals who loves each other, not as a master/slave or provider/user relationship.

It might just be that I have a strange world-view, and that the ideal girl does not exist. Perhaps girl only like dough, and that one-night-stands is what girl rely looking for... What do I know? I am single, have not had a relationship with a girl for many years.

2013-09-06

The Paper Crane and The Heavy Objects That Fell

"It is just like inventing the wheel, it has already been done!"
-- Someone...

Introducing SSTS -- The (Super) Simple Type System

So a few days ago I started thinking about GLib and GObject and wondered how easy -- or hard -- it would be to create my own base object system. So the first thing that every good hacker does when faced with such a question is to do it, from scratch, without looking at others code.

So after a few hours I had written my base object type with every function that I would ever need. Than the next day I wrote the first object derived from this base object. (Still not even compiled the code). On the third day I started writing tests and ironed out some compile errors, and than I wrote more tests (this time with the derived object type) and tested everything with valgrind and ironed out every memory leak I could find.

Than, I decided to write a new type, a Map... This is where I found out that all the plane sailing that I have had took an abrupt end, and I was faced with a non-trivial problem:

How do I discern a object that is of the type system from an object that is not? I need to be be able to call the objects destructor if it is, and ordinary free () if it was not.

This lead me -- after some non-help from G+ -- to dig though GLib/GObject C code only to find out that the problem is non-trivial. In GLib/GObject it seems that they use a lookup table to find out if an object is or is not of the type GObject.

Action plan:

There is two ways I could do this:

  • The sane and hard way -- basically reimplementing what GLib/GObject does.
  • The easy but mad way -- just ask the user for a destruction method/function as a parameter.

The first way would be the hardest to implement, and probably course trouble if I were to use GObjects somewhere. But if I do it that way the user of the library would have less work to do.

If I do it the second way it would mean less work, but the end user would probably not be so pleased to have to specify the destruction method for each map. I may even have to have the user specify it for every item in the map.

If I go with Plan A (The Sane, but hard way) it also solves other inheritance related issues: How to know, in large object hierarchies, what object is what type.

The lookup table would contain pointers to every object that is registered with the system (at run-time), during the registration of the object the object must tell the system what types it is (what objects it has inherited from).

The look-up list would have to have two fields per item: a key (the pointer to the object) and a value that is a list of object-types that the object is.

Any way: for those that are interested in this (Super) Simple Type System it can be found on launchpad.