ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.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> @bcardiff can probably drop the `-1` from the end as well iirc?
<FromGitter> <Blacksmoke16> er nvm
ur5us has quit [Ping timeout: 252 seconds]
ur5us has joined #crystal-lang
alexherbo22 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo22 has quit [Ping timeout: 240 seconds]
<FromGitter> <christopherzimmerman> Anyone had any luck getting Crystal 0.32.0 from homebrew? I don't think its been updated there yet.
<FromGitter> <Blacksmoke16> The pr was opened a few hours ago
return0e has quit [Ping timeout: 250 seconds]
return0e has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 265 seconds]
<FromGitter> <anamba> hmm. i thought i solved my own problem the other day (explicitly forcing HTTP::Client to use IPv4 or IPv6 by using the appropriate kind of IP as the host and setting the Host header manually, but I failed to account for SNI. maybe the answer is to set the `remote_address` property on the HTTP::Request manually before executing it
<FromGitter> <anamba> ok, now i can't figure out how to execute the HTTP::Request 😆
<FromGitter> <Blacksmoke16> Should be some class method on http client
<FromGitter> <anamba> you would think
<FromGitter> <anamba> aha... there it is. there is a Client#exec
<FromGitter> <anamba> found it in the api docs as well. don't know how i missed that
<FromGitter> <anamba> https://crystal-lang.org/api/0.32.0/HTTP/Client.html#exec(request:HTTP::Request):HTTP::Client::Response-instance-method
<FromGitter> <watzon> I'm curious, what are you making @anamba?
<FromGitter> <anamba> nuts. i'm not sure `HTTP::Request#remote_address=(addr)` is working
<FromGitter> <anamba> nothing much, just a small part of a larger suite of tools that detect configuration issues on client websites
<FromGitter> <anamba> in this case, i'm looking for websites that have AAAA records but are not actually reachable via IPv6
<FromGitter> <anamba> which we wouldn't notice because our home and office ISPs don't offer IPv6 service :(
<FromGitter> <watzon> Hmm very interesting
<FromGitter> <anamba> oh, whoops
<FromGitter> <anamba> ``` # This property is not used by `HTTP::Client`. ⏎ property remote_address : String?``` [https://gitter.im/crystal-lang/crystal?at=5df1abd27d382b523f60d58d]
<FromGitter> <anamba> back to square one
<FromGitter> <anamba> next strategy is monkey patching `HTTP::Client#socket`
<FromGitter> <anamba> bingo
<FromGitter> <anamba> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5df1ae6f55d9392300f65f09]
<FromGitter> <anamba> bonus: used the new built-in `String#presence`
ur5us has quit [Ping timeout: 250 seconds]
ur5us has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 250 seconds]
knifehits is now known as teardown
ur5us has quit [Ping timeout: 250 seconds]
alexherbo22 has joined #crystal-lang
ht_ has joined #crystal-lang
<FromGitter> <vlazar> > On a different note... What do you call a Crystal programmer? `Crystaller`? ⏎ ⏎ A `Crystal head`! :D (any Breaking Bad fans out there?)
alexherbo22 is now known as alexherbo2
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter> <stergiom> ```code paste, see link``` ⏎ ⏎ ..this works fine in version `0.31.1`, but not with 0.32.0`, should it? [https://gitter.im/crystal-lang/crystal?at=5df1e485578ecf4b1f8c1d10]
DTZUZO has quit [Ping timeout: 268 seconds]
ht_ has quit [Quit: ht_]
yukai has quit [Ping timeout: 276 seconds]
flaviodesousa has joined #crystal-lang
ur5us has joined #crystal-lang
MasterdonX has quit [Ping timeout: 268 seconds]
MasterdonX has joined #crystal-lang
ur5us has quit [Ping timeout: 250 seconds]
DTZUZO has joined #crystal-lang
<repo> anamba you already got pt 2 figured out, eh? :)
<repo> i'm really struggling today, but no spoilers. i want to figure it out myself :)
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 246 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 276 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 265 seconds]
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> @stergiom whats the issue?
<FromGitter> <Blacksmoke16> ah, i think the issue is modules dont include class methods so the `from_json` constructor doesnt get included...
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
duane has joined #crystal-lang
flaviodesousa has quit [Quit: KVIrc 4.9.3 Aria http://www.kvirc.net/]
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
<FromGitter> <bew> @Blacksmoke16 here @asterite would say "another reason to remove extends and unify it with include" :D
<FromGitter> <Blacksmoke16> indeed :p
ht_ has joined #crystal-lang
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
alexherbo21 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 268 seconds]
alexherbo21 has quit [Quit: The Lounge - https://thelounge.chat]
DTZUZO has joined #crystal-lang
<FromGitter> <j8r> the `not_nil!` approach to avoid exception is quite clever
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <j8r> A given method returns `Success(T) | Error`
<FromGitter> <j8r> instead of `T` and otherwise raising an exception
<FromGitter> <j8r> Then, if we don't want do handle the types, we can use `noerr!`
<FromGitter> <watzon> I agree that extends and include should be unified if possible
<FromGitter> <tenebrousedge> why?
<FromGitter> <j8r> which returns `Success(T)#noerr!` returns `self`, and `Error#noerr!` raises :)
<FromGitter> <j8r> this gives the choice to the user
<FromGitter> <alehander92> but the user now has to guess that your method might raise
<FromGitter> <j8r> no?
<FromGitter> <j8r> the methods return an union
<FromGitter> <j8r> if the user don't want to handle the types itself (with case/when), then it can simply call `#noerr!`, which raises on `Error`.
<FromGitter> <Blacksmoke16> why not just handle errors with exceptions?
<FromGitter> <j8r> because more expensive
<FromGitter> <j8r> and this approach is simple
<FromGitter> <Blacksmoke16> depends on what you're doing i guess, id argue exceptions are simpler
<FromGitter> <watzon> Where is this coming from? A shard I haven't heard of?
<FromGitter> <j8r> here it's just calling a method more, really not more complex
<FromGitter> <j8r> and this prevent having to rescue and re-raising the exception, which is not really good
<FromGitter> <Blacksmoke16> the problem is if you use this method in other stuff that uses exceptions that no longer works anymore
<FromGitter> <Blacksmoke16> depends on context tho
<FromGitter> <j8r> why?
<FromGitter> <j8r> Here this union is the result of a JSON API response
<FromGitter> <alehander92> yeah, its a good translation from Result to exception, sorry
<FromGitter> <j8r> and the result of raising without giving choice vs having to call `#noerr!` is the same at the end
<FromGitter> <Souravgoswami> Hi, how can I use the C's .crypt() method as in Ruby ?
<FromGitter> <Souravgoswami> `String#crypt()` in Ruby
<FromGitter> <j8r> For instance, the API can return a 404, but it's not a big deal :)
<FromGitter> <j8r> why do you want to use it @Souravgoswami ?
<FromGitter> <j8r> There is an `scrypt` shard
<FromGitter> <j8r> If you really want: ⏎ ⏎ ```@[Link("crypt")] ⏎ lib LibC ⏎ fun crypt(Char*, Char*) : Char* ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5df28f59e47fb31eb79ee886]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
ur5us has joined #crystal-lang
<FromGitter> <kinxer> Is it normal for math libraries to have `.log` be the natural logarithm? I would've expected it to be log base 10, with `.ln` as the natural logarithm.
<FromGitter> <tenebrousedge> is it oriented towards some specific type of math?
<FromGitter> <kinxer> https://crystal-lang.org/api/0.31.1/Math.html#log(value:Float64)-instance-method
<FromGitter> <kinxer> https://carc.in/#/r/86ze
<FromGitter> <kinxer> Looks like `Math.log(Number)` is the natural logarithm.
<FromGitter> <tenebrousedge> they have `log10` too
<FromGitter> <tenebrousedge> looks like we're copying Ruby https://ruby-doc.org/core-2.3.0/Math.html#method-c-log
<FromGitter> <tenebrousedge> I didn't realize Ruby did that
<FromGitter> <kinxer> Yeah. I'll admit that my math schooling wasn't extensive, but every time I encountered logarithms, the notation either had explicit bases or treated "log" as the log base 10 (or explicitly stated the base in the text).
* FromGitter * tenebrousedge shrugs ¯\\_(ツ)_/¯
<FromGitter> <kinxer> Wikipedia lists `log(x)` as a notation used sometimes for each of base 10, base *e*, and base 2.
<FromGitter> <kinxer> -_-
<FromGitter> <kinxer> The documentation for `::Math` could use some loving attention.
<FromGitter> <kinxer> I'd like to do that myself, but I'd have to look up most of the methods in Ruby or Fortran library docs, and I don't have time for that right now.
<FromGitter> <tenebrousedge> I am still pondering the wisdom of attaching an `owner_id` to all my models. Pros: simplifies permissions code dramatically, which otherwise would involve traversing various optional and polymorphic relations to find a (guaranteed to exist) `owner_id`. Cons: duplicates this information lots
<FromGitter> <kinxer> Are you more constricted in runtime or memory?
<FromGitter> <tenebrousedge> constricted in dev time, and writing complicated joins is hard
<FromGitter> <kinxer> So probably attaching the `owner_id` to everything is the way to go for now? How difficult of a refactor would that be in the future to change it?
<FromGitter> <tenebrousedge> Probably: drop the column, write the complicated query. There's probably no danger this field would be exposed to the user
Yxhuvud has joined #crystal-lang
duane has quit [Read error: Connection reset by peer]
<FromGitter> <stergiom> ```code paste, see link``` ⏎ ⏎ ..considering that ^this works in `0.32.0`, I expected the mixin variant to do the same. ⏎ ⏎ @Blacksmoke16 it breaks with `Error: undefined method 'new_from_json_pull_parser' for SomeEntity.class` ... [https://gitter.im/crystal-lang/crystal?at=5df2b7bb2bca3016aa6c6f94]
<FromGitter> <Blacksmoke16> > ..considering that ^this works in `0.32.0`, I expected the mixin variant to do the same. ⏎ ⏎ They work differently
<FromGitter> <Blacksmoke16> in this case the method is inherited from the parent
<FromGitter> <stergiom> yup, I see that now, I went by both working in `0.31.1`
<FromGitter> <Blacksmoke16> while `include` doesn't include class methods, which is what the constructor is
<FromGitter> <christopherzimmerman> Is there a way to have a class inherit from another class, and then disallow some of the methods of the base class from being called?
<FromGitter> <christopherzimmerman> I know I can override them and raise explicitly, but I am wondering if there is a better way.
<FromGitter> <Blacksmoke16> would have to use some macros
<FromGitter> <Blacksmoke16> PHP handles this by using private methods, as they arent inherited
<FromGitter> <Blacksmoke16> but in crystal they are so rip
<FromGitter> <Blacksmoke16> i think id rather they were not
<FromGitter> <Blacksmoke16> would give purpose to protected methods as currently they arent much different than private
<FromGitter> <christopherzimmerman> I can think of a macro that would redefine the method and raise an exception, I think I'd prefer to have it be a compile time thing.
<FromGitter> <Blacksmoke16> yea that would be the way to do it
<FromGitter> <Blacksmoke16> using an inherited hook
<FromGitter> <christopherzimmerman> Maybe I need to just redesign my inheritance a bit and take off the methods on another base class :P
<FromGitter> <christopherzimmerman> Might be an XY problem altogether.
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <Blacksmoke16> could be a mixin
<FromGitter> <Blacksmoke16> if only some types need it
<FromGitter> <j8r> or use composition
<FromGitter> <j8r> anyway, you can look at hooks https://crystal-lang.org/reference/syntax_and_semantics/macros/hooks.html
<FromGitter> <j8r> there is `method_added`
<FromGitter> <j8r> I struggle to find how using `HTTP::Client` with IOs. I would like to send a json body to a server without creating an intermediary `String`
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/HTTP/Client.html#post(url:String%7CURI,headers:HTTP::Headers?=nil,body:BodyType=nil,tls=nil):HTTP::Client::Response-class-method
<FromGitter> <Blacksmoke16> body is of type https://crystal-lang.org/api/master/HTTP/Client/BodyType.html
<FromGitter> <j8r> Not the body response
<FromGitter> <j8r> But the body to send
<FromGitter> <Blacksmoke16> right
<FromGitter> <Blacksmoke16> where does the JSON body come from?
<FromGitter> <j8r> from an in-memory object
<FromGitter> <j8r> like `Hash(String, String).to_json`
<FromGitter> <Blacksmoke16> ```io = IO::Memory.new ⏎ obj.to_json io ⏎ HTTP::Client.post("/", body: io)``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5df2c6277ce7ea1e35737b53]
<FromGitter> <j8r> hum yeah...
<FromGitter> <j8r> Not sure there will have a gain
<FromGitter> <Blacksmoke16> :shrug:
duane has joined #crystal-lang
yukai has joined #crystal-lang
<FromGitter> <j8r> I think it's not possible with the current API
<FromGitter> <j8r> to stream the data to send
<FromGitter> <j8r> without using an intermediary IO or String
return0e_ has quit [Read error: Connection reset by peer]
Xeago_ has joined #crystal-lang
Xeago has quit [Read error: Connection reset by peer]
Xeago_ is now known as Xeago
coderobe is now known as Guest49709
coderobe6 has joined #crystal-lang
return0e has joined #crystal-lang
MasterdonX has quit [Quit: ZNC 1.7.4 - https://znc.in]
Guest49709 has quit [Ping timeout: 268 seconds]
MasterdonX has joined #crystal-lang
coderobe67 has joined #crystal-lang
<FromGitter> <j8r> if a `String` or `Bytes` is passed to the body, an `IO::Memory` is created, then copied to the socket
coderobe67 has quit [Client Quit]
coderobe67 has joined #crystal-lang
coderobe6 has quit [Ping timeout: 265 seconds]
coderobe672 has joined #crystal-lang
coderobe672 has quit [Client Quit]
duane has quit [Ping timeout: 265 seconds]
coderobe67 has quit [Ping timeout: 240 seconds]
ht_ has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 250 seconds]