Fast Case Converter

Often I find myself needing to convert between upper case to lower case and vice versa. This is a fairly simple thing to do if you understand ASCII encoding. A good reference for the ASCII Table can be found here. As you can see, to convert a letter to lower case you would add 32 to the current value and subtract 32 to convert it from lower to upper. However to implement this it takes a few lines of code to put some conditions in that check to see the current case and decide to add or subtract.

I was looking at the ASCII Table the other day and came up with a simplistic method to swap the case of a given character. That is to exclusively-or the value of the character with 0x20. This will convert the upper case to lower and the lower to upper. Its probably the fastest method to swap ,CPUs can xor in one cycle (excluding memory load time). However you still need some type of conditions to make sure the character is actually a letter and not a number of symbol.

Enjoy!
Read More

A Walk Through the Human Mind

I wrote the following paper for a Philosophy class that I am enrolled in. The paper mostly deals with dualism versus naturalism and focuses on some common arguments for both sides. I do a bit of a critical review of each side and attempt to conclude with my own views.

Whether Dualism or Naturalism is true hangs on more than just general philosophical debate. As would run contrary to the first glance, dualism would make the humans mind off limits to science, while naturalism gives science complete control. Both describe where the soul of a person is contained, but use radically different belief systems to come to their conclusions




The first question that would be asked is what is a soul? Webster gives the following definition: “the immaterial essence, animating principle, or actuating cause of an individual life.” At first glance this seems very well defined. As a human being I notice that I am radically different from any of my animal counterparts, however what exactly is it that makes me so different? On the physical side I obviously look different from any animal, but most animals look different compared to other animals. Also most dualists believe that only humans have souls, thus it cannot be physical traits that set me and the animal world apart. Is it intelligence, language, or reasoning? Well all three can be seen in some form or another in the animal kingdom. It is not so easy to find exactly what it is that makes us human and everything else not human.



To give a partially complete answer of what makes us human it would be in the way humans constantly reevaluate their thoughts and actions. We do more than low level reasoning to solve simple logic problems, we use high level reasoning that allows us to gain knowledge from little to no actual experience. For example, the ability to reason about the existence of a soul is a high-level reasoning problem that no animal is able to do. This seems like a huge leap from the most intelligent, non human animal but it is the next logical step after low level reasoning. While, most low level reasoning requires a single pass through of all of the information at hand to yield a result, high-level reasoning requires multiple passes, taking what we have previously decided to be true and using that as part of our input for the next round of reasoning to gain new meaningful information. So to be human means to have the ability to do high level reasoning and gain knowledge from no experience.



Now that we understand what the soul is, we must examine where the soul is. This is the heart of the debate between dualism and naturalism. In dualism it is believed that the soul is an immaterial object that is physically separate from the brain. Naturalism takes the stance that the soul, commonly referred to as the mind, is simply part of the brain. Which one is correct?



Descartes argues that dualism is the correct answer. He takes his arguments against scepticism and turns them into an argument for dualism. The argument often takes the form: I can imagine that my body does not exist, but I cannot imagine that I myself do not exist therefore I must be entirely distinct from my body. The two premises nearly follow directly from Descartes' own arguments and the arguments of scepticism, however, the conclusion tends to be a bit of jump. Descartes does show that I myself and my body can be two separate things in this argument but he does not show that it is necessarily true. In fact the only way that it be necessarily true would be if the sceptical argument was correct, something that even Descartes has argued against.



It is a bit ironic that Descartes argues for dualism while he argues against scepticism. By forcing the mind to be separate from the body, as it is in dualism, he is creating a world in which nothing has to exist except for the soul. If souls are what make us human than we could simply be brains in a vat, or in the case of dualism, non-physical entities that either simulate a physical world or are actually connected to a physical body. Both cases would make the sceptical arguments virtually true.



Other arguments for dualism turn out to be a bit of a let down as well. Descartes attempts to argue for the connection between the human mind and the soul, but it doesn't appear to be scientifically possible to transfer the information from our physical world to the non-physical world of souls. One could then argue that perhaps souls are part of this physical world and we have not yet found a way to measure their existence. If this were true, it seems scientifically silly to think the soul has to be outside of the brain.



With so many strikes building against arguments for dualism it seems like it cannot be correct. However, no matter how many individual arguments for a topic are proven to false, the topic, itself, could still be true until someone proves that it is not. In order to disprove dualism we must examine dualism itself and see what it implies, and see if these implications fit our model of the world or not.



Modern science believes that humans came from creatures that evolved over a very long period of time here on earth. At some point two creatures that where very human-like mated to give birth to a human child. Now starting with the assumption that evolution is correct, at what point did the soul come about? Well there are two answers: the first is that the souls were there prior to the existence of humans; the second is that they existed upon the creation of the first human child.



The first argument would imply that every creature has a soul. This argument doesn't exactly make sense because we have already defined the soul to be what makes us human. It is possible that we ill-defined the soul, but most modern dualists do not believe that every creature has a soul. This isn't exactly a satisfactory reason to discredit the argument. The idea of the soul is generally believed to stem from religion. Which says that the soul is what lives on after we have died in this physical world. From this it seems strange to believe that a god would make animals live on after they have died.



