Showing the current breakpoint name when testing responsive designs using only CSS

on

In building a new version of this website (yes, exciting I know!) I was looking for an easy way to see which current breakpoint was being used in the responsive layout. The quickest and easiest way before testing on specific devices is to just resize the browser. So I wanted a way to see when a certain breakpoint would take effect.

Turns out, there’s a pretty simple way to do this purely in CSS. continue reading…

Properly handling naked domains and SSL on Heroku

on

If you’ve used Heroku in a production environment you may have noticed their avid warnings about using a naked domain on the service. This would be a domain like example.com, with no subdomains, including the www subdomain. However, that doesn’t mean that all businesses (or I’d argue most) are able to require a subdomain, even www, for all traffic. You simply can’t stop users from typing in example.com no matter how much you market www.example.com. They have sound points as to why you want to avoid them but there are a few tricks to make this work as reliably and securely as possible. After discussing with their support team on several issues, here’s the final solution. continue reading…

An Old Man Learning to Play Ice Hockey, Part I

on

Part 1: The Introduction

As a kid I was never very interested in playing organized sports. Sure, I played pick up games with the kids around the neighborhood all the time. Football, street hockey, you name it. But in general, playing for an organized team was never very high on my priority list. That is with the exception of one sport: ice hockey. It was the era of Mario Lemieux, Jaromir Jagr and two Stanley Cups, after all. The problem, as I’m learning now, is that playing ice hockey is fucking expensive. Sorry for the language, but trust me, it’s expensive enough to earn an expletive. Anyway, my parents could never afford it, though I know they wanted to. It was easy enough for me to forget it though and I eventually retreated happily to playing punk rock as my after-school activity of choice.

Fast forward fifteen or so years continue reading…

delayed_job in Rails 3

on

I searched for how to use delayed_job and Rails 3 on Google last night and went down a little rabbit hole I thought I could try to help someone else avoid. I ended up at http://www.dixis.com/?p=335 which provided a great, but out of date, article on how to do this. It recommends using collectiveidea’s fork of delayed_job in the master branch, but as it turns out the latest in the master branch in is in flux at the moment. The ActiveRecord backend is currently being abstracted into it’s own gem (which is a great idea) but that means the generators to make the database tables are no longer there. It also in general seems not ready for prime time.

continue reading…

New jQuery plugin: Fix on scroll

on

I added a new jQuery plugin that will fix an element to the top of the browser window once you scroll past it, similar to the functionality of the actions bar in the newest gmail UI.

Find it at https://github.com/jonathandean/jquery.fixOnScroll

Here’s a quick sample usage. Let’s say I wanted to make a sidebar element with an ID of sidebar stay fixed after I scroll past it, I would just do:

$(document).ready(function(){
  $('#sidebar').fixOnScroll();
});

If the top of the sidebar is below the top of the browser window it will just stay in it’s normal position until you scroll past it, at which point it will stick to the top of the browser window and always remain visible.

There are more usage examples on the README page of the git repository

Running older versions of Selenium RC and keeping Firefox 4

on

Some older versions of Selenium RC don’t work properly with the new Firefox 4 (we are using 1.0.3 I believe.) The best solution is to upgrade your version of Selenium to at least 1.0.4 I’m told, but we aren’t able to do that for our project. So here is a way you can run Firefox 3 and 4 on the same computer so that you can use Firefox 4 as your primary browser and allow Selenium to launch Firefox 3 (even while Firefox 4 is already running.) For the moment I’m short on time so you’ll have to refer to some external articles and change a few of the steps. Time permitting I will try to consolidate all steps into this article to make things easier to follow and just in case those articles become unavailable at some point.

continue reading…

Installing meld diff tool on OS X Snow Leopard (using fink)

on

Install fink

First we’re going to install fink as it will provide an OS X-ready version of meld for us (and quite a number of other UNIX programs as well). At the moment you’ll need to install fink from source for Snow Leopard (OS X 10.6). If you’re using another version of OS X there are binaries available for 10.1 to 10.5 on the main downloads page. The download for the source version is located at http://www.finkproject.org/download/srcdist.php. The latest version at the time of this writing is 0.29.10 and can be found directly at http://downloads.sourceforge.net/fink/fink-0.29.10.tar.gz. Download and save that file somewhere.

