Code or Die Welcome to my kitchen

Yak shaving tips, Infosec, Astronomy, Gardening

This is my blog. Proud guardian of three cats and two dogs, I currently reside in San Antonio, Texas.

I'm interested in gardening, astronomy, infosec among other pursuits. About this site.

Past and current projects. You can also browse the blog archive if you like.

Message of the Day: Party on dudes!

Adventures in HTML Validation

It is pretty straightforward to plunk in a source file, URL or text input into Nu Html Checker and validate your markup to see that it cuts mustard. I recently reviewed the HTML for this site, and I have been generally obsessing about it and HTML outlines.

HTML Validation

Why validate?

Like any code HTML gets sticky quickly if you are not adhering to guidelines as you craft it. Guidelines matter and they exist for a good reason. If you ignore validation as you throw up your pages, errors are likely to accumulate until a catastrophic error will force an investigation with its attendant costs. This is not a case of technical debt, rather of laziness or worse, indifference. The case for validation is that if you have been making your pages validate as they go up, then during inevitable catastrophic failures you can use the validator as another useful tool to narrow down and fix a bug rather than as a source of noise.

Accessibility

HTML validation and outlines create structure to your website and this makes it organized logically and legibly for screen readers. This is the prevailing wisdom as I understand it, so validating and making sure your HTML outline makes the most sense for accessibility concerns. From https://validator.w3.org/nu/about.html:

  • There are some markup cases defined as errors because they are potential problems for accessibility, usability, interoperability, security, or maintainability because they can result in poor performance, or that might cause your scripts to fail in ways that are hard to troubleshoot.
  • Along with those, some markup cases are defined as errors because they can cause you to run into potential problems in HTML parsing and error-handling behavior—so that, say, you’d end up with some unintuitive, unexpected result in the DOM. Validating your documents alerts you to those potential problems.

Apart from HTML validation, there is an online accessibility validator which can help determine what else may be missing in terms of accessibility.

Plain old correctness (in spec)

It just feels right. Experimentation and breaking the rules are admirable qualities of your friendly neighborhood hacker, however there certainly is a time and place for experimentation. Folks, it is cool to rely on the established spec for serious projects. Pinkie-swear.

Knowing when to look the other way

Building on the previous statement, sometimes it is OK to just overlook certain things. For example, for my page the only things that currently show “error” or “warning” are for the Creative Commons License, which are relatively minor gripes.

To illustrate a great point, this blog post by Coding Horror’s Jeff Atwood nails the ambiguity: Learning the rules of the validator, even if you don’t agree with them, teaches you what the official definition of “valid” is.

HTML Outline

An document outline provides a graphic representation of the sections of your markup as they relate to each other, which is fundamental to present the page correctly to the user. According to spec, the relationships of these elements leads to the structure of the document and its outline. There are arguments against the effectiveness of the new HTML5 outline guidelines, but I am using them in conjunction with the traditional h1 - h6 scheme as this is backwards compatible.

Here are a couple of tools available for working with HTML outlines:

Summary

For my page there were a couple of interesting ‘quirks’. I had linked to Google Fonts with this line:

<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Merriweather|Open+Sans|Inconsolata' type='text/css'>

The validator complained that there was a Bad Value, and that “Illegal character in query.” This was the suggested code snippet auto generated by Google Fonts. After a little search it turns out the pipes ‘|’ were responsible. I switched those to %7C to resolve the encoding issue.

<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Merriweather%7COpen+Sans%7CInconsolata' type='text/css'>

I had the aforementioned errors and warnings about the Creative Commons tag which also happens to be auto-generated. I decided to sacrifice that in the interests of sanity.

Finally for my outline, there were some rather embarrassing header mix ups that I promptly fixed, making my HTML outline tree a lot smoother. There were also “Untitled Section” labels on my sidebar and footer sections. This made me a bit leery due to accessibility reasons1, so I researched how to put invisible headers on them for screen readers. This solution that works as of this writing was found on this Stack Overflow answer:

Add class="visuallyhidden" to the header element.

