<Andriamanitra>
is adding methods to built-in types a good thing to do in crystal?
<FromGitter>
<naqvis> for project use, shouldn't matter, but if you are developing a shard, then that might confuse users or that might get conflicted with higher versions of language
<FromGitter>
<naqvis> in essence, monkey patching isnt' that bad as people ought to think about it :P
<yxhuvud>
well, changing existing methods is pretty bad.
<FromGitter>
<naqvis> true , but that falls back to line between use and abuse
<FromGitter>
<naqvis> same can be said for operator overloading
<Andriamanitra>
hmm i see, so if you were developing a shard would you rather make your own type and add methods to that or use functions instead?
<Andriamanitra>
like, let's say you wanted to add #is_prime method to integers
<FromGitter>
<naqvis> opening stdlib classes and adding methods is risky in a fact that it might conflict with higher versions (as there might be similar methods get added, but with different implementation and/or usage)
<FromGitter>
<naqvis> for such cases, I would recommend against polluting the stdlib and provide separate helpers/utils module to provide the functionality
<Andriamanitra>
yeah but how would you go about doing that? would you prefer inheriting/compositing from stdlib classes or just having functions at the cost of not-so-nice api
<FromGitter>
<naqvis> definitely customized code (either via inheritance and/or composition) is preferred as that would have different namespace than stdlib and won't conflict
<Andriamanitra>
presumably the functions would also be within a module
<FromGitter>
<naqvis> i think we were talking about monkey patching
<Andriamanitra>
yeah, we were, but since i got the impression that it's not such a great idea for shards i was asking what's the "proper" way to things in crystal
<FromGitter>
<naqvis> for project own use, adding methods/functionality to stdlib shouldn't be a big deal, but for libraries, adding functionality to stdlib should be treated with care, as that might confuse users, prone to conflict and prone to frowning eyes from other users of your library :P
<FromGitter>
<naqvis> but if you really have good thoughts/ideas and believe that should be part of stdlib, then it won't hurt to proceed with raising a RFC on crystal repo and bring that up to table for discussion with community and core team. Might get a chance to get that added to future version
<FromGitter>
<naqvis> just my thoughts and suggestions
<Andriamanitra>
i appreciate it, i guess i won't go modifying stdlib (or maybe i will, but i won't publish it and no one will ever know of my sins)
<FromGitter>
<naqvis> :P
<repo>
Blacksmoke16: hey o/ i'm giving athena-validator a try and i'm a bit stuck with the callback validator. I used it like described in the docs: https://p.jokke.space/UWua/ but it gives me a compile time error: https://p.jokke.space/SESDq4/
<raz>
woopsie, google is down
<FromGitter>
<maxbertinetti> Badly downβ¦.
<raz>
well, i told them to get a backup server but they wouldn't listen π
<oprypin>
oopsie woopsie
hightower4 has joined #crystal-lang
<FromGitter>
<erdnaxeli:cervoi.se> sadly a yielding method cannot be recursive, it bit me today for the AoC puzzle :p
<FromGitter>
<erdnaxeli:cervoi.se> I could have use a proc
<frojnd>
I have Parser class (src/parser.cr) inside Main class (src/main.cr) I would like to call Parser class, but I'm getting Error: undefined constant Parser on line `class Main < Parser`
<frojnd>
Is there someting I'm missing with classes being in each own files?
<frojnd>
Do I have to "load" Parser class in main.cr? Just like I have to require "shards"?
<yxhuvud>
yes
<frojnd>
I did add requre "parser"
<FromGitter>
<erdnaxeli:cervoi.se> you need to require the specific file with a relative path
<frojnd>
But then I got message `Error: can't find file 'parser'`
<FromGitter>
<erdnaxeli:cervoi.se> it should have worked, that's weird
<FromGitter>
<jrei:matrix.org> Anyway, going to use the Gitter channel instead of IRC in Matrix
<repo>
Blacksmoke16: oh ok that should work!
<FromGitter>
<erdnaxeli:cervoi.se> > <@jrei:matrix.org> Anyway, going to use the Gitter channel instead of IRC in Matrix β β that's probably a better idea :p
<FromGitter>
<Blacksmoke16> π
<raz>
sigh... those times when the code in front of you is so terrible, you try different different syntax themes to see if that makes it any better
* raz
mumbles something about go-lang
<frojnd>
haha
<raz>
blacksmoke16: can athena have a little cookbook about auth? (i assume it's easy, but not sure where to start looking. would like an annotation `@[Auth]` that grabs the token from auth-header, looks up user, makes it available in the endpoint-handler)
<frojnd>
I have a file wuth bunch of lines like this: `{"2021-01-01" => "bla"}` I would like to add stuff to it and make it json so it would look like this: https://carc.in/#/r/a405 so reading file line by line and then how to make this enormous json?
<FromGitter>
<Blacksmoke16> gl
<FromGitter>
<Blacksmoke16> why does the file contain ruby/crystal hashes in the first place?
<frojnd>
First it was array: `array = Array(Array(String)).new` then I added inside some data like this: `array << ["#{date}", verse_id]` and after that I made it hash: `hash = array.to_h`
<FromGitter>
<Blacksmoke16> can you regenerate the data in the file?
<FromGitter>
<Blacksmoke16> that would be easier
<frojnd>
And make it json dynamically?
<FromGitter>
<Blacksmoke16> i mean like do `array.to_json` instead, then write that to the file?
<frojnd>
Well **** let me activate my server... It's my ISP's issue I can't reach bunch of US sites wiych HTTP:Client.get "url"
<frojnd>
This weekend I went to other location and it worked like charm... just to let you know if you remember my last HTTP::Client.get "url" not working
<FromGitter>
<Blacksmoke16> might be able to write a regex that matches like `/" => "/` and replaces it with `": "`
<FromGitter>
<Blacksmoke16> then just parse it as json
<frojnd>
Wait so in the end it looks like this: `{"2020-12-14" => "MT 21:23-27 "}` ?
<frojnd>
Wait so in the end it looks like this: `{"2020-12-14" : "MT 21:23-27 "}` ?
<FromGitter>
<Blacksmoke16> neither of those are valid json
<FromGitter>
<Blacksmoke16> it should be like `{"2020-12-14": "MT 21:23-27"}`
<frojnd>
Ok
<frojnd>
Ok done
<frojnd>
I have structure in that file that is `{"foo": "bar"}` now how can I make it more complex? like I showed here: https://carc.in/#/r/a40f
<FromGitter>
<Blacksmoke16> parse it, modify it, resave it
<FromGitter>
<anthonyshull> but i think i would lose all string methods
<FromGitter>
<Blacksmoke16> hm
<FromGitter>
<Blacksmoke16> i mean doesnt every time have a timezone?
<FromGitter>
<anthonyshull> not if they don't report it
<FromGitter>
<anthonyshull> it's five o'clock somewhere
<FromGitter>
<anthonyshull> java has separate classes for date, datetime, and datetime with timezone
<FromGitter>
<Blacksmoke16> mk
<FromGitter>
<Blacksmoke16> fwiw in your example you want to do `def to_s(io : IO) : Nil`
<FromGitter>
<anthonyshull> what i want to be able to do is have some methods on top of string methods. so they could still do something like split on 'Z'
<FromGitter>
<anthonyshull> ah, thanks
<FromGitter>
<anthonyshull> i'm thinking maybe the best thing would just be helper functions that map `string -> bool` for things like `timezone?`
<FromGitter>
<Blacksmoke16> got an example of what that would look like?
<FromGitter>
<anthonyshull> haven't thought about implementation yet. probably just some regex looking for 'Z' or '+' or '-'
<FromGitter>
<anthonyshull> helper functions should just go in a module, right?
<FromGitter>
<Blacksmoke16> not unless you intend to use them elsewhere?
<FromGitter>
<Blacksmoke16> couldnt they just be methods in that type
<FromGitter>
<anthonyshull> well, if i have a type ISOString then i would lose all methods like `split`
<FromGitter>
<Blacksmoke16> is that something you want to call on your instance directly?
<FromGitter>
<anthonyshull> this is for an SDK and the underlying API returns different granularity depending on the underlying service provider
<FromGitter>
<anthonyshull> so keeping the values as strings allows the user to use string methods...like split on 'Z'
<FromGitter>
<anthonyshull> if we tried to cast to `Time` we would be making assumptions that the end user might not want to make since Time is an instant (meaning you have to know the timezone)
<FromGitter>
<HertzDevil> but why would you let the clients do the splitting
<FromGitter>
<anthonyshull> we are going to provide some convenience methods
<FromGitter>
<jrei:matrix.org> @anthonyshull: not really, because methods exists on it to set/change timezone
<FromGitter>
<jrei:matrix.org> `#location`, `#zone` for instance
<FromGitter>
<anthonyshull> i don't think that's a very good user experience...we cast the TZ to something and then the user can override it
<FromGitter>
<anthonyshull> better to say ... here is a string and some convenience methods but we're not going to make assumptions
<FromGitter>
<jrei:matrix.org> `Time` has all the convenience methods needed
<FromGitter>
<jrei:matrix.org> What assumptions? It justs parse the date
<FromGitter>
<anthonyshull> yes, but we *have* to make an assumption about the TZ
<FromGitter>
<anthonyshull> which we don't know
<FromGitter>
<jrei:matrix.org> ha ok
<FromGitter>
<jrei:matrix.org> There are dates with no timezones?
<FromGitter>
<jrei:matrix.org> or there are in UTC?
<FromGitter>
<jrei:matrix.org> > Z is the zone designator for the zero UTC offset
<FromGitter>
<anthonyshull> no, it's very common in industry for time to be reported local time but without the timezone information
<FromGitter>
<Daniel-Worrall> Pretty sure `Time` can parse all those scenarios
<FromGitter>
<anthonyshull> so, i worked in oil and gas and one company would report everything in CST because that is where their headquarters was
<FromGitter>
<jrei:matrix.org> for example, there is just 16:01:05.... nice
<FromGitter>
<anthonyshull> `Time represents a date-time instant in incremental time observed in a specific time zone.`
<FromGitter>
<jrei:matrix.org> @Daniel-Worrall: Time needs a timezone :/
<FromGitter>
<anapsix> > did you try `.last 10` β β oh nice.. beats `[-10..-1]`
<FromGitter>
<anthonyshull> in this application something happened at 4pm...but 4pm where? where your headquarters is? where the event happened? etc.
<FromGitter>
<jrei:matrix.org> maybe use UTC, and document it ?
<FromGitter>
<anthonyshull> so, because we really don't know it's safer not to assume and cast it to 4pm UTC
<FromGitter>
<anthonyshull> yeah, that could lead to events happening seemingly on different days depending on the time difference
<FromGitter>
<jrei:matrix.org> If you use UTC, you can use `Time.parse_utc`
<FromGitter>
<anthonyshull> haha, it's not about not having methods to parse time
<repo>
jrei: are you on matrix.org or are you running your own home server?
<FromGitter>
<anthonyshull> it's that you have to have an instant in time in a timezone which we do not know
<repo>
i'm still waiting for anything that isn't python to self host
<FromGitter>
<anthonyshull> it's like saying we want a float but we don't know the mantissa so we're just going to say it's .5 and document it
<repo>
well.. not _anything_
<FromGitter>
<anthonyshull> that's really weird
<FromGitter>
<jrei:matrix.org> repo: matrix.org. I ran in the past mine, but not bothering with it now
<repo>
but something a bit less resource hogging
<repo>
jrei: alright
<FromGitter>
<jrei:matrix.org> @anthonyshull: or you can use a custom type to make it clear
<FromGitter>
<anthonyshull> making a type `ISOString`
<FromGitter>
<jrei:matrix.org> which then holds the string, and `Time`, for example
<FromGitter>
<jrei:matrix.org> yeah
<FromGitter>
<jrei:matrix.org> note that you probably want to be a struct, being immutable
<straight-shoota>
Why not go just use dedicated types for date and floating time?
<FromGitter>
<jrei:matrix.org> repo: resources is not really the problem for home use with Python
<FromGitter>
<jrei:matrix.org> it's usually the environment and admin, like venvs, dependencies, upgrade
<straight-shoota>
stdlib doesn't provide that, but you could easily add your own. Should be sufficient to make them simple structs wrapping `Time` and only exposing what's relevant
<FromGitter>
<HertzDevil> just looked at ruby and it actually has a dedicated date class
<FromGitter>
<jrei:matrix.org> sometimes python-dev gcc is needed, then make. If we upgrade the OS, it can break the app because of dynamic linking, etc
<FromGitter>
<HertzDevil> it uses the julian epoch
r0bby has quit [Read error: Connection reset by peer]
<FromGitter>
<anthonyshull> yeah, like i was saying, java has date, datetime, and datetime with timezone
<repo>
jrei: ouch
<FromGitter>
<anthonyshull> so i could use a union of those three and they could pattern match
<repo>
jrei: i might be giving dendrite a try
r0bby has joined #crystal-lang
<FromGitter>
<HertzDevil> and it's more than just the date portion of `Time` because it needs to support multiple calendar reforms
<FromGitter>
<jrei:matrix.org> repo: not sure it is a good idea, will be less stable with less feature
<repo>
not a fan of go but it's way further on the way to a fully featured synapse replacement than conduit
<repo>
jrei: mmh i gues
<repo>
s
<FromGitter>
<jrei:matrix.org> ha, looks better now
<FromGitter>
<jrei:matrix.org> last time I looked to Dendrite, it was far from production ready
<FromGitter>
<jrei:matrix.org> (maybe I'm mixing with an other), it was using ElasticSearch - which is a huge no for me
<repo>
oh boy
<FromGitter>
<HertzDevil> ruby actually has `Time` (date + time) and `DateTime` (date + time + calendar)
<straight-shoota>
Java's date and time API actually has about 9 different date/time types or so
<straight-shoota>
so you can always do "more" :D
zorp has joined #crystal-lang
<straight-shoota>
but I think the scope of Crystal's stdlib is fine. `Time` represents a timeline instant and is fully based on the ISO calendar.
<straight-shoota>
That's sufficient for basic needs
<FromGitter>
<jrei:matrix.org> repo: ha no, that was Kafka
<repo>
yeah that's almost as bad
<repo>
but it can run without kafka for smaller deployments
<FromGitter>
<jrei:matrix.org> hopefully yes! For a homeserver, SQLite for the win!
<repo>
mmh postgres is fine i think
<FromGitter>
<jrei:matrix.org> why bother?
<repo>
it's no bother?
<FromGitter>
<jrei:matrix.org> sqlite is fast for few users, easy to backup, light
<FromGitter>
<jrei:matrix.org> Postgres you need to upgrade, do SQL thing to create an user, passwords, etc
<repo>
naah
<repo>
not in docker
<FromGitter>
<jrei:matrix.org> it will use more resources like a synapse + sqlite then
<repo>
no it won't :D
<FromGitter>
<jrei:matrix.org> more than sqlite then
<repo>
don't mistake postgres for sqlite
<repo>
*mariadb
<repo>
yes sure, more than sqlite
<Andriamanitra>
sqlite is nice for quickly putting something up but the lack of features does get annoying quickly
<FromGitter>
<jrei:matrix.org> Andriamanitra but here we won't touch posgtres, dendrite will
<FromGitter>
<jrei:matrix.org> as said in the INSTALL.md doc, depends on your deployment size. If you're alone, there will be no difference.
<FromGitter>
<jrei:matrix.org> as you prefer then. Docker + postgres sounds overkill, I'd just put the binary somewhere + systemd unit file personally
<repo>
?
<repo>
how is that overkill
<repo>
if i already have a docker swarm running multiple services
<Andriamanitra>
docker + postgres sounds simpler than messing with systemd and binaries tbh
<repo>
^
<FromGitter>
<jrei:matrix.org> fair enough then
<FromGitter>
<jrei:matrix.org> Andriamanitra not for me, systemd is really simple (like 5 lines)
<Andriamanitra>
so is docker, like 2 commands :p
<FromGitter>
<jrei:matrix.org> yeah, as you wish
<FromGitter>
<jrei:matrix.org> Really, by experience, I prefer having things simple, because sh** happens.
<Andriamanitra>
and as a bonus it makes it trivial to migrate between machines if ever necessary
<FromGitter>
<jrei:matrix.org> K8S is a mess :(
<repo>
jrei: your simple clearly isn't my simple though :)
<FromGitter>
<jrei:matrix.org> scp -r the directory, on my case
<FromGitter>
<jrei:matrix.org> Simple for devs != simple for admins
<Andriamanitra>
it's probably just a matter of which tools we're familiar with :p
<FromGitter>
<jrei:matrix.org> K8S make it simple to continuously deploy, but there are multiple layers which makes debugging harder
<FromGitter>
<jrei:matrix.org> no, really, I know what I'm talking about Andriamanitra. I mean, just see the codebase of K8S
<FromGitter>
<jrei:matrix.org> At work we have Hardware -> EC2 VM -> K8S pod -> the app, vs in my home: Raspberry PI -> the app
<FromGitter>
<jrei:matrix.org> it is a bad decision to go to K8S if we have not enough resources...
<repo>
and don't get me wrong, i know my way around systemd. I've written probably around 100 service with all the bells and whistles systemd has to offer. Including socket activation, protected system, change root, etc. I like docker for it's simplicity to define all services needed for an application in a single file. It's trivial to update and to migrate across servers.
<FromGitter>
<jrei:matrix.org> So I don't see what's wrong with synapse
<repo>
it's a resource hog
<FromGitter>
<jrei:matrix.org> If you use Docker + Swarm + Postgres, resources optimization is not the most important
<repo>
they have their own chapter in the readme for it
<straight-shoota>
overhead with orchestration can certainly make sense when you're managing hundreds or of nodes
<FromGitter>
<jrei:matrix.org> repo: did you have issues?
<repo>
a friend did
<straight-shoota>
but for a single app deploy: not so much
<FromGitter>
<jrei:matrix.org> really, as said before, depends of the users
<FromGitter>
<jrei:matrix.org> how many?
<repo>
like.. 5?
<FromGitter>
<jrei:matrix.org> this will do, really.
<FromGitter>
<jrei:matrix.org> synapse it largely capable of 5 concurrent users. Matrix.org runs it with a lot more
<repo>
no, he had 5 users, and complained about massive ram usage
<repo>
with what hw specs? :D
<repo>
because that, too, matters
<FromGitter>
<jrei:matrix.org> ... not sure it was because of synapse/Python.
<repo>
otoh this was maybe 2 years ago. things might've changed since then
<FromGitter>
<jrei:matrix.org> that's not because a program is in Go vs Python that it won't have memory leaks
<FromGitter>
<jrei:matrix.org> and/or consume lots of RAM
<repo>
of course not
<FromGitter>
<jrei:matrix.org> Personally, I'd go for synapse: production-ready, less likely to have bug/leaks in consequence.
<repo>
yeah i'll give it a og
<repo>
go
<repo>
sorry, this has been crazily off topic :D
<FromGitter>
<jrei:matrix.org> Would be great is synapse is compatible with dendrite
<FromGitter>
<jrei:matrix.org> then you could switch easily
<FromGitter>
<jrei:matrix.org> ... yeah ^.^'
<FromGitter>
<jrei:matrix.org> Anyway, my main point is to have something that fits your need ;) β Enterprises and people like having HA, perf and so on but sometimes it not a good deal
<FromGitter>
<jrei:matrix.org> and also, scalability
<FromGitter>
<jrei:matrix.org> swarm is good, to bad it was "replaced" by K8S :(
<repo>
mmh
<FromGitter>
<jrei:matrix.org> no?
<repo>
i've avoided having to deal with that
<repo>
still use swarm in production
<repo>
k8s seems so overkill for most of my use cases
<FromGitter>
<jrei:matrix.org> in your job? Yes it is a good idea
<FromGitter>
<jrei:matrix.org> Nomad is another option
<repo>
i guess it's not explicitly mentioned, that you can abbreviate namespaces like this
<FromGitter>
<anthonyshull> yeah, it's like 1 sentence at the bottom of a page in Programming Crystal
<FromGitter>
<jrei:matrix.org> repo: I post there because I don't where otherwise: I got `CORS header βAccess-Control-Allow-Originβ missing` when accepting your invite
<repo>
ah nice
<repo>
hm
<repo>
oh boy
<repo>
nothing works :D
<repo>
i can't join any rooms either
<FromGitter>
<jrei:matrix.org> likely a configuration is missing
<FromGitter>
<jrei:matrix.org> AFAIK, by default, the server is "isolated"
<repo>
likely
<FromGitter>
<jrei:matrix.org> that's legit if the goal is to have a corporate chat