This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Single consumer, single producer circular buffer using Win32 SRW | |
// Ref: https://github.com/vibhav950/cbuf | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1jwnlrf | |
// Ref: https://nullprogram.com/blog/2024/10/03/ | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <string.h> | |
typedef uint8_t u8; | |
typedef int32_t b32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!profile claude | |
!user | |
Please give me an example of using WASI `path_open` to open a file for writing. In particular, I don't know where to get the `dirfd` parameter. | |
!assistant | |
# Example of using WASI `path_open` to open a file for writing | |
The WASI `path_open` function requires a directory file descriptor (`dirfd`) as its first parameter because WASI uses a capability-based security model. Here's how to use it: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Robust Lock: if a "thread" exits while holding a lock, it is unlocked | |
// linux $ cc -pthread example.c | |
// w64dk $ cc example.c -lntdll | |
// Ref: https://old.reddit.com/r/C_Programming/comments/1jd82ux | |
// Ref: https://github.com/cozis/timestamp_lock | |
// This is free and unencumbered software released into the public domain. | |
#include <assert.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://old.reddit.com/r/C_Programming/comments/1iljkn2 | |
// https://github.com/jamesnolanverran/dmap | |
#include "dmap.c" | |
#include <string.h> | |
#define KEYLEN 8 | |
#define RUNS 10 | |
#define KEYS 1000000 | |
static void encode(char *key, int x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Input: | |
// A number N, representing the size of the square board grid. N rows of | |
// N characters each, where each character is either R (red) or A (blue). | |
// | |
// 2. Objective: | |
// Rearrange the rows of the board to maximize the area of the largest | |
// contiguous rectangular zone for each color (R for The Famous, A for | |
// The Warriors). | |
// | |
// Determine the winning team based on the larger rectangular area of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Examples of quick hash tables and dynamic arrays in C | |
// https://nullprogram.com/blog/2025/01/19/ | |
// This is free and unencumbered software released into the public domain. | |
#include <assert.h> | |
#include <stdarg.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question 2: Steganography using 4-bit LSB algorithm | |
Scope: File Processing, Pointers, Dynamic Memory Allocation (No arrays) | |
File to use: stego_lsb.c | |
Preliminary: | |
This question should be solved using dynamic memory allocation along with | |
pointers. Any submitted work which includes an array will be given | |
automatically a zero mark. To view pgm files, you can use the “Irfan View” |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t)) | |
#define S(s) (Str){(uint8_t *)s, sizeof(s)-1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Slim Reader/Writer Condition Variable Demo / Test | |
// $ cc -nostartfiles -o main.exe demo.cpp | |
// $ cl /GS- demo.cpp /link /subsystem:console kernel32.lib | |
// This is free and unencumbered software released into the public domain. | |
#define assert(c) while (!(c)) *(volatile i32 *)-4 = 0 | |
using b32 = signed; | |
using i32 = signed; | |
using uz = decltype(sizeof(0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quick test of environment variable passing | |
// $ cc -nostartfiles -o testenv testenv.cpp | |
// $ cl testenv.cpp /link /subsystem:console kernel32.lib | |
// | |
// Spawns a copy of itself with a custom-built environment block, and | |
// the spawned child examines/probes that block. | |
// | |
// This is free and unencumbered software released into the public domain. | |
typedef int I; |
NewerOlder