Pages

Wednesday, February 8, 2012

five from umberto eco 
Schools ought to teach the high art of how to be discriminating.
~~~~~
I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth.
~~~~~
Comedy is the quintessential human reaction to the fear of death.
~~~~~
I always assume that a good book is more intelligent than its author. It can say things that the writer is not aware of. 
~~~~~
If you interact with things in your life, everything is constantly changing. And if nothing changes, you're an idiot.
~~~~~
via form is void

Friday, February 3, 2012

Merging JSON Objects Successfully

If you've been using JavaScript for a while you've probably come across the problem of comparing JSON objects. At first glance it doesn't seem to be very easy since {} !== {} evaluates to true. One solution would be to use JSON.stringify on the objects and you would be able to see equality.

Another problem is doing a merge of objects since $.extend() and $.merge() fall a little short. Merge is used for arrays and will put duplicate objects into the merged array. Extend doesn't do a complete recursive merge merge even with passing the parameter true for deep.

Take a look:

var obj1 = {
    data: [
        {
            id: 1,
            text: "1"
        },
        {
            id: 2,
            text: "2"
        },
        {
            id: 3,
            text: "3"
        }
    ]
};



var obj2 = {
    data: [
        {
            id: 3,
            text: "three"
        },
        {
            id: 4,
            text: "4"
        }
    ]
};

$.extend(true, obj1, obj2) yields:
//Missing {id: 1, text: "1"} and {id: 2, text: "2"}
{
  "data": [
    {
      "id": 3,
      "text": "three"
    },
    {
      "id": 4,
      "text": "4"
    },
    {
      "id": 3,
      "text": "3"
    }
  ]
}

jQuery's extend for the data array seems to be doing a merge based on position instead of comparison with obj1's objects in the same position. The options are slowly dwindling. That's why I made my own recursive function to do a deep merge. You can check out my gist and run mergeDeep(obj1, obj2) to return:

//All the data has been merged properly
{
  "data": [
    {
      "id": 1,
      "text": "1"
    },
    {
      "id": 2,
      "text": "2"
    },
    {
      "id": 3,
      "text": "3"
    },
    {
      "id": 3,
      "text": "three"
    },
    {
      "id": 4,
      "text": "4"
    }
  ]
}

Listen to: Active Child

Do it guys. They're awesome.


Wednesday, February 1, 2012

Donate your marrow!

Hello everyone.

Today I'm urging you to sign up for marrow donation. The process is really easy and what happens is they put you on a marrow registry and they notify you if a match comes up. I did mine a month or so ago. If you are matched you have the opportunity to save a life. Who would turn down saving someone? The medical stuff from what I understand would be paid for by the receiver if that's a concern. Here is where I signed up. They will send you some q-tips to swab the inside of your cheek for a tissue sample and you'll mail them back and be registered.


While you're waiting for your q-tips to arrive check out this video of my good friend Derek Story shreddin' it.


via PostSecret