Ugly Stool Rotating Header Image

Uncategorized

Boston Globe Bibliophiles: Bob Shacochis

The Boston Globe has a weekly column where a bibliophile is interviewed.  The article is edited down to include mostly details about what the person is reading.  If you have a hard time finding the next book to read it’s a great source.  Here’s my attempt to collect, and publish the information for the world at large.

Quick Bio: Bob Shacochis

The interviewee is an author of the following books.

“…about the fastest boat ride every down the Colorado River. It should be an instant classic.”

“Her writing is always gentle and transcendent, and, of course, it sits in darkness.”

“It’s great narrative fun.”

“…and liked it.”

Have you read any other daddy-daughter books?

“Kathryn Harrison’s The Kiss. Kathryn was my independent study student at the Iowa Writer’s Workshop.”

What books do you assign in your nonfiction seminar at Florida State University?

“I don’t assign any. Just give them a list. The five top books are…”

“…am looking forward to reading”

NOTE: All of these links have a kickback to me, so manually search if you want to avoid that.

Boston Globe Bibliophiles: Peter Sagal

The Boston Globe has a weekly column where a bibliophile is interviewed.  The article is edited down to include mostly details about what the person is reading.  If you have a hard time finding the next book to read it’s a great source.  Here’s my attempt to collect, and publish the information for the world at large.

Quick Bio: Peter Sagal

“I tried to read What I Talk About When I Talk About Running by Haruki Murakami, who I love, but couldn’t.”

“…there are a couple a good books.”

“I have friends writing books that I want to read, like…but, I really don’t have time for pleasure reading.”

“…two terrific books”

“…one of the funniest memoirs I ever read.”

“Two really good books.”

“Steve Martin’s Born Standing Up is one of the best books about making art ever written.”

“I’d love to be lost in some big novels.”

“I loved…”

“I’d love to get lost in some nonfiction, too, like…”

NOTE: All of these links have a kickback to me, so manually search if you want to avoid that.

Boston Globe Bibliophiles: Andre’ Gregory

The Boston Globe has a weekly column where a bibliophile is interviewed.  The article is edited down to include mostly details about what the person is reading.  If you have a hard time finding the next book to read it’s a great source.  Here’s my attempt to collect, and publish the information for the world at large.

Quick Bio: Andre’ Gregory

“This last week I was finishing a beautiful novel…”

“I’ve begun a tremendous biography about someone I thought wouldn’t interest me, Teddy Roosevelt”

“One of my favorite books of all time is the four-volume biography of Lyndon Johnson. I’ve read that twice. I’m just hoping he’s still with us for the fifth volume.”

“I’ve read twice.”

“I think she [Debbie Eisenberg] is our greatest short story writer.”

“An American writer I adore is Philip Roth.”

“It’s one of my very favorites.”

“I reread Brothers Karamazov again and found it rather boring. It’s not the book. It’s us. We change.”

“I’ve read Pema Chodron. She’s a Buddhist who’s written staggeringly helpful books, particularly for when you go through hard times.”

NOTE:All of these links have a kickback to me, so manually search if you want to avoid that.

Boston Globe Bibliophiles: Bill McKibben

The Boston Globe has a weekly column where a bibliophile is interviewed.  The article is edited down to include mostly details about what the person is reading.  If you have a hard time finding the next book to read it’s a great source.  Here’s my attempt to collect, and publish the information for the world at large.

Quick Bio: Bill McKibben is a journalist who has dedicated most of his life to fighting global warning.  He became an author on the topic starting in 2007.

"I just read a great novel."

"He’s only written a few books because they are so long…"

"By far my favorite book of last year was Katherine Boo’s."

"There’s a wonderful nonfiction account of Mumbai called."

"Early in my life, [I was drawn to] the America West. I spent a lot of time reading John Muir and Edward Abbey."

"I compulsively read Wendell Berry."

"When I was teaching myself how to organize, the most important document I read was Taylor Branch’s majest three-volume history of the civil rights movement."

There’s a children’s book that was of great help to me.

There are two books in recent times about the fossil-fuel industry that are really important.

