Skip to content

Instantly share code, notes, and snippets.

View MirzaMerdovic's full-sized avatar
💭
🐀

Mirza Merdovic MirzaMerdovic

💭
🐀
View GitHub Profile
var builder = WebApplication.CreateBuilder(args);
builder.Configuration
.AddAzureAppConfiguration(options =>
{
var connectionString = Environment.GetEnvironmentVariable("AppConfiguration__ConnectionString");
options
.Connect(connectionString)
.Select("Appc:*", "configs")
@MirzaMerdovic
MirzaMerdovic / EventGridWebHook.cs
Last active July 3, 2022 20:06
Snippet for: Azure App Configuration as a configuration provider in .NET Core apps - Part 3: Hot-Reload (https://medium.com/p/de398e009553)
app.MapPost(
"/refresh",
async (
[FromBody] Azure.Messaging.EventGrid.EventGridEvent[] request,
[FromServices] IConfigurationRefresherProvider refreshProvider) =>
{
var eg = request.First();
if (eg.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent")
{
Perf
| where ObjectName == "System"
| extend UpTime = CounterValue * 1s
| project TimeGenerated, Computer, UpTime
| summarize arg_max(TimeGenerated, *) by Computer
| order by UpTime desc
==================================================
let Linu = Heartbeat
@MirzaMerdovic
MirzaMerdovic / UbuntuCommands
Last active May 6, 2019 20:24
Ubuntu Commands
Get OS version:
lsb_release -a
Get OS release name:
lsb_release -cs
Get Memory usage:
free -m
Resource monitor:
@MirzaMerdovic
MirzaMerdovic / Git Commands
Created February 26, 2019 17:59
GIT Commands
# Add all files and commit
git add .
git commit
# Rebase master to working branch
git rebase master -i
# Rebase and fixup N commits on master
In example below N = 2
git rebase HEAD~2 -i
private static TDelegate BuildHandler<TDelegate>(TServiceImpl instance, string methodName)
{
MethodInfo method = instance.GetType().GetMethod(methodName);
IEnumerable<ParameterExpression> parameters = method.GetParameters().Select(x => Expression.Parameter(x.ParameterType)).ToList();
var call = Expression.Call(Expression.Constant(instance), method, parameters);
var func = Expression.Lambda<TDelegate>(call, false, parameters).Compile();
return func;
}
@MirzaMerdovic
MirzaMerdovic / Add your LocalIP to hosts file
Created December 5, 2018 14:05
Powershell script that will resolve you local IP address and persist it to your hosts file.
Install-Module -Name 'Carbon' -AllowClobber
$ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1}
$ip.ipaddress[0]
Set-HostsEntry -IPAddress $ip.ipaddress[0] -HostName 'home' -Description "Local IP Address"
@MirzaMerdovic
MirzaMerdovic / Injecting AspNet.Core Configuration
Last active September 22, 2018 22:18
Snippeet for injecting reloadable strongly typed configuration into your asp.net core Web API
Let's say that your appsettings.{envinronment}.json looks like this.
```
{
"DatabaseConfiguration": {
"apiDb": "Server={localhost};Initial Catalog={database};User ID={userName};Password={password};",
"api2Db": "Server={localhost};Initial Catalog={database};User ID={userName};Password={password};"
},
}
```
@MirzaMerdovic
MirzaMerdovic / gist:c36822fc0552b108ec2c47d9760850a4
Created May 7, 2018 10:26
Convert Newtonsoft.Json.Linq.JArray to System.Collections.Generic.Dictionary<,>
// If you have a serialized dictionary in your configuration for example, something like this:
// "dictionary": [{"1":"asda"}, {"2":"qweww"}, {"3":{"awdsd333"}]
Dictionary<int, string> parameters =
((JArray)serializedJArray)
.Children<JObject>()
.ToDictionary(x => int.Parse(x.Properties().First().Name), x => x.Properties().First().Value.ToString());
## Method
private static Task<IEnumerable<T>> QueryAnonymAsync<T>(IDbConnection connection, Func<T> typeBuilder, string sql)
{
return connection.QueryAsync<T>(sql, typeBuilder);
}
## Usage
return
await
QueryAnonymAsync(conn,