Just A Programmer We're just programmers

27Apr/123

All Aboard #SQLAmtrak

Update: I have settled on the train.

I have three announcements in this post. First of all, I’d like to announce that I will be speaking at SQL Saturday 121 in Malvern, PA, just outside of one of my favorite cities, Philadelphia. Secondly, I’d like to announce that I will be taking Amtrak there from Newark Penn Station in Newark, NJ. Finally, I’m inviting you all to join me in a little adventure I’d like to call #SQLAmtrak!

Why #SQLAmtrak?

Because I love traveling by rail, and I’m sure I’m not the only one! I enjoy flying, and long drives. However, Amtrak is my favorite way to travel. In fact, just this Tuesday and Thursday I took Amtrak from Newark to Philadelphia to speak at PhillyNJ.NET and PhillyDB respectively. Previously I’ve also taken Amtrak to DC for MongoDC, and in December I took the entire route of the California Zephyr as part of a convoluted journey to MongoSV and the first MongoDB Masters conference. (BTW, I’ve also taken Amtrak to non-nerdy things with my wife. I swear sometimes I pretend to be normal!)

When you love something this much you want to share it with the world! I want to share this experience with members of #SQLFamily, most of whom I only know through the internet, and many I’ve not ever met in virtually.  I know if we all spend an hour and a half on a train together, it will be a great social experience. BTW if you need a business justification, call it a networking experience.

Ok, but how many people from Newark will be attending SQL Saturday 121?

The answer might be zero, because I actually live in Jersey City. Seriously though, this Amtrak journey makes sense for several groups of people.

  • If you live or work in New York City, the train stops at New York Penn Station before Newark
  • The train will also stop in Metro Park and Trenton, which are easily accessible from Central Jersey
  • If you work in the city of Philadelphia, you can join us for the last part of the journey from Philadelphia 30th Street station to Paoli.
  • Finally, if you are flying in, you can fly to EWR, you can take the New Jersey Transit one stop from Newark Airport to Newark Penn Station. Its quite likely that you can get a cheaper/faster/more direct flight from wherever you are coming to EWR as opposed to a Philadelphia airport.

What train are we taking?

Originally I was proposing that we take Amtrak Keystone Train 655. Which gets to Paoli at 8:40pm. However, I have book tickets for Keystone Train 651, which arrives at 6:02. The complete schedule for both trains is as follows:

Station Train 651 Departs Train 655 Departs Ticket Price
NY Penn 4:03 6:35 $50
Newark 4:20 6:52 $49
EWR * 3:49 6:40 $63
Trenton 4:55 7:28 $32
Conrwells Heights N/A 7:40
North Philly N/A 7:52
30th Street Phil 5:35 8:00 $6.50
Ardmore 5:48 8:15
Paoli 6:02 8:40

* For those flying in, its $5.50 for an Air train ticket to the NJ transit station and $8.50 to take NJ Transit from EWR to Newark Penn. You can buy those tickets on arrival.

Note that you need to buy a ticket in advance if you will get on the train before 30th Street. Also, ticket prices go up the longer you wait. Finally, there is no business class available on this train. Even if there was, not everyone would want to spring for it, and the whole point of this is for the gathering to be social, so we will take coach.

What if I get to Newark Penn early?

People will want to fly in early, and will likely want to have a light meal and or drinks before departing. For those of us who will be departing from Newark, I am proposing we go to Iberia Restaurant a short walk from Newark Penn in the Portuguese Ironbound section of Newark, voted best Sangria in the Ironbound by my wife and I. Weather permitting there is outdoor seating, and the tapas are great.

What do I have to do to take part?

If you plan on going, email my at justin@ the domain of this blog. Everyone is responsible for buying their own train tickets. I’m going to hold off until Sunday May 6th (one week from today) before buying mine in case I get some feedback that other people would prefer a different time. Iberia doesn’t require reservations, so you don’t have to commit to going to the restaurant.

What about the return trip?

I’m open to the idea of a coordinated return trip. However, I don’t expect a good consensus to happen for that.

How should I promote this?

Blog/tweet/etc about this. Tell your friends! Use the hashtag #SQLAmtrak.

19Apr/120

PowerShell 3.0 [ordered] and MongoDB

Recently, Shay Levy published a blog post about new features related to the Add-Member cmdlet in PowerShell 3.0. In it, one of the examples involved the use of [ordered]. The example, shown below is:

PS&gt; $pso = New-Object -TypeName PSObject<br />
PS&gt; $pso | Add-Member ([ordered]@{One=1; Two=2; Three=3}) -PassThru</p>
<p>One Two Three<br />
&#8212; &#8212; &#8212;&#8211;<br />
  1   2     3

The take home of this example was simple; using the @{} operator by itself created a System.Hashtable object, and the order of those keys are not guaranteed. Therefore not guaranteeing the order of the properties of the PSObject. However we could use [ordered] to make it an “ordered hashtable” (Shay’s words).

So I spent some time looking for the MSDN documentation for OrderedHashtable. I never found it so I decided to fire up my Windows 8 VM and see what its type is.

PS C:Userszippy&gt; [ordered]<br />
Unable to find type [ordered]: make sure that the assembly containing this type is loaded.<br />
At line:1 char:1<br />
+ [ordered]<br />
+ ~~~~~~~~~<br />
    + CategoryInfo          : InvalidOperation: (ordered:TypeName) [], RuntimeException<br />
    + FullyQualifiedErrorId : TypeNotFound

Eventually, I figured out the problem is that [ordered] is not a type alias. I’m actually not exactly sure what it is, but I’m pretty sure its not a type alias. I did figure it it creates OrderedDictionaries.

    PS C:Userszippy&gt; ([ordered]@{}).GetType()</p>
<p>    IsPublic IsSerial Name                                     BaseType<br />
    &#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;-                                     &#8212;&#8212;&#8211;<br />
    True     True     OrderedDictionary                        System.Object

So I said to myself, “ok that’s cool, but can I cast from an OrderedDoctionary to a MongoDB.Bson.BsonDocument with the MongoDB .NET driver?” I say this because a while back I submitted some patches to improve the driver’s user experience in PowerShell. My main goal was to be able to use the HashTable notation to define a BsonDocument like so:

[MongoDB.Bson.BsonDocument] $doc = @{<br />
    &quot;_id&quot;= [MongoDB.Bson.ObjectId]::GenerateNewId();<br />
    &quot;FirstName&quot;= &quot;Justin&quot;;<br />
    &quot;LastName&quot;= &quot;Dearing&quot;;<br />
    &quot;PhoneNumbers&quot;= [MongoDB.Bson.BsonDocument] @{<br />
        &#8216;Home&#8217;= &#8217;718-555-1212&#8242;;<br />
        &#8216;Mobile&#8217;= &#8217;646-555-1212&#8242;;<br />
    };<br />
};

The only problem with this notation is you cannot define the order of the keys. Luckily, I found that [Ordered] works flawlessly!

[MongoDB.Bson.BsonDocument] $doc = [ordered]@{<br />
    &quot;_id&quot;= [MongoDB.Bson.ObjectId]::GenerateNewId();<br />
    &quot;FirstName&quot;= &quot;Justin&quot;;<br />
    &quot;LastName&quot;= &quot;Dearing&quot;;<br />
    &quot;PhoneNumbers&quot;= [MongoDB.Bson.BsonDocument] [ordered]@{<br />
        &#8216;Home&#8217;= &#8217;718-555-1212&#8242;;<br />
        &#8216;Mobile&#8217;= &#8217;646-555-1212&#8242;;<br />
    };<br />
};

I’ve updated the gist repo for my post on using MongoDB with PowerShell.