.visuallyhidden {
  position: absolute !important;
  height: 1px;
  width: 1px;
  overflow: hidden;
  clip: rect(1px 1px 1px 1px); 
  /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
}

The headers are now invisible, but allow screen readers to see them. Overflow hidden is to hide scrollbars.

My final HTML outline:

1. Sidebar
    1. Sidebar Nav
    2. Code or Die live to code
2. Early Coder Reading List
    1. Beginner:
    2. Intermediate:
    3. Advanced:
3. My Sublime Prefs
    1. User Preferences
        1. Font
        2. Theme
        3. Packages
        4. Key Bindings
    2. Bric-a-Brac
4. Setting Up
    1. Basics
    2. Setup
        1. Install Command Line Tools
        2. Configure Sublime Text from the command line, subl.
        3. Bash profile and UNIX environment
        4. Homebrew
        5. Install sqlite3 with Homebrew
        6. Install postgres with Homebrew
        7. Install a Ruby Manager with Homebrew
        8. Install Ruby using a Ruby Manager
        9. Install git with Homebrew
        10. Install node with Homebrew
        11. Install Ruby gems
        12. Install bash using Homebrew
    3. Conclusion
5. Hi MTV 
    1. Licensed under Creative Commons

Perhaps it seems a little nit-picky but I learned quite a few new things for such a cursory glance into the spec. Learning to validate you HTML is important and the less these practices seem like esoteric nuisances, the more I can learn to do things correctly. If at some juncture I aim to transgress, then I know what exactly I am breaking and why.

  1. HTML5Doctor “For accessibility reasons, we recommend each sectioning element have a heading, even <aside> and <nav> … If you don’t want these headings to be visible, you can always hide them with CSS.” 

Early Coder Reading List

Here is an early coder resource focusing on Ruby, JavaScript and Rails development. As dead tree media tends to obsolescence, latest online editions should be sought out if possible.

Beginner:

Intermediate:

Advanced:

My Sublime Prefs

As a segue from the previous post on setting up the developer environment, I wanted to record my current setup for Sublime Text build 3083. This is not a post that debates the relative merits of this or that text editor. Maybe some other time.

I love Sublime Text. As a tool that I use daily in my chosen profession, I am more than happy to pay for the registered version and support the developers who make it. This should not be taken as a jab at any other text editors, open source or otherwise. Software developers and engineers are known to be obsessively defensive of their chosen favorite tools, most notably text editors.

Now that we have that out of the way, here is what works for me.

I use two machines, a desktop and laptop, so I sync Sublime Text settings via Dropbox. Instructions to do this are located here.

User Preferences

Here are the contents of the synced preferences file:

User/Preferences.sublime-settings

{
  "auto_complete_delay": 25,
  "bold_folder_labels": true,
  "caret_style": "blink",
  "color_scheme": "Packages/Predawn/predawn.tmTheme",
  "ensure_newline_at_eof_on_save": true,
  "file_exclude_patterns":
  [
    ".DS_Store",
    ".tags*",
    "*.pyc",
    "*.pyo",
    "*.exe",
    "*.dll",
    "*.obj",
    "*.o",
    "*.a",
    "*.lib",
    "*.so",
    "*.dylib",
    "*.ncb",
    "*.sdf",
    "*.suo",
    "*.pdb",
    "*.idb",
    "*.class",
    "*.psd",
    "*.db",
    "*.pdf"
  ],
  "folder_exclude_patterns":
  [
    "data",
    ".zeus.sock",
    ".git",
    ".svn",
    ".hg",
    "CVS",
    ".sass-cache",
    ".bundle",
    "bundle",
    ".rbx",
    "script",
    "tmp",
    "log"
  ],
  "font_face": "Inconsolata-dz",
  "font_size": 14.0,
  "highlight_line": true,
  "highlight_modified_tabs": true,
  "ignored_packages":
  [
    "Vintage"
  ],
  "indent_guide_options":
  [
    "draw_normal",
    "draw_active"
  ],
  "line_padding_bottom": 0.5,
  "line_padding_top": 0.5,
  "predawn_tabs_medium": true,
  "rulers":
  [
    80
  ],
  "save_on_focus_lost": true,
  "scroll_past_end": true,
  "shift_tab_unindent": true,
  "tab_size": 2,
  "theme": "predawn-DEV.sublime-theme",
  "translate_tabs_to_spaces": true,
  "trim_trailing_white_space_on_save": true,
  "word_wrap": "true"
}

