Helpful Code Snippets (and app ideas!)

This post is about sharing my ‘Programming Notes and Code Snippets’ document, which I’ve been building on-and-off for a while in the hopes that it might help some of you solve a programming question you have or save you time while you’re building your code project.

I’ve also found this document to be very handy for coming up with new app ideas to get me started using new languages or tool chains. It’s how I got started on Quoats.

Google Wave used to offer this really awesome document embedding feature that doesn’t appear to be available with Google Docs (am I wrong? Correct me, please!), so I’ll just include a link to my code snippets document and an iframe version below.

Note that on all of the code snippets I include a link back to the source that I’m referencing. If these are in error or you’re the owner of the content and want it removed, be sure to drop me a line and I’ll correct the problem. As it is, these code snippets were found scattered across the Internet and this work-in-progress document merely hopes to compile them into something useful.

Enjoy and happy coding.

It’s baaaaack!

Kool-Aid Man

Image via Wikipedia

After a now completed year-long project took my full attention, I’ve re-launched my blog. It feels great to be back. Taking it down was a mistake as I really enjoyed the outlet; sharing PHP tips & tricks, and releasing news about projects that I’m a part of is a lot of fun and good for the soul. So, I’ll be getting back into the swing of things, posting often once again.

It’s amazing to look back and see how much stuff has happened in a year. I’m flipping through my older posts and remembering them like they were a decade ago instead of  just one year!

A few geeky points about the blog:

  • It’s HTML5 WordPress. Oh, yeah! (cue Kool-Aid Man)
  • It uses Microformats (I love these things)
  • The theme is my own design built off of the WordPress Toolbox theme
  • http://www.stiligececilie.net/ provided the amazing free FB, Google, etc. icons under my Twitter widget. If you’re into graphics design, you have to check out her stuff. It’s awesome.
  • It’s got some kick-ass jQuery that lets you scroll infinitely through my posts instead of pagination
  • This will be my 101st post. Sort of makes sense to cross that line when I relaunch :)

 

Enhanced by Zemanta

Develop Locally With Linux, Apache, MySQL, and PHP

PHP
Image via Wikipedia

If you’d like to develop PHP and MySQL web apps in Linux but you’re not sure how to get started then feel free to follow along with this blog post. For the most part, installation and configuration is simple and straightforward.

Though this article is directed toward users of Mandriva Linux (my Linux distribution of choice for a desktop / web-development PC), the same instructions can apply to many of the different Linux distributions including Fedora, Red Hat Enterprise Linux, Ubuntu, and Eeebuntu. For a huge list and up-to-date news of Linux distributions available to you, take a look at the Distrowatch news site.

The easiest way to install all of the software in the LAMP stack (Linux Apache MySQL and PHP) quickly is to do it using the command-line (also known as the console). Since many new users are uncomfortable with the command-line, feel free to do all of these installations graphically using the software installer from your respective distribution.

If you’d like to proceed using the graphical installer built into Mandriva Linux, use the “Install & Remove Software” icon located in the main menu.

To install apache, mysql, and php using the Mandriva command-line, follow these instructions:

  • Open up a terminal by clicking on the Mandriva star and clicking on Terminal
  • Type “su” and press enter (this will log you in as the administrator or “root” user)
  • Enter your root password
  • Type “urpmi apache php mysql phpmyadmin nano”
  • If asked which version of apache, select a stable version to install (likely the first choice)
  • If asked which version of php, select the apache module version (not CGI or CLI)
  • If asked for permission to install extra software that is required for proper operation of the LAMP stack, select “yes” and proceed

Once the software has been installed, you should be able to open up Firefox and navigate to http://localhost . This should bring up a screen that says “It works!”, meaning that apache has been properly installed.

For reference, Mandriva Linux puts your web files in the directory /var/www/html . Straight away you may not be able to access those folders with your regular user so feel free to change the permissions of the directory recursively by using the command

  • chown -R yourusername:yourusername /var/www/html

Note that this operation is definitely not secure if you plan on actually hosting your website on the live Internet using this computer, but for local development you should be okay. :) To learn more about file and directory permissions in Linux, take a look at the official documentation.

Before you are able to access your databases through phpmyadmin, you will need to set your MySQL root password using the following command (being sure to change NEWPASSWORD to a password of your choice):

  •  mysqladmin -u root password NEWPASSWORD

Using Firefox (or whatever browser you normally use) navigate to http://localhost/phpmyadmin . Log into MySQL with your “root” user and the password you just entered into the command-line. This should give you access to your MySQL databases. For more information on how to use phpmyadmin, take a look at the official website.

Let’s create a small Hello World PHP web application by navigating to our web directory and creating it. Use the following commands to achieve this:

  • cd /var/www/html
  • nano test.php

In the editor screen that appears, enter

  • <?php echo "Hello World!"; ?>

Press CTRL-X and save the file before quitting. You should now be able to navigate to http://localhost/test.php and see your hello world application :)

Hopefully this has given you enough information to get you up and running. Please feel free to post comments if you’ve run into problems and hopefully I or another person in the community will be able to help you out.

Have fun with PHP on Linux!

Reblog this post [with Zemanta]

Singleton To The Rescue, A Quick Update

Things have been crazy busy lately with work (both the full-time job as well as the freelance work I’ve been doing) and as such I haven’t had a chance to do a full blog post in a while. I appreciate all the great feedback I’ve been getting about the blog, though — I’m glad it’s helped a few of you already (and I’m not even to 100 posts yet!). Keep checking back as I’ll likely be putting up a few solid articles in February (possibly the continuation of my Subversion article!)

I just wanted to quickly post a link to a totally fantastic article I found about using the Singleton pattern for a database object. This is one of those times as a blogger where instead of re-inventing the wheel by writing about a similar subject you’re just better off setting your users up with a link to the best of the best and let it stand on its own. If you’re interested in learning more about the Singleton pattern, look no further.

I’m using a database class based off of the code in the article for a few of my projects currently, and I have to say, it works great. Let me know what you think!

Aptana Color Themes

Aptana Studio Rules

Aptana Studio Rules

When I develop at home and at work I use Aptana Studio. I purchased a license for myself at home and I use the community edition (read: free version) at work. It’s a wonderful editor with a ton of features and great community. One thing it lacks, however, is a good set of themes, out-of-the-box.

So what, you ask? Just go and download some third-party custom themes from the web!

Pishaw! It’s not that easy. I’ve done a few Google searches but not a whole lot turns up, to be honest. And that’s a shame because I bet a lot of developers are in the same boat as me.

I’ve been tinkering with themes over the past few weeks and I’ve decided to start releasing some on my site for everyone to use. The themes page will grow over time as I continue to release themes. I’d appreciate any feedback you have. The Aptana Themes page is not only for my themes, they also include some of the best themes I’ve found around the web. If you have a theme you’d like me to put up, send it to me and I’ll do just that.

Anyway, without further ado, I present the Aptana Themes page!