Perth .NET User Group Meeting, Thurs Nov 3rd, 5:30pm: Hosting in Azure – without the blues: Joe Albahari

Had enough of your data centre or web hosting company?

Join us at the Perth .NET user group, Thurs Nov 3rd 5:30pm, and find out how to move your MVC or Web Forms apps into the cloud and enjoy high availability, security and scalability – without the responsibility of OS installation, updates or security. This session will be full of practical advice and lessons learned from Joe’s own experience migrating two web sites and a licensing server into Azure, all of which now run inexpensively on a redundant pair of extra small instances.

  • TOPIC:   Hosting in Azure – without the blues: Joe Albahari
  • DATE:    Thurs Nov 3rd, 5:30pm – 7:00pm
  • VENUE:  Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

Joe Albahari is a C# MVP and author of ‘C# 4.0 in a Nutshell’ and LINQPad. He has presented at TechEd and JAOO and is a regular speaker at the Perth .NET User Group.

More details here: http://perthdotnet.org/blogs/events/archive/2011/10/16/hosting-in-azure-without-the-blues-joe-albahari.aspx

Perth .NET User Group Meeting, Weds 19th Oct, 5:30pm: Amazon Web Services (AWS) in Action with Andy Marks

Join us at the Perth .NET user group, Weds Oct 19th 5:30pm, where Andy Marks will introduce the philosophy and principles behind AWS and briefly describe some of the key components around storage and compute capabilities. The session will include a short hands-on activity for participants to build and deploy their own cloud-based application.

  • TOPIC:   Amazon Web Services (AWS) in Action with Andy Marks
  • DATE:    Wednesday, Oct 19th, 5:30pm – 7:00pm
  • VENUE:  Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:    Free. All welcome

Andy serves ThoughtWorks principally as the Perth and Melbourne Technical Lead in the design and implementation of enterprise applications. He also has considerable experience in coaching and mentoring development teams adopting Agile practices.

Optional Requirements: Laptop with internet connectivity (for the hands on section of the talk).

Perth .NET User Group Meeting, Thurs 6th Oct: C#/Mono with Ben Last

Join us at the Perth .NET user group, Thurs Oct 6th 5:30pm, where Ben Last will discuss a real world application using C# and Mono. nearmap.com make heavy use of C#, but in a very non-Windows environment. Plenty of people have played with mono as a .NET platform, but there are not that many who have used it in a large-scale, high-traffic, n-tier environment. Hear our story, and find out if mono delivers what it promises.

  • TOPIC:  C#/Mono with Ben Last
  • DATE:   Thursday, Oct 6th, 5:30pm – 7:00pm
  • VENUE: Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:   Free. All welcome

Ben is a Software Engineer and Architect with more than twenty years’ experience in the design and implementation of large-scale software systems. He joined NearMap in April 2009 and is the Development Manager for HyperWeb, which delivers very high volumes of image data via the nearmap.com website and over the Internet. Before joining NearMap, Ben was R&D Manager at EMCC Software in the UK, leading product development teams for mobile enterprise and consumer applications and consulting on mobile and networked software development.

TSQL: An Efficient Dynamic Numbers Table

A numbers table is simply a table containing sequential integer values. The size of the required table will vary depending upon its use, but it is not uncommon to find permanent tables containing 1,000,000 rows. A numbers (or tally) table forms the basis of solving problems in a set-based way, and is a powerful technique for finding gaps in sequences, string manipulation (which if done purely with TSQL’s built-in functions can run very slowly), etc. It is also often used in the form of a date table, enabling some very efficient set based join constructs to be used on date range calculations.

While it is usual to create a fixed table in the database, there is the occasional need for a dynamic version. There are several ways not to do this! Such as the recursive CTE or a while loop inserting values one after another. A better option is the CROSS join against system tables method, and better still is Itzik’s often cited, cross joined CTE method:

--===== Itzik's CROSS JOINED CTE method 
WITH E00(N) AS (SELECT 1 UNION ALL SELECT 1),
E02(N) AS (SELECT 1 FROM E00 a, E00 b),
E04(N) AS (SELECT 1 FROM E02 a, E02 b),
E08(N) AS (SELECT 1 FROM E04 a, E04 b),
E16(N) AS (SELECT 1 FROM E08 a, E08 b),
E32(N) AS (SELECT 1 FROM E16 a, E16 b),
cteTally(N) AS (SELECT ROW_NUMBER() OVER (ORDER BY N) FROM E32)
SELECT N
FROM cteTally
WHERE N <= 1000000;
GO

After a little experimentation, I found that reducing the number of cross joins by increasing the size of the first table results in a more efficient query plan. I wrapped this up in an inline table valued function with the option of a start and end value for the sequence:

IF OBJECT_ID (N'dbo.tvf_DynamicNumbersTable') IS NOT NULL
DROP FUNCTION dbo.tvf_DynamicNumbersTable
GO

CREATE function dbo.tvf_DynamicNumbersTable
(
@pStartValue int = 1,
@pEndValue int = 1000000
)
returns table
as
return
(
with rows16(N) as
(
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union all
select 1
),
rows256(N) as
(
select t1.N from rows16 t1 cross join rows16 t2
),
rows65536(N) as
(
select t1.N from rows256 t1 cross join rows256 t2
),
rows2pow32(N) as
(
select t1.N from rows65536 t1 cross join rows65536 t2
),
Numbers(N) as
(
select row_number() over (order by N) as N from rows2pow32 t1
)
select N from Numbers
where N between @pStartValue AND @pEndValue
);

Windows 7: Fast and Flexible File Copy with RoboCopy

Did you know that RoboCopy is included with all editions of Windows 7? I didn’t until very recently, when a colleague (Mike Minutillo) mentioned it.

Robocopy (short for Robust File Copy) can do so much more than the standard Copy and Xcopy commands.

The basic syntax is as follows:

robocopy source destination [file [file]…] [options]

The source and destination parameters are specified as drive:\path or \\server\share\path. The file parameter can contain one or more literal file names, or it can use ? and * wildcards.

For instance, this command copies the contents of one folder and all its subfolders from a local drive E to a shared folder:

robocopy “E:\test” \\server\public\test\ /MIR /W:30 /R:10 /MT:8 /LOG:\\server\public\logs

The /MIR switch mirrors the two folders, copying all folders (even empty ones) from the source directory and removing folders from the destination if they no longer exist on the source. The /W and /R switches set the wait and retry options; in this case, Robocopy will retry each copy up to 10 times, waiting 30 seconds between attempts. The /MT[:n] switch performs a multi-threaded copy, where n indicates the number of threads to be used (n is 8, by default) and can range from 1 to 128. The /LOG: switch logs output to the specified location.

To see the full list of options, type robocopy /? at a command prompt.

There’s even a GUI!