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
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
zorp has joined #crystal-lang
Liothen has quit [*.net *.split]
r0bby has quit [*.net *.split]
Stephie has quit [*.net *.split]
r0bby has joined #crystal-lang
Liothen has joined #crystal-lang
Stephie has joined #crystal-lang
ryanprior has quit [Read error: Connection reset by peer]
return0e[m] has quit [Remote host closed the connection]
hamoko[m] has quit [Read error: Connection reset by peer]
<FromGitter> <plainas> mmm..... undefined method 'as_s' for Array(JSON::Any)
<FromGitter> <plainas> what am I getting wrong from the docs?
<FromGitter> <Blacksmoke16> you have an array, you trying to say its a string
<FromGitter> <Blacksmoke16> do you mean like `array.map &.as_s`?
r0bby has quit [Ping timeout: 270 seconds]
raz has quit [Ping timeout: 264 seconds]
r0bby has joined #crystal-lang
psydroid has joined #crystal-lang
raz has joined #crystal-lang
<FromGitter> <plainas> I am using kemal, and reading a json object. It deserializes fine if I print it I get this
<FromGitter> <plainas> {"user" => "asd", "message" => "ssss"}
<FromGitter> <plainas> but each of those entries is still JSON::Any
<FromGitter> <Blacksmoke16> right
<FromGitter> <plainas> how do I convert to string?
<FromGitter> <Blacksmoke16> like a json string?
<FromGitter> <plainas> no
<FromGitter> <plainas> a given hash entry
<FromGitter> <Blacksmoke16> assuming `hash` is a `JSON::Any`
<FromGitter> <Blacksmoke16> `hash.as_h["user"].as_s`
<FromGitter> <plainas> which it is. As per error message
<FromGitter> <Blacksmoke16> not really, the error says you have an array of something
<FromGitter> <Blacksmoke16> in which case it would be more like
<FromGitter> <Blacksmoke16> ```arr.as_a.each do |hash| ⏎ puts hash.as_h["user"].as_s ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f20ccb83eef7e1ffe3e366d]
<FromGitter> <Blacksmoke16> you should look into https://crystal-lang.org/api/0.35.1/JSON/Serializable.html
<FromGitter> <plainas> oh... I didn't see that part actually
<FromGitter> <Blacksmoke16> mhm
return0e[m] has joined #crystal-lang
ryanprior has joined #crystal-lang
hamoko[m] has joined #crystal-lang
<FromGitter> <wyhaines> @plainas The use of Serializable makes parsing JSON (or YAML), with a structure that you know in advance, really nice. You can define the structure and the parsing behavior in one or more easily read and understood classes.
zorp has quit [Ping timeout: 244 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 272 seconds]
<FromGitter> <plainas> @wyhaines yea I am reading kemal guides and there's an example of deffining JSON.mapping
<FromGitter> <plainas> works, but I get a deprecation warning.
<FromGitter> <plainas> looks like many things on kemal use deprecated apis. As warned, the core API has is still expected to have breaking changes
<FromGitter> <plainas> I might remove kemal and just use the core HTTP module directly. I love kemal but things are changing too fast for it to keep up. I've last used crystal 1.5 years agora. *Many* things have changed since
HumanG33k has joined #crystal-lang
zorp has joined #crystal-lang
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
heidar has joined #crystal-lang
<FromGitter> <j8r> sure, 1.5 years is long for Crystal
<FromGitter> <j8r> But https://github.com/kemalcr/kemal/pull/570 should have fixed all the deprecations, have you an up-to-date Kemal?
<FromGitter> <Blacksmoke16> could switch to another framework. Have plenty of options these days
<raz> guerilla marketing detected :p
<raz> (but yes, would at least refrain from starting new things with kemal atm)
<FromGitter> <Daniel-Worrall> Json.mapping is part of the guide in the docs which gives deprecation warnings. I believe that's what they meant
<FromGitter> <ImAHopelessDev_gitlab> did someone mention json.mapping?? i'm here!!
hamoko[m] has quit [Quit: Idle for 30+ days]
<FromGitter> <j8r> ha yeah the guide can be outdated
<FromGitter> <j8r> @ImAHopelessDev_gitlab You're still in Crystal 0.30?
early` has joined #crystal-lang
Human_G33k has joined #crystal-lang
<FromGitter> <plainas> Yeah that is what I mean. I kind of like JSON.mapping better than serializable. more minimal syntax. Doesn't achieve the same as serializeable, but I like it
early has quit [Quit: Leaving]
HumanG33k has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> how you figure its more minimal? serializable is just 1 line plus the properties you have
<FromGitter> <j8r> The most minimal is definitely https://github.com/j8r/crystalizer :P
<FromGitter> <j8r> But not in the stdlib ofc
<FromGitter> <dscottboggs_gitlab> > (but yes, would at least refrain from starting new things with kemal atm) ⏎ ⏎ Any particular reason?
<FromGitter> <j8r> Now there are better maintained, designed, and stable enough web frameworks
<FromGitter> <dscottboggs_gitlab> hm, yeah I listened to @Blacksmoke16's talk on Athena on the podcast and I have to admit to being pretty sold
<FromGitter> <dscottboggs_gitlab> never been a huge fan of Lucky or Athena though
<FromGitter> <j8r> There is also Gripen: https://github.com/grip-framework/gripen
<FromGitter> <j8r> basically a Kemal++
sagax has quit [Read error: Connection reset by peer]
<FromGitter> <dscottboggs_gitlab> nice 👍
<FromGitter> <brunto> Hi everyone, I’m looking for a way to update the year of a Time `morning_start = Time.parse(start_at, "%R", Time::Location.load("Europe/Berlin"))` I looked to the Crystal API without finding smtg!
<FromGitter> <dscottboggs_gitlab> morning_start += 1.year
<FromGitter> <Blacksmoke16> i.e. get a new `Time` instance that is 1 year inthe future?
<FromGitter> <Blacksmoke16> ^
<FromGitter> <brunto> Hummm @dscottboggs_gitlab I want to set a specific year ;)
<FromGitter> <brunto> @Blacksmoke16 I think you’re right I need to create a new instance
<FromGitter> <Blacksmoke16> you do, Times are structs so are immutable
<FromGitter> <dscottboggs_gitlab> Yeah you'll need to manually call `Time.local year: my_year, month: morning_start.month, ......., location: Time::Location.load "Europe/Berlin"`
* FromGitter * Blacksmoke16 senses this would be a good use case for adding that `copy_with` method that `record` defines
<FromGitter> <dscottboggs_gitlab> yeah I definitely think this deserves a patch of some kind.
<FromGitter> <Blacksmoke16> whats the use case actually?
<FromGitter> <brunto> It’s for recording tstzrange
<FromGitter> <brunto> it’s works like this: `morning_start = Time.local(1970, 1, 1, morning_start.hour, morning_start.minute, 0, location: Time::Location.load("Europe/Berlin"))`
<FromGitter> <dscottboggs_gitlab> > tstzrange ⏎ ⏎ What?
<FromGitter> <dscottboggs_gitlab> you're trying to JUST store time and TZ?
<FromGitter> <brunto> I need to record a tstzrange inside the DB
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <brunto> But it’s works like this, thx ;)
<FromGitter> <Blacksmoke16> not sure i follow, so like a time span?
<FromGitter> <dscottboggs_gitlab> well, like a time span representing a time from midnight with the TZ encoded too
<FromGitter> <brunto> I haven’t tried Time::Span I will
<FromGitter> <dscottboggs_gitlab> that's not a type Crystal has in the stdlib
<FromGitter> <dscottboggs_gitlab> TBH I think you should define a custom type which stores a second offset and `Time::Location`
<FromGitter> <brunto> I do a raw query with: `INSERT INTO opening_times (type, day_of_week, during) VALUES ('StoreOpeningTime', 1, tstzrange('1970-01-01 07:00:00 +01:00', '1970-01-01 11:00:00 +01:00', '[]'));` it works like a charm.
<FromGitter> <dscottboggs_gitlab> oh i see, yeah I guess that can work
<FromGitter> <Blacksmoke16> still would think it would be easier to use `Time::Span`
<FromGitter> <brunto> I confirm it works
<FromGitter> <brunto> @Blacksmoke16 I think too, I’ll try
<FromGitter> <wontruefree> I posted the Jeremy Woertink interview on youtube if anyone is interested and does not listen to podcasts https://youtu.be/rQ16_IdjIjE
<FromGitter> <Blacksmoke16> or if anything work with `Time::Span` and have some private method that generates the correct string to use in the query
<FromGitter> <dscottboggs_gitlab> Thanks for what you do @wontruefree, keep it up!
<FromGitter> <wontruefree> You are welcome! I am glad you enjoy it
<FromGitter> <Blacksmoke16> > never been a huge fan of Lucky or Athena though ⏎ ⏎ Depending on when you last gave it a look, its come a long way
<FromGitter> <dscottboggs_gitlab> yeah it has been probably almost a year
<FromGitter> <Blacksmoke16> wew
<FromGitter> <Blacksmoke16> yea deff has evolved quite a lot since then
<FromGitter> <dscottboggs_gitlab> yeh wouldn't exactly be fair to judge athena by its state that long ago 😅
<FromGitter> <Blacksmoke16> https://athena-framework.github.io/athena/Athena/Routing.html#getting-started gives a pretty good overview
<FromGitter> <RespiteSage> @brunto There's this solution, but it's a little hacky: https://carc.in/#/r/9gvs
<FromGitter> <RespiteSage> If I'm understanding what you were asking correctly.
zorp has quit [Ping timeout: 256 seconds]
zorp has joined #crystal-lang
Stephie has quit [Quit: Fuck this shit, I'm out!]
Stephie has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <christopherzimmerman> Is there a good way to capture a generic expression for parsing? ⏎ I want to do something like this: ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5f22057fd7efe5438f2d52b9]
zorp has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> I doubt it
<FromGitter> <Blacksmoke16> Maybe using a macro