NOTE: All of these links have a kickback to me, so manually search if you want to avoid that.

Dumping a Sho Chart in the LINQPad Result Window

If you dump a Sho chart in LINQPad, LINQPad creates a new WinForms tab to hold the dump result.  Actually, every time a WinForm is dumped a new WinForm tab is created.  If you dump a lot of charts this can quickly add up to a lot of tabs.  Worse, the results are not inline so you have to constantly jump between tabs to get results.  Ideally, you want the dumps all in one tab.  There is a way.  LINQPad supports dumping BMP directly to the result window.  Render the chart onto a BMP, and then dump the BMP. 

Code to do the translation from WinForm to BMP is below.  I suggest you add it to your My Extensions class so it is always available.

void DumpShoChart(ShoChart shoChart, int width, int height)
{
    var field = shoChart.GetType().GetField("plot", BindingFlags.Instance | BindingFlags.NonPublic);
    var chart = field.GetValue(shoChart) as System.Windows.Forms.DataVisualization.Charting.Chart;
    chart.Dock = DockStyle.None;
    chart.Size = new Size(width, height);
    using (var stream = new MemoryStream())
    {
        chart.SaveImage(stream, ImageFormat.Bmp);
        Image.FromStream(stream).Dump();
    }
}

Dumping Charts in LINQPad

Erik Meijer and Brian Beckman did a video together on Channel 9 called LINQ – Composability Guaranteed.  The video is good, but in the middle of it Brian showed how to dump charts in LINQPad.  This is awesome!

LINQPad already makes it dead simple to pull data from a DB or an OData feed, or anything for that matter.  Before it was just  another step to graph the data.  Export the data to Excel, then click, click, click, and out pops a nice graph.  Brian showed that going to Excel was unnecessary.  You never have to leave the comfort of LINQPad at all.

With just a little bit of code you can create these types of graphs in the LINQPad result window.  (Copy the code from the forum, or download a copy from here.)

 

yowpdl

tqtfkn

muqcny

muyjnw

LINQPad supports dumping WinForm and WPF controls directly.  Brian’s first attempt actually spawned new windows, but there’s no need.  Just dump your forms, and LINQPad will do the right thing.  Notice how LINQPad created a new button to hold the dumped WinForm chart.  Every time a WinForm is dumped a new WinForm button is created.

linqpad

Test Configuration Sections in .config Files

The .config files centralize and standardize how per application or per library configuration data are stored.  The format can be a little dense to get through, and I always tend to leak this information from my brain.  I only need to know when I start a new project. 

I have had to relearn configuration data yet again, so I figured I should commit it to the electrons so I do not forget again.

Use the tests with external file dependencies post as a starting point.  The tests have to be written this way because the System.Configuration API does not support accepting input from a stream.

Step 1: Create a minimal configuration.  In this case, I have two configuration values.  The maximum number of tasks, and the period.

namespace My.Library
{
    public class MyConfiguration : ConfigurationSection
    {
        [ConfigurationProperty("maxTasks", IsRequired = true)]
        public int MaxTasks
        {
            get { return (int)this["maxTasks"];  }
            set { this["maxTasks"] = value; }
        }
        [ConfigurationProperty("period", IsRequired = false, DefaultValue = "00:00:15")]
        public TimeSpan Period
        {
            get { return (TimeSpan)this["period"]; }
            set { this["period"] = value; }
        }
    }
}

Step 2: Create an example configuration file to use for testing.

<configuration>
  <configSections>
    <section name="myConfig" type="My.Library.MyConfiguration, Library" />
  </configSections>
  <myConfig
    maxTasks="1"
    period="00:00:01" />
</configuration>

NOTE: When defining the configuration section (<section />) at a minimum the type attribute must include the full name of the type (My.Library.MyConfiguration).  The value after the comma is the assembly name (minus .exe/.dll) containing the type.  Additional information can be specified such as the version, and public key token, i.e. strong name of the assembly.

Step 3: Write a test to validate the configuration file.

