Skip to content

Instantly share code, notes, and snippets.

@unsafePtr
unsafePtr / script.ps1
Created December 1, 2025 21:23
Windows RSA key rights
# use wsl or git bash
chmod 600
# this can be run from powershell/terminal
$key = "path_to_key.pem"
# Remove inheritance and give only your user access
icacls.exe $key /reset
icacls.exe $key /inheritance:r
icacls.exe $key /grant:r "$($env:USERNAME):F"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Telegram Mini App</title>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<style>
body {
background-color: white;
font-family: sans-serif;
@unsafePtr
unsafePtr / windows-kill-process-by-port.md
Created April 3, 2025 20:13
Windows kill process by port number
function Kill-ProcessByPort { param([int]$Port) try { $processId = (Get-NetTCPConnection -LocalPort $Port -ErrorAction Stop).OwningProcess; Stop-Process -Id $processId -Force; Write-Output "Process using port $Port has been terminated." } catch { Write-Output "No process found using port $Port" } }

Usage:

Kill-ProcessByPort -Port 5008
public class TenantOutputCachePolicy : IOutputCachePolicy
{
public static string CreateVaryKey(int tenantId)
{
return $"TenantId-{tenantId}";
}
public ValueTask CacheRequestAsync(OutputCacheContext context, CancellationToken cancellation)
{
context.CacheVaryByRules.HeaderNames = "X-Tenant";
@unsafePtr
unsafePtr / entityframework_migration_consolidation.md
Created January 16, 2025 10:48
EF Migrations consolidation
  1. First revert to the target migration:
dotnet ef database update TargetMigrationName
  1. Remove all existing migrations (this removes the migration files and history). Run this command for as many migrations as you have applied from the target one:
dotnet ef migrations remove
@unsafePtr
unsafePtr / script.ps
Created August 17, 2023 10:26
Windows git cleanup branches which doesn't track remote
git branch --merged | %{$_.trim()} | ?{$_ -notmatch 'dev' -and $_ -notmatch 'master' -and $_ -notmatch 'main'} | %{git branch -d $_.trim()}
@unsafePtr
unsafePtr / CacheDecorator.cs
Last active October 25, 2018 13:39
Example of cache decorator
// Used as an interceptor to provide cache mechanism.
// ISomeService can be any other service and this is just an example for you own class cache.
// Should be used as singleton to get benefit from it.
public class CacheDecorator : ISomeService
{
private static ConcurrentDictionary<string, Task<string>> Cache { get; } = new ConcurrentDictionary<string, Task<string>>();
private ISomeService Implementation { get; }
public CacheDecorator(ISomeService implementation)