RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
chimkan has joined #crystal-lang
chimkan has quit [Client Quit]
thews has quit [Excess Flood]
thews has joined #crystal-lang
lucasb has quit [Quit: Connection closed for inactivity]
non-aristotelian has quit [Quit: non-aristotelian]
johndescs has quit [Ping timeout: 246 seconds]
johndescs has joined #crystal-lang
jemc has quit [Ping timeout: 244 seconds]
<FromGitter> <fridgerator> @ilanusse the server part might be similar (you can use http handler), but views, mailers, etc are all done differently
akaiiro has quit [Ping timeout: 250 seconds]
akaiiro has joined #crystal-lang
<FromGitter> <kinxer> @girng That sounds very cool. I look forward to seeing it. :)
Yxhuvud has joined #crystal-lang
DTZUZO has joined #crystal-lang
Renich has quit [Remote host closed the connection]
akaiiro has quit [Remote host closed the connection]
jemc has joined #crystal-lang
<FromGitter> <girng> @kinxer thx! couldn't be done w/o this community helping me
jemc has quit [Quit: WeeChat 2.2]
<FromGitter> <neutrinog> hey does anyone know if there is a "pure" crystal audio library? I mean something that's NOT just c-bindings.
<FromGitter> <neutrinog> My use case is playing audio from files on disk.
<FromGitter> <anamba> just caught up on AoC. that was pretty fun, actually.
<FromGitter> <anamba> waaaaay back in the day (late 90s) i competed in a couple ACM competitions. kinda has that feel to it.
<FromGitter> <redcodefinal> I'm trying to compile 0.27.0 for raspberry pi but im getting this error ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Anyone know whats going on? [https://gitter.im/crystal-lang/crystal?at=5c063f269f38cc0fd5a14017]
<FromGitter> <bew> what crystal version do you have installed?
<FromGitter> <bew> I think you don't have a recent enough compiler
<FromGitter> <redcodefinal> I'm compiling 0.27.0 and my installed crystal is 0.24.0
<FromGitter> <bew> you should get crystal 0.26.1 to be able to compiler 0.27.0
<FromGitter> <redcodefinal> So I should just find the highest crystal that I can compile, then use that to do the next one? interesting. Thank you!
<FromGitter> <bew> yep
<FromGitter> <bew> or if you have to start from 0.24.2, compile the next (0.25.0 I guess), then with that compile the next, etc...
<FromGitter> <girng> gn
foxxx0 has joined #crystal-lang
<foxxx0> hey, I'm having a problem understanding why an element of a newly created Tuple(Int32,Int32,Int32) is at first correctly an "Int32" and a bit later typeof(my_tuple[0]) returns "(Int32 | Int32.class)"
<jhass> uhm, got some code to show the issue?
<foxxx0> fair warning: advent of code spoiler
lucasb has joined #crystal-lang
<foxxx0> the output from line 19 returns (Int32 | Int32.class)
<foxxx0> however in line 26 (where the tuple is created), everything seems to be fine?!
<foxxx0> or is my line 4 causing this?
<FromGitter> <Timbus> youre.. yeah. assigning a tuple class to it
<FromGitter> <Timbus> did you mean : instead of =
<foxxx0> oh
<foxxx0> derp
<foxxx0> :D
<foxxx0> how do i check then if that variable was assigned?
<foxxx0> I'm now getting: "read before assignment to local variable 'guard'"
<foxxx0> "next if guard.nil?" doesn't help
<foxxx0> i suppose it is related to this? https://github.com/crystal-lang/crystal/issues/5315
<foxxx0> thanks though, i'll just initialize it correctly
ashirase has quit [Ping timeout: 268 seconds]
ashirase has joined #crystal-lang
lvmbdv has quit [Quit: brb update]
lvmbdv has joined #crystal-lang
<jokke> hey foxxx0 o/
<foxxx0> jokke: \o
<jokke> join the crystal leaderboard ;)
<lvmbdv> hwut
<jokke> 289786-69f3013e
<jokke> is there a builtin insertion sort enabled collection in crystal? :)
<foxxx0> just use Array(String)
<foxxx0> works just fine for today :D
<jokke> naah
<jokke> i want to sort while building the collection
<jokke> java had something like this
<jokke> sorted set or sth
<jokke> huh is there no binary search?
<jokke> my bad, there is
<jokke> foxxx0: bam: https://p.jokke.space/lg6s8d/ (spoiler)
<jokke> for larger inputs a sorted set would be more efficient of course
<FromGitter> <KevinSjoberg> Is there `#slice_when` in Crystal?
<FromGitter> <bararchy> what would it do?
<FromGitter> <KevinSjoberg> @bararchy slice an array on a given condition, giving you an array of arrays.
<FromGitter> <bararchy> `[].slice do |s| if a = 1` sort of thing?
<FromGitter> <KevinSjoberg> `["One", "Two", "Three", "Dance!", "One", "Two", "Three", "Dance!"].slice_when { |e| e == "Dance!" }.to_a` #=> ` [["One", "Two", "Three", "Dance!"], ["One", "Two", "Three", "Dance!"]]`.
<FromGitter> <KevinSjoberg> Pointless example but I think it illustrates what I mean. :slight_smile:
<FromGitter> <bararchy> so why not `.map` and then slice?
<FromGitter> <KevinSjoberg> @bararchy would you mind illustrating your point with an example?
<FromGitter> <bararchy> @KevinSjoberg -> https://play.crystal-lang.org/#/r/5ova
<FromGitter> <KevinSjoberg> @bararchy that wouldn't work for the example I gave above.
rohitpaulk has joined #crystal-lang
<FromGitter> <anamba> The recent npm issue has everyone thinking about how to vet dependencies, but this sounds like a better way. But not sure if it would be possible with Crystal https://medium.com/agoric/pola-would-have-prevented-the-event-stream-incident-45653ecbda99
<FromGitter> <codenoid> lol
<FromGitter> <codenoid> ups, wrong room sorry
<RX14> @anamba crystal will be less vulnerable in the same way that ruby doesn't have any documented attacks: less, larger dependencies, making auditing trust an order of magnitude easier
<FromGitter> <asterite> @KevinSjoberg Yeah, `slice_when` or `slice_before` would have been helpful for advent of code (and generally useful). I might add them in these days
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <bararchy> I remember there being a method that takes two `Int` and tells you the distance between them or something like that
<FromGitter> <bararchy> basiclly to check if a number is further then x from another one (+ or -)
<FromGitter> <anamba> @RX14 of course, the dependency situation for most platforms won't be as extreme as js/npm, but the idea is trust shouldn't be our only line of defense
<RX14> unfortumnately sandboxing depndencies isnt possible in crystal
<FromGitter> <greenbigfrog> How would I get the index of a max value in an Array? ⏎ ⏎ ```a = [3, 6, 1] ⏎ a.max # => 6 ⏎ # I'd like to get the index of 6 => 1 as well``` [https://gitter.im/crystal-lang/crystal?at=5c0682ae43c68b3727fad918]
ua has quit [Ping timeout: 246 seconds]
<FromGitter> <greenbigfrog> ```code paste, see link``` ⏎ ⏎ Is there no builtin method? [https://gitter.im/crystal-lang/crystal?at=5c06852a1c439034af18756c]
<FromGitter> <vladfaust> ```a = [3, 6, 1] ⏎ pp a.index(a.max)``` [https://gitter.im/crystal-lang/crystal?at=5c0685efbc1a693e3a54e0c6]
<FromGitter> <KevinSjoberg> @asterite I love how you knew it was for Advent of Code. :)
<FromGitter> <KevinSjoberg> @asterite would you be up for pair programming those? Would love to contribute to Crystal but with some guidance. :)
<FromGitter> <greenbigfrog> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c06877948d021555aed434f]
<FromGitter> <vladfaust> Makes sense. This 3 nanoseconds win absolutely costs 8 additional lines of code
rohitpaulk has joined #crystal-lang
<FromGitter> <greenbigfrog> 😛
rohitpaulk has quit [Ping timeout: 268 seconds]
jemc has joined #crystal-lang
<FromGitter> <kinxer> @greenbigfrog In addition to what @vladfaust said (which is true; it's really not that much of a gain), you're basically equivalently trading runtime for memory. Your faster version takes ~3.27 times as much memory (unless I'm wrong about what that <number>M stands for).
<FromGitter> <vladfaust> @kinxer, nope, @greenbigfrog's solution as well as mine takes exactly `0 B/op`
<FromGitter> <vladfaust> `M` stands for millions of operations per second :)
<FromGitter> <kinxer> Ah... So it's just the frequency.
<FromGitter> <kinxer> Good to know, @vladfaust. Thanks.
<FromGitter> <vlazar> Yeah, npm again... But the issue is not unique to npm. How do you guys freeze your dependencies? For Crystal 1.0 it would be great to have something more sophisticated than installing packages directly from GitHub.
<FromGitter> <j8r> there is a shard.lock
<FromGitter> <vlazar> how do I verify the code was not changed on github?
<FromGitter> <j8r> because of the commit hash
<FromGitter> <j8r> but the problem, even the lock don't always the commit hash
<FromGitter> <vlazar> locking to commit hashes is not common practice?
<FromGitter> <j8r> It think it should too
<FromGitter> <j8r> I you specify a version, it will put a version in the lock (no hash)
<FromGitter> <j8r> I you specify HEAD, it will
<FromGitter> <j8r> too bad, agree
<FromGitter> <vlazar> no, this is just something to be aware of for the time being
<FromGitter> <j8r> But we can't review all the code of our dependencies
<FromGitter> <vlazar> true
<FromGitter> <vlazar> I guess for me a better dependency management is on wishlist for 1.0
<FromGitter> <j8r> I still think the commit hash should be always in the lock
<FromGitter> <bew> What do you suggest @vlazar?
<FromGitter> <greenbigfrog> @vladfaust shouldn't this (the index of max, or max with index) be part of the stdlib?
<FromGitter> <vlazar> @j8r oh, great if it is, makes me less nervous :D
<FromGitter> <vlazar> bew, a registry for packages we could trust would be great I guess
<FromGitter> <j8r> I'll create an issue
<FromGitter> <vladfaust> @greenbigfrog who am I to decide
<FromGitter> <greenbigfrog> true, but do you think it should?
akaiiro has joined #crystal-lang
<FromGitter> <j8r> @vlazar today you can use libs from people you trust
<FromGitter> <vladfaust> @greenbigfrog nope, I don't think so. Because `a.index(a.max)` is enough
<FromGitter> <vlazar> @j8r ❤️
<FromGitter> <asterite> get_index_of_max doesn't return what you want, it returns the max
<FromGitter> <asterite> Ah, nevermind. The benchmark is flawed, the array has the same value in each position
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <DRVTiny> Hello4all! ⏎ What about integer overflow control in Crystal? It's a pitty that static types not leads anyway to safety against such stupid thing as overflow on addition.
<FromGitter> <kinxer> @DRVTiny ⏎ ⏎ > In this version a couple of arithmetic operators were added thanks to #6890: &+, &-, &*. They will perform additions, subtraction and multiplication with wrapping (as in, not overflowing). Some may notice that that is the exact same behaviour as +, -, *. In a future version the regular operators will raise on overflow. This will allow you to trust the result of the operations when reaching
<FromGitter> ... the limits of the representable range. The ampersand operators might be useful to think of them as applying an && 0xFF bitwise mask to the result. ⏎ (From 0.27.0 release notes (https://crystal-lang.org/2018/11/01/crystal-0.27.0-released.html)) [https://gitter.im/crystal-lang/crystal?at=5c06a03643c68b3727fbb0c7]
<DeBot> https://github.com/crystal-lang/crystal/pull/6890 (Add wrapping arithmetics operators)
<FromGitter> <DRVTiny> @kinxer ⏎ Very good. ⏎ As of now it looks like very bad result: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c06a0b9bc1a693e3a55a348]
<FromGitter> <kinxer> Yeah. @DeBot linked to the relevant pull request, if you're curious.
<FromGitter> <DRVTiny> @kinxer Amazing, thank you!
<FromGitter> <asterite> @KevinSjoberg sorry, I do it in small chunks whenever I have time, I don't think I can pair program these days (probably these years :-p)
<FromGitter> <KevinSjoberg> @asterite I see, no worries. :)
gangstacat has joined #crystal-lang
<FromGitter> <ilanusse> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c06a33fa6c29a1037e1f0dd]
<FromGitter> <ilanusse> I got this error in my nightly Travis build
<FromGitter> <ilanusse> Rebuilt it and got the same error
<FromGitter> <ilanusse> Anybody know what's up?
<jhass> Travis nightly is broken currently, sorry
<jhass> best disable it for now
<FromGitter> <ilanusse> Thanks guys!
<FromGitter> <ilanusse> I'll go ahead and disable it for now
<FromGitter> <greenbigfrog> @asterite even after unflawing my test, the result more or less the same
jemc has quit [Ping timeout: 250 seconds]
<FromGitter> <vladfaust> @ilanusse CircleCI whould work with nightly well
<FromGitter> <vladfaust> @greenbigfrog I think the issue is that at the moment of the bench start, the max element is in its place and is not changed during the whole bench
<FromGitter> <vladfaust> But even if it is, it should be enough for comparison of these two in my opinion
<FromGitter> <asterite> Yes, it's slower because index max needs to traverse the array twice
<FromGitter> <greenbigfrog> Yeah
<FromGitter> <greenbigfrog> I think would be nice to have sth like this in the stdlib
<FromGitter> <asterite> It's too specific and the time difference isn't that big
<FromGitter> <asterite> And you can still write specific code if you need it
<FromGitter> <greenbigfrog> hm, ok
jemc has joined #crystal-lang
Renich has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <wontruefree> is there a way to use compiler flags to cross compile to x86 from a 64 bit machine ?
junland has quit [Quit: Disconnected.]
rohitpaulk has quit [Ping timeout: 246 seconds]
junland has joined #crystal-lang
JuanMiguel has joined #crystal-lang
<FromGitter> <j8r> You can, there is an option in `crystal build`
<FromGitter> <ilanusse> Hey guys
<FromGitter> <j8r> Don't remind exactly
<FromGitter> <ilanusse> What features would you like in a Devise-like authentication shard?
<FromGitter> <ilanusse> I was thinking confirmation emails, lockable accounts, recovery emails, session timeouts
<FromGitter> <ilanusse> The plan is to eventually support both Amber and Lucky
<FromGitter> <ilanusse> I'll have to make wildly different template generators but the core functionality would be the same
<FromGitter> <DRVTiny> Does anybody knows some shard where i can get code snippets for event loop integration? ⏎ I know that stdlib IO integrated with ev, but it's code is too complex for me and i dont understand where IO pushes some procs or filehandles to be executed/checked by event loop on each iteration.
<FromGitter> <diegogub_gitlab> Hi guys, I'm havinga issue. While executing shards build, libs are being fetched everytime, how could I solve it?
<FromGitter> <Blacksmoke16> building locally or using docker or something?
<FromGitter> <diegogub_gitlab> locally
<FromGitter> <Blacksmoke16> hmm
non-aristotelian has joined #crystal-lang
<FromGitter> <diegogub_gitlab> only happening with one project..tried to re-init shards, and keeps happening
<FromGitter> <diegogub_gitlab> I think it has to do with this issue: https://github.com/crystal-lang/shards/issues/183
<FromGitter> <Blacksmoke16> possibly?
<FromGitter> <DRVTiny> According to https://crystal-lang.org/api/0.27.0/Crystal/EventLoop.html event loop in Crystal can work only with file descriptors. Hmm.
<FromGitter> <wontruefree> @j8r I see `--target` and `--cross-compile` but I dont see how to use them.
<FromGitter> <asterite> @DRVTiny you are not supposed to interact with the event loop, that class (and all related code) should (will) be private
rohitpaulk has joined #crystal-lang
<FromGitter> <jwoertink> I think I found a bug but I'm not totally sure. Wondering if someone could verify, or maybe explain this to me so I understand better.
<FromGitter> <jwoertink> In this example if I iterate over my array with `each` it works fine; however, if I break it down with `in_groups_of`, then it seems to lose the type
<FromGitter> <jwoertink> Maybe because `in_groups_of` could return a group with a `nil` in it?
<FromGitter> <bew> @DRVTiny what's your use case? (for interacting with eventloop directly)
<FromGitter> <jwoertink> actually, now that I type that out it's making a little more sense to me lol
<FromGitter> <jwoertink> It's not returning my array, it's returning a new one with a new type
<FromGitter> <jwoertink> 😅
<FromGitter> <jwoertink> turns out there's a second `in_groups_of` that takes an additional argument
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <asterite> you need to use `each_slice`
<FromGitter> <jwoertink> Oh? Interesting. Good call
<FromGitter> <elorest> What @asterite said! ☝️
<FromGitter> <j8r> @RX14 I love your goblin-themed logo :D
<FromGitter> <jwoertink> I wonder if there's a performance difference
<FromGitter> <asterite> The docs should probably mention the other variant in each method :-)
<FromGitter> <jwoertink> That could be a good idea
<FromGitter> <jwoertink> yup! `each_slice` is for sure what I needed, thanks!
<FromGitter> <j8r> @RX14 seing your customized logo... i'm asking to you: do not try to become a graphist/designer – keep coding in Crystal 😄
<FromGitter> <wontruefree> @j8r thanks that is way better then this
<FromGitter> <DRVTiny> @bew I want to implement ⏎ ⏎ ```sem = POSIX::Semaphore.new ⏎ # Control will be returned/yield'ed to EV ⏎ sem->down``` [https://gitter.im/crystal-lang/crystal?at=5c06d560be66d825267832b1]
<FromGitter> <girng> just curious why is `url: group[0].as(String)` needed when `url: String` sets `url` to a String already?
<FromGitter> <Blacksmoke16> more so to tell that the first value in `group` array should be a `String`
<FromGitter> <Blacksmoke16> assuming its a union
<FromGitter> <DRVTiny> POSIX Semaphores has some /dev/shm file-based interface but i dont know whether this files can be used to create file handles for non-blocking I/O. And this is too indirect way to integrate with event loop because there is simple try_wait interface, so ev loop can simply call my proc/closure (which will do try_wait internally) and check its exit status.
<FromGitter> <girng> interesting. what i do is just tryu to match the types up first and not rely on `as`. but if using an union i guess it makes since
<FromGitter> <Blacksmoke16> got a playground link example?
<FromGitter> <girng> something like this? https://play.crystal-lang.org/#/r/5p5u/edit no need to use .as, String type already set
tdc has quit [Quit: Leaving]
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
<FromGitter> <DRVTiny> @asterite Is it possible to pass some ->() from the current running myFiber to the event loop and yield (pass control to the evloop). Than EV Loop will check for the passed ->() return status on every iteration and when it will be true - myFiber will be added to some queue of Fibers which is "ready-to-continue-its-execution" .
<FromGitter> <bew> @DRVTiny there not really a concept of iteration in the evloop, the only thing it does is wait for some fd, or some time.. One thing you could do without touching the eventloop directly would be to have Fiber thar waits in a loop, and check the semaphore each time (and do sth or not)
<FromGitter> <greenbigfrog> How would I check if an object is a type that includes Enumerable?
<FromGitter> <bew> `some_var.is_a?(Enumerable)`
<FromGitter> <DRVTiny> I dont think that evloop must internally implement all possible variants of (potentially infinite) unblocking conditions for its Fibers. I can extend Crystal::EventLoop class itself (like any core class) , but i think this is too brutal/destrutive to achieve so simple and obvoius goal. ⏎ @bew Yes, i can iterate in a loop and do myFiber.yield if no success after sem.try_wait... Hmm. Some stupid way, but it
<FromGitter> ... works right now... OK, thank you, it there is not other ways to interact with evloop simple micro-loop inside a Fiber will be better than nothing :)
<FromGitter> <bew> @asterite would probably know better^^ you cab also checkout the ConditionVariable implem', but I'm pretty sure it locks the whole thread, not just the current fiber
<FromGitter> <asterite> I don't think it's a good idea to add stuff that relates to concurrency of any sort. It's better to wait for the core devs to work on that
<FromGitter> <asterite> Also semaphore in Go is in an x package, probably it's not very useful so it won't exist in Crystal
<FromGitter> <greenbigfrog> @bew thanks... Didn't realize it worked for included types (or whatever it's called)
<FromGitter> <ilanusse> They're called Modules :)
<FromGitter> <greenbigfrog> oh. right...
JuanMiguel has quit [Quit: Saliendo]
<FromGitter> <greenbigfrog> Anyone know why https://github.com/crystal-lang/crystal/pull/5021 hasn't been merged yet?
<FromGitter> <greenbigfrog> just saw someone opened https://github.com/crystal-lang/crystal/pull/6975 as followup
<FromGitter> <girng> does the amount of comments you have in your .cr files affect the total compilation speed?
<FromGitter> <bew> No
<FromGitter> <girng> thx
<FromGitter> <bew> The long time spent during the compilation is way after reading your code
ashirase has quit [Quit: ZNC - http://znc.in]
ashirase has joined #crystal-lang
<FromGitter> <greenbigfrog> Does crystal not have built in aes encryption? If not, is there any better shard then https://github.com/jamestaylr/aes ?
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 246 seconds]
Renich_ is now known as Renich
<FromGitter> <greenbigfrog> I think I might be able to use `OpenSSL::Cipher` somehow, but I'm not sure how I'd use it...
<FromGitter> <DRVTiny> @asterite what to use to synchronize processes/workers instead of semaphore? I know only one alternative: flock'ed file
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 240 seconds]
Renich_ is now known as Renich
<FromGitter> <asterite> spawn and Channel
<FromGitter> <DRVTiny> @asterite spawn and channel is not for interprocess communications as far as i know :)
<FromGitter> <DRVTiny> IPC is something about shared objects managed by (Linux) kernel, doesn't it?
<FromGitter> <DRVTiny> I've implemented slme draft for POSIX::Semaphore here: https://github.com/DRVTiny/crystal-by-example/blob/master/semaphores/lib/posix_semaphores.cr