# User:^zer0dyer$Jump to: navigation, search Hello, I'm Curtis Dyer, and I mainly endeavor to better understand a variety of topics within computer science and The Art of Computer Programming. The following user page entails the history of my gradual interest in computers and software design, in particular. I also endeavor to post any interesting snippets of code I manage to write. Feel free to drop in and say "Hi" on my discussion page, if you feel so inclined. ## CISCO Curriculum and Self-sufficient Study Back in high school, I nurtured only a passing interest in computer science. However, I found myself in a CISCO computer repair class called A+ and got my first taste of how experts deal with the newbies. The teacher was, I see now in hindsight, a wizardly network admin. He taught binary, which is the base-2 number system, and hexadecimal, which is base-16. From there on out, we were all on our own as we trudged through the curriculum on the web. There were a few students who already knew the teacher and they worked together on various projects on their own. Later in the semester, he did stop to explain how RAID works in different configurations. The rest of the semester was generally uneventful and not terribly interesting, as we droned away on old Windows 95 machines, without much help and enduring sitting on unpleasant, deformed stools. The problem was that, as someone completely unfamiliar with computer hardware, there was no context given for the vast amounts of facts we had to memorize. The class entailed all the excitement of memorizing particular permutations of a playing card deck. Without any frame of reference for understanding how the many components that make up the inner workings of a PC come together to allow us to complete our day-to-day tasks, it made the course incredibly dry, indeed. ## A Chance Meeting with HTML Due to the fast pace of the A+ course and my lack of eagerness for memorizing arbitrary model numbers for arbitrary hardware components, I wasn't completing the chapter assignments on time. I decided to get caught up on as much of the assignments as possible at home, and I ended up managing a B+ for the class. The next semester was to cover the N+ course, which is the CISCO networking course, but continuing meant seriously rearranging my schedule. And due to my already unpleasant experience in A+, I was more than eager to find a different class altogether. By chance, I remembered my old typing teacher taught a telecommunications class, in which HTML was taught. Luckily, I was able to get in, albeit after the first week had passed in the second semester. As an aside, telecommunications was an inaccurate term for that course, since all that was taught was HTML (the kind that elicits profuse vomiting). ## Down the Rabbit Hole Unfortunately, the teacher treated her students like children and was often very patronizing. However, she left me alone for the most part. I found that the class had already gone over the basics of creating an HTML document. It didn't make much sense to me at first, so I figured I would need to catch up on my own. I was already fascinated by how Web sites worked, so I went home and avoided homework to Google search "HTML tutorials." My original intent was to just get some of the basics down so I wouldn't be lost in class. I managed to find davesite.com, which is where I managed to learn the whole of the semester in one week, plus more. HTML itself isn't too complicated, it's not that difficult to learn the very basics in an afternoon. Although I picked up the basics quickly, it wasn't until about a year later that I broke many bad habits and started writing well-formed and semantic markup. This process makes it easier to maintain Web sites over a long period of time and makes it easier to consistently manage stylistically. The more I studied on my own, the more I realized the textbook was using horribly deprecated (outdated) markup. Unfortunately, the teacher didn't recognize these problems at all. Our final project involved making a basic Web site that involved employing various skills covered throughout the semester. Oddly, I decided to base my site on teaching basic HTML and CSS. Unfortunately, I wasn't nearly as informed as I fancied myself, and a good deal of the information about CSS I wrote was plain wrong. In hindsight, attempting to write a quality informative article on something can actually be a great tool in showing where your weakest points of understanding are. ## An Introduction to Netiquette After high school, I continued my pursuit of knowledge in all things Web design, which meant spending a great deal of time on the Internet. During this time, I rekindled my childhood fascination with programming. At the age of 13 or so, I had become intrigued by tinkering with QBASIC on an old MS-DOS computer my dad had. After we had upgraded to a machine with Windows 98, I had found QBASIC wasn't installed and assumed you just couldn't get it anymore. My dad had printed some information about Java, but to download the Java environment meant tying up the phone line for over a day (good old dial-up). My desire to better learn the interactive nature of Web design led me to Perl, a commonly used scripting language with a wide variety of applications. In particular, I had wanted to have a server-side script that sent email. I had very little luck with installing Perl and Apache Web Server on my computer, as I found configuring everything correctly quite confusing. At that time, I had XP Home, which doesn't include IIS, Microsoft's Web server. I then figured that I may as well find a Web host so I could avoid the hassles of setup and get straight to coding. So, I looked for any free hosts which offered Perl. I then found Aboho (which has since gone the way of Davy Jones' Locker). At first, I had little patience for dealing with people online; my intentions were rather self-serving. I posted the minimum required amount of posts on the forum to get an account started. After ticking off the admin with my impatience, I figured I should stick with working at developing offline. However, my continual failures with configuring Apache brought me back to Aboho again. When I finally got to know some people, I really started to enjoy my stay. Once I got my account, I was pretty astounded by all that you could do. Not surprising, I had quite a lot of questions in my quest to better learn Web development. Online, it's easy to lose sight of the simple fact you're dealing with actual people when only interacting via text. It's one of the more important lessons I've learned on the web. It was because of Aboho that I ventured to learn PHP (thanks to pentapenguin), which was the first scripting language in which I became fluent. ## The Road Ahead Today, I still maintain a Windows development machine running Apache with PHP as the primary server-side tool. My interest in programming has led me to tinker with plenty of other languages, however, so I also have ActivePerl, the mod_perl Apache module, and Python. I use MySQL for database management. I used to run IIS on an alternate port, but have since disabled it, since I never use it. I used to work remotely with *nix terminals via PuTTY. Strangely, I have more experience with Unix shells and developing Unix software than I do as a normal user of *nix systems. I intend to install some flavor of Linux on a spare machine at some point. In the meantime, I find using VirtualBox to run Debian in a virtual environment more than sufficient. It's especially convenient, as you are able to seamlessly integrate the virtual environment with the host environment. Thanks to the many friends I've met online, prowling the Web with Google, and Usenet, I've become adept in HTML, CSS, JavaScript, PHP, Perl, Apache server management, and C. Although I'm not quite fluent, I have acquired a decent understanding of Python. Apart from the Web, I have been endeavoring to better learn the fundamentals of computer science by manually implementing abstract data types. Since I have a Windows machine, I have made attempts to better learn the Windows API as well. Ultimately, I hope to become an expert in systems programming. C has quickly become one of my favorite languages due to its intriguing difficulty in manual memory management and the elegance of pointers. As an aside, I'm also somewhat intrigued by esoteric programming languages like Brainfuck. ### School In high school, I studied German. My German teacher was actually Scottish (and he taught French, too!). He was a terrific teacher and was actually responsible for helping improve my mastery of the English language as well. In college, I have become more interested in mathematics and had a chance to study Japanese for three semesters. Unfortunately, I have yet to become fluent in either German or Japanese. ## How to Become a Programmer ### Proper Sources On the web, in books, and anywhere there's money to be made, there will be promises to teach you Language [X] in [Y] Hours/Days. However, I have yet to witness any real shortcuts to proficiency. Computer programming is an art, a way of thinking, a unique way of breaking down problems to find solutions. Like any specialized skill, it requires time to attain intuitive understanding and mastery. The best way to learn how to program is a path one must forge on their own, since people learn in many different ways. Some might prefer starting with basic programming concepts, while others might wish to just dive right into learning a programming language by tinkering at a program's source code. Here's one of my favorite stories about learning how to program, written by a talented programmer and comp.lang.c newsgroup contributor named Peter Seebach: Growing Up in C. Books boasting to teach programming in a matter of days are unlikely to contain much in the way of substance, but the right books, on the other hand, are invaluable resources. The right books don't condescend or water down concepts and problems. The right books don't assume everything runs on any one particular operating system. The right books are plainly honest about the audience for whom the content is intended. For example, The C Programming Language, or K&R2, has long been the de facto text for teaching people the C programming language. It clearly states its intended audience is people with at least some prior programming experience. It's important to consider the aim and scope of books you intend to read. Some people mistakenly pick up texts that are actually targeted to more experienced programmers, and come away with a bad taste in their mouths. When mathematician Andrew Wiles published his proof of the Taniyama-Shimura conjecture and, in turn, Fermat's last theorem, his target audience obviously wasn't novice mathematics students, it was aimed toward other professionals in his field. Good books will challenge you to solve problems that may take you a long time to figure out. Try not forgo this process, it is essential. Even if you opt out of exercises, you will inevitably need to experience the growing pains when building your own programs. I don't mean to make the task seem grim and daunting, but it's very important to not be put off by slow progress or the inability to make a AAA video game right out of the gate. ### Choosing your Tools The programming language is the tool you use to communicate with the computer. When you set out to learn your first language, you should treasure the general concepts you learn behind building basic programs, as they can be applicable for as long as you code. However, this begs the question, "Which language should I learn first?" Although there is no standard answer, there are some languages that can be easier to pick up than others. Eric S. Raymond, a notable programmer and author in the open source initiative, wrote a document entitled, How to Become a Hacker, in which he covers the concept of choosing a first language. He recommends learning Python as a first language. It can be a good beginner language, as it enforces some good coding habits right from the start. Current versions of PHP (most commonly used for Web development) are also quite nice. These scripting languages will allow you to create some interesting and useful programs without needing outside libraries or additional software. Think of a library as a collection of code that provides a convenient interface for some added functionality within the language. Learning general purpose languages like C or C++ (never confuse the two; they are, in fact, two different languages), depending upon your approach, can make learning programming seem much more difficult. In C, the language core, itself, is actually quite spartan and minimalistic. C and C++ will require you to be aware of memory management and may frustrate beginners who would prefer to find the quickest path from Point A to Point B, so to speak. If you attempt to learn C or C++, stick to writing programs that only use the standard library, or the set of features guaranteed to be available.[1] When it comes to advancing to using libraries for things like hardware, graphics, or the operating system, things can quickly get very complex. Each of those areas require a good amount of study on their own. There are several common technologies involved with producing programs. Technologies like compilers, linkers, and makefiles are closely tied to building projects in C and C++, but each of these require some time to grasp on their own. On the opposite spectrum of managing various tools to produce your programs, there are IDEs, which generally pack many programming tools for building projects into one program. It usually transparently invokes the compiler, linker, resource compiler (for Windows applications), and possibly more things, at the press of a button. Some also automatically generate files and offer templates to further abstract the design process. While IDEs can certainly be helpful, if you start using them before learning the underlying technologies, you may end up getting tied to your IDE to build even relatively basic programs. If you ever find yourself in a situation where your IDE doesn't support a target platform, you will need to know how to build your project manually. ### Google is your Friend The best skill I have taken from learning Web development and programming is how to make the best use out of Google and generally finding solutions self-sufficiently. The next best skill is to develop a tough skin when dealing with others on the web. A lot of experts are curt and concise. Don't fawn, but don't posture; be efficient with your and others' time. Self-sufficient Google searching is a priceless tool, which is useful in many situations even outside of programming. The path to actually growing is identifying problems or puzzles that interest you, and which you can approach in logical, structured steps. You can then turn them into pieces of a program. This is the essence of programming: mapping real world problems to logical steps, which make up a program. The art of visualizing and implementing these steps transcends any one language, but learning many languages is what refines and perfects your abilities. Let's expand on real world problems relating to code. Once you've studied the basic components that make up programs, find something in your everyday life that you think could be made easier if you had a tool doing it for you—maybe it's checking certain things in RSS feeds, maybe it's automatically generating a shopping list—it should be something that you'd actually like to use. Try and think how those basic program components could be combined to reach the desired outcome. You would use Google or your textbook to fill in the blanks. For example, if you need to know what day of the week it is in your program, you'd simply search for information on date handling in your language of choice. This goal-driven nature of learning about a language can make all the difference in retaining information and gaining a more intuitive understanding of concepts. When you are forced to apply new concepts in the context of your own meaningful projects, it has a far greater impact than simply passively reading about the general concept in a tutorial or textbook. The experience of crafting your first useful program is very rewarding; it is beautiful in all its hideousness. ## Favorite Code Snippets Here, I've listed some interesting (and some not so interesting) code snippets for people to peruse. ### Never use Magic Quotes in PHP Well, as many of you probably already know, magic quotes was nothing more than a bothersome misfeature, and has been removed from PHP for quite some time. Despite this, you may not have a choice to outright dismiss this feature when dealing with certain legacy systems. Whenever possible, ensure magic quotes is disabled within php.ini. On Apache servers, you can also usually set php.ini directives within .htaccess files. To conditionally remove magic quotes only when it is enabled, we might use something like the following: <?php if ( get_magic_quotes_gpc() ) {$lambda = create_function('&$s','$s=stripslashes($s);'); array_walk_recursive($_GET, $lambda); array_walk_recursive($_POST, $lambda); array_walk_recursive($_COOKIE, \$lambda);
}

