RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
nkts has joined #crystal-lang
marius has quit [Ping timeout: 244 seconds]
nkts has quit [Client Quit]
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <iambudi> What is the best way to initialize class var like this : `@server : HTTP::Server = ?`
<FromGitter> <bew> Not inline in the class, but initialized through the `initialize` method (you'd create your `HTTP::Server` before initializing the object)
<FromGitter> <iambudi> I need to assign later not in custructor. Seems i need to use nil first.
wakatara has joined #crystal-lang
<wakatara> Hey Crystal peeps... I am looking a shard close to Go's Cobra that peopel have actually delivered production CLI apps with and was also wondering if there was something like gopakager so that I can automate the creation of binaries for brew and apt when I get this thing finished. Does anyone have strong opinions?
<wakatara> (basically, finding myself way more productive in Crystal than Go, so trying to fill in gaps I currently have.)
<FromGitter> <Blacksmoke16> the std lib has https://crystal-lang.org/api/0.27.2/OptionParser.html but i remember seeing some shards that add additional functionality
<wakatara> Blacksmoe16: Yep, seen a few of those but some seem in various states of array/usefulness. Is there a _de facto_ one people normally reach for like Cobra in the Go community?
<wakatara> Blacksmoke16: Yep, seen a few of those but some seem in various states of array/usefulness. Is there a _de facto_ one people normally reach for like Cobra in the Go community?
<FromGitter> <Blacksmoke16> not that i know of, crystal is a bit too new to have the *de facto* anything really
<wakatara> Lol. OK< fair enough. What would you use given needing a CLI app of not much complexity but requiring more structure than an options parser?
<wakatara> Thank you (I had seen that) but was wondering what was actually being used by the community. Some of them have not ben updated in years (so not sure if just stable/solid) or not in use. Admiral defintely seems to be the most mature and recently updated.
<wakatara> How do people generally package/update their apps for brew and apt and such (since, you know... binaries... ).
<FromGitter> <Blacksmoke16> :shrug:
<wakatara> =]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 250 seconds]
<FromGitter> <iambudi> i try to use bind_tls on HTTP::Server, the key and cert file checksum has no problem, but crystal throws error like this. Any clue to solve this?
<FromGitter> <iambudi> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c848fbbc8e5bc516216e592]
<FromGitter> <iambudi> i use self-signed certificate for localhost generated using openssl on mac
wakatara has quit [Remote host closed the connection]
<FromGitter> <iambudi> @bew this one work for empty initializing `@server : HTTP::Server = HTTP::Server.new { }`
chemist69 has quit [Ping timeout: 258 seconds]
chemist69 has joined #crystal-lang
marmotini_ has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
marmotini_ has quit [Ping timeout: 245 seconds]
marmotini_ has joined #crystal-lang
mntmn has quit [*.net *.split]
lesderid has quit [*.net *.split]
<FromGitter> <r00ster91> How can `@@int` be possibly `nil` here? https://carc.in/#/r/6gos
<z64> because it has no value until you call the method
<z64> which you might never do
<z64> and the type doesn't allow that
<FromGitter> <r00ster91> but when I will never call the method then I will also never add 1 to @@int which is the cause of the compile error
<FromGitter> <r00ster91> but when I will do it then I clearly assign a value to `@@int`. The compiler is probably not that smart
<FromGitter> <redcodefinal> Hey do you guys have any suggestions on ways to get the local ips from all network interfaces?
<z64> yes, it is not that smart. everything must be typed at compile time, and method calls are not considered like that. you must `@@int = 10` at the module level to default it at compile time
<z64> basically a similar reason that this doesn't compile https://carc.in/#/r/6gpa
ua has quit [Ping timeout: 255 seconds]
ua has joined #crystal-lang
crystal-lang564 has joined #crystal-lang
marmotini_ has quit [Ping timeout: 244 seconds]
ashirase has quit [Ping timeout: 250 seconds]
ashirase has joined #crystal-lang
crystal-lang564 has quit [Quit: Konversation terminated!]
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 268 seconds]
blassin has quit [Quit: The Lounge - https://thelounge.chat]
marmotini_ has joined #crystal-lang
smurfendrek123 has joined #crystal-lang
<smurfendrek123> Hello, how do i search an array for occurence of a certain element?
<z64> there's a few methods depending on what you want to do. if you want to fetch a single element, `array.find`; if you want all occurances, `array.select`. there is also `array.any?`. most of these methods come from Enumerable, which array is a descendent of https://crystal-lang.org/api/0.27.2/Enumerable.html
<smurfendrek123> z64, I would like to get the index of the element, would that be possible?
<z64> certainly https://crystal-lang.org/api/0.27.2/Enumerable.html#index%28%26block%29-instance-method
blassin has joined #crystal-lang
<FromGitter> <bew> @iambudi sure but usually you want a more complex `HTTP::Server` instance, which might be hard to initialize inline in the ivar declaration
DTZUZO has quit [Ping timeout: 245 seconds]
ua has quit [Ping timeout: 244 seconds]
<smurfendrek123> Is there a good way to cast a (Int | Nil) type to Int?
ua has joined #crystal-lang
<Groogy> is there a good handy way to duplicate the content of an array?
<Groogy> smurfendrek123 to get that type to an Int, resolve it by testing it in an ifstatement
<smurfendrek123> Groogy, there is a clone method for arrays, and also a dup method
<Groogy> No I mean, duplicate the content as in, I have 1 2 3 and I want 1 2 3 1 2 3
<smurfendrek123> Groogy, but how do i return that type? I now have: if index!= nil return index end
<smurfendrek123> but the type is still Int | Nil
<Groogy> because if index is nil then you go past that return and return nil
<Groogy> you need to raise an exception or return a number
<smurfendrek123> Groogy i do that, i raise an indexerror
<smurfendrek123> Groogy, could you send me an example of how to remove the nil?
<Groogy> show the code from pastebin or play.crystal-lang.org
<FromGitter> <r00ster91> `1_f32` does nothing, right? I'm not really sure because there's no `self` returned anywhere here: https://github.com/crystal-lang/crystal/blob/60760a5460aa13a1f80c5a1a7410782dc4076b77/src/primitives.cr#L269.
<FromGitter> <r00ster91> 1_f32.to_f32 I mean
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
<smurfendrek123> https://pastebin.com/T6GLnapK Groogy
<Groogy> yeah that should work
<Groogy> try swapping out index != nil with just simply testing index if it's true
laaron has joined #crystal-lang
mntmn has joined #crystal-lang
<smurfendrek123> Groogy, thanks!
<Groogy> Guessing it's just the compiler not seeing that properly
<Groogy> you can also do index.nil?
<Groogy> that should also work
<Groogy> if you want it to be more readable english
<smurfendrek123> Groogy, yup, thanks!
<FromGitter> <bew> smurfendrek123: usually you can write `if index = @column_names.index { |col| col == name }` and in the `if` branch, do something with `index`
<Groogy> ah yeah that will work as well
<FromGitter> <drum445> Hi Guys, when using ERB/Crinja I am having troubles with paths. If I have an anchor that looks like ⏎ `<a href="/person/login">Login</a>` ⏎ This works locally as my app is listening on /, however when I run it on my server behind nginx, which has the app listening on /myapp1/ it obviously is a 404. ⏎ I've been setting a root var which will be "/" locally and "/myapp1/" on the server and passing it to the
<FromGitter> ... template: `<a href="{{root}}person/login">Login</a>` [https://gitter.im/crystal-lang/crystal?at=5c84fc97d3b35423cb962302]
<FromGitter> <drum445> Is that a good way of dealing with this scenario, or is there a better way?
lucasb has joined #crystal-lang
_whitelogger has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
lucasb has quit [Read error: Connection timed out]
lucasb has joined #crystal-lang
_whitelogger has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
Groogy has quit [Read error: Connection reset by peer]
Yxhuvud has joined #crystal-lang
marmotini_ has quit [Ping timeout: 250 seconds]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 244 seconds]
<FromGitter> <TheOnlyArtz> Sounds like a good way, it won't be a security vulnerability as I see it, so you're probably fine :)
<FromGitter> <TheOnlyArtz> I got a question: Is there a convenient way of constructing JSON strings without using an IO? because it looks odd to create an IO for such a basic task
<z64> not sure what you want to do exactly. `JSON.build` returns a new string, as well as `Object#to_json` with no arguments
<FromGitter> <TheOnlyArtz> I'm using websockets for each room game, I want to send JSONs to the frontend
<FromGitter> <TheOnlyArtz> So like ⏎ ⏎ ```{ ⏎ "op": "new_player" ⏎ }``` [https://gitter.im/crystal-lang/crystal?at=5c852d18d1e7281f09076922]
<FromGitter> <r00ster91> You could build this JSON using `JSON.build`. You don't need an IO for it.
<z64> you can just call `.to_json` on that object..
<FromGitter> <TheOnlyArtz> It doesn't work
<FromGitter> <TheOnlyArtz> I tried doing Hash(String, String).to_json
<FromGitter> <TheOnlyArtz> You said it like I could call `to_json` on everything :)
<FromGitter> <TheOnlyArtz> Thanks
<z64> i said you could call `Object#to_json` - an *instance* of an object. Hash(String, String) is a class
<z64> which of course, contains no data (what would be serialized?)
<FromGitter> <TheOnlyArtz> I had something like ⏎ ⏎ ```a = {"a" => "s"} ⏎ ⏎ puts a.to_json``` [https://gitter.im/crystal-lang/crystal?at=5c852e84f895944c087072f5]
<z64> yes thats fine
<FromGitter> <TheOnlyArtz> ```Error in line 3: undefined method 'to_json' for Hash(String, String)```
<z64> did you not `require "json"` ?
<FromGitter> <TheOnlyArtz> uh no
<FromGitter> <TheOnlyArtz> ok now it works
smurfendrek123 has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
crystal-lang564 has joined #crystal-lang
<FromGitter> <drum445> @TheOnlyArtz ty
crystal-lang564 has quit [Quit: Konversation terminated!]
crystal-lang564 has joined #crystal-lang
<FromGitter> <TheOnlyArtz> Can I assign a macro to a class?
<FromGitter> <TheOnlyArtz> @drum445 np btw
<FromGitter> <r00ster91> yes you can
<FromGitter> <TheOnlyArtz> How so?
<FromGitter> <r00ster91> Why shouldn't it work? https://carc.in/#/r/6gs8
<FromGitter> <r00ster91> no without `self.`
<FromGitter> <TheOnlyArtz> Oh alright
<FromGitter> <r00ster91> a macro is a class "method" by default
<FromGitter> <TheOnlyArtz> Nice
<FromGitter> <r00ster91> because calling it on an instance doesn't make any sense
<FromGitter> <TheOnlyArtz> My macro syntax is wrong on so many levels lmao
<FromGitter> <TheOnlyArtz> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c853c581c597e5db6b570fc]
<FromGitter> <TheOnlyArtz> Can I get a code review again real quick? the code expanded on the backend part a lot (see: racer/router.cr) ⏎ https://github.com/TheOnlyArtz/racer
marmotini_ has joined #crystal-lang
<FromGitter> <r00ster91> @TheOnlyArtz I've added some comments
<FromGitter> <TheOnlyArtz> reading them rn
<FromGitter> <r00ster91> It's a bit annoying that you can't just add comments to a line in a file without switching to a commit which is in the range of the line you want to add a comment to
<FromGitter> <TheOnlyArtz> It's even more annoying to read through since I don't see the relevant lines
<FromGitter> <r00ster91> oh I thought you might get notifications
<FromGitter> <TheOnlyArtz> What did you mean here?
<FromGitter> <TheOnlyArtz> What macros are useless?
<FromGitter> <TheOnlyArtz> The assign_x?
<FromGitter> <r00ster91> yes
<FromGitter> <r00ster91> assign_room and assign_player
<FromGitter> <j8r> g4
Groogy has joined #crystal-lang
marmotini_ has quit [Ping timeout: 268 seconds]
marmotini_ has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
crystal-lang564 has quit [Quit: Konversation terminated!]
marmotini_ has quit [Ping timeout: 245 seconds]
marmotini_ has joined #crystal-lang
<FromGitter> <vladfaust> Hey, folks, I've finally managed to finish a solid part of Onyx docs. Give it a shot and tell me if anything is wrong, please -- https://docs.onyxframework.org/
<FromGitter> <bew> This is amaazing.. where do you find the time to do all this?
<FromGitter> <j8r> great job @vladfaust 🚀
<FromGitter> <vladfaust> The major docs commit is 14,893 additions and 1,216 deletions 💥
<FromGitter> <vladfaust> Well, Crystal is my full-time job. I've spent 167 hours on Onyx this month
<FromGitter> <vladfaust> I'm having plans on a service not about Crystal but it would be built on it
<FromGitter> <bew> oh! self-employed or in a company?
<FromGitter> <vladfaust> Let's call it "self-hoping-for-the-best"
<FromGitter> <bew> well I hope it'll work, great job on onyx at least ;)
<FromGitter> <vladfaust> Thank you, @bew! And thank you, @j8r =)
lucasb has quit [Quit: Connection closed for inactivity]
<mps> vladfaust: very nice and good docs
<FromGitter> <vladfaust> Nah, you couldn't have read them all by now 😀
<mps> I didn't, but intro was enough to see quality
<FromGitter> <vladfaust> Well, thanks. I tried hard :)
<FromGitter> <vladfaust> I mean, English isn't my native
<mps> nor it is my, when you rewrite it in your native language I will enjoy reading it :)
marmotini_ has quit [Ping timeout: 245 seconds]
<FromGitter> <alex-lairan> Hello ! :) ⏎ ⏎ I want to do something like C++ Frienship. ⏎ ⏎ I have a class *Button* who is friend to *ButtonConfig*, so *ButtonConfig* can manipulate *Button* but nobody else can. ... [https://gitter.im/crystal-lang/crystal?at=5c85815706dbbf24254d2d36]
<oprypin> alex-lairan, this is usually achieved by putting them in the same module and applying visibility restrictions
<oprypin> to methods
<FromGitter> <alex-lairan> Oh, by using `protected` ?
<oprypin> i think so
<FromGitter> <malkomalko> Anybody know how to get the offline docs/api setup?
<FromGitter> <Blacksmoke16> like https://crystal-lang.org/api/0.27.2/ that format?
<FromGitter> <bew> @malkomalko for offline API, you can clone the crystal repo, and run `crystal doc`, then open your browser on `docs/index.html`
<FromGitter> <alex-lairan> Seem's work with `yield Config.new(self)` ⏎ ⏎ But with `with Config.new(self) yield` I got a strange error : ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c85857b1fae6423ca63d6a3]
<FromGitter> <bew> @alex-lairan could you show a complete code example of the pb?
<FromGitter> <alex-lairan> I create a carc :)
<oprypin> malkomalko, https://pryp.in/crystal
<FromGitter> <alex-lairan> https://carc.in/#/r/6gt1
<FromGitter> <malkomalko> Thanks everybody for the suggestions
<FromGitter> <bew> @alex-lairan it's a bug.. it works when not in an `initialize` method https://carc.in/#/r/6gt5
<FromGitter> <alex-lairan> Oh :( That's not cool ^^ ⏎ ⏎ I open an issue :) ⏎ ⏎ Let's use `self.create`, I like this name ;) [https://gitter.im/crystal-lang/crystal?at=5c858908bf7990126e80ce2e]
<FromGitter> <bew> 👍 :)
<FromGitter> <alex-lairan> It's a known issue : https://github.com/crystal-lang/crystal/issues/4436
<FromGitter> <Blacksmoke16> so im trying to get an executable to run on `shards install` but its not actually running it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c858b75e527821f0a388ae4]
<FromGitter> <Blacksmoke16> which builds and adds the correct file to `./bin` but never gets ran
<FromGitter> <Blacksmoke16> which i should be able to do?
Groogy has quit [Quit: WeeChat 2.4]
<FromGitter> <Blacksmoke16> use case is creating a config file on install
<FromGitter> <bew> @Blacksmoke16 are you sure it doesn't run?
<FromGitter> <bew> `shards` hide the output, but it should run
<FromGitter> <Blacksmoke16> ah welp, then using `puts` as an indication of it running would be a useless idea ha
<FromGitter> <bew> indeed^^ would be nice to have a `interactive: true` for the postinstall script if you need to get user input and display some stuff
<FromGitter> <Blacksmoke16> 💯
<FromGitter> <Blacksmoke16> also might be an issue with using the `path` requirement vs getting it from github
<FromGitter> <bew> I don't think so
<FromGitter> <bew> but I guess it's also important that `shards install` is fully automated and doesn't hang.. so I guess if you want interactivity you'd have to write litle doc to tell the users to run it manually
<FromGitter> <Blacksmoke16> well when i use `path` in my `dependencies:` in `shard.yml` it doesnt work but when i use `github` it works
<FromGitter> <bew> wut
<FromGitter> <bew> do you uninstall the lib before each try?
<FromGitter> <Blacksmoke16> `rm -rf lib/ bin/ shard.lock athena.yml && shards install`
<FromGitter> <Blacksmoke16> and yea, interactive mode would be hard for CI type stuff, less you can provide a file or something to provide defaults or something
<FromGitter> <bew> yeah but even then, you probably don't want to use defaults..
<FromGitter> <Blacksmoke16> is a bit tricky indeed
<FromGitter> <Blacksmoke16> i know symfony uses `-vvv` on their commands to set the verbosity of the output
<FromGitter> <Blacksmoke16> i.e. number of `v` maps to like `logger.log xxx` -> `logger.verboselyLog xxx` -> logger.veryVerboselyLog xxx`
<FromGitter> <Blacksmoke16> even a `--debug` could be handy to at least not hide the output
<FromGitter> <bew> agree
<FromGitter> <bew> or just `--verbose`, since `--debug` can mean many things for a package manager..
<FromGitter> <Blacksmoke16> yea thats even better
<FromGitter> <Blacksmoke16> oh wait thats a thing already
<FromGitter> <bew> x) it won't show your script output though
<FromGitter> <Blacksmoke16> yea, would be easier to implement since the flag already exists and everything tho
<FromGitter> <bew> `--show-postinstall` \o/
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> anyway i guess there is something happening when using `path` vs github then
<FromGitter> <bew> did you tried with a simple `File.write("foo", "bar") in your `./bin/athena` ?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c859479d1e7281f090a03f7]
<FromGitter> <Blacksmoke16> is what it is
<FromGitter> <Blacksmoke16> ah i see
<FromGitter> <bew> ?
<FromGitter> <bew> it runs for me, with this: `File.write("/dev/tty", Dir.current)`
<FromGitter> <Blacksmoke16> since `path` symlinks it, the file is being created 2 dirs up from the parent dir
<FromGitter> <Blacksmoke16> vs 2 dirs up from the `lib` dir where the shard is being installed
<FromGitter> <Blacksmoke16> would be my guess
<FromGitter> <bew> yeah, think I've found it, `Dir.cd` follows symlinks
<FromGitter> <bew> so when it's run, you're no longer in `lib/athena/`
<FromGitter> <bew> but in the target dir (`path`)
<FromGitter> <Blacksmoke16> yup that would do it
<FromGitter> <bew> (not related to fish, but the idea is explained there)
<FromGitter> <Blacksmoke16> oh well, least it works. be pretty slick
<FromGitter> <bew> true, but it's a bug for me.. Actually I think `shards` should set a var like `ROOT=/path/to/the/root` so that you don't need to play with `../../` etc..
<FromGitter> <Blacksmoke16> a way to access the root of the app the shard being installed for would be nice yes
<FromGitter> <Blacksmoke16> esp if there every comes a way to change the install dir structure or something
<FromGitter> <bew> exactly
<FromGitter> <Blacksmoke16> hrm, even when using absolute path it doesnt get created either?
<FromGitter> <Blacksmoke16> wait nvm, using wrong file
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6gu1 im pretty sure this is a bug?
<FromGitter> <bew> maybe inked to the causes of #7007 ? but definitely weird..
<FromGitter> <Blacksmoke16> i would think it would work due to the default values