How to remove added files from Perforce Before Committing

Posted on December 2011

Recently, I’ve begun using Perforce, and adjusting to it from Subversion and Git usage has been a little bit of a challenge. While attempting to delete a few files that I added and no longer, needed I tried running the following snippet:

p4 delete left*

and received the following error.

leftBottom.png - can't delete (already opened for add)

If you’re trying to delete files in the future and you haven’t committed them yet, I’ve found that doing a revert command will solve the issue. Here’s the example below that worked for me.


p4 revert left*
leftBottom.png#none - was add, abandoned

Adding a Background Image to a UITabBar

Posted on February 2011

Here’s a little snippet that proves to be useful from time to time, when you need to apply a background image to a UITabBar.

Adding a Background Image to a UINavigationBar

Posted on February 2011

Here’s a little snippet that proves to be useful from time to time, when you need to apply a background image to a UINavigationBar.

Adding a Drop Shadow to a UINavigationBar

Posted on November 2010

For the past few days, I’ve been trying to figure out a way to apply a drop shadow to all of the UINavigationBar instances without having to create alot of extra work by subclassing the UINavigationBar, and also having to sub class the UINavigationController.

After reading a few Stack Overflow posts, I was able to successfully create a category on UINavigationBar that applies the drop shadow successfully.

Finding the Average Value of a column on a Core Data Entity

Posted on October 2010

I’ve been having trouble the past few days finding the solution to this question.  It was in the Core Data documentation, but considering how vast it was, I hoped that a simple Google query would have provided my answer. Here’s the original question over at Stack Overflow, and here’s a snippet of code I used to succesfully get the average value of a column on one of Core Data entities.

Hacking the Hootsuite Chrome Extension

Posted on August 2010

Over the past few weeks I’ve been using Hootsuite alot more, but one of the things that really frustrates me is that I couldn’t use the Chrome extension as well as I would like, because the modal window would open with a static height, and when I would try to generate the Facebook Preview Image and text, the content would run out of the modal window.

Since Chrome extensions are mash up of HTML, CSS, and Javascript, I figured it wouldn’t be too difficult to fix this problem. Here’s what I ended up doing.

Step 1. Find the Files

On OSX you can find your Chrome Extensions under ~/Application Support/Google/Chrome/Extensions/

* for those of you who don’t spend alot of time at the command prompt ~ represents the path to the User’s home directory, which in OSX is /Users/profilename

Step 2. Navigate to line 976 of  js/global.js in the plugin’s directory and replace it with this.

Step3. Save and Restart Chrome

Grepping A Log File

Posted on March 2010

Scenario: A user takes an online survey. The user’s record is updated as having taken the test but not completing it. The user claims to have taken the survey, and wants to know what went wrong in the system. Caveat: The user took the test over a month ago.

After connecting to the server and combing through the code, you find nothing that indicates an issue should have occurred. In a lightbulb moment, you decide to check the log files for errors. One small problem. The log file is 10MB large, and has data in it that goes back over a year.

What should you do? Grep to the rescue.

Validating Robots.txt Files

Posted on March 2010

This week at work, one of my coworkers came across the following scenario.

Months ago, all of the content on our development server for a client’s domain got spidered. Apparently Google trusted our domain more than the clients, due to a number of factors, so in the organic results, the development server url was outranking the production server url.

To alleviate this problem, one of our developers setup a very strict robots.txt file that disallowed all robot traffic, on this development version of the site.

Somewhere down the line, this robots.txt file got deployed to the production server. We’ve since resolved the problems this caused, but we started to wonder if that may have happened to any of our other sites.

We have worked on nearly 600 domains in the past few years, so it would be a tedious task to manually check all of these sites.

I wrote this little nugget of goodness below to solve this problem. It pulls a db table of domains that we’ve worked on, checks to see if bots are allowed on the live site, and generates a report of those sites that aren’t setup correctly.

I plan to expand it a little more, including setting it up on a cron job and generating emails nightly when a domain is setup incorrectly.

Updating Related Records With Doctrine Hooks

Posted on February 2010

On a project that I am currently working on at work, a unique problem presented itself.

Take into account the following relationship:

UML Diagram of Users, Profiles, and Activity Logs

The above diagram is incomplete, but signifies the problem we are seeking to solve. The steps field in Profile is an aggregate of the steps that exist in each activity log related to a profile.

While this could have been designed to dynamically calculate this field, given the scope of the application, number of users, and the critical nature that steps present to ranking user profiles, it was decided that steps become a field that would be updated manually when it needed to change.

Because of this we found a small problem:what happens when a user updates an activity log in such a way, that it changes the value of steps.

Thanks to some handy Doctrine Magic, the following snippet provides our solution: postInsert and postUpdate hooks in the ActivityLog model that update the steps field in the related Profile.