Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Matheus C. França kassane

🏠
Working from home
View GitHub Profile
@kassane
kassane / zig_cpp-modules.md
Last active February 19, 2023 13:51
Zig/clang++ (C++20) modules
View zig_cpp-modules.md
// main.cpp

import moduleTest;

#include <cstdio>

auto main() -> int
{
View bl808.zig
const micro = @import("microzig");
const mmio = micro.mmio;
pub const devices = struct {
/// Bouffalo BL808 chip
pub const BL808 = struct {
pub const properties = struct {
pub const license =
\\
\\Copyright (c) 2022 Bouffalo Lab
@kassane
kassane / forth.zig
Last active January 2, 2023 13:55 — forked from MasterQ32/forth.zig
Zig Comptime Forth
View forth.zig
//! 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 / sample.c
Last active December 28, 2022 20:48 — forked from batiati/sample.c
TigerBeetle C & C++ sample
View sample.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
#include "tb_client.h"
/////////////////////////////////////////////////////////////////////////////////////
// Place this file at the same folder tb_client.h //
// Shows the basic usage of the TigerBeetle C client. //
@kassane
kassane / check_cpu_version.cpp
Last active December 22, 2022 13:39
Check architecture version to x86_64 CPU - written on C++
View check_cpu_version.cpp
// 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
View client.cpp
#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)
View tlsf.hpp
#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 December 18, 2022 14:33
Basic NTPClient (C++ asio) example
View asio_ntpclient.cpp
// 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)
View asio_libvlc.cpp
// 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 December 11, 2022 16:45
libVLC simple example
View cli_player.c
#include <stdio.h>
#include <stdlib.h>
#include <vlc/vlc.h>
int main(int argc, char **argv)
{
libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;