RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | 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
<watzon> Is it possible to do this with `HTTP::Client#post`? https://github.com/excon/excon#streaming-responses
<watzon> I know you can get a stream if you use a block, but is it possible to get a chunk, remaining bytes, and total bytes?
vivus has left #crystal-lang ["Leaving"]
<FromGitter> <jwaldrip> I wish HTTP::Handlers were not linked lists... why wouldn't an approach like this work?
<FromGitter> <jwaldrip> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a877b6d8f1c77ef3a171742]
salvor has quit [Changing host]
salvor has joined #crystal-lang
<FromGitter> <jwaldrip> A) It’s much easier to dup and array of pointers than it is each handler when it is reused. B) handlers could be stricter
<FromGitter> <jwaldrip> Structs*
<Guest28202> make a proposal :)
Guest28202 is now known as RX14
<FromGitter> <petertseng> hmm. suggestion on how to avoid repeating myself when I do something like `h1 = Hash(String, Hash(String, Int32)).new { |h, k| h[k] = Hash(String, Int32).new(0) }` ? ⏎ ⏎ Perhaps this is a possibility? ⏎ ⏎ ```alias H = Hash(String, Int32) ⏎ h2 = Hash(String, H).new { |h, k| h[k] = H.new(0) }``` ... [https://gitter.im/crystal-lang/crystal?at=5a87807cc3c5f8b90dc5e63e]
jradd has quit [Ping timeout: 260 seconds]
jradd has joined #crystal-lang
<watzon> we need something like this for crystal https://mholt.github.io/json-to-go/
<Papierkorb> Build it? As opposed to Go you can even make use of union types to statically type different kind of structures
<watzon> Yeah I'm seeing if I can throw something together. I'm trying to wrap the docker api right now and it would be really helpful and save me a lot of time.
<Papierkorb> Fair point, doesn't Docker have something like a swagger spec?
<watzon> I've never used swagger so I couldn't really say
<Papierkorb> And I don't even know if there's already a swagger generator for Crystal ;)
jradd has quit [Ping timeout: 256 seconds]
ome has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
greengriminal has joined #crystal-lang
<watzon> Doesn't look like it
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
<FromGitter> <jaynagpaul> Is there a simple way to add together a url with query params in it and a Hash(String,String)? This seems to tell me that has_key? is undefined, and seems very unelegant to me. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a87bbcc6fba1a703a604144]
qard has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<watzon> @jaynagpaul I've just been doing this: `query = "?" + HTTP::Params.encode({ "key" => "value" })` and then concatenate that onto the URL. Really it would be nice if all of the `HTTP::Client` request methods allowed you to define query params.
<watzon> Or if URI allowed you to set query params with a Hash or NamedTuple
<FromGitter> <jaynagpaul> I tried to cover most edge cases as well, so this seemed to be the best solution: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a87c1700202dc012e45db30]
radagast_04 has quit [Ping timeout: 252 seconds]
baweaver is now known as baweaver_away
qard has quit [Quit: qard]
rohitpaulk has joined #crystal-lang
baweaver_away is now known as baweaver
rohitpaulk has quit [Ping timeout: 260 seconds]
* watzon sent a long message: watzon_2018-02-17_06:59:23.txt <https://matrix.org/_matrix/media/v1/download/matrix.org/ibXvpWdBGDXhaZNvOkAzWcdG>
<watzon> Obviously I'm not going to be able to conver 100% of cases, but this is going to at least get a lot of boilerplate stuff out of the way
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
alex`` has joined #crystal-lang
devil_tux has joined #crystal-lang
<devil_tux> howdy, quick q: as I'm aware XML::Node needs enumerable so I can .each element?
hightower3 has joined #crystal-lang
<hightower3> Is HTTP::Client#post_form no longer there? What should I replace it with?
<devil_tux> oh, children NodeSet
<hightower3> Oh I see, HTTP::Client.post( form: )
alex`` has quit [Quit: WeeChat 2.0.1]
<watzon> Those classes were generated from that JSON structure
rohitpaulk has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
maattdd has joined #crystal-lang
radagast_04 has joined #crystal-lang
radagast_04 has quit [Ping timeout: 240 seconds]
radagast_04 has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
maattdd_ has joined #crystal-lang
<watzon> Working on getting a site up for it now
<FromGitter> <straight-shoota> Why is this implemented in JS instead of Crystal?
alex`` has joined #crystal-lang
alex`` is now known as alexherbo2
alexherbo2 is now known as alex``
<FromGitter> <straight-shoota> This means you'll need to install a JS runtime just to be able to use this for Crystal development?
<watzon> The point isn't to use it in Crystal projects
<watzon> It's based off of this idea https://mholt.github.io/json-to-go/
ome has quit [Quit: Connection closed for inactivity]
<FromGitter> <straight-shoota> what would you use the generated Crystal code for, if not a Crystal project??
alex`` has quit [Ping timeout: 240 seconds]
maattdd_ has quit [Ping timeout: 255 seconds]
<watzon> The point is to generate crystal classes with JSON mappings so that they can be copy-pasted into a project. It will help with wrapping large APIs like docker's
<watzon> Just generates boilerplate code
BlaXpirit has joined #crystal-lang
oprypin has quit [Remote host closed the connection]
BlaXpirit is now known as oprypin
baweaver has quit [Ping timeout: 240 seconds]
baweaver has joined #crystal-lang
baweaver is now known as Guest75431
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 256 seconds]
FromGitter has quit [*.net *.split]
FromGitter has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <sdogruyol> just found out that we don't have Singleton Methods https://play.crystal-lang.org/#/r/3lo6
<FromGitter> <sdogruyol> @bararchy it's because of JSON::Any change
<FromGitter> <straight-shoota> @watzon yes I understand the purpose, I just don't get why the boilerplate generator istself is not a Crystal tool as that would simplify the toolchain
<FromGitter> <sdogruyol> are you getting that error from kemal @bararchy ?
<FromGitter> <sdogruyol> if so use https://github.com/kemalcr/kemal/pull/435
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <r00ster91> how do I just generate 10 times a "puts"? ⏎ I tried ⏎ ⏎ ```{%for i in 10%} ⏎ puts "hello" ⏎ {%end%}``` [https://gitter.im/crystal-lang/crystal?at=5a882f07e4ff28713a8bad26]
<Yxhuvud> 10.times { puts }
<FromGitter> <r00ster91> you dont understand
<FromGitter> <r00ster91> i want to *generate* 10 times a puts
<FromGitter> <r00ster91> with macros
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 256 seconds]
<FromGitter> <j8r> ```{%for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] %} ⏎ puts "hello" ⏎ {%end%}``` ⏎ ⏎ I haven't find another way to do it. [https://gitter.im/crystal-lang/crystal?at=5a88354135dd17022eb72fbc]
<FromGitter> <j8r> Other topic linked: are immutable arrays planned?
<FromGitter> <r00ster91> man not even this is working ⏎ ⏎ ```{%for i in Array.new(10, 0)%}``` [https://gitter.im/crystal-lang/crystal?at=5a88366835dd17022eb736bb]
<FromGitter> <j8r> yes, because macros are specials - no object orientation, so no dots.
<FromGitter> <j8r> but the `[0..9]` syntax may be implemented - normal arrays are
<FromGitter> <r00ster91> oh man there really should be an easier way to generate 10 times puts
<FromGitter> <j8r> like python, a `for i in range(10)` ?
<FromGitter> <j8r> BTW this is quite surprising to generate exacly the same thing `n` times with a macro, are you sure the `10.times { puts }` can't fill your needs?
<FromGitter> <r00ster91> i dont really have a "need". I just want to know how to generate this with macros
maattdd has quit [Ping timeout: 248 seconds]
<FromGitter> <j8r> very ofter the array is filled with strings(or whatever), this way you have a macro boilerplate that will be used for each string in the array
<FromGitter> <r00ster91> but this isnt really efficient. its a dumb way. there should be something else
<FromGitter> <j8r> a macro is used to avoid boilerplate
<FromGitter> <j8r> To generate classes, defs, variables that's share a same structure. Here, that's exactly the same, so the macro is not really useful
<FromGitter> <j8r> I don't know how the compiler works, but maybe the `x.times` method is close of macros for performance
<FromGitter> <j8r> better said: `puts; puts; puts; puts` vs `4.time { puts }` may be close
maattdd has joined #crystal-lang
alex`` has joined #crystal-lang
maattdd_ has joined #crystal-lang
devil_tux has quit [Ping timeout: 248 seconds]
alex`` has quit [Ping timeout: 252 seconds]
jradd has joined #crystal-lang
maattdd_ has quit [Ping timeout: 260 seconds]
alex`` has joined #crystal-lang
<FromGitter> <jwaldrip> How can I make an abstract method with a block signature?
<Papierkorb> add a fully typed &block argument
<Papierkorb> the implementations don't need to have that argument as long they `yield` like normal. They can have it of course.
<FromGitter> <jwaldrip> so this should work no?
<FromGitter> <jwaldrip> ```abstract def call(c : HTTP::Server::Context, &block : HTTP::Handler::Proc)```
<Papierkorb> looks okay on first sight
<FromGitter> <jwaldrip> as implemented: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a885516888332ee3a95d7ef]
<FromGitter> <jwaldrip> should work
<FromGitter> <jwaldrip> but doesnt
<Papierkorb> "Doesn't work" doesn't work as explanation.
<Papierkorb> s/explanation/description/
<FromGitter> <jwaldrip> one sec
<FromGitter> <jwaldrip> going to share more
<FromGitter> <jwaldrip> https://carc.in/#/r/3lok
<Papierkorb> https://carc.in/#/r/3lom minimal sample works as expected
<Papierkorb> https://carc.in/#/r/3loo As does when only knowing about the interface
TakeYourFreedom has joined #crystal-lang
greengriminal has joined #crystal-lang
TakeYourFreedom has quit [Quit: Leaving]
<FromGitter> <jwaldrip> Got it working, thanks!
<watzon> @straight-shoota I don't know how you mean. I wanted it to be a web based tool which is pretty much the only reason I used JS. Also the json-to-go project was done in JS, and I baed my project off of it so keeping it in JS made things a little simpler
alex`` has quit [Ping timeout: 240 seconds]
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 276 seconds]
<FromGitter> <jwaldrip> I got an alternative implementation of Handlers/Middleware working without linked lists!
<FromGitter> <jwaldrip> Do you think it would be valuable to propose a change into Crystal with this implementation?
<FromGitter> <sdogruyol> @jwaldrip sorry for not following, what's the purpose of this change?
jradd has quit [Quit: WeeChat 2.0.1]
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 256 seconds]
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 240 seconds]
<FromGitter> <jwaldrip> A handler is used in an http route, and sometimes contains configuration. In some router configurations, handlers may want to be reused with their configuration. Because each Handler today is a linked list. You would have to duplicate every handler to have it exist as part of a different list
<FromGitter> <jwaldrip> That is not the case in the implementation I just shared.
<FromGitter> <jwaldrip> There is no modification to each middleware to make it middleware, which means they can now also be structs in this implementation where they could not before.
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 276 seconds]
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 260 seconds]
maattdd_ has joined #crystal-lang
hightower2 has joined #crystal-lang
alex`` has joined #crystal-lang
maattdd_ has quit [Ping timeout: 252 seconds]
maattdd_ has joined #crystal-lang
maattdd_ has quit [Ping timeout: 260 seconds]
greengriminal has quit [Quit: Leaving]
<FromGitter> <Yive> is it not possible to create a hash which will have other hashes stored in it?
<Papierkorb> of course it's possible.
<FromGitter> <Yive> hmm I might not be doing it right then since `table = {} of String => Hash` errors out
maattdd_ has joined #crystal-lang
<Papierkorb> >> table = {} of String => Hash; p(table)
<DeBot> Papierkorb: can't use Hash(K, V) as generic type argument yet, use a more specific type - https://carc.in/#/r/3lp6
<Papierkorb> > use a more specific type
<Papierkorb> Do as the compiler tells you and you shall succeed.
<Papierkorb> Static languages aren't like dynamic languages in that you have to proof to the compiler that what you're about to do can be traced at compile.time and will work at run-time. That's the reason there's no "NoMethodError" at run-time.
<Papierkorb> compile-time *
maattdd_ has quit [Ping timeout: 276 seconds]
maattdd_ has joined #crystal-lang
vivus has joined #crystal-lang
styler1972 has joined #crystal-lang
maattdd_ has quit [Ping timeout: 264 seconds]
<styler1972> ha, thanks for the upvotes :)
<styler1972> awesome, thank you!
maattdd_ has joined #crystal-lang
<FromGitter> <sdogruyol> styler1972 ideally, it'd be suitable to use Nginx as reverse proxy for your Kemal application
<FromGitter> <sdogruyol> but you can also use Kemal with custom port and SSL
<styler1972> i'll end up getting to that eventually
<styler1972> so you run two instances of the webapp? one on 80 and one of 443?
<FromGitter> <sdogruyol> well like I said you better use Nginx for that and proxy both 80 and 443 ports to Kemal
<styler1972> i mean this works for now.. basically im just setting up a placeholder so i can configure gsuite.. i'll take your advice regarding nginx
Guest75431 is now known as baweaver
<Papierkorb> You should always use NGINX (or apache or so) over directly exposing the application servers. The benefits are too large, and the disvantages of not are too large too
baweaver has quit [Changing host]
baweaver has joined #crystal-lang
<FromGitter> <sdogruyol> ^
<Papierkorb> Except for local development, there's no reason to ever not use NGINX (or apache or ...)
<watzon> Ok guys, feast your eyes https://watzon.me/projects/json-to-crystal
<watzon> It's in beta, so please let me know of any issues you have
maattdd_ has quit [Ping timeout: 256 seconds]
<styler1972> chrome on mac, didnt convert anything
<FromGitter> <sdogruyol> @watzon interesting
<Papierkorb> > 480KiB of JS?
<Papierkorb> Letting go of horizontal cursor/movement keys makes the cursor jump to the beginning of the line, it also generates errors in the log
<Papierkorb> (using Firefox)
<watzon> Yeah it's meant to be more of a copy/paste thing. The large JS size is a temporary issue. Right now all of my JS is being bundled together for the whole site.
<Papierkorb> `{"a": [{ "bar": 1 },"Hi",4]}` tries to generate a class inside the Array(..) definition
<watzon> styler1972: what did you do? It's meant to convert input pasted with ctrl-v (or cmd-v), I'll add support for regular paste later hopefully
<watzon> Papierkorb: Crap. I'll check it out
<Papierkorb> Apart from that it's nice that it's already using union types
<watzon> Yeah that was one of the goals. It's nice to have unions in Crystal.
<styler1972> watzon: i just typed actually
<styler1972> copy/paste works like a charm
maattdd_ has joined #crystal-lang
styler1972 has quit [Quit: Page closed]
<FromGitter> <j8r> @watzon is it planned to have the equivalent in crystal?
maattdd_ has quit [Ping timeout: 240 seconds]
<watzon> @jr8 well I've already done most of the hard work which is figuring out how to do it. I don't see why I couldn't pretty easily make a Crystal version
<watzon> Do you have a use case in mind?
<FromGitter> <j8r> yeah! that's exactly what I need when handling different configurations from different softwares
<FromGitter> <j8r> I want to build a REST api to modify e.g. my configuration of Transmission torrent, Ghost blog etc
jnyw has joined #crystal-lang
robacarp has joined #crystal-lang
mooe has joined #crystal-lang
devil_tux has joined #crystal-lang
<devil_tux> so I just did an apt update of crystal compiler and for some reason it didn't append to bin path, so I symlinked in manually to bindir but now everytime I try to `shards build` some strange `execvp` error terminates the compiler process
<devil_tux> I'm on v0.24.1 running on RHEL
rohitpaulk has joined #crystal-lang
<devil_tux> I've switched `crystal` version in shards.yml but to no avail
<devil_tux> Here is the build output https://pastebin.com/raw/ARQGFtkT
<robacarp> does crystal have any libraries for terminal cursor manipulation?
<devil_tux> robacarp: isn't there an ncurses fork?
<robacarp> that feels a little heavy for what I'm after, I just want to be able to make a list of items in the terminal, similar to what fish-shell does for tab completion
<robacarp> curses is for writing to the whole window, right?
<devil_tux> robacarp: try TerminalTable
<devil_tux> from top of my head
<devil_tux> might be of use
<FromGitter> <robacarp> I looked at that too, and it might be, but I want to have the cursor jump between options printed in the table, so they can be selected and rearranged.
<FromGitter> <robacarp> maybe I should just use curses
<watzon> Curses may be a little heavy, but it does just about everything
<watzon> If you can find a c library that does what you want you can always wrap it
<watzon> Or just write your own by with stdout. That shouldn't be too difficult
<robacarp> I was headed in that direction, but searching stack overflow for information I found one post that said "use the stdlib in <language>" and I thought I should do a survey to find out what's out there
<robacarp> awesome_crystal has a bunch of things, but nothing that overtly does what I want
<devil_tux> tried initing a new project, still same error .. shall I write issue?
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
<FromGitter> <CaDs> Hello, this might be a silly question, but here goes nothing. Is there any documentation regarding how to build crystal itself? ⏎ I’m looking into this issue https://github.com/crystal-lang/crystal/issues/5672 and I was wondering how to test it in local
<Papierkorb> Run `make`.