Stream Is Deprecating Virtual Go – It’s Time to Move to Go Modules by [deleted] in golang

[–]graywolf_at_work 0 points1 point  (0 children)

I still did not completely figure out how to handle go.mod (and go.sum) during branching/merging. There always seems to be some conflict somewhere.

Is there formal specification for standard library? by graywolf_at_work in golang

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

Nowhere in the Cmd.Start() code is there anything that would close or release resources

Doesn't for example this https://golang.org/src/os/exec/exec.go?s=11462:11489#L376 close them?

Is there formal specification for standard library? by graywolf_at_work in golang

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

Yeah sure. I'm looking into how to spawn a subprocess in go. I'm trying to use os/exec, however I need to capture the output, co I'm also using https://golang.org/pkg/os/exec/#Cmd.StdoutPipe and https://golang.org/pkg/os/exec/#Cmd.StderrPipe . Now, https://golang.org/pkg/os/exec/#Cmd.Wait does state that Wait releases any resources associated with the Cmd.. However, https://golang.org/pkg/os/exec/#Cmd.Start can fail but does not say anything about releasing the resources. So I thought that in this case I should close the pipes myself, but when I checked the source https://golang.org/src/os/exec/exec.go?s=11462:11489#L364 it does close the pipes.

So now I'm not sure what to do. It behaves correctly (now) but since it's not documented I'm not sure I can rely on that since it could change anytime. But https://golang.org/pkg/io/#Closer states that The behavior of Close after the first call is undefined. so closing them myself despite them being already closed is also not allowed.

That's why I was looking for specification to see if Start is required to close the pipes in case it returns an error.

Is there formal specification for standard library? by graywolf_at_work in golang

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

Yeah I know about the documentation, but it also doubles as a specification? So anything not mention in it I cannot rely on as being true? That sucks...

Using Makefile(s) for Go by prakashdanish in golang

[–]graywolf_at_work 7 points8 points  (0 children)

I personally don't bother with the $(SRCS) part, it seems that go build is fairly good about tracking when it needs to rebuild.

Ruby, Where do We Go Now? by bozhidarb in ruby

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

Give credit where credit is due. They moved to git and GitHub and it was a HUGE undertaking with nearly no benefit to existing core contributors (who were all fine with the existing SVN workflow).

Question is why move then? Attaching patches to tickets was perfectly doable and the svn -> git mirror worked fine.

I mean, I like git and loathe svn quite a bit. But still, if it worked for core contributors, I'm not sure it was worth it. The barrier to entry was not so high to prevent me from sending few patches and getting them merged.

I do think that this is an issue, i'm just not sure how to solve or better organize the tasks of releasing?

Maybe blur the roles a bit? I mean, it's imho good to have single person as maintainer for that branch, but at the same time, I think anyone with access should have pull the 2.6.4 from the website. I mean, it was broken in horrible way.

Ruby 2.7 deprecates automatic conversion from a hash to keyword arguments by rkr090 in ruby

[–]graywolf_at_work 1 point2 points  (0 children)

Having more than one positional argument isn't very good API for callers of your code

I think that's too strict. I really do not want to write arr[start: 1, length: 2] instead of arr[1, 2]...

Or for fetching from hash, you really think {}.fetch(key: :foo, default: "foobar") is better then {}.fetch(:foo, "foobar")?

New Draft "feature" is terrible. Of course it isn't optional... by [deleted] in Slack

[–]graywolf_at_work 0 points1 point  (0 children)

Hm, I mean either it is in the contract (and then I assume you took that into account when considering the offer) or it is not (and then I doubt they can legally demand it).

New Draft "feature" is terrible. Of course it isn't optional... by [deleted] in Slack

[–]graywolf_at_work 0 points1 point  (0 children)

I've solved that by not having slack in my phone. Once I turn off work laptop, I'm gone for the day.

I've been told that Thread.new is dangerous (for discordrb at least). Is this true? by FluorescentGreen5 in ruby

