<FromGitter>
<girng> well to be fair to my level of comprehension, there is nothing u have to wrry about π
<FromGitter>
<drosehn> So if I've figured this out correctly, crystal has two nice ways to check whether individual flag values have been set. Is there a nice terse way to set or unset the flags? β In: https://carc.in/#/r/4ulm
<FromGitter>
<drosehn> Is there a cleaner-looking way to set a flag than `user_wants |= ShowFields::S_Ownr` ? β and to unset a flag than `user_wants &= ~ShowFields::S_Ownr` ?
<FromGitter>
<girng> what does |= and &= do?
<FromGitter>
<drosehn> It'd be nice to support something like `user_wants.s_ownr = true` and `user_wants.s_ownr = false`, for instance.
<FromGitter>
<drosehn> Those are how you turn one-bit on and one-bit off in a set of bits.
<FromGitter>
<drosehn> `user_wants |= ShowFields::S_Ownr` is saying "take the current value of `user_wants`, and make sure the flag named `ShowFields::S_Ownr` is turned on"
<FromGitter>
<drosehn> `user_wants &= ~ShowFields::S_Ownr` is saying "first take the value of `ShowFields::S_Ownr`, and then negate that value (so you have a value which is all the flags *except* `ShowFields::S_Ownr` turned on), and then bitwise-and that value to the current value of `user_wants`. This has the effect of turning off `ShowFields::S_Ownr` without changing any of the other flags.
<FromGitter>
<girng> wow O_o, interesting, thanks for explaining
<FromGitter>
<girng> i've seen that |= and &= before but just never really knew what it was doing lol
<FromGitter>
<drosehn> disclaimer: I still might be missing something, and there's already a nicer way to turn those flags on and off. But I think that's at least enough so you can get an idea of what the difference is between "plain enums" and "@[Flag] enums".
DTZUZO has quit [Read error: Connection reset by peer]
<FromGitter>
<asterite> I think enums started as something exclusive to C bindings, and then we moved them into the language. I agree that in Crystal they are not very useful... I never use them in personal code. Maybe we could remove them or rethink them to simplify the language.
<FromGitter>
<drosehn> (mind you: I only spent time on this because it's still awfully hot and humid outside, and I've been putting off the trip home. I really should leave soon though)
<FromGitter>
<drosehn> It might not take much to make them much nicer-looking for pure-crystal code. If I had a better understanding of macros I might try that.
DTZUZO has joined #crystal-lang
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
ashirase has quit [Ping timeout: 245 seconds]
<FromGitter>
<bew> Aaaand there's a new music named Crystal :p With a nice description: Being different is like
<FromGitter>
<bew> Grr
<FromGitter>
<bew> Being different is like being a Crystal, unique & beautiful β¨
ashirase has joined #crystal-lang
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
ashirase has quit [Ping timeout: 250 seconds]
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
ashirase has joined #crystal-lang
fifr has quit [Ping timeout: 255 seconds]
ashirase has quit [Ping timeout: 246 seconds]
bds has joined #crystal-lang
ashirase has joined #crystal-lang
fifr has joined #crystal-lang
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
fifr has quit [Ping timeout: 246 seconds]
bds has quit [Ping timeout: 245 seconds]
fifr has joined #crystal-lang
<FromGitter>
<drosehn> Hmm, wait. structs in crystal are immutable, aren't they?
<FromGitter>
<girng> sometimes i accidentally type struct instead of class lmao. i just replace struct with class and it fixes it
<FromGitter>
<girng> You know, I was doing some thinking today. I would like to dedicate a moment of silence (length of reading this) to thank this awesome community and especially the lead devs and contributors for maintaining and developing crystal. I honestly don't know where I would be right now. Lost in my js code in nodejs, not understanding object orientation as much as I do now, and other stuff this community has taught me
<FromGitter>
... over the past 8+months. It's truly appreciated, and I am grateful for it all from the bottom of my heart.
sz0 has joined #crystal-lang
<FromGitter>
<bew> Struct are not necessarily immutable, but you can use them without setter, which make them kinda immutable
<FromGitter>
<bew> And when you pass a struct to a function it'll always make a copy
<FromGitter>
<bew> You welcome @girng ;) we're happy to see you learn! (now go learn git, pleaaase! ^^)
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter>
<codenoid> cool
<FromGitter>
<vegai> @j8r oh, right, thanks for the stylish reminder
<FromGitter>
<vegai> ameba complains about those still, though :)
<FromGitter>
<ninetailschris> Weird issue with trying to add to int32 or int64 from modal. It works when you use a = p.credits.to_s.to_i32 + 150. But I can't seem to find the underlying issue.
<FromGitter>
<j8r> @vegai thank you, even unintentionally, to point this out. Maybe you are right to bring your own style, I'm asking in #6621 what people thinks about style enforcement
<FromGitter>
<vegai> Iβm all for 100% style enforcement personally
<FromGitter>
<vegai> but I can accept a linter tool like ameba as a compromise
<FromGitter>
<vegai> a linter tool has the benefit of potentially giving recommendations that have nothing to do with style
<FromGitter>
<icyleaf> @j8r i updated some comments on that commit.
Raimondii has joined #crystal-lang
<FromGitter>
<j8r> Is there a dev branch with specs that you wish to pass? I will see more clearly what you want to have π
ashirase has quit [Ping timeout: 240 seconds]
<FromGitter>
<icyleaf> wait a moment. :)
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
ashirase has joined #crystal-lang
<FromGitter>
<j8r> Anyway I've just migrated one of my project from Crest to Halite, and starred it yesterday :) The difference was mainly type safety, `.get` vs `:get`
<FromGitter>
<icyleaf> @j8r i found you starred Halite yesterday π welcome any issues.
<FromGitter>
<j8r> other thing totally unrelated, better to have images non versioned, at least put same in a dedicated branch that will have no history kept. Because each time you change the image this will increase the repo size (the old one kept in history + the new one). β Thanks for the branch, just fork the project
<FromGitter>
<icyleaf> You are right, i noted it to todo list.
<FromGitter>
<icyleaf> In fact, history only apply in redirect with 30x status code. i think i store the response early.
<FromGitter>
<j8r> hum I think you can't do because of the `.class`
<FromGitter>
<j8r> you have to find a way to replace this `Feature.class` to `Feature`, and then you will be able to `.new`
<FromGitter>
<j8r> the problem is that `Feature` in an abstract class
<FromGitter>
<vladfaust> Why can't I define an empty `alias MyNamedTuple = NamedTuple()`? I have method `foo(**values : MyNamedTuple)`, and `MyNamedTuple` may be empty (it's generated in macros)
<FromGitter>
<vladfaust> Turns into `expecting token 'CONST', not ')'`
<FromGitter>
<vladfaust> I think it's OK for `foo` to accept no arguments when `MyNamedTuple` is empty
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
<FromGitter>
<vladfaust> Ah, I get it, thanks!
<FromGitter>
<j8r> @icyleaf I will dig more on this later. I think the `@@features = {} of String => Feature.class` in the `Features` module approach may be the wrong one, maybe find another way
<FromGitter>
<j8r> I didn't know we could have class variable in modules, but that makes sense to be able to do it
<FromGitter>
<icyleaf> @j8r Thanks for helping, i will try different ways.
<FromGitter>
<icyleaf> For now, middlewares in Halite are works but not friendly for developer.
<FromGitter>
<vladfaust> And it wouldn't work with generic types I guess
<FromGitter>
<bew> Hmm agree that's quite ugly
<FromGitter>
<rishavs> How can I respond with a json in my http server? I am struggling with writing the json to the response io β I am assuming something like; β β ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b87cea14be56c5918b82f93]
return0e has quit [Ping timeout: 240 seconds]
return0e has joined #crystal-lang
<FromGitter>
<vegai> I know this is not classy
<FromGitter>
<vegai> but I was about to port that scanner thing I showed earlier into rust
<FromGitter>
<vegai> and noticed that they donβt have a way to read a single utf8 character from an IO stream
<FromGitter>
<vladfaust> Ticks would call system proc
<FromGitter>
<vladfaust> It's usually used like `echo "foo"` - system calls
<FromGitter>
<vladfaust> Damn gitter
<FromGitter>
<j8r> The ticks aren't to call a subprocess, `Process.run`?
<FromGitter>
<rishavs> I am using the ticks for the string interpolations
<FromGitter>
<vladfaust> @j8r is right
<FromGitter>
<vladfaust> Use `%Q[{"status": "success"}]`
<FromGitter>
<rishavs> so i can write stuff like `context.response.write (`{"status": "success", "data": {"type": "#{animal.type}", "taste": "#{animal.taste}" }`)
<FromGitter>
<j8r> @rishavs use `%({"status": "success"})` instead, ticks calls Process.run
<FromGitter>
<vladfaust> You don't need to call `.to_json` if the string is already json
<FromGitter>
<j8r> for example, if you do `puts `echo $SHELL``
<FromGitter>
<rishavs> holy crap, i think i just again got confused with JS strring interpolation.....
<FromGitter>
<vladfaust> So you either do `ctx.response.print(%Q[{"status": "success"}])` or `ctx.response.print({"status": "success"}).to_json)`
<FromGitter>
<talbergs> Hello, if I wanted to add a few methods/properties to `HTTP::Server::Context` how would that be done, so `kemal` upon that object crietion would create my version of `HTTP::Server::Context` ?
<FromGitter>
<vladfaust> It's called "monkey patching"
Groogy has joined #crystal-lang
<FromGitter>
<talbergs> Yes. Thank you!
<jokke>
hey o/ anyone here using vim to write crystal? I'm using neomake and i'm super unsatisfied with the error output of it. it's always just a line saying "instanciating 'Foo#bar()'" without any further details. Is there any way to have more verbose or more precise error messages in vim?
alex`` has quit [Quit: WeeChat 2.2]
<FromGitter>
<talbergs> I use neovim this deoplete plugin.
<FromGitter>
<talbergs> yes intelligent completion is wip. I type it all out still. =/
<jokke>
i mean it's better than no compile time checks at all but it's annoying to see that your code has an error and then having to run crystal build on the file yourself from the command line to see the what the error actually is
<FromGitter>
<talbergs> hm `ale` shows me few errors on :au bufwrite.
<jokke>
ale?
<FromGitter>
<talbergs> i gotta really dig around my dotfiles now, can't find where is it happening.
<FromGitter>
<talbergs> no, can't do no luck ^^. You'll need to poke around my dotfiles it's there somewhere.
<jokke>
niiice. neomake has ameba integration
bds has joined #crystal-lang
<bds>
Hello, I have a Kemal controller action that receives a HTTP POST from Slack. I want to reply to the request as soon as possible and do the work processing the event asynchronously. I am new to using `spawn` and it seems to work - is this correct?
<bds>
post "/events" do |env|
<bds>
raw_event = env.params.json
<bds>
spawn do
<bds>
end
<bds>
end
<bds>
EventHandler.call(raw_event)
<FromGitter>
<vladfaust> Yes, it is, @bds
<FromGitter>
<bds> @vladfaust ty! :)
<FromGitter>
<codenoid> hi
<FromGitter>
<codenoid> how to use bcrypt generate in crystal
<FromGitter>
<fridgerator> save `password.to_s` (from that example) in your database, when you want to check against a user supplied password, do `Crypto::Bcrypt::Password.new(@saved_password) === the_password_to_check`
<FromGitter>
<codenoid> right, the .new function load string hash
<FromGitter>
<codenoid> thankyou nick
<FromGitter>
<fridgerator> `==`, not `===`. I've been writing too much javascript
<FromGitter>
<codenoid> crystal syntax makes me horny
<FromGitter>
<fridgerator> thats..... good?
<FromGitter>
<ryanprior> thats.....unnecessary
<FromGitter>
<rishavs> > `==`, not `===`. I've been writing too much javascript β β same here. I am getting confused between their syntaxes
<FromGitter>
<j8r> π€
<FromGitter>
<codenoid> `undefined method '[]' for BSON::Code` when accessing `mongo_row_doc["parent_key"]["child_key"]`
<FromGitter>
<codenoid> what is simple way to access that
akaiiro has quit [Ping timeout: 246 seconds]
akaiiro has joined #crystal-lang
ua has quit [Ping timeout: 246 seconds]
ua has joined #crystal-lang
alex`` has joined #crystal-lang
bds has quit [Ping timeout: 252 seconds]
DTZUZO has quit [Ping timeout: 252 seconds]
<FromGitter>
<rishavs> has anyone done any image scraping in crystal? particularly getting the most representative image from a web page (like reddit and facebook do)
akaiiro has quit [Ping timeout: 246 seconds]
<FromGitter>
<codenoid> i do @rishavs
<FromGitter>
<codenoid> how to convert JSON::Any to hash in crystal,
<FromGitter>
<codenoid> <3 @girng β ok @bew i'll use it right now
<FromGitter>
<girng> there is also this site @codenoid that generates the class stuff from json but i forgot what it was called so u don't have to write all those properties
<FromGitter>
<girng> but i think it's different now since serializable is a thing now??
<FromGitter>
<girng> what is `io`, whatever the if block returns?
<FromGitter>
<girng> never seen a variable used like this before, i thought it could only work if it's doing `io = methodname()` or something lol
<z64>
yes, its whatever the `if` returns
<FromGitter>
<girng> that's cool
<FromGitter>
<snadon> is it possible to concatenate two `String?` together? I tried inside an `if first && last ... end` but still getting the String | Nil error
<FromGitter>
<snadon> i'm probably missing something, i thought it would compile if i check it is not Nil before doing anything
<FromGitter>
<Timbus> the thing you are missing is that .name is a method call, so you have no guarantees that it is not nil even after you check. what if .name returned a random value? what if .name was set to a different value in another thread?
<FromGitter>
<Timbus> you want `if name = mob.name`
<FromGitter>
<Timbus> then use `name`
DTZUZO has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter>
<snadon> thank you! it makes perfect sense
akaiiro has quit [Ping timeout: 244 seconds]
johndescs has quit [Ping timeout: 240 seconds]
johndescs has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<docelic_gitlab> @papierkorb: does bindgen try to compile the original library before generating bindings for it?
<FromGitter>
<ninetailschris> Looking into Time class docs and don't see why I would have this error with Time.parse https://carc.in/#/r/4utk. Any ideas?
<FromGitter>
<docelic_gitlab> ninetailschris: sure, as the message tells you you're missing the third argument (location)
<FromGitter>
<Sija> @ninetailschris `Time.parse` API changed in v0.26.0, from this version on youβd need to pass a `Time::Location` or use `Time.parse!`
<FromGitter>
<docelic_gitlab> this was added in 0.25.0
<FromGitter>
<Sija> See #6369
<FromGitter>
<ninetailschris> Thank you. I solved it :)
<FromGitter>
<vladfaust> @asterite, could you please help? I have to resolve type from `Assign` when it's `var = [] of Type`. I got to β β ```code paste, see link``` β β But there is no `StringLiteral#resolve` method. I need `type` to be resolved. `.id` doesn't work too, because one cannot resolve `MacroId`. ... [https://gitter.im/crystal-lang/crystal?at=5b887e95ac25fd11b5ba83e9]