Skip to content

Instantly share code, notes, and snippets.

View DamienBraillard's full-sized avatar

Damien Braillard DamienBraillard

View GitHub Profile
@DamienBraillard
DamienBraillard / aspnet_core_tips_and_tricks.md
Last active January 14, 2020 08:32
Some tips for ASP.Net core development

Asp .Net core tips and tricks

SSL and security

Linking a development certificate with a HTTPSYS web site

On windows:

  1. From start menu, open "Manage computer certificates"
  2. In "Personal/Certificates", locate the "localhost" certificate and open it
  3. Copy it's Thumbprint and keep it for later (beware, there are hidden characters at the beginning and/or the end)
@DamienBraillard
DamienBraillard / TeamCity_setup_with_Ubuntu.md
Last active December 7, 2019 09:49
TeamCity setup under Ubuntu

Installing TeamCity

Install MySql

Install and secure MySql isntallation:

apt install mariadb-server
mysql_secure_installation
@DamienBraillard
DamienBraillard / ISimpleRoleProvider.cs
Last active April 1, 2024 06:22
Asp.Net Core simple role authorization with Windows Authentication
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
namespace DamienBraillard.AspNetCoreSimpleRoleAuthorization
{
/// <summary>
/// Defines the base functionality of the class used to provide applicative roles for a user when using the simple role
/// authorization.
/// </summary>
const languages = ['en', 'fr'];
this.translateService.addLangs(languages);
for (const lang of languages) {
this.translateService.setTranslation(lang, require('../assets/i18n/' + lang + '.json'));
}
// Set this after 'setTranslation' to avoid unnecessary XHR request
this.translateService.setDefaultLang('en');
@DamienBraillard
DamienBraillard / DownloadFileComponent.ts
Last active November 1, 2018 10:18
Angular 2+ Download file from API
import { Http, ResponseContentType } from '@angular/http';
...
constructor(
private http: Http,
) { }
downloadFile() {
return this.http
.get('https://jslim.net/path/to/file/download', {
@DamienBraillard
DamienBraillard / WindowsAuthorizationMiddleware.cs
Created October 31, 2018 14:43
Global AD windows auth middleware for Asp .Net core
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Builder
{
public static class WindowsAuthorizationAppBuilderExtensions
@DamienBraillard
DamienBraillard / RunSynchronouslyWithDispatcher.cs
Created September 19, 2018 08:19
Calling async code from WPF event handlers synchronously
// BEWARE: There is no universal way to synchronously wait for async tasks. This can be used in a WPF context only.
private static void RunSynchronously(Func<Task> func)
{
// Gets the awaiter for the task
var awaiter = func().ConfigureAwait(false).GetAwaiter();
// Creates a new dispatcher frame that will lock (like Window.ShowDialog()) but with the message pump still running
// The dispatcher frame terminates only when the task to wait for has completed
DispatcherFrame frame = new DispatcherFrame();
@DamienBraillard
DamienBraillard / AsyncHelper.cs
Last active September 19, 2018 07:07
Run async method as sync
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
namespace MvvmFramework
{
public static class AsyncHelper
{
private static readonly TaskFactory TaskFactory = new