Today I Learned: Simultaneously opening Ruby gem source files in Vim tabs

May 30, 2015

Say you're working on a Ruby Gem structured like:

|-- bin
|   `-- sample_gem
`-- lib
    |-- sample_gem
    |   |-- bar.rb
    |   |-- baz.rb
    |   |-- biz.rb
    |   |-- foo.rb
    |   `-- version.rb
    `-- sample_gem.rb

Use this to open the full set of source files in Vim tabs:

vim -p bin/sample_gem lib/**/*.rb

Today I Learned: How to replace minitest-reporters with minitest-rg in the Ruby on Rails Tutorial (3rd ed.)

May 30, 2015

Michael Hartl uses the minitest-reporters gem to colorize test results in the third edition of the excellent Ruby on Rails Tutorail. I prefer minitest-rg. To use it instead:

  1. Remove (or just don't add) these lines to test/test_helper.rb:

    require 'minitest/reporters'
    Minitest::Reporters.use!
  2. Replace this section of the Gemfile:

    group :test do
      gem 'minitest-reporters', '1.0.5'
      gem 'mini_backtrace',     '0.1.3'
      gem 'guard-minitest',     '2.3.1'
    end

    With this:
    group :test do
      gem 'minitest',           '5.7.0'
      gem 'mini_backtrace',     '0.1.3'
      gem 'guard-minitest',     '2.3.1'
      gem 'minitest-rg',        '5.1.0'
    end
    The order is important. Calling minitest-rg earlier causes problems.

Introducing "Today I Learned"

May 30, 2015

Code snippets represent a large portion of my posts. They generally include, "While working on X, I ran into issue Y and came up with this solution Z…" type descriptions for context. Interesting as that might be, they aren't critical. What they are is time consuming to produce. I post less often because of that. Inspired by the HashRocket's Today I Learned blog1, I'm changing my approach and dropping the backstory.

Starting today, code snippet posts will fall under umbrella "Today I Learned: …" titles. There will still be enough context to make sense, but the specific reasons I went down any particular rabbit hole will be greatly reduced. I figure this will cut two thirds or more off writing time.

Less muss, less fuss, more posts.


Footnotes

  1. Today I Learned from the crew at Hashrocket - Frequent snippet posts. It's only been going for a couple months. There's already a bunch of nice things though. Good stuff.

Social Media App Store Icon

April 22, 2015

The Atlantic just redesigned their site. It's heavy on photography and looks very nice.

They also did something I've not seen before: Including a Apple App Store icon in their social media icon set.

Smart.


Finding Things in Ruby's ObjectSpace

March 19, 2015

Here's a great development nugget courtesy of the book Design Patterns in Ruby1.

The standard Ruby library contains a module called ObjectSpace that:

… contains a number of routines that interact with the garbage collection facility and allow you to traverse all living objects with an iterator.

It's that last part that's of interest and leads us to the method:

ObjectSpace.each_object

Pass it a class name and it'll iterate over all existing objects of that type. That means we can find specific objects from anywhere in an application2.

Here's the start of a simplistic example: A Character class that stores first and last names and a few instances that aren't assigned to anything.

# Sample part 1

class Character
  attr_reader :first_name, :last_name
  def initialize (name)
    @first_name, @last_name = name.split(/ /)
  end
end

names = [ "John Robinson", "Maureen Robinson", "Zachary Smith",
  "Judy Robinson", "Will Robinson", "Penny Robinson", "Don West"
]

names.each do |name|
  Character.new(name)   # Lost in Space?
end

To demonstrate the method, let's produce a list of everyone who's not a member of the Robinson family. This is done by passing ObjectSpace.each_object the Character class name and examining the last_name property of each object returned in the loop.

# Sample part 2

ObjectSpace.each_object(Character) do |obj|
  if obj.last_name != "Robinson"
    puts "#{obj.first_name} #{obj.last_name}"
  end
end

Running that, we get our list:

Don West
Zachary Smith

There are usually explicit connections between objects that need to know about each other. When there's not and it would be tricky to implement one, ObjectSpace.each_object can provide a nice bridge.


Footnotes:

  1. Design Patterns in Ruby "… a guide to solving real-world problems with Ruby." I'm only seven chapters in. If I get nothing else out of it, it's already been worth the price of admission. This is one of those books that fits squarely into both the "Wish I'd read it years ago" and the "To re-read repeatedly" categories.

  2. Update on January 5, 2017 - Important to point out this is probably a bad idea most of the time. I was just intrigued to see that it was possible.


A Bright New Light Bulb Idea

March 16, 2015

Innovation in light bulb design continues apace. The leading example is variable color, smart phone controlled LED lights. Yes, seriously1. Even incandescents, the dinosaur of light bulbs, are evolving.

Traditional incandescents work by suspending a little piece of tungsten inside a vacuum.

A new technique recently hit the scene. Instead of a filament, a smaller halogen bulb is wired inside the main bulb.

Illumination, Russian Doll Style.

There is also a hole in the screw cap. This would prevent a traditional incandescent from working, but the halogens don't need an external vacuum. My guess is that this acts as a pressure valve or ventilation. Whatever the case, it certainly looks intentional.

This whole hybrid-halogen concept looks like someone ended up with a ton of surplus halogen bulbs and said, "Hey, what if we jury-rigged these inside of a standard bulb?" and everyone laughed. Until they did it and it worked.

Definite points for creativity.


Footnotes:

  1. Philips Hue - Personal Wireless Lighting - "The bulbs, the bridge and the app will change the way you use light. Forever. Experiment with shades of white, from invigorating blue/white to cozy yellow/white. Or play with all the colors in the spectrum."

Rsync --exclude List for Mac OS X

Posted: January 24, 2015 - Updated: March 04, 2015

Updated March 4, 2015 with more cruft identifiers including several from Windows machines

This is my reference for patterns to exclude when moving files around with rsync. It ignores system cruft that doesn't need to be copied and throws me off when it shows up on my FreeNAS server. I'm posting it to have access to it from anywhere and for anyone else who might find it useful.

--exclude='$RECYCLE.BIN' --exclude='$Recycle.Bin' --exclude='.AppleDB' --exclude='.AppleDesktop' --exclude='.AppleDouble' --exclude='.com.apple.timemachine.supported' --exclude='.dbfseventsd' --exclude='.DocumentRevisions-V100*' --exclude='.DS_Store' --exclude='.fseventsd' --exclude='.PKInstallSandboxManager' --exclude='.Spotlight*' --exclude='.SymAV*' --exclude='.symSchedScanLockxz' --exclude='.TemporaryItems' --exclude='.Trash*' --exclude='.vol' --exclude='.VolumeIcon.icns' --exclude='Desktop DB' --exclude='Desktop DF' --exclude='hiberfil.sys' --exclude='lost+found' --exclude='Network Trash Folder' --exclude='pagefile.sys' --exclude='Recycled' --exclude='RECYCLER' --exclude='System Volume Information' --exclude='Temporary Items' --exclude='Thumbs.db'

A Kind of Redesign

February 16, 2015

Welcome to the new and improved redesign of alanwsmith.com!

Don't be surprised if you can't tell the difference.

This redesign is almost entirely behind-the-scenes. Instead of my hand-build code, the page templates now use a framework called Bootstrap1. The biggest change is that the site is now "responsive" (i.e. it'll resize itself nicely for laptops, tablets and phones).

Making the site phone friendly has been on the back-burner for some time. It moved up the priority list dramatically when Google sent me an email titled "Fix mobile usability issues". It said, in part:

Google systems have tested 66 pages from your site and found that 97% of them have critical mobile usability errors. The errors on these 64 pages severely affect how mobile users are able to experience your website. These pages will not be seen as mobile-friendly by Google Search, and will therefore be displayed and ranked appropriately for smartphone users.

Or, put another way, "Your site is about to disappear from the internet."

There's still plenty of rough edges, but the foundation is in place. According to the testing tool2, I still have work to do to appease the robots. In the mean time, it does look way better on phones.


Footnotes:

  1. Bootstrap was started by Twitter. In the old days, making your own site framework was a right of passage. With all the little gotchas of making sites look good across different sites of displays, it doesn't make sense. Bootstrap or another framework like Foundation are the way to go.

  2. The Mobile-Friendly Test lets you see what Google things about your page. It's one of many they provide to help build better sites. Something they excel at.


Go To Index Page: 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106


© Alan W. Smith
RSS Feed