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 / snippet.cs
Created January 18, 2019 11:29
[C#] Open a file for reading but don't lock it
Stream stream = null;
try
{
stream = File.Open(Path.Combine(this.applicationPath, fileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var reader = new StreamReader(stream))
{
stream = null;
return reader.ReadToEnd();
}
}
@sdurandeu
sdurandeu / connection.rdp
Created September 8, 2017 17:55
Remote Desktop: Ask for credentials
// see https://morgansimonsen.com/2015/11/06/connecting-to-an-azure-ad-joined-machine-with-remote-desktop/
screen mode id:i:2
use multimon:i:0
desktopwidth:i:1920
desktopheight:i:1080
session bpp:i:32
winposstr:s:0,1,188,-1067,1554,-30
compression:i:1
keyboardhook:i:2
@sdurandeu
sdurandeu / example.ps1
Created July 5, 2017 00:45
Powershell: Manipulate a Json Configuration File
# read configuration file
$configuration = Get-Content -Raw -Path $parametersFilePath | ConvertFrom-Json
# generate intermediate ARM template parameters file with serialized JSON settings
$armParametersFile = @{
"`$schema" = "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#";
"contentVersion" = "1.0.0.0";
"parameters" = New-Object psobject;
}
@sdurandeu
sdurandeu / arm-template.md
Last active December 4, 2017 10:12
Azure ARM Template Samples

ARM Templates Samples

Azure App Service

Including how to:

  • Set Connection Strings
  • Set app settings with a Cosmos DB Accunt Key, the Azure Storage Key and App Insights Instrumentation Key
  • Output the Website Publishing Username and Password
  • AlwaysOn turned on
@sdurandeu
sdurandeu / DownloadFileAsync.cs
Last active July 5, 2017 00:25
Http Client Examples
// HIGHLIGHTS:
// - the httpclient should not be created on every request, it should be static
// - HttpCompletionOption.ResponseHeadersRead to return before downloading the full file
// see https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client
// "HttpClient is intended to be instantiated once and re-used throughout the life of an application.
// Especially in server applications, creating a new HttpClient instance for every request will exhaust the number of sockets available under heavy loads.
// This will result in SocketException errors."
namespace TryAzureCdn.WorkerRole
{
using System.Collections.Generic;
@sdurandeu
sdurandeu / powershell.ps1
Created June 30, 2017 19:28
Publish an Azure WebJob with MsBuild from Powershell script
# Notice the '' around the username to escape the $ sign
$queueDefaultAssetsWebjobProjectPath = Resolve-Path -Path $queueDefaultAssetsWebjobProjectPath
$arguments= "$queueDefaultAssetsWebjobProjectPath /p:Configuration=Release /p:DeployOnBuild=true /p:DeployTarget=MsDeployPublish /p:MsDeployServiceUrl=$($configuration.ApiPublishingUrl) '/p:UserName=$($configuration.ApiPublishingUserName)' /p:Password=$($configuration.ApiPublishingPassword) /p:DeployIisAppPath=$($configuration.ArmParameters.AppServiceApiName) /p:SkipExtraFilesOnServer=true"
Write-Host "Publishing webjob 'QueueDefaultAssetsWebJob' with MSDeploy..."
iex "&$msBuild $arguments"