?>


You might want to only alter the superglobal that's relevant, however.

### Power Sets and C

Steve Gibson, computer programmer and security professional, maintains his own news server, and while lurking, I noticed someone had asked a question about how to generate all the possible substrings of a string, where the substrings are delineated by dots. For example, given the string, "abcd", we would generate:

abcd
a.bcd
ab.cd
a.b.cd
abc.d
a.bc.d
ab.c.d
a.b.c.d


As it turns out, this problem can be modeled well by the notion of power sets, where the power set, P(S), is defined as the set of all subsets for some set S. The power set includes the empty set and S itself. The size of a power set is given by |P(S)| = 2n where n is the size of the set, S. From a combinatorics perspective, we can view the subsets in the power set as a series of combinations of length 0 to n:

$|\mathcal{P}(S)| = \sum_{k=0}^{n} {n \choose k}, \;\;\; \text{where} \, {n \choose k} = \frac {n!}{k!(n-k)!}$

However, in our case, we end up with 2n - 1 substrings, because we cut the amount of subsets in half by skipping odd integers in order to leave out substrings resulting in separators appearing before the first letter or after the last.

The solutions I had seen posted in the newsgroup seemed circuitous and were, if I recall correctly, written in Visual Basic! I decided to implement the power set solution in C and utilized bitwise logic rather than operating on a string or, worse, an array of integers.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* we can use the left shift operator to test only the bit in position x'' in an integer n'' */
#define BITTEST(n, x) ((n) & (1u << (x)))

static void powerset(const char *data, const char *sep, FILE *fp)
{
size_t i, j;
size_t len = strlen(data);

/* this is equivalent to 2^len */
size_t nset = 1 << len;

/* we avoid placing separator on outside ends of string */
for (i = 0; i < nset; i += 2) {
for (j = 0; j < len; ++j)
fprintf(fp, "%s%c", BITTEST(i,j) ? sep : "", data[j]);
putc('\n', fp);
}
}

int main(void)
{
powerset("abcd", ".", stdout);
return 0;
}


## References

1. ^ ISO/IEC 9899:2011. Programming Languages—C. §5.1.2: "Execution Environments". 5 August 2013.