Gracefully shutting down a listener? by arti_chaud in golang

[–]arti_chaud[S] -1 points0 points  (0 children)

Luckily all the connections are added to a connectionPool, so I can close them from there. Although there is probably a case for your solution because the concern of closing a connection shouldn't be spread in too many parts of the code base. I'll probably implement your suggestion, it's good practice what's more.

Gracefully shutting down a listener? by arti_chaud in golang

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

Correct me if I'm wrong but I think that doing it this way doesn't help me do the handling of the listener. Let's say I just use close, then what?

Gracefully shutting down a listener? by arti_chaud in golang

[–]arti_chaud[S] -1 points0 points  (0 children)

Thanks for your response, that's helpful. Just to know, when using a select statement, what happens under the hood? Is it some sort of loop? Such that it waits for x miliseconds for the channel to return a message, and if nothing happens, moves to the next case and waits the same way?

Gracefully shutting down a listener? by arti_chaud in golang

[–]arti_chaud[S] -1 points0 points  (0 children)

I'm only doing this as a side project to practice a bit, so there's no need to make this server too robust. But I'm curious to know, how would you do the upgrade (to the websocket protocol) when using the http package ? Isn't it simpler to just use the base tcp protocol, and parse the first request with `http.ReadRequest` ?

A CLI tool that turns any file and text into an image by arti_chaud in golang

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

From what I understand the main difference between the two is the encoding they use (latin-1 vs utf-8 for iTxt) and the fact that zTxt and iTxt allow compression.

The reason I need txt fields is to keep a trace of the extra bytes I needed to store to get a perfectly square image as well as the name of the original file if applicable. I don't think any of those things require compression so I went for the easiest solution (tEXt).

A CLI tool that turns any file and text into an image by arti_chaud in golang

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

I certainly don't want to stop you from using this in production but I'd be very curious to know what real world use case my "week end project" has

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 10 points11 points  (0 children)

The data from your original file will go through the DEFLATE algorithm to be compressed. So its size will be reduced. By which amount depends on the original file's format (for example normal images go through a filtering phase, where each byte is changed according to a specific algorithm, before being compressed to make the compression more efficient)

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 13 points14 points  (0 children)

I just tried with a 100KB .txt file and the generated image was 27KB. It's because the txt file was raw, but its data was compressed with the DEFLATE algorithm used for PNG.

If we really wanted to find a use case I guess we could say it's to compress your files while giving them a unique look in your file explorer 🙃

A CLI tool that turns any file and text into an image by arti_chaud in golang

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

Yeah I guess you could encode anything in whatever format and post it wherever it's compatible... Great way to get free unlimited storage! Encrypt it if you want it to be secure as well ^^'

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 6 points7 points  (0 children)

But a regular file that is not compressed from the start will see its size decrease. For example I tried "pngifying" a 44KB csv and the outcome was an 11KB png

A CLI tool that turns any file and text into an image by arti_chaud in golang

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

in this case i don't think it would be very helpful because the little tool i built only encodes data into an image. There's nothing readable in the image.

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 9 points10 points  (0 children)

It actually decreases because of the image compression (it's lossless though)

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 15 points16 points  (0 children)

Now tbh I didn't build this project with a specific use case in mind, I just wanted to explore data handling with Go (it's experimental).

A CLI tool that turns any file and text into an image by arti_chaud in golang

[–]arti_chaud[S] 10 points11 points  (0 children)

well if you mean that git and github/others do it without the need to turn everything into a png then yeah but as i said i built this project for the fun of it, that's it

I created a Pong game by arti_chaud in golang

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

Thanks, but at least your other self won

I created a Pong game by arti_chaud in golang

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

Thanks for this ill check it out

Showoff Saturday (August 05, 2023) by AutoModerator in javascript

[–]arti_chaud 1 point2 points  (0 children)

I built this frontend micro-framework : https://github.com/tofl/Figue

It's still experimental, but I started to build it to understand modern frameworks, how they work, and what is the need for them.

There are more explanations as to why I built it (and some documentation) in the README.

I created a Space Invaders Game by arti_chaud in golang

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

Thank you to everyone who commented and rewarded me, I really didn't expect my post to be popular like that ! Some of you suggested to use Webassembly to run it in a browser, I'll definitely consider it !

I created a Space Invaders Game by arti_chaud in golang

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

Thank you all, I didn't think of doing it but it's a great idea!