havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.0, 3.0.3, 2.7.5: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
gr33n7007h has joined #ruby
roadie has joined #ruby
gproto23 has quit [Ping timeout: 256 seconds]
ur5us has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
roadie has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
<bobdobbs> I'm assuming my script will be run in a linux environment. I want to test for the availability of a linux command. Is Shell the best tool to use?
Rounin has quit [Ping timeout: 256 seconds]
<leftylink> so I am surprised at how much faster Range#sum is than manually doing it
<leftylink> take a look
<leftylink> pandabot: rb def timeit; t = Time.now; yield; Time.now - t end; n = 2*10**7; [timeit { (1..n).sum }, timeit { k = 0; (1..n).each { k += _1 } }]
<pandabot> [3.812e-06, 1.143860173] - https://carc.in/#/r/ck4i
<leftylink> now, Range#sum could potentially use a constant-time implementation if it were acting on integers, but not all ranges are on integers
<leftylink> well let's see what happens if the range isn't over integers then
<leftylink> pandabot: rb def timeit; t = Time.now; yield; Time.now - t end; rng = (?a..?아); [timeit { rng.sum("").size }, timeit { k = ""; rng.each { k += _1 }; k.size }]
<pandabot> stderr: -e:2: invalid multibyte char (US-ASCII) - exit 1 - https://carc.in/#/r/ck4l
<leftylink> oh come the **** on
<leftylink> pandabot rb def timeit; t = Time.now; yield; Time.now - t end; rng = (?a.."\u{ffff}"); [timeit { rng.sum("").size }, timeit { k = ""; rng.each { k += _1 }; k.size }]
<pandabot> [0.108215762, 0.092518891] - https://carc.in/#/r/ck4w
<leftylink> okay so not significant advantage of #sum there versus #each
<leftylink> so #sum seems to have a case that does the direct calculation for integer ranges
<leftylink> which of course it cannot do for non-integer ranges
<leftylink> where can I see the code that governs this optimisation?
<leftylink> pandabot: ri Enumerable#sum
<leftylink> oh lol it's right there in the doc
<leftylink> "If the method is applied to an Integer range without a block, the sum is not done by iteration, but instead using Gauss’s summation formula."
<leftylink> as for the code, let's see... it's probably that int_range_sum call
<leftylink> anyway my question is answered. if the docs reflect when it was added, it'd be around 2.7. et's see
<leftylink> nope. apparently this optimisation has always been there, undocumented, since the introduction of Enumerable#sum in 2.4.0 (https://stackoverflow.com/questions/41636558/why-is-rangesum-defined-in-enumerable-module), and it was only just documented in 2.7
fcser has quit [Read error: Connection reset by peer]
John_Ivan has quit [Ping timeout: 256 seconds]
fcser has joined #ruby
<leftylink> you gotta tell us these things!
<leftylink> can't hold out on us like that
fcser has quit [Client Quit]
fcser has joined #ruby
roadie has joined #ruby
<leftylink> so I can reasonably expect that even if I gvae some absurd numbers that #sum will still calculate it as fast as it can create the bignums for it
<leftylink> pandabot: rb def timeit; t = Time.now; yield; Time.now - t end; n1 = 10**10**3; n2=10**10**4; timeit { (n1..n2).sum }
<pandabot> 0.000143933 - https://carc.in/#/r/ck4x
<leftylink> I just am stunned that they thought to put ths in
roadie has quit [Ping timeout: 240 seconds]
<bobdobbs> when I do 'IO.popen("ls")' in irb, I get back this: #<IO:fd 8>
<bobdobbs> what does that mean?
John_Ivan has joined #ruby
<leftylink> is the answer "file descriptor 8" of the desired level of detail or was more needed
<havenwood> bobdobbs: You can then create a new I/O object using that file descriptor ("fd"), like: IO.new(8) #=> #<IO:fd 8>
<havenwood> bobdobbs: Every file and socket a process has open has a fd, alongside the 0, 1, & 2 fd for stdin, stderr, and stdout.
<havenwood> (by default)
John_Ivan has quit [Read error: No route to host]
John_Ivan has joined #ruby
<bobdobbs> I understand some of that
<bobdobbs> ulimately what I'm trying to do is test to see if a system command is present, but without echoing it's output
<bobdobbs> I came across 'system', but this echos the output. Some googling led me to IO.popen. But that echos the output as well
<weaksauce> could use which
<bobdobbs> oh wait, not it doesn't echo the output. But it does echo that glyph... which describes the file descriptor?
<bobdobbs> weaksauce: what is that? I can't find it with Google.
<weaksauce> `which alkjsdlfjs`.empty?
<weaksauce> just a linux command to show you which program would execute
<weaksauce> if you were to use it
<weaksauce> `which ls`.empty? # => false
<weaksauce> `which alkjsdlfjs`.empty? # => true
<bobdobbs> weaksauce: Oh. Do the backticks result in passing the string to the system as a command?
<weaksauce> yes backticks is run that command and give me a string output
<weaksauce> i think only stdout though
<weaksauce> it might not be really portable though depending on the shell
<havenwood> bobdobbs: Do you need it to be portable across all systems or just Linux or BSDs?
<havenwood> bobdobbs: You can have #system send stdout and stderr to dev null.
<havenwood> bobdobbs: system('sh -c "command -v foo"', %i[out err] => File::NULL)
oxfuxxx has quit [Ping timeout: 256 seconds]
<havenwood> bobdobbs: That ^ for example, is a POSIX way to check if the command exists, sending any output to a black hole.
<havenwood> bobdobbs: system('sh', '-c', "command -v #{cmd_name}", %i[out err] => File::NULL)
<havenwood> (where cmd_name is the command name)
<havenwood> that works well on BSDs, macOS, Linux, or basically anything with sh.
<havenwood> if you need Windows, etc, too, don't shell out and check elsewise.
<havenwood> bobdobbs: A nice thing about #system is you can then use the return value of `true` or `false` to see if the command was found.
roadie has joined #ruby
ralu has quit [Ping timeout: 256 seconds]
roadie has quit [Ping timeout: 240 seconds]
<bobdobbs> havenwood: hai. I've just come back to terminal, so I'm reading your messages to me now.
<bobdobbs> havenwood: I'd like my script to be portable across linux OS's
<bobdobbs> havenwood: and I want to avoid assuming which shell is active for the user
roadie has joined #ruby
<havenwood> bobdobbs: sh and command are defined by POSIX and should be reasonable to rely on
<havenwood> bobdobbs: sounds like a fit
<havenwood> system('sh', '-c', "command -v bobdobbs", %i[out err] => File::NULL) #=> false
<havenwood> bobdobbs: You could alternatively look at PATH yourself, if you're anticipating the command will be in the PATH and is executable.
<havenwood> command will likely be more portable than PATH
<havenwood> i mean, it is
<adam12> Gemdocs.org is now slightly less hacky. I've moved everything to a compressed filesystem and dropped storing everything as gzip. Gonna try to find time this week to generate docs for all new gem releases of versions I have already stored, and maybe setup the webhook to add new ones.... maybe. Or at least for the gems I already have for now.
oxfuxxx has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
<bobdobbs> Thans havenwood
<bobdobbs> *thanks
roadie has joined #ruby
<bobdobbs> havenwood: sorry, I'm looking at this documentation for 'system'. I can't see how to supress messages: https://apidock.com/ruby/Kernel/system
ralu has joined #ruby
<bobdobbs> havenwood: I mean, I can see the example you've given me. But I can't see how it maps to the docs
<bobdobbs> Or at least to the documentation that I can find. There might be official documentation for this call, but I can't find it.
<adam12> bobdobbs: Look for the Kernel#spawn docs.
<adam12> And imho, use rubyapi.org as it's likely more up to date. https://rubyapi.org/3.1/o/kernel#method-i-spawn
<bobdobbs> thanks
<adam12> (or the official docs)
<adam12> Kernel#system wraps Kernel#spawn so many of the arguments translate over.
<adam12> Good luck. I'm crashing :)
<bobdobbs> Sorry, I can't see anything in the docs for 'system' that might apply to supressing output
oxfuxxx has quit [Ping timeout: 240 seconds]
gproto23 has joined #ruby
mahlon_ is now known as mahlon
<havenwood> pid = spawn(command, :err=>:out)
<havenwood> Look under :redirection
<havenwood> bobdobbs: redirecting :out and :err to dev null suppresses output
<havenwood> the example above directs stderr to stdout
<havenwood> bobdobbs: there's not a dev/null example, but if you can redirect stdout and stderr to nothing to suppress
<havenwood> *then you can direct to nothing to suppress
<havenwood> redirecting stdout and stderr to /dev/null is a common pattern, at least
<havenwood> bobdobbs: The system docs say "See Kernel#spawn for details."
<havenwood> The spawn docs have the details, like adam mentione.d
roadie has quit [Ping timeout: 240 seconds]
Pipip has joined #ruby
bluedust has joined #ruby
<bobdobbs> havenwood: thanks again
roadie has joined #ruby
roadie has quit [Ping timeout: 240 seconds]
bluedust_ has joined #ruby
bluedust has quit [Ping timeout: 240 seconds]
<bobdobbs> havenwood: I'm not sure that spawn works in this case either. If the command doesn't exist, then a traceback gets generated.
bluedust has joined #ruby
TomyWork has joined #ruby
roadie has joined #ruby
dviola has joined #ruby
bluedust_ has quit [Ping timeout: 240 seconds]
ur5us has quit [Ping timeout: 240 seconds]
roadie has quit [Ping timeout: 240 seconds]
mixfix41 has quit [Quit: quittin']
roadie has joined #ruby
_ht has joined #ruby
CrazyEddy has quit [Ping timeout: 240 seconds]
CrazyEddy has joined #ruby
hd1 has joined #ruby
<hd1> https://github.com/ksss/kqueue/issues/1 anyone encounter this?
Rounin has joined #ruby
ur5us has joined #ruby
<havenwood> bobdobbs: I mean use system but the docs from spawn.
<havenwood> The system docs just reference the same options from spawn, but use system.
<havenwood> Command should work as I showed it.
roadie has quit [Quit: ERC (IRC client for Emacs 25.3.50.1)]
hd1 has quit [Quit: Connection closed]
ur5us has quit [Ping timeout: 240 seconds]
Pipip has quit [Quit: Ex-Chat]
Guest3367 has joined #ruby
oxfuxxx has joined #ruby
___nick___ has joined #ruby
oxfuxxx has quit [Ping timeout: 256 seconds]
taupiqueur has joined #ruby
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 268 seconds]
oxfuxxx has joined #ruby
roadie has joined #ruby
bluedust has quit [Remote host closed the connection]
John_Ivan has quit [Ping timeout: 256 seconds]
<rapha> hi all
<rapha> why might Sequel insist that "SQLite3::CorruptException: database disk image is malformed" although with `sqlite3` it opens just fine and `pragma integrity_check;` say all is fine?
<rapha> says*
bluedust has joined #ruby
<jhass[m]> maybe the command line tool and the ruby binding link against different versions of libsqlite3?
<jhass[m]> Or you're simply not opening the same file actually :P
<rapha> I made sure about the latter before asking :P
<rapha> Hmm, the former sounds something to look into, tho
<rapha> Also happy new year!
<jhass[m]> thanks, same to you :)
<jhass[m]> a blind bundle pristine sqlite3 / gem pristine sqlite3 might also be worth a shot
roadie has quit [Ping timeout: 240 seconds]
roadie has joined #ruby
bluedust has quit [Remote host closed the connection]
roadie has quit [Ping timeout: 240 seconds]
oxfuxxx has quit [Ping timeout: 256 seconds]
roadie has joined #ruby
John_Ivan has joined #ruby
kaleido has quit [Ping timeout: 250 seconds]
bluedust has joined #ruby
taupiqueur has quit [Ping timeout: 256 seconds]
oxfuxxx has joined #ruby
<John_Ivan> any reason why the "write" method isn't listed here? https://ruby-doc.org/core-2.5.0/File.html
<John_Ivan> nvm. it's in the IO parent.
nmollerup has quit [Remote host closed the connection]
bluedust_ has joined #ruby
bluedust has quit [Ping timeout: 256 seconds]
keinbock has quit []
nmollerup has joined #ruby
bluedust_ has quit [Remote host closed the connection]
TomyWork has quit [Remote host closed the connection]
bluedust has joined #ruby
<libsys> sup guys... question... I want to create a file which only contains routes in a hash and I can load programatically later
<libsys> but I only can think on reading the file and then running eval, that's right, but seems hackish
<libsys> is there a more elegant way?
<libsys> I need to import the same routes on 2 different files
<libsys> /contexts
<libsys> *actually it's an array of hashes
<adam12> Is the file supposed to be user-editable? or plaintext?
<Hess> does `Kernel#load` solve your problem?
oxfuxxx has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
RawFiend has joined #ruby
<libsys> adam12: it should be ruby code ... idk what you mean by user-editable
<libsys> Hess: hmm... probably, but IDK how... if I assign a local variable routes = [{...}}] and then Kernel#load I can't read routes
<libsys> this is what I'm doing now: LeanWeb::App.new(eval(File.read('routes.rb'))).build_static
<libsys> and inside routes.rb is only an array of hashes
<adam12> libsys: I just meant if you expected people to edit them or not. Since if not, you could of stuck them in PStore or something.
<adam12> I don't see why eval would be an issue here.
RawFiend has quit [Remote host closed the connection]
<adam12> Maybe wrap it in a method so you don't see the eval as the client.
kaleido has joined #ruby
kaleido has quit [Changing host]
kaleido has joined #ruby
<adam12> LeanWeb::App.load_routes("routes.rb")
taupiqueur has joined #ruby
<libsys> adam12: right, I think that's the way to go
taupiqueur has quit [Ping timeout: 240 seconds]
taupiqueur has joined #ruby
taupiqueur_ has joined #ruby
taupiqueur has quit [Ping timeout: 256 seconds]
MeowcatWoofWoofF has quit [Quit: You have been kicked for being idle]
CrazyEddy has quit [Ping timeout: 240 seconds]
Guest51 has joined #ruby
Guest51 has quit [Client Quit]
<havenwood> libsys: or check out apeiros' literal_parser gem: https://github.com/apeiros/literal_parser
rhe has quit [Quit: ~ *]
<havenwood> No YAML? :P
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
rhe has joined #ruby
mmalter has quit [Read error: Connection reset by peer]
Common-Lisp has joined #ruby
gproto23 has quit [Remote host closed the connection]
gproto23 has joined #ruby
<adam12> Connected Rubygems webhook to gemdocs.org. New releases of all gems should start being added automatically.
<adam12> It will be interesting to see what this does for disk usage. Some gems are absolutely enormous.
<adam12> I've moved to zstd for compression and I'm seeing about a 5:1 compression ratio currently.
kaleido has quit [Ping timeout: 256 seconds]
Common-Lisp has quit [Ping timeout: 240 seconds]
gproto23 has quit [Remote host closed the connection]
<rapha> so my boss, of all poeple, just asked if there is something like Python's Spyder IDE for Ruby
<rapha> i.e. where you can see all variables, play with them
<rapha> basically irb/pry but more visual, with a nice GUI
<rapha> RubyMine is deffo too expensive and i can't find something like that in VSCode ... any others?
<adam12> VSCode + Debug.gem might be OK, but you're inside a debugger so .. maybe not?
<rapha> i think that'd take it a little too far, yeah
<adam12> There's this one too: https://github.com/nguyenquangminh0711/ruby_jard still debuggerish
<rapha> and needs to be put into the code manually
<rapha> i think most ruby people are just happy with pry as it is
<adam12> irb has picked up most of the pry pieces. I still use pry out of habit, and if I need to do a custom console, but outside of that, pry sees less usage for me lately.
<adam12> And I'd rather run debug.gem than binding.irb almost always.
<rapha> hmmm no reason so far to stop using it
<adam12> Maybe you could do debug.gem, rdbg your command, then configure watch or outline or whatever the options are to display all variables at program pause.
<rapha> will try Debug.gem ... so far i've lived okay with printf debugging
<rapha> i do see the appeal of having an IDE where you can have a file open together with a terminal, run the file, then see your stack and play with it
<rapha> (or maybe even interact with your stack visible, as Matlab allows one to do)
<rapha> visually*
<adam12> You can get that with the debug extension for vscode I believe.
<rapha> hmm
<rapha> will try then
<rapha> adam12: so that's nice in terms of seeing the stack, but then you click on "debug console" and type "puts 'blah'" and to see the output you have to click back on "terminal". sad that they didn't find a way to make those two tabs one single tab.
<rapha> okay, told him about it. we'll see how that goes.
<rapha> thanks!
<rapha> jhass[m]: fwiw that didn't help (gem pristine) and i ended up rebuilding the database on that same computer with that same sequel gem which needs to be able to access it.
dangerousdave has joined #ruby
<dangerousdave> Anyone else here have a policy whereby additional code review approvals must be sought for complex, or extensive code changes?
bluedust has quit [Remote host closed the connection]
<adam12> dangerousdave: How do you mean?
<adam12> dangerousdave: After initial review, or if the code is complex, more than 1 review is necessary?
dangerousdave has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
goldfish has joined #ruby
smp has quit [Quit: ZNC 1.8.2 - https://znc.in]
taupiqueur_ has quit [Remote host closed the connection]
taupiqueur has joined #ruby
smp has joined #ruby
RawFiend has joined #ruby
RawFiend has quit [Quit: Gone away...]
RawFiend has joined #ruby
RawFiend has quit [Ping timeout: 256 seconds]
ur5us has joined #ruby
bluedust has joined #ruby
bluedust has quit [Ping timeout: 256 seconds]
___nick___ has quit [Ping timeout: 256 seconds]
roadie has quit [Ping timeout: 268 seconds]
_ht has quit [Remote host closed the connection]
taupiqueur has quit [Quit: taupiqueur]
Guest3367 has quit [Ping timeout: 256 seconds]
michigan has joined #ruby
<michigan> Howdy!
<michigan> Shouldn't https://ruby-lang.org/ be working? Only https://www.ruby-lang.org/ seems to work.
samgranieri has quit [Quit: ZNC 1.8.2+deb2build1 - https://znc.in]
samgranieri has joined #ruby
CrazyEddy has joined #ruby
<havenwood> michigan: I think it's long been just the latter that works, but unsure. There's no strict rule that you should support www subdomain or lack of but I agree it's "normal" to just work.
<havenwood> michigan: I don't know of anyone against having it also work omitting the "www" but needs to be configured.
<michigan> Can't hurt! :-)
<weaksauce> that's a pretty low effort thing to have not working
ur5us has quit [Ping timeout: 240 seconds]
* LACampbe1 stealthily checks on website
<havenwood> weaksauce: but then you'd have to rename the repo :P https://github.com/ruby/www.ruby-lang.org
<havenwood> j/k j/k
<weaksauce> hah