Git – move accidental commits to a different branch

If you’ve been working on a common staging branch when you thought you were working on a personal feature branch, you can move your work by doing the following:

git checkout feature_branch
git cherry-pick SHA (Do this for each commit on the mistaken branch)
git checkout staging
git reset –hard HEAD~n (where n = the number of mistakenly committed commits)

This assumes you haven’t already pushed your changes to a common repository.

If you have modified files uncommitted on the staging branch, commit them, cherry pick them into your feature branch, then reset staging as above.

Git – list commits in topic branch that are not within the master branch

git log topic ^master –no-merges

This will list all commits within the topic branch that are not found within the master branch.

I needed this to cherry-pick specific commits out of a working feature branch when I mistakenly rebased against a common staging branch.

WordPress permalink 404 not found with .html or .htm in error message

WordPress will throw a 404 not found error, with either a .html or .htm extension for permalink pages if a file of the same name can be found within the web root directory. So, for instance:

* If you create a new wordpress page called ‘contact’, and
* You create an HTML page called ‘contact.html’ within the root directory, then

You will run into this 404 not found error when attempting to visit the wordpress page at:

Simply remove or rename the contact file within the root directory and the error will disappear.

Rails select method with default value

When using the select form builder method in rails, for instance:

In conjunction with the options_from_collection_for_select method, like :field, options_from_collection_for_select(@fields, ‘id’, ‘name’)

Remember, there is a fourth argument in the above method, which defines the selected value, like so :field, options_from_collection_for_select(@fields, ‘id’, ‘name’, @object.field)

Keep heroku from falling asleep / idling (even with PHP)

Ruby on Rails Scenario

The easiest way to keep a Rails App from idling is to use New Relic Standard (free), in conjunction with their availability monitoring. You can do this in a couple of ways:

Issue the following command with the Heroku Toolkit

heroku addons:add newrelic:stark

Or, login to your heroku account and provision the addon from there.

Once the New Relic addon is provisioned, go to the new relic control panel. You can get there by logging into Heroku and clicking the New Relic addon within your App’s resources dashboard.

Now, complete the setup instructions provided by new relic.

Once you are connected, do the following:

Go into the new relic dashboard for your app
Hover over ‘settings’ on the main top menu
Click “availability monitoring” in the secondary top menu.
Enter the URL of the app you would like to keep awake / keep from idling

By completing the above steps, New Relic will not only Ping the provided URL, but they will actually consume the page’s content. This will keep the Heroku instance awake and it gives you the option to receive an email if it goes down.

PHP Scenario

Heroku, PHP, and New Relic are not compatible, yet. New Relic requires a standalone daemon to be installed on the underlying web server and unfortunately Heroku does not support the installation of that daemon at this time.

So, we can’t use New Relic to keep the Heroku PHP application from idling.

Enter CloudFlare.

Cloudflare is basically an easy (and free) to configure CDN/Proxy.

How does this keep your Dyno from falling asleep? Cloudflare acts as a cache for non-dynamic content (not HTML), which they frequently refresh throughout the day. These requests will keep your PHP app from idling.

Special ultra obvious statement

Only do this if it is necessary for your dyno to remain active all day. If you’re just running a development version of your production site, there is no reason to keep it spinning all day long. This will help to save resources on Heroku’s end, and will ultimately keep the prices down for everyone.

Monitor production resque with local resque-web

This post assumes you are processing background jobs on a development/production environment utilizing Redis and Resque.

If you’re monitoring your local resque instance with resque-web, just run the following commands to change the resque-web’s redis reference to your production redis instance

  • resque-web -K
  • resque-web -r [your redis location]

If you’re using RedisToGo, for instance, you can get the redis location by logging into your account.  If your account is through Heroku, just click the RedisToGo plugin in your app’s dashboard, and the redis location will be in the upper right hand corner.

WordPress on Heroku

I wanted a simple way to push WordPress to Heroku.  It doesn’t get much simpler than this

In regards to using your own custom domain name, the tutorial recommends using A records with a set of defined IP addresses.  Instead, I think the better approach is to use a CNAME record pointing to your Heroku App’s location.  You can find Heroku’s recommendation here:

Additionally, the tutorial doesn’t mention how to change the domain name within WordPress.  To change the domain in wordpress, just do the following:

  1. Login to your WordPress Administrator’s Control Panel
  2. Goto: Main Left Menu -> Settings -> General
  3. Change the WordPress Address
  4. Change the Site Address
  5. Save.

This will take care of the domain name switch.  Just remember to add a CNAME record to your domain’s DNS before completing this step.