continue reading…

Git tip: merging the latest version of one or more files from another branch

on

Today I was working in two separate branches in git and wrote a jQuery plugin that was useful to both branches. The problem was that I committed this new file along with changes to other files in order to use it. So I didn’t want to use cherry-pick to grab the commit because I didn’t want the other changes from that commit. There’s also the case where there are many commits involving that file in the other branch and you just want the most up to date version of that file. Turns out there’s a simple way to merge the latest version of a file (or even multiple files) from another branch into yours. Just follow this syntax:

git checkout <other branch name> <path(s) to file(s)>

Example of a single file:

git checkout new_feature public/javascripts/jquery.newplugin.js

Example for multiple files:

git checkout new_feature public/javascripts/jquery.newplugin.js public/stylesheets/jquery.newplugin.css

Then you can commit and you’ll have that file in your branch without causing any git ugliness.

Resource (and a little more detail) on Jason Rudolph’s blog.

Fixing blank pages after upgrading to WordPress 3

on

Today I finally clicked the auto-upgrade button to upgrade my WordPress site to the newest version, 3.0.1. I then noticed that I wasn’t seeing the content of a lot of my pages. I could still see the lists of posts but I wasn’t getting anything on a single post or normal page. I verified the data was in the database.

Here’s what my page.php looked like:

<?php get_header(); ?>
<div id="pageWrapper">
	<h2><?php the_title(); ?></h2>
	<?php the_content(); ?>
</div>
<?php get_footer(); ?>

This was all fine and dandy for WordPress 2.x but obviously wasn’t working for 3.0. Turns out the solution is quite simple. I just need to put the_content() back into "the loop":

<?php get_header(); ?>
<div id="pageWrapper">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		<h2><?php the_title(); ?></h2>
		<?php the_content(); ?>
	<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>

I’m not sure why the change but I suppose I should have always explicitly used "the loop". Maybe I was taking advantage of a bug this whole time? Or maybe this was an intentional change that I should have seen coming. At any rate, if you see your content missing after an upgrade, take a look at your theme and make sure the_content() is always inside "the loop".

Dynamic config files in Symfony

on

Don’t like the idea of manually setting certain values in your Symfony YAML configuration files? Or maybe, like in my case, you want the value of one setting to be set based on the value of a previous one, maybe a calculation of other values for instance. It may not be obvious at first but you can include PHP blocks in your config files. You just need to be a little careful about the line endings in order for it to work properly. If you take a look at your apps/application/config/settings.yml there’s already an example in there in how to achieve this:

dev:
  .settings:
    error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>

Here’s a (silly) example of what you may want to put in your app.yml:

<?php $i = 10; ?>
all:
  numbers:
    option1: <?php echo ($i++) . "\n" ?>
    option2: <?php echo ($i++) . "\n" ?>
    default: <?php echo $i . "\n" ?>

Just note “\n” at the end of the line as this is important. Without it the newline character won’t be added and the resulting YAML will be malformed. Also be really careful not to put any spaces or anything in front of a PHP block that doesn’t output anything, such as the first line in that example since that will also be malformed YAML. Just always remember to think of what the output will look like and that it must be valid YAML.

Note: I’m using Symfony 1.4 and haven’t verified this in other versions.

Dividing numbers in Ruby returning zero or an integer unexpectedly?

on

There’s a “quirk” about Ruby that I often forget when going back to it after a long period of time using other languages. If you divide two integers in Ruby then it’s going to give you an integer as a result. Consider the following:

some_int = 3
another_int = 2
answer = some_int / another_int  # answer is going to be 1 here

To fix this you’ll need to convert your integers to floats first. The following will work:

some_int = 3
another_int = 2
answer = some_int.to_f / another_int.to_f  # answer is going to be 1.5 here

the to_f function is going to convert the integers to floats and give you the float (decimal) answer.