Subscribe: Lance's TextBox
http://geekswithblogs.net/lance/rss.aspx
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
add  create  data  expedia  geekswithblogs net  lance archive  lance  net lance  net  new  originally posted  posted geekswithblogs 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Lance's TextBox

Lance's TextBox



» About Me » My Resume »Twitter



Copyright: Lance Robinson
 



Merge Delimited Files on a Common Key

Tue, 18 Oct 2011 17:17:52 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/10/18/merge-delimited-files-on-a-common-key.aspxMany times I need to merge two separate datasets that have a common key column – for example: dataset 1: ID, Name, Weight, Height dataset 2: ID, Address1, Address2, Phone1, Phone2 I can’t just concat the data together, instead I need the merge to happen around the ID key, so that each ID only has a single row in the result.  So, of course I wrote a powershell script to do this for me.  Take a look at it below.  I called it “Merge-TsvFiles”, but it takes a delimiter as one of its paramters, so you could use this for CSV or whatever. If you have any thoughts as to how this can be further improved code-wise or speed-wise, please comment! function Merge-TsvFiles {   param(     [string] $file1 = $(throw "file1 required."),     [string] $file2 = $(throw "file2 required."),     [string] $delimiter = "`t",     [string] $key = "ProfileID"   )   $data1 = import-csv -path $file1 -delimiter $delimiter   $data2 = import-csv -path $file2 -delimiter $delimiter   #write-host "$data1.Length total data rows, and $data2.Length total merge data rows."   $i = 0   #grab the new column names   $newcols = $data2 | gm -MemberType NoteProperty   Foreach ($datarow in $data1)   {     $i++     $data2 | where-object {$_.$($key) -eq $data1.$($key)} | %{       Foreach ($col in $newcols) {         if ($col.Name -ne $key) {           Add-Member -inputObject $datarow -name $col.Name -value $_.$($col.Name) -MemberType NoteProperty;         }       }     }   Write-Progress -activity "Merging data" -status "Merged $i of $($data1.Length) rows..." -percentComplete (($i / $data1.length) * 100)  } write-host "Writing output..." $data1 | export-csv "output.txt" -delimiter "`t" } Technorati Tags: PowerShell,Data Merge,CSV,TSV [...]



VS2010 Find In Solution Explorer Hotkey/Toolbar Button

Wed, 31 Aug 2011 14:29:29 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/08/31/vs2010-find-in-solution-explorer-hotkeytoolbar-button.aspx

First I found this blog post – which worked but only after some tinkering.  There is a comment there that describes a better (simpler) solution, IMO.

Step 1: Create the following macro, which simply toggles (twice) the existing TrackActivityinSolutionExplorer command – this is the same command that happens if you turn on solution explorer tracking in Visual Studio options, except here we’re turning it on and then immediately off:

Public Sub SelectCurrentItemInSolutionExplorer()
  DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
  DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
End Sub

Step 2: Create a toolbar button to run this macro.  To do this, right click on the toolbar and click customize.  Click “New…” to create a new toolbar, I took the default name of “Custom 1”.  Go to the “Commands” tab and click the “Toolbar” radio button, select your new toolbar from the dropdown list.  Click “Add Command…”, select Macros from the categories list and select your new “SelectCurrentItemInSolutionExplorer” macro as the command.  Click “OK'”, then you can “Modify Selection” to give it a custom name or image.

Technorati Tags: ,
(image)



How Expedia Made My New Bride Cry

Sun, 19 Jun 2011 14:00:02 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/06/19/how-expedia-make-my-new-bride-cry.aspxIf you would like to help me out, you can Tweet this story OR email Expedia and ask them to make things right for me and my wife. This is the story of how Expedia made my new bride cry. When Expedia followed up their failure with our honeymoon trip with a complete and total lack of acknowledgement of any responsibility for the problem and endless loops of explaining the issue over and over again - I swore that they would make it right. When they brought my new bride to tears, I got an immediate and endless supply of motivation. I hope you will help me make them make it right by posting our story on Twitter, Facebook, your blog, on Expedia itself, and when talking to your friends in person about their own travel plans.   If you are considering using them now for an important trip - reconsider. Short summary: We arrived early for our honeymoon flight - but Expedia had made a mistake with the data they supplied to JetBlue and Emirates, which resulted in us not being able to check in (one leg of our trip was missing)!  At the time of this post, three people (myself, my wife, and an exceptionally patient JetBlue employee named Mary) each spent hours on the phone with Expedia.  I myself spent right at 3 hours (according to iPhone records), Lauren spent an hour and a half or so, and poor Mary was probably on the phone for a good 3.5 hours.  This is after 5 hours total at the airport.  If you add up our phone time, that is nearly 8 hours of phone time over a 5 hour period with little or no help, stall tactics (?), run-around, denial, shifting of blame, and holding. Details below (times are approximate): First, my wife and I were married on June 18th, the 3 year anniversary of our first date. She is awesome. She is the nicest person I have ever known, a ton of fun, absolutely beautiful in every way. Ok enough mushy - here are the dirty details. June 19th, 2:30 AM - Early Check-in Attempt - we attempted to check-in for our flight online. Some sort of technology error on website, instructed to checkin at desk. 4:30 AM - Arrive at airport. Try to check-in at kiosk, get the same error. We got to the JetBlue desk at RDU International Airport, where Mary helped us. Mary discovered that the Expedia provided itinerary does not match the Expedia provided tickets. We are informed that when that happens American, JetBlue, and others that use the same software cannot check you in for the flight because. Why? Because the itinerary was missing a leg of our flight! Basically we were not shown in the system as definitely being able to make it home. Mary called Expedia and was put on hold by their automated system. 4:55 AM - Mary, myself, and my brand new bride all waited for about 25 minutes when finally I decided I would make a call myself on my iPhone while Mary was on the airport phone. In their automated system, I chose "make a new reservation", thinking they might answer a little more quickly than "customer service". Not surprisingly I was connected to an Expedia person within 1 minute. They informed me that they would have to forward me to a customer service specialist. I explained to them that we were already on hold for that and had been for nearly half an hour, that we were going on our honeymoon and that our flight would be leaving soon - could they please help us. "Yes, I will help you". I hand the phone to JetBlue Mary who explains the situation 3 or 4 times. Obviously I couldn't hear both ends of the conversation at this point, but the Expedia person explained what the problem was by stating exactly what Mary had just spent 15 minutes explaining. Mary calmly confirms that this is the problem, and asks Expedia to re-issue the itinerary. Expedia tells Mary that they'll have to transfer her to customer service. Mary asks for someone specific so that we get an answer this time, and goes on hold. Mary get's connected, explains the situatio[...]



Soooo Good Vegetarian Lasagna

Thu, 05 May 2011 17:16:17 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/05/05/soooo-good-vegetarian-lasagna.aspx

(image) I know I don't usually blog about food - but it is one of my favorite things in life!  So I just had to share this quick and easy recipe for vegetarian lasagna because it tastes amazing.  It started as some recipe I found from a web search, but I didn't have certain ingredients and I wanted to add others, so here's what I ended up with:

In a large pot, sautee:
1 T olive oil
1 T dried thyme
1 T dried basil
2 cloves garlic, smashed
1 large chopped onion
1 10oz package of frozen spinach (add this last so the flavor of the herbs can come out in the oil)

Then add the following and simmer for 20 min.  The sauce will be very chunky when finished:
32 oz fire roasted diced tomatoes
1 cup spagetti sauce of your choice
1/2 cup water
1 zucchini, sliced
2 jalapenos, sliced

In a separate bowl combine 8oz mozzerella, 1/2 cup grated parmesan, and 2 cups of ricotta (I used low fat).

In baking dish layer sauce, dry lasagna noodles, sauce, noodles.  Then layer spinach, cheese, sauce, noodles and repeat, finishing with sauce on top.  If you don't have enough sauce left over at the end to completely cover the noodles, don't worry about it too much.  This makes great leftovers, and the microwave will soften those exposed oven hardened noodle edges.

Wow.  :)  I would post a picture but I ate it.  Will add later.

