Substack's philosophy of small things

Those of you who follow the Node.js community at all will recognize substack as one of the most prolific package authors on NPM. You have probably also picked up on the fact that he is a big fan of small packages.

I ran across this interview the other day and I think substack communicates his “small things” philosophy well. Simply put, the UNIX philosophy works. Do one thing, do it well, and it will stand the test of time.

Continue reading

Google Chrome and WOFF font MIME type warnings

If you are getting warnings like Resource interpreted as Font but transferred with MIME type font/x-woff in Google Chrome then it means your web server is serving the font with the wrong MIME type.

It took awhile for the WOFF font format to get an approved MIME type so there are several variations hanging around.

  • font/x-woff
  • font/woff
  • application/x-font-woff

Thank God an official type was finally decided on, application/font-woff.

Unfortunately, Google Chrome (as of 26 beta) still expects you to use application/x-font-woff and doesn’t recognize application/font-woff as a valid MIME type. This has been fixed in the WebKit trunk but hasn’t been merged into Chrome yet. The Chromium bug report has been closed so it should be coming soon.

Continue reading

jQuery CSS Clip Animation Plugin

Yesterday I needed to animate the CSS clip property using jQuery. jQuery.animate() doesn’t support this natively so I went searching for a plugin. I found exactly what I needed in a simple plugin by Jim Palmer, unfortunately it hasn’t been updated to work with jQuery 1.8.0+.

So here you go, a forked and updated copy of the plugin which will work with jQuery 1.8.0+.

Changes include:

  • Support for jQuery 1.8.0+
  • Support for the element’s initial clip value to be specified via a stylesheet instead of an inline style
  • Support for decimal clip values (thanks to a comment by Manoel Quirino Neto)
  • Type checking fx.end to guard against errors in some scenarios
  • Support for IE8

The element you are animating must have a clip style specified. Otherwise, usage is as you would expect.

Continue reading

Single day of eternity

High up in the North in the land called Svithjod, there stands a rock. It is a hundred miles high and a hundred miles wide. Once every thousand years a little bird comes to this rock to sharpen its beak. When the rock has thus been worn away, then a single day of eternity will have gone by.

-Hendrik Willem Van Loon

Continue reading

Using Unix terminal shortcuts in the Windows command prompt

Unix terminals have a few basic keyboard shortcuts.

  • CTRL+L to clear the window
  • CTRL+D to close the window
  • CTRL+V to paste text

The Windows command prompt doesn’t support these by default but we can fix that with AutoHotkey.

If you don’t already have it installed, you can follow the steps in my blog post.

Add this magic to your AutoHotkey script to enable these shortcuts in the Windows command prompt and PowerShell.

Continue reading

Using enum flags to model user roles in C#, SQL, and Go

Using an enum flags property to hold users’ roles is just one trick I’ve learned from @SeiginoRaikou, one of my co-geniuses at InterWorks.

Historically I have always modeled user roles with a Role table and a many-to-many relationship with my User table.

    +-------------------+
    | User              |
    |-------------------|
    | UserId   : int    +-------------+---------------+
    | UserName : varchar|             | UserRole      |
    +-------------------+             |---------------|
                                      + UserId : int  |
    +-------------------+             + RoleId : int  |
    | Role              |             |---------------+
    |-------------------|             |
    | RoleId   : int    +-------------+
    | RoleName : varchar|
    +-------------------+

Compared to a flags enum approach this is downright wasteful. With flags, there is only ever one column to work with and it is an integer. No second table. No joins or second query.

Continue reading

Open Graph Twitter Cards and Your Blog

Have you ever wondered why some web pages have a great preview when linked on Twitter, Facebook, or Google+ while others look so lacking?

What you are seeing are formats such as the Open Graph protocol and Twitter Cards at work.

Continue reading

Using bookmarks to quickly navigate in PowerShell

There are a few folders that I spend a lot of time and it is surprisingly slow to type cd c:\path\to\my\project many times a day. I solved this by creating a module that allows me to bookmark directories and navigate to them using aliases. Simply put, I can shorten the previous command to g project.

Usage looks like this:

Set-Bookmark <name> <path>
Get-Bookmark # to list all
Get-Bookmark <name>
Remove-Bookmark <name>
Clear-Bookmarks
Invoke-Bookmark <name>

I alias Invoke-Bookmark as g for speed.

Continue reading

Benchmarking scripts and programs with PowerShell

UNIX has the time command that will measure the execution time of a program. Timings are returned for the wall clock and CPU time. It looks something like this.

$ time ping google.com -c 1
PING google.com (74.125.225.232) 56(84) bytes of data.
64 bytes from dfw06s26-in-f8.1e100.net (74.125.225.232): icmp_req=1 ttl=54 time=19.7 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 19.767/19.767/19.767/0.000ms

real   0m0.173s
user   0m0.010s
sys    0m0.100s

The real, user, and sys information at the end is the output from time. StackOverflow has a great explanation of what those values mean.

Continue reading

An MKLINK PowerShell Module

MKLINK is a very useful utility on Windows. Unfortunately there aren’t any native PowerShell functions that replace it so we still have to shell out to the command prompt.

This can be made less painful with a helper function that will pipe all arguments to the MKLINK command.

function mklink { cmd /c mklink $args }

Personally though, I prefer to use native PowerShell functions whenever possible so I put together a module that provides wrappers for the key functionality of MKLINK.

Continue reading