Code

  • Quick Tip: Add a Widget to WordPress

    A couple of weeks ago I was working on a WordPress site and thought it might be nice to add a simple widget that allows the user to place my bit of code anywhere in the sidebar they’d like. Here I’ll show you how to add a simple widget to WordPress.

    (more…)

  • 7 WordPress Plugins that Make Your Client’s Life Easier

    preview

    WordPress is becoming an increasingly popular content management system on top of it’s popularity as a blogging system. More developers are choosing it as a solution to enable clients to update their own websites. And while WordPress out of the box is an excellent system, it could use a few tweaks to give most clients the freedom they need. Here are 7 plugins that will make your client’s job of managing their own website easier.

    (more…)

  • Directory Handler at Theme Forest

    I’m happy to announce my first Theme Forest component, Directory Handler. it’s a simple set of 2 classes that handle (in several ways) listing the contents of a directory. The main class, DirectoryHandler, includes several functions that:

    • Get and/or print the entire contents of a directory
    • Normalize the name of a file or directory (replace special characters with spaces)
    • Return the extension of a file
    • Return all of the files of a directory in an array
    • Return all of the sub directories of a directory in an array

    TheImageDirectory class extends the functionality of DirectoryHandler by changing the get and print directory functions to:

    • Print a thumbnail version of the image
    • Integrate lightbox for easy image viewing/browsing.

    You can view a live demo here and Download the full documentation here.

  • Random Code Generator 1.0

    A couple of weeks ago, when I officially launched the redesign, I mentioned the forthcoming release of a plugin I wrote for the redesign. Random Code Generator is that plugin. I needed a plugin that generated a random promotional code and stored it in a database. I’m currently using it on Manifest Development to manage various promotions and ‘prizes’ I have going on, to make sure people can get a code, but cannot use it twice. Here is the official description:
    (more…)

  • Gloss WordPress Plugin

    Today, I officially released my first public WordPress plugin, Gloss. Gloss is a dictionary/glossary management plugin I decided to build which upgrading Manifest Development (more on that later).

    It’s a fairly simple plugin that’s still very much in beta as I’m looking to do user testing on it, since all my WordPress blogs are 2.7 and on the same server. I’ve created a page for it here with some extra instructions, to do list, and feedback form. If you have WordPress, give it a try! It’s much appreciated and I’d love to hear your feedback. Thanks!

  • Google Web Toolkit

    gwt logo

    After I got back from Google I/O, I mentioned Google Web Toolkit was something they showed off that I was very impressed by. It allows you to build complete AJAX applications using Java. In one of my grad classes this semester, we had the opportunity to use Google Web Toolkit (GWT) on a semester long project. After using it I’ve come to the conclusion that is it great, but I’m not sure I would use it for a normal web design project.

    First, here is a sample GWT project I made called “The Decider.” It allows you to add items to a list and then the program will randomly select one for you. This is all done completely asynchronously. I was able to implement it completely in Java (which I think is easier than javascript) and then build the HTML around it using GWT’s ‘Widget’ classes. Again, you’re using Java to build the interface (without using Java Swing). This takes a little getting used to, but you can pick up pretty quickly after reading GWT’s documentation. A nice thing about the widgets is they all have their own CSS class assigned to them, and there are methods that allow you to add, remove, and override CSS classes. You can also build an HTML page with your own CSS id’s and dynamically add things to them with GWT.

    GWT is great is you’re unfamiliar with web design and you want to showcase some project your doing on the web. Google’s default styles look nice and you can really focus on the functionality, especially if the scope of the project didn’t include a web based implementation. It’s also good if you want to roll out a completely asynchronous UI relatively quickly. With The Decider, I didn’t have to worry about the advanced javascript stuff, using something like Dojo or JQuery, etc. I just wrote in Java, which I am pretty comfortable with. However, if from the outset you know you want to make a web app, I’d recommend doing it the traditional way. Writing your own HTML and CSS is semantically correct and less bloated than a GWT project. But of-course, I’m a web developer first, and I just have my feet wet with GWT. I’m willing to bet with a little extra time, due to the freedom you have with GWT you can make that lightweight, semantically correct (tableless!) interface you want with the power of Java behind it. And you can probably get rid of some of the bloat before deploying your app.

    All-in-all, GWT is really powerful and I think it will be a game changer. Next semester, another grad class I’m taking will be using it and I can’t wait to really get under the hood now that I have an understanding of how things work.

  • Freelancers: Generalize Your Code

    One thing that was really driven home during my first year of grad school was the importance of reusable code. Not to say that it wasn’t taught to me as an undergrad, because it was; this year it just seemed to hit harder. As a freelancer in a niche market (small businesses, facebook apps), I tend to generate a lot of similar code. Just recently (within the last few months), I’ve started to generalize that code into reusable PHP objects, and it really helps.

    I point out freelancers in the subject of this post because I feel, at least starting out, it’s not something freelance programmers (or designers for that matter) think to do. I know my concerns were more getting those jobs so I could code, not the process of coding. But whether it be a list of objects you can use on each site, or a HTML/CSS template with variables for the title, key words, headers, etc., you can save a lot of time in the long run by taking the extra time to abstract out the details and come up with something general you can use over a number of different sites. I, for example, have general code for: XHTML/CSS templates (NOT the design, just the general tags that should be applied to every site), [basic] contact forms, [basic] google maps, database objects, image uploading objects and XML parsing objects. Right now I am taking the time to look at other code I’ve done to see how I can generalize it.

    This doesn’t only save time in writing the code either, but in testing. If you have core code that you know works, you don’t need to test for the general cases, or debug that code; just what you’ve added to customize it for that site or app. It’s stuff like this that will increase your productivity and your profits in the long run.

    So generalizing code helps- and not just with time, but productivity and profits. And just about anything can be generalized to some extent. So the next time you code, take an extra moment to think how you can abstract away the details of that project (the variables if you will), and how much of what you are doing is reusable.

  • How to Learn a New Programming Language

    As I said in the last two posts, Google I/O was truly inspiring. It got me to thinking about how I program, what languages I chose to do it in, and what I can do to become a better software developer. Two things I will be doing are getting more proficient with Java (especially for my Master’s Thesis) and learning Python. I’ve begun going through and learning some of the syntax and nuances of Python and found I follow a pretty similar (and effective) pattern for each language I learn. (It’s worth noting that in the following, I assume the reader has at the very least read about programming and has some language to learn in mind.)

    First, pick up a book. I usually go with the for the Absolute Beginner series. It taught me PHP/MySQL and did it in a very effective, modular way. The authors don’t assume you know how to program, but the books aren’t so slow that if you have, you’re bored. They also provide the tools you need to set up your environment, resources, and all of the book’s sample code on a CD. Each chapter takes you through 2 or 3 smaller programs, and builds a full one at the end. In my opinion, they have the perfect combo of code and text.

    Then, build one program. Just one- and continue to expand it as you learn new syntax. I build a “Guess the number” game. It’s a simple problem with an easy solution that you can expand on. My plan of action for this program goes like this, following along with the book I’m using.

    • Basic print statement. Something like "I'm thinking of a number..."
    • Variable assignment. Hard code the first number you want the user to guess. That way you know the right number and can check your logic for the next step. x= 3.
    • Get input from the user/store it in a variable. guess= get_input("What's your guess").
    • If statements. If guess == x: print something, else: print something else.
    • While loop. Do something like prompt to user to see if they want to guess again, accepting yes or no. while keepGoing != no: doing it again

    These five basic steps show you the important basics- input, output, and flow of control. The next few steps could be language dependent, but you can also take some liberties and get creative.

    • Change x to a random value. If the user wants to guess again, the number will now change. x= rand(0, 10).
    • Allow the user to enter five guesses at a time. This will do a couple of things for you- make use of an array, and use a for loop.
    while i <= 5: 
       guesses[i]= get_input("What's one of your guesses?")
       i= i+1
    				
    for guess as guesses: 
       if guess == x: print something, 
       else: print something else
    
    • Write a function/method to check if the guess is correct. It might be a trivial thing to do here, but you're really just doing it to learn the syntax.
    • Create a 'Guesser' class. This of course assumes you're using an object oriented language. Write one class with functions to prompt the user, store the input and make the guess, etc.
    • Finally, try storing the results in a file. Keep a counter for how many times the user, plays, and for each time, store each guess, the actual answer, and if they got it right or not.

    With these steps, you're learning a new control structure, how to use arrays, write to files, and most importantly how to modularize your code through functions and classes. I think with that, you will know enough basic stuff about the language to go off and write some other less trivial programs.

    After that, it's really up to you to dig deeper into the particular language you are learning to really make use of its power. The Absolute Beginner books take you beyond the above exercises and do some language specific things. With PHP, it was creating a web app and connecting to a MySQL database. With Python, it looks like you build a basic game. With Java, you should probably explore Generics or threads. Either way, once you learn the basic syntax, it's time to harness the true power of the language.

    My last piece of advice is to pick up the O'Reilly cookbook for that particular language. They're usually for a more advanced user of the language, but are extremely helpful in doing specific things. The PHP and Java Cookbooks have helped me immensely.

  • Learn a Programming Language

    Over at LifeHacker, they are hosting a spirited discussion on what the programming language to learn first is. I think this is a pretty interesting discussion to have and want to comment on what the others are saying, as well as justify my stance. First of all, I did weigh in, saying:

    I’d say if you’re not going to be a serious applications programmer, learn some weak-typed language like PHP or Javascript first to get your feet wet with program logic without having to worry about whether your types (the difference between say a number and a word) are correct. This will help you with the control structures(if statements, loops), how the logic works and how to solve some basic problems. Then you can move on to a more advanced language and learn the different types, objects, etc.

    Many of the others who commented said that Javascript is not a programming language, it’s a scripting language. Is there a huge difference? Maybe, but not to someone first learning. They will not be doing things a programming language calls for- they will be learning control structures and how a program works, what kind of logic goes into writing a program, etc. To be honest, I first learned Java when I was a freshman in college, but I didn’t really understand programming until I picked up PHP over winter break of that academic year. So is there a difference? Sure. Is it a huge deal to someone starting out? Not at all.

    Then we’ve got those who say, “Learn C first, it’s the best” or someone even said, “Learn Assembly.” I know how to program and Assembly is hard. You’re not writing code in something that looks remotely like English and you need an understand of how data is represented on a machine. It sort-of applies for C too, as C is a low level language. Don’t get me wrong, C is the best language I’ve coded in- it’s fast and you can do really powerful stuff. But I think pointers alone is enough to turn someone off to C and programming in general.

    Finally, we’ve got those who say learning an Object Oriented (OO) language is the way to go. I can see that. I feel there is enough abstraction there that the learner might be ok. They shouldn’t dive right into object, however, because objects are pretty difficult to visualize if you’re just starting out.

    I still say my approach is at least a good one. Learning a simpler language that doesn’t put restrictions on data types will allow the learner to focus on program logic more than data representation. They will begin how to think like a programmer and can move up from there. PHP isn’t a bad place to start because it acts like a simple language (weak typed, syntax is pretty easy to understand), but you can do some powerful things like create objects.

    Teaching yourself to program is a pretty daunting task to begin with. However, if you pick up a good book and start with a simple language, you should be fine.

    PS- HTML is not a programming language. It’s a Markup Language. You will not learn anything about programming.