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
@zmts
zmts / tokens.md
Last active April 27, 2025 21:01
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
<?php
define('BOT_TOKEN', 'XXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXX'); // place bot token of your bot here
function checkTelegramAuthorization($auth_data) {
$check_hash = $auth_data['hash'];
unset($auth_data['hash']);
$data_check_arr = [];
foreach ($auth_data as $key => $value) {
$data_check_arr[] = $key . '=' . $value;
@panesofglass
panesofglass / winforms-mvu.fsx
Last active November 22, 2023 15:30
Sample WinForms F# Script
#r "mscorlib.dll"
#r "System.dll"
open System
open System.Windows.Forms
type Update<'Msg, 'Model> = 'Msg -> 'Model -> 'Model
type Dispatch<'Msg> = 'Msg -> obj -> EventArgs -> unit
type View<'Model, 'Msg> = 'Model -> Dispatch<'Msg> -> Control
@Szer
Szer / Program.fs
Created May 20, 2021 07:53
That's the minimum giraffe sample?
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting
open Giraffe
WebHost
.CreateDefaultBuilder()
.UseKestrel()
.Configure(fun a -> a.UseGiraffe(route "/" >=> POST >=> bindJson json))
.ConfigureServices(fun s -> s.AddGiraffe() |> ignore)
.Build()
@altbodhi
altbodhi / skip_loop.n
Created July 13, 2022 13:07
The skip loop with Nemerle.
using System.Console;
def skip_loop(counter, skip, max, idx, lst) {
if (idx >= max) lst
else
if ( counter >= skip )
skip_loop(1, skip, max, idx + 1, idx :: lst)
else
skip_loop(counter + 1, skip, max, idx + 1, lst)
}
@altbodhi
altbodhi / micro_bench.n
Created July 14, 2022 02:39
Compare two equivalent of skip loop function with different paradigm: imperative and functional
using System;
using System.Console;
using System.Collections.Generic;
using System.Diagnostics;
def skip_loop(counter, skip, max, idx, lst) {
if (idx > max) lst
else
if ( counter >= skip )
skip_loop(1, skip, max, idx + 1, idx :: lst)
/**
* Performs Murmur3_32 hashing.
* https://en.wikipedia.org/wiki/MurmurHash
* @param key Int32Array input key
* @param seed int32 input seed
* @returns int32 value
*/
export default function murmur332(key, seed) {
let hash = seed;
import murmur332 from './murmur332.js';
// https://en.wikipedia.org/wiki/Bloom_filter
// https://hur.st/bloomfilter/
export default class BloomFilter {
#data;
#dataBitMask;
@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 / 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 =