Skip to content

Instantly share code, notes, and snippets.

View altbodhi's full-sized avatar
🏠
Working from home

altbodhi

🏠
Working from home
View GitHub Profile
@altbodhi
altbodhi / SberAccountParser.fsx
Created September 2, 2025 04:21
Парсер выписки по счету из приложения Сбер Онлайн (pdf)
#r "nuget: FSharp.Data"
open FSharp.Data
open System
type AccountTransaction =
{ Date: DateTime
Category: string
Amount: decimal
Description: string }
@altbodhi
altbodhi / ContinuationExample.fsx
Created August 31, 2025 15:23
F# Continuation Example
// продолжения на F#
type Cont<'a, 'r> = ('a -> 'r) -> 'r
module Cont =
// Создание continuation из значения
let ret (x: 'a) : Cont<'a, 'r> =
fun k -> k x
// Связывание continuation
let bind (m: Cont<'a, 'r>) (f: 'a -> Cont<'b, 'r>) : Cont<'b, 'r> =
@altbodhi
altbodhi / Locator.cs
Created August 16, 2025 00:32
Search adplace by loc
namespace Company.AdPlaceSearchEngine;
public record Location(string Name);
public record AdPlace(string Name);
public abstract record SearchResult(Location Location)
{
public record NotFound(Location Location) : SearchResult(Location);
public record Success(Location Location, List<AdPlace> AdPlaces) : SearchResult(Location);
}
@altbodhi
altbodhi / Text.find.fsx
Created April 5, 2025 07:35
Wirt Niklaus Example search in string via F#
module Text =
/// поиск индекс первого вхождения образца в строке
let findFirst (s: string) (p: string) =
// предикат проверяющий совпадение части строки с образцом
let eqSample i (s: string) (p: string) =
let rec loop j =
if j < p.Length && p.[j] = s.[i + j] then
loop (j + 1)
else
@altbodhi
altbodhi / TelegramWebApp.fsx
Created March 27, 2025 14:22
Check hash initData TelegramWebApp
module TelegramWebApp =
open System.Security.Cryptography
open System.Text
open System.Web
let validateInitData botToken (initData: string) =
let items =
initData.Split "&" |> Array.map (fun x -> let p = x.Split("=") in (p[0], p[1]))
// controller
[HttpGet("tgCheckWebAppAuth")]
public async Task<IActionResult> CheckWebAppAuth([FromQuery] Dictionary<string, string> userData)
{
var user = telegramLoginUrl.CheckWebAppTelegramAuthorization(userData);
if (await Invalid(user)) return Unauthorized();
await SignIn(user, [new Claim("Source", "TelegramWebApp")]);
@altbodhi
altbodhi / Home.razor
Last active December 20, 2023 14:25
throttled
@page "/"
@rendermode InteractiveServer
<input value="@query" @oninput="OnInput" />
@if (isGetItems)
{
<div style="font-style: italic;">поиск...</div>
}
else
@altbodhi
altbodhi / Atomic.fsx
Created November 21, 2023 03:12
Atom in F#
open System
type Message<'a> =
| Get of AsyncReplyChannel<'a>
| Update of AsyncReplyChannel<'a> * ('a -> 'a)
type Atom<'a>(o: 'a) =
let agent =
MailboxProcessor.Start(fun b ->
let rec loop (acc) =
@altbodhi
altbodhi / Index.razor
Created October 25, 2023 09:17
Fail on Sound generating in browser
<MudButton ButtonType="ButtonType.Button" OnClick="BeepIfIncomingMessage">OK</MudButton>
@code {
async Task BeepIfIncomingMessage()
{
if (jsSoundUtils == null)
jsSoundUtils = await JS.InvokeAsync<IJSObjectReference>("import", "./js/SoundUtils.js");
var res = await jsSoundUtils.InvokeAsync<object>("soundBeep");
}
@altbodhi
altbodhi / ZenUtil.fsx
Created October 15, 2023 13:19
Simple timer for zen meditation written on F#
module ZenUtil
#r "nuget: NAudio"
#r "nuget: System.Speech"
open NAudio.Wave
open System
module WindowsSpeech =