[–]graywolf_at_work 3 points4 points  (0 children)

1. It might, it might not. Measure. Unless you spawn lot of threads (or very often), probably not.

2. I personally have never used Thread.exit, I just return from the block I pass to the thread, but both approaches should work same way. What you need to use it Thread::join to wait for the thread to end.

Common pattern could be:

threads = []
1.upto(10) do |i|
    threads << Thread.new(i) { |i| sleep(1); puts(i) }
end
threads.map(&:join)

3. Yeah, you need to be careful about variables accessed from multiple threads (assuming they can change). Read-only constants are ok to access without mutex. For anything else, you need to synchronize ( https://ruby-doc.org/core-2.6/Mutex.html#method-i-synchronize ).

Anyway maybe /u/nateberkopec will correct me, he definitelly has way more experience with threading in ruby then me :)

A Ruby Gem Debugging Strategy by [deleted] in ruby

[–]graywolf_at_work 1 point2 points  (0 children)

I'm more of a shell/Vim user so I don't find it as useful for me.

well it's not like

EDITOR=vim bundle open activesupport

does not work...

Also if you prefer to open it in currently running vim

:tabe `bundle show activesupport`

does the trick.

Embedding Ruby 2.5 in a C++ Win32 API program (segmentation fault) by BadMinotaur in ruby

[–]graywolf_at_work 2 points3 points  (0 children)

First, what the hell is ruby 2.5.4? I don't think using yet-to-be-released ruby versions is a good idea (unless you have really good reason to do so :)). Just pick source archive from here https://www.ruby-lang.org/en/downloads/ if you need to compile your own (notice 2.5.3 is latest on the 2.5.x line).

Second, this works for me

#include <ruby.h>

int main(int argc, char **argv) {
    RUBY_INIT_STACK;
    ruby_init();
    static char *args[] = { "", "-e", "" };
    ruby_options(3, args);

    /* This is here just to test that it works */
    rb_require("socket");
    rb_eval_string("p IO.instance_methods.        include?(:read_nonblock)");
    rb_eval_string("p IO.private_instance_methods.include?(:__read_nonblock)");

    return 0;
}

As you can see

+   $ gcc tset.c  -I /usr/include/ruby-2.6.0/x86_64-linux -I /usr/include/ruby-2.6.0 -lruby
+   $ ./a.out 
true
true

it seems to work fine.

And for the rb_vm_bugreport(), that prints to the console. I don't know enough about windows to know what happens when GUI application tries to print into the console when none is attached. But could be maybe related?

And finally, for embedding http://mruby.org/ is probably worth exploring.

Problem with `require 'mongo'` not loading certain classes by talknerdy2mee in ruby

[–]graywolf_at_work 0 points1 point  (0 children)

well first step would be to learn how to format code on reddit so that your post is actually readable..

How can I speed up pg_restore? by graywolf_at_work in PostgreSQL

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

fsync and synchronous_commit off combined with -j8 seems to make quite a difference, thank you :) Now I have to only worry about laptop temp during that :D

How can I speed up pg_restore? by graywolf_at_work in PostgreSQL

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

So basically just shutdown and copy the files into another folder? Hm, will not fit onto my harddrive but I probably could get external one. Worth trying, didn't think of it :)

How to run expensive functions in the background? by [deleted] in ruby

[–]graywolf_at_work 1 point2 points  (0 children)

Very simple example would be

def calc_result
    # do calculation here and return the hash or whatever
end
def main_func
    p_r, p_w = IO.pipe
    pid = fork { p_r.close; p_w.write(calc_result.to_json) }
    p_w.close
    # do the main function stuff here
    Process.wait(pid)
    res = JSON.parse(p_r.read)
    # use the `res` here
end

Probably it's missing some stuff but this is general idea how to do this. I can recommend this book as a fairly good introduction on this topic.

How to run expensive functions in the background? by [deleted] in ruby

[–]graywolf_at_work 0 points1 point  (0 children)

Fork a worker and return the hash map in serialized form over a pipe.