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
C-o is now known as Pascal
<FromGitter> <straight-shoota> @omidathari `-127_i8.to_u8.to_s(2)` should give you the result. It's a bit of a hack and `-127.to_u8` might raise in the future. `(-127_i8.to_i16 + 256).to_s(2)` is probably better. ⏎ Maybe I'm missing something and there is a more elegant method. I'm tired.
<FromGitter> <omidathari> @straight-shoota That worked great. thanks
<jokke> lol i bet stumpy_png got a lot of fetches today :D
<FromGitter> <bhargavrpatel> I see the note of avoid shared variables and opting for fibers but how would you determine what a fiber does depending on state? Just to get around documentation and API, I am trying to create a loose replica of the Raft Protocol's election phase. Not complete yet but I am not sure how I can make an existing fiber which is constantly sleeping respond to TCP input
<FromGitter> <bhargavrpatel> Without having the `while true` break using shared state
<FromGitter> <bhargavrpatel> Here is my mockup code: https://gist.github.com/bhargavrpatel/71db9d6d0133117f40f6d330a3f2bd75
gangstacat has quit [Ping timeout: 252 seconds]
non-aristotelian has quit [Quit: non-aristotelian]
johndescs has quit [Ping timeout: 250 seconds]
johndescs has joined #crystal-lang
gangstacat has joined #crystal-lang
<FromGitter> <bhargavrpatel> hm actually, a lot of incorrect login in above snippet. Working through, but I believe the question still tands.
<FromGitter> <bhargavrpatel> Updated it
<FromGitter> <girng> WoW! if doing Hash(String, CustomType).from_json, I can now access everything by dot notation. Also don't need to do as_f, as_s, or whatever all over like I was doing before. I still love JSON.parse, but I really like this way as well!
<FromGitter> <dscottboggs_gitlab> oh, yeah, JSON::Serializable in structs is the way to go
<FromGitter> <dscottboggs_gitlab> I love how crystal handles serialization, very intuitive
<FromGitter> <girng> I have an idea of something awesome now since I kind of know how macros work hahha
<FromGitter> <girng> @dscottboggs_gitlab 👍
<FromGitter> <Blacksmoke16> ayy
<FromGitter> <proyb6> sample = {} of String => self
<FromGitter> <proyb6> I wonder what "=> self" means?
<FromGitter> <dscottboggs_gitlab> I think it would depend on the context?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
woodruffw has quit [Ping timeout: 246 seconds]
<FromGitter> <girng> gosh i love structs
woodruffw has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> whys that?
<FromGitter> <girng> dot notation mostly, and it makes me feel like i'm doing it "right" because i'm defining my values to the correct types. hard to explain, i'm weird.
<FromGitter> <dscottboggs_gitlab> no, you're right, I just was slightly confused because that also applies to classes. but yes compared to languages that just use hash-tables for everything it does feel very "right" haha
<FromGitter> <girng> haha, well i guess i feel the same way w/ classes too
<FromGitter> <girng> i wonder what that phenomena is called?
<FromGitter> <dscottboggs_gitlab> strict typing?
literal has quit [Ping timeout: 250 seconds]
<FromGitter> <girng> guess that's it, i never knew i would like it though, i always liked to use whatever for any variable
<FromGitter> <girng> maybe just what i accustomed to growing up
<FromGitter> <girng> but there is definitely a difference (psychologically) i find that interesting and very cool
<FromGitter> <dscottboggs_gitlab> same. in Java and sometimes Go it just seems cumbersome but crystal taking care of boilerplate with macros and inheritance really nails the sweet spot to me
<FromGitter> <girng> awesome
<FromGitter> <dscottboggs_gitlab> true. I'm more sure that my code does what I want it to
<FromGitter> <girng> yep, exactly
<FromGitter> <dscottboggs_gitlab> it feels nice to write code that looks elegant too, and crystal enables that in a lot of ways.
marmotini_ has joined #crystal-lang
<FromGitter> <girng> yeah i much prefer looking at crystal's syntax compared to my old nodejs server files
<FromGitter> <dscottboggs_gitlab> no damn curly braces or dollar signs everywhere haha
<FromGitter> <girng> bahwhahh
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5rdg
<FromGitter> <Blacksmoke16> prob is some way to make some nice pre processing here
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I'm having a weird issue with a shard.
<FromGitter> <Blacksmoke16> uh oh
<FromGitter> <dscottboggs_gitlab> here, this shell script replicates the issue. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f46acf4880a60a25d1c68]
<FromGitter> <dscottboggs_gitlab> when you run that, you get
<FromGitter> <dscottboggs_gitlab> ```in src/borken.cr:1: while requiring "kemal-auth-token": can't find file 'kemal-auth-token'```
<FromGitter> <Blacksmoke16> should you be adding an `EOF` as the first thing in the file?
<FromGitter> <Blacksmoke16> `cat << EOF > shard.yml`
<FromGitter> <dscottboggs_gitlab> that's a heredoc
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <dscottboggs_gitlab> writes the contents between that line and the other EOF to the file
<FromGitter> <dscottboggs_gitlab> sorry for being confusing I should've just used quotes
<FromGitter> <dscottboggs_gitlab> It looked like it was an older version of the shard.yml, it didn't have a `target` or `crystal` directive, so I added those, and also tried changing the dashes in the name to underscores but that's legal so it didn't make a difference
gangstacat has quit [Ping timeout: 246 seconds]
Raimondi has quit [Read error: No route to host]
<FromGitter> <Blacksmoke16> dunno
<FromGitter> <dscottboggs_gitlab> damn
<FromGitter> <Blacksmoke16> same error if you try a diff shard?
<FromGitter> <dscottboggs_gitlab> no it's that shard
<FromGitter> <Blacksmoke16> ah
<FromGitter> <dscottboggs_gitlab> it hasn't been updated in almost 2 years.
Raimondi has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> I brought it up-to-date and it's specs pass but I can't `require` it into another project
<FromGitter> <dscottboggs_gitlab> same as here (https://github.com/akwiatkowski/kemal-auth-token/issues/2)
<FromGitter> <Blacksmoke16> try just `kemal-auth`
<FromGitter> <dscottboggs_gitlab> same
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <dscottboggs_gitlab> I'm gonna try renaming the main entrypoint to `kemal-auth-token`
<FromGitter> <dscottboggs_gitlab> oooh I think that's going to fix it.
Raimondi has quit [Ping timeout: 240 seconds]
gangstacat has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> yeah that fixed it
<FromGitter> <girng> am loving the `when` ` then` one liner. gotta thank blacksmoke for that one :D
<FromGitter> <Blacksmoke16> :ok
<FromGitter> <Blacksmoke16> 👌
<FromGitter> <Blacksmoke16> ah man, is there no way to do like `@type.class_methods`?
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <Blacksmoke16> `@type.class.methods`
<FromGitter> <dscottboggs_gitlab> nice
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f4fa8e4787d16e37a4635]
<FromGitter> <Blacksmoke16> WIP proof of concept
<FromGitter> <dscottboggs_gitlab> oooh that's nice
<FromGitter> <Blacksmoke16> atm just need a way to parse params from the route string in the call method
<FromGitter> <Blacksmoke16> and some way to smartly convert string to T
<FromGitter> <Blacksmoke16> but i have some ideas so see how it goes
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f50ae5e409525034a7b7c]
<FromGitter> <Blacksmoke16> that seems to work
<FromGitter> <Blacksmoke16> also need a way to store the procs with dynamic params...
<FromGitter> <dscottboggs_gitlab> I have a `type Token = StaticArray(UInt8, 512)`
<FromGitter> <dscottboggs_gitlab> is there any way to add methods to that?
<FromGitter> <Blacksmoke16> whats the `type` keyword do?
<FromGitter> <dscottboggs_gitlab> like an alias?
<FromGitter> <dscottboggs_gitlab> StaticArray is a Struct so you can't inherit from it
<FromGitter> <dscottboggs_gitlab> I could create a struct with only one variable but that seems...like not the crystal thing to do haha
<FromGitter> <Blacksmoke16> what like
<FromGitter> <Blacksmoke16> ```struct StaticArray ⏎ def foo ⏎ "foo" ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c0f517933d9e11991b373a9]
<FromGitter> <dscottboggs_gitlab> like ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c0f518228907a3c7bff37a5]
<FromGitter> <anamba> yeah you could just reopen it... although you'd then have #foo on *every* staticarray
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f51cd80986419d5716a79]
<FromGitter> <anamba> @dscottboggs_gitlab that's probably the best way.
<FromGitter> <Blacksmoke16> yea pretty much
<FromGitter> <dscottboggs_gitlab> :/
<FromGitter> <Blacksmoke16> still not sure what the `type `does
<FromGitter> <Blacksmoke16> ah its for C bindigns?
<FromGitter> <dscottboggs_gitlab> oof I probably was using that wrong
<FromGitter> <Blacksmoke16> `alias` is prob what you want
<FromGitter> <dscottboggs_gitlab> yes but you can't define methods on an alias
<FromGitter> <anamba> hmm that page features recursive types
<FromGitter> <Blacksmoke16> you shouldnt have to, its just defining a type with a diff name
<FromGitter> <dscottboggs_gitlab> yeah alias doesn't get the behavior I was going for either.
<FromGitter> <dscottboggs_gitlab> Alias is just a like a macro that drops in the type in its place
<FromGitter> <dscottboggs_gitlab> I was going for something stronger
return0e has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> ok
return0e has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> but you're right that `type` wasn't what I was looking for
marmotini_ has quit [Ping timeout: 250 seconds]
<FromGitter> <dscottboggs_gitlab> I think this is the best I'm going to get. Which is fine, it just seems like it would be more efficient to be able to define methods directly on a type alias like in go ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f53b4e4787d16e37a5bdc]
<FromGitter> <dscottboggs_gitlab> which is where I got that `type` keyword now that I think about it
<FromGitter> <dscottboggs_gitlab> whoops
<FromGitter> <anamba> question, why aren't .fresh and .from_s initializers?
<FromGitter> <dscottboggs_gitlab> they aren't?
<FromGitter> <anamba> or are you trying to match an existing interface
<FromGitter> <anamba> i mean as in `def initialize`
<FromGitter> <dscottboggs_gitlab> Oh I guess I could do that
<FromGitter> <dscottboggs_gitlab> I originally wrote that by trying to inherit from the `TokenType`, which you can't do because it's a struct. I didn't want to collide with the existing initializers on that type
<FromGitter> <anamba> crystal has a neat thing like swift/objc where you can do `def initialize(from s : String)`
<FromGitter> <dscottboggs_gitlab> overloads?
<FromGitter> <anamba> and call it like `Token.new(from: "string")`
<FromGitter> <anamba> i forgot what it's called. an alternate arg name
<FromGitter> <dscottboggs_gitlab> oh wait, what?
<FromGitter> <dscottboggs_gitlab> OMG
<FromGitter> <anamba> external names
<FromGitter> <dscottboggs_gitlab> that's amazing
<FromGitter> <anamba> after finding that, i now tend to use some kind of overload of `initialize` instead of initializers with random names
<FromGitter> <dscottboggs_gitlab> yeah this is pretty nice but it still seems like the struct with one property is a weird thing to have ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f55fc28907a3c7bff508a]
<FromGitter> <anamba> i dunno, looks good to me
<FromGitter> <anamba> well... it feels bad to me to call new within initialize
<FromGitter> <dscottboggs_gitlab> oof you're right I should've looked closer at that
<FromGitter> <dscottboggs_gitlab> I changed it to `@data = ` like in the other one
<FromGitter> <anamba> ok good
<FromGitter> <anamba> @DanilaFe did you give up
<FromGitter> <DanilaFe> no...
<FromGitter> <DanilaFe> I wish...
<FromGitter> <DanilaFe> I'm still struggling
<FromGitter> <anamba> @DanilaFe it's ok to give up. i did... in a way. in a way that still got me the answer 😂
<FromGitter> <DanilaFe> I'm probably going to quit AoC after this one.
<FromGitter> <anamba> aww why
<FromGitter> <dscottboggs_gitlab> what's AoC?
<FromGitter> <anamba> https://adventofcode.com/2018
<FromGitter> <DanilaFe> because I'm rank 2k+ at this point, any leaderboard standings I might have had are in the garbage now.
marmotini_ has joined #crystal-lang
<FromGitter> <anamba> you are still leading our leaderboard. or at least, you will be once you finish part 2
<FromGitter> <dscottboggs_gitlab> what's it for?
<FromGitter> <DanilaFe> I'm not sure if I'll even finish part 2
<FromGitter> <DanilaFe> I wrote a dynamic programming algorithm....and it's even slower than my original
<FromGitter> <DanilaFe> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f59a4e4787d16e37a7d16]
<FromGitter> <anamba> @dscottboggs_gitlab AoC is just for fun. to challenge yourself. for me, to see if i can remember the stuff i learned in hs/college (which was a looong time ago). couple days ago i had to recall some stuff i learned in 10th grade
<FromGitter> <DanilaFe> dynamic programming solution, which still takes several seconds
<FromGitter> <dscottboggs_gitlab> oh ok
<FromGitter> <dscottboggs_gitlab> that problem did look fun
<FromGitter> <DanilaFe> I'm not sure why it takes so long since it's basically glorified array access
_whitelogger has joined #crystal-lang
<FromGitter> <DanilaFe> it's kind of painful getting rank 108 on part one and then 2k+ on part two
<FromGitter> <DanilaFe> and that has happened several times in a row
<FromGitter> <girng> i know a good way to challenge myself. the thought of going outside
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 250 seconds]
marmotini has quit [Ping timeout: 246 seconds]
marmotini has joined #crystal-lang
<FromGitter> <anamba> @DanilaFe i wonder if the puzzles are designed to increase in difficulty over time? i'm guessing they don't, since there is a sort of continuous storyline. my rank for part 2 has been better than part 1 for all but 1 of the days.
<FromGitter> <DanilaFe> they should
<FromGitter> <DanilaFe> get harder
<FromGitter> <DanilaFe> yeah, last year I would be faster on part 2
marmotini has quit [Remote host closed the connection]
<FromGitter> <nagash> @anamba Oh, can I join the leaderboard?
<FromGitter> <anamba> @nagash absolutely. if i can find just the link :joy
<FromGitter> <anamba> > *<Jenz>* Go here https://adventofcode.com/2018/leaderboard/private, with join code: 289786-69f3013e
<FromGitter> <nagash> @DanilaFe I struggled today as well. Had a slow solution for part 2, I started refactoring while it was running and finished refactoring before it was even done, then it was quick.
<FromGitter> <anamba> ok you win today if you found a solution that made it fast :)
<FromGitter> <DanilaFe> let me time mine
<FromGitter> <DanilaFe> how long does yours take?
<FromGitter> <DanilaFe> 1) 5 seconds for me...
<FromGitter> <anamba> i just let mine iterate through sizes until it stopped finding higher numbers. it never got all the way up to 300 but that turned out not to matter very much.
<FromGitter> <DanilaFe> ah
<FromGitter> <nagash> @DanilaFe Oh no, not that "fast". "fast" as in it will finish before I give up. 21secs.
<FromGitter> <anamba> i ctrl-c'd mine after it gave me an answer that the system would accept :-D
<FromGitter> <DanilaFe> darn...I wonder if it's possible any faster
<FromGitter> <DanilaFe> because using DP, indiviual square computation is O(1) because
<FromGitter> <DanilaFe> however, the number of squares is still O(n^2)
<FromGitter> <DanilaFe> if I do what you said, and stop after I can't find larger numbers
<FromGitter> <DanilaFe> then my solution takes .3 seconds
<FromGitter> <anamba> i see, you stored all the computations to try to make the larger sizes go faster? if you do that, then i'm thinking, if you really wanted to make this go fast, you could ignore the squares that are primarily composed of lower scoring squares. skip the areas that have no chance to be the best, focus on the areas that were already high scoring for smaller sizes.
<FromGitter> <DanilaFe> but how can I know which areas have the chance?
<FromGitter> <anamba> actually, now i wonder if anyone decided to attack this in the opposite direction (i.e. big to small)
<FromGitter> <anamba> but... i have already expended enough brain power on this, and really should get back to work :)
<FromGitter> <DanilaFe> I did
<FromGitter> <DanilaFe> back to small
<FromGitter> <DanilaFe> the solution is size 11 though
<FromGitter> <DanilaFe> so it wouldn't have helped
<FromGitter> <DanilaFe> (by I did I mean I tried before, not my final solution)
<FromGitter> <girng> is it possible to use a different operator (`+=` or `-=`) in a method, based on the value of a parameter? ⏎ https://play.crystal-lang.org/#/r/5rfl
<FromGitter> <dscottboggs_gitlab> gotta use a macro
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5rfn/edit
<FromGitter> <dscottboggs_gitlab> shit
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5rfo
<FromGitter> <girng> whattt O_O my reaction (https://media.giphy.com/media/l0IypeKl9NJhPFMrK/giphy.gif). haha awesome
<FromGitter> <girng> could I get away with it, just using `{{operator.id}}`?
<FromGitter> <girng> or it doesn't matter
<FromGitter> <dscottboggs_gitlab> what do you mean?
<FromGitter> <girng> what_kind, p, and value are in macros. is that required for the operator to work?
<FromGitter> <dscottboggs_gitlab> hm, I would do it differently. lets see
<FromGitter> <girng> https://play.crystal-lang.org/#/r/5rfr oh WOW it does!!
<FromGitter> <girng> gosh that's epic af
<FromGitter> <girng> Thanks @dscottboggs_gitlab !!
<FromGitter> <dscottboggs_gitlab> I think you meant to put `increment` and `decrement`, not allocate and deallocate?
<FromGitter> <girng> yeah i just did deallocate cause i'm only running the decrement one on the nodes the player removed
<FromGitter> <girng> but i meann decrement works too
<FromGitter> <girng> i'm pretty terrible at namiing stuff. i'm sure if i gave it more thought it would prob help me in the long run though, that's for sure...
<FromGitter> <j8r> ?
<FromGitter> <anamba> > https://play.crystal-lang.org/#/r/5rfr oh WOW it does!!
<FromGitter> <girng> hi @j8r :D
<FromGitter> <anamba> careful that probably doesn't do exactly what you think it's doing
<FromGitter> <dscottboggs_gitlab> yeah I thought there was something wrong with that
<FromGitter> <anamba> remember, a macro is just a program that outputs code to the place you call the macro
<FromGitter> <girng> i don't get it
<FromGitter> <girng> isn't it doing exactly what i want?
<FromGitter> <anamba> it is doing what you want... just not in the way you are thinking
<FromGitter> <anamba> just wanted to clarify that
<FromGitter> <j8r> Hi @girng
<FromGitter> <girng> oh it's a macro method, not an inline
<FromGitter> <girng> i thought it was inline
<FromGitter> <girng> https://play.crystal-lang.org/#/r/5rg1 yeah, see that doesn't work. you are right Aaron, not what i thought
<FromGitter> <dscottboggs_gitlab> HERE
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5rg3
<FromGitter> <dscottboggs_gitlab> this is what macros can do for you!
<FromGitter> <dscottboggs_gitlab> :D
<FromGitter> <anamba> ooh, interesting
<FromGitter> <girng> O_O
<FromGitter> <girng> need me some to process this
<FromGitter> <dscottboggs_gitlab> which immediately leads to https://play.crystal-lang.org/#/r/5rg5
<FromGitter> <dscottboggs_gitlab> > i think i understand it ⏎ ⏎ oh good! anything you're iffy on?
<FromGitter> <girng> was just confused at the inline namedtuples but i see the ':' now, which then points to the + or - haha
<FromGitter> <girng> is it a namedtuple if it's in a macro??
<FromGitter> <dscottboggs_gitlab> yes exactly
<FromGitter> <dscottboggs_gitlab> you could also extract that out into a constant
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5rg6 then you can define `ATTRIBUTES` in a central location!
<FromGitter> <girng> my brain is about to explode
<FromGitter> <dscottboggs_gitlab> :D
<FromGitter> <nagash> @anamba @DanilaFe Eh, as fast as I could get. I'm giving up now. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0f7c1b80986419d57262b6]
Renich has quit [Quit: Renich]
<FromGitter> <yxhuvud> I've seen a ruby solution that is twice as fast as that.
notdaniel has joined #crystal-lang
ashirase has quit [Ping timeout: 252 seconds]
ashirase has joined #crystal-lang
sagax has quit [Ping timeout: 250 seconds]
dkh has joined #crystal-lang
notdaniel has quit [Ping timeout: 264 seconds]
<FromGitter> <drum445> @RX14 A while ago we were chatting about i3. Do you just use the tabbed layout?
<RX14> yes
<RX14> pretty much
<RX14> i use splits a few times a year
<FromGitter> <drum445> I only ever use maximised windows, so I don't see the point in not using a tiling wm
<RX14> same
dkh has quit [Quit: Leaving]
<FromGitter> <asterite> for part 2 I just did the naive solution, with `--release` it runs in almost 2 minutes. It's not much to wait :-) (it takes more time to think about the dynamic programming solution :-P)
<FromGitter> <asterite> but the DP solution is nice to think about... i might try it and compare times
<FromGitter> <yxhuvud> my slowest so far (not counting todays day2 take 100ms for both parts, so suddenly getting a minute isn't acceptable for me.
<FromGitter> <asterite> haha, yes, when you run it and a few seconds pass I think "hm, this isn't right..."
<FromGitter> <proyb6> Yeah, Day 11 part 2 in Golang just too 0:00:08 and 5MB+ memory
Jenz has joined #crystal-lang
<Jenz> Feels good doing something ridicolously stupid every now and then: https://github.com/Homebrew/brew/issues/3901
<Jenz> Just remembered
<Jenz> Just with "ridicolously" spelled right
* Jenz :<
Jenz has quit [Client Quit]
<FromGitter> <girng> everytime i see "brew" i think of @bew
<FromGitter> <bew> ¯\_(°-°)_/¯
<FromGitter> <j8r> @girng girng reminds me grin 😁
Jenz has joined #crystal-lang
<FromGitter> <girng> 😆
<FromGitter> <j8r> :girning:
<Jenz> haha
<FromGitter> <girng> @j8r lolz
<mps> RX14: I posted new APKBUILD for crystal to alpine-aports last night, waiting for ncopa to move it in repo
<mps> anyone can help me with graceful shutdown (close) for HTTP::Server, I could post source somewhere
Jenz has quit [Ping timeout: 250 seconds]
<FromGitter> <proyb6> AOC Day 11 could use partial sum?
<FromGitter> <spencerwi> Hi y'all, I'm back. Is there some Crystal equivalent of the weird Python construct: ⏎ ⏎ ```if __name__ == "__main__": ⏎ main()``` [https://gitter.im/crystal-lang/crystal?at=5c0fdb44178d7860a1bdf1b6]
<FromGitter> <spencerwi> it's helpful for allowing a file to be executable as a program entry point, but also allowing import of the file without execution of the "main-method" code
<FromGitter> <spencerwi> Looks like I can "whitelist" specs by doing:
<FromGitter> <straight-shoota> @spencerwi Since Crystal code is compiled, you can't know the name of the program at runtime. It can be easily changed by `-o` argument or by renaming the binary.
<FromGitter> <straight-shoota> A typical idiom for separating library code from running a main method is to use a separate file as entrypoint for an application. For example `app.cr` or `cli.cr`.
<FromGitter> <spencerwi> That makes sense
<FromGitter> <straight-shoota> When you want to require the library code without automatically executing anything, it's `require "my-shard"`. When building an exectuable it's `crystal build src/app.cr -o my-shard`
<FromGitter> <spencerwi> The approach I'm using works for my quick Advent-of-Code solutions, but you're right that separating "library" code from "executable" code is the right approach for real code
<mps> anyone knows does graceful shutdown works for HTTP::Server close
<FromGitter> <j8r> nope
<FromGitter> <j8r> If not implemented, I don't think it would be too hard: ⏎ ⏎ 1) don't accept any new connections ⏎ 2) wait until all are finished ⏎ 3) close [https://gitter.im/crystal-lang/crystal?at=5c0fe288178d7860a1be2096]
<mps> j8r: you mean it doesn't work, i.e. doesn't close gracefully
<FromGitter> <j8r> mps: what are you using now?
<mps> I have solution with counting opened connections and close only if it is zero
<mps> but RX14 told me that it could work without that
<RX14> you just call .close
<RX14> just server.close
<RX14> and it doesnt accept new requests
<mps> yes
<RX14> and then when all the requests return, it stops the server
<RX14> and .close returns
<mps> RX14: here is the example I'm trying
<FromGitter> <drum445> @spencerwi you shouldn't really need that in Crystal
<RX14> mps, what happens?
<mps> exits when signal comes
<mps> without waiting
<RX14> oh, looks like it doesn't wait :/
<mps> start the server, connect with curl, press Ctrl-C and it immediately ends
<RX14> i was really sure it did... maybe we didnt merge that PR
<FromGitter> <j8r> btw we should have 2 mods
<FromGitter> <j8r> and a timeout for the graceful one
<FromGitter> <j8r> (the timeout already exists AFAIK)
<RX14> mps, actually, .listen should wait until everything shuts down gracefully
<RX14> actually no it doesn't at all
<mps> it doesn't in my example
<RX14> fuck
<RX14> open or bump an issue
<RX14> because there's no way currently
<RX14> and there should be
<mps> oh, well, no problem, now I know that it doesn't work and not trying
<mps> you save some of my time
<RX14> i misread the source
<RX14> it waited until all the connection accepters shut down gracefully
<RX14> which is absolutely useless
<mps> i don't know inner working of that in crystal so couldn't help
<mps> I could post solution with connections counting and fiber.yield, to examine it
<mps> it works but just for signal sent once, if two signals arrives before close it gives me "Can't close server, it's already closed (Exception)"
<mps> I mean, before exiting and not close
<mps> RX14: sorry to bothering you, but would you look at my solution with counting connections and give your opinion. I will post it if you agree
<RX14> i'm busy right now
<mps> ok, maybe later when you have time just page me
<mps> cul
<RX14> mps, just send it now and i'll look when i can
<mps> ok
<mps> here it is http://tpaste.us/ZgE4
akaiiro has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
akaiiro has joined #crystal-lang
Renich has joined #crystal-lang
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 246 seconds]
rohitpaulk has quit [Ping timeout: 250 seconds]
<FromGitter> <vladfaust> Excuse me, I'm experimenting with C bindings. Got this code: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ How to do it properly? [https://gitter.im/crystal-lang/crystal?at=5c0ffe588b656e2b04fb3262]
<FromGitter> <vladfaust> ```code paste, see link``` ⏎ ⏎ Compiles, thanks! 🎉 [https://gitter.im/crystal-lang/crystal?at=5c0fff4a8336e22a7d188974]
<FromGitter> <vlazar> @vladfaust are you working on bindings for https://github.com/ohler55/agoo?
<FromGitter> <vladfaust> @vlazar yeah
<FromGitter> <vlazar> That's cool! Would be great to see how it works with Crystal
<FromGitter> <vlazar> Last time I've tried it with Ruby it was superfast but there were errors with requests... hope it's better now
<FromGitter> <straight-shoota> RX14, mps `HTTP::Server.listen` isn't properly implemented currently. It just waits for all socket listeners to be closed. But there might still be active requests.
<FromGitter> <straight-shoota> It's a bit tricky because a general implementation needs to pay attention to upgraded connections.
Raimondi has joined #crystal-lang
<mps> straight-shoota[g]: thank you for explanation. I will look at go-lang implementation if I find some time
<mps> they have graceful shutdown IIRC
<FromGitter> <straight-shoota> IIRC we talked about this in the context of #5776, RX14
<DeBot> https://github.com/crystal-lang/crystal/pull/5776 (Refactor `HTTP::Server` to bind to multiple addresses)
<mps> straight-shoota[g]: yes, and I had a hope that the problem is solved in meantime
<FromGitter> <straight-shoota> nope, still todo
<FromGitter> <straight-shoota> it shouldn't be too difficult though
<mps> ok, no problem for me. just would like that the crystal have that
<FromGitter> <straight-shoota> My secret wish is to have #6468 for this =)
<DeBot> https://github.com/crystal-lang/crystal/issues/6468 ([RFC] Structured Concurrency)
<mps> straight-shoota[g]: btw, with your help and some tweaks I have server with graceful restart (and with one supervisor)
Jenz has joined #crystal-lang
<FromGitter> <vladfaust> Playing with threads and connections I've managed to reach 165k RPS with Agoo (single Process), while HTTP::Server is giving 110k RPS
<FromGitter> <vladfaust> Forking Agoo doesn't give an effect because it's already multi-threaded C
non-aristotelian has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
<RX14> We will be removing stuff from the stdlib
<RX14> It will happen
<RX14> Before 1.0
<Jenz> Yeah Im completely for that
<Jenz> But ARGF?
<Jenz> There's no way it's a good idea to remove ARGF
<Jenz> I wonder if I'm being an idiot again, and is the only one who thinks so
<z64> based on the examples in https://crystal-lang.org/api/0.27.0/toplevel.html#ARGF what does ARGF facilitate that Crystal code using `File` and `STDIN` doesn't cover?
<Jenz> It's not that it's covered elsewhere, it's that it's very convenient
<z64> as someone who has never used ARGF before, the section on "manipulating argv to control argf" is confusing. and it would be very simple to implement argf in crystal, which, for most cases would be a little more than `io = ARGV.empty? ? STDIN : File.open(ARGV.first, "r")`
<FromGitter> <0x2C6> hey guys. What can I use instead of asterisk in crystal which points an array in ruby smt like that
<z64> personally, i'm not for or against removing it - but i dont think anything would really be lost by removing it either that can't be replaced by a few lines
<z64> @0x2C6 hello there. your question isn't entirely clear; could you maybe write an example of what you want to do, that does or doesn't work, on https://carc.in/#/cr ? i assume you're talking about the splat operator, but not sure what you want to do with it
<Jenz> z64: IMO it's very convenient, and more reason to keep it than to remove it
* Jenz ¯\_(ツ)_/¯
<z64> but, am i understanding that the convenience is not having to write that ternary i just posted above..?
<Jenz> tbh Im not completely sure DX
<z64> oh. okay lol:)
<FromGitter> <drosehn> Doesn't `STDIN` default to unprocessed ARGV values in crystal, or is that just in ruby?
<Jenz> Not in crystal I'm quite sure. Though not completely sure
<FromGitter> <0x2C6> Ok in ruby if I write something like that it returns me that ⏎ ` ⏎ a, *b, c = [1,2,3,4] #=> a = 1, b = [2, 3], c = 3 ⏎ ` ⏎ but in crystal it occurs an error, the splat operator works in function quite well but doesn't while assignment. I hope that was clear :) [https://gitter.im/crystal-lang/crystal?at=5c101de833d9e11991b8fb1b]
<FromGitter> <drosehn> ie, `STDIN` *is* something kinda like: `ARGV.empty? ? File.open("/dev/tty", "r") : File.open(ARGV.first, "r")`
<FromGitter> <bew> Yes, it's not possible currently @0x2C6, there's an open issue about that
<FromGitter> <drosehn> really it's more like a "push new File.open"
<FromGitter> <bew> @0x2C6 #132
<DeBot> https://github.com/crystal-lang/crystal/issues/132 (Array/Tuple decomposition)
<FromGitter> <bew> wut @drosehn there is no relation between STDIN and ARGV, or did I miss sth said before?
<FromGitter> <0x2C6> hmmm :( Okay thank you because I watch official docs and for a moment I thought maybe I am missing something
<FromGitter> <0x2C6> I'm new on crystal, have any suggested book or something else ?
<FromGitter> <drosehn> There is some connection in ruby, because I just fixed a bug in one of my ruby scripts because of that. (or maybe it's with `$stdin` in ruby, not `STDIN`). I didn't know if the same connection existed in crystal.
<FromGitter> <drosehn> given the ruby script: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c1020d88336e22a7d197131]
<FromGitter> <drosehn> ```#!/usr/bin/env ruby ⏎ blah = gets ⏎ printf "gets read in '%s'\n", blah.chomp``` [https://gitter.im/crystal-lang/crystal?at=5c10210d8336e22a7d1972ea]
<FromGitter> <drosehn> if you run the script with no parameters, it reads from the terminal. if you supply a parameter of `first_arg`, you'll get an error message about "No such file or directory - first_arg".
<FromGitter> <drosehn> change it to:
<FromGitter> <drosehn> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c1021e44808192b03201aef]
<FromGitter> <drosehn> and `crystal run` that, with or without a parameter.
<FromGitter> <bew> Oh weird, no there's no relation in Crystal
<FromGitter> <drosehn> well, I just did that in `Crystal 0.25.1 (2018-07-02) LLVM: 5.0.2` on macOS, and it worked as I expected. No idea where the connection would be.
<FromGitter> <j8r> Wow you're on an old version
<FromGitter> <drosehn> I can't seem to build the latest version from brew, and haven't wanted to delve into why.
<FromGitter> <drosehn> ... though I'm about 99% sure that it's because I'm on El Capitan, and brew has dropped active support for that.
<FromGitter> <drosehn> (that version of macOS, I mean)
<FromGitter> <drosehn> Interesting if that behavior has changed in the newer versions of crystal.
<z64> @drosehn yes close, STDIN in crystal uses LibC to figure out the current tty and open an IO::FileDescriptor to it
<FromGitter> <drosehn> but does it also check for left-over values in `ARGV`?
<z64> no, not that i can see
<FromGitter> <drosehn> what happens if you `crystal run` the short program I posted above, both with and without a parameter? (do it at a command line, not from within a web-ized playground)
<z64> it doesn't do anything with the parameter
<FromGitter> <drosehn> okay, interesting.
<FromGitter> <drosehn> (not that I object. just that it's interesting the behavior changed)
<FromGitter> <drosehn> another week until end-of-semester here, and then hopefully I'll be able to get my crystal world updated and working.
<z64> don't recall it ever changing, went as far back as crystal 0.20 *shrug*
<FromGitter> <drosehn> Well, as I just mentioned, the behavior of that program worked the way I'd expect (based on ruby), with me running `0.25.1`.
<FromGitter> <asterite> ARGF is not ARGV.first, it's the concatenation of all the files given as arguments to the program (or STDIN if no file is given)
<FromGitter> <drosehn> Ah, so it drops out any arguments which start with `-`? That's probably the significant detail I was missing.
<z64> ah okay @asterite. thank you
<FromGitter> <drosehn> Also explains why I haven't run into this bug (in my own programs) much more often!
<FromGitter> <Blacksmoke16> crap `splatting a union (Tuple(Int64) | Tuple(Int64, Int32)) is not yet supported`
Raimondi has joined #crystal-lang
Jenz has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> need a way to cast my tuple returned from a method to a specific type...
<FromGitter> <jwoertink> That repo looks like when you make an app and need to test the data so you load it with junk.
literal has joined #crystal-lang
<literal> is there a way to handle each request of an HTTP::Server with its own fiber?
<literal> so a request handled could wait on IO without blocking another request
<FromGitter> <bew> Isn't it already how it works?
<literal> well then, problem solved
<FromGitter> <bew> And for each requests it's line 362
<FromGitter> <bew> :)
<FromGitter> <DanilaFe> @nagash if you stop after seeing numbers, it's 200ms
<FromGitter> <DanilaFe> In Crystal
<FromGitter> <DanilaFe> Now I don't know what the ruby solution did, and its probably much more clever than me...
<FromGitter> <DanilaFe> @yxhuvud what was your best time for d11p2?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5rnb i added a comment of what im trying to do
<FromGitter> <Blacksmoke16> out of ideas at this point :/
<FromGitter> <Blacksmoke16> could reloop over the methods and build out a case statement or something to cast it correctly... hmm
<FromGitter> <jwoertink> Is this a new web framework you're working on?
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Client Quit]
Renich has joined #crystal-lang
<FromGitter> <Blacksmoke16> Dunno yet, ATM it's more of a see if you can do it fun project
<mps> anyone know for a guide about parsing xml to hash or structure
<FromGitter> <Blacksmoke16> hmm i did the case thing
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c104d88178d7860a1c0f3fe]
<FromGitter> <Blacksmoke16> but args still is the unioned type...
<FromGitter> <Blacksmoke16> is the correct type in the case so might just have to do it in there?