Skip to content

Instantly share code, notes, and snippets.

View codingoutloud's full-sized avatar

Bill Wilder codingoutloud

View GitHub Profile
@codingoutloud
codingoutloud / DumpAllWindowsCerts.cs
Created November 3, 2012 03:03
Dump all digital certificates in Windows certificate store to stdout
// Iterates through all of the X.509 digital certificates installed in the certificate store
// on a Windows operating system, dumping out some metadata about each. Each certificate, in
// each Certificate Store, from each Certificate Location is included.
//
// Bill Wilder | @codingoutloud | Oct 2012
// Original: https://gist.github.com/4005661
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
@codingoutloud
codingoutloud / windows-azure-certs.txt
Created November 3, 2012 03:27
Dump of Windows Azure Certificates from a Web Role instance (output is from https://gist.github.com/4005661)
Store Location: CurrentUser
Store Location/Store Name: CurrentUser/AddressBook
Store Location/Store Name: CurrentUser/AuthRoot
Certificate (some fields): for OU=Security Communication EV RootCA1, O="SECOM Trust Systems CO.,LTD.", C=JP - has private key False by OU=Security Communication EV RootCA1, O="SECOM Trust Systems CO.,LTD.", C=JP
Certificate (some fields): for CN=D-TRUST Root Class 3 CA 2007, O=D-Trust GmbH, C=DE - has private key False by CN=D-TRUST Root Class 3 CA 2007, O=D-Trust GmbH, C=DE
Certificate (some fields): for OU=certSIGN ROOT CA, O=certSIGN, C=RO - has private key False by OU=certSIGN ROOT CA, O=certSIGN, C=RO
Certificate (some fields): for E=scr@registradores.org, STREET=Principe de Vergara 72 28006 Madrid, CN=Certificado de la Clave Principal, OU=Certificado Raiz, OU=Certificado Propio, O=Servicio de Certificacion del Colegio de Registradores (SCR), C=es - has private key False by E=scr@registradores.org, STREET=Principe de Vergara 72 28006 Madrid, CN=Certificado de la Clave Principal,
@codingoutloud
codingoutloud / TraceToComputeEmulator.cs
Last active November 17, 2016 09:41
Enable Diagnostic Trace Logging for Windows Azure Compute Emulator from ASP.NET
// Code snippet for use in Windows Azure Cloud Services.
// The EnableDiagnosticTraceLoggingForComputeEmulator method can be called from ASP.NET
// code to enable output from the System.Diagnostics.Trace class to appear in the
// Windows Azure Compute Emulator. The method does nothing when deployed to the cloud,
// when run outside the compute emulator, when run other than in DEBUG, or run repeatedly.
//
// The code uses Reflection to dynamically load the needed assembly and create the
// specific TraceListener class needed.
//
// EXAMPLE INITIALIZING FROM Global.asax.
@codingoutloud
codingoutloud / GenerateCryptographicallyStrongUrlSafeRandomToken.cs
Last active May 11, 2016 22:24
Generate a random(ish) token that is safe to be used in a URL. Allow caller to specify strength though number of generated random chars.
// Bill Wilder | @codingoutloud | http://www.cloudarchitecturepatterns.com | Nov 2012
// Original: https://gist.github.com/4121999
// Similar GenerateUrlSafeRandomToken.cs, except upgraded to use crypto-strength RNG
// Add reference to System.Web.dll
public static string GenerateUrlSafeCryptographicallyStrongRandomToken(int strength = 16)
{
using (var rng = new RNGCryptoServiceProvider())
{
var randomBytes = new byte[strength];
rng.GetBytes(randomBytes);
@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 / RandomTokenGenerator.cs
Created December 4, 2012 04:14
Generate a random string that is URL safe.
using System;
using System.Security.Cryptography;
using System.Web;
namespace DevPartners
{
// author: Bill Wilder, @codingoutloud
// original: https://gist.github.com/4200537
public static class RandomTokenGenerator
{
@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);
}