Skip to content

Instantly share code, notes, and snippets.

View jpda's full-sized avatar
🤔
ok

John Patrick Dandison jpda

🤔
ok
View GitHub Profile
@jpda
jpda / IndexManager.cs
Created April 8, 2015 05:41
Create Index Schema from Type
public static void CreateIndexFromType(Type t)
{
var indexName = t.Name.ToLower();
if (SearchClient.Indexes.Exists(indexName))
{
Trace.WriteLine("Found existing index, deleting...");
SearchClient.Indexes.Delete(indexName);
}
try
@jpda
jpda / DelayManager.cs
Created May 13, 2015 15:40
DelayManager.cs
internal class Delay
{
public TimeSpan DelayTime { get; set; }
public int Multiplier { get; set; }
public TimeSpan ResetTime { get; set; }
public int TerminationThreshold { get; set; }
}
internal class DelayManager
{
@jpda
jpda / provision.ps1
Created September 24, 2015 18:17
Windows 10 IoT Password/Name Change
Param (
[string]$IP,[string]$Name,[string]$Password
)
$stockPass = ConvertTo-SecureString "p@ssw0rd" -AsPlainText -Force # Default password
$securePass = ConvertTo-SecureString $Password -AsPlainText -Force # new target password
$stockCreds = New-Object System.Management.Automation.PSCredential("$IP\Administrator", $stockPass)
$newCreds = New-Object System.Management.Automation.PSCredential("$IP\Administrator", $securePass)
Get-Service -Name WinRM | Start-Service -Verbose # Ensure WS-Man is started
@jpda
jpda / deployment.ps1
Last active September 25, 2015 19:19
Windows 10 IoT Multi-device Deployment
param (
[string][Parameter(Mandatory = $true)]$DeviceName,
[string][Parameter(Mandatory = $false)]$DefaultAppName = "IotCoreDefaultApp",
[string][Parameter(Mandatory = $true)]$TargetAppName,
[string][Parameter(Mandatory = $true)]$TargetAppPath,
[string][Parameter(Mandatory = $true)]$DeviceUsername,
[string][Parameter(Mandatory = $true)]$DevicePassword
)
$ErrorActionPreference = "Stop"
Add-Type -Path "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Net.Http.dll"
@jpda
jpda / Web.config
Last active January 6, 2016 22:04
WCF Web Host debug web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
@jpda
jpda / App.config
Created January 6, 2016 21:59
WCF Client sample app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthService" />
</basicHttpBinding>
@jpda
jpda / Startup.Auth.cs
Last active April 19, 2016 15:11
Azure AD Auth Code
private static readonly string ClientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static readonly string AadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static readonly string TenantId = ConfigurationManager.AppSettings["ida:TenantId"];
private static readonly string PostLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
private static readonly string Authority = AadInstance + TenantId;
private static readonly string TargetResourceId = ConfigurationManager.AppSettings["ida:TargetResourceId"];
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());

Keybase proof

I hereby claim:

  • I am jpda on github.
  • I am jpda (https://keybase.io/jpda) on keybase.
  • I have a public key whose fingerprint is 57E2 0A64 15FC 9288 006C 0E20 1B0E B0CE C35D 3922

To claim this, I am signing this object:

@jpda
jpda / program.cs
Created April 13, 2017 20:34
Azure Service Bus client explosion
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Filters;
namespace ConsoleApp2
{
class Program
{
@jpda
jpda / program.cs
Created June 9, 2017 19:44
Azure AD Password grant type
private static string GetUserToken()
{
var cid = "<application client ID>";
var targetCid = "<target resource ID - be careful here, some apps require client/resource ID (GUID), others also accept a URI";
var key = "<URL-encoded client secret key>";
var reqUri = "<authority, usually something like https://login.microsoftonline.com/<tenant ID or domain name>/oauth2/token";
var postData = $"resource={targetCid}&client_id={cid}&grant_type=password&username=user%40jpda.onmicrosoft.com&password={password}&type=openid&client_secret={key}";
// example: "resource=00000002-0000-0000-c000-000000000000&client_id=eeb7d568-2e05-45cf-87eb-d07604340af7&grant_type=password&username=user%40jpda.onmicrosoft.com&password=lol&scope=openid&client_secret=urlencodedsecretkey"