Skip to content

Instantly share code, notes, and snippets.

View codingoutloud's full-sized avatar

Bill Wilder codingoutloud

View GitHub Profile
@codingoutloud
codingoutloud / myconventions.md
Last active October 13, 2015 02:38
Decided to make a list of conventions I practice in development... They aren't necessarily *right*, but are what they are.
@codingoutloud
codingoutloud / DumpExpiredCerts.cs
Created December 1, 2012 01:18
Dump information about expired certificates from the Windows Certificate Store
using System;
using System.Security.Cryptography.X509Certificates;
namespace DumpExpiredCertificates
{
internal class Program
{
private static void Main(string[] args)
{
// Iterates through all of the X.509 digital certificates installed in the certificate store
@codingoutloud
codingoutloud / RunningAsAdministrator.cs
Created December 5, 2012 21:27
Am I running as an Administrator?
using System.Security.Principal;
// Is this thread running with Administrator role?
private static bool RunningAsAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
if (identity == null) return false; // Administrator should always have access to this
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
@codingoutloud
codingoutloud / temp-tidy.ps1
Created December 10, 2012 20:27
PowerShell script to tidy up the application TEMP area on Windows by deleting files older than 7 days
# The intent is that the command is to be scheduled to be run by the Windows Scheduler once a day: http://stackoverflow.com/a/8888886
# For Windows Azure, a new Windows Scheduler task is best added by a Startup Script and, like any other machine with the default PowerShell security settings, will need the PowerShell ExecutionPolicy configured: http://blogs.msdn.com/b/jimoneil/archive/2011/02/07/azure-startup-tasks-and-powershell-lessons-learned.aspx
# Bill Wilder @codingoutloud
# See also http://blog.codingoutloud.com/2012/12/10/tidy-the-temp-folder-on-windows-azure
get-childitem $TEMP -recurse | where {$_.lastwritetime -lt (get-date).adddays(-7)} |% {remove-item $_.fullname -force -recurse -verbose}
@codingoutloud
codingoutloud / blob-cache-control-header.cs
Created February 13, 2013 19:24
Snippet of Azure Client SDK 1.7 code that demonstrates setting ContentType and CacheControl headers.
// .NET Storage SDK 1.7
CloudBlob destBlob = TargetContainer.GetBlobReference(destFileName);
destBlob.Properties.ContentType = "image/jpeg";
destBlob.Properties.CacheControl = "x-ms-blob-cache-control: public, max-age=31556926"; // cache for up to one year
try
{
destBlob.UploadFile(sourceFilespec);
}
@codingoutloud
codingoutloud / AzureCustomRetryPolicy.cs
Created February 13, 2013 19:28
Show Custom Retry Policy for Windows Azure Storage SDK.
// Azure Storage SDK 1.7
public static RetryPolicy TrackingRetryExponential(int maxRetryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff, ILog logger)
{
logger.InfoFormat(
"Setting TrackingRetryExponential: maxRetryCount = {0}, minBackoff = {1}, maxBackoff = {2}, deltaBackoff = {3}",
maxRetryCount, minBackoff, maxBackoff, deltaBackoff);
return () => (int currentRetryCount, Exception lastException, out TimeSpan retryInterval) =>
{
@codingoutloud
codingoutloud / get-gitignore.ps1
Last active December 16, 2015 12:39
Download my latest .gitignore file - useful when creating a new Windows Azure Project
Invoke-WebRequest https://gist.github.com/codingoutloud/3318347/raw/ -OutFile .\.gitignore
@codingoutloud
codingoutloud / AzureEmulatorPowerSwitch.cs
Created May 27, 2013 22:24
Power Switch for the Azure Emulator processes. Make it easy to programmatically turn Storage or Compute emulation On or Off.
using System;
using System.Diagnostics;
using System.IO;
namespace DevPartners
{
/// <summary>
/// Power Switch for the Azure Emulator processes. Make it easy to programmatically turn Storage or Compute emulation On or Off.
/// </summary>
public static class AzureEmulatorPowerSwitch
@codingoutloud
codingoutloud / rewrite-to-https.web.config
Created September 6, 2013 05:21
A rewrite rule for ASP.NET that will redirect HTTP requests to be HTTPS requests. Credit: Maarten Balliauw ( this guy: http://blog.maartenballiauw.be ) showed me how to do it.
<system.webServer>
<rewrite>
<rules>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
@codingoutloud
codingoutloud / relax.ps1
Last active December 24, 2015 02:19
Use this to "relax" the constraints on a Windows Azure VM - primarily for a Cloud Service VM. It also installs some handy tools. Goal is to make it easy to diagnose issues on a VM. If you use this, plan to reimage the VM afterwards.
# original: https://gist.github.com/codingoutloud/6730043
# (inspired by http://blogs.msdn.com/b/kwill/archive/2013/08/26/azuretools-the-diagnostic-utility-used-by-the-windows-azure-developer-support-team.aspx)
# MANUALLY FIRST DO THIS from ELEVATED PowerShell command prompt
<#
Set-ExecutionPolicy Unrestricted -Force ; New-Item -ItemType Directory -Path c:\tools ; cd c:\tools ; notepad c:\tools\relax.ps1
#>
<#