Calculating longitude length in miles?

https://gis.stackexchange.com/questions/142326/calculating-longitude-length-in-miles

It doesn’t matter at what longitude you are. What matters is what latitude you are.

Length of 1 degree of Longitude = cosine (latitude in decimal degrees) * length of degree (miles) at equator.

Convert your latitude into decimal degrees ~ 37.26383

Convert your decimal degrees into radians ~ 0.79863

1 degree of Longitude = ~0.79863 * 69.172 = ~ 55.2428 miles

More useful information from the about.com website:

Degrees of latitude are parallel so the distance between each degree remains almost constant but since degrees of longitude are farthest apart at the equator and converge at the poles, their distance varies greatly.

Each degree of latitude is approximately 69 miles (111 kilometers) apart. The range varies (due to the earth’s slightly ellipsoid shape) from 68.703 miles (110.567 km) at the equator to 69.407 (111.699 km) at the poles. This is convenient because each minute (1/60th of a degree) is approximately one [nautical] mile.

A degree of longitude is widest at the equator at 69.172 miles (111.321) and gradually shrinks to zero at the poles. At 40° north or south the distance between a degree of longitude is 53 miles (85 km)

Note that the original site (about.com) erroneously omitted the “nautical” qualifier.

Left join and Left outer join in SQL Server

http://stackoverflow.com/questions/406294/left-join-and-left-outer-join-in-sql-server

As per the documentation: FROM (Transact-SQL):

<join_type> ::=
    [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [ <join_hint> ] ]
    JOIN

The keyword OUTER is marked as optional (enclosed in square brackets), and what this means in this case is that whether you specify it or not makes no difference. Note that while the other elements of the join clause is also marked as optional, leaving them out will of course make a difference.For instance, the entire type-part of the JOIN clause is optional, in which case the default is INNER if you just specify JOIN. In other words, this is legal:

SELECT *
FROM A JOIN B ON A.X = B.Y

Here’s a list of equivalent syntaxes:

A LEFT JOIN B            A LEFT OUTER JOIN B
A RIGHT JOIN B           A RIGHT OUTER JOIN B
A FULL JOIN B            A FULL OUTER JOIN B
A INNER JOIN B           A JOIN B

Also take a look at the answer I left on this other SO question: SQL left join vs multiple tables on FROM line?.enter image description here

What is the difference between UNION and UNION ALL.

http://stackoverflow.com/questions/49925/what-is-the-difference-between-union-and-union-all

UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not.

There is a performance hit when using UNION vs UNION ALL, since the database server must do additional work to remove the duplicate rows, but usually you do not want the duplicates (especially when developing reports).

UNION Example:

SELECT 'foo' AS bar UNION SELECT 'foo' AS bar

Result:

+-----+
| bar |
+-----+
| foo |
+-----+
1 row in set (0.00 sec)

UNION ALL example:

SELECT 'foo' AS bar UNION ALL SELECT 'foo' AS bar

Result:

+-----+
| bar |
+-----+
| foo |
| foo |
+-----+
2 rows in set (0.00 sec)

Send SMTP email using System.Net.Mail via Exchange Online (Office 365)

http://stackoverflow.com/questions/6244694/send-smtp-email-using-system-net-mail-via-exchange-online-office-365

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("[email protected]", "SomeOne"));
msg.From = new MailAddress("[email protected]", "You");
msg.Subject = "This is a Test Mail";
msg.Body = "This is a test message using Exchange OnLine";
msg.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(“your user name”, “your password”);
client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
client.Host = “smtp.office365.com”;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
try
{
client.Send(msg);
lblText.Text = “Message Sent Succesfully”;
}
catch (Exception ex)
{
lblText.Text = ex.ToString();
}

What’s the difference between unicode and utf8?

http://stackoverflow.com/questions/3951722/whats-the-difference-between-unicode-and-utf8

This is an unfortunate misnaming perpetrated by Windows.

Because Windows uses UTF-16LE encoding internally as the memory storage format for Unicode strings, it considers this to be the natural encoding of Unicode text. In the Windows world, there are ANSI strings (the system codepage on the current machine, subject to total unportability) and there are Unicode strings (stored internally as UTF-16LE).

