ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.29.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
<FromGitter> <Blacksmoke16> something like that yea
<alex``> writer.puts content
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> which would write to both files at the same time
<FromGitter> <Blacksmoke16> well, not actually the *same* time but you know what i mean
<alex``> yep :p
<FromGitter> <tenebrousedge> IO#pipe does not do what I thought it did o__O but still kinda useful, see https://github.com/crystal-lang/crystal/blob/0004179c9576c89d14e617423828af6f31e6d7a1/spec/std/logger_spec.cr
<alex``> there is way to iterate 2 arrays at the same time?
<FromGitter> <tenebrousedge> `zip` is probably a good option
<FromGitter> <tenebrousedge> how big are the arrays?
<alex``> I have an array of strings, input and output, which size should be same, and want iterate them
<alex``> idk
<alex``> can be big
<alex``> (big to me = 1000~)
<FromGitter> <tenebrousedge> if `zip` doesn't perform well, just use `(0...arr.size) { |idx| arr[idx], other[idx] }`
<alex``> i do that currently
<FromGitter> <tenebrousedge> `zip` is more elegant, but creating the intermediate array can be costly
<alex``> zip transforms arr1, arr2 to val1 => val2?
<FromGitter> <tenebrousedge> `arr.zip(other) do |(val1, val2)|
<alex``> I was expecting a list of [val1, val2]
<FromGitter> <tenebrousedge> the parentheses are important
<alex``> https://crystal-lang.org/api/master/Enumerable.html#zip(*others:Indexable|Iterable|Iterator,&block)-instance-method
<FromGitter> <Blacksmoke16> whats the goal here?
<alex``> i do not see parenthesis
<FromGitter> <tenebrousedge> `arr.zip(other) do |(val1, val2)|`
<alex``> compare each value to do an action
<alex``> you sure about parenthesis mandatory?
<FromGitter> <Blacksmoke16> ah so compare array1 with array2, idx 0 and idx 0 etc?
<alex``> I was thinking it would do it automatically as you give more than one
<alex``> yes Blacksmoke
<FromGitter> <Blacksmoke16> and want a bool if they all the same?
<alex``> hm
<FromGitter> <Blacksmoke16> like true they all the same, or false there is at least one different?
<alex``> I want to perform different action, "pick" for same, "map" for diff, "drop" for deleted (value of output is empty)
<FromGitter> <Blacksmoke16> hmm ok
<FromGitter> <Blacksmoke16> do you care about the values themselves, or just that some are diff?
<alex``> you was thinking to all? / any?
<alex``> I care actually, in the loop, I do something like pick << {input} or map << {input,output} or drop << {input}
<FromGitter> <Blacksmoke16> are they going to be the same size?
<alex``> they should, normally they have to be the same size, (the user could delete a line)
<alex``> I check the size of the output the user edited
<alex``> before doing my stuff
<alex``> and compare with input.size
<FromGitter> <Blacksmoke16> could do like `arr.size times do |idx| { arr[idx]; arr2[idx] }`?
<alex``> times starts at 0? :o
<FromGitter> <Blacksmoke16> prob?
<FromGitter> <tenebrousedge> check size first, use `zip`, then reject empty, then partition based on equality
<FromGitter> <tenebrousedge> or `map` instead of partition if you don't mind a conditional in the loop
<alex``> array.size.times could save iterations
<FromGitter> <tenebrousedge> it's the same thing as using the range
<alex``> "partiton based on equality" is what I was doing?
<alex``> `pick << {input} or map << {input,output} or drop << {input}`
<alex``> (I'm not native english sorry)
<FromGitter> <Blacksmoke16> imo prob doesnt really matter
<FromGitter> <Blacksmoke16> `We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.`
<alex``> zip looks nicer because we have the value directly, instead of arr[idx]
<FromGitter> <Blacksmoke16> readability is an impt factor as well
<FromGitter> <tenebrousedge> always use higher-order iterators if possible
<FromGitter> <tenebrousedge> ```code paste, see link```
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/crylog/releases/tag/v0.1.1 new crylog version is out
<FromGitter> <Blacksmoke16> fixes a bug and adds a new formatter
<alex``> Blacksmoke16 I finished my program almost
<alex``> but for MultiWrite
<alex``> how to write to the file?
<alex``> I do that
<FromGitter> <Blacksmoke16> `writer.puts "value"`?
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9b528b76eac527ab6635a]
<alex``> no
<FromGitter> <Blacksmoke16> prob have to open them first
<alex``> with just writer.puts Blacksmoke, when I do Process.run with the editor, the file is empty
<alex``> I have to .close input and output
<FromGitter> <Blacksmoke16> try `writer.flush`
<alex``> I tried xd
<FromGitter> <Blacksmoke16> i mean that should do it
<FromGitter> <Blacksmoke16> `writer.puts "foo"
<FromGitter> <Blacksmoke16> `writer.flush`
<FromGitter> <alexherbo2> ``` writer.puts input.join('\n') ⏎ writer.flush``` [https://gitter.im/crystal-lang/crystal?at=5cf9b5b265392c3b60d14492]
<FromGitter> <alexherbo2> I was doing that
<FromGitter> <Blacksmoke16> that should do it
<FromGitter> <alexherbo2> nope :(
<FromGitter> <alexherbo2> you want my program to test?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9b63de41fe15e75255037]
<FromGitter> <Blacksmoke16> i just did it and it worked fine
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9b6513dcdab400301796c]
<alex``> $ crystal build batch.cr
<alex``> the file is empty for me
<FromGitter> <Blacksmoke16> ill check it out later tonight, show is coming on afk a bit
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> tempfiles dont even show u for me
<FromGitter> <Blacksmoke16> ah, they were getting deleted towards the bottom
<FromGitter> <Blacksmoke16> if i dont delete the temp files yea i see
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9bdd89b50f63935951199]
<FromGitter> <Blacksmoke16> @alexherbo2
<alex``> it’s bad to have delete at the end?
<alex``> I would like to have them on top and ensure they run on EXIT
<FromGitter> <Blacksmoke16> well i mean i was trying to see if data was written to the files and they were getting deleted
<FromGitter> <Blacksmoke16> so i obs could see if they had anything in them
laaron- has joined #crystal-lang
<alex``> shards can install binaries to user ~/.local/bin or other?
laaron has quit [Ping timeout: 256 seconds]
<alex``> currently I do; make install with -> mkdir ~/.local/bin; ln -s "$PWD/bin/batch" ~/.local/bin
<FromGitter> <Blacksmoke16> why not just do shards build
<FromGitter> <Blacksmoke16> then it pops out in `bin/` in your project dir
<alex``> I do that but wanted to install for user
<FromGitter> <watzon> You'd have to use make or something for that
<FromGitter> <Blacksmoke16> when they install it?
<FromGitter> <watzon> I'm hoping shards will support actually installing in the future
<FromGitter> <watzon> Like rubygems
<FromGitter> <Blacksmoke16> im pretty sure they do
<FromGitter> <Blacksmoke16> ```executables: ⏎ - athena``` [https://gitter.im/crystal-lang/crystal?at=5cf9c088bf4cbd167c42cc0e]
<FromGitter> <Blacksmoke16> ```targets: ⏎ athena: ⏎ main: src/athena.cr``` [https://gitter.im/crystal-lang/crystal?at=5cf9c091b76eac527ab6a24c]
<FromGitter> <Blacksmoke16> should add `athena` to your bin on install
<FromGitter> <watzon> That just creates the binary and puts it in the `bin` directory
<FromGitter> <Blacksmoke16> right
<FromGitter> <watzon> I think he wants to actually install the binary
<FromGitter> <Blacksmoke16> ooooo
<FromGitter> <Blacksmoke16> like to their system
<FromGitter> <watzon> Like put it in /usr/local/bin
<FromGitter> <Blacksmoke16> gotcha
<FromGitter> <Blacksmoke16> might be able to add a postinstall script to do it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9c0c665392c3b60d18aca]
<FromGitter> <Blacksmoke16> is what i do to generate the config file on install
<FromGitter> <watzon> Hopefully shards will be able to do that in the future, but yeah, for now you need a script
<FromGitter> <watzon> Make can handle it as well
<FromGitter> <Blacksmoke16> ye
<FromGitter> <tenebrousedge> make D:
<alex``> Blacksmoke yep ^^
<FromGitter> <Blacksmoke16> or really just add the binary to your github release and they can just download it and put it where they want w/o having to use crystal
<alex``> I need to add scripts/{rename,convert,relink} to be really useful
<FromGitter> <watzon> @Blacksmoke16 that's also a good way to do it, provided there isn't a reason they'd have to build on their system
<FromGitter> <watzon> I think the only reason for that would be if they need access to the crystal compiler or something
<FromGitter> <Blacksmoke16> would also have to provided binaries for various architectures
<FromGitter> <watzon> Like with `icr` and `scry`
<alex``> Blacksmoke16 what do you think of batch?
<FromGitter> <Blacksmoke16> might want to write some tests/docs
<alex``> I don’t know how test work in Crystal
<alex``> wow thanks
<FromGitter> <Blacksmoke16> np
<FromGitter> <watzon> Testing in Crystal isn't bad
<FromGitter> <watzon> Testing API wrappers is a pain in the ass
<FromGitter> <Blacksmoke16> TIL `actual.should be <= expected`
<FromGitter> <watzon> But otherwise...
<FromGitter> <Blacksmoke16> that works
<FromGitter> <Blacksmoke16> i always been doing like `(actual <= expected).should be_true`
laaron- has quit [Remote host closed the connection]
<FromGitter> <watzon> Interesting
<FromGitter> <Blacksmoke16> testing api wrappers?
<FromGitter> <Blacksmoke16> just mock out a response and assert correct stuff happens?
laaron has joined #crystal-lang
<FromGitter> <watzon> Well yeah, it's just a pain. Webmock and V8 make things easier though.
laaron has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> fair
<FromGitter> <watzon> Reddit's API is going to make for a massive pain in the ass
<FromGitter> <watzon> Deserializing wise
<FromGitter> <Blacksmoke16> doesnt look too bad
<FromGitter> <Blacksmoke16> parent type with `kind` property, then each child implements the `data` property
<FromGitter> <watzon> So have a Thing class and each model that falls into that category extend the Thing class?
<FromGitter> <watzon> I guess this is really what I should've linked to https://github.com/reddit-archive/reddit/wiki/JSON#thing-reddit-base-class
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> and just implements `data`
<FromGitter> <Blacksmoke16> ofc would prob have to have various other types that may or may not be able to be reused
<FromGitter> <Blacksmoke16> as each level of nesting would need its own type
<FromGitter> <Blacksmoke16> records would be helpful for this
<alex``> what is the equivalent of shell trap "cmd" EXIT?
<alex``> I want to clean tempfile when exiting
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/toplevel.html#at_exit(&handler:Int32,Exception?-%3E):Nil-class-method
<alex``> thanks again
<FromGitter> <Blacksmoke16> Np, imma get to bed o/
<FromGitter> <sam0x17> what is the syntax again to statically check if we are on linux vs osx?
<FromGitter> <sam0x17> found it: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf9cd3f3dcdab40030205dc]
<FromGitter> <sam0x17> thx
DTZUZO has quit [Ping timeout: 248 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
chemist69 has quit [Ping timeout: 248 seconds]
chemist69 has joined #crystal-lang
<alex``> do you use 'unless' with block?
<FromGitter> <tenebrousedge> you can execute a block conditionally using `unless` if you really want to, I guess?
<alex``> don’t know if it’s just me but I prefer `if not` than `unless` when using a block
<alex``> and unless as ternary
<alex``> I found unless as block confusing
<alex``> especially with en 'else'
<alex``> tenebrousedge you prefer 'unless' or 'if !'?
<FromGitter> <tenebrousedge> I probably prefer `if` with an `else`, but otherwise `unless`
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <watzon> @tenebrousedge that's actually a rubocop thing
<FromGitter> <watzon> Ameba as well
<FromGitter> <tenebrousedge> @watzon my opinion may be shared by bbatsov, but I promise I came by it honestly. Did you mean to respond to alex though?
<FromGitter> <watzon> Nope, just letting you know that your preference is actually a standard
<FromGitter> <watzon> so 👍
<FromGitter> <tenebrousedge> well, I do get the impression that you're probably a step ahead of me with regards to Crystal, but I'd like to think that I have the Ruby standard library and rubocop rules memorized. I'm not sure whether I would feel happier if that were or weren't true, though
<FromGitter> <watzon> Well I should say that the standard is this: use if/else or unless whenever you want, however avoid unless/else.
alex`` has quit [Ping timeout: 272 seconds]
<FromGitter> <bararchy> unless else is the devil
<FromGitter> <tenebrousedge> I think I actually tried to use it in a Crystal program recently, but it didn't work, and that was probably a good thing
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <pynixwang> https://goby-lang.org/
<FromGitter> <pynixwang> this toy
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZO has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron- has joined #crystal-lang
<Groogy> Hello! O/
chemist69 has quit [Ping timeout: 258 seconds]
ashirase has quit [Ping timeout: 268 seconds]
ashirase has joined #crystal-lang
<FromGitter> <mistergibson> Hello
alex`` has joined #crystal-lang
bougyman_ is now known as bougyman
alex`` has quit [Ping timeout: 245 seconds]
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Client Quit]
laaron has joined #crystal-lang
alex`` has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
alex`` has quit [Ping timeout: 272 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<mps> straight-shoota: j8r: have you seen my msg last night => build of 0.29.0 failed in 'abuild check', with this http://tpaste.us/P0D1
bcardiff has joined #crystal-lang
bcardiff has quit [Client Quit]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <mwlang> I don't do unless / else, either. Would rather do if / else and just flip contents of the blocks around. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ when you use unless in a block, you're separating the logic from the action and that's what's making it challenging to follow the flow. [https://gitter.im/crystal-lang/crystal?at=5cfa6c27cea82952790b0e40]
<FromGitter> <tenebrousedge> 👍
<FromGitter> <tenebrousedge> I'm not sure I realized the subject was conditionals *within* a block. Those are usually best avoided altogether
<FromGitter> <j8r> yes mps
<FromGitter> <mwlang> @Blacksmoke16 > should just have to do ServerResponse wrapped in back ticks -- then it doesn't link automatically if I just do `ServerResponse`
<FromGitter> <Blacksmoke16> are you referencing it within a different namespace?
<FromGitter> <Blacksmoke16> if so yea, would have to provide the full "path"
<FromGitter> <mwlang> I would say, "yes"
<FromGitter> <mwlang> I mean, it's the README
<FromGitter> <Blacksmoke16> oh
<FromGitter> <mwlang> what's it's namespace? :-p
<FromGitter> <Blacksmoke16> then just do like `ServerResponse (https://apidocs.com/path/to/that/file)`?
<FromGitter> <mwlang> I was gonna say, we needed something like the link syntax to get at it.
<FromGitter> <Blacksmoke16> the readme isnt built by the doc engine so yea
<FromGitter> <mwlang> ```ServerResponse (Binance::Responses::ServerResponse)``` for example.
<FromGitter> <mwlang> then how does referencing with ```Binance::Responses::ServerResponse``` link?
<FromGitter> <Blacksmoke16> oh, when viewed from your api docs?
<FromGitter> <Blacksmoke16> prob since it considers it top level namespace
<FromGitter> <Blacksmoke16> so is trying to find a ServerResponse there, but doesnt
<FromGitter> <mwlang> hmmm...haven't tried it from github view...so maybe it doesn't link there, either.
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <mwlang> oh, well. I just be long-winded for now to get it done and move on.
<FromGitter> <j8r> mps I think it's due to a default cipher change in OpenSSL
<FromGitter> <mwlang> one thing I'm curious about...where to host the generated docs.
<FromGitter> <Blacksmoke16> github pages works well enough
<FromGitter> <Blacksmoke16> https://blacksmoke16.github.io/crylog/
<mps> j8r: ah, yes. I forgot this.
<FromGitter> <j8r> You know?
<mps> I read somewhere about change
<FromGitter> <j8r> I create an issue. On your side, it's fair to mark it as pending
<FromGitter> <j8r> or fix the spec
<mps> or announce that it will be changed, not sure what
<mps> would you mind to send me patch for spec, I'm busy making kernel for arm32 for rc2 release of Alpine, and some other tasks
<FromGitter> <Blacksmoke16> @mwlang can pretty easily setup to update the docs when stuff is merged into master via travis
<FromGitter> <mwlang> good idea. is it easy to set up?
<FromGitter> <Blacksmoke16> yes ;p
<FromGitter> <mwlang> ok, I'll google travis approach...haven't used travis in a fair number of years....I think a lot's changed in the interim.
<FromGitter> <j8r> mps ok, I send you in your mail from patchwork
<FromGitter> <Blacksmoke16> go to project settings, first tab
<FromGitter> <Blacksmoke16> just create a branch called `gh-pages`
<FromGitter> <Blacksmoke16> then setup a deploy in `.travis.yml`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cfa6f64f3a60a79a46d34b7]
<FromGitter> <Blacksmoke16> are some options you can configure how you want
<mps> j8r: nice, many thanks
laaron- has joined #crystal-lang
laaron has quit [Remote host closed the connection]
duane has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <PlayLights_twitter> Hello, im a novice on this but, why crystal bycrypt can't validate a 2b hash and when I replace 2b to 2a, it works?
<FromGitter> <tenebrousedge> use the playground to give us some example code
duane has quit [Quit: leaving]
<FromGitter> <PlayLights_twitter> sure
duane has joined #crystal-lang
<mps> j8r: nothing yet in my mailbox?
<mps> do you have it on github
duane has quit [Client Quit]
duane has joined #crystal-lang
duane has quit [Client Quit]
duane has joined #crystal-lang
<alex``> do you use spec/spec_helper.cr in simple projects?
<alex``> it has been generated by `crystal init` but I'm tempted to remove it
<FromGitter> <Blacksmoke16> at the minimum it should just require spec and your main file
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> ```require "spec" ⏎ require "../src/myApp"``` [https://gitter.im/crystal-lang/crystal?at=5cfa7f3782c2dc79a568ac71]
<alex``> it's a bad practice if I remove that file and put the require in src/my_app_spec.cr?
<FromGitter> <Blacksmoke16> id say yes
<FromGitter> <Blacksmoke16> would make it harder to expand on in the future
<FromGitter> <Blacksmoke16> vs requiring the spec helper in your tests
<alex``> for example, how I can put a context for my tests?
<alex``> initialize data for each one
<FromGitter> <Blacksmoke16> like a global thing or on a per `it` block basis?
<alex``> in my program also I removed the `module Name`, to have a `def main`, don’t know if I should have keep it
<alex``> Blacksmoke16 I want to have an initial 'input', so I have data filled
<FromGitter> <Blacksmoke16> but you dont need the `main` method
<FromGitter> <Blacksmoke16> ```# do some setup ⏎ ⏎ # your main code``` [https://gitter.im/crystal-lang/crystal?at=5cfa8057cea82952790bb1b6]
<FromGitter> <Blacksmoke16> im not saying it wouldnt be a bad idea to break up code into a class/struct tho
<alex``> module Hello
<alex``> puts "hello"
<alex``> end
<alex``> the program will print "hello" like that??
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/71nk
<alex``> it is called when sourcing?
<alex``> class Hello
<alex``> puts foo
<alex``> end
<FromGitter> <Blacksmoke16> use three backticks for code blocks please
<alex``> def foo
<alex``> puts "bar"
<alex``> end
<alex``> I'm on irc sorry
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/71nm
<alex``> I don’t understand how it's possible xD
<FromGitter> <Blacksmoke16> when you run a file code is run top to bottom, so stuff you require first runs first, plus whatever code should execute that that require has
<FromGitter> <Blacksmoke16> so like
<alex``> why foo is successfully called but not defined yet?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cfa818965392c3b60d6e092]
<alex``> in ruby t.rb:1:in `<main>': undefined local variable or method `foo' for main:Object (NameError)
<FromGitter> <Blacksmoke16> maybe someone else can confirm this, but as far as i know compiler has a pass earlier on to identify/type everything so that when it runs it know about it
<FromGitter> <Blacksmoke16> thats my understanding at least
<alex``> make sense but surprise me
<FromGitter> <Blacksmoke16> since its a compiler lang, vs ruby when is just executing it line by line
<alex``> in a program, what is the benefits of using `Module Name; {code-here}; end` instead of directly `{code-here}`?
<FromGitter> <Blacksmoke16> namespacing
<alex``> which editor are you using Blacksmoke16 btw?
<FromGitter> <Blacksmoke16> so you avoid name conflicts with other libs/crystal itself
<FromGitter> <Blacksmoke16> for example
<FromGitter> <kinxer> Another example: ⏎ ⏎ ```module PlayerStats ⏎ class Int``` [https://gitter.im/crystal-lang/crystal?at=5cfa82e69b50f639359aab02]
<FromGitter> <Blacksmoke16> ☝️ June 3, 2019 3:44 PM (https://gitter.im/crystal-lang/crystal?at=5cf5789acea8295279e8be34)
<alex``> in https://github.com/alexherbo2/batch/blob/master/src/batch.cr, struct, would go inside the module?
<FromGitter> <kinxer> BlackSmoke's example is better. :P
<FromGitter> <Blacksmoke16> sublime
<FromGitter> <Blacksmoke16> with crystal plugin
<alex``> and remove the main function to put the body of main directly in the module?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> but might be better to take a more OOP approach than just one big block of code
<FromGitter> <Blacksmoke16> like could you split any of this out into objects?
<FromGitter> <Blacksmoke16> which would also make testing easier as you could test each piece of code on its own
<alex``> I’ll try to improve my Crystal-fu
<alex``> yeah I realized that
<alex``> I’ll start by removing the main function
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <PlayLights_twitter> hey is there any reason why HTTP::Server::Response is write only? I need to read it to write the response body on the log :(
<FromGitter> <Blacksmoke16> cant you just call `gets_to_end` on it?
<alex``> I don’t see in https://crystal-lang.org/reference/guides/testing.html how to store data, like setup / teardown for each test
<FromGitter> <PlayLights_twitter> I got an 'Cant read from HTTP::Server::Response' im trying to modify the class directly
<alex``> the right way to do is to add a method `get_data` in spec/spec_helper.cr and call them for each test?
<FromGitter> <Blacksmoke16> it `it` block should be not dependent on any other `it` blocks
<FromGitter> <Blacksmoke16> there is https://crystal-lang.org/api/master/Spec.html#before_each%28%26block%29-class-method
<FromGitter> <Blacksmoke16> but it runs globally and isn't scoped to a specific `describe` block
<FromGitter> <Blacksmoke16> but yea, a common way to doing it is to define something in your helper class that you can use in each spec
<FromGitter> <Blacksmoke16> i can get you an example if you want
<FromGitter> <Blacksmoke16> @PlayLights_twitter could maybe set the output IO of the response to a multiwriter and then writes to the response body would also be written to the other IO?
<mps> j8r: patch arrived, thanks
<FromGitter> <r00ster91> When iterating through something and I want to know whether this iteration is the last one, are there better ways to find that out than ⏎ ⏎ ```array.each_with_index(1) do |value, index| ⏎ index == array.size ⏎ end``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5cfa860465392c3b60d70326]
<FromGitter> <j8r> mps 👌
<FromGitter> <PlayLights_twitter> @Blacksmoke16 yeah I ended up doing that, im was messing with too many variants of IO
<FromGitter> <Blacksmoke16> 👍
<alex``> Blacksmoke16 yeah I would like a good practise to using data / test
<FromGitter> <Blacksmoke16> then within my specs you can do `create_message(message: "Some message")`
<FromGitter> <Blacksmoke16> to override specific values, or just do `create_message` to get the defaults
<alex``> thx!
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> @r00ster91 not as far as i know
<FromGitter> <tenebrousedge> @r00ster91 why not just deal with that element separately?
<FromGitter> <r00ster91> @Blacksmoke16 I think I will go with the `array.each_with_index(1) do |value, index|` variant. I thought it's slower but it isn't actually ⏎ @tenebrousedge why dealing with it separately? I'm building a string with all the array elements so I'm iterating through the array and when I would want to do that seperately, outside of the loop then I would still have to check if it's the last element
<FromGitter> <Blacksmoke16> im assuming so you dont want to add like a `,` to the last one?
<FromGitter> <r00ster91> yep
<FromGitter> <Blacksmoke16> i mean could just add a like `.chomp(',')`
<FromGitter> <r00ster91> oh and because I want to use an "and" for the last element
<FromGitter> <r00ster91> 1, 2, 3 and 4
<FromGitter> <Blacksmoke16> ah, fair enough
<FromGitter> <Blacksmoke16> `1, 2, 3, and 4` 😉
<FromGitter> <tenebrousedge> arr[1..-2].join(", ") + "and #{arr.last}"
<FromGitter> <bew> similar, but without creating intermediate array `arr.each.first(arr.size - 1).join(", ") + " and #{arr.last}"`
<FromGitter> <PlayLights_twitter> Hey, please some help, Why is this code invalid? `puts {success: true}.to_json` returns "Syntax error in eval:1: expecting token 'CONST', not 'true'"
<FromGitter> <bew> try adding parenthesis for puts
<FromGitter> <tenebrousedge> @bew are you entirely sure that `first` doesn't create an intermediate array?
<FromGitter> <bew> yes
<FromGitter> <bew> with `arr.each` I make an iterator, then doing `first` on it will just give me the first N elements when I want to iterate on it (in `join`)
<FromGitter> <PlayLights_twitter> Interesing `Error in line 1: undefined method 'to_json' for NamedTuple(success: Bool)`
<FromGitter> <bew> @PlayLights_twitter `require "json"`
<FromGitter> <PlayLights_twitter> Is that similar to this?
<FromGitter> <PlayLights_twitter> `env.body_response = {success: true}.to_json`
<FromGitter> <PlayLights_twitter> Compiler says this is an invalid code `Syntax error in eval:1: expecting token 'CONST', not 'true'`
<FromGitter> <PlayLights_twitter> but here I can't use parenthesis
<FromGitter> <bew> huh that's weird
<FromGitter> <bew> this syntax works for me.. https://carc.in/#/r/71ny
<FromGitter> <bew> can you show moar code?
<FromGitter> <PlayLights_twitter> I see the problem
<FromGitter> <PlayLights_twitter> the error was not on that line the compiler thinks, it was when I was calling the macro that generates that line
<FromGitter> <PlayLights_twitter> n_n, thanks @bew
<FromGitter> <tenebrousedge> oh, `each.first`, yeah that makes more sense
<FromGitter> <bew> @PlayLights_twitter (╯°□°)╯︵ ┻━┻ :P
<FromGitter> <bew> :p
laaron- has quit [Remote host closed the connection]
t1|Mike has quit [Ping timeout: 258 seconds]
laaron has joined #crystal-lang
t1|Mike has joined #crystal-lang
<alex``> there is shorcuts simalary to &.method?
<alex``> but doing method(mapped_object)
<FromGitter> <Blacksmoke16> not sure i follow
<alex``> ["a","b","c"].map(&.shell_escape), I defined shell_escape in String, but might be a bad idea
<alex``> shell_escape(string) is better no?
<alex``> to avoid conflicts in Crystal
<alex``> arguments = arguments.map(&.shell_escape).join(" ")
<alex``> arguments = arguments.map { |argument| shell_escape(argument) }.join(" ") is a bit verbose
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/71o3 like this?
<alex``> what is that lol
<FromGitter> <Blacksmoke16> runs each item of the array to the method
<FromGitter> <Blacksmoke16> is the same as doing like ` ["a","b","c"].map { |i| shell_escape i }`
<alex``> which one you would use you in that context?
<alex``> you have a doc on the syntax you showed me?
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<alex``> Blacksmoke16 what is the data would have been [["a"], ["b"], ["c"]]
<FromGitter> <Blacksmoke16> prob just use the normal version
<alex``> it's not possible with the &-> no?
<FromGitter> <Blacksmoke16> prob not
<alex``> you prefer which one in the case of shell_escape?
<FromGitter> <Blacksmoke16> doesnt really matter tbh
<FromGitter> <Blacksmoke16> whichever one you find more readable
alex``` has joined #crystal-lang
alex`` has quit [Ping timeout: 248 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<mps> j8r: I'm building 0.29.0 on both arches and preparing to push it to repo. Do you mind to put you in commit message in relation to patch you posted
alex``` has quit [Ping timeout: 272 seconds]
alex``` has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <watzon> Porting a C program to Crystal
<FromGitter> <watzon> God save me
<FromGitter> <Blacksmoke16> why not just link the C program and *not* do that :p
<FromGitter> <watzon> I might lol. Word2Vec is very large and pretty complicated.
<FromGitter> <watzon> I just want to simplify things for the end user
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> TIL crystal book has a dark theme
<FromGitter> <watzon> That it does haha
relyks has joined #crystal-lang
relyks has quit [Read error: Connection reset by peer]
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cfad44365392c3b60d937f3]
<FromGitter> <nsuchy> how do I go about fixing the requires
<FromGitter> <Blacksmoke16> uhh
<FromGitter> <Blacksmoke16> i feel like there is more to the error than is shown here
<FromGitter> <nsuchy> oh
<FromGitter> <nsuchy> there's much more
<FromGitter> <Blacksmoke16> the last few lines has the actual error
<FromGitter> <Blacksmoke16> not the first
<FromGitter> <nsuchy> oh
<FromGitter> <nsuchy> I thought the test suite was broken
<FromGitter> <nsuchy> 😂
duane has quit [Ping timeout: 248 seconds]
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
alex``` has quit [Ping timeout: 246 seconds]
laaron has joined #crystal-lang
alex``` has joined #crystal-lang
<FromGitter> <watzon> Matrix and Vector classes would be nice to have in the standard library
<FromGitter> <nsuchy> Any ideas https://gitlab.lunorian.is/snippets/192
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <nsuchy> based on everything I've read and tried so far im a bit suck
<FromGitter> <j8r> @watzon how does it simplify things by rewriting a program instead of bindings + wrapper?
<FromGitter> <watzon> No external dependencies to compile
<FromGitter> <watzon> simplifies things for the developer using the library, definitely not for me
<FromGitter> <j8r> Vector is Array?
<FromGitter> <j8r> And C Array is StaticArray
<FromGitter> <watzon> SImilar
<FromGitter> <tenebrousedge> but most people don't need them, so a separate class makes sense
<FromGitter> <watzon> Exactly
<mps> j8r: 0.29.0 is built on Alpine, for 3.10 and edge
<FromGitter> <watzon> Vector is meant to represent a vector used in Linear Algebra
<FromGitter> <watzon> Same with Matrix
<FromGitter> <tenebrousedge> Ruby has a Matrix module https://ruby-doc.org/stdlib-2.5.1/libdoc/matrix/rdoc/Matrix.html
<FromGitter> <tenebrousedge> so it would make sense for Crystal to have this as well
<FromGitter> <watzon> I've written my own Vector and Matrix classes, but having them in the stdlib or having a nice numpy type library would be nice
<FromGitter> <watzon> @tenebrousedge Idk about that argument, Crystal != Ruby
<FromGitter> <watzon> But it would be nice
<FromGitter> <j8r> mps: nice, good job! On my side, i opened https://github.com/crystal-lang/crystal
<mps> I put your nick in commit message
<mps> thought to put full name but wasn't sure will you agree
<FromGitter> <tenebrousedge> Crystal != Ruby, but Crystal is derivative of Ruby, and many things that make sense for Ruby also make sense for Crystal. And vice versa, but the Rubyists seem to have a knee-jerk attitude against adopting any Crystalisms
<FromGitter> <j8r> Really? That was a one line patch, I don't mind
<FromGitter> <j8r> :)
<FromGitter> <tenebrousedge> Crystal is more open to good ideas, no matter their source
<FromGitter> <watzon> True, just saying the core devs don't really accept "A is in Ruby so Crystal should also have A" as an argument
<mps> anyway, you helped a lot to have crystal in alpine and you deserve credits
<FromGitter> <j8r> I guess, thanks mps 😅
<mps> and straight-shoota (between others) of course, to not forget
<FromGitter> <j8r> How did you do it so fast?
<mps> hmm, I thought I'm slow :)
<mps> I started last night with building with different options and test to see what will be 'best' for now
<mps> tests take time