February 13, 2010

The new Little Black Hat

Kevin Hallmark @ 9:41 pm —

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. 🙂

January 28, 2010

Remote Debugging PHP on Mac OS X using xdebug and MacGDBp

khallmark @ 4:38 pm —

A debugger is one of the most powerful development tools available. However, with PHP, debugging a site can be tricky. A lot of times, the host you need to debug is remote. Xdebug, the PHP debugger, solves this problem with their remote debugging feature.

Unfortunately, getting remote debugging with xdebug setup on Mac OS X can be a little tricky. This tutorial will help you setup your environment for easy remote debugging using Xdebug and MacGDBp.


» read more

November 5, 2009

PHP 5.3 and the dangers of ‘goto’

khallmark @ 9:14 pm —

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

July 2, 2009

On the dangers of goto

khallmark @ 12:27 pm —

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.

http://xkcd.com/292/

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).

May 29, 2009

Setting up Tomcat 5.5 on Mac OS X 10.5

khallmark @ 8:38 am —

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.

Installing Tomcat

  1. 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)
  2. 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.
  3. 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.
  4. Open Terminal.app (/Applications/Utilities/Terminal.app)
  5. Navigate to DIRECTORY
  6. Type “./bin/startup.sh” into the Terminal and hit enter
  7. 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

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

  1. Add this line to /etc/hostconfig as root:
    TOMCAT=-YES-
  2. Open the downloaded archive, it should unzip to a folder called Tomcat
  3. Open up the file named “Tomcat”
    1. Update line 12 of the script to point to your DIRECTORY
      export DIRECTORY=”/opt/local/tomcat”
    2. Update line 15 to point to the version of the JDK you want to use
      export JRE_HOME=”/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home”
  4. Copy the Tomcat folder to /Library/StartupItems/Tomcat
  5. Open Terminal.app and type the following commands
    1. cd /Library/StartupItems
    2. sudo chown -R root:wheel Tomcat
    3. sudo chmod -R 755 Tomcat
  6. Use the script to start/restart the server by typing 
    /Library/StartupItems/Tomcat/Tomcat [start|stop|restart]  
  7. The server will now start on boot
  8. TIP: You might want to add an alias to this script in your .profile
    alias tomcat=”sudo /Library/StartupItems/Tomcat/Tomcat” 

April 30, 2009

In Pursuit of the Perfect Dev Environment: Textmate PHP Syntax Validation

Kevin Hallmark @ 10:07 am —

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!

http://cssgallery.info/textmate-php-syntax-check/

April 16, 2009

Essential Safari Web Developer Plug-ins

Kevin Hallmark @ 12:56 pm —

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.

April 3, 2009

Reverse Engineering MySQL Queries in web apps

Kevin Hallmark @ 10:26 am —

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.

February 12, 2009

Getting xDebug Working on Mac OS X with MacPorts

Kevin Hallmark @ 3:25 pm —

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)
zend_extension="/opt/local/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

; General config
;Dumps local variables on exception
xdebug.show_local_vars=On
;Dump server variables
xdebug.dump.SERVER=*
;Dump global variables
xdebug.dump_globals=On
xdebug.collect_params=4;

; Tracing
xdebug.auto_trace=On
xdebug.trace_output_dir= /opt/local/php_traces/
xdebug.show_mem_delta=On
xdebug.collect_return=On

; Profiler
xdebug.profiler_enable=1
xdebug.profiler_output_dir=/opt/local/php_traces

; Debugging. You might need to specify your host with some additional options
xdebug.remote_enable=1

For viewing profile output:
http://www.maccallgrind.com/

You will use this program to open the cachegrind.out files in /opt/local/php_trace

For using the debugger:
http://www.bluestatic.org/software/macgdbp/

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()

May 27, 2008

Orlando PHP Meetup

Kevin Hallmark @ 2:50 pm —

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!