Showing posts tagged tech

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 
<!— keep IE in quirks mode —>
<!DOCTYPE html>
<html>
  <head>
<!— This following meta tag does no good since there is no way to trigger quirks
mode only in IE7. The problems with an xml prolog that triggered quirks mode were
fixed in IE7, but this meta tag was not yet introduced, so the only thing you can do
is trigger IE-wide quirks via the comment before the DOCTYPE //—>
    <meta http-equiv=“X-UA-Compatible” content=“IE=EmulateIE8” />
    <style type=“text/css”>
/*You still need an unbroken chain of 100% from the viewport down to the ‘table’
container*/
      html, body, #wrapper { margin: 0px; padding: 0px; height:100%; }

/* This is the heart of the new layout. You don’t even need to worry about
min-height vs. height issues, because table handle those fine without weird issues
when the browser window becomes smaller than the content.*/
      #wrapper { display: table; width: 100%; }
      #header { display: table-row; height: 99px; }
      #logo { display: table-cell; }
      #header_contents { display: table-cell; }
      #container { display: table-row; }
/* This is the one min-X needed, it prevents the sidebar from collapsing down to
it’s contents width when the containing div tries to shrink due to the window being
shrunk down*/
      #sidebar { display: table-cell; width: 200px;
                            min-width: 200px; vertical-align: top;}
      #content { display: table-cell; }
      
/* Fluff, purely for illustration of the containers */
      .box { width: 100px; height: 100px; background: grey; }
      #content .box { width: 300px; }
      #header_contents { border: 2px solid green; background-color: #cfc; }
      #sidebar { border: 1px solid blue; background-color: #ccf; }
      #content { border: 2px solid red; background-color: #fcc; }
    </style>
<!— The quirks mode based IE approach below. Since in that box model paddings and
margins are not additive with the contents width/height, you can just add some
paddings to the parent. For an explanation of the sidebar negative margin tricks,
google ‘holy grail css.’ And the header is just absolutely positioned over the space
created by the padding trick on the container //—>
<!—[if IE]>
<style type=”text/css”>
#wrapper, #logo, #header, #container, #sidebar, #content { display: block }
#header { position: absolute; padding-left: 200px; }
#logo { float:left; height:100%; width:200px; margin-left: -200px; }
#header_contents { height: 100%; width:100%; float:left;}
#sidebar { float: left; height: 100%; margin-left: -200px; }
#container { height: 100%; padding-top: 99px; padding-left: 200px; }
#content { height: 100%; width: 100%; float: left; }
</style>
<![endif]—>
  </head>
  <body>
    <div id=“wrapper”>
      <div id=“header”>
        <div id=“logo”>Logo</div><div id=“header_contents”>Header</div>
      </div>
      <div id=“container”>
        <div id=“sidebar”><div class=“box”>Sidebar</div></div>
        <div id=“content”>
          <div class=“box”></div>
        </div>
      </div>
    </div>
  </body>
</html>

Posted via email from a timocracy of one | Comment »

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!

Posted via web from a timocracy of one | Comment »

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:

 1 2 3 4 5 
class MySweetRackApp
  def initialize
    Proc.new { |env| [200, {‘Content-Type’ => ‘text/html’}, [‘success’]] }
  end
end

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:

https://gist.github.com/28d510d9fc25710192bc

Posted via web from a timocracy of one | Comment »

Beware respond_to format with redirects in shared systems before_filter - DoubleRenderError

If you use an authenticated_system on your Rails site, with global before_filters for things like requiring login to access pages, 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 request directly to a 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

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
def anon_access_denied
  respond_to do |accepts|
    accepts.html do
      store_location
      redirect_to login_path
    end
    accepts.xml do
      headers[“Status”] = “Unauthorized”
      headers[“WWW-Authenticate”] = %(Basic realm=”Web Password”)
      render :text => “Could’t authenticate you”, :status => ‘401 Unauthorized’
    end
    accepts.js do
      render(:update) { |page| page.redirect_to login_path }
    end
  end
end

Posted via web from a timocracy of one | Comment »

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 mess with your current 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.

 1 2 3 4 5 6 7 8 9 10 11 
#Just be careful. Safest to properly end color sequence, so instead of this
#export PS1=”\[\033[01;32m\]\u\[\033[00m\]\[\033[01;31m\]\$(git_br)\[\033[01;32m\]\[\033[00m\]:\[\033[01;36m\]\$(git_pwd)\[\033[00m\]\$ “
 
#do this
USER_GREEN=’\[\e[01;32m\]’
#NO_COLOR=’\[\e[00m\]’
REPO_RED=’\[\e[01;31m\]’
PATH_BLUE=’\[\e[01;36m\]’
END_COLOR=‘\e[m’
 
PS1=”${USER_GREEN}\u${END_COLOR}${REPO_RED}\$(git_br)${END_COLOR}:${PATH_BLUE}\$(git_pwd)${END_COLOR}$ “

Posted via web from a timocracy of one | Comment »

Call a custom jar from ruby in jruby

 1 2 3 4 5 6 7 8 9 
#javac HelloWorld.java && jar cvf HelloWorld.jar HelloWorld.class
require ‘java’
require ‘HelloWorld.jar’
import ‘HelloWorld’
 
puts HelloWorld.new.hello
#=> “Hello cruel world”
 
#jruby hello_world.rb

Posted via email from a timocracy of one | Comment »

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"`'

Posted via web from a timocracy of one | Comment »

Setting RAILS_ENV on Dreamhost when running Passenger

It may depend on which server you are on, but mine has mod_env
enabled, so it’s a simple matter of setting the ENV[‘RAILS_ROOT’] in
an .htacess file
 
SetEnv RAILS_ENV staging

Posted via email from a timocracy of one | Comment »

http://g.raphaeljs.com/

http://g.raphaeljs.com/

A sweet javascript charting/graphing library. Soon there may be no
need for flash/flex every again?

Posted via email from a timocracy of one | Comment »