May 4, 2015

Viewing the progress of a MySQL command line Import

khallmark @ 4:20 pm —

Instead of importing from a dump file like this:

mysql -uxxx -pxxx dbname < /sqlfile.sql

You can use a utility called “pv” (pipe viewer) to view the progress of an import. This will show you a nifty progress bar that will let you see the estimated progress through the file. This program works by reading each line of the file, updating the progress bar, and passing the line of SQL code to the MySQL console.

pv sqlfile.sql | mysql -uxxx -pxxxx dbname

You can install the command in an Ubuntu environment using the command:

sudo apt-get install pv

or you can install it on a Mac using MacPorts with the command:

sudo port install pv

December 10, 2010

PHP is falling apart (or Why we need ‘finally’)

Kevin Hallmark @ 11:58 am —

PHP is crumbling.

PHP 6 was delayed for years and now sits abandoned as they restart the effort. In the meantime, a bunch of features are being backported to PHP5.x branches. Each new 5.x release has more features from what would have been PHP 6. PHP is stagnating.

The PHP core team has fallen apart. There is no leadership. There is no guidance. There is no logic. There is just a cobbled together release of miscellaneous features that are somebody’s baby.

For example, ‘goto’.

‘Goto’ should not be implemented in any modern language, period. It’s not needed. Yet, PHP chose to implement this in version 5.3! The reasons for adding this were dubious at best, showing a lack of language design skills. You can read all about my opinion on goto here: http://www.littleblackhat.com/blog/2009/11/php-5-3-and-goto/

I recently found this little gem on the php website: http://bugs.php.net/bug.php?id=32100 (thanks @lesmothian).

The best (and only) comment we get about why there is no ‘finally’ block is “We’ve had long discussions and came to the only conclusion that we don’t need that, for more search the mailing list archieves(sic).” Of course, that conversation can’t be found in the list archives. Does that matter? Of course not.

Finally is part of many modern programming languages: Java, Javascript, C#, Ruby, Python, Objective C, Perl, VB.net… the list goes on. Many of these languages and their designers abhor ‘goto’ and praise ‘finally’.

The use cases for finally assure proper memory management and resource deallocation. Without it, the chance for a mistake in control structure flow increases significantly. Additionally, unless I reraise the exception, it short circuits my app wide exception handling code. Reraising deletes runtime information about the source of the error.

Finally results in cleaner more reliable code. It should be implemented in PHP.

This essay only touches on the idiotic decisions of the PHP team. First ‘goto’, now ‘finally’. Suffice to say, I am getting less and less attached to PHP by the day. I hope that one day the php team gets some leadership again.

May 12, 2010

Google launched a new design, and I hate it

khallmark @ 10:15 am —

Update 2:

Apparently, you can get the old interface back with a little hack.

http://www.gtricks.com/google-tricks/how-to-get-old-google-interface-or-layout-back/

Update:

You can complain here: http://www.google.com/quality_form

For uniformity, let’s complain using the same options. Select the option from my screenshot below.

Dear Google,

The new left navigation is horrible. Don’t get me wrong, I like the functionality the left rail exposes. I like being able to easily filter my results by content type, date, etc… but I don’t want those features in a left rail.

Simply put, the left rail undermines what originally made Google great: simplicity. Google has always been visually simple, allowing me to easily scan search results. The new left rail is just a distraction. It takes some of the most valuable screen real estate and fills it with something that is not always needed.

The most important information on the page is my search results, not the sorting, filtering, or ordering therein. When I use Google, I want to access search results 100% of the time. The algorithm is so good, most of the time I don’t even need to refine my results because the answer is right there. I want to filter my results significantly less often.

The search filtering might be better suited to a right rail: there when I need it, ignorable when I don’t.

The new left rail also removes an important visual cue from the page: the browser left edge. My brain naturally tracks to the left edge of the browser window, much like reading a book. Now, instead of shiny clean search results, I get the left bar. While there is still a line for visually tracking the edge of search results, its soft coloring doesn’t give you a strong visual cue for the left edge of the content area; the contrast between the browser edge and the page is still a stronger cue. I end up scanning to the left edge of the browser, bringing my attention back to this evil left rail.

I understand that you want to advance your search engine, exposing more features to your customers. I’m all for it. However, those changes should not come at the expense of a tried and true product. You should let long-term customers retain their current configuration, if they desire. Give users the new look by default, but let account holders turn it off.

Remember “New Coke”? Instead of replacing their tried and true product, they could have released it alongside their flagship product. Don’t repeat the mistakes of your predecessors!

Please don’t make me hack it away.

Thanks,

Kevin

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.