This was all devised in the early days of Unicode, before we realised that UCS-2 wasn’t enough, and before UTF-8 was invented. This is why Windows’s support for UTF-8 is all-round poor.

This misguided naming scheme became part of the user interface. A text editor that uses Windows’s encoding support to provide a range of encodings will automatically and inappropriately describe UTF-16LE as “Unicode”, and UTF-16BE, if provided, as “Unicode big-endian”.

(Other editors that do encodings themselves, like Notepad++, don’t have this problem.)

If it makes you feel any better about it, ‘ANSI’ strings aren’t based on any ANSI standard, either.

Call vs Start

http://stackoverflow.com/questions/13257571/call-command-vs-start-with-wait-option

For exe files, I suppose the differences are nearly unimportant.
But to start an exe you don’t even need CALL.

When starting another batch it’s a big difference,
as CALL will start it in the same window and the called batch has access to the same variable context.
So it can also change variables which affects the caller.

START will create a new cmd.exe for the called batch and without /b it will open a new window.
As it’s a new context, variables can’t be shared.

Addendum:
Using CALL can change the parameters (for batch and exe files), but only when they contain carets or percent signs.

call myProg param1 param^^2 "param^3" %%path%%

Will be expanded to (from within an batch file)

myProg param1 param2 param^^3 

Best way in .NET to manage queue of tasks on a separate (single) thread

http://stackoverflow.com/questions/20056727/need-to-understand-the-usage-of-semaphoreslim

http://stackoverflow.com/questions/20904328/c-sharp-async-tasks-in-a-queue-or-waiting-list

http://stackoverflow.com/questions/25691679/best-way-in-net-to-manage-queue-of-tasks-on-a-separate-single-thread

To create an asynchronous single degree of parallelism queue of work you can simply create a SemaphoreSlim, initialized to one, and then have the enqueing method await on the acquisition of that semaphore before starting the requested work.

 

public class TaskQueue
{
    private SemaphoreSlim semaphore;
    public TaskQueue()
    {
        semaphore = new SemaphoreSlim(1);
    }

    public async Task<T> Enqueue<T>(Func<Task<T>> taskGenerator)
    {
        await semaphore.WaitAsync();
        try
        {
            return await taskGenerator();
        }
        finally
        {
            semaphore.Release();
        }
    }
    public async Task Enqueue(Func<Task> taskGenerator)
    {
        await semaphore.WaitAsync();
        try
        {
            await taskGenerator();
        }
        finally
        {
            semaphore.Release();
        }
    }
}

Of course to have a fixed degree of parallelism other than one simply initialize the semaphore to some other number.

Delayed Expansion

http://stackoverflow.com/questions/14347038/dos-batch-why-are-my-set-commands-resulting-in-nothing-getting-stored

You found the bbb (batch beginner bug), but not the variable is empty, it’s the expansion that doesn’t work as expected.

Percent expansion is done when a line or a complete parenthesis block is parsed, before the code will be executed.
But to solve this you can use the delayed expansion, this doesn’t expand at parse time, it expands just at execution time.

setlocal EnableDelayedExpansion

if exist "%_REALPATH%\tomcat-%TOMCAT_VER2%" (
set CATALINA_HOME=%_REALPATH%\tomcat-%TOMCAT_VER2%
set TOMCAT_VER=%TOMCAT_VER2%
echo "!TOMCAT_VER!"
) else if exist "%TOMCAT_VER2%" (
set CATALINA_HOME="%TOMCAT_VER2%"
set TOMCAT_VER="%TOMCAT_VER2%"
echo "!TOMCAT_VER!"
)

What does the “@” symbol do in Powershell?

Source: https://stackoverflow.com/questions/363884/what-does-the-symbol-do-in-powershell#574388

PowerShell will actually treat any comma-separated list as an array:

“server1″,”server2”

So the @ is optional in those cases. However, for associative arrays, the @ is required:

@{“Key”=”Value”;”Key2″=”Value2″}

Officially, @ is the “array operator.” You can read more about it in the documentation that installed along with PowerShell, or in a book like “Windows PowerShell: TFM,” which I co-authored :). –  Don Jones