(image)



ADO.NET Entity Framework – Code First Development Pattern

Thu, 14 Apr 2011 07:42:00 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/04/14/ado.net-entity-framework-ndash-code-first-development-pattern.aspxHere’s a quick start introduction to the ADO.NET Entity Framework Code First Development Pattern.  For a more complete (but still intro) walkthrough, check out ScottGu’s blog. At the time of this writing, you’ll need the EF 4.1 Release Candidate.  After EF 4.1 is released you’ll no doubt be able to find it on the ADO.NET team blog. 1.  Create a new empty ASP.NET MVC2 Web Application, add a reference to System.Data.Entity.  If using the EF4.1 RC - add a reference to the EntityFramework dll that comes installed with it. 2.  Add the model classes you’d like to represent your data objects.  For example if you need to represent game nights, you might create a class called Game with properties that describe the game night date, location, and other information. 3.  Create a “Context Class” that inherits DbContext, which contains nothing but DbSet public properties.  For example if you created in step 2 a class called “Game”, here you’d have a property defined as: public DbSet Games { get; set; } At this point, EF code first will make certain assumptions (which we can override later if necessary) that allow us to write less code: - The context class will map its properties (those DbSet properties) to tables with the same names (a Games table, in our example). - Each row in that table will map to an instance of the model class (a Game instance, in our example).  - Properties in the model class are columns in the table. - A property in the model class with the name “Id” or “Id” will be made the primary key. - Relationships between tables are inferred if one model class has a property with the name “Id”. 4.  Add a controller to see EF Code First in action.  For example, add Index (to just return a list of our game nights) and Create actions (to create a new game night). 5.  Add the views (Index: strongly typed IEnumerable of Game, Create: strongly typed Game – content Create). 6.  Create the database.  One of those EF Code First assumptions is that it will automatically look for a connection string with the same name as the context class (eg, Games).  Scott Guthrie recommends the use of SQL CE 4 for early development, and moving to SQL Server or SQL Express closer to the time of deployment. Important:  IF you’re using SQL CE or SQL Express, and your connection string points to a database file that does not yet exist, it will be automatically created for you! Updating The Model If you update the model (lets say we add a new property to our Game class), you’ll get an error the next time you attempt to run the application (“context has changed since the database was created”.  EF Code First can handle this too:  in Global.asax, add the following to the Application_Start event handler: Database.SetInitializer<>(new RecreateDatabaseIfModelChanges<>()); RegisterRoutes(RouteTable.Routes); Gu gives a nice tip – create a custom class that implements RecreateDatabaseIfMOdelChanges< and overrides the Seed function to add “seed” rows to the database with default data.  This way when we recreate the database after a model update, the database isn’t empty – but is seeded with our default data.  Use this new custom class in the call to SetInitializer instead of RecreateDatabaseIfModelChanges. Technorati Tags: ASPNET,MVC,Entity Framework,EF,Code First [...]



Visual Studio 2010 Find and Replace With Regular Expressions

Thu, 10 Mar 2011 22:07:24 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/03/10/visual-studio-2010-find-and-replace-with-regular-expressions.aspx

Here is a quick notes about using regular expressions in the VS2010 Find Replace dialog. 

1.  To create a backreference, use curly braces (“{“ and “}” ) instead of regular parentheses.

2.  To use the captured backreference, use \1\2 etc, where \1 is the first captured value, \2 is the second captured value, etc.

Example:

I want to find*:

info.setFieldValue(param1, param2);

and replace it with:

SetFieldValue(info, param1, param2);

To do this, I can use the following find/replace values:

Find what:

{[a-zA-Z0-9]+}.setFieldValue\({[a-zA-Z0-9., ]+}\);

Replace with:

SetFieldValue(\1, \2);

Use Regular Expressions is checked, of course.

*If you’re wondering why I’d want to do this – because I don’t have control over the setFieldValue function – its in a third party library that doesn’t behave in a very friendly manner.

(image)



Creating Team Foundation Work Items With PowerShell

Wed, 26 Jan 2011 15:58:22 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2011/01/26/creating-team-foundation-work-items-with-powershell.aspxHere is the simple function I added to my powershell profile:               function create-tfstask ($desc) { tfpt workitem /new $workItemType /collection:$serverUrl /fields:"Title=$($desc);Assigned To=$assignee;AreaId=$areaId;IterationId=$iterationId" }         To find the AreaId and IterationId for your project/versions, just look at a bug you know is setup correctly: PS C:\> tfpt query /collection:http://3bs001vsteam:8080/tfs /wiql:"select AreaId,IterationId from workitems where ID = 879" Next I hooked this into my existing "todo" function by adding a new case in its $target switch statement for “tfs”, which calls my create-tfstask function and returns.  Updated todo function:           function todo { param([string] $target = "work", [string] $msg ) $emailFrom = "lance@3birdsmarketing.com" #combine all the cmd line args into one "message" if ($args -ne "") { $msg = $msg + " " + $args } #what is the target of the message? switch ($target) { "work" { $target = "lance@3birdsmarketing.com" } "home" { $target = "lmrobins@gmail.com" } "tfs" { create-tfstask $msg; return } } $subject = "Todo: " + $msg $body = $msg $smtpServer = "3bs001exch" $smtp = new-object Net.Mail.SmtpClient($smtpServer, 25) $smtp.Send($emailFrom, $target, $subject, $body) }       Technorati Tags: PowerShell,TFS,Team Foundation [...]



How do I rollback a TFS check-in?

Tue, 21 Dec 2010 16:24:04 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2010/12/21/how-do-i-rollback-a-tfs-check-in.aspx

I can never remember how to rollback a check-in, and there all kinds of mess in search results about this (change between different versions of TFS etc), so I thought I’d just put this here so I won’t forget anymore.  :)  Thanks to @manningj, TFS genius.

