Simplest static site on Heroku (plain Rack)?

gem 'rack-rewrite', '~> 1.0.0'
require 'rack/rewrite'

use Rack::Rewrite do
  rewrite '/favicon.ico', '/images/favicon.ico'
  rewrite '/', '/index.html'
end
run Rack::File.new('public')

Filed under  //   hosting   ruby   tech  

Comments [0]

The new css 100% width and height with header and sidebar

It's been a while since I've had to deal with making a cross-browser 100% height layout - long enough that a couple version of IE have come out since.  CSS support in IE has come a long way, so I thought I'd start fresh and try a purely standards based approach for the latest IE and standards based browsers, using the 'display: table-*' styles, and just do a fallback for older versions of IE (a 100% height modified Holy Grail layout that relies on the IE quirks box-model).

Unfortunately, while IE8 does support the table display styles, IE7 doesn't, and there doesn't seem to be any way to put IE7 in quirks mode, while keeping IE8 and every other browser in standards mode.  So I just settled on the old-fashioned approach of having one layout for all other browsers and keeping the IEs clumped together in quirks mode.

(download)

Filed under  //   browsers   css   tech   webdevelopment  

Comments [1]

Git sub-tree merging back to the subtree for pushing to an upstream

While git sub-tree merge strategy works great for merging a library into vendor (when you want to pull HEAD on that library instead of waiting for releases), I had trouble finding documentation on pushing back to upstream.  This is annoying because one of the most obvious times you may want to use subtree is when you manage the library yourself, so can just pull straight from the repo, and want to push your maintenance changes back.

Surprisingly, and not what I have come to expect from git, it just works.  From the example in the docs I linked, when you are checked out on master

git merge --squash -s subtree --no-commit rack_branch

will merge the rack_branch into where you have specified.  But it just works the other way to.  If checked out on rack_branch

git merge --squash -s subtree --no-commit master

will do what you expect, so you can now just push your library branch back to it's upstream.

Awesome!

Filed under  //   git   tech  

Comments [4]

Filed under  //   rack   ruby   tech   testing  

Comments [0]

Testing a rackup (config.ru) file with Rack::Test

The ever useful rack-test gem let's you easily integration test any rack project.  All you have to do is include the Rack::Test::Methods and define an app method that returns your rack app.  So people usually have a config.ru that just references their my_application.rb that they reference in their config.ru and then in their test file they can also reference that app and return it.  Something to to this effect:

I had a project where I was actually trying to better breakdown a more complex app, and I wanted to just be able to use Rack's built-in map method at the top level of my config.ru to route to different apps.  And in at least some of the cases I wanted to be able to test the whole thing.  Also, I figured sometimes it's useful to actually be able to test your rackup file itself, all routing/mapping included.  So I dug around in the rack code and found how the rackup command handles the .ru file, and came up with this:

Update

If you are running off of a new enough version of rack, you could also just use Rack::Builder.parse_file

Filed under  //   rack   ruby   tech   testing  

Comments [0]

Beware respond_to format with redirects in shared systems before_filter - DoubleRenderError

If you have global before_filters for things like requiring login to access pages (such as in authenticated_system.rb), be careful of missing formats in the respond_to.  I just tracked down a bug on an app where we were getting DoubleRenderErrors because of unauthenticated requests directly against a dynamic csv file.  

We had a before_filter that was denying request and redirecting them to login, in different ways, depending on the format, but hadn't thought to include csv.  In this case, it is wise to include a catch-all at the end using .any

Filed under  //   ruby   rubyonrails   tech  

Comments [0]

Simplicity *does* mean simple, readable methods

Following a link from @raganwald I came across an article where Mike Taylor was debating wether the concept of simplicity, as it pertains to the length and complexity of methods isn't subjective.  He read a decent chunk of Fowler's Refactoring, found himself disagreeing with the tendency to composable, well named methods, in favor larger methods with the low-level implementation in the method itself, and hoped maybe he was wrong, because the lure of The One True Way is strong.  While I am often a subjectivist, as I told my fiance, "Honey, somebody on the internet is wrong - I must inform them immediately."

Basically Mike breaks it down into two approaches: top-down, where the methods are named what they do and abstracted away so you don't see each step of implementation at the top, and bottom-up, where the main method is a little larger and is built up of the implementation itself.  He favors bottom-up, and I am a partisan of the other camp, as rubyists often seem to be.

I think there is one most important reason to favor the big-picture top-down in this dichotomy.  From top-down you can dive down into the implementation and see the details if you chose, but in bottom-up there is no way to get the equivalent top-down view without just reading and understanding the whole program.  Basically, advocating the bottom up approach is like making world-maps illegal, because you can get a better feel for navigating your hometown with a city-map.

From this flows the second most important reason, the inability to mentally page out to disk, so to speak, means you have to hold more of the program in your head to understand what is going on.  That means as the program grows in size, it gets harder and harder to keep track of it all.  And the reason this is really a problem, is when it comes time to introduce new people to the code.  By not abstracting things away into bite-sized chunks you've just forced them to learn every piece of everything involved to have a hope of understand things enough to actually get any work done.

A third point: various software engineering theories like: cyclomatic complexity and single-responsibility principle.

I will admit that getting carried away with classitis and class hierarchies, Java style, has some cost, when it comes to following what a program does.  There is a little balancing act required there.  But, I do think, that decomposing methods is an unequivocal win.  I think Rein's tongue-in-cheek talk on Unfactoring is a better visual, code-based proof of the importance of this for maintainability than anything I could whip up here (about 5 minutes in he gets into the examples).

Lastly, who hasn't gone back and looked at their old code and wondered what they were doing?  If you want to go back and tweak something, it's painful if you have to refigure out every piece of implementation.  This is a case where scanability and readability is a huge win.
Filed under  //   internetdebates   ruby   tech  

Comments [10]

The trouble with bash colored prompts munging your control-r bash history searches

Basically, you just want to be very careful properly escaping and ending color sequences in your bash prompt.  If you mess them up, when you try to use spiffy bash tricks that alter the text on your current input line, such as control-r to search through your bash history and then left of right arrow to edit that line, you'll get a partially overwritten line that is impossible to read or edit properly.

Filed under  //   bash   tech  

Comments [0]

Filed under  //   jruby   ruby   tech  

Comments [0]

Tagging a git release with current branch name and date

Either add this to your .git/config

[alias]
datetag = !git tag `git name-rev --name-only HEAD`-`date \"+%Y%m%d%H%M\"`

or run it in your project folder to add it to the config for that project:

git config alias.datetag '!git tag `git name-rev --name-only HEAD`-`date "+%Y%m%d%H%M"`'

Then you can just run 'git datetag' to create a new tag to use as a release

Filed under  //   deployment   git   hosting   tech  

Comments [0]