failing like never before

22Feb/090

Change of Majors

College freshmen are always told that on average, a college student will change their major at least twice (or something like that, please don't quote me on this). I always thought that I would never change my major; I liked my choice, I had always wanted to be an engineer, and I thought I knew what I wanted. But over the past year, its occurred to me that I have no idea why I decided to pick electrical engineering, and the more EE classes I take, the more I realize how little I actually like the subject; the thought of having to take another electromagnetics class doesn't exactly make me want to dance a jig, and while solid state physics can be interesting sometimes (thanks to my awesome professor), I can't see myself working with wave equations and Fermi-Dirac statistics for the rest of my life. Oh, and plus, I am no longer a math king. Really more of a math peasent then anything else, which is definetely not a good thing when I'm in a major that has so many math requirements that its only two classes short of a math minor.

I came to an epiphany several weeks ago that my major simply was not making me happy, and that it was time for me to change. I've chosen Computer Science and Engineering as my new major, although it remains to be seen whether or not my application into the Computer Science department will be accepted.

22Feb/090

Weekly Biking

I've had this sticky-note with my biking stats for the previous week sitting on my desk for a while now, so here it is:

Distance: 9.634 miles
Average Speed: 13.4 MPH
Max Speed: 28.8 MPH
Elapsed Time: 43 minutes and 10 seconds

19Feb/090

Current Biking Events

Over the weekend I managed somehow to lose the cable that I use for locking my bike up. I could have sworn that I brought my bike, cable, and padlock into the room before it started to rain again, but for some reason I just cannot find my cable. So of course, I haven't been riding my bike lately since I can't afford to leave it unlocked outside of my classroom. And since one of my roommates leaves his shiny new Trek 1.7FX in the room at all times, all my other roommates have been getting a little annoyed by the presence of two bikes in the living room, which was never that large to begin with. Today, I decided to just borrow one of roommates cables, and use it until my cable decides to show its ugly mug. So today was the first time I have ridden my bike in several days. But on to something a little more exciting...

Almost two weeks ago, I got out of class and it was pouring rain (unusual weather for lovely Southern California, even in Winter). The padded seat on my bike was soggy with absorbed water and my cheap Wal-mart brakes were squeaking like mad canaries. I wasn't on my bike for even a minute before I realized that one of my toe-clips felt a little loose, and a closer examination revealed that one of the screws holding the toe-clip to the pedal was missing. Figuring that it wasn't too huge of a deal, as long as I kept excessive force off of that clip, I remounted my bike and continued on my way. About two minutes later, the second and last remaining screw on that toe-clip fell off along with the little metal bracket. Even better, the straps that went with the toe clip were rotting through and the metal buckle for adjusting the straps were rusted completely solid, which meant there was no way for me remove the straps and clip from the pedal without some pliers or a pair of scissors. Apparently the fates were against me on that day. And so, I pushed my bike all the way back to my room, in the pouring rain, with one of toe clips flapping around and dragging against the ground.

I ordered some strapless toe-clips from Amazon (my roommate was ordering a few things, and needed a few extra dollars to get free shipping) a few days after my toe-clips debacle. Full toe-clips are nice for riding longer distances without stopping, but I've found that they're a pain in the butt to get in and out of while riding through town. I figured that some strapless toe-clips would give me a little more power then riding with just platforms, while allowing me to avoid some of the annoyances of full toe-clips.

The strapless toe-clips arrived last night, and I've spent a few minutes in them already. They seem fairly effective at allowing me to put a little more power in, and they're fairly easy to get in and out of. I'll write a little more about them once I've given them some more street time.

10Feb/091

Weekly Biking

Distance Traveled: 8.38 Miles

Max Speed: 29.2 MPH

Average Speed: 14.4 MPH

Time Traveled: thirty five minutes

Tagged as: , , 1 Comment
9Feb/090

A Simple Weird Sorter

This is a little toy program written for one of my CS classes. The program takes a positive integer N as an argument and reads from stdin until it gets an EOF. The program then sorts the input using qsort, while assuming that each element to be supported is N bytes long.

Fun facts: the output from this program looks kinda cool if you do "./program_name 1 < index.html" where index.html is some large webpage.

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

#define MEM_SIZE 100

// for the sake of ease, token length and input array are global
unsigned long global_token;
char * in_ptr;

// comparator for qsort,
// returns 1 if a is bigger, -1 is smaller, 0 if equal
int comparator(const void  * a, const void * b)
{
  unsigned int i;
  int r_value = 0;
  for(i = 0; i < global_token; ++i)
  {
    if( *(i + (char*)a) < *(i + (char*)b))
      return -1;
    else if ( *(i + (char*)a) > *(i + (char*)b))
      return 1;
  }
  return 0;
}

// get input from stdin and save it to dynmaically allocated memory
unsigned long get_input()
{
  char* temp_in_ptr;
  unsigned long ar_size, n_ar_size;
  unsigned long max_size = MEM_SIZE;
  for(ar_size = 0; !feof(stdin); ++ar_size) // loop until EOF
  {
    if(max_size == (1 + ar_size)) // check if more memory is needed
    {
      temp_in_ptr =(char *)realloc(in_ptr,
                  (size_t)(MEM_SIZE + max_size));
      if(!temp_in_ptr) // returns error and exits if realloc fails
      {
        fprintf(stderr, "Error in allocating memory for input.");
        fprintf(stderr, "Input data may be too large.\n");
        free(in_ptr); // free dynamically allocated memory
        exit(1);
      }
      in_ptr = temp_in_ptr;
      max_size += MEM_SIZE;
    }
    *(in_ptr + ar_size) = fgetc(stdin); // get next char from input
    if(ferror(stdin)) // check for read error
    {
      fprintf(stderr, "Error encountered in reading input.\n");
      free(in_ptr); // free dynamically allocated memory
      exit(1);
    }
  }
  ar_size --; // get rid of EOF char
  // if string was not multiple of token length, need to make it
  // a multiple of token length and fill end with '\0'
  if(ar_size % global_token != 0)
  {
    n_ar_size =
       (global_token * (unsigned int)(ar_size / global_token + 1));
    if(n_ar_size > max_size) // check if more memory is needed
    {
      temp_in_ptr = (char *)realloc(in_ptr, (size_t)n_ar_size);
      if(!temp_in_ptr) // check for error in mem allocation
      {
          fprintf(stderr, "Error in allocating memory for input.");
          fprintf(stderr, "Input data may be too large.\n");
          free(in_ptr); // free dynamically allocated memory
          exit(1);
      }
      in_ptr = temp_in_ptr;
    }
    for(; ar_size != n_ar_size; ++ar_size) // fill with '\0'
    {
      *(ar_size + in_ptr) = '\0';
    }
  }
  return ar_size;
}  

int main(int argc, char** argv)
{
  unsigned long ar_size, i;
  in_ptr = (char *)malloc(MEM_SIZE * sizeof(char));

  if (argc < 2)
  {
    fprintf(stderr, "Must provide at least one argument.\n");
    free(in_ptr); // free dynamically allocated memory
    exit(1);
  }
  // use strtoul() to convert char to long int
  // and use errno to check for error in conversion
  errno = 0;
  global_token = strtoul(*(argv + 1), NULL, 0);
  if(!global_token || errno == ERANGE)
  {
    fprintf(stderr, "Argument must be a positive integer.\n");
    free(in_ptr); // free dynamically allocated memory
    exit(1);
  }    

  ar_size = get_input(); // get data from stdin
  // sort with qsort
  qsort(in_ptr, (size_t)(ar_size / global_token),
      (size_t)(sizeof(char) * global_token) , comparator);

  for(i = 0; i < ar_size; ++i) //print sorted data
  {
    printf("%c", *(in_ptr + i));
  }
  free(in_ptr); // free dynamically allocated memory
  return 0;
}
Tagged as: , , , No Comments
3Feb/090

Weekly Biking

More biking states for the past week. Not exactly my best numbers.

Distance Traveled: 15.427 Miles

Max Speed: 28.3 MPH

Average Speed: 12.6 MPH

Time Traveled: 1 hour and thirteen minutes

2Feb/092

One Reason to Buy a Mac

When people ask me why I won't buy a Mac, I generally give three reasons:

  • Too expensive -I know a lot of people will argue that the 13.3 inch Macbooks actually have a list price that is similar to a Windows Laptop, but they forget that Macbooks are never available in the bargain bin on Black Friday
  • Right click - although I have gotten a little more used to the way Mac's double click, I still don't like it that much.
  • Delete key - this is decidedly annoying, and I just don't like having to press Function+Backspace when I want to delete.

Mind you, this is just me and I won't try to push these ideas on other people, some people don't mind throwing down a few hundred extra dollars, or losing the delete key (which most people never use). But lately, I have discovered one very good reason to buy a Mac.

The day before Thanksgiving, I tripped over the power cord to my HP dv2910us. Thankfully, the laptop was wedged between piles of junk and it didn't fall off the table, but the plug was bent out of shape and the little plastic insulation on the plug's tip cracked off. Since I needed a working laptop for school, I couldn't afford to order a new power cord from ebay and wait a week for it to arrive, so instead of paying ten dollars, my dad paid fifty dollars for a new cord and brick. I know its crazy, but it had to be done. Once I had the new cord, I figured the matter was resolved and that everything was going to be hunky-dory.

Just last week,  two months after I tripped over my power cable, I woke up, plugged my laptop in, and turned it on, just like most any morning. It immediately started making a funny, high-pitched buzzing, so I switched it off. It didn't take me long to notice that the power connection port was sparking, so like any sane man would do, I unplugged the power. If you look at the poorly-taken picture to the left, you can just barely notice that the white plastic ring surrounding the port is melted on the left-hand side. As far as I can guess, my tripping over the cord probably damaged the connection port just slightly, and two months of plugging and unplugging the power cable was enough to aggravate the port's damaged condition to the point that it started shorting.