Skip to content

Instantly share code, notes, and snippets.

@asabla
asabla / Math.cs
Last active February 16, 2024 13:39
Semantic Kernel Native Math plugin example
// Copyright (c) Microsoft. All rights reserved.
using System.ComponentModel;
using Microsoft.SemanticKernel;
namespace Plugins;
public class MathPlugin
{
[KernelFunction, Description("Take the square root of a number")]
@asabla
asabla / Example.cs
Created February 11, 2024 12:08
Semantic Kernel - Using a local (OpenAI API compatible) model
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
var kernelBuilder = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: "ollama-model-name"
apiKey: "can-be-what-ever");
kernelBuilder.Services.ConfigureHttpClientDefaults(e =>
e.ConfigurePrimaryHttpMessagehandler(() => new ExampleRedirectHandler()));
@asabla
asabla / Program.fs
Last active February 16, 2023 19:59
Transform CSV files with F# - Convert some columns to Capital first letters of each word
open FSharp.Data
open System.Globalization
[<Literal>]
let ResolutionFolder = __SOURCE_DIRECTORY__
// Schema can also be set to "" if you want it to auto generate
// column names similar to: Column1, Column2
type TargetCSV = CsvProvider<
"./test.csv",
@asabla
asabla / ApiSettings.cs
Created February 16, 2023 17:08
Fluent Configuration validation example in .net 7 and web api
using System.ComponentModel.DataAnnotations;
namespace DotnetConsoles.Configuration.Api;
public class ApiSettings
{
[Required, Url, MinLength(10), ]
public string WebhookUrl { get; set; } = null!;
[Required, MinLength(3)]
@asabla
asabla / list-duplicated-files.ps1
Last active June 14, 2021 19:23
Find duplicated files with powershell
Get-ChildItem -Recurse -File |
Group-Object Length |
Where-Object { $_.Count -gt 1 } |
select -ExpandProperty group |
foreach { Get-FileHash -LiteralPath $_.FullName } |
group -Property hash |
where { $_.count -gt 1 } |
select -ExpandProperty group
@asabla
asabla / check-windows-update-install-date.ps1
Created May 2, 2021 19:56
Find and list windows updates through powershell
Get-ChildItem -Path HKLM:\System\Setup\Source* | ForEach-Object {Get-ItemProperty -Path Registry::$_} | Select-Object ProductName, ReleaseID, CurrentBuild, @{n="Install Date"; e={([DateTime]'1/1/1970').AddSeconds($_.InstallDate)}} | Sort-Object "Install Date"
@asabla
asabla / .bashrc
Created April 23, 2021 18:29
Prune old git branches
func_gitprune() {
echo 'Starting git prune'
echo "Found $(git branch | wc -l) number of local branches"
echo "Starts prune of origin branches...."
git remote prune origin
echo "Local branches which can be removed:"
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}'
@asabla
asabla / old-notes.txt
Created September 24, 2020 20:48
Network troubleshooting notes
Network troubleshooting
1. Check /etc/sysctl.conf
Specifically:
* net.core.netdev_max_backlog
* net.core.rmem_max
* net.core.rmem_default
Example values for default:
* net.core.netdev_max_backlog = 1000
* net.core.rmem_max = 131071
* net.core.rmem_default = 163480
@asabla
asabla / installation.ps1
Created September 12, 2019 08:51
Small Powershell script to create a local instance of Microsoft ServiceBus
# Reference: https://docs.microsoft.com/en-us/previous-versions/azure/jj193022(v=azure.10)?redirectedfrom=MSDN
# Before you can get started, you'll have to install the service it self with Web Platform installer.
# A direct link to binary it self can be found on the page from reference link.
# Prerequisites
# 1. Make sure you have SQL Express installed (at least 2012)
# 2. Make sure you have installed the service it self (it won't start until configured)
# You can verify this by looking for 'Windows Fabric Host Service' amongst windows services.
@asabla
asabla / digitalocean-dns-challenge
Last active May 11, 2018 10:29
Docker certbot examples
docker run -it --name certbot \
-v <certs>:/etc/letsencrypt \
-v <logs>:/var/lib/letsencrypt \
-v <do-secret>:/.secrets \
certbot/dns-digitalocean certonly \
--agree-tos \
--dns-digitalocean \
--dns-digitalocean-credentials /.secrets/do-token.ini \
--dns-digitalocean-propagation-seconds 60 \
--preferred-challenges dns-01 \