Skip to content

Instantly share code, notes, and snippets.

View JKamsker's full-sized avatar

Jonas Kamsker JKamsker

View GitHub Profile
@JKamsker
JKamsker / WeakDictionary.cs
Created July 13, 2024 17:27
Useful c# snippets
using System.Collections.Concurrent;
public class WeakDictionary<TKey, TValue>
where TKey : class
where TValue : class
{
private readonly ConcurrentDictionary<TKey, WeakReference<WeakEntry>> _dictionary = new();
public bool TryGetValue(TKey key, out TValue value)
{
@JKamsker
JKamsker / enforce.js
Created June 26, 2024 06:51
OpenAI Chat GPT-4o enforce
// ==UserScript==
// @name OpenAI Chat GPT-4o enforce
// @version 1
// @grant none
// @description This script enforces the GPT-4o model on the OpenAI Chat website
// @match https://chatgpt.com/*
// @run-at document-end
// ==/UserScript==
(function() {
@JKamsker
JKamsker / BufferOwner.cs
Last active June 13, 2024 07:02
BufferOwner.cs
public readonly struct BufferOwner<T> : IDisposable
{
private readonly T[] _buffer;
private readonly ArrayPool<T> _pool;
public BufferOwner(int size, ArrayPool<T> pool)
{
_buffer = pool.Rent(size);
_pool = pool;
}
@JKamsker
JKamsker / LiteToDos.md
Last active June 4, 2024 12:34
Things to do on LiteDB
  • Establishing community and contributing guidelines
  • Fixing most urgent bugs
    • Lock recursion bug
  • Memory leak
@JKamsker
JKamsker / TeamViewerDevice.cs
Created December 22, 2023 10:26
Get Teamviewer devices
var dev = new TeamViewerDevice()
{
ApiToken = "APIKEY",
};
await dev.GetTeamViewerDevice();
Debugger.Break();
public class TeamViewerDevice
{
@JKamsker
JKamsker / AsyncMutex.cs
Last active December 8, 2023 18:19
FileWriterMutex
using System.Collections.Concurrent;
namespace JKToolKit.Logging.File.Utils;
public abstract class AsyncMutex : IDisposable
{
private static ConcurrentDictionary<string, AsyncMutex> _localMutexes = new ConcurrentDictionary<string, AsyncMutex>();
public abstract Task<IDisposable> WaitOneAsync(CancellationToken ct);
@JKamsker
JKamsker / keybase.md
Created October 31, 2023 13:31
keybase.md

Keybase proof

I hereby claim:

  • I am jkamsker on github.
  • I am jkamsker (https://keybase.io/jkamsker) on keybase.
  • I have a public key ASAE3Pbe3Sm3SiIeiXZ8MZ7pm5xLfsqEGXuY4CXIhFM_Tgo

To claim this, I am signing this object:

@JKamsker
JKamsker / ConstructorRedirect.md
Created August 17, 2023 14:32
Constructor Redirect

Proposal: Constructor redirect

Summary: Allow for constructor arguments to be seemingly mirrored by a generic factory method.

Sample: myfactory.Create("param1", "param2", "param3");

class CommandType

@JKamsker
JKamsker / CompletionScript.ps1
Created July 30, 2023 23:20
AutoComplete Ideas
$script:process = $null
$script:path = "C:\Users\W31rd0\source\repos\work\Apro\Apro.AutoUpdater\ApGet\bin\Debug\net6.0\ApGet.exe"
$script:logPath = "C:\Users\W31rd0\Downloads\tmp\gpt\log.log"
$script:useCompletionServer = $false
function Invoke-ApGet {
# call external debugger
return & $script:path $args
}
@JKamsker
JKamsker / ApGet.ps1
Last active July 25, 2023 14:23
ApgetWebInstall
# Set the URL of the ZIP file and the target directory
$zipUrl = "https://apropatchcdn.blob.core.windows.net/patch-staging/apget/latest/apget.zip"
# https://apropatchcdn.blob.core.windows.net/patch-staging/apget/latest/apget.zip"
# https://apropatchcdn.blob.core.windows.net/patch-staging/apget/latest/apget.zip
# $targetDirectory = "$env:USERPROFILE\Tools\Apget"
$targetDirectory = Split-Path ($profile.CurrentUserAllHosts)
$targetDirectory = Join-Path $targetDirectory "Tools"
$targetDirectory = Join-Path $targetDirectory "Apget"