Skip to content

Instantly share code, notes, and snippets.

View matu3ba's full-sized avatar

Jan Ph. H. matu3ba

View GitHub Profile
@matu3ba
matu3ba / sh1.hpp
Created November 27, 2024 13:45
SHA-1 in C++ flie sha1.hpp with fixes from https://github.com/vog/sha1 revision 3f8a4aa032d144309d00dbfe972906a49b3631b9
/*
sha1.hpp - source code of
============
SHA-1 in C++
============
100% Public Domain.
Original C Code
@matu3ba
matu3ba / mem_consistency.cpp
Created April 24, 2022 18:01
notes on memory consistency
// Memory concistency and atomicity
#include <atomic>
#include <cassert>
#include <iostream>
#include <mutex>
#include <thread>
// assume: init of data = 0, flag != SET
// hint: L1 and B1 can repeat many times
@matu3ba
matu3ba / concepts_check_mul_op.cpp
Last active August 27, 2024 20:59
concepts_check_multiply_operator_example
#include<iostream>
#include<type_traits>
#include<cstdio>
#include<concepts> // c++20
struct A {
bool operator == (A const &);
int operator * (int factor) {
return m * factor;
}
#if defined(__STDC__)
#define IS_MAYBE_C89
#if defined(__STDC_VERSION__)
#if (__STDC_VERSION__ >= 199409L)
#define IS_NOT_C89
#endif
#endif
#endif
#ifndef IS_MAYBE_C89
@matu3ba
matu3ba / ptrtoint_inttoptr.c
Last active June 23, 2024 21:31
clang c89 ptr to int -Weverything
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void ptrtointtoptr(void);
static void memset_16aligned(void * ptr, char byte, size_t size_bytes, uint16_t alignment) {
assert((size_bytes & (alignment-1)) == 0);
@matu3ba
matu3ba / ptrtoint_inttoptr.c
Created June 23, 2024 20:52
cerberus iso compat pointer works
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void memset_16aligned(void * ptr, char byte, size_t size_bytes, uint16_t alignment) {
assert((size_bytes & (alignment-1)) == 0); // Size aligned
assert(((uintptr_t)ptr & (alignment-1)) == 0); // Pointer aligned
memset(ptr, byte, size_bytes);
}
@matu3ba
matu3ba / error_msg
Created June 23, 2024 20:48
cerberus error ptrtoint_inttoptr.c
cerberus ptrtoint_inttoptr.c
ptrtoint_inttoptr.c:24:16: error: constraint violation: initializing 'void*' with an expression of incompatible type 'usual arithmetic conversions with type [integer promotion of [usual arithmetic conversions with type [integer promotion of [uintptr_t] and integer promotion of [unsigned short]]] and integer promotion of [integer promotion of [uintptr_t]]]'
void * ptr = ((uintptr_t)mem+align_min_1) & ~(uintptr_t)align_min_1;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
§6.7.9#11, sentence 2:
11 The initializer for a scalar shall be a single expression, optionally enclosed in braces. The
initial value of the object is that of the expression (after conversion); the same type
constraints and conversions as for simple assignment apply, taking the type of the scalar
to be the unqualified version of its declared type.
@matu3ba
matu3ba / results.txt
Last active June 22, 2024 14:43
benchmarks for muloti
Benchmark 1: ./mulo_fast
Time (mean ± σ): 1.008 s ± 0.009 s [User: 1.006 s, System: 0.001 s]
Range (min … max): 0.996 s … 1.027 s 10 runs
Warning: The first benchmarking run for this command was significantly slower than the
rest (1.027 s). This could be caused by (filesystem) caches that were not filled until af
ter the first run. You should consider using the '--warmup' option to fill those caches b
efore the actual benchmark. Alternatively, use the '--prepare' option to clear the caches
before each timing run.
@matu3ba
matu3ba / ansi-colors-discord.md
Created June 1, 2024 21:20 — forked from kkrypt0nn/ansi-colors-discord.md
A guide to ANSI on Discord

A guide to ANSI on Discord

Discord is now slowly rolling out the ability to send colored messages within code blocks. It uses the ANSI color codes, so if you've tried to print colored text in your terminal or console with Python or other languages then it will be easy for you.

Quick Explanation

To be able to send a colored text, you need to use the ansi language for your code block and provide a prefix of this format before writing your text:

\u001b[{format};{color}m

\u001b is the unicode escape for ESCAPE/ESC, meant to be used in the source of your bot (see ). If you wish to send colored text without using your bot you need to copy the character from the website.

@matu3ba
matu3ba / acl_min.zig
Created January 24, 2024 22:18
Minimal ACL. but ugly.
// zig run acl_min.zig
pub const DWORD = c_ulong;
pub const HANDLE = ?*anyopaque;
pub const PVOID = ?*anyopaque;
pub const PSID = PVOID;
pub const PSECURITY_DESCRIPTOR = PVOID;
pub const enum__SE_OBJECT_TYPE = c_uint;
pub const SE_OBJECT_TYPE = enum__SE_OBJECT_TYPE;
pub const wchar_t = c_ushort;
pub const SE_FILE_OBJECT: c_int = 1;