Skip to content

Instantly share code, notes, and snippets.

View mouadcherkaoui's full-sized avatar
🎯
Focusing

Mouad Cherkaoui mouadcherkaoui

🎯
Focusing
View GitHub Profile
@mouadcherkaoui
mouadcherkaoui / push_replace.ps1
Created October 25, 2019 18:59 — forked from Fireforge/push_replace.ps1
Nuget Package push Powershell script with debug/release specific files
#
# push_replace.ps1
#
# This script is designed to produce customized release and debug nupkgs from a Visual Studio C# project. This is especially useful
# for nupkgs that include native DLLs that are different depending upon debug or release mode.
#
# How to use:
# In your .nuspec file in the <files> section, add the following line:
# <file src="$filelist$" target="lib\native" />
# That line is set to go to lib\native because this script was made for handling native DLLs, but that target can be anything.
@mouadcherkaoui
mouadcherkaoui / blazor-auth.md
Created September 9, 2019 16:29 — forked from SteveSandersonMS/blazor-auth.md
Blazor authentication and authorization

Authentication and Authorization

Authentication means determining who a particular user is. Authorization means applying rules about what they can do. Blazor contains features for handling both aspects of this.

It worth remembering how the overall goals differ between server-side Blazor and client-side Blazor:

  • Server-side Blazor applications run on the server. As such, correctly-implemented authorization checks are both how you determine which UI options to show (e.g., which menu entries are available to a certain user) and where you actually enforce access rules.
  • Client-side Blazor applications run on the client. As such, authorization is only used as a way of determining what UI options to show (e.g., which menu entries). The actual enforcement of authorization rules must be implemented on whatever backend server your application operates on, since any client-side checks can be modified or bypassed.

Authentication-enabled templates for Server-Side Blazor

private const string subscriptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //your-subscription-key;
private const string _endpoint =
"https://westus.api.cognitive.microsoft.com/face/v1.0/detect";
private const string localImagePath = @"Images/image.jpg";
private const string remoteImageUrl =
"http://images5.fanpop.com/image/photos/26900000/Nicolas-Cage-nicolas-cage-26969804-2069-2560.jpg";
public interface IFluentApiDefinition
{
IFluentEndpoint HasEndpointUri(string endpoint);
}
public interface IFluentEndpoint
{
IWithVersion OfVersion(string apiVersion);
@mouadcherkaoui
mouadcherkaoui / Struct.ps1
Created April 12, 2019 22:22 — forked from proxb/Struct.ps1
Using PowerShell and Reflection to dynamically build a Struct with Constructors and Methods
#region Module Builder
$Domain = [AppDomain]::CurrentDomain
$DynAssembly = New-Object System.Reflection.AssemblyName(([guid]::NewGuid().ToString()))
$AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, [System.Reflection.Emit.AssemblyBuilderAccess]::Run) # Only run in memory
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(([guid]::NewGuid().ToString()), $False)
#endregion Module Builder
#region STRUCTs
#Order of creating these Structs is important
#region MyStruct
$Attributes = 'AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, BeforeFieldInit'
using System;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using ObjectDumper;
using Xunit;
namespace Classdynamic.BK5
@mouadcherkaoui
mouadcherkaoui / ViewModelBase.cs
Created April 6, 2019 17:16 — forked from mariodivece/ViewModelBase.cs
A simple ViewModelBase for WPF Apps
namespace Unosquare.Wpf
{
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
public abstract class ViewModelBase : INotifyPropertyChanged
{
// uncomment the line below for Log4Net Logging
@mouadcherkaoui
mouadcherkaoui / Guid.ts
Created December 12, 2018 10:19 — forked from emptyother/Guid.ts
GUID class for Typescript
class Guid {
public static newGuid(): Guid {
return new Guid('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = Math.random() * 16 | 0;
const v = (c == 'x') ? r : (r & 0x3 | 0x8);
return v.toString(16);
}));
}
public static get empty(): string {
return '00000000-0000-0000-0000-000000000000';
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionAppName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},
@mouadcherkaoui
mouadcherkaoui / AppDataContext.csx
Last active March 22, 2020 19:13
Example of using EntityFramework in Azure Functions
#load "member.csx"
using System.Data.Entity;
using Microsoft.Azure;
public class AppContext: DbContext {
public static string connectionString = CloudConfigurationManager.GetSetting("SqlAzureConnectionString");
// we should have an appSetting named SqlAzureConnectionString
// or simply use it in connectionStrings section and use this method
// ConfigurationManager.ConnectionStrings["ConnectStringToUse"].ConnectionString