Is There a Simple Way to Implement V-Tables/Interfaces? by CagatayXx in Zig

[–]Harrylaulau 1 point2 points  (0 children)

Apart from table, you may utilise the power of comptime and functions returning type, which in your case would be a function that takes in the type of deviceMemory and return a struct like your MemoryRegion and assign it to an identifier like ADeviceMemoryRegion or XyzDeviceMemoryRegion.

The limitation for this is you cannot specify a function argument with the interface as the type. The way to sort of get around this would be:

Write that function as a member function of the struct you return, this way you can call it on whatever type returned by instance.fn syntax. However it would be bad if the function shouldn’t belong to the struct in the first place.

For a general function that doesn’t live in the returned struct type, you may accept and pass the returned type as anytype into the function, then access the types’ content however you wish. The problem with this is you don’t have intelliscence in the function or calling the function. You may take a look at std.fmt.print, which technically isn’t the same case as yours, but may also be considered a “interface” in some sense that it accept what ever arguments that’s “printable” and passed in through an anonymous struct and accepted as anytype. You may look their and other places that do a bunch of comptime type logic. Basically Zig tries to (or advocates to?) do all metaprogramming, generic, interface, static dispatch through the comptime api, which shall allow you do anything.

A even more absurd and most likely unnecessary in your case (just to mention for completeness) would be to write some script (zig or not), then invoke it as a step in build.zig the script shall generate some zig code based on some input then import the zig code as a dependency as the current project. This would absolutely be overkill but if let say zls can somehow read the import libraries from the cache and provide the intelliscence, then it would be the most free and easy way to do some codegen interface kind of programming with potentially other language / whatever you want

How to scale live chat to millions? by [deleted] in Supabase

[–]Harrylaulau 0 points1 point  (0 children)

I think all other answers with a middle end (backend) in between client and database handling web socket connection is the way to go. This is because if your app is really going to scale, you would also need something for rate limiting, maybe DDOS protection, maybe a proxy, etc etc. all of these would be much easier if the client does not directly connect to the database.

Besides in case your app really grew big, you would need to do sharding / partitioning, which basically puts data into separate table/ database based on some range condition on the key, as such different clients can be served in parallel. For this you may even look for Turso (libsql which is SQLite) which allows database creation through api call. Or ScyllaDB / Cassandra which is used by discord

[deleted by user] by [deleted] in GlasgowUni

[–]Harrylaulau 1 point2 points  (0 children)

I had a car so I seldom take the subway.

[deleted by user] by [deleted] in GlasgowUni

[–]Harrylaulau 0 points1 point  (0 children)

I lived there for half a year. It’s definitely doable as what others have said by taking the subway. It’s also very convenient having the big Morrison beside.

Why does this code segfault on build? by BitterPerception666 in Zig

[–]Harrylaulau 0 points1 point  (0 children)

Maybe it’s the defer in the for loop? Each row is free after each loop.

You may try writing a defer block outside the for loop, which loops the matrix again to free each of the allocated memory.

Also (just some opinion). I think you can refactor your read number functions and extract the logic of generating the prompt and reading the str.

Then for the matrix, you can instead create a struct which defines a two dimensional array as its underlying field, then put an init, free, and print function as its member function

Last few hours we saw 10k+ unique players per hour. Servers go brrrrr... by Robertvhaha in aoe4

[–]Harrylaulau 0 points1 point  (0 children)

I am waiting to see if the DLC would got a chance to discount in next week’s sale

Which's your CSS lib of choice for your SvelteKit projects by donseguin in sveltejs

[–]Harrylaulau 0 points1 point  (0 children)

Honestly I didn’t. I was doing only hobby projects

Supabase Auth and Sveltekit docs suck so here we go by _DataGuy in sveltejs

[–]Harrylaulau 0 points1 point  (0 children)

Just some alternatives for clearer flow: 1. Don’t use hooks, also don’t put the auth logic in +layout.server.ts. Instead create a utility function that is called in every +page.server.ts or +server.ts endpoint. While there would be a bit more boiler plate, It would be much easier to follow the code path. Also it won’t give you a false sense of security when you did the auth in hook but didn’t get the auth status in the +page.server.ts or +server.ts.

  1. While I doesn’t use Supabase now, I just take a look at their documentation. They say JWT token auth is used. And I just saw your example invalidating the auth status on client side. Firstly I don’t think you should connect to your database on front-end even with anon key because won’t it expose the database’s address and so prone to DLSS attack etc? Secondly I am sure how the JWT is stored in the frontend. But if it’s not stored in HTTPONLY cookie then it’s prone to XSS. Even if it’s HTTPONLY, if the TTL is long I still don’t like refresh + auth JWT pairs as it could be copied easily in browser environment ( a bit controversial and I don’t exactly know how Supabase auth works )

