Web Development Class & A Resource

I have been trying to improve my own web development skills over this break to exceed the skills that our professor has been teaching us.  In about a month and a half we will have to present our web site to the class.  I don’t know about anyone else, but I am a bit competitive and I will be bummed out if my group does not have the best site in the class.

I consider it necessary to have a clean and appropriate look to the website, as well as full functionality and the impassibility that the site would actually go live after the class.  In my groups case, the plan is to make the site a full time site for a Fraternity on campus.  This makes it a lot easier for the color scheme, so it won’t drive me crazy looking for hours for a great theme.  I hope to have the design and HTML/CSS done by the time we start class again next week, that way we can focus on the functionality and the server side programming.

If I get something up and running that is semi presentable I will post it here, and hopefully get some feedback.  But before I go, I want to leave this link to a pretty good resource.  This is especially good if you are just starting out with web development and it helped me work a little more with CSS: 30 Days to Learn HTML & CSS

All 30 days are already posted, so you can work through them at your own pace.  Hopefully someone will find it useful.  Later!

Advertisements

Electric!

With my digital electronics class this semester I have come to realized I really, really enjoy building circuits and using IC’s to build logic.  So I decided I wanted to expand my knowledge to see if a Masters degree in Electrical Engineering/Computer Engineering would be something I would enjoy pursuing.  After doing some searching I think I found a really good online resource to cover my basics before getting into the more advanced topics, and building some cool electronics.  The site is called All About Circuits and it has some online “books” for things such as DC, AC, Semiconductors and Digital.

While I am learning a lot about digital in my class, I also need to learn about DC, AC and Semiconductors so I can build some cool stuff on my own.  I think I may have just found a new. slightly expensive hobby.

Anyone else out there who enjoys building electronics with some tips for a newbie to get started?

Embracing Failure

I have not failed. I’ve just found 10,000 ways that won’t work.
    –Thomas Edison

 

I have been thinking recently about how to improve myself.  What areas can I work on to become a better programmer, Computer Science student, person?  I came to the conclusion that I sometimes shy away from a challenge, or from learning new things because I hate failing.  This lead me to think about why I hate failing so much.  It seems to me that failure and mistakes are just part of life.  Just like waking up, and eating, and feeling emotions.  None of these things are bad, they just exist.

So what makes me hate something that happens in life?  I think it is because of the social stigma we attach to failure.  If I don’t pass a class or if I had be held back in grade school I would have been looked down upon by my peers.  If I were to have a failing grade, I would get something taken away as a punishment.  Essentially in our culture, if I fail the focus is on the bad consequences that occur because of it.

I think that this has paralyzed me, and I just want to stick to what we know we can succeed at.  And when I do fail, instead of looking at my mistakes to learn from them I push them aside and try to forget about them.  This has to be the worst thing I could do!  I need to start making mistakes.  To start learning.  To start embracing my failures.  The Thomas Edison quote above is going to be a new philosophy to live by.  Failure is only bad if I do not learn anything from it.  Mistakes where I learn something valuable from are just as good as success is sometimes, and I cannot help contribute to forming a better future if I am to afraid to get my hands a little dirty when exploring.

So here is to embracing failure!

Clearly Defined Objectives

 

We have all been there.  Looking at our product and wondering why it was so hacked together.  Maybe its not hacked together, but it is completely different than what was originally intended.  I have been there and I really dislike it. that’s for sure.

I started to wonder why that was, and I actually couldn’t determine what was causing it in myself.  It was not until I was helping my roommate out with some Java homework that I started to realize a problem, especially for those just starting out but also for others that have been developing a little bit longer.  And that problem is not fully understanding the objective.

What I mean by this is that any project we set out to do has a purpose.  Weather that purpose is to connect people socially, help track finances, or display cat pictures they all have objectives to be met.  Not clearly understanding what the end point is can be extremely detrimental when going about solving the problem.  You can’t solve a problem, when you don’t know what the problem is right?

I feel like we kind of skip over the idea of planning and researching before coding in University courses these days and that is a major part of development.  So from now on, I am making it a goal to clearly outline the objectives of any project, or problem I am working on before I even right the first piece of code.  How will this help me?  I think it will save me a little bit of time in the long run, and keep me from pulling my hair out.

So my challenge to any who doesnt do it yet, clearly define your goals before jummping into work.  And then stick to those goals!

/rant

Quicksort

I always find certain algorithms extremely simple yet sophisticated.  And I would have to say that Quicksort is one of those algorithms.  I was working on a bit of JavaScript for my web development and I kind of ended up on a tangent that had me wanting to be able to search through a bunch of numbers to see if it is included in the data.  So I figured I would use Binary Search to find it, but then I remembered that I would need sorted data for that to work.  Because I knew I wasn’t going to get pre-sorted data I would have to take the information as an array and sort it on my own.

Anyone who has studied algorithms knows that the other options that come to mind are usually selection sort, insertion sort, bubble sort and mergesort (from a basic algorithms class.)  The first three all share the same worst case performance of O(n2) and both insertion and bubble have a best case performance of O(n).  Merge sort and Quicksort are both O(n log n) in the average case, and I wasn’t to worried about a stable sort so I went with Quicksort.  I looked it up online to make sure that I still remembered the concept, but I have never written a Quicksort algorithm.  I will first post some pseudo code for a Quicksort and then I will talk about it and follow it up with my JavaScript implementation of the algorithm!  Lets get started:

 

Pseudo Code

function quicksort (Array A)

    if length of A <= 1:

        return A

    get pivot value.

    remove pivot value from array.

    create empty arrays less and greater.

    for x in length A:

        if x <= pivot:

            append x to less
 
       else:

            append x to greater

    return concatenation(quicksort(less), pivot, quicksort(greater))

The Explination

The idea is that you take the unsorted array (or list) and pick a random index to use as the pivot value.  Then once you get the pivot value, you remove that value from the array so you don’t compare the value to itself.  Then for all other values in the array you compare them to the pivot value.  If the value in the array is less than or equal to the pivot value it is to be stored into the new array called less.  Otherwise, it is stored into the new array called greater.  Pretty straight forward.  The interesting bit comes in with the use of recursion.  The return calls the quicksort function, this time on each separate array.  It concatenates the answer to have the new sorted less array, followed by the pivot value (which is now in its final spot), and then the sorted greater array.

Pretty cool right?  This is called a Divide and Conquer algorithm because it is splitting the data that needs to be sorted into smaller and smaller subgroups until the problem is solved! This can be adapted for any language you are working with, and as promised here is my code that I wrote using JavaScript to implement this algorithm.

 

The JavaScript

//The quicksort function that allows the binary search to work properly.
function quicksort(numData)
{
    //returns the array if only one element or none at all
    if(numData.length <= 1)
        return numData;

    //creating the two new empty arrays and an index var
    var less = new Array();
    var greater = new Array();
    var i;

    //picking a random pivot point
    var pivotIndex = Math.floor(Math.random() * numData.length);
    var pivotValue = numData[pivotIndex];

    //remove the pivotValue from the array
    numData.splice(pivotIndex, 1);

    //now for the rest of the array, put the data in the correct subarray
    for (i = 0; i < numData.length; i++)
    {
        if (numData[i] <= pivotValue)
            less.push(numData[i]);
       else
            greater.push(numData[i]);
    }

    //recursivly calls quicksort as well as concatenates the answers
    return quicksort(less).concat(pivotValue,quicksort(greater));

}

Conclusion

I hope that this helped you understand a little bit more about the Quicksort algorithm, and hopefully you can now implement this as well for any of your sorting needs!  If you have any questions, or need some clarification, let me know!