Code

  • The Visible Light Spectrum

    Visible Light

    I am taking a Light and Photography course at school where we are learning about the electromagnetic spectrum (EMS) and visible light, color temperature, etc. When giving us a website for the EMS, my professor mentioned he could not find one that was more “interactive”. So, me being the overachiever, I decided to make one. This is how I made it…

    I wanted to make a spectrum with clickable areas to display each color. I did not want an image map. Image maps went out with tables. So I created the color background using a multicolor gradient overlay in Photoshop. I then measured out how many pixels each color was. Using some CSS, I created a div that was the height and width of the image I created and made the image the background. I then created a div for each color in the spectrum. With the parent class .color, I was able to float all of color divs left and give them a specific height…

    .color{
    float: left;
    height: 196px;
    }

    Then, each color got its own color ID that was defined by the different widths.

    Now, the hover part. To make each of these colors a link, I simply used blank .gif images set to specific widths. When you would click on the invisible image, the color information comes up. The color boxes were done by code I adapted from the Lightbox JS project, which is linked on the EMS site. Maybe when I get some more time, I will do the entire EMS, not just the visible light sections. Later!

  • Coding Process

    Here is a paper I recently found. It’s on my coding process (after being a coder for about 2.5 months), and was written my freshman year of college…

    What I do BEFORE I write any code?

    Before actually coding any program, I have to make sure I understand it. Usually, I will understand what I have to do, but not what that means when it comes to writing the program. However, for the last 2 assignments we’ve had, I sat down, and wrote exactly what I had to do, and then what kind of methods I could use for writing that program. This took some time on my part. Just recently I’ve realized I should do this, and it makes writing the program so much easier. Since this course is my first experience with programming, It takes me a little longer to actually realize what I have to do and how to go about doing it. This is, I should also mention, the longest part of the process for me. For the current program, we actually had to write and hand in what we thought we had to do. We had to set up an array that took the inputted number and added 1 to t hat spot in the array. Ex. If 50 was the input, the a[50]= 1. Then the program had to print out the array with the number in that array. So this example would print 50: 1. After figuring out what I had to do, I thought of the best solution. Since I am new to programming, the best solution might not be the best, but I want to be sure that the program works. My solution was that I should set up an array, then use a for loop to make each value in that array 0. Then read in the Int. with a while loop, and made the loop terminate with a value less than 0. After each number was read in, I set up another for loop that, if the value in the array spot was greater than 0, it would print the array spot and its value.

    What I do BEFORE I get my first clean compile?

    Before my first clean compile, I go back to make sure that I didn’t miss anything. If I did, I would fix it. This is before any compile. I align everything to make sure it is all written correctly. Then if I compile, and it is not clean, I fix the errors the best I can. Sometimes, this would include asking a friend for some pointers on where I messed up. With this particular program, my error at compile time was that the file input class Prof. Plishka provided was not updated. So I went out to the website and got the updated one. I make sure everything makes sense, and then I proceed to my first clean compile.

    What I do AFTER my first clean compile?

    After my first clean compile, I first pray to God that the program works. Sometimes, it does. Usually, it doesn’t. So I go back to my code to check where the problem might be. After checking through the entire program- pretty much line by line, I assess where the problem might be and solve it accordingly.

    Quite a bit has changed since then, and now coding is ‘like a second language’ to me. I don’t really need to put a lot of thought into how I will do something, just into how I can make it better, more efficient. I use a lot more print statements for error checking now than I did then, and they really do help pin point any problems. I don’t need to check line by line any more, since I am more familiar with whatever languages I use, so I usually can tell what is giving me trouble. As for asking friends for help, that is always good to do. Writing code is like writing a paper in the sense that you might over look errors because you wrote it. Later.

  • Teach yourself how to program

    As some of you may know, I have taught myself a lot of the programming I know. It started with HTML, then CSS, some JavaScript, and then I moved on to PHP and MySQL. AJAX and Java are in the works, though I have some help from school with Java. In any case, I thought it might be good to write how I went about teaching myself PHP.

    With HTML and CSS it was a little easier because I had Frontpage to learn from. But the best way to learn those 2 things it to look at other people’s source. I still do that occasionally when I see a cool CSS effect that I want to try. There are also an infinite amount of resources on HTML, as well as other Web based languages. W3 Schools is, in my opinion, the best.

    PHP/MySQL Programming for the Absolute Beginner

    Learning a programming language like PHP is a little harder than that because PHP is processed by the server, and is invisible to the user. When I taught myself, I first purchased a book that familiarized me with the language. PHP/MySQL Programming for the Absolute Beginner is great for that. It covered not only the language, but some theory behind programming. I strongly suggest you learn theory if you are serious about programming. While languages change, theory will always be the same. Don’t just learn the syntax of a language- but how and why each component works- Ifs, Whiles, methods/functions, etc.

    In addition, read online tutorials, how tos, and do it yourself. The programs from that book and books like PHP for Dummies are good. Do a program a day- even if they are simple and easy. They are meant to teach you how to use certain types of syntax. My Del.icio.us links on the side usually have some good PHP/programming resources. PHP.net is and will always be the best. It’s a huge database of all of the php functions- Functions are code written outside of the main program that can be called upon. The ones on php.net are built in, already written. These will save you massive amounts of time you would spend writing your own stuff. PHP has over 700 built in functions. Occasionally, on this site, you will find something I have written, and I will make the code available for download.

    It is not always easy to learn a programming language, but if you work hard, do practice programs and READ, you will be well on your way to writing your own apps in no time. Later!

  • Version 4.0

    The New TehJoey is officially launched. You may have been noticing over the last few days, when layouts were switching back and forth. But this is more than just a layout change, which is what my last one and the one before that really was.

    For this I decided on something different. Recently I came to the conclusion that my programming skills are stronger than my design skills. I like the programming aspect better- functionality, performing certain tasks, etc. So that what I focused on here. The layout is simple, but I feel it is good. It’s clean and easy to read. However, the focus is on some new features. I am now coming close to 300 posts. With the way my category and archiving system is set up, finding stuff isn’t easy. So, taking a page from Del.icio.us, Flickr, and Binary Bonsai, I am going with ‘tags’ instead of categories. Really, they are kinda the same. But with tags, I can add more to each post, make it easier for users to find something by topic. I am currently going through my posts, adding more tags to each post.

    Secondly, after being allowed to post comments on LifeHacker, I found I REALLY REALLY like they way their comments were handled. Between them, and Mike Industries with the comment preview, I came to the conclusion I wanted that too. So with some AJAXness, I did. Maybe I will fill you in on how i did it at a later date.

    I will more than likely post again on the new layout. For now, if you have a suggestion or find a bug, you can report it on the About Page. Later!

  • The coding process

    During my winter break, which is very quickly coming to a close, I have done a lot of coding- stuff I have never done before. Each time I have pretty much followed the same process and have found the same thing.

    It starts off with me thinking about or writing down what I want to accomplish with the program at hand. Recently, I wrote a mailing list. So with the mailing list I wanted to accomplish these things:

    • Allow people to sign up via a form
    • Generate a confirmation number once they join, add them to a database and send them an e-mail to confirm their subscription.
    • Once they confirm, edit the database to reflect that. If they were added by mistake, delete them from the database.
    • Once they confirm, send them one more e-mail stating they have been confirmed.

    Once I get to the coding, I write functions, connection codes, queries, etc. to accomplish said goals. Then there is the debugging phase. I usually call it the What? why the hell isn’t this working??? phase. Usually after staring at it and doing a few things I know won’t work, the solution comes to me in a flash of brilliance.

    And once you are all debugged, you’re done, right? Well, not quite. Now is the time to look over ever thing, since you code is working, and see if there is anything you over looked. With this particular project, there were 2 major things I over looked:

    • A major security risk when unsubscribing
    • A check to make sure the person signing up did not already sign up

    After writing that code, it’s debug time again, and then another check. It’s usually good also, to get a couple of friends who know what they are doing to check it for you too, so they can throw some ideas at you, and maybe check something you may have over looked. Just like writing a paper, your friends might see something you didn’t because they didn’t write it. Later.

  • Writing a User log-in

    Here is the user login code I have been promising. It’s an image so it looks nice. You can download it at the bottom of the post. Keep in mind- This must be placed before the head tag in the page so if cookies are created, they can be…

    This might not be the most efficient code, but it does work. To get the actual code, click here. And if you do make it better, please let us know in the comments! Later

  • Types of classes, part 2

    Today I will continue my series on classes in Java. To review where we are, you can read this post.

    First of all, we need to add a couple of methods to our class. There are two other types of methods in classes: reporters and mutators. A reporter does exactly that. As you might notice, our instance variables are private, meaning that only that class can see it. So if we want to know certain information about the student, we must write a method that looks at the variable in question and reports it. A mutator method changes the object in some way. So, that being said, lets write a couple of these methods.

    ………..

    public String tellName(){
    return name;
    }

    public void computeGPA(float newAvg){
    float oldAvg= gpa;
    gpa= (oldAvg+newAvg)/2;
    }

    Here, we have added two methods to our class- a reporter and a mutator. Our reporter, tellName, looks at the current value of String name and returns it. Since we are returning a value, the method must be of the type we are returning. It is public so it can be accessed from outside our class. Now, here I just wrote one for name, but to get the other values (age, gpa, status), you must write a reporter method for each variable, as it’s respective type (an age reporter would be of type int).

    Our next method is a mutator that figures out a new gpa. This is a simple one that accepts a new GPA from the client and averages the new and old one together. This method is not returning anything, just doing a calculation, so it is a void method. It is accepting a variable of type float, which we declare in the parentheses before the do work in the method. Then we perform the calculation. We declare a new variable called oldAvg that gets the value of gpa, and then we assign the new value to gpa.

    That is all there is to other types of methods. They can be as simple or as complicated as you see fit. Next time, I will talk about inheritance and extensions. Later!

  • Types of classes

    Today and over the last couple of days we have been talking about classes in Java. I’m fairly certain I understand them enough to now talk about them here. Tonight I will introduce them and continue the discussion later.

    Basically, a class “consists of a collection of types of encapsulated instance variables and types of methods, possibly with implementation of those types together with a constructor function that can be used to create objects of the class. A class is a cohesive package that consists of a particular kind of compile-time metadata. A Class describes the rules by which objects behave; these objects are referred to as “instances” of that class. …” In basic terms, it is the blue prints of an object. Inside of a class, you will find instance varibles with values, methods to manipulate these variables, and constructors of those objects. If we were to make a class called Student , it might look something like this:

    public class Student{

    private String name;
    private int age;
    private float gpa;
    private char status;

    public Student (String stuName, int stuAge, float stuGpa, char stuStat){
    name= stuName;
    age= stuAge;
    gpa= stuGPA
    status= stuStat

    }
    public Student(){
    name= “”;
    age= 0;
    gpa= 0.0;
    status= null;
    }

    }

    This class has 2 methods- both constructors- and 4 instance variables in it. The variables are initialized, but have no values. This is where the constructors come in. The first constructor for Student has 4 arguments sent to it. One for name, age, gpa and status. The constructor takes these 4 values sent by the client (NOT necessarily a user) and applies them to our 4 instance variables. The second constructor, which has no arguments, simply creates an object where all of them variables are set to nothing values.

    For right now we only have constructors in our class. Next time, I will talk about other possible methods for our Student class, and subclasses that might inherit out Student class. Later

    PS- to read ahead, and check out the counter class we have been working on in class, you can find it here
    I know this was a little rushed, so if you have any questions, feel free to comment them or email me.

  • Coding

    This semester I am taking CompSci II, an advanced Java programming course at my school. So I figured I might as well live up to the name of my blog and talk about it. I am not planning on talking about CS I stuff- that is, basic programming- ifs, whiles, fors etc. unless I am asked. I’d also like you to keep in mind that I am still learning the CS II stuff, so if you see something that’s wrong or it doesn’t seem like I fully understand it, feel free to correct me in the comments.
    It’s tough to kinda find a starting point for this- so I guess I can go by class. Tonight we did error handling and exceptions. There are 3 types of errors- syntax, logic, and run time. Exception handling is for run time errors, which, if the program is not coded correctly, will make the program crash. This takes away from the robustness of the program, where robustness is the property of reacting “gracefully” (as opposed to “crashing”) when abnormal conditions.
    To prevent crashes, making the program more robust, we add exception handling in the form of a try/catch statement. a try/catch statement is set up like this:

    try{
    -code with possible bugs/errors/exceptions-
    }
    catch(excetionType1 name){
    -how you want to handle the error-
    }
    catch(excetionType2 name){
    -how you want to handle the error-
    }
    finally{
    -statements executed after try and catch sections-
    }

    The way this is set up, you put code in the try section. If at any time in that code an error occurs (stated in Java as “An exception is thrown”) it will check the catch statements looking for that exception to see how to handle it. Usually, (in my experiences) the exception is simply handled with a print statement stating the error. In the future, I’m sure we will look into how to use exception handling not only to state the error, but also allow the program to keep going, or revert back to before the error. The finally statement will be executed whether or not an exception is thrown.
    You can find a list of Java Exceptions here. Once my professor posts his notes on exception handling, I will post them here. Later

    Update: Here is that link like I promised.

  • Casabona.Org

    The Official Launch! Im excited to announce, on June 1st, 2005- the official launch of Casabona.Org– a website I have been working for a few months now. It is teh culmination of my PHP/MySQL skills up to this point. You can read the Site Schematic here to get an idea of how i did it all (or most of it). The idea behind the site besides incorporating my new skills is to inform people of the different services I offer and a place to post my resumé. I will also be posting different projects there ready for testing/downloading. Very soon: a Resumé Creator. Fill out a form, and boom- your resumé ready to print. The beta version will be out as soon as I work out a couple of bugs. The site will be updated every monday and/or friday with new links, stories, project updates ect. One thing I plan on adding soon is a contact me page- a form you can fill out with suggestions for the site or projects, or general questions or comments. I hope you all like the site! Let me know what you think!! Later.