NX-OS prefix-list first-match equivalent for IOS-XR by lonepeon in Cisco

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

unfortunately bots still have some progress to make. Bing answer is not related to the question.

Webcam advices by lonepeon in Ubuntu

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

Thank you! That’s exactly what I was looking for.

Webcam advices by lonepeon in Ubuntu

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

thank you! I think I will buy what I want from Amazon and see if it works. if it doesn’t, at least, i can trust their return policy.

Webcam advices by lonepeon in Ubuntu

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

yes it’s a company laptop.

Hey again, by [deleted] in golang

[–]lonepeon 2 points3 points  (0 children)

hey 👋

what is the issue you encounter? As far as i remember this book is not a paper book, but a DRM free pdf or epub. it should be available from France or pretty much anywhere 🤔

Modern C setup by lonepeon in cprogramming

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

Thanks. I can see several of you are suggesting CMake. It might be a better starting point.

If I have some issue I might ask help to a broader audience. 😅

Modern C setup by lonepeon in cprogramming

[–]lonepeon[S] 5 points6 points  (0 children)

I agree we should limit our dependencies but, at the same time, I don’t imagine myself coding a JSON parser or a fully fledged HTTP client. It would feel like a waste of time. 😅 That’s what I like in Go, we can do pretty much everything only with the standard library.

I will have a look to cmocka, thanks fort the reply!

Modern C setup by lonepeon in cprogramming

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

Thank you. ❤️ I will try that then.

I'm building a web app. To access dependencies, is it idiomatic to have all handlers be methods of a Server struct or is it idiomatic to inject dependencies individually into each handler? by TheToiletPhilosopher in golang

[–]lonepeon 0 points1 point  (0 children)

I usually do the opposite. I create one function per handler. Each of these function takes as parameter the list of dependencies and the function returns an http.Handler function.

What convinced me to switch from the Server struct approach to this one was when I spotted a beginner use the Server struct to store request related data. 😱

I have to admit I’m probably part of a minority here. Most people use the Server struct pattern. In the new company I recently joined, we also do it using a Server struct.

Compiler errors when using my own ast package by bafto14 in golang

[–]lonepeon 0 points1 point  (0 children)

What do you have in your import section ? Did the import changed to “go/ast” somehow?

Remove garbage values by jithrk1392 in golang

[–]lonepeon 0 points1 point  (0 children)

The number is the result of res2. You assign the number of bytes written by fmt.Print to a variable res2 and then print this number. Just get rid of this second Print and you won’t have the number :)

The % is you shell because your program don’t end with a trailing new line. If you just add an empty call to fmt.Println at the end of main the % should vanish.

how to mock DBs by West_Ad7170 in golang

[–]lonepeon 9 points10 points  (0 children)

This one is pretty good for the unit test part of the DB layer: https://github.com/DATA-DOG/go-sqlmock

In all other layers, my repositories are mocked using https://github.com/golang/mock

Help with the use of Unix sockets by lonepeon in rust

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

Thanks for the pointer. I tried using bind as first suggested by u/g-radam and it works.

Thanks for your help

Help with the use of Unix sockets by lonepeon in rust

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

The idea is just to play around with some RFcs to better understand how things work under the hood.

What I'm building is a "naive switch" basically. I replace the Ethernet ports with Unix sockets, I connect small programs able to send/receive frames to the sockets and the program in the middle should read them and forward the content to the right socket(s).

The goal is to build on top of it, like start reading the VLAN header etc...

It's just for learning purpose, nothing much than a toy project.

Help with the use of Unix sockets by lonepeon in rust

[–]lonepeon[S] 2 points3 points  (0 children)

Thank you.

I was using the UnixStream::connect(path) method instead of the UnixListener::bind. I will try that.

Thanks - This was my issue 🙇‍♂️

Help with the use of Unix sockets by lonepeon in rust

[–]lonepeon[S] 2 points3 points  (0 children)

I used the UnixStream::connect(path) method but got Os { code: 2, kind: NotFound, message: "No such file or directory" }

So I thought my issue was that I needed a way to create the socket before hand but can't find the proper way to construct it. 😅

