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 / std_log.md
Last active April 23, 2024 11:13 — forked from leecannon/std_log.md
Quick overview of Zig's `std.log`

A simple overview of Zig's std.log for Zig v0.12.0 or higher

Logging functionality that supports:

  • If a log message should be printed is determined at comptime, meaning zero overhead for unprinted messages (so just leave the code peppered with debug logs, but when it makes sense scope them; so downstream users can filter them out)
  • Scoped log messages
  • Different log levels per scope
  • Overrideable log output (write to file, database, etc.)
  • All the standard std.fmt formatting magic

Basic Usage:

@kassane
kassane / Dockerfile
Created April 1, 2024 20:14
Modm.io - C++ modern for embedded - STM32
# Based on: https://modm.io/guide/installation/
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y \
python3 \
python3-pip \
scons \
cmake \
@kassane
kassane / builtin_cnl.zig
Last active March 26, 2024 14:15
zig esp32 (espressif llvm backend)
const std = @import("std");
/// Zig version. When writing code that supports multiple versions of Zig, prefer
/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
pub const zig_version = std.SemanticVersion.parse(zig_version_string) catch unreachable;
pub const zig_version_string = "0.12.0-dev.xtensa.2858+8e52bb152";
pub const zig_backend = std.builtin.CompilerBackend.stage2_llvm;
pub const output_mode = std.builtin.OutputMode.Obj;
pub const link_mode = std.builtin.LinkMode.Static;
pub const is_test = false;
@kassane
kassane / zcc.md
Last active March 18, 2024 09:15
Zig compiler on C/C++ projects - CMake, Meson and other

Unix-like

$> export CC="zig cc $@"
$> export CXX="zig c++ $@"
...
# your build system
$> cmake or meson - commands
@kassane
kassane / Event_Loop.md
Created April 6, 2019 14:26
Explain Event Loop

Event Loop

In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program.

It works by making a request to some internal or external "event provider" (that generally blocks the request until an event has arrived), and then it calls the relevant event handler ("dispatches the event").

The event-loop may be used in conjunction with a reactor, if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling).

The event loop almost always operates asynchronously with the message originator.

@kassane
kassane / main.zig
Last active February 16, 2024 20:14
zig build to PSVita target
// replacing https://github.com/vitasdk/samples/blob/master/hello_world/src/main.c
const c = @cImport({
@cInclude("psp2/kernel/processmgr.h");
@cInclude("psp2/kernel/threadmgr.h");
@cInclude("stdio.h");
@cInclude("debugScreen.h");
@cDefine("printf", "psvDebugScreenPrintf");
});
pub export fn main() c_int {
#!/bin/bash
## A script to install Funtoo Linux on a computer.
####---------------------------------------------####
export PS1="(chroot) $PS1"
echo Downloading the portage tree...
ego sync
emerge --sync
@kassane
kassane / gdextension_interface.zig
Last active December 29, 2023 17:13
Godot 4 - GDExtension for zig bindings
// GDExtension - zig (v0.11.0 or master) binding
// cmd: godot --dump-gdextension-interface -q --headless
// based on: https://github.com/godot-dlang/godot-dlang/blob/master/gdextension_interface.h
const std = @import("std");
pub const GDExtensionVariantType = enum(c_uint) {
GDEXTENSION_VARIANT_TYPE_NIL = 0,
GDEXTENSION_VARIANT_TYPE_BOOL = 1,
GDEXTENSION_VARIANT_TYPE_INT = 2,
GDEXTENSION_VARIANT_TYPE_FLOAT = 3,
module intrusive_mpsc_queue;
import core.atomic;
// An intrusive MPSC queue in D.
struct IntrusiveQueue(T)
{
private T* head;
private T* tail;
private T stub;

Named arguments in D language

DIP1030

Named/labeled/keyword arguments are useful in Python and OCaml, but in the D language they were proposed by DIP1030 and adopted three years ago.

Currently, templates are not supported, but recent DMDs -preview allow you to try out these features without any flags. The verification environment this time is DMD2.106.0.