DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
chachasmooth has quit [Ping timeout: 250 seconds]
chachasmooth has joined #crystal-lang
chachasmooth has quit [Ping timeout: 250 seconds]
chachasmooth has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
hendursaga has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
_ht has joined #crystal-lang
ua has joined #crystal-lang
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 252 seconds]
straight-shoota has quit [Quit: ZNC 1.8.2 - https://znc.in]
jhass has quit [Quit: Bye]
asterite has quit [Quit: Bye]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
straight-shoota has joined #crystal-lang
jhass has joined #crystal-lang
Nekka has quit [Ping timeout: 240 seconds]
Nekka_ has joined #crystal-lang
Nekka_ is now known as Nekka
<FromGitter>
<noaheverett_twitter> Is it possible to parse the TLS Client Hello to get the SNI, setup an OpenSSL context with the correct cert/key based on hostname then handle that connection via a HTTP::Server block? I've been doing some digging in the docs/examples and it seems this is being handled internally, so would a custom TCP/HTTP server needed to be written? ⏎ ⏎ My hope is that I could get the SNI via a TLS Client
<FromGitter>
<tenebrousedge> I have no idea, but I am curious why you want to do this
<FromGitter>
<noaheverett_twitter> @tenebrousedge HTTPS reverse proxy that handles the TLS for a dynamic list of domains 😅
<FromGitter>
<tenebrousedge> this isn't something you can do with existing tools? Traefik maybe?
<FromGitter>
<noaheverett_twitter> @tenebrousedge https://caddyserver.com/ would handle this great, but looking for a more light-weight solution as I need just a small subset of their features and preferable something written in Crystal to tailer to our edge cases...but yes, fallback is probably Caddy
<FromGitter>
<tenebrousedge> Caddy is also great
<FromGitter>
<tenebrousedge> fewer dependencies is good, but having more features available might make development easier later
<FromGitter>
<tenebrousedge> idk
<FromGitter>
<Blacksmoke16> using something like that is prob also more robust longer term. I.e. dont have to maintain it, will have security fixes and such, can spend that time on the actual project
<FromGitter>
<noaheverett_twitter> @tenebrousedge @Blacksmoke16 y'all are probably right....but I love using Crystal! 😆
<FromGitter>
<Blacksmoke16> sometimes it's about using the right tool for the job :)
DTZUZU has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 240 seconds]
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter>
<kaukas_gitlab> Hi! Could you please help me understand what I'm doing wrong? Or is this a Crystal bug? https://play.crystal-lang.org/#/r/b1r5 ⏎ It provides a block with one parameter but Crystal complains that it expects zero.
<FromGitter>
<Blacksmoke16> otherwise it seems to be because you're capturing the blocks, which need to have their input/output values/types defined beforehand as it turns the block into a proc
<FromGitter>
<Blacksmoke16> specifically: ⏎ ⏎ > In the above example the type of &block wasn't specified: this just means that the captured block doesn't take any arguments and doesn't return anything.
<FromGitter>
<riffraff169> is there a best way to select a hash entry based on some keys? like, my var is a hash of structs, and i want to select a specific hash entry based on `mystruct.value`
<FromGitter>
<riffraff169> does hash respond to select?
<FromGitter>
<tenebrousedge> have you checked the API docs?
<FromGitter>
<tenebrousedge> (and yes, it does)
<FromGitter>
<riffraff169> i could just do a `.each` and compare and return the one that matches, but that seems unintuitive
<FromGitter>
<Blacksmoke16> not sure i follow. If you have a hash of `String, Hand` then you'd need to just do `hash["key"]` no?
<FromGitter>
<tenebrousedge> `find` is a thing
<FromGitter>
<riffraff169> ah awesome ... in Enumerable
<FromGitter>
<Blacksmoke16> is there a reason you cant just do `hash[mystruct.value]`?
<FromGitter>
<Blacksmoke16> iterating over each element seems like a waste if you're using a hash in the first place
<FromGitter>
<riffraff169> because the key is not the same as `mystruct.value`
<FromGitter>
<Blacksmoke16> could you make it the key? or the key is something else already?
<FromGitter>
<riffraff169> it is hashed by a different key, but may need to search for an item based on a key
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<tenebrousedge> I was using a `Hash(Regex, Class)` the other day
<FromGitter>
<tenebrousedge> which `[]` is pretty useless with
<FromGitter>
<tenebrousedge> I needed the associative data structure
<FromGitter>
<tenebrousedge> that it can be key-addressed was irrelevant
<FromGitter>
<riffraff169> this is what i came up with...the relevant part is the find, the last line...
<FromGitter>
<Blacksmoke16> is there only going to be 2 things in the hash? or i assume this is a contrived example?
<jhass>
Array({A, B}) is often the more efficient data structure if you're never going to lookup by key
<FromGitter>
<riffraff169> contrived...just minimal to make it useful
<FromGitter>
<riffraff169> hmm
<FromGitter>
<tenebrousedge> Tuple or Named Tuple are pretty neat too
<FromGitter>
<riffraff169> im still translating the code...i may end up changing if i find i dont have to look up by key
<jhass>
that is unless A needs to be unique
<FromGitter>
<riffraff169> i think i may need to dig in to the code more... it is a java enum, which is a class that has multiple values, almost like a rust enum, sort of, kind of
<FromGitter>
<Blacksmoke16> use a crystal enum? :P
<FromGitter>
<riffraff169> im doing a class that uses a constant hash of the enums.....but if the class doesnt use the enum name then not useful
<FromGitter>
<riffraff169> that really doesnt translate directly to a crystal enum
<FromGitter>
<riffraff169> thats more like a rust enum
<FromGitter>
<Blacksmoke16> it *could* as you can define methods on an enum, then use like `case / in` to return the correct value for the other stuff :shrug:
<FromGitter>
<Blacksmoke16> depends on what the type will be used for id say
<FromGitter>
<riffraff169> this specific enum, the name (`NONE`, `RIGHT`, etc) isnt referenced at all
<FromGitter>
<riffraff169> but others the name of the enum is....so...hmm
<FromGitter>
<riffraff169> i might do some enum experimenting
<FromGitter>
<riffraff169> but those values are what i was using a macro to load into a constant at compile time, like they are present in the java jar
<FromGitter>
<Blacksmoke16> depends on i guess if you need to pass these things around or something
<FromGitter>
<Blacksmoke16> and like mutate them etc, but using an enum looks like a pretty good solution if you just need to associate some static values with a name
<FromGitter>
<riffraff169> one of the enums has like 400 entries, would not like to create a bunch of case statements covering all those possibilities
<FromGitter>
<Blacksmoke16> oof
<FromGitter>
<riffraff169> this is one line in that enum:
<FromGitter>
<riffraff169> sorry, that isnt an enum, just a plain class...hmmm
<jhass>
if I'd got that many constants I'd honestly consider turning stuff into json or yaml write a script to generate crystal code and stuff that into a run macro...
<FromGitter>
<riffraff169> ok, this one with like 20 has this `BATTLE_AXE("Battle Axe", "BA", 15, 3, 7, 9, 4, 16),`
<FromGitter>
<riffraff169> thats what im doing....
<FromGitter>
<riffraff169> so im working on the code that has to work with that
<jhass>
but then it shouldn't matter to generate a case or whatever boring thing
<FromGitter>
<riffraff169> so was using hash, like `WEAPON["BATTLE_AXE"].name == "Battle Axe"`
<jhass>
it's hard to give advice here because we got no clue how any of this data is going to get used
<FromGitter>
<riffraff169> yeah, just all those values (like the battle axe values above) are used to perform calculations...all static data
<FromGitter>
<riffraff169> but some of the enums of like a min and max, and a function will find which item for which the value is within the bounds
<jhass>
that answers the what for not so much of the how :) Not saying it's easy to explain here without getting too deep into the project
<FromGitter>
<riffraff169> like, i have a value 12, which item matches `value >= a.minval && value <= a.maxval`
<FromGitter>
<riffraff169> yeah, im still digging in the code myself....ill have more answers as i get there
<FromGitter>
<riffraff169> i agree, im experimenting...ill have more questions, maybe, as i go along
<FromGitter>
<riffraff169> hopefully ill get better and better at crystal and be able to answer the questions myself, or know how to find the answer i need myself better
<jhass>
I'd probably try to sort stuff into different categories of usage and try to think of a good data structure for each of them separately
<FromGitter>
<riffraff169> and maybe at some point be able to contribute rather than just take
<jhass>
it sounds like you're actually dealing with a quite diverse set of usages
<FromGitter>
<riffraff169> almost all of them are in that kind of format (the data), and several of them sort of use the same pattern....figure out which contains the bounds....i havent encountered all the usages yet
<FromGitter>
<riffraff169> anyway, thanks
<jhass>
just because the author of where you're getting them from picked a particula format doesn't mean it's the best, especially when porting to a new language :)
<FromGitter>
<riffraff169> that is true....i also thought of an array at one time, which might be better for some of it where the enum name isnt used, like the HAND that i can tell
<jhass>
maybe try to remove a dimension of complexity right now and just load them at runtime from json/yaml/whatever and figure out the data structures you need, then you can think about how to generate code to seed those data structures at compile time
<FromGitter>
<riffraff169> that might be better....more top-down than bottom-up, at least with that part...i do tend to use a mixture, but sometimes get stuck in the weeds
<jhass>
I got that impression a little, hence my suggestion to look for simplification/subset of the problem :)
<FromGitter>
<riffraff169> was concentrating on getting the data to stay in the code, when at first i was just trying to get the data in so i can start working on it
<jhass>
make it work, make it fast, make it pretty, in that order not at once :)
<FromGitter>
<riffraff169> yeah
<FromGitter>
<riffraff169> thats true too
<FromGitter>
<riffraff169> ive been programming off and on for about 40 years, but came from a systems engineering side, not software development...so my programming may not be as structured as people who do programming more professionally
<jhass>
Idk, it's a very young discipline. I feel like it's often still more on the personality/personal experience side than on the formal education side. Most people that I know that I consider better than average programmers picked it up way before university
<FromGitter>
<riffraff169> yeah....i started with basic on commodore pet in 81, then c64, then assembly on c64, then c in 89, c++ 92, briefly looked at java in 97 but hated it....ruby, python, crystal, pike, a little rust, go, shell since the 90s...some forth and lisp and fortran...but almost all of it self-study and working with it
<FromGitter>
<riffraff169> was able to write a couple of device drivers for the linux kernel on an embedded system, which was neat
<FromGitter>
<tenebrousedge> dang, that's a lot of languages for someone who isn't a "professional" coder
<FromGitter>
<riffraff169> haha...i like to learn
<FromGitter>
<riffraff169> still, most of my stuff is infrastructure...san storage, networking, security, automation, configuration management, clustering, ha, dr, etc
<FromGitter>
<riffraff169> my last job i knew some software developers who only knew java and c#...so, yeah
<mps>
anyone can point me to example for https client using tls and certificates from files in local FS
<mps>
simple, one source file (if possible)
<mps>
and btw, keys in hash must be quoted even if they are single (and simple) word without special characters?
<FromGitter>
<Blacksmoke16> For a static string key yes. Otherwise without the quotes it would assume it to be a variable
<mps>
aha, understand and reasonable, now :)
<mps>
and this solved my previous question above
postmodern has joined #crystal-lang
<postmodern>
does crystal have an equivalent of IO.console or STDOUT.winsize?
sagax has quit [Remote host closed the connection]