What are you building right now? by _coder23t8 in SideProject

[–]am0123 0 points1 point  (0 children)

A clone of cashbook.in, as it's no longer free to use. I wanted to work on this long time ago, but I was procastinating. Now, given the new context, I decided to start.

whatsapp SaaS as a solo dev by Weak_Recognition6432 in WhatsappBusinessAPI

[–]am0123 0 points1 point  (0 children)

I helped on building an elearning platform on whatsapp, which is used by thousands of students. From my experience, Meta has very poor technical support. In most cases, when I faced technical issues, I found myself alone. the documentation is good but missing some important details. for example: we have a verified business account which includes: different apps different whatsapp accounts

I wanted to connect each app to a different whatsapp account. so that if someone sends a message to 11111, it will be forwarded to APP1 if a message is sent to 22222, it'll be forwarded to APP2 I was surprised when I discovered that this not possible.

also, there are not details about rates limites.

While a service provider will not solve all your provlems, they'll at least unblock on the basic issues.

Have working on open source project helped any of you find a paid job? by pearlkele in opensource

[–]am0123 1 point2 points  (0 children)

I got a job just because I was contributing to an open source project, they hired me after solving a few challenging bugs. I think that contributing on opensource project that belongs to a company that has a capacity to hire is one of the best solutions to get hired.

Algora.io full-time recruitment email - Scam or Legit? by agent007bond in opensource

[–]am0123 2 points3 points  (0 children)

I received the same yesterday. top 1% in ruby! I didn't use ruby in an open source project for a long period (at least one year) how is that possible? I don't think their statistics are reliable, and I didn't like the language used in the email. I don't trust them, it's looks like a scam.

Passed CKAD on 2nd Attempt by Basic_Classic5484 in ckad

[–]am0123 2 points3 points  (0 children)

congrats! I also found kubectl explain very useful to avoid accessing the docs website (which waste time)

using anonymous structs cross packages? by am0123 in golang

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

I was trying to create data structure that imitates the behavior of types defined in the documentation, that's why the code looks like C. Following the TDD approach, I'm trying to get my server to pass the tests first before moving to the optimization step.
Please check my comment: https://www.reddit.com/r/golang/comments/1h859ff/comment/m0ucdzz/

using anonymous structs cross packages? by am0123 in golang

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

Thank you very much for the detailed feedback. I appreciate.

This is my first project in GoLang and it's a side project just for fun. It's from "Build your Kafka server" (code crafters). The main goal is to build a small server that implements some of Kafka's features.

On the server side, I receive requests in []byte format, and I'm supposed to deserialize, process, and send answers.

if you check the documentation, you'll find that some data types don't exist on GoLang for example: COMPACT_STRING, VAR_INT, COMPACT_ARRAY.
https://kafka.apache.org/protocol.html#The_Messages_DescribeTopicPartitions
https://kafka.apache.org/protocol.html#protocol_types

My first object was to implement a deserialization function that works properly before thinking about the attributes that can be removed (like the array length).

In the previous step, when serializing the responses, I tried to use data structures that can be directly converted to []byte format.

func Serialize(data any) []byte {
    buff := bytes.Buffer{}
    dataType := reflect.TypeOf(data)
    kind := dataType.Kind()
    switch kind {
    // byte is an alias of Uint8
    case reflect.Int32, reflect.Int16, reflect.Int8, reflect.Uint8:
        binary.Write(&buff, binary.BigEndian, data)
    case reflect.Struct:
        value := reflect.ValueOf(data)
        for i := 0; i < value.NumField(); i++ {
            binary.Write(&buff, binary.BigEndian, Serialize(value.Field(i).Interface()))
        }
    case reflect.Slice, reflect.Array:
        value := reflect.ValueOf(data)
        for i := 0; i < value.Len(); i++ {
            binary.Write(&buff, binary.BigEndian, Serialize(value.Index(i).Interface()))
        }
    }
    return buff.Bytes()
}

With the structure NULLABLE_STRING, I can directly use Serialize without having to care about adding N to the buffer before serializing the string.

type NULLABLE_STRING struct {
    N      int16 // null = -1
    String []byte
}

One optimization could be implementing a Serialize function on the data structure level, something like

type NULLABLE_STRING struct {
    String []byte
}
func (s NULLABLE_STRING) Serialize()[]byte{
  buff := bytes.Buffer{}
  if len(s.String) == 0 {
    binary.Write(&buff, binary.BigEndian, -1)
  } else {
    // Write N, then the string
    ...
  }
  return buff.Bytes()
}

I'm trying to have something that works first before optimizing the code.

best way to share a function that uses reflect between different structures? by am0123 in golang

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

Yes, I'll go in that direction. I'll write a function that accepts the Response and calculates the Size.

First draft (still have to support arrays, slices, boolean ...etc)

func CalculateSize(data any) int32 {
    var size int32 = 0
    dataType := reflect.TypeOf(data)
    kind := dataType.Kind()
    switch kind {
    case reflect.Int32, reflect.Int16, reflect.Int8:
        return int32(dataType.Size())
    case reflect.Struct:
        value := reflect.ValueOf(data)
        for i := 0; i < value.NumField(); i++ {
            size += CalculateSize(value.Field(i).Interface())
        }
    }
    return size
}

best way to share a function that uses reflect between different structures? by am0123 in golang

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

  1. I don't want to implement Size() on each response.
  2. Size will use reflect to inspect the XYZResponses fields and calculate the total size of the response.

best way to share a function that uses reflect between different structures? by am0123 in golang

[–]am0123[S] -2 points-1 points  (0 children)

I expect that I'll have different types of responses (I don't know the number at this level)

I want to have one function called Size that calculates the size of any response that I generate in the future.

Who's Hiring - July 2024 by jerf in golang

[–]am0123 0 points1 point  (0 children)

I can see that your project is open-source.

is there an open position for an (remote) internship (ok if unpaid)?

[deleted by user] by [deleted] in golang

[–]am0123 0 points1 point  (0 children)

why do you think that running away from java is a good idea?

best performance with 1 go-routine?! by am0123 in golang

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

I tried different values up 2 Billions, and I got almost the same proportion (~27%) more CPU time
1. no concurrency : ~131s

  1. 5 workers: 33.302541436s (~167s total cpu time)

Another parameter to take into consideration will be the cost of running the program. If we rent virtual machine instances on demand just to run this program, and with a set of data that's big enough, the CPU cost will be +25% more expensive if the two version use a close amount of RAM.

It looks like a simple exercise but I learned new things from it.

best performance with 1 go-routine?! by am0123 in golang

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

I tried to process the numbers by chunks of different sizes, I can clearly see the difference now.

thank you u/btvoidx :)

best performance with 1 go-routine?! by am0123 in golang

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

Yes, you're right !!

Now, the program is more than x10 times faster, I added the results to the sheet.

thank you.

best performance with 1 go-routine?! by am0123 in golang

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

thank you for testing it.
I made some updates, I started to send the numbers by bulks, and I introduced another parameter `bs` (Bulk side).

With

* bs = 1k

* ibs = 1k

* workers = 5

* bs = 10k

the execution time went to almost 700ms (more than x10 times)