ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
zorp has joined #crystal-lang
deavmi has quit [Ping timeout: 250 seconds]
deavmi has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
deavmi has quit [Ping timeout: 250 seconds]
deavmi has joined #crystal-lang
ur5us has joined #crystal-lang
deavmi has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
<FromGitter> <jwaldrip> CrystalShards.org may be down for tonight
<FromGitter> <jwaldrip> I am migrating to a new kubernetes cluster
<FromGitter> <jwaldrip> Is this still the preferred crystal comm channel?
<FromGitter> <tenebrousedge> depends on who you ask
<FromGitter> <tenebrousedge> but yes
<FromGitter> <jwaldrip> What are the other ones?
<FromGitter> <tenebrousedge> slack
<FromGitter> <jwaldrip> ive been in that, but I thought that died long ago
rocx has quit [Ping timeout: 260 seconds]
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
ur5us has quit [Ping timeout: 272 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <Zed-Inc> hey guys, im currently trying to learn crystal and was having some trouble with tuples
<FromGitter> <Zed-Inc> how do you assign a value to a tuple?
<FromGitter> <mavu> You dont :)
<FromGitter> <mavu> Tuples are imutable
<FromGitter> <mavu> you make a new one. See https://crystal-lang.org/api/master/Tuple.html
<FromGitter> <naqvis> ^
<FromGitter> <naqvis> For starters, Crystal Reference (https://crystal-lang.org/reference/) is always a very good place to learn Crystal.
<FromGitter> <Zed-Inc> thanks @mavu
<FromGitter> <Zed-Inc> @naqvis i am reading through the crystal reference now, i must've missed the key word immutable :)
<FromGitter> <naqvis> 👍
ur5us has joined #crystal-lang
<FromGitter> <codenoid> cool
alexherbo29 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo29 is now known as alexherbo2
ua has quit [Read error: Connection reset by peer]
ur5us has quit [Ping timeout: 256 seconds]
ua has joined #crystal-lang
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#44e7ba0 (master - Remove Process.run("which") from compiler (#9141)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/678525815
<DeBot> https://github.com/crystal-lang/crystal/pull/9141 (Remove Process.run("which") from compiler)
<FromGitter> <Zed-Inc> ok so im trying to make a new directory with a Dir object
<FromGitter> <Zed-Inc> but i keep getting errors that the .mkdir() is an undefined method
<FromGitter> <Zed-Inc> I think im not importing something, but no where in the docs can i find what i need to import
alexherbo22 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo22 is now known as alexherbo2
<FromGitter> <Zed-Inc> ok nevermind, my error was trying to make a new directory instance rather then calling Dir.mkdir()
<FromGitter> <ImAHopelessDev_gitlab> @tenebrousedge Regarding that Donald Knuth quote. So much time was wasted in my nodejs days ;O
<FromGitter> <ImAHopelessDev_gitlab> I look back.. and think, what in the ever god almighty were you doing
<FromGitter> <straight-shoota> @ImAHopelessDev_gitlab Did we not all have a troubled youth...? :D
rocx has joined #crystal-lang
<FromGitter> <rishavs> the time that you enjoyed wasting.. was not wasted
sz0 has quit [Quit: Connection closed for inactivity]
cyberarm has joined #crystal-lang
<FromGitter> <j8r> again... https://www.githubstatus.com/ 😧
<FromGitter> <watzon> @tenebrousedge I believe the discord is more active
<FromGitter> <tenebrousedge> ugh
<FromGitter> <tenebrousedge> than here?
<FromGitter> <tenebrousedge> or than slack?
<FromGitter> <watzon> Than slack. This is the most active channel for sure.
<FromGitter> <tenebrousedge> k
<FromGitter> <j8r> So Gitter/IRC > Discord > Slack, for activity?
<FromGitter> <alehander92> why dont you bridge discord<=>irc
<FromGitter> <alehander92> like we do at nim
<FromGitter> <didactic-drunk> How do you get the crystal version within a crystal program?
<FromGitter> <Blacksmoke16> `Crystal::VERSION`
<jhass> >> Crystal::VERSION
<DeBot> jhass: # => "0.34.0" - https://carc.in/#/r/8xvs
<FromGitter> <watzon> I'd be willing to bet Gitter/IRC > Discord > Telegram > Slack. But I'm not in the slack channel. The Telegram group I made gets decently active though.
<FromGitter> <didactic-drunk> What about class method detection? `responds_to?` checks instance.
<FromGitter> <watzon> Does `responds_to?` not work with a class? I've never tried it.
<jhass> >> {String.responds_to?(:build), String.responds_to?(:bytesize), "".responds_to?(:bytesize)}
<DeBot> jhass: # => {true, false, true} - https://carc.in/#/r/8xvt
<jhass> all as one would expect I'd ssay
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#27e1288 (master - Refactor preserving state out of OptionParser#parse (#9133)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/678629950
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9133 (Refactor preserving state out of OptionParser#parse)
<FromGitter> <watzon> Yeah, so `typeof(var).responds_to?` should work
<FromGitter> <didactic-drunk> ``` ^ ⏎ Error: can't execute RespondsTo in a macro``` [https://gitter.im/crystal-lang/crystal?at=5ea1b2a311ffed12682d2a30]
<FromGitter> <Blacksmoke16> `{{ Process.has_method? "signal" }}`
<FromGitter> <Blacksmoke16> try that
<FromGitter> <didactic-drunk> Works.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <didactic-drunk> Although the name seems inconsistent. Shouldn't it be `respond_to?` or `class_responds_to?`
<FromGitter> <Blacksmoke16> does it matter? only that thing changes is what `it` is
<FromGitter> <Blacksmoke16> either an object or a type
<FromGitter> <didactic-drunk> Can't be found with grep.
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <Blacksmoke16> im just saying its the same method no matter what the receiver is
<FromGitter> <didactic-drunk> But why `has_method?` and not `responds_to?`? Most of the documentation and articles mention `responds_to?`.
<FromGitter> <Blacksmoke16> because the former is a macro method
<FromGitter> <didactic-drunk> That doesn't explain why.
<FromGitter> <Blacksmoke16> :shrug: fits better with the other methods like `.has_constant?` or `.has_attribute?`?
<FromGitter> <Blacksmoke16> plus in future `responds_to` will probably handle arguments
<FromGitter> <Blacksmoke16> versus a simple bool of `does this method exists on T`
<FromGitter> <rishavs> Regarding Crystal on windows, just wanted to confirm ; ⏎ Event loop , Signal , Mutex , Sockets , Backtraces , Iconv , Threads ⏎ Are all network related? ⏎ Ie. other use cases like filesystem access are doable? [https://gitter.im/crystal-lang/crystal?at=5ea1bb6461a0002f79447271]
<FromGitter> <xmonader> guys i'm trying to parse json and apparently it breaks if the content of a string is "\n"
<FromGitter> <Blacksmoke16> example?
<FromGitter> <xmonader> this doesn't work ⏎ ⏎ ```"content": "\n",``` [https://gitter.im/crystal-lang/crystal?at=5ea1bf68e5ed621d4dd6e42f]
<FromGitter> <xmonader> problem the content is going to have too many \n in it
<FromGitter> <xmonader> but why this works in other languages? that's also generated from a rust/serde backend :)
<FromGitter> <Blacksmoke16> seems its generating invalid json 😉
<FromGitter> <xmonader> @Blacksmoke16 but I checked that json in json validators :) also, if invalid i wouldn't be able to load it from rust too. the idea is I want to use crystal for preprocessing of mdbooks
<FromGitter> <xmonader> the idea is mdbook generates a json, i read from crystal and push to stdout to the remaining processors in the pipeline.
<jhass> mmh, well "any codepoint", U+10 very much is a codepoint that's not " or \
<FromGitter> <xmonader> it worked well with python, rust
<jhass> I would say ruby is wrong here too
<jhass> oh, no. Ary is right, U+10 very much is a control character
<jhass> though the spec is a little vague here but not really defining them
<jhass> it seems serde ought to do the right then when parsing at least https://github.com/serde-rs/json/pull/414
<jhass> https://github.com/serde-rs/json/commit/b8654e04ebdef5a9ea90eae5d48cb336dbeb26dd and here's the patch which should make it serialize correctly
<FromGitter> <j8r> just released https://privpage.net - the backend is done in Crystal
<FromGitter> <j8r> fairly simple project - 300 lines
<FromGitter> <robacarp> code?
<FromGitter> <j8r> private haha
<FromGitter> <robacarp> :|
<FromGitter> <j8r> I would like to see if it can become popular
<jhass> typo: GitLab Pages Acces Control. -> Access
<FromGitter> <j8r> thanks jhass
<FromGitter> <sam0x17> is there any kind of priority setting for fibers?
<FromGitter> <j8r> If I release just now, one could use the project and capitalize on it
<jhass> not that I'm aware of, no
<FromGitter> <sam0x17> kk
<FromGitter> <j8r> even though here it is fairly simple to reproduce
<jhass> mmh, serving everything on the same hostname means I can set cookies for the entire site
<jhass> and read them for the entire site
<FromGitter> <sam0x17> I guess if I Fiber.yield at each incremental step of my background task that would be equivalent to "low priority" yeah?
<FromGitter> <j8r> jhass yep, indeed
<FromGitter> <j8r> there is a github oauth cookie
<jhass> probably also some shenigangs with installing workers and discovering other people's site contents etc, dunno, not too up on all the webdev security
<jhass> just seems dangerous to run arbitrary JS with a hostname share among all users
<jhass> that's why github is using another domain entirely for github pages and even give every user their own hostname on it
<FromGitter> <j8r> I have a friend that work in security, I asked him to look at
<FromGitter> <sam0x17> I'm pretty sure github silos everything via oauth
<jhass> because then you can put it on the public suffix list and be mostly done with it
<FromGitter> <j8r> but jhass, the cookie has no critical data
<FromGitter> <j8r> if a malicious guy use it, it can't do anything
<FromGitter> <j8r> it is a session
<jhass> well, maybe somebody puts something on there worth stealing
<jhass> (for the sake of not starting to argue whether session stealing isn't an issue already)
<FromGitter> <j8r> they share the same hostname, they just have subdomains
<FromGitter> <j8r> I could do the same though
<jhass> I guess you could set a CSP that forbids running any JS
<FromGitter> <j8r> so, privpage.net would be equal to github.io
<jhass> got your terms mixed up there, a domain or zone is anything that serves a SOA record, a hostname is any name within a zone
<FromGitter> <j8r> I mean, how they would work with subdomains - it is something possible
<FromGitter> <j8r> I can add CSP yep
<FromGitter> <j8r> but github.io has no issue, because everything is public. ⏎ gitlab.io at the other hand, use OAuth
<FromGitter> <j8r> (sometimes)
<jhass> github.io has no issue because they use a separate hostname for each user and then put themselves on the PSL
<FromGitter> <straight-shoota> @wontruefree Have you considered running testing your doc PRs with https://github.com/maiha/crystal-examples ? When adding many examples it would probably make sense to ensure they work as intended. Great work btw.!
<FromGitter> <ImAHopelessDev_gitlab> yuck, github's new notification page
<FromGitter> <j8r> I could add `Content-Security-Policy: default-src https://privpage.net/THE_REPO/THE_USER`?
<jhass> gosh don't ask me about how CSPs work specifically :P
<FromGitter> <j8r> need to try those mitigations
<jhass> but CSP just limits what code can run, not what it can do
<jhass> so the only mitigation with CSP here would be disallowing any code to run
<FromGitter> <ImAHopelessDev_gitlab> > Ruby doesn't have LLVM to lie to you about what it's doing ⏎ ⏎ @tenebrousedge what do you mean by "to lie"?
<FromGitter> <tenebrousedge> LLVM will optimize away method calls, even the one that you're trying to test
<FromGitter> <tenebrousedge> which is probably what we were seeing in that benchmark
<FromGitter> <ImAHopelessDev_gitlab> is that a good or bad thing, or depends on the context?
<FromGitter> <tenebrousedge> good for performance, bad for accurate benchmarking
<FromGitter> <tenebrousedge> writing good benchmarks in Crystal is difficult and probably mostly not worth the effort
<FromGitter> <tenebrousedge> profiling on real world data sets is almost always better than benchmarking *per se* regardless of the context
<FromGitter> <ImAHopelessDev_gitlab> i agree
<FromGitter> <tenebrousedge> I really want `scan` in a macro >__>
<FromGitter> <3n-k1> anyone have experience with granite? it keeps throwing errors when i try to create an instance of a model
<FromGitter> <Blacksmoke16> whats the error
<FromGitter> <alehander92> why would you need `scan`
<FromGitter> <tenebrousedge> because the alternative is to go through a string character-by-character with a bunch of state flags to parse it into tokens
<FromGitter> <j8r> does javascript requests includes cookie?
<FromGitter> <j8r> session for instance
<FromGitter> <Blacksmoke16> depends on the cookie iirc
<FromGitter> <Blacksmoke16> i.e. path/domain and other attributes of the cookie, like `secure`
<FromGitter> <j8r> I have HttpOnly set
<FromGitter> <Blacksmoke16> that just means js cant access it
<FromGitter> <Blacksmoke16> do you mean like XHR request?
<FromGitter> <j8r> good, I am relieved :)
<FromGitter> <j8r> yes
<FromGitter> <Blacksmoke16> prob related to that
<FromGitter> <j8r> It seems they are :/
<FromGitter> <Blacksmoke16> whats the problem exactly?
<FromGitter> <Blacksmoke16> do you have a js frontend?
<FromGitter> <j8r> I don't want a cookie being accessible from JS
<FromGitter> <Blacksmoke16> whats what httpOnly flag does
Deuns has left #crystal-lang [#crystal-lang]
<FromGitter> <j8r> it protects the javascript to access to the cookie
<FromGitter> <j8r> but does not affect the requests
<FromGitter> <Blacksmoke16> right, so whats the problem?
<FromGitter> <j8r> so, a page /x can GET another one /y
<FromGitter> <j8r> I don't think it is possible: `/a/*` pages cannot access `/b/*` pages
<FromGitter> <j8r> like SameOrigin, but for paths
<FromGitter> <Blacksmoke16> is what `path` attribute is for
<jhass> the problem is hosting user content from different users on the same hostname :P
<FromGitter> <j8r> not sure `path` will work...
<FromGitter> <j8r> I could add another cookie to know on which site the user is
<FromGitter> <j8r> and the security blocking would be server side
<FromGitter> <j8r> and use the `path` attribute
<FromGitter> <j8r> I think it can works, thanks @Blacksmoke16 and jhass
<FromGitter> <rishavs> @oprypin in your windows crsfml post, why do you need to download the crystal repo? Does the crystal.exe refers to some libs in the repo?
<FromGitter> <j8r> wow so few docs in Cookies, gonna add some
<FromGitter> <j8r> 2hours... wow just before me 😄
<FromGitter> <straight-shoota> @rishavs To compile a Crystal program you need the standard library and that is provided in the crystal repo
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<raz> 3n-k1: my experience with granite caused me to switch to jennifer ;)
<FromGitter> <rishavs> thanks @straight-shoota !
<raz> granite is *super* basic. if you need anything beyond most basic querying i'd suggest to look into jennifer (or perhaps clear or crecto) instead
<FromGitter> <kinxer> @Blacksmoke16 What's the status of your generic serialization shard?
<oprypin> @rishavs: Crystal programs are always compiled from source. that source includes standard library. need that.
<oprypin> o woops, already answered before me
<FromGitter> <rishavs> :D
<FromGitter> <rishavs> I am just starting on a tryout of crsfml. wish me luck
<oprypin> good luck :>
<FromGitter> <Blacksmoke16> @kinxer is on the back burner atm, as i needed some new DI features in order for it to work how i wanted
<FromGitter> <Blacksmoke16> mainly for deserialization side of things
<FromGitter> <kinxer> A'ight. Thanks for the update.
<FromGitter> <Blacksmoke16> i.e. determines where the obj that the data gets applied to originates
<FromGitter> <Blacksmoke16> could be from a db, or just like `T.new`
<FromGitter> <wontruefree> @straight-shoota I could not remember where that repo was. I run most of the examples in a temp script but I copy pasts some things. But I do execute most of the examples but I write them out by hand both in the script and the docs.
<FromGitter> <rishavs> @oprypin hitting a 32/64bit issue on trying to build the LIB; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea1e4e31e3d5e20633cf812]
<oprypin> well then check that you didnt miss selecting 64bit anywhere
<oprypin> rishavs, most likely one right now would be the "x64 developer command prompt" which wouldn't be x64 in your case
<FromGitter> <xmonader> how do i represent this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea1e61d5d245d59f312e4d8]
<oprypin> what is going on
<FromGitter> <tenebrousedge> `Hash(String, Hash(String, Array(String)))`
<FromGitter> <rishavs> Oleh, that fixed it. My hello world works! now to the sfml examples!
<FromGitter> <xmonader> @tenebrousedge thank you
<FromGitter> <tenebrousedge> np
<FromGitter> <tenebrousedge> @xmonader actually that doesn't seem to match your example?
<FromGitter> <tenebrousedge> it looks like your inner hash is `Hash(String, Array(String) | Int32)`
<FromGitter> <tenebrousedge> which really seems like you want a struct
<FromGitter> <tenebrousedge> https://crystal-lang.org/api/0.34.0/toplevel.html#record(name,*properties)-macro
<FromGitter> <tenebrousedge> `record FileCounter, count : Int32, paths : Array(String)`
<FromGitter> <tenebrousedge> `record FileCounter, count = 0, paths = Array(String).new`
<FromGitter> <tenebrousedge> @xmonader
<FromGitter> <tenebrousedge> or use `Path`
<jhass> +1 to more value types
<jhass> we should make a challenge, whenever somebody asks "how to represent this nested hash/array structure" answer with a bunch of record marco invocations
<FromGitter> <tenebrousedge> probably not a terrible idea
<FromGitter> <tenebrousedge> but in this case it sounds like what they want to do is use `group_by`
<FromGitter> <tenebrousedge> there's probably no reason that `count` would ever be anything but the size of the paths array
<FromGitter> <rishavs> flippy bird running on windows! woohoo!
rcvalle has joined #crystal-lang
<FromGitter> <tenebrousedge> yay!
<FromGitter> <Blacksmoke16> whats with the title
<FromGitter> <rishavs> the power of the bird flips it
<FromGitter> <rishavs> `window = SF::RenderWindow.new(mode, "pɹıq ʎddılɟ")`
<FromGitter> <tenebrousedge> ```code paste, see link```
<FromGitter> <Blacksmoke16> 👍
<oprypin> rishavs, ayy
<jhass> mmh, that code paste just came without a link?
<oprypin> guess it did, huh
<FromGitter> <tenebrousedge> mine?
<jhass> yeh
<FromGitter> <tenebrousedge> I just used the triple \`
<jhass> yeah, normally the bridge bot sends a link for those
<oprypin> no no it's just the bridge to IRC
<FromGitter> <oprypin> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea1ed9e94ac2758e3035f4e]
<FromGitter> <oprypin> worked this time
<FromGitter> <tenebrousedge> huh
<FromGitter> <oprypin> ```code paste, see link```
<jhass> hah
<oprypin> ok i see. it happens when ```\nonly one line of code\n```
<FromGitter> <tenebrousedge> huh okay
<oprypin> again, totally a bug on the bridge bot, nothing else
<FromGitter> <tenebrousedge> I mean, I wasn't taking it as a personal reflection 😆
<jhass> I wouldn't mind if just shows the code directly in this case
<jhass> maybe a cap on length to be safe
<jhass> also for two or even three line pastes
<jhass> and otherwise a little preview instead of "code paste see link" could be cool
<FromGitter> <watzon> Hey look at @oprypin not using IRC
<FromGitter> <watzon> Just for the code block huh? Lol
<jhass> appreciate your sacrifice
<FromGitter> <kinxer> In specs, will `focus: false` make some tests not run by default?
<FromGitter> <straight-shoota> @kinxer That's the default value, specifying it explicitly has no effect
<FromGitter> <kinxer> Gotcha. That makes sense. Is there a way to make a certain spec (or tag) run only when requested?
<FromGitter> <kinxer> I mean, I guess you could do that by putting `focus: true` on everything except what you want to not run by default, but that's not great.
<FromGitter> <straight-shoota> Indeed it isn't :D
<FromGitter> <straight-shoota> I don't think there's a skip option except for `pending` but that doesn't compile the code so you can't enable it at runtime
hightower2 has quit [Ping timeout: 250 seconds]
<FromGitter> <kinxer> Huh. That seems strange. I'm sure there's been discussion about this... I'll search the open issues.
<jhass> just put those specs into a separate file that you don't include into your main suite run
<FromGitter> <straight-shoota> Maybe you recall the discussion about tags
<FromGitter> <straight-shoota> You can use a tag `it tag: "skip" {}` and `crystal spec -- --tag ~skip`
<FromGitter> <straight-shoota> But like jhass said, I'd also suggest to use separate files. Let all your regular specs run every time and have the special ones separated.
<FromGitter> <sardaukar> hello, all! 👋
<FromGitter> <Blacksmoke16> o/
<FromGitter> <kinxer> @straight-shoota @jhass Thanks for the advice.
<FromGitter> <sardaukar> anyone with Crinja experience here?
<FromGitter> <sardaukar> I decided to abandon ECR for my project
<FromGitter> <sardaukar> I think something like crinja or liquid.cr might be more useful
<FromGitter> <j8r> @straight-shoota the author, very likely :)
<FromGitter> <sardaukar> but can't seem to work out crinja filters :|
<FromGitter> <sardaukar> @straight-shoota hey! :D
<FromGitter> <straight-shoota> sure
<FromGitter> <straight-shoota> Might know a thing or two about it
<FromGitter> <sardaukar> I'm trying to create a filter to format time
<FromGitter> <sardaukar> like `{{ post.published_at | time(format="long") }}`
<FromGitter> <sardaukar> I have ```time = Crinja.filter({format: nil}) do ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea1f6f61eb8bd3978eef03a]
<FromGitter> <sardaukar> but `can't cast Crinja::Value to String` on the target
<FromGitter> <straight-shoota> you need to call `as_s` instead of `as(String)`
<FromGitter> <sardaukar> oh. what's the difference? :|
<FromGitter> <sardaukar> well, regardless the compiler still hates me `Error: no overload matches 'Time.parse' with types (Crinja::SafeString | String), String, Time::Location`
<FromGitter> <straight-shoota> `Crinja::Value` is the similar to `JSON::Any` in being a simple wrapper struct that can hold different value types. You can't cast that struct to the type of the value, because it's actually an instance variable (`@raw`).
<FromGitter> <straight-shoota> But helper methods like `as_s` exist to make that easy for you. It's essentially just `@raw.as(String)`
<FromGitter> <sardaukar> I had to do `.as_s.as(String)` doesn't sound right
<FromGitter> <sardaukar> but now it compiles
<FromGitter> <straight-shoota> Argh, yeah that's an inconsistency in the API. I should've recommended `as_s!`
<FromGitter> <straight-shoota> They should probably be switched. Or a different name for the one that returns `SafeString`.
<FromGitter> <sardaukar> interesting that `TIME_FORMATS[arguments["format"].as_s]` worked fine
<FromGitter> <sardaukar> ``` "url" => "%Y-%m-%d", ⏎ "long" => "%B %-d, %Y", ⏎ }``` [https://gitter.im/crystal-lang/crystal?at=5ea1f85d3ea9b172a486a0e6]
<FromGitter> <straight-shoota> Probably because `Hash
<FromGitter> <straight-shoota> Hash#[] doesn't restrict argument type
<FromGitter> <sardaukar> I don't get that - how can Hash #[] work with a SafeString, then?
<FromGitter> <straight-shoota> You could call `TIME_FORMATS[nil]` and the compiler wouldn't complain.
<FromGitter> <straight-shoota> cf #8893
<DeBot> https://github.com/crystal-lang/crystal/pull/8893 (Enforce hash key types at compile time)
<FromGitter> <sardaukar> ok so it's not working, just not complaining - gotcha
<FromGitter> <straight-shoota> Not it really works because `arguments["format"]` can't actually be a `SafeString` but the compiler can't prove that
<FromGitter> <straight-shoota> At least your `{{ post.published_at | time(format="long") }}` sample won't make it `SafeString`
<FromGitter> <j8r> ho crap
<FromGitter> <j8r> Multiple cookies with the same name is not supported
<FromGitter> <Blacksmoke16> makes sense
<FromGitter> <Blacksmoke16> prefix it with their subdomain or something?
<FromGitter> <j8r> I think it won't be a problem if I set the path
<FromGitter> <j8r> there shouldn't have 2
<FromGitter> <j8r> yes or prefix then
<FromGitter> <sardaukar> @straight-shoota I'm getting `Unhandled exception: Unexpected type in Crinja value ⏎ cause: cast from Time to String failed, at /home/sardaukar/Code/OWN/crystal/brucite/lib/crinja/src/runtime/value.cr:376:7:376`
<FromGitter> <sardaukar> which makes sense, because `post.published_at` is a `Time?`
<FromGitter> <sardaukar> how can I unpack it as one to use in the filter?
<FromGitter> <straight-shoota> Easy: `as_time`=)
<FromGitter> <sardaukar> *should have read the docs*
ur5us has joined #crystal-lang
<FromGitter> <sardaukar> thanks! 😅
<FromGitter> <robacarp> https://crystal-lang.org/api/0.34.0/Path.html#/(part:Path%7CString):Path-instance-method this is brilliant
hightower2 has joined #crystal-lang
<hightower2> Hey is it possible to store some fixed content in a match variable during a regex... Like, I have regex such as (abc)|(def), and I'd like to set some variable depending on which part it matches... like (?<myvar="it was abc">abc)|(?myvar<myvar="it was def">def)
<hightower2> any syntax to do this would be fine, I just put together a wild example
<FromGitter> <tenebrousedge> yes
<FromGitter> <tenebrousedge> use a capture group and refer to it with `\1`
<FromGitter> <tenebrousedge> or a named capture or whatever
<hightower2> yes, yes, but I need it to be different, not refer to something that matched
<hightower2> Like,
<hightower2> if the regex matches "abc", then I want to set variable myvar to "abc matched"
<hightower2> or if it matches "def" then I want to set myvar to "it was def that matched"
<FromGitter> <tenebrousedge> `gsub(/(abc)|(def)/, "\\1 matched")`
<FromGitter> <tenebrousedge> or pass a hash as the second param
<hightower2> yes I understand what you meant but this was just an example, not a real need to re-use the word "abc" or "def"
<hightower2> like,
<FromGitter> <straight-shoota> @robacarp `Path#/` is a little gimmick, yes
<FromGitter> <straight-shoota> But actually not that useful proabably because `#join` can directly join multiple components and is more performant than repeated `/`
<jhass> hightower2: why don't you just do x = case m[1] when "abc"; "a matched"; when "def"; "b matched"; end?
<hightower2> because they're not literals... like, this is specifically what I need:
<hightower2> if regex matches (?<year>\d{4}-?<month>\d{2}-?<day>\d{2}) then I want to set variable format to "%y-%m-%d". But if another OR regex matches, the one saying ?<month>\w{3} ?<day>(\d+), ?<year>\d{4}, then I want to set format="%b %d, %Y"
<jhass> in general this seems very XY question
<hightower2> but I can't do this with IFs, because only a single regex executes, containing a number of those OR elements
<jhass> why only a single regex?
<jhass> where's that limitation coming from?
<FromGitter> <tenebrousedge> store `Hash(Regex, Formatstring)` and use `find`
<jhass> I guess you could just name the capture groups differently
<jhass> and check which ones are set
<FromGitter> <robacarp> but it sure is pretty. with a method which returns a Path, you can do something like this very nicely: `api_host / "resource" / id / "sub_resource"` rather than stacking them all up in an array and joining on it
_ht has quit [Quit: _ht]
<FromGitter> <tenebrousedge> I don't see a point in using a single regex
<FromGitter> <robacarp> Or doing the rubyism of `api_host.join "resource", id, "sub_resource"` which does the job but it doesn't read as well
<hightower2> tenebrousedge: You mean running 10 separate/individual regexes (as long as they're precompiled) wouldn't be slower than running one with all possibilities OR-ed?
<FromGitter> <tenebrousedge> I'd want to see it benchmarked, regexes are pretty slow, especially the complicated ones
<jhass> srsly, you're the prototype example of premature optimization
<FromGitter> <robacarp> Performance is fun, and great to think about at times, but readability is way more important
<jhass> yeah, the backtracking might be slower than just running two
<FromGitter> <tenebrousedge> ^
<hightower2> jhass I don't think there's any harm in trying to understand what is fast(er) than something else... and readability is not an issue because I define regexes separately and then only for execution join them with Regex#union
<jhass> depends a lot on the regex, how smart you are with the + thingies that disable backtracking and the input data set
<jhass> well no harm, instead of lowering your productivty by constantly worrying about something that's not gonna actually affect the application you're building
<FromGitter> <robacarp> heh, my comment was targeted at the `Path` discussion but I guess it works for the regex discussion too...
<jhass> make work, make it beatiful, make it fast
<jhass> in that order
<FromGitter> <tenebrousedge> and if you never get to the third step throw hardware at it
<FromGitter> <tenebrousedge> you can fit enormous amounts of data in memory these days
<jhass> more importantly if you do the other two steps first, you may never achieve the first one
<FromGitter> <tenebrousedge> https://yourdatafitsinram.net/
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#a803b36 (master - Implement Process.times on Windows. (#9149)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/678765832
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9149 (Implement Process.times on Windows.)
<jhass> gah, now I try to remember what the + thingies are called in regex, something with p...?
<jhass> possesive qunatifiers!
<FromGitter> <straight-shoota> Was going to say quantifier with mirrored initial
<FromGitter> <j8r> :/ `malloc(): unsorted double linked list corrupted`
<jhass> congratulations
<FromGitter> <j8r> ...where should I dig, maybe something related to Hash
<jhass> do you write or use any not super popular C binding? Using any to_unsafe calls?
<FromGitter> <jwaldrip> Coming Soon ^
<FromGitter> <sardaukar> 👍
<FromGitter> <j8r> jhass not at all, plain regular Crystal here
<FromGitter> <j8r> not pointer, nor unsafe
<jhass> hum. well. that really shouldn't be able to corrupt the heap anymore these days
<jhass> maybe... memtest? :D
<jhass> j8r: something happening consistently or a fluke?
<FromGitter> <j8r> I run my program, all is ok. If I perform requests shortly one after another, the 5th yields to this error
<FromGitter> <j8r> If I do slowly no problem
<FromGitter> <j8r> I think it occurs on the router https://github.com/ricr-web/ricr, the routing is done with Hashes
<FromGitter> <sardaukar> @straight-shoota is there a way for Crinja to remove the newlines from the `if`s and so on?
<FromGitter> <sardaukar> from the output, I mean
<jhass> it's quite likely for things like this that cause and trigger are at different pointss
<jhass> maaaybe you have some luck staring at valgrind output for some time, idk
<FromGitter> <j8r> hum, I'm narrowing down. not the router
<FromGitter> <j8r> got it jhass
<FromGitter> <j8r> I don't know the explanation though
<FromGitter> <j8r> I have used `HTTP::Client.new("api.github.com", tls: true)` inside a route
<FromGitter> <j8r> If I use it like this, creating a new client each time - no problem
<FromGitter> <j8r> However, if I reuse the same client - not
<FromGitter> <j8r> ha, I think I forgot to close
<FromGitter> <j8r> hum no, nvm
<FromGitter> <j8r> Is it safe to have concurrent use of the same `HTTP::Client`?
zorp has quit [Read error: Connection reset by peer]
<FromGitter> <straight-shoota> @sardaukar yeah, use `{%-` and `-%}`
<FromGitter> <straight-shoota> > Is it safe to have concurrent use of the same `HTTP::Client`? ⏎ ⏎ Definitely no.
<FromGitter> <sardaukar> thanks! btw, the docs at https://straight-shoota.github.io/crinja/ seem to be wrong - they mention using` {%%` as valid
<FromGitter> <sardaukar> maybe it's a typo?
<FromGitter> <j8r> I guess I'll have to make a pool in the future
<FromGitter> <sardaukar> (it's all over the docs)
<FromGitter> <j8r> thanks @straight-shoota
<FromGitter> <straight-shoota> That's probably an escaping issue
<FromGitter> <straight-shoota> The rendering at https://github.com/straight-shoota/crinja is correct
<FromGitter> <sardaukar> yeah, the link there for objects (https://straight-shoota.github.io/crinja/api/latest/playground/objects.html) also has the escaping issue
<FromGitter> <straight-shoota> The tags in examples unfortunately collide with liquid tags when github pages builds the site with jekyll
<FromGitter> <straight-shoota> Yeah, they're all built the same way. It's an easy fix though: https://github.com/straight-shoota/crinja/commit/588ad44f0daad49c639751dae10dee4ca8205925
<FromGitter> <straight-shoota> Thanks for reporting
<FromGitter> <sardaukar> 👍
<FromGitter> <xmonader> trying to define a pointer ref to use from some where else ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I get ` transformers["onlink"] = ->onlink(String)` [https://gitter.im/crystal-lang/crystal?at=5ea212a95d245d59f31369e0]
<FromGitter> <Blacksmoke16> and whats the problem?
<FromGitter> <xmonader> @Blacksmoke16 edited
<FromGitter> <Blacksmoke16> onlink for what?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8xy1
<FromGitter> <xmonader> i just want to pass it to that hash so i can invoke it later on like any higher order function
<FromGitter> <Blacksmoke16> works fine, issue is with somewhere else
<FromGitter> <xmonader> interesting works indeed on the playground
<FromGitter> <straight-shoota> @sardaukar Now it's fixed: https://straight-shoota.github.io/crinja/
<FromGitter> <sardaukar> thanks!
<FromGitter> <xmonader> @Blacksmoke16 https://play.crystal-lang.org/#/r/8xy3 do you see anything suspicious here?
<FromGitter> <xmonader> i forked markd lib and if i remove 16 to 22 lines it works fine
<FromGitter> <tenebrousedge> is that valid syntax? I thought that was only for vars
<FromGitter> <Blacksmoke16> prob reason its a method defined in a module
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8xy8
<FromGitter> <Blacksmoke16> id search github and see if it was reported before, otherwise that looks like a bug?
<FromGitter> <xmonader> @Blacksmoke16 I'm not allowed to define methods in Modules in general? I thought I did that when I used ruby ages ago?
<FromGitter> <tenebrousedge> no that part is fine
<FromGitter> <xmonader> @tenebrousedge I found it here https://github.com/crystal-lang/crystal/issues/6597
<FromGitter> <Blacksmoke16> no i mean the issue seems to be converting a method to a proc within a module
<FromGitter> <tenebrousedge> yeah it's supposed to be valid, it's in the Book
<FromGitter> <xmonader> I managed to got it work this way ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2178c501f8f72a5fe19d4]
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> whats the reasoning for forking markd?
<FromGitter> <xmonader> @Blacksmoke16 I want to do more preprocessing on the markdown, and it doesn't allow custom callbacks in the parser
<FromGitter> <xmonader> so what I'm doing is allowing that and invoking it when suitable in parser, hopefully if that makes sense to the author they merge it
<FromGitter> <Blacksmoke16> better to maybe make an issue/PR?
<FromGitter> <Blacksmoke16> ah 👍
<FromGitter> <xmonader> Yes indeed :) first day working on crystal :D
<FromGitter> <tenebrousedge> @xmonader did you see the discussion previously about hash vs struct?
<FromGitter> <tenebrousedge> and `group_by` ?
<FromGitter> <xmonader> @tenebrousedge I actually had to convert to struct in the end
<FromGitter> <tenebrousedge> it's probably the better way to go
<FromGitter> <xmonader> didn't see the group_by no :(
<FromGitter> <xmonader> that json thing annoyed me today, but crystal is kinda "forced"
<FromGitter> <tenebrousedge> well it seemed like you were wanting to do something like this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea218d55d245d59f31379f8]
<FromGitter> <xmonader> oh no heart reacts in gitter! :(
<FromGitter> <xmonader> Yes that'd solved it perfectly for sure
<FromGitter> <tenebrousedge> well structs are nice too
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea219702bf9ef12699d902a]
<FromGitter> <tenebrousedge> assuming that you had something like: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea21a0d5d245d59f3137ca9]
<FromGitter> <tenebrousedge> not tested of course
<FromGitter> <xmonader> almost the same, but not record I used class with properties
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> if the data is static record (struct) is better
ur5us has joined #crystal-lang
<FromGitter> <didactic-drunk> Is anyone working on a `Log` formatter class?
<FromGitter> <Blacksmoke16> To wrap the proc?
<FromGitter> <Zed-Inc> does crystal not have for loops?
<FromGitter> <Blacksmoke16> Nope
<FromGitter> <Blacksmoke16> Probably is a better iterator method
<FromGitter> <Zed-Inc> what should i use instead to get the sam result as a for loop?
<FromGitter> <Blacksmoke16> just trying to iterate over items in an array?
<FromGitter> <Blacksmoke16> ```arr.each do |item| ⏎ # Do whatever ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ea227f394ac2758e3040cb7]
<FromGitter> <Zed-Inc> thanks that works perfectly
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Zed-Inc> would that work on named tuples as well?
<FromGitter> <Zed-Inc> or just arrays?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/NamedTuple.html#each(&):Nil-instance-method
<FromGitter> <Zed-Inc> how do i miss these things?? i have like five tabs open on those docs
<FromGitter> <Blacksmoke16> ;p
<FromGitter> <watzon> @Zed-Inc make sure to always check out included modules like Enumerable and Iterable, that's where a lot of methods like that come from