Skip to content

Instantly share code, notes, and snippets.

@tetsu-koba
tetsu-koba / 00_v4l2_capture_sample
Last active February 12, 2023 01:04
v4l2 capture sample
v4l2 capture sample
Build
$ zig version
0.11.0-dev.1594+a5d25fabd
$ zig build-exe -lc v4l2sample.zig
Run
$ ./v4l2sample /dev/video2 640 360 out.jpg
@tetsu-koba
tetsu-koba / stream_source_test.zig
Last active January 17, 2023 07:27
Zig test for std.io.StreamSource
const std = @import("std");
const expect = std.testing.expect;
const io = std.io;
fn copy(dst: *io.StreamSource, src: *io.StreamSource) !usize {
const r = src.reader();
const w = dst.writer();
const BUFSIZE = 512;
var buf: [BUFSIZE]u8 = undefined;
var len: usize = BUFSIZE;
@tetsu-koba
tetsu-koba / c2zig
Last active July 2, 2024 07:37
shell script for zig translate-c
#!/bin/bash -eu
if [ $# -ne 1 ]; then
echo "Usage: $0 <cfilename> ending '.c' or '.h'"
exit 1
fi
if [[ $1 == *.c ]]; then
OUTPUT=$(basename $1 .c)_translated.zig
elif [[ $1 == *.h ]]; then
OUTPUT=$(basename $1 .h)_h_translated.zig
else
@tetsu-koba
tetsu-koba / 00_zig_library_example
Last active December 24, 2022 06:42
Zig library example
Zig library example
@tetsu-koba
tetsu-koba / 00_udp_lib_for_zig.txt
Last active December 21, 2022 02:06
UDP client library for Zig
UDP client library for Zig
@tetsu-koba
tetsu-koba / 00_UDP_example.txt
Last active December 22, 2022 03:50
UDP connection example for Zig language
UDP connection example for Zig language
@tetsu-koba
tetsu-koba / 00_tcp_example
Last active December 19, 2022 12:43
TCP socket example of Zig language
TCP connection examples in Zig language
const std = @import("std");
const os = std.os;
const log = std.log;
const time = std.time;
const MAX_EVENT = 5;
const READ_BUFSIZE = 64 * 1024;
const WRITE_BUFSIZE = 64 * 1024;
fn createSignalfd() !os.fd_t {
@tetsu-koba
tetsu-koba / epoll_example.c
Created December 17, 2022 02:45
epoll and signalfd example in C
#include <stdio.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/signalfd.h>
#define MAX_EVENTS 5
#define READ_BUFSIZE (64*1024)
Rec and send SRT with retry