Saturday, August 27, 2011

Atlantic Beach

Atlantic Beach
Atlantic Beach welcomes new visitors and vacationers back with a hot sun and a wealth of activities. Enjoy the beautiful beaches and major attractions, while enjoying the historic beauty, heritage and amazing the area is known for.
They say there are at least 101 things to do on the coast of crystal, and we say with certainty that it is true. Atlantic Ocean and the Intracoastal Waterway and rivers winding, water-activities include boat tours, cruises, scuba diving, Tours Ecology, fishing piers and fishing, kayaking and boat rentals and more. Atlantic Beach offers one of the best dive destinations in the United States and its natural beauty is unmatched.
The story is also a major attraction at the Crystal Coast. Visitors can enjoy many fun activities along the beach of the Atlantic. For family fun, miniature golf, bumper cars and jetskis fabulous diversions.
Local heritage is also indicated in attractions such as the historic site and museum Core Sound Waterfowl. Skilled craftsmen also gathered along Atlantic Beach. Galleries, arts and entertainment and craft sales abound.
The Crystal Coast is a golfer's paradise with many top flight courses to choose from. With several golf courses in the region, such as Brandywine Bay, Star Hill and Silver Creek Golf Course, you can play from sun up to sundown.
Fall offers the North Carolina Seafood Festival the first week in October on the waterfront of Morehead City and Atlantic Beach King Makerel tournament in September.
Whether in spring, summer or fall, the beautiful Crystal Coast has something to offer everyone. Atlantic Beach offers the serenity of a lazy one week holiday and a weekend. Call our location in Atlantic Beach real estate and blue water vacation to find your "little place in the sun" today.

Wednesday, August 17, 2011

How to query windows azure diagnostics for a time range?

Windows Azure Diagnostics stores data in Azure Table. Unfortunately, Azure Table only supports a single index, which means queries that don't use the index are dog slow.  In azure terminology, that index is the partition key, and Windows Azure Diagnostics sets the partition key on your behalf using the following formula:     0 + DateTime.Ticks

You can generate the Partition key query in powershell for all logs after 7/15 by doing:
PS C:\> "PartionKey gt '0$((Get-Date '2011/7/15').Ticks)'"
PartionKey gt '0634462848000000000'


For the curious, gt is the greater than operator in Azure Table, which is based on ADO.Net DataServices, which is now called WCF Data Services, which is  OData.

Monday, August 8, 2011

F# and the immediate window

(This post is inspired from this Stack Overflow question)



F# debugger integration is quite good, except for the immediate window. The immediate window requires C# style syntax, so calling F# functions is not intuitive. Below are recipes for the immediate window integrated into a console application. As always code can be found here:

// Learn how to use the immediate window for F#.
module Program=

// To build, add a reference to Microsoft.CSharp. This is required for dynamic support in
// the debugger.
let allowDynamicToWorkFromImmediateWindowByLoadingCSharpBinders = Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.BinaryOperationLogical

let plusOne = (+)1
let xPlusOnes = [1;2;3] |> Seq.map plusOne

[]
let main (args) =
printfn "Try the following in the immediate window:
// plusOne 4
((dynamic)plusOne).Invoke(4)

// Seq.Head xPlusOnes
Microsoft.FSharp.Collections.SeqModule.Head(xPlusOnes)

// let xPlusTwos= xPlusOnes |> Seq.map plusOne
// Seq.Head xPlusTwos
var xPlusTwos = Microsoft.FSharp.Collections.SeqModule.Map(plusOne,xPlusOnes);
Microsoft.FSharp.Collections.SeqModule.Head(xPlusTwos)"

System.Diagnostics.Debugger.Break()
let returnValue = 1
returnValue

Sunday, July 17, 2011

Using Ads to get free DropBox storage space.

(I did not "invent" this idea, someone told me about it. I figure you'll be interested in the experience, it was rather surprising for me.)

Google makes money on ads, oodles and oodles of it. Up until today, I never "understood" the value of ads.  Today, I got a chance to use ads, here is my story:

Dropbox is a storage service, if your friend signs up by clicking your referral URL, both you and your friend get 250MB of free storage up to 8GB of storage. This means if you can get 32 (8GB/250MB) friends to sign up you get lots of free storage.

As you can imagine, I don't have 32 friends, so the question is how do I get people to click on my URL? Ads!  I signed up for a Google AdWords account, and created an add which read - "Download DropBox and get free 250MB of storage". Here are the stats from my experiment:

  • Total Cost: $15.00
  • Cost/GB:$1.87/GB
  • Impressions (number of times add shown): 3.6K
  • Clicks: 257
  • Average Cost per Click 0.06
  • Conversions (times people installed DropBox after clicking) : 32

In this experiment each of impressions -> clicks -> conversions, is a 10x decrease, which seems astronomically high to me.  Seriously, 1 in a 100 people who saw my ad signed up for DropBox.  No wonder eyeballs are so valuable!

A final note for the clever among you, would it have been cheaper to purchase storage from dropbox instead of paying for ads?  DropBox pricing is $2.40/GB/Year,  and worse you can only purchase it in increments of 50GB.  Thus, using ads and the referral system is a good deal.

Saturday, July 2, 2011

Using WinDBG/CDB and SOS to find a thread given a ManagedThreadId

CDB and SOS have more power than most people realize, I’ll use this post to show some some handy cdb/sos tricks while at the same answering the simple question of which thread a ManagedThreadId maps to.

At the end of this post you’ll be able to:

  • Map a ManagedThreadId to the correct thread ordinal
  • Use CDB to convert from decimal to hex
  • Pipe CDB commands through pipeline commands like findstr

Full source for the simple app below can be found here. In the below app we want to figure which thread we’re running on so we can inspect the stack.

    internal class Program
{
private static void SleepForever() { Thread.Sleep(Int32.MaxValue); }

static void Main(string[] args)
{
const int countThreadsToStart = 20;
foreach (var unused in Enumerable.Range(0, countThreadsToStart))
{
// Instantiate thread that prints and stores its ManagedThreadId.
new Thread(() =>
{
// store ThreadId as an object as this forces boxing and lets us find the object on the stack via !dso in SOS.
object boxedThreadId = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine("Find my threadId of {0}", boxedThreadId);
SleepForever();
}).Start();
}
SleepForever();
}
}


Step 1, run this app in CDB:



 PS C:\hgs\ig2600_blog\FindTheThread\bin> C:\bin_drop\public_dbg_64\cdb .\Debug\FindTheThread.exe

Microsoft (R) Windows Debugger Version 6.11.0001.404 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: .\Debug\FindTheThread.exe

Find my threadId of 3
Find my threadId of 4
Find my threadId of 5
Find my threadId of 6
Find my threadId of 7
Find my threadId of 8
Find my threadId of 9
Find my threadId of 10
Find my threadId of 11
Find my threadId of 12
Find my threadId of 13
Find my threadId of 14
Find my threadId of 15
Find my threadId of 16
Find my threadId of 17
Find my threadId of 18
Find my threadId of 19
Find my threadId of 20
Find my threadId of 21
Find my threadId of 22
(e28.c94): Break instruction exception - code 80000003 (first chance)
ntdll!DbgBreakPoint:
00000000`7744ef90 cc int 3
0:025> .loadby sos clr


Lets say our goal is to debug what’s running on thread 21, how do we know which thread ordinal we should debug on?   Luckily we have a !Threads command:



 0:025> !threads
ThreadCount: 22
UnstartedThread: 0
BackgroundThread: 1
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
PreEmptive Lock
ID OSID ThreadOBJ State GC GC Alloc Context Domain Count APT Excepti
on
0 1 224c 000000000054dd80 200a020 Enabled 0000000002ac90b0:0000000002ac9fd0 00000000004ee680 0 MTA 2 2 c8c 0000000000553bd0 b220 Enabled 0000000000000000:0000000000000000 00000000004ee680 0 MTA (Finalizer)
4 3 1670 0000000000591620 200b020 Enabled 0000000002ac3be0:0000000002ac3fd0 00000000004ee680 0 MTA
5 4 1c84 0000000000578370 200b020 Enabled 0000000002ac4160:0000000002ac5fd0 00000000004ee680 0 MTA
6 5 1a54 000000000057a190 200b020 Enabled 0000000002ac6160:0000000002ac7fd0 00000000004ee680 0 MTA
7 6 2364 0000000000591f90 200b020 Enabled 0000000002aca160:0000000002acbfd0 00000000004ee680 0 MTA
8 7 b38 0000000000593570 200b020 Enabled 0000000002acc160:0000000002acdfd0 00000000004ee680 0 MTA
9 8 1c88 0000000000594df0 200b020 Enabled 0000000002ace160:0000000002acffd0 00000000004ee680 0 MTA
10 9 ef8 00000000005966b0 200b020 Enabled 0000000002ad0160:0000000002ad1fd0 00000000004ee680 0 MTA
11 a 21d0 0000000000597f70 200b020 Enabled 0000000002ad2160:0000000002ad3fd0 00000000004ee680 0 MTA
12 b 22a8 0000000000599830 200b020 Enabled 0000000002ad4160:0000000002ad5fd0 00000000004ee680 0 MTA
13 c 600 000000000059b0f0 200b020 Enabled 0000000002ad6160:0000000002ad7fd0 00000000004ee680 0 MTA
14 d 2388 000000000059c9b0 200b020 Enabled 0000000002ad8160:0000000002ad9fd0 00000000004ee680 0 MTA
15 e 19b8 000000000059e270 200b020 Enabled 0000000002ada160:0000000002adbfd0 00000000004ee680 0 MTA
16 f 1e9c 000000000059fb30 200b020 Enabled 0000000002adc160:0000000002addfd0 00000000004ee680 0 MTA
17 10 1c9c 00000000005a13f0 200b020 Enabled 0000000002ade160:0000000002adffd0 00000000004ee680 0 MTA
18 11 20c4 00000000005a2d40 200b020 Enabled 0000000002ae0160:0000000002ae1fd0 00000000004ee680 0 MTA
19 12 14bc 00000000005a4600 200b020 Enabled 0000000002ae2160:0000000002ae3fd0 00000000004ee680 0 MTA
20 13 1994 00000000005a5ec0 200b020 Enabled 0000000002ae4160:0000000002ae5fd0 00000000004ee680 0 MTA
21 14 19bc 00000000005a7780 200b020 Enabled 0000000002ae6160:0000000002ae7fd0 00000000004ee680 0 MTA
22 15 1ac 00000000005a9040 200b020 Enabled 0000000002ae8160:0000000002ae9fd0 00000000004ee680 0 MTA
23 16 2084 00000000005aa900 200b020 Enabled 0000000002aea160:0000000002aebfd0 00000000004ee680 0 MTA
0:025>


In this output, the first column is the thread ordinal (which is what the ~ operator works on).  The second column, is the OSID which is the ManagedThreadID,  but is inconveniently the value is displayed in hexdecimal.  To continue we need to find the thread ordinal, given an OSID of 21 in base 16. To convert 21 to hex, use the evaluation operator (?), and pass in an explicitly base 10 number by pre-pending 0n:



 0:025> ? 0n21
Evaluate expression: 21 = 00000000`00000015
0:025>


Now, re-run !threads, but pipe the output through findstr 15 . Findstr can be run via the .shell command:



 0:025> .shell -ci "!Threads" findstr 15"
15 e 19b8 000000000059e270 200b020 Enabled 0000000002ada160:0000000002adbfd0 00000000004ee680 0 MTA
22 15 1ac 00000000005a9040 200b020 Enabled 0000000002ae8160:0000000002ae9fd0 00000000004ee680 0 MTA


OSID 15, is thread 22, lets switch to it with the ~s operator:



0:025> ~22s
ntdll!NtDelayExecution+0xa:
00000000`7745009a c3 ret


To verify we have the correct thread, we can dump the stack and inspect the boxedThreadId Object. We do this with !dso to (dump stack objects) and then run !do (dump object) on the int32.



0:022> !dso
OS Thread Id: 0x1ac (22)
RSP/REG Object Name
0000000021F7E4C0 0000000002ac2110 Microsoft.Win32.SafeHandles.SafeFileHandle
0000000021F7E590 0000000002ac3048 System.IO.StreamWriter
0000000021F7E5C0 0000000002ac3318 System.Byte[]
0000000021F7E5E0 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E638 0000000002ae7fe8 System.Int32
0000000021F7E640 0000000002ac2070 System.String Find my threadId of {0}
0000000021F7E680 0000000002ac1fe8 System.Threading.ContextCallback
0000000021F7E698 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E6A0 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E6B0 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E6C0 0000000002ac3490 System.IO.TextWriter+SyncTextWriter
0000000021F7E6D0 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E6D8 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E6E0 0000000002ae7fe8 System.Int32
0000000021F7E6F0 0000000002ac8ea0 System.Threading.Thread
0000000021F7E700 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E748 0000000002ac1fe8 System.Threading.ContextCallback
0000000021F7E750 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E760 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E770 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E7A0 0000000002ac8f60 System.Threading.ExecutionContext
0000000021F7E7B0 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E7C0 0000000002ac8ef8 System.Threading.ThreadHelper
0000000021F7E810 0000000002ac8f20 System.Threading.ThreadStart
0000000021F7E978 0000000002ac8f20 System.Threading.ThreadStart
0000000021F7EBB0 0000000002ac8f20 System.Threading.ThreadStart
0000000021F7EBC8 0000000002ac8f20 System.Threading.ThreadStart

0:022>!do 0000000002ae7fe8
Name: System.Int32
MethodTable: 000007fee50bc848
EEClass: 000007fee4c40890
Size: 24(0x18) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
000007fee50bc848 400047b 8 System.Int32 1 instance 21 m_value
0:022>


Note the value is 21, exactly what we were looking for! Leave a comment if you have things you’d like to see me debug.

Sunday, June 26, 2011

Use Paint.Net to Highlight key areas in an image to get your point across

Earlier, I mentioned how important communication is to software engineering. A key tool in communication is being able to highlight portions of images.  For this task I use some basic features of Paint.Net.  In the below image I want to draw your attention to the name of the dress, and the name of the color of the dress. Without these highlighted regions, it's likely your eye wouldn't have picked up the points I wanted you to see.useForPaintNet

To perform these highlights in Paint.Net do the following:

  • Copy image into Paint.Net
  • Select the ellipse tool
  • Specify Fill Options as Draw shape with outline
  • Set Secondary color(the fill color) to yellow
  • Set transparency to 50 %
  • Draw ellipse

Saturday, June 25, 2011

Cool Tools: VirtuaWin

Virtual desktop software allow you have several desktops, and switch between them easily.  This is the equivalent of virtual memory, but for desktop real estate. Good virtual desktop software allows you to move windows between virtual desktops, and will have good usability including hot keys.  VirtuaWin is a great free virtual desktop app for windows,  go install it .  Once installed you should do the following:

  •     Customize the notification area to always show the VirtuaWin Tray Icon

  •     Use C-A-Right, C-A-Left, C-A-Up, C-A-Down to navigate between your desktops

  •     Left Click on the VirtuaWin icon to interact with your windows

  •     Right Click on the VirtuaWin icon to play with settings



Enjoy, and be sure leave comments if there are tools you'd like more information on.