jsha/README

a blog by Jacob Hoffman-Andrews

Archive for April, 2011

Ruby function STFU: temporarily redirect noisy stdout writes to /dev/null

without comments

This function is handy if you have some third-party gem that generates writes to stdout or stderr which you wish to suppress. Simple wrap your call to the noisy function in an `stfu’ block. If an exception is thrown, it will be reopened with stdout and stderr pointing to the console again.

  def stfu
    begin
      orig_stderr = $stderr.clone
      orig_stdout = $stdout.clone
      $stderr.reopen File.new('/dev/null', 'w')
      $stdout.reopen File.new('/dev/null', 'w')
      retval = yield
    rescue Exception => e
      $stdout.reopen orig_stdout
      $stderr.reopen orig_stderr
      raise e
    ensure
      $stdout.reopen orig_stdout
      $stderr.reopen orig_stderr
    end
    retval
  end

  require 'some_noisy_gem'
  stfu do
    some_function_that_generates_a_lot_of_cruft_on_stdout
  end

Written by jsha

April 14th, 2011 at 2:45 pm

Posted in Uncategorized

Add an HTTP Host column to Wireshark

without comments

Diagnosing HTTP traffic in Wireshark can be a pain because it is not always clear from the Info column where the traffic is going. All those “GET / HTTP/1.1″ blend together. Fortunately it’s easy to add a column.

Go to Edit -> Preferences -> User Interface -> Columns. Click “+ Add”, and for “Field type” select Custom. The “Field name” box will now be enabled. In it type “http.host”. Click the “New column” text above to set the display name to “HTTP Host.” Hit OK and you are done!

Screen shot 2011-04-01 at 1.59.25 PM

Written by jsha

April 1st, 2011 at 1:55 pm

Posted in Uncategorized