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:9557582
Created March 14, 2014 21:41
Empty a TeamCity database
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
DECLARE @schema VARCHAR(128)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])
SELECT @schema = (SELECT TOP 1 schema_name(schema_id) FROM sys.tables WHERE [name] = @name)
WHILE @name IS NOT NULL
BEGIN
SELECT @SQL = 'DROP TABLE [' + @schema + '].[' + RTRIM(@name) +']'
@sdurandeu
sdurandeu / gist:11409404
Created April 29, 2014 19:17
Automatically finding missing and duplicate files in CSProj (Revisited)
Param(
[string]$filePath = $(throw "You must supply a file path")
)
clear
"--- Working... ---"
$filePath = Resolve-Path $filePath
@sdurandeu
sdurandeu / Minutes:Seconds Difference between two dates using UTC
Created May 15, 2014 15:25
Minutes:Seconds Difference between two dates using UTC
var startDateUtcMilliseconds = "2324324823" // In C#: (buildRun.Date.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalMilliseconds.ToString();
var hours, minutes, seconds;
if (rowItem.currentBuild) {
var startDate = new Date(parseInt(startDateUtcMilliseconds));
var msec = Date.now() - startDate;
hours = Math.floor(msec / 1000 / 60 / 60); // discard
msec -= hours * 1000 * 60 * 60;
minutes = Math.floor(msec / 1000 / 60);
msec -= minutes * 1000 * 60;
@sdurandeu
sdurandeu / gist:aae46604b1ab27001885
Last active August 29, 2015 14:01
Create SSH Key and Key Fingerprint
// see https://help.github.com/articles/generating-ssh-keys
// Get fingerprint
ssh-keygen -l -f /path/to/keys/id_rsa.pub
// Generate key
ssh-keygen -t rsa -C "your_email@example.com"
ssh-add ~/.ssh/id_rsa
@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:1ec9b4f9cb7da812db6e
Created May 16, 2015 13:11
Information about wireless adapter
netsh wlan show interfaces