RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
hightower2 has quit [Ping timeout: 240 seconds]
LastWhisper____ has joined #crystal-lang
slightlyamusing has joined #crystal-lang
cremes has joined #crystal-lang
cremes has quit [Client Quit]
cremes has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cremes has quit [Quit: cremes]
slightlyamusing has left #crystal-lang ["WeeChat 2.0.1"]
cremes has joined #crystal-lang
cremes has quit [Client Quit]
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 1.9]
DTZUZU has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 256 seconds]
hightower2 has joined #crystal-lang
alex`` has joined #crystal-lang
rohitpaulk has joined #crystal-lang
hightower2 has quit [Ping timeout: 248 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
hightower4 has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower2 has joined #crystal-lang
hightower2 has quit [Changing host]
hightower4 has quit [Ping timeout: 256 seconds]
jnyw has quit [Quit: WeeChat 2.0.1]
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
cremes has joined #crystal-lang
Groogy2 has joined #crystal-lang
Groogy has quit [Disconnected by services]
jokke1 has joined #crystal-lang
Groogy2 is now known as Groogy
<Groogy> Morning
<Groogy> o/
Groogy_ has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 260 seconds]
alex`` has quit [Quit: WeeChat 2.0.1]
DTZUZU has quit [Quit: WeeChat 1.9]
<FromGitter> <aisrael> TIL: If you override a `Foo.new` and don't `yield`, then any code that calls `Foo.new do |x|` silently fails (the block doesn’t get called)
<FromGitter> <aisrael> OTOH, if you try to override `Foo#foo` but don’t declare a `(&block)` parameter, then the original `Foo#foo()` gets called when you do `instance_of_foo.foo do |x|`
<FromGitter> <aisrael> (Ok, my understanding doesn’t seem to be 100% spot on. Trying to write some sample code that demonstrates the various behaviour.)
DTZUZU has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` is now known as alexherbo2
alexherbo2 is now known as alex``
hightower3 has joined #crystal-lang
cremes has quit [Quit: cremes]
hightower3 has quit [Ping timeout: 256 seconds]
DTZUZO has joined #crystal-lang
cremes has joined #crystal-lang
<FromGitter> <faustinoaq> Hi crystal community, somebody know how can I read updates in a file without printing all file again?
<FromGitter> <faustinoaq> I'm using `loop { puts File.read("some.log"); sleep 1 } }` but reads all file again
<FromGitter> <faustinoaq> something like watching a file
<FromGitter> <cfurrow> @faustinoaq it's not efficient, but you could do `File.read_lines("some.log")` to get an array of lines in the file. On each loop you could also store the number of lines read, and compare it to the previously read number of lines. Then, loop over the array, but only output the line indices that came after the previous number of lines read. ⏎ ⏎ e.g. if you read in a file that had 5 lines, output all 5. on
<FromGitter> ... the next loop, you read that the same file has 6 lines, so now output only the 6th line. the next loop may have 8 lines, so only read out 6,7,8, or whatever.
<FromGitter> <cfurrow> I don't know if crystal-lang has a "tail" functionality, but that is what you're really after, I think.
<lvmbdv> is there a way to "process" a string so "\\n" which is printed as "\n" is turned into an actual newline?
<lvmbdv> i tried sprintf but didn't work, i think
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <l3kn> lvmbdv: I'm not sure if there is a method in the stdlib that does this. If not, something like `str.gsub("\\n", "\n")` should work
<FromGitter> <l3kn> lvmbdv: Maybe even https://carc.in/#/r/3ib3, if you need to handle tabs etc, too
<RX14> @faustinoaq just call `gets_to_end` in a leep with sleep 1
<lvmbdv> i need to handle everything C string literals do, just wanted to see if i missed a stdlib function in my search
<lvmbdv> thank you l3kn
<RX14> @faustinoaq if you recieve EOF, and then write more bytes to the file, then try to read again you just get the extra bytes.
<RX14> so you just need to keep trying to read until you get something
<RX14> unless you want to implement inotify
<FromGitter> <faustinoaq> > just call `gets_to_end` in a leep with sleep 1 ⏎ ⏎ RX14 Thank you!
<RX14> i just observed what tail -f did in strace
<RX14> it's not too hard
<RX14> you can use this to replace the `sleep 1`
<RX14> it patches in a nice File.watch(path) do |event|
cremes has quit [Quit: cremes]
cremes has joined #crystal-lang
cremes has quit [Quit: cremes]
woodruffw has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
cremes has joined #crystal-lang
cremes has quit [Quit: cremes]
c-c has quit [Quit: Lost terminal]
cremes has joined #crystal-lang
cremes has quit [Client Quit]
OceannBoy has joined #crystal-lang
<crystal-gh> [crystal] ysbaddaden opened pull request #5677: Fix: uninitialized sa_mask value in sigfault handler (master...core-sigfault-uninitialized-mask) https://git.io/vNx3j
OceannBoy has quit [Ping timeout: 276 seconds]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Remote host closed the connection]
<FromGitter> <drosehn> The `inotify` solution is the best solution. But if that was not available, what you could do is do a `File.stat()` when you reached EOF, and also save the location of `File#pos`. Then each time you wake up from `sleep`, do another `File.stat()` to see if the size of the file has changed. If the file has not changed, then loop back and do another `sleep`. If the size has changed and gotten larger, set
<FromGitter> ... `File#pos=` and then start reading. If the size has changed and gotten smaller, then you'd probably want to re-read the whole file.
faustinoaq has joined #crystal-lang
<FromGitter> <drosehn> I mention this because I have some programs where I don't restart reading from the EOF, but I restart reading from after the last valid entry, where each entry is multiple lines. So it might be that the program does need to re-read some lines, but not the whole file.
OceannBoy has joined #crystal-lang
faustinoaq has quit [Read error: Connection reset by peer]
faustinoaq has joined #crystal-lang
<RX14> @drosehn but that just uses more syscalls then just attempting to read() and getting back 0
<RX14> the best case: there's more data, you get the data
<RX14> worse case: there's no data, you get EOF
<RX14> why do stat when you can just not do stat?
cremes has joined #crystal-lang
woodruffw has joined #crystal-lang
woodruffw has joined #crystal-lang
woodruffw has quit [Changing host]
OceannBoy has quit [Ping timeout: 256 seconds]
cremes has quit [Quit: cremes]
<FromGitter> <marksiemers> I have crystal built from master locally, if I want to make sure that is used locally for one of my projects, (on macOS) do I just need to switch the symlink here: `lrwxr-xr-x 1 mark admin 43 Feb 2 10:40 /usr/local/bin/crystal -> ../Cellar/crystal-lang/0.24.1_2/bin/crystal` to point to the binary built from master?
<FromGitter> <marksiemers> Or does something in the shards.yml need to change?
<oprypin> marksiemers, how about you don't mess with global system files? well on mac it's a lost cause but whatever
<oprypin> /full/path/to/crystal build stuff
<wmoxam> will that build against the correct crystal stdlib?
<wmoxam> might have to muck with some env variables to get that to work correctly :p
<FromGitter> <marksiemers> Thanks oprypin, I wasn't sure if invoking the binary without changing the system version would use the correct stdlib, etc. (as wmoxam mentioned).
<oprypin> i dont know how you tie `shards` into this. if it has no way to override the crystal binary, that's pretty bad.
woodruffw has quit [Quit: And then he took off.]
<RX14> oprypin, PATH="/full/path/to/bin:$PATH" shards lel
woodruffw has joined #crystal-lang
woodruffw has joined #crystal-lang
woodruffw has quit [Changing host]
<FromGitter> <drosehn> I thought I had tried "just do another read" and it raised an exception, however that might have been in a different language. All these different programs run together after awhile.
<FromGitter> <drosehn> Also, I wanted to re-read some of the data. So doing `stat()` is cheaper than doing `pos=` followed by some reads when there is no new data to read.
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <drosehn> emphasis on "new data".
<FromGitter> <drosehn> Oh, yeah, it was in crystal, although it was a different program. Not a `tail` program (where I know I have to sleep to wait for data), but in the program where I was trying to duplicate ruby's `popen`. If I did a read after EOF, I got an exception which I then have to `rescue` to get the code to work properly.
cremes has joined #crystal-lang
cremes has quit [Client Quit]
<FromGitter> <marksiemers> FWIW, running the binary directly confirmed what I needed it to: `~/git-repos/marksiemers/crystal/bin/crystal spec spec/amber/router/pipe/error_spec.cr:15`
cremes has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 1.9]
jokke has quit [Ping timeout: 252 seconds]
OceannBoy has joined #crystal-lang
<oprypin> ?
rohitpaulk has quit [Remote host closed the connection]
DTZUZU has joined #crystal-lang
duane has joined #crystal-lang
relyks has joined #crystal-lang
OceannBoy has quit [Ping timeout: 240 seconds]
OceannBoy has joined #crystal-lang
OceannBoy has quit [Ping timeout: 256 seconds]
cremes has quit [Quit: cremes]
alex`` has quit [Ping timeout: 276 seconds]
alex`` has joined #crystal-lang
<frojnd> I would like to check if all chars in a string are digits. How would I do that? Something in the line of "123".chars.all? { |c| c =~ [0-9] } ?
<FromGitter> <bew> you can use `.all? &.digit?` I think
faustinoaq has joined #crystal-lang
<frojnd> digit being method of what class?
<FromGitter> <bew> Char
<frojnd> digit? for char does not exists
<frojnd> s/exists/exist
<FromGitter> <bew> Yes sorry it's number? https://crystal-lang.org/api/0.24.1/Char.html#number%3F-instance-method
<frojnd> Thank you
faustinoaq has quit [Ping timeout: 276 seconds]
cremes has joined #crystal-lang
ua has quit [Ping timeout: 264 seconds]
ua has joined #crystal-lang
qard has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter> <marksiemers> oprypin, there was a bug in crystal 0.24.1 and ysbaddaden thought it might be fixed on master, to reproduce, I needed to run a spec in the amber shard. ⏎ That's why I was asking questions earlier about getting a locally built crystal to work with a shard. ⏎ For my case, I didn't need to set the path (per RX14's suggestion) just running `crystal spec` with the locally built binary confirmed that the bug
<FromGitter> ... was fixed in crystal master.
hightower4 has joined #crystal-lang
<hightower4> Hey, I have a shard in shard.yml which I point to github repo and set 'branch: master'. But, when shard is installed, instead of getting latest master branch, it installs me some version and prints: Installing ...name... (0.9.5 at master)
<hightower4> How do I make it get the latest thing in master branch?
faustinoaq has quit [Ping timeout: 256 seconds]
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 256 seconds]
<FromGitter> <asterite> branch: master
cremes has quit [Quit: cremes]
<hightower4> Yes, as mentioned I have that
<hightower4> And it tells me "Installing baked_file_system (0.9.5 at master)"
cremes has joined #crystal-lang
jnyw has joined #crystal-lang