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.)
<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?
<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
<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?
<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
<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
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> 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
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> 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> 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>
<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