Thursday, August 9, 2012

Brain Hacking with Caffeine

A few weeks ago I went to a meetup for coders and someone there said that caffeine actually programs your brain. Curious to know what he meant, I did some refreshing on my brain knowledge and came up with the following suggestion:

In your brain is are chemicals called neurotransmitters. These are transferred between the cells (called neurons) of your brain to communicate messages. There are two key neurotransmitters that caffeine affects. The first of these is called dopamine. Dopamine is released into your brain to communicate the feeling of pleasure and it is needed for motor functions. Essentially, it reinforces us to continue doing whatever we are doing. When dopamine is released, it floats around in the space between neurons (called synapses) until it locks into dopamine receptors of neurons. When this chemical latches to a receptor, we get a nice happy feeling.




When all of the dopamine receptors have been filled, enzymes are released to clean up the remaining dopamine that's floating around. After all, a healthy brain is a tidy one! Caffeine slows down this process so the extra dopamine hangs around longer. During that extra time the dopamine floats around, you feel more uplifted. However, when there is too much dopamine hanging about, you end up with uncontrollable movements which could explain the jittering people do when they're high on caffeine. Since dopamine levels control muscle movement, higher dopamine can also lead to a higher pulse.

The other neurotransmitter affected by caffeine is adenosine. This neat little brain chemical is responsible for helping us sleep. When adeonsine is released into the brain, it binds to adenosine receptors, much like dopamine. When this neurotransmitter finds a neuron slot to bind to, it makes us feel drowsy by slowing that neuron's activity. It just so happens that caffeine looks like adenosine to the brain, so it takes adenosine's seat in the neuron by binding to its receptor instead. Caffeine doesn't slow down the neuron so the effects of the sleep-inducing adenosine are staved off - if only temporarily.

So you can see where one might get the idea that caffeine programs your brain. Personally, I'd call it hacking.

Tuesday, July 24, 2012

Integer Intrigue



Today I ran into a problem when trying to run an SQL insertion query into a table that had columns like the following:

database.customer:

cu_id: int(11)
cu_otherID: int(11)
cu_name: varchar(255)
...

Some insertions would work and others did not even though the data was coming from the same source. I managed to narrow the problem down to the cu_otherID field. I noticed that in a successful query, the value was inserted as-is (for example, the value 1005423522) but in an unsuccessful query the value inserted was not the same as the value from the source data (for example, the value 5442231112). For some reason, the cu_otherID for the unsuccessful queries was always 2147483647.

You see, the thing about integers is that they take up space in memory; 32 bits in this case. The first bit is known as the sign bit, which determines if the value is positive or negative. When the sign bit comes into play, the integer is known as a signed integer and has a maximum value of 2147483647. When the sign bit is not used, the integer is called an unsigned integer and the maximum value of a 32 bit unsigned integer is 4294967295.

Here's an illustration of a 32-bit integer in memory:


So, back to the issue. It's obvious now that the insertion is putting in the maximum int value for the cu_otherID because the value from the source data is above the max. Making the int unsigned would give a higher threshold, but it still doesn't cut it for many of the values. In this case, I defaulted to changing the cu_otherID field into varchar like so:

ALTER TABLE customer MODIFY cu_otherID varchar(255);

Now the values in the cu_otherID column can be strings of up to 255 characters. No worries about limits there!


Tuesday, July 17, 2012

Untrusted Time


You've no doubt come across a page like the one above. I did when I recently plugged my desktop back in to get it running for my wife. Normally, I'm able to jump around the web in Firefox as soon as the desktop picks up on an internet connection. However, no matter where I went, this page popped up. I checked Windows Firewall and didn't see the websites being blocked. I checked AVG and saw that it still had the typical settings. So what was up?

After an amount of time that's too embarrassing to note here. I decided to stop being lazy and change the system clock to the current time. To my surprise, the officer in the yellow box left me alone immediately. Who knew he just wanted to be on time?