<FromGitter>
<Daniel-Worrall> Can I deconstruct variable names in a proc? Something like `["a","b"].each.with_index.reject(&->((i : String,j : Int32)){i == "a" || j == 3}).to_a`
<FromGitter>
<Blacksmoke16> mm prob not
<FromGitter>
<Daniel-Worrall> What does `!yield` do?
<FromGitter>
<Blacksmoke16> same as `!var`
<FromGitter>
<Blacksmoke16> but negating the return value of the yield
<FromGitter>
<Daniel-Worrall> ahh
<FromGitter>
<Daniel-Worrall> I was thinking too hard and assumed it was special syntax
<FromGitter>
<Daniel-Worrall> Anyway, to my actual question. Can we use the 2nd yield arg when using the 1 liner block forwarding syntax? `hash.each(&.dosomethingwithvalue)`?
<FromGitter>
<Daniel-Worrall> hashes yield 2 values instead of a tuple of key,value, only the key can be accessed this way
<FromGitter>
<Daniel-Worrall> also means you can do `hash.each do |k,v|` instead of `hash.each do |(k,v)|`
<FromGitter>
<Daniel-Worrall> although tuples autosplat anyway
<FromGitter>
<Daniel-Worrall> actually, each yields a tuple
<FromGitter>
<Daniel-Worrall> but select/reject yield 2 args
<FromGitter>
<Daniel-Worrall> So I feel like this is a bug
<straight-shoota>
These method definitions are so old, maybe autosplat wasn't even a thing back then :D
<raz>
blacksmoke: so `self.view "foo", status: status` would be the same as `return foo` (but override the status)? 🤔
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Blacksmoke16> `ART:Response` are returned directly w/o invoking the view layer as before. `ART::View` object is a new thing that contains information about the response, but in a format agnostic way, scalar values are turned into an `ART::View` behind the scenes
<FromGitter>
<Blacksmoke16> `ART::View` and scalar types invoke the view layer which consumes it and some other data to return an `ART::Response`
<FromGitter>
<Blacksmoke16> also sets things up a bit better for automatically calling the correct format handler based on the `Accept-*` header formats
<raz>
yup, that should make my life complete. i mean, it hasn't been a big deal anyway - the only place where i want to override the status is for 200 vs 201 (more of an OCD concern than a real one). other codes come from exceptions.
<FromGitter>
<Blacksmoke16> i.e. such as the thing straight-shoota wanted
<raz>
yup, small step for me, big step for athena and others. there are certainly use-cases where being able to override that stuff in the method is crucial
<FromGitter>
<Blacksmoke16> ill still trying to figure out to best fit your JSON API format thing into it tho
<straight-shoota>
oh, what did I want?
<FromGitter>
<Blacksmoke16> as like the view listener got a lot simpler
<FromGitter>
<Blacksmoke16> that thing where you could have your shardbox api methods return a like hash/namedTuple of args and throw on a `@[Template("foo.crinja")]` and it just works
<straight-shoota>
ah yes
<straight-shoota>
FTR I also find it crucial that an action can set the status code
<FromGitter>
<Blacksmoke16> its currently possible, but with some gotcha
duane has quit [Ping timeout: 256 seconds]
<FromGitter>
<Blacksmoke16> atm it wasnt possible to dynamically determine and set the status code at runtime while within an action AND invoke the view layer
<FromGitter>
<Blacksmoke16> it isnt*
<FromGitter>
<Blacksmoke16> this adds in a third way to bridge that gap
<straight-shoota>
meanwhile I think I hit a wasp nest while looking at #9339
<raz>
oh the view listener works splendidly for me tho. this is the athena boilerplate that i use so far: http://ix.io/2J4U - all of it. less verbosity is ofc always welcome, but i'm fine with <100 loc of machinery.
<straight-shoota>
there are at least four different iterators implementing very much the same thing: Range::StepIterator, Number::StepIterator, Int::DowntoIterator, Int::UptoIterator
<FromGitter>
<Blacksmoke16> lovely
<raz>
with that i can just return anything json-serializable or raise exceptions and it gets wrapped into json:api. plus clear validation errors get cleanly wrapped too.
<raz>
could hardly be happier. athena ftw ♥️
<FromGitter>
<Blacksmoke16> what i was getting at is the view listener doesnt actually do the same thing anymore
<raz>
well, as long as it can do a similar thing, i'm fine ;)
<FromGitter>
<Blacksmoke16> imo if you're not using any of the serializer component id just add this to the base controller type and call it a day, prob be a bit more efficient as well ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fe14d9c22f12e449b0511e0]
<FromGitter>
<Blacksmoke16> ofc maybe with a status arg
<raz>
might work, i'll have to look into that. i know some reshuffling is coming up also with StreamedResponse etc.
<FromGitter>
<Blacksmoke16> this way it wouldnt even need to invoke the view layer just to add a wrapping key
<raz>
yup, i'll check it out in the next boilerplate refactor (i.e.: when the next athena update breaks my current impl :D)
<FromGitter>
<Daniel-Worrall> Do we have any strict conventions on explicit brackets?
<FromGitter>
<Daniel-Worrall> in the stdlib
<FromGitter>
<Blacksmoke16> hm?
<FromGitter>
<Daniel-Worrall> I see a lot of different things where sometimes the method calls have brackets and sometimes not
<FromGitter>
<Daniel-Worrall> but I can't find any style choices on this
<FromGitter>
<Blacksmoke16> ah you mean `()`?
<FromGitter>
<Daniel-Worrall> yeah
<FromGitter>
<Daniel-Worrall> e.g. `self[k] = yield k, self[k], v` `memo[k] = v unless yield k, v` `delete(key) if yield(key, value)`
<FromGitter>
<Blacksmoke16> i personally dont use them most of the time
<FromGitter>
<jrei:matrix.org> Me too yes
<FromGitter>
<Daniel-Worrall> There's no consistency
<FromGitter>
<jrei:matrix.org> Only when there are nesting
<FromGitter>
<Blacksmoke16> only use them when i need call another method, or to make it more clear, i.e like `some_method 1, Foo.new 2, 3`
<FromGitter>
<Blacksmoke16> should be `some_method 1, Foo.new(2), 3`
<FromGitter>
<jrei:matrix.org> One issue is no difference between variable vs methods :/
<FromGitter>
<jrei:matrix.org> Not new – this comes from Ruby
<FromGitter>
<jrei:matrix.org> Anyway, we usually know this, and IDE can help – no big deal
<FromGitter>
<Blacksmoke16> i been using `self.`a lot for methods lately
<FromGitter>
<Daniel-Worrall> I know it works, I just don't like both being used 5 lines from the other
<FromGitter>
<Daniel-Worrall> I'd rather stick to 1 style
<FromGitter>
<Daniel-Worrall> Also seems you can't `yield {1, 2}`
<FromGitter>
<Daniel-Worrall> you need the parenths
<FromGitter>
<Blacksmoke16> thats expected, there are quite a few issues a bout it
<FromGitter>
<Blacksmoke16> parser doesnt know if its a block or a tuple
<FromGitter>
<Daniel-Worrall> is it for any method call?
<straight-shoota>
if your WSL instance is named differently, you can find it at `\\wsl$\`
<FromGitter>
<Daniel-Worrall> ty ty
<straight-shoota>
1.0.2g isn't the newest but it should technically be supported
<straight-shoota>
maybe something broke it and there's no test against such an old version
<FromGitter>
<Daniel-Worrall> I have ubuntu4.16, it wants to update to 4.18
<FromGitter>
<Daniel-Worrall> I'll see if these minors fix anything
<FromGitter>
<Daniel-Worrall> That's what I get for using ubu16
<straight-shoota>
yeah, it's to be expected
<straight-shoota>
but it's not really a big deal I suppose
<FromGitter>
<Daniel-Worrall> yeah, I just need to ignore local failing specs
<FromGitter>
<Daniel-Worrall> no big deal
<straight-shoota>
I'm still on 16.04 on WSL1 on my laptop :D
<FromGitter>
<Daniel-Worrall> ouch
<FromGitter>
<Daniel-Worrall> Migrating is just zzz
<FromGitter>
<Daniel-Worrall> Ooh, I'll probably get better speeds once I move my crystal to the wsl mount
<FromGitter>
<Daniel-Worrall> There's a silly overhead for file access
<straight-shoota>
yeah maybe
<FromGitter>
<Daniel-Worrall> Aww yeah, I'm excited now
<straight-shoota>
but I wouldn't expect much of a difference
<straight-shoota>
WSL2 has really fast file access (compared to WSL1)
<FromGitter>
<Daniel-Worrall> I was running my aoc benchmarks WSL2 against native windows bootstrapped, and I saw I was getting a 0.01something overhead for the file reads
<FromGitter>
<Daniel-Worrall> but it was slower in general on windows
<frojnd>
Not sure how to run shards on carc.in but you can try it yoursel
<frojnd>
Ok This seems to be web specific... some pages ignore case sensitive urls but others don't
<frojnd>
What is interesting if I try to access some page that ignores case senstive urls... I can't get response I want with HTTP::Client.get even though that firefox shows the page
<frojnd>
Hm
hightower2 has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
<FromGitter>
<Blacksmoke16> is there a built in way to get the intersection of two hashes?
<FromGitter>
<erdnaxeli:cervoi.se> Set.new(h1.toa) & Set.new(h2.toa) ? (with the correct types for the Set)
<FromGitter>
<erdnaxeli:cervoi.se> even (Set.new(h1.toa) & Set.new(h2.toa)).to_h
<FromGitter>
<erdnaxeli:cervoi.se> not very elegant :p
hightower2 has joined #crystal-lang
woodruffw has quit [Ping timeout: 264 seconds]
woodruffw has joined #crystal-lang
<hightower2>
Hey why the various IO write methods don't have a variant accepting the buffer (pointer(uint8)) and a length? or in other words, after I have a buffer of which I know `len` bytes are written, what's the most efficient way to write len bytes of that to an IO?
<hightower2>
ok thanks.. I was trying to avoid wrapping it into another object though, but if that's how it's done than that's it
<hightower2>
(since the buffer itself is larger than the amount of data that was meaningfully written into it)
<straight-shoota>
a slice is free, just a struct
<hightower2>
ok, great, thanks for the discussion
<hightower2>
A conceptual question -- I have a lib binding to C, and some of the functions return strings from C (ptr(uint8)). For use/reading in Crystal these are best converted to String of course, but if/when they are used as input into further functions from the C lib they can be passed without converting to/from String at all. Is there a rule of thumb how to support both purposes and how to name the methods? Or I just use String.new(...) and
<hightower2>
later str.to_unsafe and that's it?
woodruffw has quit [Ping timeout: 256 seconds]
woodruffw has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
<straight-shoota>
If you don't need a Crystal string, you can safe the extra allocation for building one from a char array
<straight-shoota>
I'm not sure if there are any established conventions for this
<straight-shoota>
a typical solution might be to provide a low level API based on C strings and a high level API based on Crystal strings.
<FromGitter>
<Blacksmoke16> i dont have lucky installed but id be curious to see what it would do if you did something like `application/json;q=0.5, text/html`
hightower2 has joined #crystal-lang
ua_ has quit [Ping timeout: 256 seconds]
_ht has quit [Remote host closed the connection]
ua_ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> `Missing MIME type for extension "text/html" (KeyError)` welp
<FromGitter>
<Blacksmoke16> wait
<FromGitter>
<tenebrousedge> eh, probably no one uses that one
<FromGitter>
<Blacksmoke16> nvm, user error
<FromGitter>
<Blacksmoke16> doesnt seem like theres a way to get the extension based on the mime type
<FromGitter>
<Blacksmoke16> er maybe like `MIME.extensions("text/html").first`
<FromGitter>
<Blacksmoke16> i.e. given a mime type like `application/json` map it to a format like "html"
<FromGitter>
<Blacksmoke16> er "json" in that case
<FromGitter>
<tenebrousedge> I'm not sure what you're after where the MIME would not be descriptive
<straight-shoota>
mime lookup is primarily ext => type
<FromGitter>
<Blacksmoke16> i guess what im getting at is if you declare something as handling `html`, id need a way to map all the mime types for html to the name `html`
<FromGitter>
<tenebrousedge> `html` is just a name though
<FromGitter>
<Blacksmoke16> i.e. the user can just say `html` and not `application/xhtml+xml` or `text/html`