Skip to content

Instantly share code, notes, and snippets.

View jackdbd's full-sized avatar

Giacomo Debidda jackdbd

View GitHub Profile
@jackdbd
jackdbd / cairo-singular.c
Created January 23, 2021 14:40
Singular values cairo example
/**
* Uses Singular values of transformation matrix to find the length of the
* major and minor axes of the scaled pen.
*
* Found in the cairo tutorial
* https://github.com/freedesktop/cairo/tree/6a6ab2475906635fcc5ba0c73182fae73c4f7ee8/doc/tutorial/src
*
* Dependencies:
* - cairo: sudo apt-get install libcairo2-dev
*
@jackdbd
jackdbd / leak.zig
Created January 21, 2021 22:38
Memory leak example with different Zig build modes
//! Memory leak example with different Zig build modes.
//!
//! The program does not compile because zig detects a memory leak:
//! zig build-exe leak.zig -O Debug && ./leak
//! zig build-exe leak.zig -O ReleaseSafe && ./leak
//!
//! The program compiles, but there will be undefined behavior:
//! zig build-exe leak.zig -O ReleaseSmall && ./leak
//! zig build-exe leak.zig -O ReleaseFast && ./leak
//! See also:
@jackdbd
jackdbd / integer_overflow.zig
Last active April 16, 2023 14:36
Integer overflow with custom integer in Zig
//! Integer overflow with custom int in Zig
//! build and run with:
//! zig build-exe integer_overflow.zig && ./integer_overflow
const std = @import("std");
pub fn main() void {
std.log.info("unsigned int (primitive type) [0, 7)", .{});
// usize is an unsigned pointer sized integer. See also: https://github.com/ziglang/zig/issues/5185
// usize is a primitive type:
// https://ziglang.org/documentation/master/#Primitive-Types
@jackdbd
jackdbd / xcb.zig
Last active January 18, 2024 14:29 — forked from NBonaparte/xcb.zig
Minimal XCB + Cairo example in Zig
//! Minimal XCB + Cairo example in Zig
//! Dependencies: libc, xcb, cairo
//! install XCB development files
//! sudo apt-get install libxcb1-dev
//! install cairo development files
//! sudo apt-get install libcairo2-dev
//! build and run with:
//! zig build-exe xcb.zig -lc -lxcb -lcairo && ./xcb
const std = @import("std");
const c = @cImport({
@jackdbd
jackdbd / reflection.zig
Last active April 11, 2023 09:00
Function reflection in Zig
//! Example of function reflection in zig.
//!
//! 1. Compile this gist
//! zig build-exe reflection.zig -O Debug && ./reflection
//!
//! 2. Run the tests
//! zig test reflection.zig
const std = @import("std");
const Hello = struct {
@jackdbd
jackdbd / hello_wasi.zig
Last active January 23, 2021 14:45
Zig program running on wasmtime (WASI runtime)
//! Example of using the zig standard library and reading command line arguments.
//! https://ziglang.org/documentation/master/#WASI
//! See also the talk Zig loves WASI! by Jakub Konka
//! https://www.youtube.com/watch?v=g_Degmqfo4Q
/// In order to run this example you will need a WebAssembly runtime such as wasmtime.
/// https://wasmtime.dev/
/// 1. compile the wasm module with the zig compiler
/// zig build-exe hello_wasi.zig -target wasm32-wasi
/// 2. run the .wasm module with wasmtime and pass the command line arguments

Keybase proof

I hereby claim:

  • I am jackdbd on github.
  • I am jackdbd (https://keybase.io/jackdbd) on keybase.
  • I have a public key ASBqZ9eR47yxI8eZ6ESHGOTIRaafg_TzBwlo5KIcNQJOFQo

To claim this, I am signing this object: