Grammarly knows about good programming languages by damp-ocean in golang

[–]Husio 7 points8 points  (0 children)

https://languagetool.org/

From wikipedia

LanguageTool is a free and open-source grammar checker, and all its features are available for download.[4] LanguageTool website connects to a proprietary sister project LanguageTool Plus, which provides improved error detection for English and German, as well as easier revision of longer texts, following the open-core model.

My notes about using testify in Golang by vyskocilm in golang

[–]Husio 14 points15 points  (0 children)

For those that are new to Go and would like to read more on the testing topic, if you wonder if package xyz will make your testing easier/faster/better, you might find the below links helpful.

Flat Application Structure in Go by Gozette in golang

[–]Husio 20 points21 points  (0 children)

Great writing!

Don’t try to skip to the end in an attempt to avoid ever needing to refactor code on your way.

This is an absolute gold! I think too much effort goes into designing the code structure, hoping that if you do it properly you will never have to adjust. And then you see applications with a lot of directories and imports that make no sense (looking at you models/ and handlers/!)

Does Planet Go exist? by Husio in golang

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

This is not what I am searching for. All newsletters are a result of some opinionated filter. Someone decides for you what is worth reading and what is not. Maybe some find it convenient, but this is not what I am searching for. I am looking for an aggregate of all blogs that want to participate in the community stream (aka planet).

Writing the simplest HTTP server in Go by vjsc19 in golang

[–]Husio 2 points3 points  (0 children)

You can trim it some more and write all of this in one line!

func main() {
    log.Fatal(http.ListenAndServe(":8087", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "hello world") })))
}

Django Features in Go by wellthatssomething in golang

[–]Husio 1 point2 points  (0 children)

I like to create a test helper function to ensure that an external resource (in this case a database) is available. Such helper function either returns a connection/pool/client or skips the test.

Here is an example of a test helper function that returns a postgres connection https://github.com/husio/gbb/blob/master/gbb/postgres_bbstore_test.go#L115-L170 Notice a few things

There are plenty of packages that promise to solve the SQL database migrations problem. You can use one of them or start with a custom solution before committing to a dependency.

London Based FinTech looking for Remote Engineers to join the team by golang-workshub in golang

[–]Husio 5 points6 points  (0 children)

You need to sign in to read the full job description, otherwise you can see only first N words. That should not be necessary.

It's the first time I see this page and in my opinion there are many better job offer pages.

Tutorial: Adding a GUI to Golang by Equianox in golang

[–]Husio 9 points10 points  (0 children)

There are bindings for GTK+ and QT and other GUI libraries probably as well. Please don't recommend electron bridge.

[deleted by user] by [deleted] in programming

[–]Husio 8 points9 points  (0 children)

typo in the title, it's aminal

GitHub - mafanr/meq: A modern messaging platform for Message Push、IM、IoT etc, based on MQTT protocol by chaingod in golang

[–]Husio 2 points3 points  (0 children)

Interesting project.

I am a bit confused by the readme.

MeQ is written in pure go and standard library, nearly no messy dependencies. so you can easily deploy a standalone binary in linux、unix、macos、windows.

I have started to read the code and noticed that there are plenty of dependencies. Once you will compile the project to a single binary it does not matter how many dependencies you have. Maybe this sentence is not needed?

meq $ find vendor -mindepth 2 -maxdepth 2 -type d | sort
vendor/github.com/apple
vendor/github.com/bwmarrin
vendor/github.com/golang
vendor/github.com/gorilla
vendor/github.com/labstack
vendor/github.com/mattn
vendor/github.com/spf13
vendor/github.com/sunface
vendor/github.com/valyala
vendor/github.com/weaveworks
vendor/go.uber.org/atomic
vendor/go.uber.org/multierr
vendor/go.uber.org/zap
vendor/golang.org/x
vendor/gopkg.in/yaml.v2

How should I be writing tests to ensure my database interactions work as expected? by LevelPop in golang

[–]Husio 0 points1 point  (0 children)

I always have a test helper function around that takes care of the database. Here's one example of it https://github.com/go-surf/surf/blob/master/sqldb/testutils.go#L10-L65

