Welcome to the new Little Black Hat site. Over the next few months, I’m going to be adding some great new features to the site. First, I’m planning to add a project gallery to the site. This will let you see what I have been up to. I’ve also got a few projects to open source, so those should be coming soon as well. For visitors looking for information about my services, there will be something for you too. Overall, I expect things to happen here much more regularly. I love coding sites from scratch, but WordPress helps me in this time crunch world. No need to reinvent the wheel. 🙂
PHP 5.3 came out recently. For better or worse, the great PHP gods decided it would be a good idea to add ‘goto’ to the language. Up until now, PHP has never had ‘goto’. The question I’ve been bouncing around in my head is “Why?!”. In my 15 years programming (yes I really have been programming since the age of 10), I don’t think I have ever used a “goto” statement in a real program. Maybe in my first Hypercard stack, or using Basic in my 7th grade computer class, I may have.
My stance has always been, and will always be, ‘goto’ is a crutch for the lazy. It enables bad design. Sure, it might be easier to code one rare algorithm using a ‘goto’ statement. This is not the majority. The majority of algorithms can be implemented without ‘goto’, it just takes more thought. I cannot think of any algorithm that requires ‘goto’.
» read more
I had this big long essay prepared, ranting about how much I hate ‘goto’, and why it’s so evil (especially in php). However, xkcd has made that all irrelevant.
Remember kids, friends don’t let friends use ‘goto’. It gets you eaten by a velociraptor. Or grue (if you’re coding in the dark).
Installing Tomcat 5.5 on Mac OS X 10.5 is a fairly easy process. I have adapted and distilled these directions from the Apache Foundation Tomcat Wiki. I also have modified the provided Startup Item provided on the wiki and I have made it available for download from this site.
- Download Tomcat 5.5 from the Apache site. You’ll want to download the latest version of the “core” package (this is all you need to get Tomcat started)
- Put the contents of the package in your favorite install location. From now on we’ll call it DIRECTORY. I choose to put mine in “/opt/local/tomcat” because this is the location of my MacPorts files. You could easily put it anywhere. Remember DIRECTORY, you’ll need it later.
- Fix the permissions. The recommendation by wiki is to set wide open permissions, to make all the files 777. Realistically, I feel like there should be a more restricted permission set that should work.
- Open Terminal.app (/Applications/Utilities/Terminal.app)
- Navigate to DIRECTORY
- Type “./bin/startup.sh” into the Terminal and hit enter
- Test the server by going to http://127.0.0.1:8080. You should see a the default Tomcat page, which looks like the image below.
Tomcat is working properly
Installing the StartupItem
Once you get Tomcat installed, you’ll probably want to install the StartupItem as well. This will allow Tomcat to start on boot.
Download the archive
- Add this line to /etc/hostconfig as root:
- Open the downloaded archive, it should unzip to a folder called Tomcat
- Open up the file named “Tomcat”
- Update line 12 of the script to point to your DIRECTORY
- Update line 15 to point to the version of the JDK you want to use
- Copy the Tomcat folder to /Library/StartupItems/Tomcat
- Open Terminal.app and type the following commands
- cd /Library/StartupItems
- sudo chown -R root:wheel Tomcat
- sudo chmod -R 755 Tomcat
- Use the script to start/restart the server by typing
- The server will now start on boot
- TIP: You might want to add an alias to this script in your .profile
alias tomcat=”sudo /Library/StartupItems/Tomcat/Tomcat”
cssgallery.info has an article about validating your PHP syntax automatically on save using Textmate. This is incredibly valuable. No more uploading files with bad syntax!
So I’ve been gathering a lot of different Safari plug-ins and I thought it was time to document me development setup. This is a list of plug-ins that I use with Safari to really help me get things done.
Essential Developer Plug-ins
These are plug-ins I can’t live without. I usually put these on any machine I have to do development work with. I can’t work without these plug-ins.
- SafariTidy – This plug-in gives you a bar at the bottom of Safari much like the HTML Validator for Firefox
- Forget Me Not – Saves your tabs and lets you reopen them with Cmd+Z (in case you accidentally close one you don’t want to)
- XML Viewer for Safari – This plug-in let’s you view XML in a nicely formatted way, instead of just the text inside the XML.
Nice to have plug-ins
These are plug-ins I don’t put on every machine, but I’ll usually put them on any machine I use on a regular basis.
- DeliciousSafari – Integration with Delicious into Safari, including a links menu in the menu-bar and an add to Delicious button. I know there are links you can put on the Bookmarks Bar, but I like this solution so much more.
- SafariStand – Allows you do inline HTML modification, gives you a visual Tab Shelf and some other nice goodies. Might be obsolete with Safari4, but I haven’t upgraded yet.
- Safari AdBlock – Finally a free AdBlock plug-in for Safari that actually works. It uses the Firefox plug-ins file format for fast updates
These are only a few of the plug-ins that are available for Safari. I’ll keep this list up-to-date as I discover new ones.
So here I am, sitting at work. I’ve been tasked with reverse-engineering the login system for this website. Ugh. The code is spaghetti. Queries are a mish-mash. How do I figure this out?
What I discovered is that you can log literally every single mySQL query made to the server. This is really useful if you need to figure out crazy things like what queries run when new user is inserted.
Add the following line to your my.cnf file:
log = /var/log/mysql/mysql.log
This gets rid of the hassle involved with finding and tracing mysql queries directly.
xdebug is a powerful PHP debugging tool. With xdebug you can get all sorts of debugging out, stack traces, and memory usage (as well as delta). It also gives you classic code-stepping tools and breakpoint. Finally, you can debug your PHP applications! Getting it working on Mac OS X has been a bit confusing, but this how to guide will give you all the tools you need!
Before we proceed, you have MacPorts installed right?
So how do we go about getting xdebug? First, install xdebug:
sudo port install php5-xdebug
Next enable xdebug. All this goes in your php.ini
; NOTE: This line adds the xdebug extension. The macports install will give you the path,
; or may even add this automatically. Be smart, look for a similar line in your config first.
; (Edit: 06/22/2012)
; General config
;Dumps local variables on exception
;Dump server variables
;Dump global variables
; Debugging. You might need to specify your host with some additional options
For viewing profile output:
You will use this program to open the cachegrind.out files in /opt/local/php_trace
For using the debugger:
Just put “XDEBUG_SESSION_START=session_name” in your query string. Session_name can be any alphanumeric string.
You can set a breakpoint with: xdebug_break()
Next Tuesday at the Bonnier Corporation offices is the Orlando PHP Meetup. We’re going to be doing a code-shootout comparing Zend Framework, CakePHP, CodeIgniter, and Symfony.
I’m going to representing Zend Framework.
The goal is for each developer to create the same application using each framework. Each developer is already up to speed with their respective framework, to eliminate the learning curve for each framework.
Which framework will reign supreme? Show up and find out!