Archive for the 'Programming' Category

Primes by Python

The point of the following post is not necessarily the content, but the format. I just installed the SyntaxHighlighter plugin for WordPress, and I wanted to test it out. So, the story goes, yesterday I was trying to get my Python touch back (I haven’t had time to write code in quite a while), and thought it would be cool to be able to be able to post code in an aesthetically pleasing manner, if I ever write any code worth publishing (but not quite good enough to distribute as software). Anyway, here goes.


# A quick function to determine if a given number is prime
def isprime(num):
lst=[]
for n in range(2,num/2+1):
if round(num/n)*n==num:
lst.append(n)
if len(lst)==0:
print "Yeah, it's prime"
return True
else:
print "Nope, actually it has factors", lst
return False

After publishing this and looking at the result, I realize that the highlighting works, but there is no automatic indentation! As indentation is critical with Python, I think I’ll be searching for another plugin that can handle this.

Spiderbrot

Spiderbrot Small

While recently writing code to render the Mandelbrot set, a notorious fractal, when plotted on the complex plane, I made an error in my code, and came up with the exceedingly odd image above. It looked similar enough to what I was aiming for that I knew I hadn’t utterly screwed up, but something was obviously wrong. Looking over my code, I realized that I had used the new x (or a, as the case may be) value in the recursion to determine the y (or b) value, instead of the old one, as should have been so (instead of y=2*x*y+b, I was accidentally using y=2*(x^2-y^2+a)*y+b). This was easy to fix (so I can now generate the intended fractal), and it made the above image so much cooler, once I knew what was generating it. The gray area in the middle would be black with an greater number of possible recursions or a slightly different coloring scheme (I only used 100 recursions), but I thought it looked cooler this way. Feel free to generate your own. Larger image of mine here.

A Fractal Thing

Circles Fractal (Small)

The above fractal-like image was recently generated by yours truly with some recursive code written in the language Processing. (Find a higher resolution image here.) I have spoken of this language (Processing) in a former post, but I have only lately started playing with it more (partly due to the advent of winter break!). I find it quite sophisticated for graphical uses, and easy and fun to learn. Check out my code, if you are interested.

Back with Windows

As many readers may know, I have been using Linux for the past nine months or so. But now, to my slight chagrin, I announce to the world that I have reinstalled Windows XP, and am now using it as my primary operating system. I decided to do this for several reasons, first and foremost the greater compatibility with, well, everything. Except perhaps my open source ideals, which still remain intact.

In order to switch over, I needed to do several things. I wanted my data (music, code, photos, movies, etc) available from wherever I may be (on my system), so I bought an external hard drive (a Seagate FreeAgent 250G), upon which I currently have stored all my digital possessions. It seems to be working very well so far, and I can access it flawlessly from both Windows and Linux (Ubuntu Gutsy Gibbon).

With the XP CD that I had, I kept getting a “session 3 initialization failure” (or something of the like), but then I realized it was scratched. It told me there was something wrong with my hardware, but it was wrong. So I had to use another XP install CD that we had, and that one worked perfectly.

I had a problem of having “No Device” for my sound, but then realized that Windows does not automatically recognize all my hardware, and I actually had to dig out my motherboard CD and install the drivers (my sound is integrated, I think). So, after two hours of frustrated attempts and fifteen seconds of brilliant insight, my sound works again.

I need software. I am downloading and installing all the necessary programs for my digital way of life (Firefox, OpenOffice, iTunes, Pidgin, VLC, Google Earth, Sketchup, etc), and installing some old stuff from when I used Windows before (like Photoshop).

But what of programming? I intend to try out Microsoft Visual Basic (since I have succumbed to Microsoft technology anyway, why not give it a try). I also want to try Java with NetBeans, Processing, and maybe Ruby. Maybe C#. Maybe I’ll go back to REALbasic, but that costs money, an obvious drawback. I have been working with PHP more lately, and HTML as always. I will probably continue using Python for some things (probably just simple scripting), but I have tried and failed to get the hang of GUI coding with Python and GTK and Glade. Maybe I’ll try again later. Not now.