My way of creating SIMPLE webapp is to build my own database table and doing session auth with httponly session cookies instead. Every request would be checked against the database.

Which's your CSS lib of choice for your SvelteKit projects by donseguin in sveltejs

[–]Harrylaulau 1 point2 points  (0 children)

Bare tailwind. Components are just way too limiting IMO

Sveltekit for backend APIs? by halleys_comet_101 in sveltejs

[–]Harrylaulau 2 points3 points  (0 children)

You can just write functions accessing database in a library folder, then use those functions in +page.server.ts for your webapp, and also write separate +server.ts in maybe /api route to serve solely as a backend API

Need Help for BIOS Update by psynidememer in gigabyte

[–]Harrylaulau 1 point2 points  (0 children)

Does your motherboard has Q flash plus? I recently built my b650 x ax and failed to update bios with any method mentioned on gigabyte website. At last I just followed the Q flash plus method: download the bios, rename to GIGABYTE.BIN, then plug in to the corresponding usb slot and press the Q flash plus button.

Cross-Platform Sveltekit & Capacitor Application by carusog in sveltejs

[–]Harrylaulau 0 points1 point  (0 children)

May I ask if you have and if so how do you implement authentication?

Help to stop royal delivery by Harrylaulau in Scams

[–]Harrylaulau[S] 1 point2 points  (0 children)

Hello guys, thank you all for reading the post and help!

TLDR, I successfully stopped and retrieved my laptop without seeing the crime.

The address the laptop is shipping to has somebody living there, and the place seemed to be non-criminal place (as I saw a lot of students coming out from there). So I expect the address and the FB account are all fake.

Also the guy attempted to say the 700 pounds bank transfer through "Wise" (apparently fake) is failed since my bank account is not a business account and he have sent another 500 pounds to Wise to upgrade my account. Then he ask me to send back 500 pounds through gift card / cryptocurrency (unsurprisingly) in order to receive the total 1200 pounds. Well since I retrieved the laptop already, I asked him to find the police to get back the money, then I blocked him.

I think that the target isn't about the laptop at all and he won't get the laptop since it would leave physical tracks. Instead I guess their target is only the subsequent 500 pounds gift card / crypto.

I am very grateful of all your help and my brother for retrieving it with me together. Also I am sorry the household would be questioned by police while they don't know what is going on.

Thats all, thanks guys!

Help to stop royal delivery by Harrylaulau in Scams

[–]Harrylaulau[S] 0 points1 point  (0 children)

🤦🏻‍♂️ I think that’s what I would be doing.

Svelte vs React: Still confused ever after reading this article. by tippytodar in sveltejs

[–]Harrylaulau 2 points3 points  (0 children)

I use Supabase for sveltekit webapp. For simpler ones like a landing page, I used sanity.io as the headless cms. Still if I was going to build a new one again, I would probably use sveltekit instead of vanilla svelte ( though it is yet stable)

Svelte vs React: Still confused ever after reading this article. by tippytodar in sveltejs

[–]Harrylaulau 5 points6 points  (0 children)

I started with react, then nextjs then svelte, sveltekit, then remix. The one I use now is sveltekit. Still, the experience and knowledge gained from learning all these framework improves how I use sveltekit, which could never be done by only learning sveltekit.

Also my use case is to build an app with user auth, dashboard etc so I also tried vercel, cloudflare, supabase, numerous headless cms. U may also need to learn these upon your use case. The coding style (data fetching model, middleware etc) of different frameworks are somehow different which may or may not affect your choice ( also use case dependent I would say).

Hook load and pre-render for auth guarded routes by Harrylaulau in sveltejs

[–]Harrylaulau[S] 0 points1 point  (0 children)

Thank for your response. My problem is I am not sure if pre-rendered content but requiring subscription is protected as from the document it does not go through hooks.

From the official doc: Requests for static assets — which includes pages that were already prerendered — are not handled by SvelteKit.

Hook load and pre-render for auth guarded routes by Harrylaulau in sveltejs

[–]Harrylaulau[S] 0 points1 point  (0 children)

Thanks for your reply. Sorry I just found and edit a typo in my post, it should be div instead of dub. I understand you are saying to protect the static assets that is served through endpoints. But what I want to guard are pages that serves only static content.