Code

  • Reuseability

    Code

    A few months ago I developed a Scrubs Quotes application for Facebook. This is a simple app that displays a random quote from the show on your profile. One of the first lessons/ideas being taught to me in the Software Engineering Masters program here at the University of Scranton is that when you develop software, you should make it as abstract and general as possible. Reusable code is key. With that in mind, I set out to make my quotes app a little more reusable.

    As far as the scope of the project goes, it wasn’t that daunting of a task. When programming in PHP, I usually make everything a function anyway because of the ease of use. But there were some things I needed to clean up. The first thing I did was create a config file with all of the application specific information- database connection info, application title, links to include in the app, etc. This makes changing the app as easy as changing a single file. Other files that I felt could be edited I placed in separate files as well. This includes the style sheet, which up until that point was included in the header file.

    Once that was done, there was not a heck of a lot more to do. In an upcoming version of this software, I want to include an SQL file to generate the databases, and an easy switch to make the app sightly different if there is a single person being quoted, or multiple people.

    My first use of this reusable version of the app manifests itself in a Demetri Martin Quotes application. The set up was really easy and I was able to have the app up and running in just minutes. This is a pretty exciting little project for me because it’s a great practice in system design and software development. As time goes on I hope to grow this engine and possibly make releases of the software for others to use. I would like to learn how to make this easily updateable as far as adding features go and see how scalable it really is.

  • Scrubs Quotes App

    Scrubs Quotes

    I don’t do too many things on a whim, but the other night when I saw a group dedicated to having a Scrubs Quotes Facebook application developed, I couldn’t help myself. As a big fan of Scrubs, as well as a developer, I thought I might try my hand at it. I tinkered a little with Facebook apps and it seemed easy enough. I set out that night to do that app, and finished it the next day.

    I figured I did not need a database for this project. Just a text file with a quote per line. I’d throw in some HTML when needed, and the last two characters of the file are the person’s initials. For example: Hey, Girl's Name - <strong>Dr. Cox</strong> pc. In the processing of each line, I use the initials to display the picture of the character in the profile.

    For a project like this, following Facebook’s Step-by-Step Guide is all that’s necessary. Facebook provides great documentation on creating apps, and as long as you know some programming language, you should be able to pick it up pretty easily. For those of you who have Facebook, you can check out the app here. If you don’t have Facebook, I’ve provided screen shots.

    In the near future I hope to add more quotes, and make it more user interactive by allowing them to add their own quote to their profile if they don’t want a random one.

  • Security vs. Usability

    Comp Sec

    A problem that all web developers people in the computer field face is security. When creating your application, website, server, you have to take into account what kind of security measures you must take to protect yourself and your users. However, you have to make sure that these measures don’t horribly inhibit the users. Twice over the last couple of months I have ran into server trouble where I felt the server disallowing certain actions strongly inhibited my ability to create a good website.

    The first occurred in October, while I was creating a website for a client. They wanted to be able to upload images to the server, to add them to the site. This required me to set the permissions on sections of the site to 777 (all can execute). There are numerous web apps out there that do this, and if the programmer does it right, security is not a huge issue. However, the server I was working decided (after years of me using it), they were going to reset the permissions every 6 hours for ‘security’ measures without notifying it’s customers. Never mind that I spent hours debugging a script I knew was working. How can one make a sophisticated web app without being able to change the permissions for more than 6 hours at a time?

    More recently, I am working on a website that would send emails through a php script using the standard mail() function. Only, due to ‘security reasons,’ the mail() function is disabled. Now I cannot report bugs automatically, nor can the user use the current contact form. Sure, the mail() function could be exploited, but so can almost anything when dealing with a scripting language. Are they going to disable SQL in fear of SQL injection statements?

    The point is that if these servers are going to disable certain, very useful functions, what are they providing as an alternative for their users? They are choosing a little bit more security in exchange for strongly inhibiting their users from creating more user driven web applications.

  • Winn Cards and Comics

    Winn C&C

    The Winn Site is a project I have been working on for a couple of months now. The guys wanted a brand new site- the one they had was, umm, bad. They also wanted an online catalog that they could update, along with the ability to update tournament dates. With that in mind, I got started.

    The design I gave them was a pretty basic XHTML/CSS layout. The logo was one that they supplied, so I went with that color scheme. I used divs to organize the soon-to-be large amount of information in an aesthetically pleasing way. The challege with the design of this site was that they could add as many products they wanted whereever they wanted, and the design had to be able to handle it. The great part about the site, however, is the programming aspect of it. I created a number of functions to print the catalog info, as well as add, edit and delete to/from the site. The back end I wrote is totally custom, password protected, and designed to be pretty ‘liquid,’ meaning easy to update and manage. They have the ability to add products, including uploading a picture [how to on that in a later post], add tournaments, with custom date and time functions, and add categories which automatically become part of the navigation. They can also edit anything, and delete anything. The product page is the best page on the site, using flow control to change what exactly is displayed on the site. The user can also sort any information on the product pages and there is a search function, making finding any product very easy to do.

    All in all it was a good experience, and I learned a lot. I did have experience in coding CMSs before this, such as on my own sites, but this was my first real updatable online catalog. In the near future they hope to add a shopping cart, which it looks like I will also be doing for them. Later!

  • Programming in C

    This semester I am taking a class where it was recently decided the primary language will be C. While I did dabble in C a little bit last semester, I didn’t do all that much. This evening I did our first assignment, which was a simple “Hello World” program in C, programmed on a UNIX machine I telneted into. Here is my slightly more complicated program and some explanation:

    C

    While I would be able to achieve this by printing printf("Hello World");, I wanted to illustrate character arrays and pointers in my program. I stored the string “Hello World” in a character array, because C does have a String object, or any objects for that matter. This will probably be the hardest thing for me to adjust to in C. The line that reads float *ad= &prt is simply assigning a ‘pointer’ variable. In C you can access the actual memory address of anything variable in the program. this is what ‘ad’ is. ‘&prt’ is the actual value stored in the variable ‘prt’. Without the &, I would be getting the address of ‘prt’, and not the actual value. I then print the string, and the address the string is stored in.

    I understand that anyone who has never seen C probably thinks this is very difficult, but I hope to add a few more posts about C, looking more in depth into pointers, addresses, and printf(), among other things. Later!

  • New Facebook Fun

    Facebook

    For all the people out there with Facebook, an online social site for college and now high school students all across America, it got some new features. CollegeV2 has an extensive write up on it here, but I wanted to add my 2 cents in.

    First is the Facebook API. An API is an “Application Programming Interface,” which basically amounts to developers being able to use some of facebook’s programming to make their own 3rd party applications. What it means is (probably) a bunch of new websites and resources for those of us who have a facebook account. And if you are a programmer, you get the opportunity to create some of that 3rd party software and be recognized on the site. If anyone has any ideas, I’d love to help.

    Joseph Casabona's Facebook profile

    What you see to the left is a facebook badge. It is a little add on you can put on your website, blog (live journal, blogger, xanga, etc.), or even your myspace, and it displays whatever information you choose to display from your facebook profile. Mine will be added to the about page, and probably won’t change much. It also links directly to your profile.

    Finally, Facebook Notes. It’s kind of like a blog, but they aren’t calling it that. You can write notes for yourself, about your friends (linking your friends in the note), add pictures, and import your blog, which I did. It seems like a pretty cool idea, and looks A LOT nicer than the MySpace blog.

    That’s all I got! Let me know if you find anything new, or what your thoughts are on the aforementioned in the comments! Later!

  • Uploading Images in PHP

    After dabbling in PHP for some time, and writing an image upload script about 8 months ago, I would like to post it here, with a short tutorial. I have recently reused the script and a friend of mine asked how he would go about doing such a thing. My upload script, to begin, is a function in PHP that returns the path of the image file, which I then add to a database.

    The first thing you must do is set the form up correctly. along with the form name and method (for this, method="post"), you have to specify that you are uploading more than text. Simply add enctype="multipart/form-data" in the form tag. Second, you have to set the permissions on your server to allow uploads. You have to set the Permissions to “777” or Read, Write, Execute for Owner, Group and Public (or World).

    Permissions Image

    Now onto the function. While processing the form, all you do is add something like $image= upload_pic($picName);. This calls the function upload_pic(), passing the argument $picName. The following is an image with well documented code explaining what is going on. For some reason, WordPress doesn’t like it when I code right in the post. At the bottom of the post is a .txt file with all of the code in this post.

    Upload Image Image

    Here is the .txt file with all of the code shown above. If you have any questions, or feel I missed something, be sure to comment on it! Later.

  • OMG MySpace!?

    OMFG

    As many of you might know, I was a big hater of MySpace. This was because of all the emo, 12 going on 20 year olds that infest its system, as well as the horribly (HORRIBLY) done layouts. I mean, they break every rule in the “Book on Good Design,” that is- picture as background, a million animated GIFs, embedded music, super wide layout, no color scheme. It’s all wrong!

    So, I was going to make it my undertaking to fix it up, and learn how to make it look awesome. However, Mike D. of Mike Industries beat me to the punch. Much thanks to Mike D. for the time he spent making it “web developer friendly,” if MySpace could be such a thing. What I hope to accomplish when I get some time (Lord knows when that will be…) is to make it real cool and add some of my own things to build on top of what Mike did.

    What I like about MySpace, after you get through lines and lines of CSS to make it look nice, is the social networking aspect of it that Facebook has. I figure it’s a good way to put my name out there. We will see what comes of it. You can check it out Here. Let me know what you think. Later!

  • Fading Pages in Javascript

    I am not a huge proponent of Javascript. However, I recognize that it is becoming more and more powerful and used, especially since AJAX has become more popular. With a new redesign of one of my sites, I wanted to do something different and cool- so I looked to 24 Ways. There I found a nice tutorial on using the effects from Script.aculo.us. Using that tutorial and some extra programming, I was able to create fading “pages”, which are actually divs we fade in and out.

    First of all, you must follow the 24 Ways tutorial. I have made all of the javascript from that tutorial available in this post, and then my modified combo.js. All of my changes occur in that. Once you read that 24 Ways Tutorial, come back here.

    So by now, you are familiar with all of the files, and the main functions provided in the combo.js. I took combo.js and modified it a little here:

    JS Code

    Notice I added a few lines at the top of the function. On top of that I added this to my main page:

    JS Small

    These codes create and check cookies, which is what I used to check what “pages” were open. When a page is open (when the page is first loaded, it is welcome), a cookie created with the name of that page. When a new page is clicked on, my code checks the cookie to see what is currently open, then closes it. After that, the cookie is rewritten with the new page open. The cookie functions are included in my combo.js. When it is all said and done, we have this. Later!

  • Coding at a new level

    This semester I am taking a class called Machine Organization and Assembly Language. What this amounts to is learning how to program on lower levels than Java and C++. Instead I am [currently] programing right to the hardware, or one level higher. It’s interesting and in some ways more difficult. While there is a lot to know in higher levels like Java, there is more you have to keep track of in Machine and Assembly. Right now we are using a pseudo architecture called “Pep/8” which is a simple ‘machine/OS’. It is not actually used, but servers on an academic level to illustrate.

    Below is some code at first machine level and then assembler in Pep/8. The program reads in 2 single digit numbers and outputs a single digit answer. For example: 2+2 wouls yield 4, which 8+4 would yield 2. Achieve this, I checked to see if the sum was greater than 9, if so, subtract
    10.

    04 00 0B 00 00 00 00 00 00 00 0A 31 00 03 31 00 05 C1 00 03 71 00 05 E1 00 07 B1 00 09 08 00 29 C1 00 07 81 00 09 E1 00 07 39 00 07 00 zz

    …What that results to in Assembly is:

    pep8 assmbly

    To give some perspective, in Java, it would look something like this…

    {
    //read in 2 ints, I and j
    int sum= i + j;
    if(sum >= 10){
    sum= sum - 10;
    }
    System.out.print (sum);
    }

    …Later