This leaves us with the second argument, which is that when the first child was born, a soul was either created or assigned for this first human. What was it that the parents of the first human didn't have but the child did have? From evolution it is known that very subtle changes are the only ones that are made from parents to offspring. So the parents likely had pretty similar DNA and physical traits compared to the first human. It is hard to imagine that such a small change could have such a dramatic change on this world. Again, however, this isn't exactly a fulfilling proof that the soul couldn't have been attached at the first birth. Let's assume that the first human did get a soul when it was created. How did this child mate to create new humans? Well, other non-human creatures could have created human offspring which had the exact same change from the non-humans that allowed the soul to be attached. These offspring would need to have been created fairly close together so that they could eventually meet and mate. This seems very unlikely, as the probability of this happening is very low. Another option is that the first human mated with other non-humans and again created a human. This seems to take away what makes a human special, the human offspring could be more like its non-human parent than its human one. Why would a soul attach to a slightly human creature and not other non-human creatures? The final option is that the first human had a sibling of the opposite sex who was also born with the unique set of traits that made it human. Then the siblings mated to create more humans. This seems unlikely because the only universal law of humanity is that siblings should not mate. That rule appears in every culture in some form or another. Why would the first generation of human violate what appears to be an inherent law of human nature?



Thus it appears that the dualist argument has been defeated given that evolution is true. It would be nice if we could get rid of the condition of evolution being true. There are arguments that attempt to do just that, but they tend to involve a lot of other assumptions and are not completely satisfactory proofs.



Let's now turn our attention to that of naturalism. It seems natural to feel that you exist separate from your body. This part that we feel is separate we generally call the mind. The brain is not the same as the mind, but rather the physical vehicle for our mind. We can consider our brain as a black box; by this we mean that lots of input goes into our brain and a lot of output comes out of our brain. Our brain cannot directly interact with the world around it, all it can do is use the inputs from our senses to gather information and use our body to express information. Using this view of the brain it is natural to see where the mind comes from. The mind is an emergent property of our brain attempting to exist outside of itself. The brain must place itself outside of our bodies to be able to interact with the world around us. Thus our mind is created to be that imaginary thing outside our body.



So it appears that our belief in dualism is a natural side effect of the way our brain attempts to make sense of the input it receives in order to interact with the world. It is important to remember that disproving dualism does not disprove religion or cheapen the value of a human life. Religion sits in a different domain than science it answers what happens after this life, while science answers how this life works.


Read More

MySQL and Java common problem

Have you ever received the following error while using Java and MySQL:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1

This is a common error when you first set up Java and MySQL to work together. To correct it simply add the following lines of code to your my.cnf in the section [mysqld]
collation_server=utf8_general_ci
character_set_server=utf8
Read More

Self Replicating Code

For a class recently the teacher challenged us to write a code snip-bit that would be self replicating. By that I mean write a program that when executed would write out its own source code. This is a bit harder than you'd initially think it to be. My first attempt tried to store the source code within the program when execute it would output what was stored within. However this creates a chick and egg problem. The source code contains the source code. Something that at first stumped me. Then I remembered Stringification in the C preprocessor and I came up with this:

#include "stdio.h"
#define M(Code) main(){FILE* fp = fopen("source.c", "w");fprintf(fp,"#include \"stdio.h\"\n#define M(Code) %s\nM(%s)\n",#Code,#Code);fclose(fp);}
M(main(){FILE* fp = fopen("source.c", "w");fprintf(fp,"#include \"stdio.h\"\n#define M(Code) %s\nM(%s)\n",#Code,#Code);fclose(fp);})


This is a pretty cute program if I can say so myself. When its ran it will create a file called source.c that will be exactly the same as the code above. You could even recompile source.c and it will create another source.c. You should attempt to do this on your own to see if you can come up with other cool ways of doing it.

Download: SelfRep.c
Read More

Dual booting Linux and Windows with linux already installed

I have always been told in order to dual boot Linux and Windows you must first install Windows then Linux. The idea being that Window's boot loader does not play nicely with Linux like Grub or Lilo does. However it is often easier to install Linux then Windows; like with the up coming Windows 7 release, Linux users may want to try out Windows 7 without having to reinstall their Linux installs. I cam across a great tutorial on how to do just this.
Read More

A Lapse in Policy

We have all be on the phone talking to someone that we may not know all to well, when at the end of the conversation they say "sounds good, go ahead and shoot me an email about this.". If you are like me you think, "why did we just talked about it". However that email actually is used for quite a few things: The most obvious one is that it will be used as a reminder, people often use there inbox as a to-do list. The next thing that email will be used for is a record of your request, most companies have very strict policies on change management where all changes must have a request associated with it. The final thing that email will be used for is authentication, with the raise of knowledge about social engineering over the phone email as authentication has come into play.

The lapse in policy comes from the last two things the email serves. It comes from the assumption that only the person who controls the email account can send an email from that email address.  Unfortunately email, like most Internet protocols was invented before security was taken into account. Its actually considered quite trivial to send an email appearing to come form any name and email address that you please.

Fortunately there is a simple fix to this problem: Simply reply to all request emails with a confirmation request. So if person A requests person B to preform some task on the companies file server. Before preforming the task, person B should send a confirmation email to A asking for A to confirm the task.  Then the request and the confirmation should be stored for record keeping and we can be sure to the point of the security of the email account that the request was authentic.
Read More