Skip to content

Instantly share code, notes, and snippets.

@cmatskas
cmatskas / netcoremainwithsecrets.cs
Last active March 22, 2022 17:04
User Secrets In Core Console
using Microsoft.Extensions.Configuration;
IConfiguration config = new ConfigurationBuilder()
.AddUserSecrets<Program>()
.Build();
Console.WriteLine($"My not-so-secret secret is {config["mySecret']});
@cmatskas
cmatskas / PowerShell
Last active March 16, 2022 23:40
PS Script to Install fonts
echo "Install Custom fonts"
$fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
foreach ($file in gci *.ttf)
{
$fileName = $file.Name
if (-not(Test-Path -Path "C:\Windows\fonts\$fileName" )) {
echo $fileName
dir $file | %{ $fonts.CopyHere($_.fullname) }
}
}
C:.
+---.atom
| \---compile-cache
| \---836a81e7afc5e1080850f10b0790220f3d81503a
| \---js
+---.p4merge
+---Contacts
+---Desktop
+---Documents
| +---Custom Office Templates
private async Task<AuthenticationResult> Login()
{
AuthenticationResult authResult = null;
var accounts = await Program.PublicClientApp.GetAccountsAsync();
var firstAccount = accounts.FirstOrDefault();
try
{
authResult = await Program.PublicClientApp.AcquireTokenSilent(scopes, firstAccount)
.ExecuteAsync();
@cmatskas
cmatskas / detached-head-merge.ps1
Created August 22, 2015 21:55
Git merge detached head
$git checkout –b temp #makes a new branch from current detached HEAD
$git branch –f master temp #update master to point to the new <temp> branch
$git branch –d temp #delete the <temp> branch
$git push origin master #push the re-established history
using System.Collections.Concurrent;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.Resource;
using Microsoft.Identity.Web.TokenCacheProviders.InMemory;
@cmatskas
cmatskas / appinsightsconsolenlog.cs
Last active August 9, 2021 11:29
AppInsights logs with nLog
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using NLog;
using System;
using System.Collections.Generic;
using System.Threading;
namespace AppInsightsTest
{
class Program
@cmatskas
cmatskas / p4merge.md
Created June 3, 2021 18:08
Set up p4merge as the default merge and diff tool in Git

Assuming that P4Merge was installed in the default location on Windows, i.e 'C:\Program Files\Perforce\p4merge.exe' then the following commands will configure p4merge as the default tool for both merge and diffs in Git

Set up commands

$ git config --global diff.tool p4merge
$ git config --global difftool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'
$ git config --global merge.tool p4merge
$ git config --global mergetool.p4merge.path 'C:\Program Files\Perforce\p4merge.exe'
@cmatskas
cmatskas / enforceTLS.json
Last active January 29, 2021 15:28
Azure Policy Enforce TLS 1.2
{
"properties": {
"mode": "all",
"parameters": {
},
"displayName": "SSL WebSites",
"description": "This policy enables you to restrict websites to only accept TLS traffic with minimum version 1.2",
"policyRule": {
"if": {
"anyOf": [
@cmatskas
cmatskas / ipsecurityarmtemplate.json
Last active January 15, 2021 04:12
IP Security ARM Template
{
"apiVersion": "2015-08-01",
"name": "[variables('webSiteName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]":"Resource",
"displayName": "Website"
},
"dependsOn": [