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
<RX14> I tried to implement select against filedescriptor read and write once
<RX14> it didn't work out as well as i'd hoped
<FromGitter> <asterite> Yeah, implementing that is super hard. I'm pretty sure the current select doesn't work well (in fact I think there are bugs reported to it)
<RX14> @asterite yeah I found that out
<RX14> also, looks like looking up if a file is a symlink on windows takes about 8 syscalls
<RX14> oh, no looks like i remembered wrong, that was something else...
claudiuinberlin has quit [Quit: Textual IRC Client: www.textualapp.com]
wontruefree has joined #crystal-lang
<RX14> @asterite file_spec.cr now passes
<RX14> (with a LOT of {% unless windows %} though)
<RX14> stuff like File.symlink? I still need to get working
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
jnyw has joined #crystal-lang
wontruefree has joined #crystal-lang
<crystal-gh> [crystal] RX14 pushed 1 new commit to master: https://git.io/vNZr9
<crystal-gh> crystal/master 48a1130 Chris Hobbs: Simplify Crystal::System interface by adding File.stat? and lstat? (#5553)...
wontruefree has quit [Client Quit]
sz0 has quit [Quit: Connection closed for inactivity]
<crystal-gh> [crystal] RX14 opened pull request #5579: Ensure String#to_utf16 result has a null terminator (master...feature/to_utf16-fixup) https://git.io/vNZo3
<crystal-gh> [crystal] RX14 opened pull request #5580: Reenable Crystal::Hasher seed randomisation on win32 (master...feature/crystal-hasher-seed-windows) https://git.io/vNZol
<crystal-gh> [crystal] RX14 opened pull request #5581: Rename win_nt.cr to winnt.cr (master...feature/windows-winnt-rename) https://git.io/vNZoa
cbass has joined #crystal-lang
cbass has quit [Ping timeout: 276 seconds]
<travis-ci> crystal-lang/crystal#48a1130 (master - Simplify Crystal::System interface by adding File.stat? and lstat? (#5553)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/328345286
<DeBot> https://github.com/crystal-lang/crystal/pull/5553 (Simplify Crystal::System interface by adding File.stat? and lstat?)
hightower2 has joined #crystal-lang
<hightower2> Can I use macros to define some compile-time variable that I continuously append with stuff as I call a macro, and then dump the accumulated content at once?
hightower2 has quit [Ping timeout: 256 seconds]
<FromGitter> <mikeeus> @RX14 I've been contributing to the Lucky Framework because I'm familiar with web frameworks, but I'll look around the stdlib and see if I can be of use
vivus has quit [Quit: Leaving]
<FromGitter> <Dillybob1992> hey, just saw this article (http://serdardogruyol.com/benchmarking-and-scaling-websockets-handling-60000-concurrent-connections-with-kemal) might be a dumb question but: would the results be roughly the same with a regular TCP Server?
<crystal-gh> [crystal] asterite closed pull request #5579: Ensure String#to_utf16 result has a null terminator (master...feature/to_utf16-fixup) https://git.io/vNZo3
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vNZXG
<crystal-gh> crystal/master d294dd1 RX14: Reenable Crystal::Hasher seed randomisation on win32
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vNZXZ
<crystal-gh> crystal/master d7c9551 RX14: Rename win_nt.cr to winnt.cr...
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
faustinoaq has joined #crystal-lang
<travis-ci> crystal-lang/crystal#d7c9551 (master - Rename win_nt.cr to winnt.cr): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/328362255
<travis-ci> crystal-lang/crystal#323613b (master - Ensure String#to_utf16 result has a null terminator): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/328362103
<FromGitter> <Dillybob1992> just curious, why doesn't my second loop get called?
DTZUZU has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<jnyw> @Dillybob1992 you have an infinite loop that prints out 1 every 0.1 secs to the terminal. your second loop never has a chance to be executed because the first loop never terminates
<faustinoaq> @Dillybob1992 you need to put the first loop inside a spawn
<FromGitter> <Dillybob1992> oh, so the loops are synchronous?
<jnyw> @Dillybob1992 indeed.
<FromGitter> <Dillybob1992> so the more `loop do`'s I have, more spawns I will need for them, i think?
<FromGitter> <Dillybob1992> im coming from nodejs background so this is really all new, but i'm liking it
<jnyw> @Dillybob1992 if you haven't already you should take a look at https://crystal-lang.org/docs/guides/concurrency.html
snsei has joined #crystal-lang
<FromGitter> <Dillybob1992> thanks, my mind is currently blown reading that but i do have the docs bookmarked :D
jnyw has quit [Ping timeout: 255 seconds]
<FromGitter> <asterite> But node has no loop
<crystal-gh> [crystal] Sija opened pull request #5582: BigDecimal.new(str : String) handles scientific notation (master...bigdecimal-with-scientific-notation) https://git.io/vNZDx
<FromGitter> <Dillybob1992> i kept thinking loop do with sleep(0.1) in it is compared to setInterval in js
<FromGitter> <Dillybob1992> but im very wrong
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
relyks has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
jnyw has joined #crystal-lang
DTZUZO has quit [Ping timeout: 264 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 276 seconds]
relyks has quit [Quit: relyks]
claudiuinberlin has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
snsei has joined #crystal-lang
<FromGitter> <straight-shoota> Should `String.from_utf16` respect a string being null-terminated? @asterite RX14
<RX14> Hmm?
<FromGitter> <straight-shoota> in TIME_ZONE_INFORMATION the names are `StaticArray(WCHAR, 32)`
<FromGitter> <straight-shoota> so I would use `String.from_utf16(info.standardName.to_slice)` to convert to a String
<RX14> So add an overload which takes a null terminated wchar*
<RX14> Uhh, to_s??
<RX14> And no, it doesn't
<FromGitter> <straight-shoota> to_s?
<RX14> There's no handling of null termination
<RX14> It wasn't necessary until now
<FromGitter> <straight-shoota> yeah I figure
<FromGitter> <straight-shoota> that's why I asked if it *should* handle that
<RX14> There should be an overload with a slice that doesn't
<RX14> And an overload with a pointer that does
<RX14> Only the each_char overload method needs to change
<FromGitter> <straight-shoota> but is there a usecase for non null-terminated wchar strings?
alex`` has joined #crystal-lang
<RX14> Uhh, all of them until now?
<RX14> Checking for null adds complexity
<RX14> Of you know the length why bother
<FromGitter> <straight-shoota> true
<RX14> Plus nul is a perfectly valid Unicode codepoint
<FromGitter> <asterite> In the other hand, we are currently traversing the slice twice to determine the bytesize of the string, so...
<FromGitter> <asterite> (I think nim allocates the maximum possible bytesize and then uses that and later takes a subslice or realloc, not sure what's more efficient)
<FromGitter> <asterite> But true, the null byte is a good reason to not do this if the length is available
<RX14> Personally I think the best approach is using realloc
<RX14> Allocate as if it was ascii
<RX14> Then if we reach the end of the allocation, realloc for 1.5x
<RX14> Or something
<RX14> all optimizations when "windows is slow" is the top of our todo instead of "windows doesn't work"
<RX14> @asterite i'm proabbly going to rework File::Stat to copy what Go does
<RX14> except a bit more crystally
<FromGitter> <asterite> Sounds good. I think Go's API is excellent
<RX14> yeah
<FromGitter> <asterite> I hope there's no problem copying API designs...
<RX14> go's API for their os package is fantastic
<FromGitter> <asterite> Yes, we can optimize utf-16 stuff later, probably reallocating is good
<RX14> I like to think the go team would be happy we're copying them :)
<RX14> @asterite although, go's stat only provides modification time, not creation time
<ua> if anyones interested %Q{ } can be used as multiline comments :^)
<livcd> but go's os api does not contain a lot of useful stuff which they think does not belong to std :)
<FromGitter> <asterite> RX14 I wonder why is that. It's not available on Windows?
<RX14> I'm sure it is
<FromGitter> <asterite> Strange...
<RX14> Yeah
<livcd> i think it's in experimental
<FromGitter> <asterite> We should also make glob return file infos instead of strings, it should be more efficient plus useful
<FromGitter> <asterite> Even though it might be a little less convenient
<RX14> Well surely it should return both
<RX14> Since we have recursive blobs, and stat only contains basename
<RX14> It'd be impossible to interpret the results
hightower2 has joined #crystal-lang
<RX14> Globs*
<livcd> RX14: where did you not find it ?
<RX14> FileInfo
<livcd> i am pretty sure it's here
<RX14> thats not the os package
hightower has quit [Ping timeout: 256 seconds]
foxxx0 has quit [Quit: foxxx0]
<livcd> that's why I said not all of it is there
<crystal-gh> [crystal] straight-shoota opened pull request #5583: Add overload to String.from_utf16 with pointer (master...jm/string-from-utf16-pointer) https://git.io/vNZjL
Ven`` has joined #crystal-lang
Ven`` has quit [Client Quit]
DTZUZO has joined #crystal-lang
alex`` has quit [Quit: WeeChat 1.9]
faustinoaq has quit [Ping timeout: 255 seconds]
Ven`` has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
alex has joined #crystal-lang
alex is now known as alexherbo2
alexherbo2 is now known as alex``
Ven`` has joined #crystal-lang
alex`` is now known as alex
greengriminal has joined #crystal-lang
<FromGitter> <Dillybob1992> @ua, ty haha. kept doing # each line ^_^
<ua> yeah it was really pissing me off
<RX14> there was a reason why we don't have multiline comments
<RX14> I'll be really sad if these take off as a hack
<RX14> just comment out blocks in your editor
<ua> i did but had to use keyboard shortcut after adding each line
<RX14> huh?
<RX14> just selct and ctrl-/ in most editors does it
<RX14> that's one mouse movement and a keyboard shortcut
<RX14> far easier than typing %q{ and then moving and typing }
<ua> yeah if you first write all the lines
<ua> or want to coment out code *
<RX14> well when you're writing lines you only need to press "# " once per line
<RX14> and it's pretty rare to me
<FromGitter> <Dillybob1992> since im doing more coding with classes i usually just comment out the ClassName.new part instead now
<RX14> ua, what do you mean "want to comment out code" ?
pabs has quit [Remote host closed the connection]
<ua> nah i just wrote it down stupidly
<ua> in a stupid way
<FromGitter> <Dillybob1992> regarding the mysql connector https://github.com/crystal-lang/crystal-mysql
<FromGitter> <Dillybob1992> do i have to use DB.open each time to run a query?
<RX14> no
<RX14> you want to keep the returned DB object around
<FromGitter> <Dillybob1992> ohhh ok, thank goodness
<ua> is stuff like "reasons for no multiline comments" written down somewhere?
<FromGitter> <Dillybob1992> i know, in nodejs when we used the db.query, it was async (had to promises or callback hell) to the get value. in crystal's DB connector, are the calls synchronous? so callback hell is not a thing, we just get the value right after the query?
<RX14> @Dillybob1992 yes, synchronous is the default
<RX14> if you want concurrency, use spawn {}
<ua> i see Conventions in docs, but deeper reasons why its that way?
pabs has joined #crystal-lang
<FromGitter> <Dillybob1992> @RX14, i see, so since im using the TCP server example and using spawn handle_connection, if i call query inside the handle_connection methods i should be fine
<RX14> ua, because it's an extra feature which replicates what most editors have built in
<RX14> and there's all sorts of arguments about the syntax
pabs has left #crystal-lang [#crystal-lang]
<RX14> any proposal to add multiline comments would turn into a bunch of bikeshedding
pabs has joined #crystal-lang
<RX14> so why bother, it's 2018 and most editors have this built in
<RX14> @Dillybob1992 yes
<ua> but then %Q{ } just creates string thats not used afterwards and probably just get deleted by compiler
<RX14> yeah
<RX14> nobody ever realised you could emulate them pretty well with %Q{}
<RX14> do they nest?
<FromGitter> <Dillybob1992> @RX14 i see, so after a spawn functioname, anything inside that functionname doesn't need to be spawned again, unless it's a loop do? if i got that right
<RX14> it's not that simple
<RX14> spawn just runs a function in another thread
faustinoaq has joined #crystal-lang
<RX14> (not quite but in effect it's the same)
<livcd> is the m:n thread scheduler work stalled ?
<RX14> yes livcd
<FromGitter> <Dillybob1992> thank you, understanding spawn more now :)
<ua> %Q{ itself can be nested but it tries to do string interpolation
<ua> so some pieces of code are affected
<ua> if you comment them like that
<RX14> yay, it's broken
<ua> haha
<ua> still works most of the time :P
<RX14> well, for that usecase
<RX14> which it wasn't intended for
pabs has quit [Remote host closed the connection]
pabs has joined #crystal-lang
<RX14> I know why there's only mtime @asterite
<RX14> atime is frequently not set on unix filesytems, and ctime is useless
<RX14> and btime is unsupported on most filesystems
<RX14> well, it's usually mount -o relatime
pabs has quit [Client Quit]
pabs has joined #crystal-lang
<FromGitter> <Dillybob1992> hmm, so i heard on unix subsystem we're not allowed to modify any files in the unix directory
<RX14> from windows
<RX14> you can access windows files from the unix subsystem
<RX14> by using /mnt/c/
<RX14> and that's all you need:
<RX14> just work in a directory on your C drive and use it normally from windows
<RX14> when you want to work in that directory using linux just cd there inside /mnt/c/
<FromGitter> <Dillybob1992> so it'll be ok to edit shard.yml's to add a module?
<RX14> well, where is the shard.yml
<RX14> and what are you editing it with?
<FromGitter> <Dillybob1992> sublime text 3, but it's windows version so i need to use inline editor in linux then?
<RX14> No
<RX14> That's fine
<RX14> As long as its not notepad you're fine
<FromGitter> <Dillybob1992> kk
<RX14> The warning against editing unix files from windows is when you go digging around in the AppData folder to find the root Linux file system
<FromGitter> <Dillybob1992> i see, i thought i had to do that to edit shard.yml
<RX14> As I said, depends where the shard.yml is
<RX14> If you're working in /mnt/c you're fine
<RX14> If you're not you're not fine
<RX14> as in, use C:\Users\Foo\Projects\Whatever\ on windows
<RX14> then /mnt/c/Users/Foo/Projects/Whatever to access it on linux
<RX14> and you're fine
<FromGitter> <Dillybob1992> oh so it can just be in the directory of project
<RX14> ???
faustinoaq has quit [Quit: IRC client terminated!]
<RX14> your projects shouldn't be on your desktop
<RX14> the shard.yml file is per-project
<RX14> you should have a folder for your project with the shard.yml in, and put the source files in the src folder
<RX14> you can use `crystal init` to make this folder for you
<RX14> with a shard.yml file which is complete
<FromGitter> <Dillybob1992> ohhh
<FromGitter> <Dillybob1992> oh wow, it's got the entire project all rdy for me
<FromGitter> <Dillybob1992> i looked at all tutorials and stuff never saw that (could be me though)
<FromGitter> <Dillybob1992> i'm doing ` crystal ./src/GameServer.cr` now, but is that the right way? could i just do `crystal run` or?
<FromGitter> <picatz> @Dillybob1992 You'd use `./binary` on a compiled version of your program.
<FromGitter> <picatz> `crystal run file.cr` will compile and run the program for you under the hood
<FromGitter> <Dillybob1992> okay, so for development it's normal to point to /src/ foldeER?
<RX14> @Dillybob1992 `crystal src/file.cr` is usually the same as `crystal run src/file.cr`
<RX14> if you want to build an executable you just do `crystal build src/file.cr`
<FromGitter> <picatz> ^ that ✨
<RX14> if you're going to deploy it
<RX14> or test performance
<FromGitter> <Dillybob1992> oh nice, wow the executable files runs INSTANTLY O_O
<FromGitter> <Dillybob1992> so fast
<RX14> use `crystal build --release src/file.cr`
<FromGitter> <picatz> @Dillybob1992 crystal is very fast for a lot of things!
<RX14> @Dillybob1992 yes most of the `crystal run` time is compiling it
<RX14> crystal run is the same as crystal build then running the exebutable
<RX14> but as one command
<FromGitter> <Dillybob1992> im converting my gameserver from nodejs to crystal after i saw kemal websocket benchmark.
<FromGitter> <picatz> Nice! I think you'll really like crystal.
<FromGitter> <Dillybob1992> rx14 and others here help a lot, w/o them i'd be lost ^_^
<FromGitter> <picatz> The community around crystal is also pretty great, yeah. 👏
<FromGitter> <Dillybob1992> :) :)
relyks has joined #crystal-lang
<FromGitter> <Dillybob1992> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a5a3f096117191e615fba5c]
<FromGitter> <Dillybob1992> some reason, it's not throwing an error, am i doing that right?
<FromGitter> <l3kn> You'll need a `begin` first
<FromGitter> <l3kn> oh, sorry, I didn't know about the short form without `begin`
<FromGitter> <Dillybob1992> oh oops.
<FromGitter> <Dillybob1992> lol that was unintentional
<FromGitter> <Dillybob1992> i didn't know hahaha
<FromGitter> <Dillybob1992> im dumb, connect doesn't return an error
<FromGitter> <Dillybob1992> so ofc it won't work -.- wow
greengriminal has quit [Quit: This computer has gone to sleep]
commavir has joined #crystal-lang
<FromGitter> <Dillybob1992> im trying to find out how to catch this raise: http://crystal-lang.github.io/crystal-db/api/0.5.0/DB/ConnectionLost.html
<FromGitter> <Dillybob1992> where does it get raised at?
hightower has joined #crystal-lang
<FromGitter> <Dillybob1992> Actually, it does get raised like that i changed `localhost` to `localhost25` and it does work correctly `No address found for localhosts:3306 over TCP`. i guess it just continues to connect for certain amount of time
greengriminal has joined #crystal-lang
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
Ven`` has quit [Client Quit]
<FromGitter> <Dillybob1992> This works! :D I hope I'm doing it right
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter> <picatz> As long as that's not an actual production password anywhere: looks fine to me! 😂
<FromGitter> <Dillybob1992> lol, ya dev only will change l8er :D
<FromGitter> <Dillybob1992> i relly am starting to get a hold of crystal, im feeling more comfortable now
wontruefree has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
DTZUZO has quit [Quit: WeeChat 2.0]
<FromGitter> <bajro17> Hi can you please tell me when will crystal be ready for windows approximately is this possible to be until july?
snsei has joined #crystal-lang
<oprypin> possible
<RX14> depends on your definition of ready I suspect
<FromGitter> <Dillybob1992> is it possible to make the mysql module not exit on error raise ( i know i can just do being db.exec "statement" rescue e puts e.message), however i'd have to do that around each `.exec` i run, would be cool if i could catch all those errors somehow
<FromGitter> <picatz> @Dillybob1992 I guess you could write a wrapper function of sorts for yourself.
<FromGitter> <picatz> Not sure if that's the best way to do it. 😂
<FromGitter> <Dillybob1992> ima try that, thank you :)
faustinoaq has joined #crystal-lang
<FromGitter> <Dillybob1992> I'm getting unidentified exec2 but it's defined in my class, any idea? :O
<FromGitter> <l3kn> Do you want to execute that code every time an instance of that class is created?
<FromGitter> <l3kn> If so, you should put it inside `def initialize ... end`
<FromGitter> <l3kn> This way it tries to call a method `exec2` defined on the class `GameServer`, not instances of that class
<FromGitter> <Dillybob1992> oh, you can put def functioname inside def itself?
<FromGitter> <l3kn> no, I mean the part with `begin ... end`
<FromGitter> <l3kn> do you want to share the db connection between instances of that class?
<FromGitter> <Dillybob1992> well, my class will only be initialized once (forever), i jsut am trying to get `db` to work everywhere in it
<FromGitter> <l3kn> If I were you, I would make `db` a normal property and put the `DB.connect` stuff inside the `initalize` function, that way it will be executed each time a new instance is created
<FromGitter> <Dillybob1992> ok will try
<FromGitter> <Dillybob1992> how should i assign my `db`? what do u mean by a normal property? ` property db = DB ` ?
<FromGitter> <l3kn> https://carc.in/#/r/3drj
<FromGitter> <l3kn> I didn't include the `begin ... rescue` stuff because this way a game server would be useless without a database connection
<FromGitter> <Dillybob1992> `instance variable '@db' of GameServer must be DB, not DB::Connection+` hmm
<FromGitter> <l3kn> I'm not sure about the class names for `crystal_db`, just change `property db : DB` to `property db : DB::Connection`
<FromGitter> <l3kn> just `property db` might work, too
<FromGitter> <Dillybob1992> ok, ty tried `property db : DB::Connection` `Error: instance variable '@db' is initialized inside a begin-rescue, so it can potentially be left uninitialized if an exception is raised and rescued`
<FromGitter> <l3kn> That's what I meant above, just leave the `begin` and `rescue` away for now
<FromGitter> <l3kn> At some point you would call `GameServer.new(....)`, you could handle the exception at that point
Ven`` has joined #crystal-lang
<FromGitter> <l3kn> from the docs it seems like calling `db.close` at some point is important, not sure where that would go
<FromGitter> <Dillybob1992> ohhh i see. so then i cando ` begin GameServer.new() rescue error` later, and it will catch the db errors thrown i assume
<FromGitter> <Dillybob1992> in any event, ty this helps. im too used to global variables, in nodejs i'd just put a db = connect at top of file and use everywhere :P
<FromGitter> <bcardiff> @l3kn are you sure you want a single connection? maybe you should use `DB.open`instead of `DB.connect`. Did you check: https://crystal-lang.org/docs/database/ for some sample usages?
<FromGitter> <Dillybob1992> @bcardiff ya i got that up now. im not sure how many i should open? i was reading and it said it has an internal pool
<FromGitter> <l3kn> I was thinking about ways to fix the code from https://files.gitter.im/crystal-lang/crystal/2mkA/image.png , from the docs it seems like `DB.open` would be better
<FromGitter> <l3kn> or even using the block syntax and passing the connection to `GameServer.new` inside that
<FromGitter> <Dillybob1992> but if i use the block method i heard it closes automatically
<FromGitter> <bcardiff> if you expect to have a long living instance to access the database, a pool should be used. Even if you want to limit the max concurrent connections to 1, since it will handle reconnection. ⏎ ⏎ yes, the block closes the whole pool at the end to release resources.
<FromGitter> <Dillybob1992> ok, so doing `DB.open "mysql://root@localhost/test" |db| ` with block syntax is preferred because then pooling is all done automatically for me?
<FromGitter> <Dillybob1992> closes and opens
<FromGitter> <bcardiff> Mostly, it depends how you organize the code. Both can work.
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
hightower is now known as hightower4
<FromGitter> <bcardiff> If you want to use GameServer as a singleton I would suggest to define an @@instance class variable and let everything else (@db) be instance variables.
<FromGitter> <bcardiff> @Dillybob1992 / @l3kn some fixes to the code could be: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a5a752f96885c834c35c7e4]
<FromGitter> <bcardiff> The exec2 in the class level begin/end can't call instance methods, hence the `self.exec` in the `def` to fix it.
<FromGitter> <Dillybob1992> OHHH i see, self.name did it
<FromGitter> <bcardiff> 👍 I'm glad that helped.
<FromGitter> <Dillybob1992> i remember shoota telling me couple days ago about extend self
<FromGitter> <Dillybob1992> but not work for classes right ? :D
<FromGitter> <Dillybob1992> thx brian and leon 👍 👏
claudiuinberlin has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<FromGitter> <Dillybob1992> i decided to try modules (good learning experience)
<FromGitter> <Dillybob1992> any idea what causing this invalid memory access?
<FromGitter> <bew> Your `def db; db; end` will probably break
<FromGitter> <bew> Not sure that's your problem though
<FromGitter> <Dillybob1992> oh, i removed that but get `undefined local variable or method 'db'`
jxv has joined #crystal-lang
wontruefree has joined #crystal-lang
<jokke> hey..
<jokke> is it not possible to define abstract initializers?
<jokke> here's what i'm trying to do: https://p.jokke.space/ZDI/
<jokke> ah
<jokke> okay that makes sens
<jokke> e
<FromGitter> <bew> jokke no but you can put the initialization outside it should work
<jokke> yeah i did it differently
<jokke> set it via default in the json mapping
<jokke> and got rid of the initializer
<FromGitter> <bew> That works too 👍
alex has quit [Ping timeout: 255 seconds]
Ven`` has joined #crystal-lang
<greenbigfrog> I know json normally doesn't allow comments, but is there a way to add comments to json, which gets used with JSON.parse?
<RX14> you'll have to pre-process the json
<RX14> before it reaches the json parser
<Yxhuvud> If you need comments, use yaml - it is a strict superset of json that has comments.
<RX14> also that too
<RX14> if you need comments in JOSN it's meant to be written by humans
<RX14> and JSON is a terrible configuration language
<RX14> YAML is far nicer
greengriminal has quit [Quit: This computer has gone to sleep]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<greenbigfrog> true
<greenbigfrog> how would I convert json like this to yaml?
<FromGitter> <straight-shoota> you just use it as yaml
<FromGitter> <straight-shoota> yaml is a superset of json, so any valid json is valid yaml, theoretically. There are a few minor differences but for most usecases it should be fine
<hightower4> greenbigfrog, yes green buddy, if you didn't know, yaml it's a superset of json!
<greenbigfrog> ah. so I would just do: https://hastebin.com/rometonuvo.ini ?
<RX14> no
<RX14> YAML is a superset of JSON
<RX14> any valid JSON without modification is valid YAML
<RX14> just parse it with no conversion
<RX14> at all
<crystal-gh> [crystal] RX14 opened pull request #5584: Rename and rework File::Stat as File::Info (master...feature/file-info) https://git.io/vNno6
<greenbigfrog> oh. now I get what you're trying to say... Just YAML.parse instead of JSON.parse and I can add comments with #
<RX14> or use however much of yaml syntax as you want
<greenbigfrog> yep
<greenbigfrog> thanks
<RX14> I do suggest going the whole way and writing standard yaml though
Cyrus has quit [Quit: Moving shells]
<RX14> actually not sure if it's possible to have an array as the root in yaml
<RX14> actually
<RX14> greenbigfrog, that yaml file is just "- test: hi"
<RX14> i mean json
snsei has quit [Remote host closed the connection]
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
snsei has joined #crystal-lang
Cyrus has joined #crystal-lang
qard has joined #crystal-lang
OceannBoy has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jnyw has joined #crystal-lang
<FromGitter> <Dillybob1992> hey guys, having a bit of trouble trying to get messages. `socket.read_line` works really cool, it only shows strings that have + `\n` at the end from client. which is good, and what i want. however! i want to detect if a string sent from the client doesn't have a `\n` at the end, and disconnect that user. how should i go about doing that?
<RX14> well, how do you know if the user sent a string if there's no \n ?
<RX14> a socket has no "lines" or "messages"
<RX14> it's just one byte after another until you get to the end of the socket
<RX14> you can't have a "line without a \n" because you've defined lines to be delimited by \n
<FromGitter> <Dillybob1992> damn, hmm
<RX14> what problem are you trying to solve?
faustinoaq has quit [Quit: IRC client terminated!]
faustinoaq has joined #crystal-lang
<FromGitter> <Dillybob1992> well, on my client i'm sending just a regular message `socket << "hellofmrign"` in a loop (for testing), and then when i stop the client, i get thousands upon thousands of text that is echo'd in command prompt out of no where (puts msg), it could dmg crystal if a malicious user isn't sending +\n strings because i will eventually want to kick them after sending xxx too fast
<RX14> i'm confused
<RX14> where are these messages coming from?
<FromGitter> <Dillybob1992> another crystal app (called client)
<RX14> i meant the stuff echoed
<FromGitter> <Dillybob1992> that's what i'm worried/confused about they just randomly appear
<FromGitter> <Dillybob1992> bcz read_line doesn't get them
<FromGitter> <Dillybob1992> butt hey all echo out when i cancel
<RX14> no
OceannBoy has quit [Ping timeout: 260 seconds]
<RX14> that's not what's happening i'm sure
<RX14> or at least by your description
<FromGitter> <Dillybob1992> one second, let me record it for 3-5 second u can see
OceannBoy has joined #crystal-lang
<FromGitter> <Dillybob1992> Okay, so this one: https://gyazo.com/223ed7d6074433ff1d710fdb6488b3f5 is where the messages get blocked somewhere and then when I do ctrl+c to cancel, they all get echo'd in cmd ⏎ ⏎ This is: https://gyazo.com/81f7e3b01567ba5ecd9c09b050267bc8 where it works correctly because I have the `\n` delimiter ⏎ ⏎ ``` loop do ⏎ msg = socket.read_line ⏎ puts msg```
<FromGitter> <Dillybob1992> basically, when i send a bunch of messages that `socket.read_line` doesn't read, they all get then pushed out in `puts msg` when client exits, i don't know how to stop that
<RX14> @Dillybob1992 use socket.flush after `socket <<`
<hightower4> Hey, is there a way to test if a module is defined? I'd like to do something like: if const_defined?( MyModule) ... do something ... end
<RX14> what for?
<hightower4> I have two files in a directory and they will surely get 'require'd, but I want them to be no-op unless a module to which they refer exist
<hightower4> and is loaded
<RX14> just require the module from the files?
<RX14> require only loads things once so it won't work either way
<RX14> even if we did have what you want
<hightower4> if the module is not already loaded I must not do any work. Ideally these files would not exist if the modules aren't loaded, but making them not exist would be pretty much of a pain
<hightower4> so I'm trying this route
<RX14> so the answer is no
jxv has quit [Quit: string on the can snapped off]