So, after this slightly long-winded explication of my current digital status, I hope I have not bored you. I felt the need to make my doings known, and this is the place to do it. But the deed is done, and I shall thus sign off for now.

HTML Tidy

Welcome to your monthly post from Matt Nichols, a man with very little free time. The topic of this post is a piece of software I have recently found, which is just too cool to be omitted from anyone’s technically oriented blog, especially mine.

This software of note is HTML Tidy (online version here). This software not only is capable of finding errors in your HTML code, but also extirpating excessive sloppiness in the code. While I may not make that many errors in my coding (I test extensively), I am rather sloppy with popularly accepted (W3, cough, cough) conventions (being doctype declarations, etc).

As I am starting to be commissioned as a web developer (I have gotten a few jobs building sites for people), I have decided that it might be a good idea to clean up my act, if you will. So, I could either go through the painful and tedious process of learning the aforementioned conventions and putting them to use in every single file, or I could try to find something to do it for me. Deus ex machina: HTML Tidy!

Anyway, this will save me an ample amount time and probably make someone happy (or at least the average web browser). I just thought you should know about it.

New MattNichols.net Design

I have recently spent some time redesigning the home page of MattNichols.net, the primary reason that you have not seen any posts around here for awhile. As you can see if you visit my home page, it is quite different from how it used to be. It now has several more links than it used to, organized into categories. I have three sites (this blog, Singularity Software, and Nautilus Web Design), and two media pages (gallery and video). The new site also has a nice new feature, the ability to list files (in two categories: code and documents) which I want to make visible on my home page. I did this with PHP, writing code that allows me to just drop the files in two directories (code/ and documents/) and they will automatically be listed on the home page. I am very happy and satisfied with how this works.

In working on the layout yesterday, I continued to learn about cross-browser compatibility. Internet Explorer is such a pain in the neck to deal with! Not only does it refuse to recognize some of the more common CSS position tags, but releases earlier than 7.0 do not render PNG transparency! The former I managed to deal with (so my hit counter appears fixed at the bottom right in both IE and other, more intelligent browsers), but the latter I left alone. I considered using GIFs, but they can’t antialias into transparency, which is a valuable feature for my site. So the site looks terrible to those who haven’t updated to the most recent version of Internet Explorer, but it is worth it for the rest, to whom it looks great.

I also recently learned how to preload images using JavaScript, so you don’t have to wait around for the link images to change when you scroll over. Very nice.

Singularity Tops 1,000!

Browsing to my software website (call it my “company”, if you will) today, I noticed that my hit counter had reached 1,001! This means that over 1,000 people have visited Singularity Software! (check it out)

But you may ask, as did my mom, what does this mean to me? This is an important milestone only in that it shows the magnitude (paltry compared to some, but seemingly large to me) of my presence on the internet. Since the launch of Singularity Software, over 1,000 people have visited, over 1,000 people have seen who I am on my coding side, and over 1,000 people have had the option to put to use that which I spend so much time and thought upon: my software creations. I greatly value this part of my life, and it is of great importance to me that others have had the opportunity to appreciate that as well.

Upon visiting Singularity, one may notice that nothing has happened there in ages. It has remained fairly static for the last 5+ months. By way of reason and excuse, I present the fact that not only was I beginning to be greatly overwhelmed with school (a.k.a. AP classes) about five months ago, but that was also about when I switched to using Linux (upon which REALbasic, my old language, does not work that well). Thus, I have had neither time nor means to pursue my most prevalent hobby, but I will now alert you that the time when I have both is readily approaching. My self-education in Python is nearing a usable point, and I am building up a sea of coding project ideas. So stay alert and watchful: my code may soon again be appearing on the web!