<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.
<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>
<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
<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.!
<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>
<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>
<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.
<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
<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> 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> 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*
<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> 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>
<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>
<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