Skip to content

Instantly share code, notes, and snippets.

View ilmax's full-sized avatar
🚀

Massimiliano Donini ilmax

🚀
View GitHub Profile
-- Right click copy and paste
config.mouse_bindings = {
{
event = { Down = { streak = 1, button = "Right" } },
mods = "NONE",
action = wezterm.action_callback(function(window, pane)
local has_selection = window:get_selection_text_for_pane(pane) ~= ""
if has_selection then
window:perform_action(act.CopyTo("ClipboardAndPrimarySelection"), pane)
@ilmax
ilmax / Broken.cs
Created October 19, 2023 11:49
SQLite sample
using Microsoft.EntityFrameworkCore;
var customers = new List<Customer>();
for (int i = 0; i < 20; i++)
{
customers.Add(new Customer(i, i % 5, i * 2));
}
using (var context = new AppDbContext())
{
@ilmax
ilmax / terraform-workaround.tf
Created April 6, 2023 13:37
terraform-workaround
## Get an access token using standard cli functionality
data "external" "token" {
program = ["az", "account", "get-access-token"]
}
## Put the access token in a local variable for ease of use
locals {
accessToken = data.external.token.result["accessToken"]
}
@ilmax
ilmax / dark-magic.ps1
Created April 4, 2023 18:04
Grant permission to an azure ad app
$downstreamApp = az ad app list --all --query "[?displayName=='$downstreamServiceName']" | ConvertFrom-Json
if (!$downstreamApp) {
throw "The app registration $downstreamServiceName does not exist."
}
# Get the downstream app scopes
$downstreamAppScopes = az ad app show --id $downstreamApp.appId --query "api.oauth2PermissionScopes" | ConvertFrom-Json
# Get the id and name of the first scope (using the first because we have just one and it's usually the user_impersonation scope)
$scopeName = $downstreamAppScopes[0].value
@ilmax
ilmax / roles.json
Last active February 11, 2023 10:31
Get MsGraph scopes and roles
{
"Scopes": [
{
"adminConsentDescription": "Allows the app to read the available Teams templates, on behalf of the signed-in user.",
"adminConsentDisplayName": "Read available Teams templates",
"id": "cd87405c-5792-4f15-92f7-debc0db6d1d6",
"isEnabled": true,
"type": "User",
"userConsentDescription": "Read available Teams templates, on your behalf.",
"userConsentDisplayName": "Read available Teams templates",
@ilmax
ilmax / insert.sql
Last active November 17, 2022 16:22
Typed Ids
Executed DbCommand (37ms) [Parameters=[@p0='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
INSERT INTO [Blogs] ([Name])
OUTPUT INSERTED.[Id]
VALUES (@p0);
Executed DbCommand (17ms) [Parameters=[@p0='?' (DbType = Int32), @p1='?' (Size = 4000), @p2='?' (DbType = DateTimeOffset), @p3='?' (Size = 4000), @p4='?' (DbType = Int32), @p5='?' (Size = 4000), @p6='?' (DbType = DateTimeOffset), @p7='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
SET IMPLICIT_TRANSACTIONS OFF;
SET NOCOUNT ON;
@ilmax
ilmax / wrk.txt
Created July 28, 2022 11:31
wrk results
No deployment in progress
wrk -t8 -c32 -d2m --latency --timeout 5s https://xxxxxxxxxxxxxxxxxx.azurecontainerapps.io/api/echo/ping
Running 2m test @ https://xxxxxxxxxxxxxxxxxx.azurecontainerapps.io/api/echo/ping
8 threads and 32 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 36.48ms 31.84ms 216.95ms 72.82%
Req/Sec 126.06 26.67 250.00 75.33%
Latency Distribution
50% 14.21ms
@ilmax
ilmax / deploy.sh
Last active July 28, 2022 10:11
Deployment script
#!/bin/bash
rg=<your resource group name here>
app=<your container app name here>
baseimage=<your acr name here>.azurecr.io/<your repository name here>
tag=<your image tag here>
host=<your deployment app host here>
url=http://$host/resource-groups/$rg/apps/$app/deploy
echo "Starting deployment at: $url"
curl --get --data-urlencode imageName=$baseimage:$tag $url
@ilmax
ilmax / runbook.ps1
Created July 24, 2022 10:33
Azure automation account runbook to scale up & down an App Service Plan
$errorActionPreference = "Stop"
Write-Output "--- Connecting to Azure using MSI..."
Connect-AzAccount -Identity
Write-Output "--- Reading variables...."
$rg = Get-AutomationVariable -Name 'rg-name'
$servicePlan = Get-AutomationVariable -Name 'service-plan-name'
$sk = Get-AutomationVariable -Name 'scale-down-sku'
@ilmax
ilmax / containerapp.tf
Last active November 25, 2022 15:41
azapi terraform provider configuration
resource "azapi_resource" "aca-test-environment" {
name = "aca-test-environment"
type = "Microsoft.App/managedEnvironments@2022-03-01"
location = var.location
parent_id = azurerm_resource_group.aca-test-rg.id
body = jsonencode({
properties = {
appLogsConfiguration = {
destination = "log-analytics"
logAnalyticsConfiguration = {