Skip to content

Instantly share code, notes, and snippets.

View jernejk's full-sized avatar

Jernej Kavka (JK) [SSW • Microsoft MVP] jernejk

View GitHub Profile
@jernejk
jernejk / qdrant-search
Created February 2, 2026 06:49
Moltbook.sh CLI (part 2)
@jernejk
jernejk / Moltbook.sh
Created February 2, 2026 06:47
Moltbook CLI (part 1)
#!/usr/bin/env bash
# moltbook - CLI for searching Moltbook (social network for AI agents)
set -euo pipefail
API_BASE="https://www.moltbook.com/api/v1"
CONFIG_DIR="${HOME}/.config/moltbook"
CONFIG_FILE="${CONFIG_DIR}/config"
INDEX_FILE="${CONFIG_DIR}/index.json"
QDRANT_SEARCH="$(dirname "$0")/qdrant-search"
QDRANT_COLLECTION="moltbook-posts"
@jernejk
jernejk / TagWithExtensions.cs
Created January 17, 2024 01:03
Custom TagWithContext to extend EF Core TagWith with caller class name, method and tag/purpose (optional)
public static class TagWithExtensions
{
public static IQueryable<T> TagWithContext<T>(this IQueryable<T> queryable, string? message = "", [CallerFilePath] string callerFileName = "", [CallerMemberName] string callerName = "")
{
string logScopeName = GenerateLogScopeName(message, callerFileName, callerName);
return queryable.TagWith(logScopeName);
}
private static string GenerateLogScopeName(string? message = null, string callerFileName = "", string callerName = "")
{
public async Task InsertTweetStoreProc(string username, string message, CancellationToken ct = default)
{
using (_logger.BeginScope(new Dictionary<string, object> { { "EFQueries", "GetTweetsLog" } }))
{
_ = await _context.Database
.ExecuteSqlRawAsync(
"InsertTweet @Username, @Message",
new SqlParameter("Username", username),
new SqlParameter("Message", message));
}
@EventType = 0xE9507561
public async Task InsertTweetStoreProc(string username, string message, CancellationToken ct = default)
{
using (_logger.BeginScope(new Dictionary<string, object> { { "EFQueries", "InsertTweetStoreProc" } }))
{
_ = await _context.Database
.ExecuteSqlRawAsync(
"InsertTweet @Username, @Message",
new SqlParameter("Username", username),
new SqlParameter("Message", message));
}
@jernejk
jernejk / create-custom-form-recognizer.ps1
Last active July 19, 2021 08:16
Create Custom Form Recognizer script
param(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $ResourceGroup = $null,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $ResourceLocation = 'EastUS',
# F0 is free and S0 is paid SKU
public async Task<IEnumerable<Tweet>> GetTweetsWithExtraLogs(CancellationToken ct = default)
{
using (_logger.BeginScope(new Dictionary<string, object> { { "EFQueries", "GetTweetsLog" } }))
{
return await _context.Tweets
.TagWith("GetTweets + LogContext")
.ToListAsync(ct)
.ConfigureAwait(false);
}
}
public Task InsertTweetStoreProc(string username, string message, CancellationToken ct = default)
{
using (_logger.BeginScope(new Dictionary<string, object> { { "EFQueries", "InsertTweetStoreProc" } }))
{
_ = _context.Tweets
.FromSqlRaw(
"InsertTweet @Username, @Message",
new SqlParameter("Username", username),
new SqlParameter("Message", message))
// A hack to make STORE PROC work when they don't return anything.
public async Task InsertTweet(string username, string message, CancellationToken ct = default)
{
using (_logger.BeginScope(new Dictionary<string, object> { { "EFQueries", "InsertTweet" } }))
{
_context.Tweets.Add(new Tweet
{
Username = username,
Message = message,
CreatedUtc = DateTime.UtcNow
});