Skip to content

Instantly share code, notes, and snippets.

View nerodono's full-sized avatar
😒
У меня не отображается статус

Aleksandr nerodono

😒
У меня не отображается статус
View GitHub Profile
use std::{
fs,
num::{NonZeroU8, NonZeroUsize},
path::Path,
};
use regex::Regex;
macro_rules! entries {
() => {};
pub(crate) fn parse_hex(buffer: &[u8]) -> Result<usize, ()> {
let mut output = 0;
let buf_len = buffer.len();
for (idx, chr) in buffer.iter().copied().enumerate() {
let shl = 4 * (buf_len - idx - 1);
match chr {
alpha @ b'a'..=b'f' => {
output += (10_usize + (alpha - b'a') as usize) << shl;
}
pub(crate) fn parse_hex(buffer: &[u8]) -> FeedingResult<usize> {
let mut output = 0;
const fn naive_upper(v: u8) -> u8 {
v & !(0x20 * (v >= b'A') as u8)
}
// !{char} = incorrect
const TABLE: &[usize] = &[
import Data.Char ( isDigit )
import qualified Data.Map as M
import qualified Data.Bifunctor as Bi
import Prelude hiding ( scope, lookup )
data BType = Open | Close
deriving Show
newtype Operator = Operator String
@nerodono
nerodono / mre.py
Created December 18, 2023 05:22
Adaptix tagged union MRE
from adaptix import Retort
from typing import Literal
from dataclasses import dataclass
from io import IOBase
@dataclass(frozen=False, slots=True)
class InputMediaVideo:
"""Represents a video to be sent."""
@nerodono
nerodono / LambdellCalculus.hs
Last active January 7, 2024 00:31
Lambda calculus reduction in Haskell
module LambdellCalculus where
import qualified Data.Bifunctor as Bi
data Term = ApplyT Term Term
| VarT Char
| FunT Char Term
deriving(Show, Eq)
isValidVar :: Char -> Bool
@nerodono
nerodono / Number.hs
Created January 12, 2024 18:55
Natural & Integer numbers definition
module Number where
data Nat = S Nat | Z
deriving(Eq)
natIntoHaskellInt :: Nat -> Int
natIntoHaskellInt Z = 0
natIntoHaskellInt (S v) = natIntoHaskellInt v + 1
instance Show Nat where
@nerodono
nerodono / JsonParser.hs
Last active April 23, 2024 22:53
JSON parser written in haskell: no adequate error checking, just JSON
module JsonParser where
import qualified Data.Map as M
import qualified Data.Bifunctor as Bi
import Data.Char ( ord
, chr
, isHexDigit
, isDigit
)
@nerodono
nerodono / nat-typefuck.rs
Created February 4, 2024 17:11
Silly natural numbers on types
trait Nat {
type Succ;
const NUMERIC: u64;
}
struct S<T>(T);
struct Z;
impl Nat for Z {
@nerodono
nerodono / lambda.rs
Created February 8, 2024 12:26
Lambda calculus on Rust types
trait Lam<X> {
type Result;
}
struct True0;
struct True1<X>(X);
struct False0;
struct False1<X>(X);