Skip to content

Instantly share code, notes, and snippets.

@maurges
maurges / Main.hs
Created November 22, 2025 20:35
Scrape a certain web novel
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE LambdaCase #-}
module Main where
import qualified Data.Text.IO as TIO
import qualified Text.HTML.Scalpel as S
import qualified System.Process as P
import Control.Applicative ((<|>))
@maurges
maurges / hash_to_curve.rs
Created January 30, 2025 10:46
generic-ec hashing to curve
mod internal {
pub trait HashToCurve: generic_ec::Curve {
/// This function may fail, but the probability of that must be low. If
/// it fails, we retry with a different prefix. If it fails too many
/// times, we panic
fn hash_to_curve(
messages: &[&[u8]],
dst: &[u8],
) -> Option<generic_ec::NonZero<generic_ec::Point<Self>>>;
}
#!/usr/bin/env runhaskell
{-# LANGUAGE LambdaCase #-}
import GHC.Stack (HasCallStack)
import Data.List (partition)
import Data.Foldable (foldl')
import Numeric (showHex)
import System.Environment (getArgs)
import Text.Read (readMaybe)
@maurges
maurges / default.nix
Last active October 5, 2024 19:56
Use fish as nix shell. Works with other shells too
{ system, nixpkgs ? <nixpkgs> }:
let pkgs = import nixpkgs {inherit system;};
in pkgs.stdenvNoCC.mkDerivation {
name = "fshell";
script = pkgs.substituteAll {
src = ./fshell.bash;
bashInteractive = pkgs.bashInteractive;
};
@maurges
maurges / nodrop.rs
Created July 25, 2024 13:36
Some fuckery with rust typeclasses; trying to do equality for constants
#![feature(generic_const_exprs)]
pub trait NoDrop {}
trait False<const V: bool> {}
impl<T> False<false> for T {}
// Doesn't work actually, get some weird non-descriptive errors "unconstrained generic constant"
impl<T> NoDrop for T where
T: False<{ std::mem::needs_drop::<T>() }>,
@maurges
maurges / Solve.hs
Last active December 5, 2023 21:34
AOC 5
import Data.List (sort)
data Range = Range {start :: !Int, end :: !Int}
deriving (Show, Eq, Ord)
type Mapping = [(Range, Range)] -- ^ source -> dest, not like reqs
pipe :: [Mapping] -> Int -> Int
pipe [] val = val
pipe (mapping:maps) val = case filter (rangeElem val . fst) mapping of
[(source, dest)] -> pipe maps $! val - start source + start dest
@maurges
maurges / assemble-presigs.hs
Created September 13, 2023 08:23
Assemble ecdsa presignatures into a signature
#!/usr/bin/env runhaskell
import Data.Foldable (foldl')
import Numeric (showHex)
import System.Environment (getArgs)
hex = flip showHex ""
m = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 :: Integer
sumMod m = foldl' (\a b -> (a + b) `mod` m) 0
@maurges
maurges / Cargo.toml
Created July 28, 2023 20:05
Rust ffmpeg benchmark
[package]
name = "ffmpeg-benchmark"
version = "0.1.0"
edition = "2021"
[dependencies]
ffmpeg-next = { version = "6.0.0", default-features = false, features = ["codec", "format", "software-scaling", "software-resampling"] }
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Window 2.12
Window {
width: column.width
height: column.height * 1.5
Column {
@maurges
maurges / main.rs
Created January 19, 2023 10:14
Static lifetime can demote to any other lifetime
fn main() {
let builder = Builder::new();
let mut num = 1337;
let builder = builder.set_kek(&mut num);
builder.run()
}
trait Bar {
fn foo(&self);
}