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
// 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 =
@altbodhi
altbodhi / githubEvents.fsx
Created June 21, 2023 12:58
Скрипт на F# для получения событий репозитария
(*
Для запуска на виднос выполнить команду:
dotnet fsi --exec githubEvents.fsx
*)
#r "nuget: FSharp.Data"
open FSharp.Data
let [<Literal>] url = "https://api.github.com/networks/radzenhq/radzen-blazor/events"
type Events = JsonProvider<url>
@altbodhi
altbodhi / xfce_fsharp_wallpaper.fsx
Last active March 4, 2023 13:07
F# script for xfce wallpaper picture of day
#r "nuget: FSharp.Data, 5.0.2"
open System
open System.Diagnostics
open FSharp.Data
open System.IO
let [<Literal>] feedUrl = "https://peapix.com/bing/feed"
type BingoImage = JsonProvider<feedUrl>
let out = Path.Combine(__SOURCE_DIRECTORY__, "bing")
@altbodhi
altbodhi / big_file_sort_in_csharp.cs
Created August 22, 2022 02:55
Very simple code for sorting big text file in csharp
/*
2_000_000 => 16 sec
5_ => 32
10_ => 1:10
20_ => 2:58
40_ => 13:44 file size = 2.5 Gb
*/
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Diagnostics;
using static System.Console;
var sw = Stopwatch.StartNew();
var alf = get_alf();
do_it(2_000_000);
sw.Stop();
WriteLine(sw.Elapsed); // <= 00:00:13.4216229 it is very fast! fantasctic!
char[] get_alf()
@altbodhi
altbodhi / stupid_file_sort_in_fsharp.fsx
Created August 19, 2022 01:48
Реализация тестового задания на примере https://github.com/podkolzzzin/Stream.Profiling
open System
open System.IO
let num () = Random.Shared.Next(0, 10_000)
let alf =
[| ' ' |]
|> Array.append [| 'A' .. 'Z' |]
|> Array.append [| 'a' .. 'z' |]