zig-cookbook icon indicating copy to clipboard operation
zig-cookbook copied to clipboard

New recipes from other awesome cookbook

Open jiacai2050 opened this issue 1 year ago • 4 comments

Some examples I find:

  • https://github.com/dabeaz/python-cookbook
  • https://golangcookbook.com/

jiacai2050 avatar Jan 15 '24 00:01 jiacai2050

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 avatar Jan 15 '24 02:01 horochx

@horochx Those two example seems too simple for me, I don't know if it's necessary to add them.

jiacai2050 avatar Jan 15 '24 11:01 jiacai2050

@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!

rakshasha-medhi avatar May 19 '24 00:05 rakshasha-medhi

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.

jiacai2050 avatar May 30 '24 04:05 jiacai2050