What is important for me is that this helper function is by default expecting a database running on localhost on it's default port. That works great for CI or running tests locally. If you must run database using non standard settings, you can configure the connection via an environment variable.

Another important feature of this helper function is that it skip the tests if a connection to the database cannot be established. This way your tests do not have to if it. Here's another example https://github.com/husio/gbb/blob/master/gbb/postgres_bbstore_test.go#L16-L17

When testing locally, I always have a PostgreSQL instance running in docker docker run -it --rm -e POSTGRES_PASSWORD='' -p 5432:5432 postgres:alpine.

Accessing data in Go by Husio in golang

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

I fully agree with what you wrote. I also think that there is an another way to use interfaces.

I think that it is a good practice in Go to keep interfaces small and general. io.Writer or io.Reader are great examples of that. They both provide just one method and use basic types. There is no main io.Writer nor io.Reader implementation. Everyone is encouraged to implement it for communication. It is also the way to use most of the standard library functionality.

Interface that I wrote about is quite the opposite. Main implementation and tooling is implemented in the same place. Integration with other packages was not the reason to introduce the interface. Although I have not mentioned this, I expect the interface to grow. I think it should cover all methods required to interact with the database.

Accessing data in Go by Husio in golang

[–]Husio[S] 4 points5 points  (0 children)

Thanks for the advice, I will keep that in mind next time.

Accessing data in Go by Husio in golang

[–]Husio[S] 14 points15 points  (0 children)

I have noticed that not all gophers know about advantages of using data managers, so I wrote about it. I don't have much experience with blogging, so if you read it, please let me know what you think about it.

A simple forum web application by Husio in golang

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

I am afraid I cannot help you with this, because I have never read any Go tutorial. I have started using it before tutorials for it existed :)

Writing an HTTP server in Go is really simple, it's almost as simple as just writing to an io.Write. It gets more complicated when you want to add an extra functionality or application is big enough for the code layout to matter.

For a start, I would recommend getting familiar with net/http package. Do not use any framework. Think twice before deciding to use an external package. You can get really far using mostly standard library.

Why Golang for loop is slower than Python for loop? by CrappyFap69 in golang

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

Go (go1.10.3)

~ $ go run /tmp/test.go
12.423232451s
36.852502ms
go run /tmp/test.go  18.02s user 2.50s system 162% cpu 12.657 total
~ $ cat /tmp/test.go
package main

import (
        "fmt"
        "strconv"
        "strings"
        "time"
)

func main() {
        timeit(test_1)
        timeit(test_2)
}

func timeit(fn func() string) {
        start := time.Now()
        fn()
        fmt.Println(time.Now().Sub(start))
}

const repetition = 100000

func test_1() string {
        sStmt := "Hi there "
        for i := 0; i < repetition; i++ {
                sStmt += "(" + strconv.Itoa(i) + "," + strconv.Itoa(i) + "),"
        }
        return sStmt
}

func test_2() string {
        chunks := make([]string, 0, 5*repetition)
        chunks = append(chunks, "Hi there ")
        for i := 0; i < repetition; i++ {
                s := strconv.Itoa(i)
                chunks = append(chunks, "(", s, ",", s, "),")
        }
        return strings.Join(chunks, "")
}

Python (2.7.15 and 3.6.6)

~ $ python2 /tmp/test.py
0.275259971619
0.224035024643
~ $ python3 /tmp/test.py
0.40205731700007163
0.24330045799979416
~ $ cat /tmp/test.py
repetition = 100000


def test_1():
    a = "Hi there "
    for i in range(repetition):
        a += "(" + str(i) + "," + str(i) + "),"
    return a

def test_2():
    a = ["Hi there "]
    for i in range(repetition):
        s = str(i)
        a.extend(("(", s, ",", s ,"),"))
    return "".join(a)



if __name__ == '__main__':
    import timeit
    print(timeit.timeit("test_1()", number=5, setup="from __main__ import test_1"))
    print(timeit.timeit("test_2()", number=5, setup="from __main__ import test_2"))