Daniel Friesen

(Dantman, Nadir Seen Fire)

Programmer, Web Developer, Animanga Fan

Topic: code

Posts with code patterns in them.

This post was last modified

One of the designs I recently had to work on needed a narrow width header in a sidebar with a large number on the left side of it and the header text vertically centered to the right.

If you've worked with CSS for awhile you've probably ran into the same issue as everyone else. Vertical alignment with universally supported css is not easy. There are multiple techniques you can use to make something vertically aligned but there are drawbacks to each.

For my use case I couldn't use any of the normal tricks I'd use. I didn't know the exact height of the number and I needed the header text on the right to wrap properly. So I couldn't use a typical technique involving line-height, absolute positioning, or padding.

[Read more...]

You probably already know about HTML5's <input type="number">. Which if supported by a browser displays a form input optimized for inputting numbers. Whether that means an up/down spinner or an optimized keyboard.

However iOS' standard behavior for the number input isn't that ideal. By default iOS will display a standard keyboard slightly modified with a row of numbers at the top. This isn't ideal as you don't need the alphabetic keys and iOS already has a full numeric keypad it could use for the input instead. For reference, other mobile OS such as Android already display their numeric keypad when focusing a number input.

A html5doctor article article went over this, pointed out a trick by Chris Coyier using <input type="text" pattern="[0-9]*"> in which the pattern forces iOS to use it's numeric keypad, and also mentioned HTML5's inputmode.

[Read more...]

Man, forgetting to add my little error catching trick inside of one app I was writing made me realize how much I take such a simple trick for granted.

app = proc do |env|
  begin
    # Application code
  rescue Exception => e
    r = Rack::Response.new
    r.status = 500
    r.header["Content-Type"] = "text/plain"
    r.body = e.to_s << "\n" << "-" * e.to_s.length << "\n" << e.backtrace.join("\n")
    r.finish
  end
end

run app

I basically write all my rack code in a way similar to that. Normally I'll probably throw in another error catching level that catches special formated ErrorPage classes for things like NoPage to generate a 404. But this here is the big absolute fallback, if at any point inside of my code I make a mistake in syntax or anything this completely catches it, and renders the full error message and a full backtrace letting me actually see the error right away instead of looking through a horrid apache log.

[Read more...]

This one is a little bit old, but if any of you are familiar with rails' views you'll probably have seen bits of view code like:

<% form_for @user do |f| %>
  ...
<% end %>

And if you've ever jumped into erb in your own ruby you've probably made an attempt at doing something similar trying to put something into the buffer without the use of =. This is of course because ERB doesn't let you use blocks when you make use of =.

[Read more...]