jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<raz> eh, yea sorry, actually the parsing needs more work (i'll just do an .includes? for me now, but ultimately you may wanna throw your full-on accept-parser from the other day at it... ;))
<raz> (tldr: browsers send more than just `application/json`, they also append `;charset=` etc.)
sorcus has quit [Quit: WeeChat 3.0]
<FromGitter> <watzon> Yep, and what actually gets included varies widely by browser. The internet is fun.
sorcus has joined #crystal-lang
<raz> yeh, it's only a quick bandaid for now anyway (cause i don't feel like patching axios.js to send a non-json format). for real json support it also needs to deal with nesting. fun indeed... :(
<raz> (or well, hand it through to a proper deserializer)
<FromGitter> <Blacksmoke16> thats already a thing
<FromGitter> <Blacksmoke16> and so what? it already supports that stuff
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe5327a69ee7f0422c0dbc8]
<raz> hm yea i'll take a look at the serializer thing
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe5335093af5216fc6006e8]
<FromGitter> <Blacksmoke16> can deserialize the body, run any validations on it, and provide the obj as the argument
<FromGitter> <Blacksmoke16> object constructor thing is also pretty neat for `PUT` endpoints as if it has an `id` field, it can lookup the record in the db and apply the changes to it, so it retains timestamps and stuff
<raz> yeh, with these abstractions i just always have to figure out how to get my context into the right places. whether and how "apply" should run may depend on a bunch of things (e.g. the authed user)
<FromGitter> <Blacksmoke16> you have options
<raz> i'm sure i do. it's just hard to see them in between all the boilerplate ;)
<FromGitter> <Blacksmoke16> *lies*
<raz> well, when all the business logic is spread out over a complex mesh of ParameterConverters, Serializers, Validators, with actual method body basically empty, i just find it hard to follow it anymore
<FromGitter> <Blacksmoke16> i mean all the business logic should be in the model
<FromGitter> <Blacksmoke16> the pram converters/serializers are generic and not specific to one type
<raz> in practice they usually are
<FromGitter> <Blacksmoke16> not if you design them right
<raz> well, i'll take a peek, but remain skeptical ;)
<FromGitter> <Blacksmoke16> single responsibility principle my friend
<raz> when all you have is a hammer, everything starts to look like a thumb :p
<FromGitter> <Blacksmoke16> we're not at 1000 layers yet tho 😉
<FromGitter> <Blacksmoke16> maybe 10
<raz> well, i'll dabble with the converters and validators a bit. hopefully those ADIs will let me inject my AuthProvider into it :p
<FromGitter> <Blacksmoke16> mhm thats the idea :)
sorcus has quit [Ping timeout: 258 seconds]
<FromGitter> <Blacksmoke16> `Error: can't restrict Tuple() to Indexable(String)` hmm
<FromGitter> <Blacksmoke16> `priorities : Indexable(String) = Tuple.new`
<FromGitter> <Blacksmoke16> i guess it makes sense
<FromGitter> <AlexCouch> Hey guys. I'm trying to write a server implementation with fibers and I need to know how I can poll for incoming connections with a TCPServer. It seems like the poll or epoll functions haven't gotten any bindings. Why is that? I've tried to set blocking to false so that accept doesn't block, but it still blocks. My fibers can't run if it's blocking everything. I've marked it as listening and still nothing.
<FromGitter> ... How come I can't call poll on a socket?
<FromGitter> <AlexCouch> Maybe I'm just missing something. I'll put my code ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe54747ce40bd3cdbff03a1]
<FromGitter> <AlexCouch> Sorry about the indentation
<FromGitter> <AlexCouch> I would like to just check if there are any incoming connections, and if not, just yield and try again after the scheduler resumes us
<FromGitter> <AlexCouch> Actually, as I'm using a test client to connect to it, there's no connection at all. I'm starting to wonder if it's a firewall issue. Not sure what's so different between the last time I ran it yesterday and now. Maybe something on my host machine failed or something. I'm gonna try and run the test client and server on my raspberry pi instead and see how that works. Maybe WSL is just throwing a fit today.
<FromGitter> <AlexCouch> Connection refused?
<FromGitter> <Blacksmoke16> Can't just use the std lib http server?
<FromGitter> <AlexCouch> It's not an http server tho. It's strictly tcp
<FromGitter> <AlexCouch> It was working yesterday. No problems. No blocking. Then now today it's just woopdeedoo. Maybe it's a firewall thing. I'll restart my machine.
<FromGitter> <Blacksmoke16> Fair enough
<FromGitter> <AlexCouch> Okay I'm an idiot. I just realized that I removed an old parameter to the server class and forgot to change the call to new. I was passing the old argument and it ended up going into the port.
<FromGitter> <AlexCouch> That's why my client couldn't connect
<FromGitter> <AlexCouch> Yep! Everything is fine!
<FromGitter> <Blacksmoke16> 👍
woodruffw has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 258 seconds]
<FromGitter> <AlexCouch> Is there any way I can poll a connected client? I can't seem to find any documentation on it for crystal. Can't I somehow select or poll? Looks like IO#select was once a method but not anymore due to its blocking nature. Any other way I can just poll a client to see if it's still connected? I tried peek but that didn't seem to solve my issue. I don't wanna close it prematurely while it still might send me a
<FromGitter> ... query. I need it alive until it disconnected.
<FromGitter> <AlexCouch> I tried setting the keepalive probes but that didn't seem to do much for me, and the they lack proper docs that explain to me what they do and why I would need to use them. Unless I didn't wait long enough but still I didn't find many results from using it.
<FromGitter> <AlexCouch> I know that calling read and it returns 0 means that there's nothing...maybe I'm overthinking it
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <AlexCouch> I guess the peek works
badeball has quit [Ping timeout: 260 seconds]
badeball has joined #crystal-lang
wmoxam has quit [Ping timeout: 260 seconds]
wmoxam has joined #crystal-lang
_whitelogger has joined #crystal-lang
entel has joined #crystal-lang
_whitelogger has joined #crystal-lang
_ht has joined #crystal-lang
<hightower2> Hey where can I quickly look up the characters allowed in a method name?
<hightower2> (or the rules for method names rather)
<hightower2> actually n/m, figured out what I'm gonna do
<raz> hightower2: `curl -s http://ix.io/2JtG | tee crystal_method.cr # && crystal crystal_method.cr`
<hightower2> ;-))
<hightower2> good one :)
<raz> :D
sorcus has joined #crystal-lang
sorcus has quit [Quit: WeeChat 3.0]
ua_ has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
_whitelogger has joined #crystal-lang
postmodern has quit [Quit: Leaving]
sorcus has joined #crystal-lang
hightower2 has quit [Ping timeout: 260 seconds]
avane has quit [Ping timeout: 240 seconds]
avane has joined #crystal-lang
<oprypin> why does VS Code highlight `it` as a keyword? it isn't
<oprypin> oh it also highlights `property!` 😩
<Andriamanitra> what is "it" if not a keyword? it sure behaves like one
<FromGitter> <Blacksmoke16> It's a method
duane has quit [Ping timeout: 240 seconds]
<FromGitter> <jrei:matrix.org> Yes, a method from the global namespace
<FromGitter> <Blacksmoke16> only if you add a `require "spec"`*
_ht has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
r0bby has quit [Ping timeout: 272 seconds]
r0bby has joined #crystal-lang
<FromGitter> <drum445> hi guys, what's the best way to check if a db connection is still alive? Currently I'm doing `conn.query "select 'a' 'a' from dual" { |rs| }` but would prefer a conn.ping type of method
<FromGitter> <drum445> also Merry Christmas
<FromGitter> <Blacksmoke16> for what reason? If you're going thru a `DB::Database` instance retries and timeouts are handled behind the scenes
<FromGitter> <drum445> It does indeed, however, even with a config string that looks like `"?max_pool_size=50&initial_pool_size=10&max_idle_pool_size=10&retry_attempts=3"` I still saw a maria conn issue where I shouldn't have
<FromGitter> <drum445> so I'm adding a manual retry system just so I can see when it occurs
<FromGitter> <Blacksmoke16> even with that config if the db is down for more than 3 sec it would still fail
<FromGitter> <Blacksmoke16> as default retry time is 1s
<FromGitter> <drum445> I added `retry_delay` and it doesn't seem to have any impact. A `DB::ConnectionRefused` error is still raised instantly
<FromGitter> <Blacksmoke16> and the db is started by the time it goes to connect?
<FromGitter> <drum445> yeah, it is a web app and I have a static class instance that is lazily loaded ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe67c20ac9d8e7463d059e6]
<FromGitter> <drum445> Then all repos that need a db connection just call DBHelper.maria - which works great as DB.open is a pool
<FromGitter> <Blacksmoke16> i dont suppose maria db needs anything specific if you're just using mysql driver?
<FromGitter> <drum445> if the db goes down for a few seconds then comes back, all requests after the DB comes back will work perfectly, the problem is while the DB is down, I would like it to try to reconnect for a few seconds before returning a 500 due to the DB exception
<FromGitter> <drum445> nah don't think so mate
<FromGitter> <drum445> Rolling my own retry system is trivial, just a for loop with a sleep - but was just curious