[Fact]
public void MyConfiguration_OverrideAllValues()
{
    string fileName = Assembly.GetExecutingAssembly().LoadFileAssemblyResource(
        "My.Tests.examples.example1.config");
    try
    {
        ConfigurationFileMap fileMap = new ConfigurationFileMap(fileName);
        Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(
            fileMap);
        MyConfiguration mine = (MyConfiguration)configuration.GetSection(
            "myConfig");
        Assert.Equal(1, mine.MaxTasks);
        Assert.Equal(TimeSpan.FromSeconds(1), mine.Period);
    }
    finally
    {
        File.Delete(fileName);
    }
}

This test validates the configuration data loaded matches the data in the seed file, example1.config.  There are two other tests that should be written.

  1. Validate that period correctly defaults to 15 seconds.
  2. Validate that MaxTasks is a required parameter.

Tests with External File Dependencies

Testing a system where you have to reach outside the environment can be awkward.  A piece of code that requires a file name instead of a Stream is bad, and to be avoided.  While this can be enforced when using one’s own code, it is not true when utilizing third party code.

If you have to test an interaction with file data there are several ways to handle it.

  1. Explicitly copy the file in the test.
  2. Use the test framework to ensure the file is deployed with your test.
  3. Embed the test data in your assembly, and recover the file data at test time.

I favor option the last option because I think it offers the most flexibility.  The first option requires you to account for a resource beyond your test and binary bits.  The second option requires you to manage data outside of your IDE, i.e. cleaning up all of those test specific directories.

Step 1: Add the file to test against to the solution.  I typically add mine to an examples folder in the test project.

image

Step 2: Embedded the file in the assembly, so when you build the project the file is packed into the assembly.

To embed the file on build do the following.

  1. Right-click the file to embed.
  2. Select properties.
  3. Under Build Action select Embedded Resource.

image

Step 3: Create an extension method to extract the resource data to a temporary location on disk.

public static class MyExtensions
    {
        public static string LoadFileAssemblyResource(this Assembly assembly, string resourceName)
        {
            string tempFileName = Path.GetTempFileName();
            using (FileStream fileStream = File.OpenWrite(tempFileName))
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                stream.CopyTo(fileStream);
            }
            return tempFileName;
        }
    }

I like the idea of an extension method, but it is not required.  Accepting the Assembly as a parameter is necessary because you will probably need to differentiate between assemblies instead of just picking the executing assembly.

Step 4: Write a test that requires the external file, run the test, assert the results, and cleanup the fie.

[Fact]
public void Test()
{
    string fileName = Assembly.GetExecutingAssembly().LoadFileAssemblyResource(
        "My.Tests.examples.example1.txt");
    try
    {
        var lines = File.ReadAllLines(fileName);
        Assert.Equal(5, lines.Count());
    }
    finally
    {
        File.Delete(fileName);
    }
}

NOTE: The name of the file is not used to locate the file in the assembly, rather the name of the resource is.  The resource name is made up of the default assembly namespace, the folder path, and the name of the file all concatenated by a period.  This is why the file is loaded by using the name “My.Tests.examples.example1.txt” and not “example1.txt”.

ruby Sinatra and SSL

I am experimenting with the Google JSON API by writing a back end service.  My intent is to re-use the available client libraries to communicate with my service.  I need to test my implementation, and the mechanics of it all to understand how it works.  I used an existing simple Google service to see how the client would interact with it.

I wanted to mock the Google service quickly, so I started with Sinatra.  I implemented HTTPS support just because – not strictly necessary for this experiment.  I had to hack up the Google service document schema to redirect all URIs from www.googleapis.com to localhost, and I made a few edits to the Google ruby client to override the default port.

The code snippet below creates a self-signed certificate on every start.  I never remember the correct OpenSSL incantation to create a self-signed certificate.  I can find the answer by asking the oracle, but it seems to take a while.  I did not want to have to create another certificate ever again.  By default the auto-generated certificate is good for one year.  (I never expect the service to run for that long.)

Sinatra is configured to response with Hello World! when issuing an HTTP GET request to http://localhost:4567/.  All other HTTP GET requests simply respond with URI requested.  HTTP POST requests echo the data back to the client in the payload.

