Skip to content

Instantly share code, notes, and snippets.

View MaxXSoft's full-sized avatar
🇨🇳
Reinventing wheels.

MaxXing MaxXSoft

🇨🇳
Reinventing wheels.
View GitHub Profile
@MaxXSoft
MaxXSoft / type_list.rs
Last active June 17, 2024 08:13
Type-level list in Rust.
//! A type-level list implementation that can assert
//! a list must contain a specific type element.
use std::marker::PhantomData;
/// Type-level boolean.
pub trait Bool {}
/// Type-level `false`.
pub struct False;
@MaxXSoft
MaxXSoft / assert_return_type.rs
Last active March 25, 2024 08:12
Asserting function's return type in Rust.
// NOTE: this trick does not work on extern functions (like `extern "C" fn ...`).
/// Trait for getting the return type of a function with argument tuple `T`.
trait ReturnType<T> {
/// The return type.
type Output;
}
/// Helper macro for implementing `ReturnType` for function types.
macro_rules! impl_return_type {
@MaxXSoft
MaxXSoft / datamosh.py
Last active November 18, 2023 08:14
MaxXing's PV tools.
#!/usr/bin/env python3
'''
Tool for making datamosh style videos with ffmpeg.
Written by MaxXing, licensed under GPL-v3.
'''
import subprocess
import os
import shutil
@MaxXSoft
MaxXSoft / main.rs
Created October 12, 2023 07:38
A simple example to emit code at runtime on AArch64 (ARM64) in Rust using crate `dynasmrt`.
//! A simple example to emit code at runtime on AArch64 (ARM64)
//! in Rust using crate `dynasmrt`.
//!
//! Written by MaxXing, 2023-10-12.
use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi};
use std::io::{self, Write};
use std::{mem, slice};
fn main() {
@MaxXSoft
MaxXSoft / Dockerfile
Created November 27, 2022 09:40
A fun tool for generating an x86-64 Linux program that runs in reverse order.
FROM ubuntu:20.04
RUN apt update && DEBIAN_FRONTEND="noninteractive" apt install -y \
python3 build-essential
WORKDIR /root
@MaxXSoft
MaxXSoft / rsync.vbs
Created April 2, 2022 07:31
Script for running `rsync` on Windows, based on the cwRsync.
' Helper script for running `rsync` from the command line.
' Author: MaxXing, 2022.
'
' You can get `rsync` for Windows on https://www.itefix.net/cwrsync.
' Then you should place this script in the same folder as the `rsync.exe` file.
'
' Usage:
' rsync.vbs [options] [source] [destination]
@MaxXSoft
MaxXSoft / aot.cpp
Last active August 13, 2022 05:12
Calculating 20! in an Elegant Way in C++
#include <iostream>
#include <vector>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <sys/mman.h>
@MaxXSoft
MaxXSoft / llvm_test.cpp
Last active March 10, 2019 08:03
Generate a simple program to object file using LLVM.
/*
generate a simple program to object file using LLVM
int main(int argc, const char *argv[]) {
if (argc == 2) {
puts(argv[1]);
}
return 0;
}
@MaxXSoft
MaxXSoft / fib_list.cpp
Last active November 16, 2018 00:59
Generate an array containing the first 1000 terms of Fibonacci sequence, at compile time.
#include <iostream>
#include <utility>
#include <type_traits>
#include <cstdint>
#include <cstddef>
using namespace std;
// compile time string
template <char c, size_t n, char ...suffix>
struct CharRepeat : public CharRepeat<c, n - 1, c, suffix...> {};