<FromGitter>
<riffraff169> the skills are static based on stats....as far as i know the information hasnt changed in years....but people play the game and use this program to calculate values rather than do it by hand
<FromGitter>
<riffraff169> there is a version in java that i have
<FromGitter>
<riffraff169> im converting to crystal for 2 reasons at least.....native linux version i guess, and crystall programming experience
<FromGitter>
<riffraff169> a programming project for me....i havent done any real serios programming for a hobby in years, too busy doing more infrastructure stuff
<FromGitter>
<riffraff169> that works great, thanks...i see where i went wrong
<FromGitter>
<riffraff169> i might just have a bunch of constants with that, like `Activities["VS"] = blah` and another line with another key...unless there is a better way
hendursa1 has joined #crystal-lang
<FromGitter>
<tenebrousedge> I think you need named tuples
<FromGitter>
<tenebrousedge> or to just make the key part of your yaml data
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
chachasmooth has quit [Ping timeout: 245 seconds]
chachasmooth has joined #crystal-lang
postmodern has quit [Quit: Leaving]
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter>
<rishavs> What does `def lines(chomp = true)` do? The documentation on it is missing. ⏎ I need to get the first line in a large string and was wondering if I should use this or just go with partition
<FromGitter>
<naqvis> @rishavs this returns array of lines, `chomp` to flag whether to remove newline character or not
<FromGitter>
<rishavs> Thanks as usual, Ali!
<FromGitter>
<naqvis> 👍
<FromGitter>
<naqvis> > I need to get the first line in a large string and was wondering if I should use this or just go with partition ⏎ ⏎ better go with `each_line(chomp = true)` to get the iterator for lazy loading
<FromGitter>
<naqvis> as `lines` will load all lines even if you just care for 1st line
<FromGitter>
<rishavs> ❤️
<straight-shoota>
@naqvis: Most efficient is probably `string.byteslice(0..string.index("\n"))`
<FromGitter>
<naqvis> Thanks straight-shoota and totally agree with your recommendation. My recommendation was based on the context of `lines` or the context which I understood from the original question
<FromGitter>
<zorgon_peterson:matrix.org> hi does crystal lang have `include` to include module functions into class like ruby?
<FromGitter>
<erdnaxeli:cervoi.se> Yes
<FromGitter>
<zorgon_peterson:matrix.org> is it not defined on all objects? I tried to use it in this line to dynamically include functions from different module, but I got an error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6086a89a06e2e024e87834db]
<FromGitter>
<naqvis> Crystal ain't ruby, so there is no dynamic inclusion
<FromGitter>
<naqvis> things need to be known at compile time
<FromGitter>
<naqvis> if you have defined `module A` with some methods then you should do a `include A` in respective Module/Class/Struct to get the mixin
<FromGitter>
<zorgon_peterson:matrix.org> sorry, don't mean to assume that. I came to get a better idea on the behavior because it doesn't seem to be documented anywhere. For context, i was trying to port over a webscrapping tool used at work to see if it would perform better. In our framework the `Proto::Net::Message` object is constructed with a `mode` parameter to determine if it will include reading or writing functions. i see
<FromGitter>
... this is not possible without dynamic inclusion. thanks for your information!
<straight-shoota>
`errors < ex` returns `Array(exception)` and that gets assigned to `memo`
<FromGitter>
<Sija> Spot on @straight-shoota, thanks! 🙏 👀
<FromGitter>
<naqvis> > sorry, don't mean to assume that. I came to get a better idea on the behavior because it doesn't seem to be documented anywhere. For context, i was trying to port over a webscrapping tool used at work to see if it would perform better. In our framework the `Proto::Net::Message` object is constructed with a `mode` parameter to determine if it will include reading or writing functions. i see this is not possible
<FromGitter>
... without dynamic inclusion. thanks for your information! ⏎ ⏎ Sorry, didn't mean to offend. Though Crystal is heavily influenced by Ruby and some portion of code will run as is in Crystal, but it is advised to re-think and re-design existing code to take advantage of Crystal features. If portion of code is returning diff ... [https://gitter.im/crystal-lang/crystal?at=6086b1d2dc24646812e4dad3]
<FromGitter>
<zorgon_peterson:matrix.org> @naqvis: thank you very much for the advise to use Union!! This works perfectly for what we are doing with this object
<FromGitter>
<naqvis> 👍
<_ht>
Are constants initialized when declared, or when first accessed?
<_ht>
I have created my own enum-type class (I know there is an enum type, but I want something more powerfull), and want to define the elements of the enum as a constant on a class.
<_ht>
However, the side effects of creating these constants don't run untill I first access them
<FromGitter>
<Blacksmoke16> what do you want to do that an enum type cant?
<_ht>
Extend it, add methods, and have any string as value
<FromGitter>
<Blacksmoke16> why dont you just do like `item One, "Do the first thing"`
<_ht>
That's also possible. I just liked "CONST = item value" for my DSL
<_ht>
But if that's not possible, I will look at alternative solutions
<FromGitter>
<Blacksmoke16> or fwiw, just do this
<FromGitter>
<erdnaxeli:cervoi.se> but in your code there is no problem
<FromGitter>
<erdnaxeli:cervoi.se> as soon as any code use Phrases::ONE, the constant will be there
<_ht>
erdnaxeli:cervoi.se Yes, but my code elsewhere assumed that all these constants have been defined and initialized, for use with user input
<FromGitter>
<erdnaxeli:cervoi.se> if you have use case where you never use it but still want it in `.values`, maybe you need another design
<_ht>
Certainly! I just was surprised
<FromGitter>
<erdnaxeli:cervoi.se> yeah it is suprising in your case because the assignement has compilation time side effects, et the assignement is removed if not used, so your macro don't run
<FromGitter>
<erdnaxeli:cervoi.se> I can understand the suprise ^^
<_ht>
Anyway, thanks for look at it.
<_ht>
I'll see if I can find another way that would be nice for my DSL
<FromGitter>
<Blacksmoke16> `item ONE = "Do the first thing"`
<FromGitter>
<Blacksmoke16> could just do `@@consts : Array(self)? = \{{@type.constants}}`, no need to map over it given its already an array
<FromGitter>
<naqvis> yay
<FromGitter>
<Blacksmoke16> `Array(self)` as it'll just be empty
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<naqvis> ❤️
<FromGitter>
<naqvis> this is still a hack as it will break when descendant class don't have any constant ⏎ `class variable '@@consts' of Bar must be (Array(Bar) | Nil), not Array(NoReturn)`
<_ht>
Now that I have read all your changes and ideas, also a special thanks to naqvis!
<_ht>
Very neat solution, and a clear sign I need to study the power of macros way more to become a Crytal wizard like you all!
hendursa1 has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
<FromGitter>
<will> Are the yum repos broken right now? This used to work for me, but started to fail today (the gpg key is saved in a file instead, and appears to not be different from the url one in doc sample) ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=60870e54a9dd556843015974]
<FromGitter>
<riffraff169> hmm, no more rpm repo? i could probably build from source and create my own rpms...
<straight-shoota>
@fdr thanks, I didn't recall that
_ht has quit [Remote host closed the connection]
lolollolololol has joined #crystal-lang
<straight-shoota>
I can't find the spec file source anywhere, though
<lolollolololol>
Hi guys. I'm new with Crystal. I came to ask how well does it perform, and is it any better than it's competition, for e.g: C.
<FromGitter>
<rishavs> How can I use a salt for password generation? The docs are missing for the salt capability. ⏎ Here is a quick example code https://play.crystal-lang.org/#/r/aznl
<FromGitter>
<RespiteSage> @lol It's not going to outperform optimized C in terms of program speed, but it will probably outperform C in terms of readability, development speed, maintainability, and especially developer happiness.
<FromGitter>
<Blacksmoke16> @rishavs im pretty sure `Bcrypt` uses built in salts, which is based on the `cost` arg
<lolollolololol>
You have a fair point. Screw all that pain with C when I can use Crystal.
<FromGitter>
<RespiteSage> One really nice thing with Crystal if you're considering using it instead of C is that it interoperates with C really easily.
<FromGitter>
<RespiteSage> It's very straightforward to make C bindings in Crystal.
<lolollolololol>
That's pretty much with any language, though. Isn't it? It's silly to compare anything with C. And yup, I saw this. Was what attracted me.
<straight-shoota>
@rishavs that `Crypto::Bcrypt::Password` constructor generates a salt value automatically
<straight-shoota>
If you want more control, use `Crypto::Bcrypt`
<lolollolololol>
Question: Crystal handles socket programming very well I would guess?
<FromGitter>
<rishavs> Thanks @Blacksmoke16 and @straight-shoota
<straight-shoota>
lolollolololol, yeah. It pretty much exposes the BSD socket API
<straight-shoota>
it's not very pretty though, but it works
<lolollolololol>
So definitely is performant?
<lolollolololol>
I was willing to use Go, but on the other hand, I don't want to. Crystal's syntax seems pretty straight forward. It's what makes me want to do some socket stuff in it.
<straight-shoota>
yes, in terms of concurrency, performance is pretty good
<straight-shoota>
should be on par with Go
<lolollolololol>
Supports asynchronous I/O as well, I suppose?
<lolollolololol>
So I can do stuff like non-blocking sockets.
<straight-shoota>
yes, all IO is asycn
<lolollolololol>
What does it use by default? epoll? kqueue (guessing this since you mentioned BSD)
<straight-shoota>
Are you by any chance familiar with OBS and package management workflows? :D
<FromGitter>
<fdr> uhhh I touched them once like, a long time ago
<FromGitter>
<fdr> but when I saw you needed multiplatform builds I kinda remembered they specialized in that and so I thought to search first, and, there you were
<FromGitter>
<fdr> I think I messed around with it a bit and decided that, for many, many frustrations, Launchpad was superior, but I don't remember why.
<straight-shoota>
okay
<straight-shoota>
b/c I'm having a hard time even getting started with that :D
<FromGitter>
<fdr> do they have a command line client?
<FromGitter>
<fdr> I think this may have had something to do with my frustration.
<straight-shoota>
yes, osc
<straight-shoota>
it's a bit of a mutant, combining a subversion CLI, build system and remote API
<straight-shoota>
and I couldn't get a local build environment set up, neither with Ubuntu nor openSUSE
<FromGitter>
<fdr> huh. Maybe I'll play with it a tiny bit and see what I can see...
<straight-shoota>
I've resorted to pushing all edits to the server and let it run there
<straight-shoota>
making some progress at least
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
<FromGitter>
<fdr> yeah, that's what I did back in the day. Had a staging project to iterate on some stuff and a real one, when I needed a closer model than what debootstrap could provide (back when I did stuff on Debian mostly)
<straight-shoota>
yeah, so far I have no idea how I'm going to do the Debian packages. Documentation is really scarce. Or not in a way to understand while familiarizing with the whole system.
lolollolololol has quit [Quit: Connection closed]
mteverst has joined #crystal-lang
<mteverst>
Are TCP sockets in crystal non-blocking by default?
<FromGitter>
<riffraff169> what is the best way to create an array of records as a constant?
<FromGitter>
<riffraff169> just something like: ```
<FromGitter>
<riffraff169> that could be done at the module level, i presume, and then a class/object could reference it
<FromGitter>
<tenebrousedge> yup
<FromGitter>
<riffraff169> one thing thats been hard for me to get used to coming from c, code outside of a function/method...because it is all code, even class/module/struct/whatever def
<FromGitter>
<tenebrousedge> it's also not a terrible idea to do like `HASH = db_setup_method`
<FromGitter>
<tenebrousedge> or `HASH = db_setup_method("myfile.yaml")`
<FromGitter>
<riffraff169> yeah, but that just really moves the initialization from top level into a function, but still have to init the same
<FromGitter>
<tenebrousedge> yes but it's easier to test in a method
<FromGitter>
<riffraff169> unfortunately trying to keep the data static in the binary
<FromGitter>
<riffraff169> so when distributing there is only one file, not the binary plus a whole data directory
<FromGitter>
<tenebrousedge> ah right, you're using a macro to do this
<FromGitter>
<tenebrousedge> but you can still write a macro that takes the YAML file as an argument
<FromGitter>
<riffraff169> yeah, i mentioned this yesterday, basically just a bunch of constants used to perform calculations...
<FromGitter>
<tenebrousedge> yes, I remember
<FromGitter>
<riffraff169> so.....when building it reads the yaml into the src, which is then baked into the binary
<FromGitter>
<tenebrousedge> yee
<FromGitter>
<riffraff169> i get the idea, im just not sure how to implement that
<FromGitter>
<riffraff169> still learning
<FromGitter>
<tenebrousedge> you want the macro section of the book
<FromGitter>
<riffraff169> plus in the reading, i would want to convert the data from YAML::Any to the proper type so i dont have to do that conversion in the code
<FromGitter>
<riffraff169> ok, ill read up on macros
<FromGitter>
<riffraff169> so i would create a macro method, then call the method ....but, and here is where my understanding kind of ends, how do you keep the call to the method from happening normally, and only run at compile time?