Skip to content

Instantly share code, notes, and snippets.

View codingoutloud's full-sized avatar

Bill Wilder codingoutloud

View GitHub Profile
@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 / BlobSemaphore.cs
Created February 13, 2013 20:02
Use Windows Azure Blob to create a semaphore spanning the cloud.
// intended to be called only ONCE in real installations - or for a clean test run when no Jobs container exists
public static void GloballyInitializeJobManager(bool quiet)
{
var blobContainer = AzureStorageAccess.GetBlobContainer(JobContainerName);
bool didNotExistCreated = blobContainer.CreateIfNotExist();
if (!quiet) System.Diagnostics.Debug.Assert(didNotExistCreated); // else, we probably should not be calling this method
var blob = blobContainer.GetBlobReference(JobGlobalJobIdSequencePath);
if (!blob.Exists())
{
blob.UploadText(JobGlobalJobIdSequenceStartingValue);
@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
#>
<#
@codingoutloud
codingoutloud / which.ps1
Last active December 24, 2015 10:19
Implements the Unix shell 'which' command using PowerShell
<#
Implements the Unix shell 'which' command using PowerShell.
original: https://gist.github.com/codingoutloud/6782961
#>
function WhichOnes
{
if ($args.Count -eq 0)
{
# obviously use of 'which' in usage text is a hack (since it is chosen to match the alias)
@codingoutloud
codingoutloud / ticks.py
Last active June 4, 2018 14:07
How many ticks since the first moment of 01-01-0001, the first day of the epoch used in Python (and .NET) date time libraries? This python program snippet calculates this. A Tick is defined (matching .NET's DateTime.UtcNow.Ticks property) as 1 / 10,000,000 of a Second. This conversion might be useful if you need interoperability across .NET lang…
# Bill Wilder (@codingoutloud), 02-Oct-2013
# Original: https://gist.github.com/codingoutloud/6800434
import datetime
def ticks_since_epoch(start_time_override = None):
"""
Calculates number of Ticks since Jan 1, 0001 epoch. Uses current time unless another time is supplied.
Mimics behavior of System.DateTime.UtcNow.Ticks from.NET with 10 million Ticks per second.
http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx
@return: Number of Ticks since Jan 1, 0001 epoch (earliest date supported by Python datetime feature)
@codingoutloud
codingoutloud / make-keys.bat
Last active August 3, 2023 19:05
Handy OpenSSL command-line combinations I've used - they might've been hard to find or come up with, so capturing them here.
@echo off
if _%1_==__ goto USAGE
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem -subj "/CN=My Cert Name"
openssl pkcs12 -export -out mycert.pfx -inkey mycert.pem -in mycert.pem -passout pass:%1
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer
openssl pkcs12 -in mycert.pfx -nodes -passin pass:%1 | openssl x509 -noout -fingerprint
openssl x509 -in mycert.pem -noout -fingerprint
@codingoutloud
codingoutloud / basicauthwithtoken.ps1
Created October 17, 2013 22:15
Use PowerShell to call HTTP Endpoint using Basic Auth when you already have a Basic Auth token in hand (not username + password). http://en.wikipedia.org/wiki/Basic_access_authentication
## Example explorers hitting a web endpoint with Basic Auth, when you already have a token in hand
$key = "sk_test_mkGsLqEW6SLnZa487HYfJVLf"
$url = "https://api.stripe.com/v1/charges"
# this will work, but the flow in Basic Auth will first ask you for a password to go with the
# value passed in, which serves as the username. You hit enter because the password is null.
# Then the response comes back... BUT - this also involved a round-trip to the server (which
# returns a 401, but also a Response header indicating that is speaks Basic Auth:
# Www-Authenticate: Basic realm="Stripe"