Skip to content

Instantly share code, notes, and snippets.

View codingoutloud's full-sized avatar
💭
Building.

Bill Wilder codingoutloud

💭
Building.
View GitHub Profile
@codingoutloud
codingoutloud / python-history.txt
Created October 21, 2013 15:05
Useful Python hacks I've encountered
# http://stackoverflow.com/questions/192109/is-there-a-function-in-python-to-print-all-the-current-properties-and-values-of
dir(somevariable) -- shows the properties available
@codingoutloud
codingoutloud / azure-service-management.py
Last active December 25, 2015 20:19
Run Windows Azure Service Management operation through Python. This requires access to a certificate. Under Windows this certificate must be in the certificate store. On Mac or Linux, this certificate must accessible in a .pem file. In either case, the specified certificate must be uploaded to the Windows Azure portal as a management certificate…
from azure.servicemanagement import *
import platform
import os
###
print("CHANGE THE VALUE of 'subscription_id' and create the correct certificate or this will NOT WORK")
###
plat = platform.system()
print("Platform == " + plat)
@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"
@codingoutloud
codingoutloud / make-keys.bat
Last active October 3, 2024 07:10
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 / 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 / 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 / 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 / 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 / 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 / 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