<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
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]
<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> 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>
<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>
<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> 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>
<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
<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>
<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
<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
<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>
<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> 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> 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`