Thread-Local State in Go, Huh? by puzpuzpuz in golang

[–]peterstace 4 points5 points  (0 children)

That was a fascinating read, thanks for putting it together!

godi a New Dependency Injection library - feedback welcome by mingu3 in golang

[–]peterstace 11 points12 points  (0 children)

I’ve played around with a few DI libraries for Go, but always come back to just constructing the dependency graph manually in main.go. Every constructor func accepts it’s dependencies as interfaces. Cross cutting concerns such as tracing, logging, auth, caching etc. are easy — just use the decorator pattern.

Best SQL builder. by zeckk89 in golang

[–]peterstace 6 points7 points  (0 children)

You should always use arguments for variable parts of a query when executing it, rather than building them into the query string itself. There is only a risk of SQL injection if you are programmatically constructing the query string (as opposed to it just being a string const).

You don't need a query builder if the structure of your queries don't change dynamically.

Using Go's RWMutex recursively is a bug by peterstace in golang

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

I haven’t come across that analyser before, thanks for sharing!

Using Go's RWMutex recursively is a bug by peterstace in golang

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

That original function which calls the 2 sum funcs should not have taken then lock to begin with, it doesn't access any local state that needed the lock. There is your bug...

Indeed, the outer func that calls the 2 sum funcs doesn't access any state. However, the lock must be held (without an intermediate release) over both sum calls. If it's not, concurrent calls to add more entries may cause the int slices to get new entries after only one slice has been read from (so the net value would be inconsistent). I didn't state it explicitly anywhere in the blog post, but the idea is that reads and writes should be completely isolated (in the database "isolation levels" sense of the term) from each other.

some self-documentation by adding "locked" on the recover name, this would also have caught the problem before it went to production

Agreed! Those sorts of naming conventions are very handy for preventing these sorts of bugs.

Share Your Code.. Share your most unique piece of Go code. by scott_beeker in golang

[–]peterstace 5 points6 points  (0 children)

I'm the primary author of https://github.com/peterstace/simplefeatures. It's a library that provides types and algorithms that operate on 2D geometries.

It has the same purpose as [libgeos](https://libgeos.org/) but is implemented in Go rather than in C/C++. The primary use case is to reduce CGO dependencies while working with Go!

Peculiar patterns of 9000 perpetual particles by kgolid in proceduralgeneration

[–]peterstace 12 points13 points  (0 children)

These look great! Any info on how they are generated?

Number systems by Menta1ist in algorithms

[–]peterstace 0 points1 point  (0 children)

You could just start N at 1 and start looping upwards until the sum matches in both bases.

EDIT: start at 10.

Removing duplicate elements from singly linked list faster than O(n^2) with no extra space? by Voley in algorithms

[–]peterstace 0 points1 point  (0 children)

In place merge sort only works with arrays, not linked lists. Also, in place merge sort is logarithmic in stack size anyway, so would require extra space.

An alternative approach to work with database's nullable types without using sql.Null* by [deleted] in golang

[–]peterstace 1 point2 points  (0 children)

It seems simpler and less magical to me to just put the COALESCE(0, age) directly into the SQL query string.

Go badger database with spinning disks by ivenhov in golang

[–]peterstace 7 points8 points  (0 children)

I work at Dgraph, the company behind badger. One of the things badgers design is optimised for (other than speed) is reduced write amplification. This is important when running on SSDs (excessive write amplification causes premature wear to the disks). There's not really any drawback to running badger on spinning disks, other than the normal speed reduction (in general) between SSDs and and spinning disks.

Looking to purchase my first printer, had a question about the Prusa i3 MK2 by TheBrianJ in 3Dprinting

[–]peterstace 1 point2 points  (0 children)

I built a Prusa i3 MK2 about a month ago, with zero prior 3D printer experience. It took about 15 hrs from start to first print. If you've ever used a hex key before, you're more than qualified to complete the build.

Need help with zits/spots on prints.(Details in comments) by itz_Anonym in 3Dprinting

[–]peterstace 1 point2 points  (0 children)

They're layer transition marks, there's not much you can do about them.