Skip to content

Instantly share code, notes, and snippets.

Avatar

Bill Wilder codingoutloud

View GitHub Profile
@codingoutloud
codingoutloud / myconventions.md
Last active Oct 13, 2015
Decided to make a list of conventions I practice in development... They aren't necessarily *right*, but are what they are.
View myconventions.md
@codingoutloud
codingoutloud / DumpExpiredCerts.cs
Created Dec 1, 2012
Dump information about expired certificates from the Windows Certificate Store
View DumpExpiredCerts.cs
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 Dec 5, 2012
Am I running as an Administrator?
View RunningAsAdministrator.cs
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 Dec 10, 2012
PowerShell script to tidy up the application TEMP area on Windows by deleting files older than 7 days
View temp-tidy.ps1
# 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 Feb 13, 2013
Snippet of Azure Client SDK 1.7 code that demonstrates setting ContentType and CacheControl headers.
View blob-cache-control-header.cs
// .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 Feb 13, 2013
Show Custom Retry Policy for Windows Azure Storage SDK.
View AzureCustomRetryPolicy.cs
// 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 Dec 16, 2015
Download my latest .gitignore file - useful when creating a new Windows Azure Project
View get-gitignore.ps1
Invoke-WebRequest https://gist.github.com/codingoutloud/3318347/raw/ -OutFile .\.gitignore
@codingoutloud
codingoutloud / AzureEmulatorPowerSwitch.cs
Created May 27, 2013
Power Switch for the Azure Emulator processes. Make it easy to programmatically turn Storage or Compute emulation On or Off.
View AzureEmulatorPowerSwitch.cs
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 Sep 6, 2013
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.
View rewrite-to-https.web.config
<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 Dec 24, 2015
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.
View relax.ps1
# 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
#>
<#