zig-cookbook
zig-cookbook copied to clipboard
New recipes from other awesome cookbook
Some examples I find:
- https://github.com/dabeaz/python-cookbook
- https://golangcookbook.com/
I will add an example in 15. Text Processing similar to the Turning an Array into a Sentence and Processing a String One Word or Character at a Time in the Go Cookbook.
@horochx Those two example seems too simple for me, I don't know if it's necessary to add them.
@jiacai2050 I'm currently learning Zig and I got quite a collection of Zig code snippets...however how to know if something is too simple? I mean I've been struggling to find reference to learn Zig, hence I made the snippet collection...and I think this Zig cookbook is gonna be amazingly helpful for Zig newcomers.
For example i see there's Generate Random Numbers in the cookbook already, but it's using crypto.random. I have snippet that uses rand.DefaultPrng:
const RndGen = std.rand.DefaultPrng;
const tMilli = std.time.milliTimestamp;
const PageAlloc = std.heap.page_allocator;
fn gen_randNum(minVal: u32, maxVal: u32, arraySize: u32) ![]u32 {
var seed = tMilli();
var rnd = RndGen.init(@intCast(seed));
var randNums = try PageAlloc.alloc(u32, arraySize);
for (randNums) |*num| {
num.* = rnd.random().intRangeAtMost(u32, minVal, maxVal);
}
return randNums;
}
I also got plenty of Sorting and Search Algorithms written in Zig.
To be honest I have been looking for an avenue to contribute to Zig learning for newcomers...so I would love to be involved in the Zig Cookbook. Cheers!
but it's using crypto.random. I have snippet that uses rand.DefaultPrng
I don't see much difference between those, so I would suggest you try another recipe, thanks.