Just drop to the command line and use tf.exe.

Example:

tf rollback /changeset:12345

For more on the tf.exe commands:

tf help

(image)

(image)



PowerShell – Recycle All IIS App Pools

Thu, 16 Dec 2010 20:59:17 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2010/12/16/powershell-ndash-recycle-all-iis-app-pools.aspx

With a little help from Shay Levy’s post on Stack Overflow and the MSDN documentation, I added this handy function to my profile to automatically recycle all IIS app pools.

 
 
 
 
 
function Recycle-AppPools {
  
    param(
    [string] $server = "3bhs001",
    [int] $mode = 1, # ManagedPipelineModes: 0 = integrated, 1 = classic
    ) 

 $iis = [adsi]"IIS://$server/W3SVC/AppPools"
$iis.psbase.children | %{
$pool = [adsi]($_.psbase.path);
   if ($pool.AppPoolState -eq 2 -and $pool.ManagedPipelineMode -eq $mode) {
   # AppPoolStates:  1 = starting, 2 = started, 3 = stopping, 4 = stopped         
     $pool.psbase.invoke("recycle")
     }
   }

}

 
 
 

 

(image)



Quick PowerShell “Todo” Gmail Emailer

Tue, 26 Oct 2010 17:27:13 GMT

Originally posted on: http://geekswithblogs.net/Lance/archive/2010/10/26/quick-powershell-ldquotodordquo-gmail-emailer.aspxI put the following function in my PowerShell profile so that I can just bring up my PowerShell console and type myself a quick “todo” note that automatically gets emailed to me for later.  There are several things of note in this tiny script: 1.  Note the use of the $args variable to effectively allow the user to enter $msg parameter without quotes even if it contains whitespace. 2.  In this particular example I’m sending the email through Gmail.  smtp.gmail.com, port 587, SSL and authentication required. 3.  Check outhe $gmailcred variable, which gets set earlier in my profile.  It gets read from a secure string file.             function todo { param([string] $target = "work", [string] $msg ) switch ($target) { "work" { $target = "lance@3birdsmarketing.com" } "home" { $target = "lmrobins@gmail.com" } } $emailFrom = "lmrobins@gmail.com" if ($args -ne "") { $msg = $msg + " " + $args } $subject = "Todo: " + $msg $body = $msg $smtpServer = "smtp.gmail.com" $smtp = new-object Net.Mail.SmtpClient($smtpServer, 587) $smtp.EnableSsl = $true $smtp.Credentials = [Net.NetworkCredential]($gmailcred) $smtp.Send($emailFrom, $target, $subject, $body) }       Technorati Tags: PowerShell,Gmail,Parameters [...]