<raz>
slightly patched, but only to wrap it for json:api
<raz>
(line 28, the rest is vanilla)
<raz>
oh and the header
<FromGitter>
<Blacksmoke16> sec, you can more easily simplify this
<raz>
JenniferTwin (their serialization thing) is JSON::Serializable, so otherwise it just works
<FromGitter>
<Blacksmoke16> like if your serialization logic is that trivial, have you considered just adding a helper method to the base controller type? then doing like `self.json UserTwin.new ...`?
<FromGitter>
<Blacksmoke16> where that method is just like
<raz>
well, not all my endpoints will return UserTwins
<raz>
but they will all return something JSON::Serializable, so that view does what i need
<FromGitter>
<Blacksmoke16> the view layer stuff is intended for more complex logic, bit overkill if all you want to do is wrap in a `data` key
<raz>
well, i thought that way i can just return JSON::Serializable and not worry
<raz>
but looks like i have to wrap a response anyway, to change the status code
<FromGitter>
<Blacksmoke16> to be clear what you had in the listener would work
<FromGitter>
<Blacksmoke16> as it sets that status based on `view.status`, which can be altered via the `@[ART::View]` annotation, like in the example i linked
<FromGitter>
<Blacksmoke16> could make your thing a bit simpler
<FromGitter>
<Blacksmoke16> i.e. fallback on the default if its not something it can handle
<raz>
hmm yea, will look into that. but i don't really like fallbacks to invisible code, so will probably keep the verbose version
<FromGitter>
<Blacksmoke16> okey dokey
<raz>
but it's all very pleasant so far π - if i can get POST then my api is almost done :D
<FromGitter>
<Blacksmoke16> whats holding back POST endpoint? the front end or?
<raz>
RequestParam is not in 0.11
<FromGitter>
<Blacksmoke16> ah right
<FromGitter>
<Blacksmoke16> dont just want to pin to the commit for now?
<raz>
maybe later, i'll just do my endpoints with GET for now ;)
<FromGitter>
<Blacksmoke16> as you wish
<FromGitter>
<Blacksmoke16> oh yea your thing is going to break in `0.12.0` :0
<FromGitter>
<Blacksmoke16> `action.view` is now `action.view_context` btw
<raz>
yup that's fine, i expect some breakage, it's 0.11 after all ;)
<raz>
and it's only ~100 LOC (w/o the endpoints) so i'll just patch up
<FromGitter>
<Blacksmoke16> easy enough
<raz>
yup, reminds me a lot of spring from java-land, but with so much less boilerplate that it's actually good
<FromGitter>
<Blacksmoke16> β€οΈ
<FromGitter>
<watzon> @Blacksmoke16 what would be the most efficient way to find and delete multiple records with Granite? Basically I want to delete every model that has a field that matches a query.
<FromGitter>
<watzon> But there might be a lot so I'd like to avoid deleting them one by one
<FromGitter>
<Blacksmoke16> mm probably some raw sql
<FromGitter>
<Blacksmoke16> with a `.exec`
<FromGitter>
<watzon> Damn I was hoping there might be a built in way
<FromGitter>
<Blacksmoke16> was an issue about it, i dont remember if it was ever implemented or not tho
<FromGitter>
<watzon> I think I'm finally going to break down and try writing my own "active record" style ORM. I need something that is feature complete and has built in migration support.
<jhass>
just gonna trust you on this, seems simple enough
<kevinsjoberg>
jhass: Sweet. There's one more incoming soon, a bit more complex.
<jhass>
not watching any of this, so ping me again then ;P
<kevinsjoberg>
It fixes the indentation rules that were taken from Ruby to correctly indent methods with a visibility modifier before it as well as classes marked as either private or abstract.
* FromGitter
* erdnaxeli:cervoi.se New day, new AoC, new questions :p
<raz>
watzon: clear orm or jennifer both do it (`Foo.where { bar = batz }.delete` generates a `delete from .. where ...` statement)
<FromGitter>
<cuteghost> Hi everyone, I need help regarding `HTTP::Server`. Thing is that I need to redirect a request to a new location. I have something like this β β ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fd0a7d967034a3e90f93943]
<FromGitter>
<cuteghost> and when I do request to the `127.0.0.1/signup` I get 200 as status code but no body with `YAY`
<FromGitter>
<cuteghost> Am I missing something that I need to implement
<FromGitter>
<Dan-Do> Try debugging using developer console in web browser, tab "network"
<FromGitter>
<Dan-Do> maybe the "Location" header should be full url, not sure :)
<hightower4>
cuteghost at a minimum you're missing the response with "content-type: text/html" etc.
<hightower4>
and you test whether your path is "/signup" twice
<hightower4>
(both in if and elsif)
<FromGitter>
<cuteghost> oh my bad
<FromGitter>
<cuteghost> in elsif location is different
<FromGitter>
<cuteghost> and it still doesn't work
<FromGitter>
<cuteghost> this is just a recap of my code it's a lot bigger
<hightower4>
it works for me
<FromGitter>
<cuteghost> try making request with HTTP::Client.exec
<hightower4>
curl 0:18000/signup -> redirecting, curl 0:18000/login -> YAY
<hightower4>
so the remaining issue is why it's not redirecting
<FromGitter>
<cuteghost> yeah I cant get body with HTTP::Client
<hightower4>
you are setting the status with == instead of =
<hightower4>
looks like you're trolling
<FromGitter>
<cuteghost> oh damn
<FromGitter>
<cuteghost> missed
<FromGitter>
<cuteghost> but it doesnt work with single = sign
<FromGitter>
<cuteghost> thank you a lot
<FromGitter>
<Daniel-Worrall> How come StaticArrays can't be instantiated with a size at runtime?
<yxhuvud>
uh, the whole point of StaticArray is that they should be possible to allocate as a known size on the stack or *embedded* in other objects.
postmodern has quit [Quit: Leaving]
<FromGitter>
<Daniel-Worrall> right
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
Nekka has quit [Ping timeout: 260 seconds]
Nekka has joined #crystal-lang
<straight-shoota>
hightower4, IIRC it was Q() that I mentioned would not work
<straight-shoota>
the percent sign could ambigously be attached to Q or the preceding {
<raz>
wait, is Q reserved?
* raz
suspiciously looks at his `class Q`
<yxhuvud>
no.
<raz>
good π
<FromGitter>
<asterite> Andriamanitra: nice!
<straight-shoota>
raz, Q() is a call and a method can't start with an upper case character
<straight-shoota>
you can't call a type/constant
<raz>
ah right, makes sense
<hightower4>
straight-shoota, ah yes, yes, ok great
<raz>
i'm in fact glad that crystal actively prohibits that, instead of coming up with absurd ideas like, i don't know, making public methods uppercase or such (that would be terrible)
* FromGitter
* erdnaxeli:cervoi.se you were right, my problem was related to using an ivar. But i don't get why the behavior change with an ivar or a "normal" var. β β Btw you can call `a` while still using `@a` in the function signature, I didn't know: https://carc.in/#/r/a35n
* FromGitter
* erdnaxeli:cervoi.se that's not the first time I noticed you can use `@a` and `a` to access the same variable, but I must admit I don't get the logic here
<straight-shoota>
when you have an ivar as a method argument like `def foo(@a); end`, that's essentially expanded to something like `def foo(a); @a = a; end`
<straight-shoota>
so the ivar is not *generally* available as a local variable, but the argument to a method is
<raz>
blacksmoke16: i always thought 16 is your age, but looking at your output i'm now more inclined to think it must be the athena team-size. you should credit those other 15 sometime :p
<straight-shoota>
if you change @a in the method body, a will still refer to the argument
<FromGitter>
<Blacksmoke16> ha, naw just my fav number :p
<raz>
:D
<straight-shoota>
the idea is that when the ivar is nilable but the argument is not, you can be sure that you have a non-nilable value in the local variable
* FromGitter
* erdnaxeli:cervoi.se right, but then how this record works: https://carc.in/#/r/a35t?
<raz>
solid work really. i mean good code is one thing, but you also kill it on the docs front and even community building / announcements along with it πββοΈ
<FromGitter>
<Blacksmoke16> i try π
<straight-shoota>
the record macro defines getters for all ivars
<raz>
and of course `application/json`, but that's a whole can of worms of its own (should prob be left to the user, parsing it to JSON::Any is prob not very useful in most cases)
<FromGitter>
<Blacksmoke16> id prob be more likely to specify the limitation of it
<FromGitter>
<Blacksmoke16> or looking at the docs prob would be doable to support both form datas
<raz>
yea, the current version is fine for me π - just wanted to give a heads up. `multipart/form-data` is normally only relevant for file uploads, but in practice i've also seen clients just use it for everything
<raz>
yup, you could in principle just parse both FormData and Params to a Hash(String, String). (i think String is binary safe when it's a file, right?) the only concern that follows then is "but what about that 8GB file upload". not sure how the other crystal frameworks handle it atm
<FromGitter>
<Blacksmoke16> i added a card to the backlog
<raz>
π(fyi, curl gives multipart/form-data with `curl -F`, handy for testing)
<FromGitter>
<Blacksmoke16> π
teardown has quit [Remote host closed the connection]
<FromGitter>
<RespiteSage> It's apparently undocumented, but I think it's the same as `each_permutation` except that it's combinations (no reordering of the same elements).
<FromGitter>
<Daniel-Worrall> Yeah, the idea to start from the end didn't occur to me. It was a good trick from last year's aoc too so I should have remembered
<FromGitter>
<RespiteSage> Yeah, I didn't think to do that, either.
<FromGitter>
<vladfaust> Indeed. May be someone came to extending `Spec` w/ channels
mistergibson has quit [Quit: Leaving]
<FromGitter>
<watzon> Vlad my friend!
<frojnd>
I'm using this shard: myhtml... I have problem with getting response.... When I try to access url with browser I get immediate response, but with HTTP::Client.get url sometimes I don't get response... can I see some more verbose messages to see what's going on?
<frojnd>
Wow after 4 minutes
<frojnd>
Anyways why is it taking it so long?
<FromGitter>
<Blacksmoke16> got some code to share?
<frojnd>
Later this is too much for me hehe at the moment
<FromGitter>
<watzon> Methods don't appear to be annotated even though they are, ans `cls.instance_vars` comes up as empty as well.
<FromGitter>
<watzon> I thought the `finished` macro would wait for that all to be defined
<FromGitter>
<Blacksmoke16> instance vars is only a thing within context of a method
<FromGitter>
<watzon> Ahh ok, well how about annotated methods?
<FromGitter>
<Blacksmoke16> those should be fine
<FromGitter>
<Blacksmoke16> but you dont have any methods with that annotation
<FromGitter>
<watzon> Ok so it isn't counting the methods created by the `property` keyword as being an annotated method. Man I just want to annotate properties haha, it shouldn't be this complicated.
<FromGitter>
<Blacksmoke16> thats what the annotation is being applied to
<FromGitter>
<Blacksmoke16> the ivar created by `property`
<FromGitter>
<watzon> Right. I guess I might need to create an initializer for the abstract class then, and then make the generated initializer call super. Think that will work?
<FromGitter>
<Blacksmoke16> what are you trying to do exactly?
<FromGitter>
<watzon> For now just experimenting and seeing if the way I want to lay out models will even work
<FromGitter>
<Blacksmoke16> have you considered *not* generating an initializer and just let it be like any other crystal type?
<FromGitter>
<anthonyshull> anyone know of any good resources on using crystal for language programming? lexing, parsing, etc.?
<FromGitter>
<anthonyshull> we are looking at building a tool similar to https://github.com/zyedidia/Literate but with support for multiple languages
<FromGitter>
<Blacksmoke16> if you follow what the compiler does, just a 1k long if/elseif statement
<straight-shoota>
there are actually lots of compilers/interpreters written in Crystal you can take a look at how they deal with these things
<FromGitter>
<anthonyshull> i was looking at something like mint which is pretty impressive
<straight-shoota>
indeed
<FromGitter>
<anthonyshull> nice
<FromGitter>
<watzon> @Blacksmoke16 that's half the goal. I want to make the generated initializer optional, which is what the `Table` macro is for. People will just have to remember to call `super` in their own initializer I guess.
<FromGitter>
<Blacksmoke16> thats going to be a nightmare
<FromGitter>
<Blacksmoke16> i can speak from experience with granite
<FromGitter>
<Blacksmoke16> i guess what stuff needs set in the parent initializer anyway?
<FromGitter>
<Souravgoswami> Just a simple question I have got for months now... How do I optimize the binary? Like passing -O3, -mtune=native, -march=native clang like flags?
<FromGitter>
<Souravgoswami> Well got it... But I don't think I am talking about this. In GCC/Clang/Icc, you can pass the -O3 option to optimize a binary... Does crystal have such implementation?
<FromGitter>
<Blacksmoke16> no, its the `--release` flag
<FromGitter>
<Blacksmoke16> that tells LLVM to produce an optimized binary
<FromGitter>
<Souravgoswami> Ah it's quite nice to have just one flag... Thanks a lot!
<FromGitter>
<watzon> @Blacksmoke16 the main thing the parent initializer is going to do is handle the annotations. Granted this is all discovery right now, chances are I'll find that Crystal isn't up to the task as I want it to be and I'll have to settle for something not as nice. Annotations really need some work.
<FromGitter>
<Blacksmoke16> is the easy way to do it
<FromGitter>
<Blacksmoke16> looks like `y` is the whole array
* FromGitter
* erdnaxeli:cervoi.se IΒ mean `y`
<FromGitter>
<Blacksmoke16> what are you expecting?
* FromGitter
* erdnaxeli:cervoi.se two first values in x, and the last one in y
<FromGitter>
<Blacksmoke16> why?
* FromGitter
* erdnaxeli:cervoi.se ruby does that
<FromGitter>
<watzon> Crystal isn't Ruby though ;) haha
<FromGitter>
<Blacksmoke16> ^
* FromGitter
* oprypin:matrix.org post, please ignore)
<FromGitter>
<watzon> (erongi esaelp ,tsop tset)
* FromGitter
* erdnaxeli:cervoi.se agree crystal in not ruby, but we could not deny crystal takes inspiration from ruby :p
<FromGitter>
<Blacksmoke16> yes, but only the good things π
* FromGitter
* erdnaxeli:cervoi.se I would have expected everything to be in `x` and not `y`
<FromGitter>
<Blacksmoke16> whats the end goal tho? why not just `.each do |y|`
<FromGitter>
<Blacksmoke16> and there, `y` has the whole array
<oprypin>
well shit, the irc bridge is not equipped to handle some newly changed json responses from gitter api
<oprypin>
and i cant recompile it because it's like 3 crystal versions behind
* FromGitter
* erdnaxeli:cervoi.se end goal was just trying to run a ruby AoCΒ solution in crystal ^^
* FromGitter
* erdnaxeli:cervoi.se IΒ will do `.each do |y|`
* FromGitter
* erdnaxeli:cervoi.se why `.each do |*x, y|` puts everything in `y` and nothing in `x` ?
<FromGitter>
<Blacksmoke16> nothing to splat so `x` is empty, then rest of stuff goes into `y`?
<FromGitter>
<Blacksmoke16> granted idk if that should even compile
* FromGitter
* erdnaxeli:cervoi.se I guess because if everything is in `x`, what is the value of `y`?Β but for `y` teh empty value is easy, it's an empty tuple
<FromGitter>
<KevinSjoberg> What are people using for editor when programming Crystal? I've tried a couple so far and they all seem to fail with basic indentation.
* FromGitter
* erdnaxeli:cervoi.se it should probably not compile
<FromGitter>
<Blacksmoke16> @KevinSjoberg sublime with crystal plugin works fine for me
<FromGitter>
<Blacksmoke16> formats on save and has highlighting
* FromGitter
* erdnaxeli:cervoi.se with crystal plugin but that's not so good. Except highlighting, there is not much.
<FromGitter>
<KevinSjoberg> @Blacksmoke16 I'll guess I'll have to try it then. I just spent 2 hours on fixing issues in TextMate. Overall it works great, formats on save as well. But indentation was broken.
<FromGitter>
<Blacksmoke16> did you tell it to use 2 spaces?
<FromGitter>
<Blacksmoke16> you install the plugin i assume?
<FromGitter>
<KevinSjoberg> Hmm, but the example I gave above doesn't work either.
<FromGitter>
<KevinSjoberg> Yep, I have the Crystal plugin installed.
<FromGitter>
<Blacksmoke16> :shrug: worked for me
<FromGitter>
<Blacksmoke16> maybe some config option you need to do?
<FromGitter>
<KevinSjoberg> Hmm. So `private def abc` works but `abstract def abc` does not. Anything before `class` breaks indentation while `class A` works.
<FromGitter>
<KevinSjoberg> Are you seeing the same thing?
<FromGitter>
<Blacksmoke16> fwiw if you just keep typing it'll format on save to be correct
<FromGitter>
<Blacksmoke16> :shrug:
<FromGitter>
<KevinSjoberg> Yeah, I do the same but it's annoying to press enter and then being in a state where the editor is fighting you.
<FromGitter>
<Blacksmoke16> yea dunno, never noticed
<FromGitter>
<Blacksmoke16> might be the plugin config somewhere? idk how thats all setup
<FromGitter>
<KevinSjoberg> Good news, it's based on TextMate where I fixed this. So PR incoming. :slight_smile:
<raz>
i'm back on vscode. wanted to like sublime, but no live search killed it for me. also the syntax highlighting is kinda weird after coming from vs (doesn't recognize as many keywords)
<straight-shoota>
raz, search experience in sublime is a main factor I switched to VS code
<straight-shoota>
... and all that other nice stuff you can do with that sidebar =)
<raz>
yea, if only it wasn't so laggy
<oprypin>
o man one day i will have to switch to it
<oprypin>
just too used to Kate, seemingly the only editor with (filtered) file tree view
<raz>
the terrible truth is, search in vscode isn't even good. it's just the bare minimum (realtime search) that you'd expect nowadays
<raz>
sublime just doesn't have even that
* raz
sad editor noises
<FromGitter>
<j8r> oprypin I tried Kate, looks nice, but no Crystal support :(
<oprypin>
yea i decide on a file-by-file basis, is Ruby highlighting or Python highlighting less broken in this case
<raz>
oh crystal highlighting works fine in vscode. even indentation is pretty solid
<raz>
not great, but at least it doesn't screw up constantly ;)
<raz>
when you see the amazing things that vscode does for js tho, you get jealous still
<raz>
i think vlad was the hero who created the plugin. we should bribe him to polish it up :P
<FromGitter>
<j8r> I have Geany, actually using 32MB :) β Not much advanced features, though
<raz>
hm, never heard of that
<oprypin>
raz, hm? no
<FromGitter>
<j8r> I don't mind spending a bit more time searching, it let me look back at part of my code, and thinking about it
<raz>
oprypin: oh, another faust
<FromGitter>
<j8r> Another faust not named vlad?
* FromGitter
* j8r not making a joke about one named panzer...
<straight-shoota>
faustino
<FromGitter>
<j8r> Haaa!
<FromGitter>
<j8r> We don't see him much now...
<hightower4>
did you see Atom editor, I think it's a fork of Sublime or something?
<hightower4>
(didn't use it... just know it was a thing, at least a couple years back)
<FromGitter>
<j8r> hightower4 VScode is a fork of Atom, sort of now
<oprypin>
seems like vscode killed atom?
<oprypin>
doesnt matter cuz both are owned by microsoft lol
<FromGitter>
<j8r> right, before I was kind of "not fair for GH". But now, "whatever, why there are Atom AND VSCode?!"
<FromGitter>
<j8r> also beware, like Chrome, VSCode has corp crap by default
<FromGitter>
<j8r> ...wtf why google result are in French
<FromGitter>
<j8r> They know my IP so suppose I want French, look at my browser lang omg...
<oprypin>
yes π
<oprypin>
hate being an honorary German
<FromGitter>
<j8r> so your results are germany?
<FromGitter>
<j8r> "frenchy" for me
<oprypin>
hm actually not, even not logged in
<FromGitter>
<j8r> I have literally nothing in French on my PC... maybe the crappy azerty keyboard. β I don't like sites guessing things on the IP of visitors
<FromGitter>
<j8r> it is intrusive, and inaccurate. More than just reading the language in user agent - simple