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
DenKn has quit [Quit: Reconnecting]
DenKn has joined #ruby
m_antis has quit [Quit: ZNC - https://znc.in]
m_antis has joined #ruby
Guest9014 has quit [Ping timeout: 240 seconds]
goldfish has quit [Ping timeout: 256 seconds]
fowl has joined #ruby
fowl has quit [Quit: Client closed]
random-jellyfish has quit [Ping timeout: 256 seconds]
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
fowl has joined #ruby
fowl has joined #ruby
fowl has quit [Changing host]
SteveR has joined #ruby
fowl has quit [Quit: Client closed]
log101 has joined #ruby
SteveR has quit [Quit: Client closed]
fowl has joined #ruby
oxfuxxx has joined #ruby
log101 has quit [Ping timeout: 240 seconds]
Rounin has joined #ruby
log101 has joined #ruby
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
log101 has quit [Ping timeout: 256 seconds]
fowl has quit [Quit: Client closed]
log101 has joined #ruby
fowl has joined #ruby
Guest9014 has joined #ruby
fowl has quit [Quit: Client closed]
Guest94 has joined #ruby
bluedust has joined #ruby
_ht has joined #ruby
teclator has joined #ruby
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
ZAJDAN has joined #ruby
shiru has joined #ruby
shiru has quit [Quit: Lost terminal]
postmodern has joined #ruby
shiru has joined #ruby
log101 has quit [Remote host closed the connection]
log101 has joined #ruby
Guest97 has joined #ruby
Guest97 has quit [Client Quit]
log101 has quit [Remote host closed the connection]
log101 has joined #ruby
log101 has quit [Ping timeout: 256 seconds]
bluedust has quit [Remote host closed the connection]
fef has joined #ruby
Guest94 has quit [Quit: Client closed]
leonthemisfit has quit [Ping timeout: 240 seconds]
AEtherC0r3 has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
AEtherC0r3 has joined #ruby
fercell has joined #ruby
bluedust has joined #ruby
___nick___ has joined #ruby
bluedust has quit [Remote host closed the connection]
brown121407 has joined #ruby
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
oxfuxxx has quit [Ping timeout: 256 seconds]
fef has quit [Quit: Leaving]
hololeap has quit [Ping timeout: 276 seconds]
constxd has joined #ruby
perrierjouet has quit [Quit: WeeChat 3.4]
bluedust has joined #ruby
Guest9014 has quit [Ping timeout: 250 seconds]
bluedust has quit [Remote host closed the connection]
oxfuxxx has joined #ruby
taupiqueur has joined #ruby
oxfuxxx has quit [Ping timeout: 240 seconds]
Tempesta has quit [Quit: AdiIRC is updating to v4.2 Beta Build (2022/01/23 UTC) 64 Bit]
Tempesta has joined #ruby
perrierjouet has joined #ruby
fef has joined #ruby
gr33n7007h has joined #ruby
shiru has quit [Quit: leaving]
<IsoLinCHiP> Any suggestions how to use active-record models from a rails app in scripts on a completely different host? Throwing everything in the same source folder isnt really an option as I have two related web apps with different models and a few scripts that need to access both.
aindilis has quit [Quit: ZNC 1.8.2+deb2+b1 - https://znc.in]
aindilis has joined #ruby
unmanbearpig has joined #ruby
robotmay has quit [Quit: No Ping reply in 180 seconds.]
robotmay has joined #ruby
<ox1eef> IsoLinCHiP: I guess share the config/database.yml and models for the scripts, at a minimum.
fowl has joined #ruby
<mooff> do they use different databases?
<IsoLinCHiP> ox1eef: git submodules, or do you recon thats going to be more headache than use?
<IsoLinCHiP> mooff: yes
<ox1eef> i guess you could have a repo with the models, and share them between web app and scripts.
Guest61 has joined #ruby
fowl has quit [Quit: Client closed]
Guest61 has quit [Client Quit]
<mooff> it's gonna be tricky, and depend on how tangled the models are with other application code, libraries, etc
<mooff> however you load the model classes, you'll need to make sure the base model for each application points to the right DB
xyhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #ruby
<adam12> If you're using Bundler, I'd reach for a private gem before a git submodule, imho. But there's no great way to do it in general.
<ox1eef> generally i think one would package the scripts and web app together, and that makes life easier.
bluedust has joined #ruby
infinityfye has joined #ruby
mmalter has joined #ruby
<Vaevictu1> you could a) fork the whole thing and keep it forked indefinitely. b) try to utilize just the models/etc and maintain them as a unified source base, which might require application changes in the /other/ app to facilitate.
<Vaevictu1> either could be correct depending on your existing code and/or environment.
<jhass[m]> when opting for git as a solution git subtree trumps git submodule 90% of the time
<jhass[m]> for the particular case I wonder if reusing the same model code in your scripts is really important or if just duplicating a bunch of bare bone model classes for them isn't just fine
<Vaevictu1> yup. depends on existing code/environment :D
<Vaevictu1> the old-school in me says "just copy it over and be free!"
<Vaevictu1> especially if they're not sharing databases.
Vaevictu1 is now known as Vaevictus
<mooff> i've got an intermittent deadlock with my Ruby bot now that it forks to handle commands :)
<mooff> i've only seen it hang when running fast-exiting shell commands over IRC. such as "$ id", "$ cmd-that-doesnt-exist", etc.. but non-deterministically
<mooff> the code does "as(sender.nick) { ... use Open3 to run command, stream output to IRC }"
<mooff> as looks like this: def as(nick)
<mooff> Process.waitpid (fork {
<mooff> become! acct # does setregid, setreuid, Dir.chdir, updates ENV
<mooff> acct = posix_account! nick
<mooff> yield
<mooff> (Thread.list - [Thread.main]).each &:join
<mooff> })
<mooff> end
bluedust_ has joined #ruby
<Vaevictus> i hope you're sanitizing everything from outside the script :D
<mooff> once in a while, it hangs on Process.waitpid, and the fork process shows as defunct in ps
fef has quit [Quit: Leaving]
<mooff> Vaevictus: it's obviously a somewhat crazy experiment, but imagine it's sort of like a public access UNIX / Ruby system over IRC (LOL)
<Vaevictus> what could go wrong, amirite?
<mooff> well, exactly!
* Vaevictus puts ;rm in my nick
<Vaevictus> as far as why it's blocking, sorry, no idea. i guess maybe check for the pid rather than waiting for it?
<mooff> oh, the nick is sanitized, and the user creation is run with system('adduser', '-D', safe_nick, ..) etc
<Vaevictus> i mean, check first, then wait.
bluedust has quit [Ping timeout: 250 seconds]
<Vaevictus> i hope this is a throwaway VM ... if it is, awesome! :D
<mooff> i'm tempted to use Process.detach and just hope for the best.. let everything be asynchronou
<mooff> but the deadlock is sort of confusing
<Vaevictus> when i wrote my IRC bots, i used perl with POE... and that kinda black magic is dangerous stuff :D
<ox1eef> haha
<Vaevictus> the deadlock is, assumedly because you can't wait for a pid to finish once it's already finished.
<ox1eef> i remember POE, vaguely
<Vaevictus> POE::Component::IRC::Client lol
<mooff> in the case where it's already finished, it should throw an exception though, right?
Sheilong has joined #ruby
<Vaevictus> I've *still* got a bot running via POE.
<ox1eef> Vaevictus: you can collect a status at any time, as far as i know.
<Vaevictus> mooff: dunno, should it?
<mooff> it seems to!
<ox1eef> Process.wait does not raise an exception. try: pid = fork {}; sleep 5; Process.wait(pid)
<Vaevictus> now that perl's retconned perl6 out of existance, it's doing better lol
<mooff> ox1eef: try Process.wait(pid) twice
<mooff> Errno::ECHILD
<Sheilong> Where in Ruby documentation it says that the foreach method for Files does not load all the lines of a file at once?
<ox1eef> is that the exception you see? i understood you dont see an exception, but a zombie
<mooff> that's right, i don't see an exception :)
<ox1eef> the point was you can collect the status long after the process exits.
<mooff> Sheilong: it may not be specified in the documentation :/
<Sheilong> Someone is telling me to use readlines instead of foreach to count the number of lines in a File. But to convince him that foreach is better, I need to prove him about my argument.
bluedust has joined #ruby
<adam12> Sheilong: I don't see it documented, but in _general_, if it's yielding a block, it's usually lazy.
bluedust_ has quit [Ping timeout: 240 seconds]
<mooff> may need to read the source code for that foreach and readlines, Sheilong
<Sheilong> adam12: where is general?
<ox1eef> Are foreach and readlines not identical?
<Vaevictus> exec("wc -l <filename>") jk
<adam12> Sheilong: General == for many Ruby methods. It's not a category of documentation.
<ox1eef> seems not - no block for readlines().
<mooff> i think readlines reads until EOF, then returns them all at once
<Vaevictus> File.foreach(filename) {} count=$.
<ox1eef> I would use readlines personally.
<Vaevictus> file=File.open("file","r"); file.readlines.size
<ox1eef> IO.readlines("foo.txt").size
<Vaevictus> this random stackoverflow says taht readlines is slower when the files are over 1mb
<mooff> from `ri foreach`, the description of CSV.foreach makes me think it /might/ be streaming
<mooff> if true it would suggest to me that foreach is "read and yield line-by-line" by convention
<mooff> ("This method is intended as the primary interface for reading CSV files.")
<Vaevictus> i think that's true, yeah
<mooff> (surely the primary interface would not load the whole file into memory :))
<Vaevictus> from my 30 seconds of research
<ox1eef> IO.foreach("foo.txt").count - this works, and foreach is returning an Enumerator.
<adam12> I wonder if #count converts it to an Array (ala, slurping it)
<ox1eef> indeed, not sure
<adam12> I'd probably do IO#read with some set size (like 8k?), then count "\n". To prevent allocations, you could probably pass a string to IO#read and let it re-use the same one.
<ox1eef> i'd check if ruby optimizes the scenario at all - and how Enumerable#count behaves without a block. It could be optimized to not iterate the whole collection.
gproto23 has joined #ruby
taupiqueur has quit [Quit: taupiqueur]
BSaboia_ has joined #ruby
oxfuxxx has joined #ruby
ZAJDAN has quit [Ping timeout: 256 seconds]
<IsoLinCHiP> Yeah, I also was considdering just making a slim model copy, but I know there is some model changes going to be coming soonish down the road.
<IsoLinCHiP> If it were tools directly related to the site, Id just put them in the source of the web pages, agreed. But I have the awkward case, that Im just operating on the data the websites generate for some different processes.
log101 has joined #ruby
<Sheilong> does File.open(path, "r").readlines.length } automatically closes the file?
oxfuxxx has quit [Ping timeout: 256 seconds]
<mooff> Sheilong: by default, it will be auto-closed when the File object is GC'd
<mooff> but that could be a long time
<Sheilong> mooff: Better use a block in such case then?
<Sheilong> File.open(path, "r") do {|file| file.length}end
<mooff> yes - that's a good way to do it
<mooff> then it'll be closed as soon as the block returns
oxfuxxx has joined #ruby
<mooff> File.readlines(path) will also close it immediately after reading
oxfuxxx has quit [Ping timeout: 256 seconds]
oxfuxxx has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
oxfuxxx has quit [Ping timeout: 250 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 268 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 250 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 240 seconds]
log101 has quit [Ping timeout: 256 seconds]
hololeap has joined #ruby
bluedust has quit [Read error: Connection reset by peer]
<Sheilong> mooff: so there is no need for a block?
log101 has joined #ruby
log101 has quit [Read error: Connection reset by peer]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 240 seconds]
Thanzex has quit [Read error: Connection reset by peer]
Thanzex has joined #ruby
ur5us has joined #ruby
<micah> i've got a daemon that does a 'puts' for some debug logging to STDOUT, i found that it is not actually spitting the logs right away and they were being buffered
<micah> i thought I could set $stdout.sync = true to fix that, but that doesn't seem to take hold and I'm stumped why
<micah> (when I stop the application, suddenly all its logs come flushing in)
<adam12> micah: Maybe something else is buffering them?
<adam12> micah: Are you running the daemon from the shell?
<micah> adam12: I'm running it via systemd... I've got 5 systems that were doing this, weirdly, when I added `$stdout.sync = true` to the code and deployed it, four of them started to work properly, but one still doesn't
<micah> i tried stdout.flush, but exception NameError -- undefined local variable or method `stdout' for main:
samgranieri has joined #ruby
Guest842 has joined #ruby
<adam12> You'd need $stdout.flush
<micah> adam12: ah, i just tried STDOUT.flush and it worked, so I should change to $stdout.flush
<micah> but... it makes me wonder why $stdout.sync = true is not working, maybe its set somewhere?
<adam12> micah: Hard to say, but $stdout is designed to be re-assigned. Maybe $stdout != STDOUT
ZAJDAN has joined #ruby
yxhuvud has quit [Ping timeout: 240 seconds]
yxhuvud has joined #ruby
Rounin has quit [Ping timeout: 250 seconds]
oxfuxxx has joined #ruby
oxfuxxx has quit [Ping timeout: 268 seconds]
finsternis has quit [Quit: Changing server]
finsternis has joined #ruby
BSaboia_ has quit [Quit: This computer has gone to sleep]
infinityfye has quit [Quit: Leaving]
gproto23 has quit [Ping timeout: 250 seconds]
BSaboia_ has joined #ruby
BSaboia_ has quit [Read error: Connection reset by peer]
_ht has quit [Remote host closed the connection]
___nick___ has quit [Ping timeout: 250 seconds]
analogsalad has joined #ruby
yassernasc has joined #ruby
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
gr33n7007h has quit [Read error: Connection reset by peer]
gr33n7007h has joined #ruby
Guest842 has quit [Ping timeout: 256 seconds]
darkxploit has joined #ruby
gr33n7007h has quit [Ping timeout: 240 seconds]
gr33n7007h has joined #ruby
Guest9014 has joined #ruby
szkl has quit [Quit: Connection closed for inactivity]
analogsalad has quit [Remote host closed the connection]
hololeap has quit [Ping timeout: 276 seconds]
samgranieri has quit [Quit: samgranieri]
fredlinhares has joined #ruby
hololeap has joined #ruby
constxd has quit [Quit: WeeChat 2.8]
Guest9014 has quit [Ping timeout: 268 seconds]
ur5us has quit [Ping timeout: 240 seconds]