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 / T To<T> template method sample
Created May 21, 2012 02:49
T ToT template method sample
public static T To<T>(Endpoint endpoint) where T : Endpoint
{
if (endpoint.GetType() == typeof(T))
return endpoint as T;
var destination = Activator.CreateInstance<T>();
destination.ApplicationId = endpoint.ApplicationId;
destination.TileId = endpoint.TileId;
destination.ClientId = endpoint.ClientId;
@sdurandeu
sdurandeu / Json to XML using Newtonsoft.Json
Created February 15, 2013 18:12
Json to XML using Newtonsoft.Json
namespace JsonToXml
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Newtonsoft;
using System.IO;
@sdurandeu
sdurandeu / gist:6378483
Created August 29, 2013 14:03
JS: Get and Set HashTag Parameter
$.getHashtagParam = function(paramToRetrieve: string): string {
var params = (document.URL.split("#")[1] || "").split("&");
var paramsCount = params.length;
for (var paramIndex = 0; paramIndex < paramsCount; paramIndex = paramIndex + 1) {
var singleParam = params[paramIndex].split("=");
if (singleParam[0] === paramToRetrieve) {
return singleParam[1];
}
@sdurandeu
sdurandeu / gist:6576538
Created September 16, 2013 03:48
OAuth Request Token (HTTPS POST Request)
// An object of options to indicate where to post to
var post_options = {
host: 'api.mercadolibre.com',
port: '443',
path: util.format("/oauth/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=" + callbackUri,
config.clientId, config.clientSecret, encodeURIComponent(code)),
secureProtocol: 'SSLv3_method',
agent: false,
method: 'POST',
headers: {
@sdurandeu
sdurandeu / gist:6995074
Created October 15, 2013 17:12
Rate an item in sharepoint
var securePassword = new System.Security.SecureString();
foreach (char c in this.password)
{
securePassword.AppendChar(c);
}
using (ClientContext ctx = new ClientContext(this.siteUrl) { Credentials = new SharePointOnlineCredentials(this.username, securePassword) })
{
Web w = ctx.Web;
List l = w.Lists.GetByTitle(CycloneTestConstants.WellKnownCycloneList);
@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:9842815
Created March 28, 2014 20:55
Async Blob Copy - Windows Azure
## For reference see http://michaelwasham.com/windows-azure-powershell-reference-guide/copying-vhds-blobs-between-storage-accounts/
Import-Module Azure
Set-AzureSubscription -SubscriptionName "Azure SDK Testing" -CurrentStorageAccount "portalvhdsq1x0n4q4zbfq5"
Select-AzureSubscription "Azure Store SDK Testing"
$destContext = New-AzureStorageContext –StorageAccountName "{destAccountName}" `
-StorageAccountKey "{destAccountKey}"
$sourceContext = New-AzureStorageContext –StorageAccountName "{sourceAccountName}" `
@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 "[email protected]"
ssh-add ~/.ssh/id_rsa