require 'sinatra/base'
require 'webrick'
require 'webrick/https'
require 'openssl'
name = "/C=US/ST=SomeState/L=SomeCity/O=Organization/OU=Unit/CN=localhost"
ca   = OpenSSL::X509::Name.parse(name)
key = OpenSSL::PKey::RSA.new(1024)
crt = OpenSSL::X509::Certificate.new
crt.version = 2
crt.serial  = 1
crt.subject = ca
crt.issuer = ca
crt.public_key = key.public_key
crt.not_before = Time.now
crt.not_after  = Time.now + 1 * 365 * 24 * 60 * 60 # 1 year
webrick_options = {
    :Port               => 4567,
    :SSLEnable          => true,
    :SSLVerifyClient    => OpenSSL::SSL::VERIFY_NONE,
    :SSLCertificate     => crt,
    :SSLPrivateKey      => key,
    :SSLCertName        => [[ "CN", WEBrick::Utils::getservername ]],
}
def agg_lines(data)
    data.each_line.collect{|x| "  >> #{x}" }.join
end
class MyServer < Sinatra::Base
    get '/' do
        "Hello World!\n"
    end
    get '*' do |x|
        "GET of URI #{x}\n"
    end
    post "*" do |x|
        request.body.rewind
        "POST to URI #{x}\n#{agg_lines(request.body.read)}\n"
    end
end
server = ::Rack::Handler::WEBrick
trap(:INT) do
    server.shutdown
end
server.run(MyServer, webrick_options)

I pieced this script together by crawling StackOverflow posts, and reading documentation.

In Search of rsync for Windows

I like almost everything about rsync.  The efficiency employed when transferring files, the mind-numbing command line options for just about every situation, the ability to work over a pipe, and network synchronization.  The biggest fail is the lack of native Windows support.  Syncing files is not solely relegated to UNIX, so anytime I have two directories to synchronize I shake my fists at the heavens,  “O rsync, rsync, wherefore art thou rsync!”

There are alternatives to rsync on Windows, and I use some of them with various levels of success.  I actually think the tools are fine, and work quite well.  The problem is me, I want to use these tools as if they were actually rsync, and they are not.

Sync Toy

Microsoft provides the free program SyncToy.  It can synchronize two directories, and works well.  It is not quite rsync because…

  1. Must define the directory pairs upfront through a UI.
  2. Leaves debris on the file system that contains records of the data moved between the two directories.
  3. The real power of this tool feels obscured by the UI. 

The latest version of SyncToy (2.1) greatly improves upon previous versions.  I setup jobs, and run them every now and again.

Robocopy

Robocopy is a command line utility to copy files.  It should be available in the default OS install, so if you have Windows it is there.  Robocopy supports mirroring two directories.

Create a backup up My Pictures – save all of the images (*.jpg fies) to my portable USB drive E:.

cmd> robocopy “My Pictures” E:\backup\pictures /MIR *.jpg

Create a backup up My Pictures to my NAS device.  Create a record so if the transfer if interrupted it can be automatically resumed.

cmd> robocopy “My Pictures” \\nas\backup\pictures /MIR /Z *.jpg

Robocopy has lots more options too.  One can do multi-threaded copy, bandwidth throttling, just create directory tree and file names (no data), etc.  Well worth a look for the CLI inclined.

Duplicati

Duplicati is a reimplementation of duplicity for Windows.  They are both great backup utilities, but not exactly what I want.  I mention them because Duplicati’s author created an rsync library for C#.  This library would be a great starting point for a Windows rsync implementation.

There are other rsync library available such as librsync, and rsync.net.  I like the idea of Duplicati’s because it is attached to an actively maintained and working application.  Start reading the source too see the implementation.

In the end it was me, not rsync.  I think the tooling on Windows is more than sufficient to do what I want – mirror two directories.  I leave the door open for experimentation.  I may write my own synchronization tool to bring a few more of the rsync-like abilites to Windows natively.  SyncToy is built upon a publicly available API, and Duplicati provides an OSS .NET rsync library too, so who knows.

Page optimized by WP Minify WordPress Plugin