RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
DTZUZO has joined #crystal-lang
<FromGitter> <robacarp> A lot of nice new features too though!
zachk has quit [Quit: Leaving]
<FromGitter> <faustinoaq> > An upgrade guide would have been nice, maybe I miss it โŽ โŽ @eliasjpr Did you see https://crystal-lang.org/2018/06/15/crystal-0.25.0-released.html ? ๐Ÿ˜…
<FromGitter> <faustinoaq> > WARNING: this shard initialy implemented the now obsolete JsonWireProtocol, but should be compatible with the W3C Webdriver spec. โŽ โŽ ^^ https://github.com/ysbaddaden/selenium-webdriver-crystal#seleniumwebdriver
<FromGitter> <faustinoaq> @eliasjpr @paulcsmith I think would be nice to create a new shard using latest updated protocol
<FromGitter> <fgimian> I believe the only way forward is to drop support for everything except 0.25.0+, at least that's how I'm approaching it. I noticed the major breaking changes when I started developing my libriary so I had been running my own build from the master branch up until now.
<FromGitter> <fgimian> YAML, JSON and File.stat in particular affected me
<FromGitter> <fgimian> I actually couldn't get what I wanted out of `File.info` personally, need to look at it again.
<FromGitter> <fgimian> So I re-implemented `File.stat` in my library using the previous code in Crystal stdlib
<FromGitter> <fgimian> not sure how Python manages to do it, but they have an `os.stat` and stay compatible with Windows and Unix
<FromGitter> <paulcsmith> I think until 1.0 itโ€™s ok to make breaking changes without backward compatibility. Iโ€™d much rather the core team spend time getting to 1.0 than maintaining old versions of code. It kinda sucks to update all the shards, but thatโ€™s ok if it saves the Crystal team time
<FromGitter> <paulcsmith> With that said, if adding a comparability layer for just the previously released version is fairly easy then thatโ€™d be great to have!
<FromGitter> <fgimian> Absolutely agreed!
<FromGitter> <fgimian> I'm not sure how trivial that would be in this case though
<FromGitter> <fgimian> (re staying compatible with both versions in libraries that is)
<FromGitter> <fgimian> one of the things I love most about Crystal is how refined and well-thought-out the stdlib is
<FromGitter> <fgimian> so any improvements (breaking or not) there to continue in that tradition are highly welcome from my end
<FromGitter> <paulcsmith> Yeah me too :)
<FromGitter> <fgimian> ๐Ÿ˜„
sz0 has quit [Quit: Connection closed for inactivity]
That_Guy_Anon1 has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 265 seconds]
<FromGitter> <fgimian> Forgive me guys, but is there a way to catch a Ctrl+C in a Crystal program?
<FromGitter> <fgimian> a simple rescue won't do, and there are no Interrupt or SystemExit exceptions available that I can see
<FromGitter> <fgimian> maybe i need to use signal trap
<FromGitter> <S-YOU> Signal::INT.trap does not work? I personally use C function directly though.
<FromGitter> <codenoid> morning
<FromGitter> <fgimian> It works perfectly for me
<FromGitter> <fgimian> ๐Ÿ˜„
<FromGitter> <S-YOU> ๐Ÿ‘
<FromGitter> <fgimian> thanks @S-YOU
<FromGitter> <fgimian> I am just used to catching an exception, so I was hunting for one
<FromGitter> <fgimian> in Python there's `KeyboardInterrupt`, and I think Ruby has `Interrupt`
<FromGitter> <S-YOU> Yeah, as long as you let Kernel context switches you can use that xD
<FromGitter> <codenoid> cool
<FromGitter> <fgimian> ta!
<FromGitter> <fgimian> guys just a silly (i'm sure this is obvious) question ...
<FromGitter> <fgimian> let's say I have โŽ โŽ `````` [https://gitter.im/crystal-lang/crystal?at=5b25da84c75ba81a2cbdc3ab]
<FromGitter> <fgimian> inside a method
<FromGitter> <fgimian> how can I make the block *optional*?
<FromGitter> <fgimian> i.e. only perform the yield if a block is provided
<FromGitter> <fgimian> I can't seem to figure it out ๐Ÿ˜•
<FromGitter> <fgimian> perhaps I need to overload?
<FromGitter> <robacarp> yeah, you need to make an overload
<FromGitter> <fgimian> thanks so much @robacarp
<FromGitter> <fgimian> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b25db0c4a5db82dd58f13df]
<FromGitter> <fgimian> works perfectly in case anyone has the same question ๐Ÿ˜„
<FromGitter> <fgimian> i'm not sure if `&block` is even needed, testing
<FromGitter> <fgimian> nah it's not
<FromGitter> <robacarp> it's not, but it helps readability
<FromGitter> <fgimian> true
<FromGitter> <fgimian> thanks a lot
<FromGitter> <robacarp> no problem
That_Guy_Anon1 has quit [Quit: Leaving]
That_Guy_Anon has joined #crystal-lang
<FromGitter> <bararchy> How's everyone handling the 0.25.0 upgrade?
<FromGitter> <bararchy> The JSON change took us sometime to work around with
<FromGitter> <codenoid> i still use 0.24
<FromGitter> <bararchy> @codenoid because of selenium? :)
<FromGitter> <codenoid> i fear to upgrade crystal
<FromGitter> <fgimian> @bararchy The JSON / YAML changes were an adjustment, but I think that overall they are for the better. I'm really happy with 0.25.0 so far. (though as mentioned earlier, I switched to the master branch of Crystal a few weeks after starting to use 0.24 and finding breaking changes, so it's been less of a transition)
<FromGitter> <fgimian> I think checking code against the master branch every couple of weeks is probably not a bad idea actually.
<FromGitter> <fgimian> @codenoid Feel free to ask any questions when you upgrade, hopefully it won't be so painful.
<FromGitter> <bararchy> True, I guess as Crystal becomes more mature the impact of new versions will subdue
<FromGitter> <fgimian> yah
<FromGitter> <fgimian> this is why I would still be weary of using Crystal in production atm personally
<FromGitter> <fgimian> but for personal projects, I don't think it's a problem
<FromGitter> <fgimian> the language is great enough (and unique enough compared to other choices) that it justifies living with some breaking changes (in my eyes)
<FromGitter> <codenoid> yeah, i don't want to use my time to following breaking change
<FromGitter> <fgimian> yah, but you never know, maybe in the next year or so we see 1.0, I hope (and pray) hehe
<FromGitter> <fgimian> the latest hangout was very positive and gave me hope ๐Ÿ˜„
<FromGitter> <bararchy> And RX14 Windows support is coming nicely
<FromGitter> <fgimian> That's awesome!! ๐Ÿ˜„
<FromGitter> <valamorgon> after upgrading to crystal 0.25, I got this: undefined method 'each' for JSON::Any
<FromGitter> <valamorgon> so how we will loop after parse json
<FromGitter> <fgimian> check out the docs
<FromGitter> <fgimian> the behaviour has changed in JSON
<FromGitter> <valamorgon> I checked but we dont have each method
<FromGitter> <valamorgon> I couldnt find info related to it
<FromGitter> <fgimian> ah yes, I just need to pop out for a bit but will try to help as soon as I'm back online
<FromGitter> <fgimian> otherwise maybe someone else can assist here
That_Guy_Anon has quit [Remote host closed the connection]
<FromGitter> <fgimian> @valamorgon try to cast it to a hash, using .as(Hash)
<FromGitter> <fgimian> can you share a code snippet showing the problem?
<FromGitter> <fgimian> sorry itโ€™s .as_h
<FromGitter> <fgimian> donโ€™t hesitate to look at the Crystal source, itโ€™s easy to read
<FromGitter> <valamorgon> hey @fgimian for nested jsons, should I as_h each time for loop? I actually started to do it, but I think it was way a lot easier to loop json::any
<crystal-gh> [crystal] r00ster91 opened pull request #6208: Fix examples in Formatting and Parsing Time (master...patch-5) https://git.io/vhMZp
<FromGitter> <fgimian> lol i believe you have to use as_a buddy
<FromGitter> <fgimian> happy to be corrected
<FromGitter> <valamorgon> as_a for array as_h for hash, now did it like this
<FromGitter> <valamorgon> hope to have each for json:any again some day
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
ua has quit [Ping timeout: 276 seconds]
snsei has quit [Ping timeout: 276 seconds]
<FromGitter> <fgimian> yeah that would be nice tbh
<FromGitter> <fgimian> ๐Ÿ˜„
<FromGitter> <fgimian> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b2616aa47559749102f6a3a]
<FromGitter> <fgimian> it definitely feels pretty tough to work with JSON and YAML data structures atm
<FromGitter> <fgimian> p.s. I like cows
<FromGitter> <fgimian> I wonder how other static languages deal with this one ๐Ÿ˜„
<FromGitter> <valamorgon> lol
<FromGitter> <fgimian> hahaha ๐Ÿฎ ๐Ÿ„
<FromGitter> <fgimian> some of my test scripts have some pretty ridiculous strings in them
<FromGitter> <fgimian> I'm sure everyone does the same thing
<FromGitter> <valamorgon> reminds me this haskell dude who happens to love cats: https://www.youtube.com/watch?v=RqvCNb7fKsg
ua has joined #crystal-lang
<FromGitter> <fgimian> watching
<FromGitter> <fgimian> omg that desktop is going to give me nightmares
<FromGitter> <MKRhere> Whew
<FromGitter> <fgimian> lmao this guy is hilarious
_whitelogger has joined #crystal-lang
<FromGitter> <codenoid> hi, how i change variable value at compile time
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <fgimian> @codenoid can you give an example?
<FromGitter> <fgimian> you can manipulate constants using macros
Groogy has joined #crystal-lang
<Groogy> Morning! o/
<FromGitter> <stronny> Morning guys! I'd like to ask again
<Groogy> shoot
<FromGitter> <stronny> Hi! Is it okay to subclass Hash? โŽ โŽ ```code paste, see link``` โŽ โŽ The two types seem the same to me, what does crystal complain about? [https://gitter.im/crystal-lang/crystal?at=5b2631bff3af564911d3a216]
<Groogy> eh not sure, but right there it looks more like you want an Alias anyway?
<Groogy> also right you should be using JSON::Any I believe not JSON::Any::Type
<Groogy> why it fails is probably something because constants for types seems to be pretty strict, if you check this out https://play.crystal-lang.org/#/r/4b89
<Groogy> so even if they look to be the same, the compiler will err
<FromGitter> <fgimian> Hey guys, there's an argument in Python's `subprocess` module which is as follows: โŽ โŽ ```code paste, see link``` โŽ โŽ Would you happen to know a way to do this in Crystal? It allows for performing a setuid or setgid in the child process just before it runs for example. [https://gitter.im/crystal-lang/crystal?at=5b263478f3e3007371b8eec1]
<FromGitter> <fgimian> the Python code is all in C ... just about to look at it but I'm scared ๐Ÿ˜Ÿ
<FromGitter> <stronny> python doesn't have lambdas like other langs do, so it invents all kinds of defer mechanics instead
<FromGitter> <stronny> you should probably just do what you need directly
<FromGitter> <stronny> note that in order to call another program from your process you have to 1) fork and then 2) exec
<FromGitter> <stronny> you are free to do anything you need between those two
<FromGitter> <fgimian> thanks so much @stronny, will give it a try ๐Ÿ˜„
<FromGitter> <stronny> Groogy: your example at least makes it clear that two types are not `==` as well as do not have the same signature
<FromGitter> <stronny> I am still unclear why crystal tells me that it expects "A, not A"
<Groogy> ยฏ\(ยฐ_o)/ยฏ
<FromGitter> <codenoid> yeah
<FromGitter> <codenoid> i mean can i add custom argument at crystal compile time
<FromGitter> <codenoid> crystal build --customarg "-gwag wagwaa"
<Groogy> you mean like flags?
<Groogy> though not sure if they can have values or just be set
<FromGitter> <fgimian> @stronny Your info was super helpful, I can see exactly what you're saying in `process.cr`. Looks like maybe I can subclass it and override `self.exec_internal` to add some logic in before the call to `LibC.execvp` ๐Ÿ˜„
<FromGitter> <stronny> you're welcome!
Jenz has joined #crystal-lang
<Jenz> Morning
<Jenz> Or evening, or whatever it is for you guys :D
<Groogy> o/
<Jenz> What does 'o/' mean? I've seen it a couple if times, but never understood what it is
<FromGitter> <fgimian> never seen that
<Jenz> ยฏ\_(ใƒ„)_/ยฏ
<FromGitter> <fgimian> may I ask where you saw it?
<Jenz> Hmm, might have been here; but I think also in some Discord server
<FromGitter> <stronny> it's a picture of a head and a raised hand, so a greeting
<Jenz> Ah, I see it now. Thanks!
<Groogy> Jenz: it's a guy waving
<Jenz> Yeah, thanks
* FromGitter * codenoid a
<FromGitter> <hmans> I know I'm a bit late, but congrats to everyone on the release of 0.25! \o/
* Jenz \o/
<FromGitter> <codenoid> \o\
<FromGitter> <codenoid> *o*
* Jenz /o/
* Jenz \o\
* Jenz \o/
<FromGitter> <rishavs> -- o --
<FromGitter> <rishavs> Is there a way to install the latest checkin using shards?
<RX14> @stronny i'm still confused about your usecase - JSON has no concept of sparse arrays. How does your JSON relate to sparse arrays?
<RX14> perhaps some example code would help
<Jenz> @rishavs 'checkin'?
<RX14> commit I assume
<Jenz> Ah
<FromGitter> <stronny> I get the initial tree from JSON, later I want to modify it
<FromGitter> <rishavs> old svn lingo :/
<Jenz> Why, why do I only get Terraria hits when i search for 'crystal shards'
<FromGitter> <rishavs> I want to run kemal with its last commit
<Groogy> you've probably been googling bunch of other terraria stuff before and crystal shards is a thing in that game? :P
<RX14> @stronny so the initial array isn't sparse at all, then you want to use it as a sparse array later?
<Jenz> @rishavs: you can specify 'branch: master'
<RX14> I really wish I had an idea of the code and json to see whats going on
<FromGitter> <stronny> I'm not picky about the mechanics, I just want to be able to assign a value out of the existing range
<RX14> but how far out of the exisiting range
<Jenz> @rishavs: see https://github.com/crystal-lang/shards/blob/master/SPEC.md for full details of shards.yml format
<Jenz> s/format/specification/
<FromGitter> <stronny> ideally anywhere in typeof(index)
<Groogy> how yeah while I got you here RX14, I've cleared the cache in ~/.cache/crystal, is there any more I need to clear to fix debug info making compiler crash when I compile with --debug in 0.25?
<RX14> no
<RX14> its a bug
<Groogy> aah it's known? I tried to find a issue on it
<FromGitter> <rishavs> > *<Jenz>* @rishavs: see https://github.com/crystal-lang/shards/blob/master/SPEC.md for full details of shards.yml format โŽ โŽ Thanks.
<Jenz> Np
<RX14> Groogy, --debug is only useful with gdb/lldb anyway
<RX14> so it's not the biggest of deals
<RX14> the default without --debug is to include line numbers in the debug info
<RX14> --debug adds variable names
<RX14> and --no-debug removes all debug info
<FromGitter> <rishavs> even Sentry is broken ๐Ÿ˜ฟ
<RX14> @stronny I'm still struggling to imagine the datastructure you're using
<FromGitter> <rishavs> 1) 25 is murdering me
<FromGitter> <stronny> RX14: I'm not insisiting on sparse arrays by the way, what really bugs me right now is that I'm unable to resize the array manually
<FromGitter> <codenoid> yeah, that's why i fear upgrade crystal to latest verfsion
<RX14> @stronny well since arrays always have to return *a* value for 0...arry.size, then the array has to be filled with something
<RX14> so you can just keep inserting nil until you get the size you want
<FromGitter> <stronny> that's what I am doing right now and it's suboptimal
<RX14> yeah
<RX14> how much of your array is nil and how much is data
<RX14> i.e. how sparse is it
<RX14> is the JSON sparse at all?
<FromGitter> <stronny> I will only know at runtime
<RX14> yeah but estimate
Jenz has quit [Ping timeout: 264 seconds]
<FromGitter> <stronny> let's take an example from doc: `array[1_000_000] = "that's a waste"` โŽ so, a million nils and one string
<RX14> so what are you trying to build, big picture?
<FromGitter> <stronny> I need to support a dynamic structure that users fill in at runtime
<Groogy> why do you need to keep the nil values though?
<FromGitter> <stronny> I don't, that's the point
<FromGitter> <stronny> I want a type that only allocates for non-nils
<RX14> @stronny whats that data structure actually holding, like can you tell me what the whole application you're building is
<RX14> the whole project or whatever
<FromGitter> <stronny> A generic data processor with plugins and JSON apis
<FromGitter> <stronny> So I have no idea what it will hold, I have to account for any possibility
<RX14> hmm
<FromGitter> <stronny> I mean manual extenstion with a << JSON::Any.new(nil) does work now, it's just not optimal
<RX14> yeah I get that
<FromGitter> <stronny> while you are here can you also take a look?
<RX14> I'd say use a hash
<RX14> but then you loose the ordering of the indexes
<RX14> if you're making a generic JSON processor, how would you then serialize the sparse array back out?
<RX14> you'd end up generating a JSON array with 999999 nils then 1 value
<FromGitter> <stronny> that's a good point!
<RX14> it just seems to me that you might not actually need sparse arrays
<RX14> because JSON doesn't support sparse arrays
<RX14> so why should a JSON processing tool?
<FromGitter> <stronny> all right, let's drop sparse arrays
<FromGitter> <stronny> it there a reason then to not allowing a manual array resize?
<RX14> because what do you fill the space with?
<RX14> if you have an Array(String)
<FromGitter> <stronny> a second argument?
<RX14> you can't fill the space with nil
<RX14> ok, thats fair enough
<FromGitter> <stronny> `a.resize(1_000_000, "")`
<RX14> then the answer is because nobody's needed it
<RX14> and it's pretty easy to create your own utility method to do it
<RX14> because it's just << until you get to the correct size
<FromGitter> <stronny> Yes, but I will have to subclass Array
<RX14> why?
<FromGitter> <stronny> and JSON.parse will not use my subclass
<FromGitter> <stronny> how else? it's private
<RX14> << and size aren't private
<RX14> also we have array[array.size...new_size] = nil
<RX14> which is a single line
<RX14> and does what you want
<FromGitter> <stronny> it doesn't
<FromGitter> <stronny> oh
<FromGitter> <stronny> I didn't test the Range
<FromGitter> <stronny> I will, thanks!
<RX14> no
<RX14> its the same
<RX14> i just checked
<RX14> it doesnt resize the array
<FromGitter> <stronny> yeah
<FromGitter> <stronny> so would't a call to resize be much faster than a million .pushes?
<RX14> yeah, it would
<RX14> but
<RX14> pushing would still be fairly fast
<FromGitter> <stronny> so it we start from zero size how many reallocs will happen along the way?
<RX14> something close to log2(n) i guess
<RX14> so ~20
<FromGitter> <stronny> we might also be left with twice the needed size allocated
<FromGitter> <stronny> If we allocate a new Array with the size given in .new and copy old values, will it be resizable later?
<FromGitter> <stronny> oh, oh, I know!
<FromGitter> <stronny> how about adding a `.new(initial_size : Int32, a : Array(T))` that will allocate a new array and copy values from the given array?
<RX14> but if we've decided that sparse arrays aren't needed, why are we still trying to insert at 1 million?
<RX14> you'll still end up with serializing out 999999 nils
<RX14> whether you call the array sparse or no
<RX14> I just don't see why you wouldn't treat an array like an array and support only append ops
<FromGitter> <stronny> I guess I'm going on inertia, sorry =)
<FromGitter> <stronny> Even if sparse arrays aren't needed, I will still have to allow users to insert at an arbitraty index
<FromGitter> <stronny> and then yes, serializing all the nils
<RX14> i don't get why you have to support that
<FromGitter> <stronny> Because It's better than a runtime exception?
<RX14> is it?
<FromGitter> <stronny> well there are reasons to support either side depending on factors
<RX14> ruby supports one way
<RX14> crystal supports the other
<RX14> and most languages are like crystal
<RX14> ruby is really the odd one out
<FromGitter> <stronny> well, I use ruby and crystal not because they are like most languages, quite the opposite in fact =)
<FromGitter> <stronny> anyway, I see your points and will have to think it over again
<FromGitter> <stronny> probably you are correct and I should just forbid that
<RX14> because is it better to crash now or crash later when you generate 100MiB of nils? :P
<RX14> in your serialized json
<FromGitter> <stronny> or have a third way and check the diff size against some reasonable limit
<RX14> >> ("nil, ".bytesize * Int32::MAX)
<DeBot> RX14: # => 2147483643 - https://carc.in/#/r/4b98
<FromGitter> <stronny> like allow out of bounds assignment if it's say 1000 or less indices off
sz0 has joined #crystal-lang
<RX14> >> ("nil, ".bytesize * Int32::MAX) / 1024**2
<DeBot> RX14: # => 2047 - https://carc.in/#/r/4b99
<RX14> 2 gigabytes of nil
<RX14> i think an exception is better
<crystal-gh> [crystal] kostya opened pull request #6209: Serializable, remove version conditions (master...serializable_cleanup) https://git.io/vhMB4
<FromGitter> <stronny> all right, thanks for the explanation, sorry for using your time
<RX14> no, its no problem
<FromGitter> <vlazar> When I have nillable object `bar` inside object `foo` what would be a Crystal way to check for `bar.value` in spec? Here is what I'm trying to do https://play.crystal-lang.org/#/r/4b97 โŽ โŽ In Ruby I would just check for `foo.bar` to not be nil before checking for `foo.bar.value`. In Crystal that wouldn't compile. So what's an idiomatic way in Crystal to do this?
<RX14> I was playing minecraft while chatting anyway so it's not like i'd be using the time productively anyway :P
<FromGitter> <stronny> also https://crystal-lang.org/docs/guides/testing.html โŽ โŽ ```actual.should be_nil # passes if actual.nil?``` [https://gitter.im/crystal-lang/crystal?at=5b264c0c9a211e26bb6990f4]
<FromGitter> <hmans> Is there any issue with the new HTTP::Server interface? My compiler is claiming the only overload for #bind is with socket : Socket::Server
<FromGitter> <vlazar> @stronny the program does non compile, something like `bar.should_not be_nil` or `bar.nil?.should_not be_false` doesn't change it
<FromGitter> <hmans> I'm pretty sure the documentation's example of `server.bind 8080` should say `server.bind_tcp 8080` (and some other occurences)
<RX14> yes
<RX14> thats a known issue
<RX14> we medded up the docs
<RX14> messed*
<FromGitter> <hmans> Ah, I see it's already fixed on master.
<FromGitter> <hmans> Other than that, my project is compiling fine... cool!
<FromGitter> <stronny> @vlazar you have to check `bar`, not `bar.value` first, then use `is_a?` to separate execution paths
<FromGitter> <vlazar> I understand https://play.crystal-lang.org/#/r/4b9f
<FromGitter> <stronny> also it's a better design to avoid nils if possible in my opinion
<FromGitter> <vlazar> my question is how I write specs if the fact that some object can be nil is checked by compiler
<FromGitter> <vlazar> do I just use `if`s in specs?
<FromGitter> <stronny> you write tests the same way you write your program later
<FromGitter> <stronny> then you have to keep them in mind and treat them accordingly
<FromGitter> <vlazar> so it's like this then? https://play.crystal-lang.org/#/r/4b9h
<FromGitter> <vlazar> is it any better than previous `bar = foo.bar.not_nil!`?
<FromGitter> <vlazar> right, `bar.nil?` is stricter
<FromGitter> <vlazar> ok then, if's it is.. thanks @stronny
<FromGitter> <hmans> The new time zone support is clashing with sqlite3
<FromGitter> <fgimian> @vlazar you could actually depend on regular truthies with `String | Nil` since an empty string will always evaluate to false
<FromGitter> <fgimian> e.g. you should be able to write
<FromGitter> <fgimian> ```bar.value.should eq("bar") if bar```
<FromGitter> <fgimian> nil will evaluate to `false` and ANY string will evaluate to `true` using truthies
<FromGitter> <fgimian> the only time I'm really careful is when using `Bool | Nil` ๐Ÿ˜„
<FromGitter> <vlazar> yeah, sure
<FromGitter> <fgimian> just a thought, using `nil?` is perfectly fine too
<FromGitter> <vlazar> I see not_nil! is used a lot actually in Crystal specs
<FromGitter> <fgimian> oh interesting, kewl
<FromGitter> <vlazar> so I guess both if's and not_nil! are fine in specs
<FromGitter> <fgimian> yeah
<FromGitter> <fgimian> they are all technically correct I think ๐Ÿ˜„
<FromGitter> <fgimian> but I (like you) often reference the Crystal source and try to follow the style used there
<FromGitter> <fridgerator> @hmans we will get a fixed sqlite3 version on Monday
Jenz has joined #crystal-lang
<FromGitter> <hmans> @fridgerator Cool! Thanks for the heads-up.
<FromGitter> <vlazar> @fgimian yeah, I've been wasting time not reading Crystal's source, I definitely should do it more
<FromGitter> <fgimian> Honestly, the source code (primarily the stdlib) is one of the biggest selling points of Crystal.
<FromGitter> <fgimian> It's not really talked about much, but try reading the stdlib for Ruby or some of Python .... Crystal's stdlib is worlds apart in terms of readability and
<FromGitter> <fgimian> Highly recommend just having the repo cloned alonside your project and open in your editor's sidebar for quick reference
Jenz has quit [Ping timeout: 240 seconds]
<FromGitter> <vlazar> totally agree, almost everything is written in Crystal, easy to check how something works even with no docs
<FromGitter> <fgimian> absolutely! I'm also learning a lot more about LibC ๐Ÿ˜„
<FromGitter> <fgimian> and how things ACTUALLY work
<FromGitter> <vlazar> interesting, do you mean that Crystal bindings push you to learn more about libc?
<FromGitter> <fgimian> moreso I am understanding how LibC plays a role in various activities, I've written various bindings myself too (because Crystal just makes it so damn easy to do)
<FromGitter> <fgimian> but also looking the `process.cr` code for example (which I'm doing as we speak), I'm seeing what's actually going on with cals to fork and execvp
<FromGitter> <fgimian> and this is the lib I'm writing atm - https://github.com/fgimian/unixium.cr/tree/master/src/unixium
<FromGitter> <fgimian> which is all C bindings to LibC and exposing certain functionality that the stdlib doesn't
<FromGitter> <fgimian> no unit tests yet though (naughty!!!) but coming soon I hope
<FromGitter> <j8r> The state of the LibC bindings in Crystal is meh - not well documented. Also adding more bindings not used in Crystal itself are refused :(
<FromGitter> <fgimian> Would love to see more yeah, hence why I started my lib
<FromGitter> <vlazar> sweet
<FromGitter> <j8r> I advocate to move the LibC out of the compiler like rust did, to have complete bindings to the LibC and not only ones used in the compiler
<FromGitter> <fgimian> @vlazar for sure mate, you should give it a shot!
<FromGitter> <fgimian> @j8r complete bindings would be lovely
<FromGitter> <fgimian> Python does have very thorough bindings which are very true to the original, whether or not that's a good or bad thing is up to the each individual
<FromGitter> <vlazar> I mean I'm playing with Crystal in my spare time, but also hope to use it at work in production, that's not my decision to make, but I will try
<FromGitter> <j8r> why it would be bad @fgimian ?
<FromGitter> <fgimian> @j8r Perhaps just because it may be considered a little too low-level. For example, the `os` module in Python feels a bit out of place in areas, because it's much more like C than it is Python.
<FromGitter> <fgimian> Personally I do prefer bindings that mimic the original behaviour because they are well known and make porting code from Python easier ๐Ÿ˜†
<FromGitter> <j8r> btw this is better than nothing :)
<FromGitter> <j8r> This is fine if you write tests, as usual
<FromGitter> <fgimian> @j8r It's a huge project to support all the bindings, but why not just create a new shard?
<FromGitter> <fgimian> if you have the time of course
<FromGitter> <j8r> Not support all tomorrow, more bindings if people are willing to propose them
<FromGitter> <fgimian> notice in my library, I try to "crystalize" the bindings
<FromGitter> <fgimian> I expose pretty names, use overloading where I can .etc
<FromGitter> <fgimian> it's not just an original interface
<FromGitter> <fgimian> I'm going to add some more to my library, but it will be mostly limited to what I need personally
<FromGitter> <fgimian> and I don't reallly want to maintain all bindings, because ... I don't have the time ๐Ÿ˜†
<FromGitter> <fgimian> but I don't doubt that having a library that does would be great!
<FromGitter> <j8r> What's sad is we have to extract https://github.com/crystal-lang/crystal/tree/master/src/lib_c to a project, and backport possible changes
<FromGitter> <fgimian> I don't actually believe `lib_c` in the stdlib has all bindings
<FromGitter> <fgimian> I'm almost certain it didn't have the ones I wanted
<FromGitter> <j8r> yes, this is for the base
<FromGitter> <j8r> And add new bindings on top of this
<FromGitter> <j8r> The goal is similar to https://github.com/rust-lang/libc
<FromGitter> <fgimian> Yah, but you could always use `lib_c` in your shard
<FromGitter> <fgimian> I do in mine, I rely on `Errno` for example
<FromGitter> <fgimian> weird name for an exception
<FromGitter> <fgimian> Python calls it `OSError`
<FromGitter> <fgimian> Ruby does `Errno` too
<FromGitter> <fgimian> wow those Rust bindings are very thorough
<FromGitter> <j8r> @fgimian as you said, there are bindings missing. And it's better to write reusable bindings for other projects. That's why creating a documented shard thaht have the goal to support OS most native functions makes sense
<FromGitter> <fgimian> just a mere 48,309 lines of code
<FromGitter> <fgimian> hahahaha
<FromGitter> <fgimian> I better get to bed buddy
<FromGitter> <fgimian> ๐Ÿ˜„
<FromGitter> <j8r> good night ๐Ÿ˜„
<FromGitter> <codenoid> good night australia
<FromGitter> <j8r> https://github.com/j8r/libc created @fgimian
<FromGitter> <codenoid> night in malaysian too
<FromGitter> <fameless0x01> Is this code supposed to give error - โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b265f2cf339a97372f2fdf2]
hightower3 has joined #crystal-lang
ahoZiorce has joined #crystal-lang
ahoZiorce has quit [Client Quit]
<FromGitter> <drum445> Hello does anyone know why I am getting this after upgrading to Crystal 0.25 (Using Kemal) โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b2669214dbdad0d85b271f4]
<FromGitter> <faustinoaq> Hey @/all if someone wants to use code snippets with crystal v0.25.0 try: https://glot.io/snippets/f22ls4132n
<FromGitter> <faustinoaq> Pretty nice alternative to carc.in and play.crystal-lang.org ๐Ÿ˜…
<FromGitter> <faustinoaq> With https://glot.io you can add multiples files and use custom flags and compile commads ๐Ÿ˜‰
<FromGitter> <S-YOU> Nice
snsei has joined #crystal-lang
<FromGitter> <fridgerator> cool
<FromGitter> <crash2burn_twitter> hey all, had a question around the "limitations" for under https://crystal-lang.org/docs/syntax_and_semantics/if_var.html
<FromGitter> <crash2burn_twitter> basically if I have a nillable instance var, I need to use the .try boilerplate everywhere in my code that I use it?
<FromGitter> <faustinoaq> Hi @crash2burn_twitter ๐Ÿ˜„
<FromGitter> <crash2burn_twitter> ugh why did it make my name crash2burn_twitter, thanks glitter
<FromGitter> <faustinoaq> > if I have a nillable instance var, I need to use the .try boilerplate everywhere in my code that I use it? โŽ โŽ I prefer `if var = @var`
<FromGitter> <faustinoaq> or avoid `nil` in your code
<FromGitter> <crash2burn_twitter> ah thats pretty good, still a bummer though! Yea maybe I'm thinking about the whole thing wrong, as I do see people mentioning to just not use nil
<FromGitter> <crash2burn_twitter> but I cant seem to wrap my head around not supporting nil in a lot of cases
snsei has quit [Remote host closed the connection]
<FromGitter> <faustinoaq> @drum445 see: https://gitter.im/sdogruyol/kemal?at=5b2674d39a211e26bb69d431 ๐Ÿ˜‰
<FromGitter> <crash2burn_twitter> and its weird to me as even golang seems to support nil for structs in a less "think about it" kind of wa
<FromGitter> <crash2burn_twitter> still enjoying the lang though :)
<FromGitter> <faultyserver> So I'm looking at the UUID docs and the class overview seems to have come from the JSON extension to the class, rather than the original class itself... https://crystal-lang.org/api/0.25.0/UUID.html
<FromGitter> <faultyserver> granted, the UUID class itself doesn't really have docs, that still seems like it shouldn't be what ends up on the API reference
snsei has joined #crystal-lang
<FromGitter> <faustinoaq> Hey @sdogruyol Any update here http://crystalweekly.com/ ? ๐Ÿ˜…
<FromGitter> <faustinoaq> > https://github.com/j8r/libc โŽ โŽ @j8r How, this shard with `--prelude="empty"` should be able to compile to almost every platform, even Windows and Android โœจ โŽ โŽ ... of course without stdlib support ๐Ÿ˜‰ [https://gitter.im/crystal-lang/crystal?at=5b2679ff8cef6c0add7f8032]
<FromGitter> <faustinoaq> Well, android not yet, ABI is still not available ๐Ÿ˜…
<FromGitter> <S-YOU> It seems to be mainly extracted from Crystal repository.
<FromGitter> <j8r> wow https://github.com/j8r/libc has already 5 starers ๐Ÿ˜ฎ .
snsei has quit [Remote host closed the connection]
<FromGitter> <j8r> @S-YOU Yes totally its extracted from the main repo. โŽ If you need new libc bindings that aren't in Crystal's `LibC`, feel free to send PRs - that's the main purpose of this shard ๐Ÿ˜„
<FromGitter> <j8r> I will add statfs of https://github.com/crystal-lang/crystal/pull/6056 on it to be able to know the system's disk usage (like `df -h` does)
akaiiro has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
<FromGitter> <sdogruyol> Just released Kemal 0.23.0 with Crystal 0.25.0 support https://twitter.com/crystalkemal/status/1008384575142232065
<FromGitter> <faustinoaq> @sdogruyol ๐ŸŽ‰
<FromGitter> <bendietze_twitter> Great guys ๐Ÿ˜„ ๐Ÿ‘
alex`` has joined #crystal-lang
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 245 seconds]
<FromGitter> <vectorselector> Hi folks, I'm dumb. โŽ breaking change #5183 has me running around trying to understand how to specifically set a Hash(String,JSON::Any) to string value in the end. โŽ myTxtSpan["textValue"] = "text" โŽ does not work anymore, since crystal 0.25 โŽ ... [https://gitter.im/crystal-lang/crystal?at=5b26a72863cb0b1a2d1f47b3]
<DeBot> https://github.com/crystal-lang/crystal/pull/5183 (Implement JSON::Any and YAML::Any without recursive aliases)
alex`` has quit [Quit: WeeChat 2.1]
alex`` has joined #crystal-lang
<FromGitter> <rishavs> I am trying a simple password comparison here. What am I doing wrong? My password never matches the one in the db. โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b26abce63cb0b1a2d1f507c]
<FromGitter> <crash2burn_twitter> not sure what your user object looks like but im guessing you need to hash the input password and THEN compare it
<FromGitter> <rishavs> I did try that but both hashes are coming different. โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b26ace1d9bcab2dd696d404]
<FromGitter> <codenoid> `pass == user.password_hash.as(String)`
<FromGitter> <codenoid> crypto bcrypt have verify function
<FromGitter> <rishavs> This was my first try. This didnt work. โŽ `````` [https://gitter.im/crystal-lang/crystal?at=5b26ae0363cb0b1a2d1f53d9]
<FromGitter> <Daggerron> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b26ae894a5db82dd5906ea5]
<FromGitter> <Daggerron> This will always give you the same hash for the same string
akaiiro has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <fridgerator> You should use BCrypt for passwords
<oprypin> vectorselector, yeah, relying on mutating JSON::Any can be a bad idea
<oprypin> vectorselector, `myTxtSpan["textValue"] = JSON::Any.new("text")` should work
<FromGitter> <j8r> The best is https://en.wikipedia.org/wiki/Argon2
<FromGitter> <rishavs> I am using Bcrypt. โŽ ` if user && Crypto::Bcrypt::Password.new(user.password_hash.not_nil!) == pass` this works. โŽ but โŽ `if pass == user.password_hash.as(String)` doesn't. I dindt think I had to hash it up again using `new` [https://gitter.im/crystal-lang/crystal?at=5b26b0e6d0546c33e701cba3]
<FromGitter> <fridgerator> no you dont have to rehash it
<FromGitter> <rishavs> @fridgerator what should be the better way to do this? โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b26b13ec016730d8665acff]
<oprypin> rishavs, this piece of code looks fine to me
<FromGitter> <rishavs> oh ok. I got confused when Nick aid that I don't have to rehash it
<oprypin> `pass == user.password_hash.as(String)` is incorrect because `pass` is plaintext password and `password_hash` is a hash
<oprypin> `bcrypt == pass` is just rigged to also hash the right hand side. it's an unfortunate use of operator overloading,
<FromGitter> <rishavs> ah. The api guide had me thoroughly confused. โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b26b2704a5db82dd59074ca]
<FromGitter> <crash2burn_twitter> wow unfortunate is a bit understated there
<FromGitter> <rishavs> This is the page in the guide; https://crystal-lang.org/api/master/Crypto/Bcrypt/Password.html
pabs has quit [Quit: leaving]
<FromGitter> <fridgerator> oh yeah, thats correct
<FromGitter> <vectorselector> > *<oprypin>* vectorselector, `myTxtSpan["textValue"] = JSON::Any.new("text")` should work โŽ Thank you very much @oprypin โŽ re:" relying on mutating JSON::Any can be a bad idea" โŽ What are the alternatives? โŽ the db is couchdb and I'm doing updates to small parts of documents requiring only casting at the last minute as couchdb updates require an entirely new document constructed out of a
<oprypin> eh it's acceptable
<FromGitter> <rishavs> what is the difference between `.as(String)` and `.to_s`?
akaiiro has quit [Ping timeout: 256 seconds]
akaiiro has joined #crystal-lang
<FromGitter> <drum445> Why is Time.now returning "2018-06-17 20:42:32 +01:00" after upgrading to 0.25, has the behaviour changed?
<FromGitter> <drum445> $ date โŽ Returns: Sun 17 Jun 20:42:32 BST 2018
<FromGitter> <drum445> Seems like it's an hour out :(
<Yxhuvud> are those times not the same? Only formatted differently
<FromGitter> <drum445> @yxhuvud Nah it's an hour out, although I just looked at patch notes and found โŽ Time.utc_now
<Yxhuvud> BST = british summer time = +1, no?
<FromGitter> <drum445> yep, however when i do Time.now + some seconds it's an hour ahead of what it should be
<FromGitter> <drum445> due to that +01:00
<FromGitter> <j8r> @rishavs tyically `as_s` comes from `JSON::Any` or `YAML::Any`, and for them is more efficient for casting than `to_s`
akaiiro has quit [Ping timeout: 256 seconds]
akaiiro has joined #crystal-lang
hightower3 has quit [Ping timeout: 256 seconds]
<FromGitter> <drum445> Ok I found my issue, I had a datetime stored in MySQL as NOW(), then I was finding out the elapsed time between Time.now in Crystal and NOW() in MySQL. โŽ MySQL was UTC โŽ Crystal was +01:00 โŽ So it meant I couldn't perform this [https://gitter.im/crystal-lang/crystal?at=5b26c07294a11e0adea803f9]
<FromGitter> <drum445> Had to change my sql script to use a time from Crystal using โŽ Time.utc_now โŽ Instad of SQL's NOW()
<FromGitter> <drum445> Or is there a way to do โŽ โŽ ```From a sql result set and specify the time zone as BST?``` [https://gitter.im/crystal-lang/crystal?at=5b26c1704dbdad0d85b3109d]
pabs has joined #crystal-lang
<FromGitter> <drum445> Sorry for spam, but this is my issue or a bug not sure. So I have two times โŽ a = 2018-06-17 21:16:54 UTC (Generated from Mysql NOW()) โŽ b = 2018-06-17 21:25:32 +01:00 (Generated from Time.now()) โŽ โŽ When I do a - b I would expect around 10 minutes, but it is actually 51 minutes. ... [https://gitter.im/crystal-lang/crystal?at=5b26c40fd0546c33e701f0f1]
<FromGitter> <Blacksmoke16> if mysql NOW is in UTC, why not just use Time.utc_now to match
<FromGitter> <drum445> Because Time.utc_now is an hour behind
<FromGitter> <drum445> mysql NOW is being read in sql as utc but it's bst
<FromGitter> <drum445> I need my rs.read(Time) to know it's bst not utc
<FromGitter> <Blacksmoke16> is your mysql server time in UTC?
<FromGitter> <drum445> Nah mysql time is correct to my timezone
<FromGitter> <drum445> the issue is I can't read it into Crystal as anything but UTC
<FromGitter> <drum445> Which it isn't
<FromGitter> <Blacksmoke16> ah ok gotcha
<FromGitter> <Blacksmoke16> how are you reading in the mysql time? using an ORM or parsing the string via like `Time.parse`
<FromGitter> <drum445> ```@db.query = "select started from foo;" do |rs| โŽ rs.each do โŽ started = rs.read(Time)``` [https://gitter.im/crystal-lang/crystal?at=5b26c834f3e3007371b9e820]
<FromGitter> <Blacksmoke16> it looks like Time.parse has an optional param to tell it what timezone to use, could maybe use that to let it know that it should be bst not utc
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.25.0/Time.html#in%28location%3ALocation%29%3ATime-instance-method
<FromGitter> <drum445> I tried that and changed it to Europe/London but it adds an hour to the time instead of just changing the zone
<FromGitter> <drum445> 22:00 UTC becomes 21:00 +01:00
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <drum445> which I think is where the problem lies
snsei has joined #crystal-lang
<FromGitter> <Blacksmoke16> wouldnt it be easier to set msql server to run in UTC then just convert the UTC datetime to whatever you need?
<FromGitter> <Blacksmoke16> but yea, thats prob it, code tells mysql its utc when its actually not
<FromGitter> <drum445> Would be a pain to have all my datetimes out in mysql though
<FromGitter> <drum445> Seems silly to not be able to declare what timezone to use when reading from sql
<FromGitter> <Blacksmoke16> looks like you could change https://github.com/crystal-lang/crystal-mysql/blob/0c51abed1b19f23400d4005948a7f304bbac2705/src/mysql.cr#L16 in the lib folder of crystal-mysql
<FromGitter> <drum445> I was trying to avoid that but I think it might be the only way
<FromGitter> <drum445> Would be nice to have a way of setting that on dbinit
<FromGitter> <drum445> anyways, cheers for your input @Blacksmoke16
<FromGitter> <Blacksmoke16> yea for sure, np
<FromGitter> <Blacksmoke16> maybe look into one of the ORMs? might make things a bit easier?
alex`` has quit [Quit: WeeChat 2.1]
akaiiro has quit [Ping timeout: 264 seconds]
kgautreaux has joined #crystal-lang
<crystal-gh> [crystal] bcardiff opened pull request #6211: Update CI to use 0.25.0 (master...ci/update-0.25.0) https://git.io/vhDZ2
snsei has quit []
snsei has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi