<FromGitter>
<Timbus> Yeah, looks like crystal apps freak out if their stdin is closed: β `perl -e 'if (!fork){close STDIN; exec("crystal")}'`
<FromGitter>
<Timbus> guess i'll check github for issue
<FromGitter>
<talbergs> https://carc.in/#/r/4h5w I magined to push to module array, but it not compiles. :(
<jokke>
Hello o/
<jokke>
i'm trying to set up a tls socket in crystal and for some reason it isn't able to negotiate a cipher with a client. The exact same settings on ruby work.
<FromGitter>
<Timbus> otherwise the context setup looks the same I guess, except we can't see the ciphers you're passing in the ruby example. Can assume it's the same as the crystal though
<FromGitter>
<Timbus> I couldn't reproduce the error, because I copied your code nearly exactly and setup my own certs
<FromGitter>
<Timbus> turns out I get the error when my certificates are faulty, or missing
<FromGitter>
<Timbus> Try making a new self-signed certificate jokke. `openssl req -newkey rsa:2048 -nodes -keyout pkey.pem -x509 -days 365 -out cert.pem`. then use the generated pkey.pem and cert.pem as the private_key and certificate_chain. It should work (at least it does for me)
<FromGitter>
<umutuluer> hi guys
alex`` has joined #crystal-lang
<jokke>
hm
<jokke>
hey uamutuluer
<jokke>
*umutuluer
<jokke>
any ideas why this throws: Unhandled exception: No address found for foo.bar.baz:5000?
<FromGitter>
<Timbus> Yeah, really seems like a DNS issue. Like at this point maybe it's a system library issue
<jokke>
god damn
<FromGitter>
<Timbus> I assume a TCPSocket also fails?
<jokke>
yeah
<jokke>
from /opt/crystal/crystal-0.25.0-1/share/crystal/src/socket/tcp_socket.cr:112:33 in 'initialize'
<FromGitter>
<Timbus> mmh. So I guess, somehow, your libc isn't able to resolve the address. Really strange but it can happen if you're using docker or even a different libc linux like alpine
Raimondi has quit [Remote host closed the connection]
<FromGitter>
<bararchy> if it's the only offender we can just copy it from FileUtils to Dir
<RX14>
and some cp magic
<RX14>
no
<RX14>
why are you so intent on removing it right away>
<RX14>
it needs to go bit it'll take time
<RX14>
after we get Path merged
<FromGitter>
<bararchy> oh, i'm not in any "hatred rage" against it XD it just seemed that it's a buig class of aliases and maybe flew under the radar
<FromGitter>
<bararchy> just wanted to point it out
<RX14>
no i've tried to remove it before and come up against issues
<FromGitter>
<bararchy> btw, how hard is it to make `.dig` for Hash?
<jokke>
hey
<jokke>
same problem still
<jokke>
i'm wondering why SSL3_GET_CLIENT_HELLO is being called even though i've disabled SSLv3
<FromGitter>
<bararchy> jokke I think it's just OpenSSL's way of saying "protocol negotiation in process"
<jokke>
mmh
<FromGitter>
<bararchy> Does it return a "No shared cipher" error?
<FromGitter>
<bararchy> Also even when disabling the SSL3 protocol the system is still `aware` of it, so it will accept a connection and say "I don't support you"
tilpner has joined #crystal-lang
<FromGitter>
<Timbus> The only way I got that error was with a missing certificate: β Unhandled exception: Failed create ssl_socket : SSL_accept: error:1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher (Exception)
<FromGitter>
<Timbus> had nothing to do with the cipher
<FromGitter>
<aisrael> Is there a way to, like, import a static function into the "top level" namespace (ideally limited to this specific file only, but if global then can maybe work with that)? E.g., like in Java `import static java.lang.Math.sqrt;` then you can just go `sqrt(x)` anywhere? β β Will including a `module` outside of a class/module work?
<RX14>
you can define functions at the top-level which are just aliases
<FromGitter>
<Timbus> Funny. I've been working on an implementation of lexical scoped imports in crystal..
<RX14>
why?
<RX14>
imports don't really make sense in crystal
<FromGitter>
<aisrael> Yeah so I just tried it (sorry, was lazy earlier) and yes, `include`ing a `module` in the "global" namespace makes the module functions available at top level
<FromGitter>
<aisrael> But once you do that, it's global, not just file-scoped (so, global namespace pollution is a problem)
<RX14>
yes exactly
<RX14>
include is not the right way to do imports
<RX14>
why are you desperate to use these class methods without a reciever?
<RX14>
just type a bit more it's not a big deal
<RX14>
if it's deeply nested, just use an alias
<FromGitter>
<Timbus> Ah, the reason I wan lexical imports is for UFCS
<FromGitter>
<aisrael> I mean, even Javascript has `import { foo } from "foo";` so...
<FromGitter>
<Timbus> scoped to a file/block
<RX14>
but UFCS doesnt make sense in crystal
<FromGitter>
<aisrael> Yeah, exactly
<RX14>
and JS has... imports
<RX14>
crystal has a global namespace
<RX14>
they're not compatible
<FromGitter>
<Timbus> My plan for UFCS was that receiver methods take the invocant as the first argument
<RX14>
but why
<RX14>
thjats the implementation, whats the reason?
<FromGitter>
<Timbus> So you can implement helper methods, such as your own Int.hours
<FromGitter>
<Timbus> and library makers don't have to monkey patch
<FromGitter>
<Timbus> seems.. pretty straightforward? or so I thought
<RX14>
well i'm not sure how that'd be implemented at all without compiler modifications
<FromGitter>
<Timbus> that's what i said
<FromGitter>
<Timbus> im doing right now
<RX14>
but that PR won't be accepted
<FromGitter>
<Timbus> guess ill call it crystal++ :p
<RX14>
you can't just PR UFCS to crystal without even discussing it first and expect it to be accepted
<RX14>
there's been discussions about UFCS before though
<RX14>
and the answer was no
<FromGitter>
<Timbus> id prefer to at least prove out the concept, im not expecting to just .. do that
<FromGitter>
<Timbus> i saw discussions without considering it in context of an import
<RX14>
but the technical feasability of UFCS is not the issue
<FromGitter>
<Timbus> ufcs doesn't work without imports. imports arent very useful without ufcs
<RX14>
so you're not creating crystal any more
<RX14>
you're... forking it
<FromGitter>
<Timbus> i also saw requests for 'function piping', and 'ruby refinements' which this would also mostly cover
<FromGitter>
<Timbus> im just trying stuff dude, i think if it works and I can prove it out to be simple and useful, its then worth considering?
<RX14>
I just don't want to see you waste your time
<RX14>
UFCS is a major major change to the language
<RX14>
it's far too late
<RX14>
neither UFCS or imports will be merged, as long as you understand that then you can experiment for fun as much as you want
Heaven31415 has joined #crystal-lang
<Heaven31415>
Hi
<Heaven31415>
Is there a way in Crystal to convert string into type object at runtime? Like foo("Int32") => Int32
<RX14>
I don't think so
<RX14>
why?
<Heaven31415>
I'm reading some files and wanted to create objects of specified type based on content of the file
<FromGitter>
<cserb> Still looking for a simple way in crystal to transmit data between peers (like in a p2p env) similar to gRPC
<FromGitter>
<cserb> Anyone with experience?
<FromGitter>
<aisrael> @Heaven31415 The closest is a `Hash(String, Class)`
<FromGitter>
<yxhuvud> I'd probably use a case statement.
alex`` has quit [Ping timeout: 260 seconds]
<FromGitter>
<umutuluer> Hi again
alex`` has joined #crystal-lang
<FromGitter>
<bararchy> hi @umutuluer
<FromGitter>
<umutuluer> i try to use array sort method
<FromGitter>
<umutuluer> but array is not normal array that has string or int
<FromGitter>
<umutuluer> it has class
<FromGitter>
<umutuluer> [] of MyClass
<FromGitter>
<umutuluer> i want to sort as my_class_instance.price
<FromGitter>
<j8r> you want to sort depending of a value in the Class?
<FromGitter>
<umutuluer> i run the code in play.crystal-lang.org
<FromGitter>
<umutuluer> error message is : Error in line 62: undefined method 'sort_by ' for Array(Order) (did you mean 'sort_by'?) β β Rerun with --error-trace to show a complete error trace.
<FromGitter>
<bararchy> btw if you dont initialize and just use the `Order` as a container maybe use a struct instead of class
<FromGitter>
<umutuluer> yes, you are right @bararchy
<FromGitter>
<umutuluer> i forgot define as new variable
<FromGitter>
<asterite> Jarrod Funnell: I like UFCS and I like imports over require. If it can solve monkey patching, I wouldn't mind a discussion about it and a PR
<FromGitter>
<umutuluer> thanks
<FromGitter>
<umutuluer> im gonna use struct, i guess only pass variable not reference
<FromGitter>
<bararchy> @asterite oh, no! let's not :\ Crystal is Crystal, let's not force the lang to be something it isn't meant to be
<FromGitter>
<asterite> He said he had a way to make it work, why not experiment with that? Wouldn't you like to import some functions into a file without having them affect the global namespace? I think it's a nice thing.
<FromGitter>
<asterite> Like, import "number/humanize" only when needed. Or those time methods like 1.second and so on
<FromGitter>
<bararchy> because you can already have those using β β ```require "http/client" β ``` β β and only get client, and it won't pollute the global namespace because you get all functionality undr Client [https://gitter.im/crystal-lang/crystal?at=5b44ae9e3572e970c1855f66]
<FromGitter>
<umutuluer> @bararchy thanks it is clear
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter>
<umutuluer> but why do you use **args in initialize
<FromGitter>
<umutuluer> i dont understand this
<FromGitter>
<j8r> If he wants to only import one Class from a file, this means it hasn't well organized its project in multiple files
<FromGitter>
<bararchy> @j8r < true
<FromGitter>
<bararchy> @umutuluer I was about to add all the param set in the initialize method instead of using properity, but just wanted to show the point of using struct and initialize `Time` inside the initialize method
<FromGitter>
<umutuluer> okey, so do i use Order.new(user_id = 5) ?
<FromGitter>
<umutuluer> it looks great, i will check
<FromGitter>
<umutuluer> thanks @bararchy
duane has joined #crystal-lang
<FromGitter>
<asterite> bararchy: if you do `require "http/client"`in any flie in your project, you can use `HTTP::Client` in any other file in your project without having to do `require "http/client"`in those files. That's what global pollution means, and it's bad because it's not clear where that `HTTP::Client` came from in the first place (in the files that don't require them)
Philpax has quit [Read error: Connection reset by peer]
<FromGitter>
<bararchy> Oh, I like it TBH. β It's much better then to have the `require` part all around your code. β I just put everything that comes from outside (shards, std) in the main file, and if I need something internal I put it in the head of the file that needs it
greenbigfrog has quit [Ping timeout: 256 seconds]
greenbigfrog has joined #crystal-lang
<FromGitter>
<j8r> but thus means a file is a namespace like in python? No way to have this. β But instead we could have a `require "http/client"` inside a module
<FromGitter>
<j8r> You can have `MyModule::HTTP::Client`
Heaven31415_ has joined #crystal-lang
<FromGitter>
<umutuluer> why puts command is not working in spec?
<FromGitter>
<umutuluer> for example in golang we can do printing operation
Heaven31415 has quit [Ping timeout: 264 seconds]
<FromGitter>
<j8r> puts == STDOUT.print "\n"
<FromGitter>
<j8r> you have to modify the IO
<FromGitter>
<bararchy> @umutuluer of curse its working, if your specs are too short then STDOUT.flush
<FromGitter>
<j8r> But what the use case of printing to stdout in spces?!
<FromGitter>
<umutuluer> only to show variable value
<FromGitter>
<umutuluer> because im using fake data in tests
<FromGitter>
<umutuluer> sometimes i need
<FromGitter>
<umutuluer> fake data is dynamic, always i use wrong method in fake library
<FromGitter>
<opensas_gitlab> hi everyone, I was wondering if there's any dependency injection framework for crystal. I googled around a little bit but couldn't find anything like that. Or is there some reason why it just doesn't make sense to use a DI framework with crystal???
<FromGitter>
<drum445> Cheers guys, yeah I had to parse the to_json as JSON
moei has joined #crystal-lang
zachk has joined #crystal-lang
zachk has quit [Changing host]
zachk has joined #crystal-lang
<FromGitter>
<asterite> opensas there's no way to do dependency injection in Crystal because: you can't have a variable of type object (yet), and there's no runtime reflection (probably never going to happen)
<RX14>
@asterite what's the main reason we don't have variables of type Reference?
duane has quit [Ping timeout: 260 seconds]
<FromGitter>
<asterite> I didn't implement it. Plus it's a huge union type, not sure how it will affect compile times. But I can try to experiment with it and see if it works.
<FromGitter>
<asterite> I'm any case, dependency injection requires runtime reflection, so that's not possible to implement
<RX14>
i'm sure you could be a tad creative with macros and get something pretty close
<RX14>
autogenerating a constructor in the class which took a DI container and asked it for the args of new could be good enough
<RX14>
and probably not too bad of a macro
<Yxhuvud>
dependency injection a la spring perhaps require that, but it is a way bigger concept than that. write a method that take as an argument something that it applies to something else? Well congrats, you are probably doing dependency injection
wontruefree has quit [Ping timeout: 260 seconds]
wontruefree has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> Is it possible, or desired, to type restrict instance variables since we currently have to assign it to a local variable for the compiler to restrict them?
zachk has left #crystal-lang ["Leaving"]
<RX14>
no, the reason why class vars can't be restricted is for thread safety
<RX14>
another thread can change the type of the instance variable between the type check and the use
<RX14>
thats why you have to copy it when you type check - to make sure it's a local var and can't be changed out from under you
<FromGitter>
<Daniel-Worrall> That makes sense, so the type restrictions are happening in the variable objects themselves. I could see it being possible if we redesigned it so we could allow a reference of the object with type restriction assigned for that block/code flow
<FromGitter>
<Daniel-Worrall> Is there a nice tool to debug uncompilable code?
<FromGitter>
<Daniel-Worrall> or debug the compiler itself
duane has joined #crystal-lang
duane has quit [Ping timeout: 265 seconds]
<FromGitter>
<bew> @rishavs what you do is super slow, for example instead of doing `rows = rows + [row]` you can do `rows << row`
<FromGitter>
<rishavs> thanks @bew
pbodev1 has quit [Quit: ChatZilla 0.9.93 [Firefox 56.0/20170903140023]]
<crystal-gh>
[crystal] j8r opened pull request #6362: Remove `ditto` and `nodoc` without colons (master...ditto_nodoc_only_with_colons) https://git.io/fNTKe
<FromGitter>
<Timbus> @asterite Thanks! I just woke up. I'll write up a simple proposal some time soon.. it's a very simple, non-breaking mechanism.. But I want to implement some of it first, to prove it works outside of my head
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter>
<j8r> Sometimes in the code we can see `ary = ary = [] of ...` - reference to @asterite ? π
rohitpaulk has joined #crystal-lang
hightower2 has quit [Ping timeout: 255 seconds]
<FromGitter>
<drum445> Is there anything in the standard lib that allows you to transform a SQL result set into an object or result of object? β Also something that allows you to inject the object's attributes into a SQL query without having to do it manually. I'm making a library for it but would be interested to see if something similar already exists
<FromGitter>
<drum445> Not bad, I quite like how dapper works in asp.net. I might try and make a similar library, but I will keep that idea in mind cheers @Blacksmoke16 . β I'll post my probably tragic attempt at a library here tomorrow ;)
<FromGitter>
<Blacksmoke16> or could use an ORM
<FromGitter>
<Blacksmoke16> then could just do like you know, `person.save`
<FromGitter>
<asterite> There's DB.mapping right in Crystal-db, though it's not complete. Then there are some ORMs out there
<FromGitter>
<asterite> No, you want just {{name.stringify}}
<FromGitter>
<Blacksmoke16> <3
<FromGitter>
<asterite> Think about the code that the macro generates. Your way is outputting name, age, and that will call the properties
<FromGitter>
<Blacksmoke16> thanks
<FromGitter>
<drum445> any orm libray suggestions?
<FromGitter>
<Blacksmoke16> Granite ;)
<robacarp>
whoop
<FromGitter>
<drum445> any lightweight ones like dapper?
<FromGitter>
<Blacksmoke16> define lightweight
<FromGitter>
<Blacksmoke16> crystal-db would be pretty light weight id say
<FromGitter>
<drum445> Something that removes the needs to manually map column to object field
<FromGitter>
<drum445> same thing on inserts/updates
<FromGitter>
<drum445> having to do rs.read(String) on huge selects isn't fun
rohitpaulk has joined #crystal-lang
<crystal-gh>
[crystal] straight-shoota opened pull request #6363: Enable Time::Location features on win32 (master...jm/fix/time-enable-win) https://git.io/fNTyi
<FromGitter>
<asterite> I don't think something like dapper exists
<FromGitter>
<jwoertink> You can look through the code to compare the ORMs to see which setup you like best. Granite is currently the fastest consistently, though, I had a really hard time setting it up because the docs weren't up to date. Clear has been the easiest to get up and running, and still has great speed. ALL of the ORMs lack some feature in one way or another
<FromGitter>
<jwoertink> Clear and Lucky only support postgres, so if you're using something else, then those are out already.
<FromGitter>
<jwoertink> Crecto and Core are also really nice if you want to use a different pattern for your ORM.
<FromGitter>
<jwoertink> Hope that helps give some insight