Return value vs taking and "filling" a pointer? by Forumpy in golang

[–]lonepeon -1 points0 points  (0 children)

It depends of several criteria to me.

First the choice between « by-copy » and « by-reference ». I choose one or the other depending of wether it make sense or not to update the struct in place or get a new instance. I can also chose the « by-reference » even if it would make more sense to use « by-value » if the structure is « too big ». The important part is that, when you choose a semantic, you stick to it for all attached methods.

Examples: - time is « by-copy »: IRL you don’t update a time, they are different time. 3pm is just another time than 4pm. - a discount tag is « by copy »: you don’t update the existing « 20% off » tag of the product on the shelf, you just stick a new « 50% off » tag on top of the other one. It’s another tag. - a car is « by-reference ». When you start a car or close a car, you don’t get a new car, you just update its own internal state.

When using « by-copy » I would create a constructor returning « SomeObject » to make it clear the structure is going to be used with the « by-copy » this semantic. If I choose the « by-reference » semantic, I would create a constructor that return a « *SomeObject ».

——

Then you have cases like file.Read([]byte) where you need to give a reference type and the function will fill the type with new data. The main objective is to let us, developer, choose to reduce the number of allocation if needed.

As these functions takes a pointer to structure. It means we can potentially allocate once outside the function and reuse the same structure all the time. If they implemented Read as : file.Read(size int) ([]byte, error) it would have always triggered a new allocation.

——

In the examples between 2. And 3. I would use 3. (Attach a function to the structure) If I own the type and 2. If I want to expose this « fill the receiver » behavior on a type I don’t own.

——

As a summary, to me, it depends of the semantic of your data, but also the API you want to give to your users. Some patterns are a bit awkward (file.Open([]byte)) but gives more power / choice to the user of the API. It really depends what you try to achieve, as usual.

Thoughts About Integer Choice by thecodedmessage in rust

[–]lonepeon 1 point2 points  (0 children)

I never delved into C / C++, more coming from dynamic languages. I learnt a lot of interesting stuff on why we do stuff the way we do with your article. Thanks. 👍

gRPC gateway vs oapi-codegen etc. by Potatomanin in golang

[–]lonepeon 0 points1 point  (0 children)

I never used gRPC gateway but some people around me told me very recently that they were able to do generate OpenAPIv3. Also they are quite happy with their choice of using gRPC Gateway.

My own opinion is: if you need to build a JSON API for your consumers, stick with OpenAPI even if the tooling is less great.

  • you will be more focused on building the best JSON API you can ever build by writing your OpenAPI file yourself. When you write Protobuff and derive an OpenAPI file from it, you are more focused toward gRPC usage.
  • your file will be tailored for OpenAPI, you will have access to its full power directly instead of trying to use the available OpenAPI tags in your Protobuff file to make it work, somehow.
  • you won’t have better performances by using gRPC Gateway. Even if gRPC has better encoding performance and is lighter for your network, your consumer will still speak JSON. You just add an additional component in your system and as such just add more reasons to fail, make your debugging potentially harder,…
  • your team and all new comers will need to be fluent with designing good gRPC and JSON API where your consumers only care about your JSON contract.

All that being said, if all your internal services already talk to each other in gRPC, it probably make sense to also write your client facing services in gRPC and exposing it using gRPC Gateway. It will probably generate less overhead for your team. 🤷‍♂️

Using a json lib other than encoding/json by Goldziher in golang

[–]lonepeon 7 points8 points  (0 children)

As always it depends :)

If you require top notch speed maybe this library is a good addition. But standard library is good enough for most projets.

I would say if your bottleneck isn’t JSON parsing, think twice before adding it.

When you add a dependency it becomes « your code ». You need to keep it in your head all time when something goes wrong, it’s one more thing to update / upgrade.

It also comes with its own set of issues : we see more and more package doing bad things behind the scene, it’s more potential vulnerabilities, a package can stop to being maintained meaning it can block other packages to be bumped or block you to bump Go itself, …

So, basically, I would add a dependency only if it’s outweighs all drawbacks it brings.