The usual suspects are here. I am a big fan of matching popular style-guides so I will use “tab size: 2”, and “translate tabs to spaces” enabled. “Save on focus lost” is a life saver as well as a time and sanity saver, especially on large projects.

“Trim trailing white space on save” is pretty self-explanatory, but for more information as to why “newline added on EOF (end of file)” should be used, check out this enlightening post on thoughtbot’s blog that explains the history.

Font

I use Inconsolata-dz, a variation of the superb Inconsolata font that includes straight quotes. I really love it, and can’t recommend it enough. Since I sync my Sublime settings from desktop to laptop and I like to reduce eye fatigue instead of squinting, it is set to a slightly larger font size than normal.

The original Inconsolata font created by Raph Levien is located here.

The Inconsolata-dz variant by David Zhou is available here.

Again, the subject of code fonts is highly contentious among the developer community, so in the interest of brevity I won’t elaborate further here. Maybe another day.

Theme

I use Jamie Wilson’s excellent theme, Predawn, and I follow the recommendations on that page for Markdown editing.

It is naturally available via Package Control.

Packages

Speaking of packages, here are my currently installed Sublime Text packages:

Since I recently reinstalled my OS, I may will definitely find more to download. One that springs to mind is Sublime​Linter and its language-specific packages.

Key Bindings

Here is the contents of the synced Key bindings file: User/Default (OSX).sublime-keymap

[
// Rails ERB tags
{ "keys": ["ctrl+shift+."], "command": "erb" },
// Paste and Indent
{ "keys": ["super+v"], "command": "paste_and_indent" },
// Vanilla Paste (no indent)
{ "keys": ["super+shift+v"], "command": "paste" },
// Reindent shortcut
{ "keys": ["super+shift+r"],  "command": "reindent" }
]

The ERB shortcut is used by SublimeERB to cycle between <%= %>, <% %>, <%- -%>, <%= -%>, <%# %>, and <% -%> and places the cursor helpfully inside of these monstrosities to ease the pain of typing embedded Ruby delimiters.

Paste and Indent makes this behavior default for ⌘-v, and allows me the option of reverting to the old paste using shift, in case I ever need it for some wacky reason.

Reindent saves me from hunting for this useful command in the menus.

Bric-a-Brac

I turn off the Minimap as it takes up valuable real estate and usually I just don’t use it.

What else? Oh yes, the app icon! The default icon that Sublime Text uses is a tad, well… it’s not nice to look at on the dock all the time. I prefer replacing it with a different one. This of course is just a cosmetic change, but there you have it. I regret nothing.

Dribbble user Lucifr offers a few crowd-sourced replacements: “Icons much less ugly than the default one for Sublime Text 2”, (they work for Sublime Text 3 too of course.)

I use this one by Daniel Matarazzo adapted from an icon by Lindsay Mindler:

Sublime Text alternate icon

To get it, follow the instructions on Daniel’s GitHub repo, although I recommend renaming the Resources folder to Resources-old or something so you can get the originals back if you need them later.

A little extra step that I found was necessary after following the above instructions was to actually replace the icon in Finder:

First download your chosen image file, preferably a PNG for scalability. Select Sublime Text.app and type ⌘-i or right-click (a useful holdover from my PC days) and select Get Info. Drag and drop your chosen image file onto the ugly icon image in the Info window (top left corner). Enjoy your sleeker Sublime Text icon.

If you have any suggestions for packages, themes or key-bindings, or if there is something horribly wrong with the above information, please feel free to shoot me an email.

Thanks for reading and happy coding.