Skip to content

Instantly share code, notes, and snippets.

View sdurandeu's full-sized avatar
💭
In London

Sebastian Durandeu sdurandeu

💭
In London
View GitHub Profile
@sdurandeu
sdurandeu / gist:5377235fb8a1e6552add
Last active July 4, 2017 23:39
Create self-signed certificates for Azure
// for azure web sites
makecert -r -pe -b 01/01/2013 -e 01/01/2014 -eku 1.3.6.1.5.5.7.3.1 -ss My -n CN=serverdnsname -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 -len 2048
// This will install it in current user
// Then export the PFX from MMC (do not run pvktopfx!)
// for remote desktop for cloud services (powershell)
$cert = New-SelfSignedCertificate -DnsName mysite.cloudapp.net -CertStoreLocation "cert:\LocalMachine\My"
$password = ConvertTo-SecureString -String "your-password" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath ".\tryazurecdnworker-westus-dev.pfx" -Password $password
@sdurandeu
sdurandeu / gist:4234fe904cfea9e39ec8
Created June 6, 2014 20:03
Request with Client Certificate
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
var cert = store.Certificates.Find(X509FindType.FindByThumbprint, "ff9afddf408ccd62a5dc83aacc48f8432ab7c86c", false)[0];
var messageHandler = new WebRequestHandler();
messageHandler.ClientCertificates.Add(cert);
messageHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
HttpClient httpClient = new HttpClient(messageHandler);
var result = httpClient.GetAsync("https://clientcertificatetesting.azurewebsites.net/").Result;
@sdurandeu
sdurandeu / gist:a7b69c1a6b119c867106
Created September 5, 2014 15:53
JSON Request with HttpClient
var operationUrl = string.Format("{0}/repos/{1}/{2}/commits/{3}/comments", GitHubClientApiUrl, this.repoOwner, this.repoName, commitId);
var jsonBody = JsonConvert.SerializeObject(new { body = message });
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Token", ConfigurationManager.AppSettings["GitHubApiAccessToken"]);
httpClient.DefaultRequestHeaders.Add("User-Agent", UserAgent);
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
return await httpClient.PostAsync(new Uri(operationUrl), new StringContent(jsonBody));
@sdurandeu
sdurandeu / gist:e80b9f7cd9e2f605ccd2
Created October 4, 2014 02:01
Validate GitHub WebHook SHA1 Token
public class GitHubTokenEncoder
{
public static string Encode(string body, string token)
{
var tokenBytes = Encoding.ASCII.GetBytes(token);
var tokenHmacSha1 = new HMACSHA1(tokenBytes);
tokenHmacSha1.Initialize();
var bodyBytes = Encoding.ASCII.GetBytes(body);
return BitConverter.ToString(tokenHmacSha1.ComputeHash(bodyBytes)).Replace("-", string.Empty).ToLowerInvariant();
}
@sdurandeu
sdurandeu / gist:0f7843f1ccd09680ed87
Last active August 29, 2015 14:08
View used ports with process id in Windows
netstat -ano
Open commandline as administrator
@sdurandeu
sdurandeu / gist:df641fd6294ce7eaf6dd
Created December 3, 2014 20:32
wpp.targets for excluding folder
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<MsDeploySkipRules Include="SkipNewRelic">
<SkipAction></SkipAction>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>\\newrelic$</AbsolutePath>
<Apply>Destination</Apply>
</MsDeploySkipRules>
</ItemGroup>
@sdurandeu
sdurandeu / gist:ed088d3f153b4e49e528
Created January 21, 2015 23:15
Powershell.exe Passing Array parameter
.\scriptParam.ps1
-----------------
Param (
[array] $myArray
)
foreach($foo in $myArray)
{
Write-Host "Value $foo"
}
@sdurandeu
sdurandeu / gist:1ec9b4f9cb7da812db6e
Created May 16, 2015 13:11
Information about wireless adapter
netsh wlan show interfaces
@sdurandeu
sdurandeu / gist:35408abd994e42030a61
Created August 24, 2015 19:50
Install .NET Fx 3.5/2 in Windows 8/10 within domain
Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess
@sdurandeu
sdurandeu / gist:e9f88bb5c4d12e538ff9
Created November 30, 2015 11:21
Reverse a string
public static string Reverse( string s )
{
char[] charArray = s.ToCharArray();
Array.Reverse( charArray );
return new string( charArray );
}