failing like never before

25Jun/080

Make Me a Syscall

I was working on a assembly language project for my computer science class one night, and was having a devil of a time debugging it. The program was supposed to read data from a file using system calls (syscalls) (and then do some more stuff) but for some reason, my program refused to read data from file. I spent over an hour tracing through my code, trying to find the probably obvious bug. My code around the "bug" looked a little like this:

...
move   $a0,$s0
move   $a1,$s1
li          $v0,14
...

I realize its a little hard to understand out of context, but what happened was that I set up all the registers properly but never actually made a syscall!

25Mar/080

Passing an Array in C

This quick little article is intended to give you a better idea of how arrays are passed in C. A basic understanding of pointers is required. If you don't know what pointers are, check them out at wikipedia.

We'll be using the following array as an example throughout the article:

char c_array[50];

The variable that we use to reference the array is actually a pointer. A pointer points to a location in the computer's memory, as you probably already know. You can have pointers to any data type you want, even a pointer to a pointer. The reason why we can reference all 50 elements of our array with just one pointer, is because arrays are allocated as one big fat chunk of memory. That is, all the elements in the array are lined up in the computer's memory one after the other. This is very handy, because if we know the location of the zero element in the array (the pointer to an array points to the zero element) we can get the physical location in memory of the fifth element (I made a funny!) by doing something like:

c_array + 4

Of course, thats a rather impractical way of accessing data, so we usually just end up doing:

c_array[4]

(Notice that I used a 4 to access the fifth element, because in Computer Science we always begin counting from 0, and not 1)

The fact that arrays are referenced by pointers, can be both good and bad. If your array is quite large, then passing by value can be quite expensive (that is, if you could pass an array by value, arrays in C have to be passed by reference). However, as you probably know, passing by reference can be a problem because you may want to leave your old array untouched. When passing an array, if you want to make sure your passed array isn't changed or modified you can either pass it as const, or else create a new array and copy all your old data into it. You can use strcpy from the standard library to copy the array into a new one.

3Feb/080

Circular Doubly Linked Lists

So a linked list is basically just a bunch of nodes linked together by pointers. In a singly linked list, each node contains a pointer that points to the node in front of it. Whereas in a doubly linked list, each node contains two pointers, one pointing forward and one pointing backwards. In a circular linked list, there is a "dummy node" that acts as a beginning-place-holder, and the list forms a kind of circle (thus the name circular). I realize that this was an extremely abbreviated and hard to understand explanation of what a linked list is. However, this is not meant to be a full explanation behind linked lists, merely a quick introduction to the rest of my post. For a full, in-depth description of linked lists, go here (oh wikipedia, where would we be without you?).

Just like in any other basic computer science class, I had to design and implement a linked list for a project. I also had to include a short write-up along with a little diagram. The diagram, is what this post is all about. Unfortunately, I had some issues getting my lovely ASCII art to display properly using XHTML markup, so heres a screenshot. I better get an 'A' on this project, if not for my awesome programming, then at least for my stellar ASCII representation of a circular doubly linked list

20Jan/080

Dynamically Create a Multidimensional Array

I had a few problems trying to dynamically create and pass a multidimensional array in C++ for my previous programming project. Of course, passing an array by value is rather ridiculous when the array is large, so I had to pass by reference. Now, passing a single dimensional array is really quite simple in C++, you just do the following:

//stuff
int input_cols;
char *char_array_ptr;
//stuff
cout << "cols? ";
cin >> input_a;
char_array_ptr = new char[input_cols];
return char_array_ptr;

And hey, you're done. The same thing could pretty much be done in C by using malloc, instead of new. But as I mentioned, I needed to pass a multidimensional array.

27Dec/070

Lightbox in Typo

A quick little explanation and demo on how to get lightbox running in Typo 4.1.1.Typo 4.1.1 uses an older version of lightbox. If you prefer to use the newer version of lightbox, then go here and download lightbox 2.0. Then, in your Typo application's public directory and overwrite the old lightbox javascript, styles, and images.

You'll also have to make sure that the theme you're using for your blog, has the necessary javascript and stylesheets included. To do this, open

/railsapp/themes/<whatever_your_current_theme_is>/layouts/default.rhtml

and ensure that the following lines of code are in your header.

<%= javascript_include_tag "typo" %>
<%= javascript_include_tag "lightbox" %>
<%= stylesheet_link_tag "/stylesheets/lightbox.css" %>

I would also like to add, that one of the javascript files needed by lightbox is massive 23kb. So if you want to keep your web page as light as possible, you may want to consider not using lightbox effects.

To use lightbox in your blog, just add the following code into the article you are posting:

<typo:lightbox src="image_link" thumbsrc="thumbnail_link" />

Here's a few examples of what lightbox can do.

"The Solid Gold Sound of the UCLA Marching Band!"

31Aug/070

Visual Studio Error Resolved

That stupid little error I mentioned earlier appears to have resolved itself.

weeee.. Visual Studio 2005.

I feel like spewing forth whole paragrahs of teenage angst right now... but that would contradcit my "vision statement" for this site.

30Aug/070

Visual Studio 2005

I'm not a big fan of .net, so I wasn't too happy when I found out I'd be programming web services and sites in visual basic and ASP for my job during the summer. But even though I'm not much of a Windows fan, I still really like the Visual Studio 2005 IDE. Its got pretty syntax highlighting, and the little helpful hints and drop-down lists are really quite nice. Everything is very configurable and fairly easy to use. That being said, sometimes I experience some very strange things with the Visual Studio IDE. Like today.

I was doing some pretty simple ASP type stuff, more HTML and CSS really, when I decided to swtich to the "Design" view so I could get a quick glimpse of what my page was looking like (I know, I could always just hit Control+Shift+w and view the page in the browser and get a better view, but I was being stupid). But when I hit the "Design" button, the IDE popped up with this little error: "Can not switch to Design view because of errors in the page. Please correct all errors labeled 'Can not switch:' in the Error List and try again." It wasn't too big of a deal, and it wasn't the first time I had gotten this. So I checked the error list, and there was only one error: "Cannot switch views. This end tag has no matching start tag." The error was being thrown around the "" end tag in this line:

<a href="index.aspx">Chipset Info</a>

You can take a look at this screenshot to see the error in all its glory.

Now this was really quite strange. There was nothing wrong (or so I thought) with that line, and nothing above it was causing it to screw up. I figured that Visual Studio was just being stupid and maybe had some latency issues with updating the errors list. I hit control+shift+w and viewed the page in a browser instead and forgot about the little "error." Throughout the day I closed and opened Visual Studio a couple times and restarted my computer once. After the reboot, I came back to this same page and the error message was still showing. I tried moving the code around a bit, but the error kept coming up. So far, I haven't been able to make the error message go away.

I could rant about Windows and how their code sucks horribly, but for the most part, Visual Studio 2005 was working great for me. Yes, it is a really annoying bug that I've gotten, but I still think Visual Studio 2005 is a good IDE. There's a plugin for VS called "Ruby in Steel" that allows a developer to code Ruby in the Visual Studio IDE. If weren't for the fact that I run Linux at home almost all the time, I would be using VS at home, and not just at work.

"Course, theres still a part of me that says, "resist the urge! Microsoft is the devil!!!" But I'm working on not being such a narrow-minded OS fanboy these days.

25Apr/071

problems with gallery

Still no luck with getting the gallery to work, although the error messages have now changed from:

MissingSourceFile (Missing model image.rb)

to:

NameError ( uninitialized constant Technoweenie::AttachmentFu::Processors::RMagickProcessor )

should be fixed in a very short amount of time.