Skip to content

Instantly share code, notes, and snippets.

View kassane's full-sized avatar
🏠
Working from home

Matheus C. França kassane

🏠
Working from home
View GitHub Profile
@kassane
kassane / adapton.c
Last active April 16, 2023 15:19
Adapton programming model & Lazy evaluation - int values
// Reference: http://plum-umd.github.io/adapton/
#include <stdio.h>
#include <stdlib.h>
typedef struct Adapton_Int {
int value;
int (*compute)(struct Adapton_Int *, struct Adapton_Int *);
struct Adapton_Int *arg1;
struct Adapton_Int *arg2;
@kassane
kassane / zig_cpp-modules.md
Last active October 6, 2023 19:41
Zig/clang++ (C++20) modules
// main.cpp

import moduleTest;

#include <cstdio>

auto main() -> int
{
@kassane
kassane / forth.zig
Last active January 2, 2023 13:55 — forked from MasterQ32/forth.zig
Zig Comptime Forth
//! Tested on Zig v0.10 (stage 1)
const std = @import("std");
test "forwarding a value" {
const result = forth("value", .{
.value = @as(u32, 42),
});
std.testing.expectEqual(@as(u32, 42), result);
@kassane
kassane / check_cpu_version.cpp
Last active December 22, 2022 13:39
Check architecture version to x86_64 CPU - written on C++
// ref: https://unix.stackexchange.com/questions/631217/how-do-i-check-if-my-cpu-supports-x86-64-v2/631226#631226
// by: Matheus Catarino França
// License: CC0
#include <fstream>
#include <iostream>
#include <string>
int main() {
std::ifstream cpuinfo("/proc/cpuinfo");
@kassane
kassane / client.cpp
Last active February 26, 2023 06:53
Draft C++ wrapper to TigerBeetle database
#include "tb_client.hpp"
int main() {
tb::Client client("localhost", 8080);
tb::Account account({0, 0, {0}, 1, 1, TB_ACCOUNT_LINKED, 0, 0, 0, 0, 0});
tb::create_account_result result = client.create_account(account);
if (result != TB_CREATE_ACCOUNT_OK) {
// Handle error
}
@kassane
kassane / tlsf.hpp
Last active December 18, 2022 17:58
Experimental - custom allocator (TLSF)
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits>
#include <memory>
#include <vector>
// The minimum block size is the size of two pointers
constexpr size_t MIN_BLOCK_SIZE = 2 * sizeof(void *);
@kassane
kassane / asio_ntpclient.cpp
Last active July 19, 2023 19:20
Basic NTP Client (C++ asio) example
// by: Matheus Catarino França
// License: CC0
// NTP timestamp is represented as a 64-bit unsigned integer,
// in seconds since January 1, 1900.
// NTP packet format:
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@kassane
kassane / asio_libvlc.cpp
Last active December 17, 2022 19:07
VLC cli-player example - with Async C++ (Asio)
// by: Matheus Catarino França
// License: CC0
// usage: g++ -o asio_vlc asio_libvlc.cpp $(pkg-config --cflags --libs libvlc)
// STANDALONE ASIO
#include <asio.hpp>
#include <chrono>
#include <iostream>
#include <vlc/vlc.h>
@kassane
kassane / cli_player.c
Last active March 25, 2023 14:04
libVLC simple example
#include <stdio.h>
#include <stdlib.h>
#include <vlc/vlc.h>
#if defined(_WIN32) || defined(_WIN64)
#include <Windows.h>
#else
#include <unistd.h>
#endif
int main(int argc, char **argv)
@kassane
kassane / wrapper-libp11.zig
Last active December 3, 2022 16:20
Proposal - Use zig-libp11
//! libp11 is a library that provides an implementation of the PKCS#11 standard.
//! It allows software developers to access and use cryptographic tokens that are compliant with the PKCS#11 standard,
//! without having to implement the PKCS#11 interface themselves. libp11 is written in C and is available as open-source software.
//! To use libp11, a software developer would typically include the libp11 header file in their source code and link their program
//! with the libp11 library. The developer would then use the functions and data structures provided by libp11 to access and
//! manage the cryptographic functions and keys on the token.
//! Here is an example of how libp11 could be used to encrypt a message using a cryptographic token:
const libp11 = @import("libp11");