havenwood changed the topic of #ruby to: Ruby 3.3.0, 3.2.3, 3.1.4 https://www.ruby-lang.org | Rules https://ruby-community.com | Logs https://libera.irclog.whitequark.org/ruby
adam12 has quit [Quit: The Lounge - https://thelounge.chat]
adam12 has joined #ruby
adam12 has quit [Read error: Connection reset by peer]
adam12 has joined #ruby
[0x1eef] has joined #ruby
[0x1eef_] has quit [Ping timeout: 256 seconds]
gaussianblue has quit [Quit: leaving]
desnudopenguino has quit [Ping timeout: 268 seconds]
desnudopenguino has joined #ruby
fercell has joined #ruby
fercell_ has quit [Ping timeout: 252 seconds]
konsolebox has joined #ruby
Linux_Kerio has joined #ruby
konsolebox_ has joined #ruby
konsolebox has quit [Ping timeout: 268 seconds]
karolis has quit [Ping timeout: 255 seconds]
ken_barber has joined #ruby
ken_barber has quit [Client Quit]
fdan has joined #ruby
jenrzzz has quit [Quit: Lost terminal]
gr33n7007h has quit [Ping timeout: 260 seconds]
gr33n7007h has joined #ruby
fdan has quit [Ping timeout: 250 seconds]
_ht has joined #ruby
[0x1eef] has quit [Quit: Leaving]
grenierm has joined #ruby
szkl has joined #ruby
osc4rpt has quit [Ping timeout: 268 seconds]
osc4rpt has joined #ruby
gaussianblue has joined #ruby
gaussianblue has quit [Quit: leaving]
CrazyEddy has joined #ruby
CrazyEddy has quit [Quit: Reconnecting]
grenierm has quit [Quit: Client closed]
CrazyEddy has joined #ruby
grenierm has joined #ruby
CrazyEddy has quit [Client Quit]
CrazyEddy has joined #ruby
rvalue has quit [Ping timeout: 256 seconds]
entropy has joined #ruby
entropie has quit [Ping timeout: 260 seconds]
entropy is now known as entropie
sam113101 has quit [Ping timeout: 240 seconds]
sam113101 has joined #ruby
konsolebox_ is now known as konsolebox
Aminda has quit [Quit: Default quit message is difficult to set. If you don't see me returning, ask me? You will find me, if you want to]
TomyWork has joined #ruby
grenierm has quit [Quit: Client closed]
weaksauce has quit [Ping timeout: 256 seconds]
weaksauce has joined #ruby
Aminda has joined #ruby
donofrio__ has joined #ruby
donofrio_ has quit [Ping timeout: 255 seconds]
xdminsy has joined #ruby
osc4rpt has quit [Ping timeout: 252 seconds]
osc4rpt has joined #ruby
[0x1eef] has joined #ruby
rvalue has joined #ruby
ken_barber has joined #ruby
c10l has quit [Remote host closed the connection]
karolis has joined #ruby
c10l has joined #ruby
pascal_blaze has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
<leah2> JSON.dump writes NaN and Infinity...
<[0x1eef]> What do you mean ? As literals or as strings ?
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
rapha has quit [Quit: WeeChat 4.1.2]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Linux_Kerio has quit [Ping timeout: 268 seconds]
Aminda has quit [Remote host closed the connection]
<leah2> literals
<leah2> >> (-1.0/0.0).to_s
<ruby[bot]> leah2: # => "-Infinity" (https://carc.in/#/r/gp70)
<leah2> >> "%f" % (-1.0/0.0)
<ruby[bot]> leah2: # => "-Inf" (https://carc.in/#/r/gp71)
<leah2> whyyyyy
<leah2> software was really made to break me
Aminda has joined #ruby
<adam12> leah2: I was thinking the same thing yesterday :( so many wtfs
<leah2> also case can't detect NaN...
<leah2> and ruby can't distinguish nan and -nan
<[0x1eef]> Oh wow, that's amazing.
<[0x1eef]> >> require "json"; JSON.dump(x: -1.0/0.0)
<ruby[bot]> [0x1eef]: # => "{\"x\":-Infinity}" (https://carc.in/#/r/gp73)
<leah2> hmm, can it even distinguish -0.0 and 0.0
<leah2> without parsing %a
<[0x1eef]> How do I generate NaN from Ruby ?
<leah2> 0.0/0.0
<[0x1eef]> JSON.parse JSON.dump(x: 0.0/0.0)
<[0x1eef]> /usr/local/lib/ruby/3.3.0/json/common.rb:219:in `parse': unexpected token at 'NaN}' (JSON::ParserError)
<leah2> :clownface:
entropie has quit [Ping timeout: 268 seconds]
karolis has quit [Ping timeout: 252 seconds]
entropie has joined #ruby
gr33n7007h has quit [Quit: WeeChat 4.2.2]
gr33n7007h has joined #ruby
aesthetikx has joined #ruby
user71 has joined #ruby
ken_barber has quit [Quit: Client closed]
Jb70 has joined #ruby
CrazyEddy has left #ruby [#ruby]
CrazyEddy has joined #ruby
<konsolebox> leah2: NaN and Infinity aren't JSON: https://datatracker.ietf.org/doc/html/rfc8259#section-6
karolis has joined #ruby
ken_barber has joined #ruby
<leah2> i know
<leah2> else i wouldnt complain...
Guest20 has joined #ruby
Jb70 has quit [Quit: Client closed]
Guest20 has quit [Quit: Client closed]
<konsolebox> leah2: I guess I misread. I thought you were expecting it to. I mean expect Ruby to produce "Infinity" and "NaN".
<konsolebox> leah2: Interestingly, to_json OTOH won't allow it.
<konsolebox> So I guess it's a bug worth reporting.
<leah2> hmm
<[0x1eef]> Sounds like a good reason to write in C :)
Linux_Kerio has joined #ruby
<gr33n7007h> Looking at #dump's default options it allows nan
<[0x1eef]> JSON.stringify from JS casts NaN to null.
<gr33n7007h> >> require 'json'; JSON.dump_default_options.update(allow_nan: false); JSON.dump(hello: 0/0.0)
<ruby[bot]> gr33n7007h: # => 1008: NaN not allowed in JSON (JSON::GeneratorError) (https://carc.in/#/r/gp8e)
<gr33n7007h> >> require 'json'; JSON.dump_default_options.update(allow_nan: true); JSON.dump(hello: 0/0.0)
<ruby[bot]> gr33n7007h: # => "{\"hello\":NaN}" (https://carc.in/#/r/gp8f)
<[0x1eef]> Can you parse it back to NaN though?
<gr33n7007h> [0x1eef]: no idea, didn't try ;)
<[0x1eef]> That's what I found weird. It can emit JSON that it can't parse again.
<gr33n7007h> the only thing i can reason is it's ruby specific: parse returns the option; "{\"max_nesting\":false,\"allow_nan\":true,\"script_safe\":false}"
<[0x1eef]> Indeed. This works: JSON.parse(JSON.dump(x: 0.0/0.0), allow_nan: true) - but's weird, especially for a default.
<gr33n7007h> there must be some reasoning for it, those ruby folks aren't all crazy ;)
<gr33n7007h> [0x1eef]: hang on, what's weird?
<gr33n7007h> NaN and Inf is not valid json.
<[0x1eef]> By default JSON.dump(x: 0.0/.0.0) will emit NaN, and then JSON.parse won't be able to parse it again (unless you set allow_nan: true). SO the default half works.
<leah2> >> JSON.load('{"x":NaN}')
<ruby[bot]> leah2: # => uninitialized constant JSON (NameError) (https://carc.in/#/r/gp8n)
<leah2> >> require 'json';JSON.load('{"x":NaN}')
<ruby[bot]> leah2: # => {"x"=>NaN} (https://carc.in/#/r/gp8o)
<leah2> works here...
<leah2> so load isnt parse?
<[0x1eef]> >> require 'json'; JSON.parse JSON.dump(x: 0.0/0.0)
<ruby[bot]> [0x1eef]: # => 226: unexpected token at 'NaN}' (JSON::ParserError) (https://carc.in/#/r/gp8p)
<leah2> yeech
<gr33n7007h> leah2: yeah, don't use load, its unsafe
<[0x1eef]> I guess not.
<gr33n7007h> load_default_options allow NaN too
<gr33n7007h> leah2: load calls parse after setting a few options and stuff
<leah2> unsafe json loading, statements dreamed up by the utterly deranged
xdminsy has quit [Read error: Connection reset by peer]
<gr33n7007h> well, from untrusted input. basically dump/load allows NaN in its default options, parse otoh doesn't
<leah2> doesnt seem very unsafe :p
<gr33n7007h> did read about all the quirks about this years ago, god knows what article it was
<gr33n7007h> leah2: :P
<leah2> i know yaml is unsafe
<leah2> and marshal ofc
<gr33n7007h> lol yeah, well unsafe XD
poems has quit [Ping timeout: 246 seconds]
poems has joined #ruby
bovis has joined #ruby
<bovis> https://bpa.st/5EYQ I'm trying to copy an existing zip file into memory, edit the copy, and then open the resulting edited stream. Why do I get the error "End-of-central-directory signature not found" when I open the resulting new zip file?
pascal_blaze has joined #ruby
[0x1eef] has quit [Quit: Leaving]
[0x1eef] has joined #ruby
pascal_blaze has quit [Client Quit]
ken_barber has quit [Quit: Client closed]
<adam12> bovis: What zip library is this?
desnudopenguino has quit [Ping timeout: 255 seconds]
desnudopenguino has joined #ruby
gr33n7007h has quit [Ping timeout: 268 seconds]
gr33n7007h has joined #ruby
desnudopenguino has quit [Ping timeout: 252 seconds]
desnudopenguino has joined #ruby
karolis has quit [Ping timeout: 260 seconds]
gr33n7007h has quit [Ping timeout: 252 seconds]
konsolebox has quit [Ping timeout: 256 seconds]
gr33n7007h has joined #ruby
_ht has quit [Remote host closed the connection]
<bovis> adam12: rubyzip. I require 'zip' at the top of the document.
<adam12> bovis: You don't show how you're writing the buffer out.
<adam12> Are you using latest rubyzip version?
<bovis> adam12: I send_data to the user. https://bpa.st/3PJQ
<adam12> bovis: Is it any different if you call `flush` first? `zip_data.flush`
sagax has quit [Ping timeout: 255 seconds]
user71 has quit [Quit: Leaving]
<bovis> adam12: Rubyzip version is 2.3.2. zip_data.flush doesn't help.
<adam12> bovis: I see it calls flush automatically from the code.
<adam12> bovis: tbh, probably too many things going on here. I'd try making a minimal example without rails & send_file (and without that ensure close block).
<adam12> If the zip is fine with those eliminated, see if you can write to a Tempfile then send_file the tempfile.
havenwood has quit [Quit: The Lounge - https://thelounge.chat]
havenwood has joined #ruby
TomyWork has quit [Ping timeout: 268 seconds]
Linux_Kerio has quit [Ping timeout: 252 seconds]
donofrio__ has quit [Ping timeout: 256 seconds]
Starfoxxes has quit [Ping timeout: 256 seconds]
Starfoxxes has joined #ruby
<bovis> adam12: Without the rails, this works fine: https://bpa.st/OTSA
<bovis> A separate but similar instance with the rails, this works fine https://bpa.st/OY6Q
<bovis> The only difference being that, in the latter, I'm not editing the existing zip in place. The tempfile is blank.
pascal_blaze has joined #ruby
<weaksauce> why not close the zip_data above send_data
<bovis> weaksauce: Just tried it. No change in results.
<bovis> Is it necessary to close the Zip::OutputStream within the block I've opened? It feels like something should go after the shovel: new_zip << File.read(...)
<weaksauce> probably yeah
<weaksauce> close
<weaksauce> Closes the stream and writes the central directory to the zip file
<weaksauce> same with close_buffer
karolis has joined #ruby
CrazyEddy has quit [Quit: Reconnecting]
<adam12> bovis: How about `send_data(zip_data.string, ... rest of stuff)` - specifically, `zip_data.string`
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
desnudopenguino has quit [Ping timeout: 268 seconds]
desnudopenguino has joined #ruby
<havenwood> bovis: Or explicitly pass your I/O and close it separately from the stream. For example: https://gist.github.com/havenwood/d2f92aea610b2d692ba18d9766b454fd
<havenwood> bovis: Is the latter the output you're shooting for?
<havenwood> bovis: Just an aside from your other gist, but Tempfile.create is preferred to Tempfile.new. Also, if you pass `"tmp.zip"` it till use use it as a prefix like `tmp.zipxoxo`. To have the latter be the extension, pass an Array like `%w[tmp .zip]` for `tmpxoxo.zip`.
<havenwood> And a block is preferred, to close the Tempfile.
<havenwood> TL;DR: Tempfile.create(%w[tmp- .zip]) { ... }
<havenwood> #=> #<File:/tmp/tmp-00000000-00000-aaaaaa.zip>
<havenwood> The docs expound on why Tempfile.create is more than a stylistic difference from Tempfile.new.
<[0x1eef]> FWIW :) Most of the time I use Tempfile in a way similar to this: Tempfile.new("namespace").tap { [File.chmod(0, _1.path), File.unlink(_1.path)] }.
<jas-maelstrom> Is there a way to programmatically draw/create a .TIFF image in Ruby? This would be for a small utility for work in a Windows environment.
<weaksauce> jas-maelstrom what are you trying to make?
<jas-maelstrom> I want to be able to generate TIFF images, actually, sorry, multi-page TIFF images and be able to programmatically write certain info from a database on them.
<jas-maelstrom> I'm in QA and our application is built around TIFF images so TIFF is a requirement here, multiple-page TIFF.
<jas-maelstrom> I just need to generate image files customized with specific data and ideally, generate them of certain file sizes.
<weaksauce> some of those may do what you want but i'm not familiar with tiff enough to say if any can do that
<jas-maelstrom> Thanks, I'll take a look.
<weaksauce> the most capable will be bindings to a c based library probably
<weaksauce> something like that
<jas-maelstrom> https://rmagick.github.io/index.html may do the job, there's even an SVG library. Thanks again!
<weaksauce> np
donofrio has joined #ruby