RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
<FromGitter> <bew> Nice find, yeh it should be mandatory to inspect the pkgbuild of a package before executing it (when using aur helpers)
duane has joined #crystal-lang
<FromGitter> <drosehn> When talking about UFCS, have you been referring to: "Uniform Function Call Syntax" ? (just curious)
duane has quit [Ping timeout: 244 seconds]
duane has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter> <talbergs> @l1meon thank you ⏎ ⏎ > @talbergs https://carc.in/#/r/4h6p
akaiiro has quit [Ping timeout: 244 seconds]
<jokke> okay i've got a minimal example where things go wrong: https://p.jokke.space/vTakY9/
<jokke> this will reliably fail with SSL_accept: error:1417A0C1:SSL routines:tls_post_process_client_hello:no shared cipher (OpenSSL::SSL::Error)
<jokke> the selected cipher definately exists: openssl ciphers | grep :DHE-RSA-AES128-GCM-SHA256
<FromGitter> <Timbus> is DHE compatible with rsa keys? some need a different key
<FromGitter> <Timbus> oh im thinking of DH, not DHE
<FromGitter> <Timbus> .. that said, your code works if i use ECDHE-RSA instead. so that's something
<jokke> yeah
<jokke> but i can't use that
<FromGitter> <Timbus> :(
<jokke> the hw that's connecting _only_ supports DHE :/
<jokke> i think this is a bug in the lib :/
<jokke> since it works with ruby bindings
<jokke> i will open an issue
<FromGitter> <Timbus> hmmm. can you pinpoint it to a missing C library call that crystal should be doing?
<jokke> hm how could i do this?
<FromGitter> <Timbus> i guess it would involve reading the openssl crystal libs, which are mostly just passing through to the C library
<FromGitter> <Timbus> maybe when you use DHE ciphers you need to pass an additional parameter or something
akaiiro has joined #crystal-lang
<FromGitter> <Timbus> googling around tells me "dhparam" might be the missing piece. https://wiki.openssl.org/index.php/Diffie-Hellman_parameters . I'd look into it further, but I am at work
<jokke> thews: oh ok thanks
<jokke> sorry
<jokke> Timbus
alex`` has joined #crystal-lang
<FromGitter> <aisrael> Is it possible to define or alias a (generic) type of `DB::ResultSet -> T`? I.e. a `ResultSetMapper(T)`?
duane has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
lvmbdv has joined #crystal-lang
manveru has joined #crystal-lang
<mindcrimes> hi again is there a way to skip a value in a .each?
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
<Yxhuvud> mindcrimes: next
<mindcrimes> ah
<mindcrimes> is there a way to skip two or would I have to impliment that myself?
<mindcrimes> nvm found it
<mindcrimes> based skip
<mindcrimes> nope nvm that doesnt work
rohitpaulk has quit [Ping timeout: 276 seconds]
baweaver is now known as baweaver_away
<FromGitter> <Timbus> oh hey, I did it jokke
<FromGitter> <Timbus> i was right, DHE needs an option set. and the option is the dh params
<jokke> seriously?
<jokke> nice!!
<FromGitter> <Timbus> ill see if i can edit your example
<FromGitter> <Timbus> and give you a working.. thing
<jokke> that'd be awesome! thank's so much
<FromGitter> <Timbus> it should be added to the standard library though, so you were right
<jokke> ah ok so you monkey patched it?
<FromGitter> <Timbus> no, .. well i guess yes, but it's not so much a patch when it comes to lib interfaces
<jokke> yeah :P
<jokke> thanks!!
<FromGitter> <Timbus> let me know if it works. also make a gitlab issue, now that you have all the details
<FromGitter> <opensas_gitlab> > I'm any case, dependency injection requires runtime reflection, so that's not possible to implement
<FromGitter> <Timbus> ?
<FromGitter> <opensas_gitlab> Thanks a lot for your reply (I couldn't follow the conversation) What would be the more appropriate way to achieve DI (or something like that) in Crystal then? Or is it just something to be taken care of later in Crystal development.
<FromGitter> <drum445> After our conversation yesterday I had a go at a little sql result set to object library ⏎ https://github.com/drum445/objectify
<FromGitter> <drum445> Could you please have a look and let me know where it can be improved/what I have done wrong :)
lvmbdv has quit [Remote host closed the connection]
wojnar has joined #crystal-lang
<FromGitter> <Timbus> forgive my ignorance, but how is this different to the crystal-db mapping? http://crystal-lang.github.io/crystal-db/api/0.4.2/DB.html#mapping%28properties%2Cstrict%3Dtrue%29-macro
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
ashirase has quit [Ping timeout: 264 seconds]
ashirase has joined #crystal-lang
wojnar has quit [Remote host closed the connection]
<FromGitter> <drum445> Ha that from_rs Is what I was after cheers, do you know any way of adding a class as a param?
<FromGitter> <drum445> instead of having to manually map all the ?
<FromGitter> <Timbus> Do you mean like.. you want to make a normal class and have something generate a mapping? instead of using a mapping to generate a class?
<FromGitter> <drum445> So when you have an insert statement i want the vales to populate from a class
<FromGitter> <Timbus> ohh
<FromGitter> <drum445> Instead of having a load of question marks
<FromGitter> <Timbus> I don't think it currently exists. I guess you could so it with a macro
<FromGitter> <drum445> Cool that can be my lib then ;) Room for it after all
return0e_ has quit [Remote host closed the connection]
alex`` has quit [Ping timeout: 240 seconds]
Philpax has joined #crystal-lang
alex`` has joined #crystal-lang
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
lvmbdv has joined #crystal-lang
<FromGitter> <drum445> fairly happy with this :) ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b45ffa233b0282df4132895]
duane has joined #crystal-lang
<FromGitter> <asterite> I'm not sure why JSON is involved in what you are doing
<FromGitter> <drum445> I couldn't find a reflection package in crystal so I can call the attributes via varaible
return0e has joined #crystal-lang
<FromGitter> <asterite> Well, if JSON can do it, you can probably too :-) But yeah, it's not easy. There's compile-time reflection. You can define `sefl.to_sql(script : String, object : T) forall T` and then inside do something like `{% for ivar in T.instance_vars %}` using macros. But you'll have to learn a few things to manage to do it.
<FromGitter> <drum445> Does crystal not have a send method like ruby?
<FromGitter> <drum445> Not sure why we don't have a get attribute by name method
<FromGitter> <rishavs> How do I rescue an exception with a specific error message? I know, I can "rescue DB::Error" , but I can't ` rescue DB::Error:no rows`. Of course, I can just check for the message in an if-else block but was wondering if this is possible with Raise method itself
<FromGitter> <asterite> @drum445 no, there's no runtime reflection in crystal
<FromGitter> <asterite> @rishavs not possible
<FromGitter> <rishavs> ok. Thanks. I will just proceed with a string match in my rescue block
<oz> it looks like Packt pub is looking for authors to co-author a book about Crystal...
<FromGitter> <straight-shoota> @rishavs there is #1124 discussing this feature
<FromGitter> <drum445> Shame about runtime reflection, what alternative is on offer then?
<FromGitter> <rishavs> @straight-shoota Thanks 👍
<FromGitter> <straight-shoota> But if the kind of error message demands different behaviour, it is likely that you should rather have more specific exception types.
<FromGitter> <straight-shoota> @drum445 compile time reflection with macros 👍
<FromGitter> <drum445> Could you give me an exmaple please my good sir
<FromGitter> <drum445> all I want to do really is ⏎ https://play.crystal-lang.org/#/r/4htn
<FromGitter> <asterite> I might try to implement exception filters, at least a first approach. Later we could limit them to avoid introducing new local variables
<FromGitter> <jwoertink> @drum445 you could do this https://play.crystal-lang.org/#/r/4htt
<FromGitter> <jwoertink> it's not as pretty, and will probably cause more issues, but it works in that instance lol
<FromGitter> <jwoertink> 😂
<FromGitter> <fridgerator> Also ugly but works : https://carc.in/#/r/4htu
<FromGitter> <jwoertink> nice!
<FromGitter> <jwoertink> @drum445 ^^ a few options to play with
<FromGitter> <drum445> Cheers guys, was hoping that each class wouldn't need a fucntion though
<FromGitter> <drum445> oh you don't have to: https://play.crystal-lang.org/#/r/4hu2 ⏎ Thanks again chaps
<FromGitter> <drum445> sorry guys, why doesn't this work https://play.crystal-lang.org/#/r/4huq
<FromGitter> <jwoertink> on the `{{attr.id}}`, you don't want the `.id`
<FromGitter> <jwoertink> if you were passing a string literal like `t, "name", "Gary"`, then you'd use the `.id` to say "don't use the string, use what the string outputs to"
<FromGitter> <drum445> Doesn't work :(
<FromGitter> <jwoertink> or something like that. Not sure how to explain it
<FromGitter> <jwoertink> hmm, yeah, it's expanding to `attr`, and not `name` like you want
<FromGitter> <drum445> indeed, how odd
<FromGitter> <drum445> Any ideas how to expand name mate?
ua has quit [Quit: Leaving]
<FromGitter> <jwoertink> This is where it gets in to some tricky things. Currently it expands to the literal variable names. Since your variable is called `attr`, that's what the macro will expand to
<FromGitter> <jwoertink> oh, there you go!
<FromGitter> <j8r> Macros is about text
<FromGitter> <jwoertink> I guess you do need the .id
<FromGitter> <jwoertink> I really don't understand them, so I avoid using them if I can lol
<FromGitter> <j8r> If you write `"mystring"`, this will be exactly this text passed to the macro
<FromGitter> <j8r> if you only want the value that it represent, add an `.id`
<FromGitter> <drum445> I have an array of strings
<FromGitter> <drum445> and for each one I need to call that send method
<FromGitter> <drum445> but it can't
<FromGitter> <j8r> Macro are in compile time, they expands when you compile
<FromGitter> <j8r> so you can't set a variables when running a macro - every arguments are taken as text
<FromGitter> <j8r> @drum445 show me the code :)
<FromGitter> <asterite> @drum445 https://play.crystal-lang.org/#/r/4hv1
<FromGitter> <asterite> that's what you want
<FromGitter> <asterite> Or, well, this: https://play.crystal-lang.org/#/r/4hv2 (the `self.doit` is not necessary)
DTZUZO has joined #crystal-lang
<FromGitter> <adamgotterer_twitter> I'm having trouble figuring out what library I need to install on MacOS to be able to build a release. I'm getting the following error: ⏎ $ crystal build run.cr --release --static ⏎ ld: library not found for -lcrt0.o (this usually means you need to install the development package for libcrt0.o) ⏎ clang: error: linker command failed with exit code 1 (use -v to see invocation) ⏎ Error:
<FromGitter> ... execution of command failed with code: 1: `cc "${@}" -o '/Users/adamgotterer/sites/chromie/chromie/run' -rdynamic -static -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '- ... [https://gitter.im/crystal-lang/crystal?at=5b462ef6e534eb69a5dbc3ed]
ua has joined #crystal-lang
<FromGitter> <adamgotterer_twitter> I tried to find a development package for libcrt0.o but had no luck
<RX14> you can't do static builds on osx
<RX14> If you have to ask, then --static doesn't work for you
<RX14> go has mislead people to think that they 1) want and 2) can have static linking
Heaven31415 has joined #crystal-lang
<Heaven31415> Hi
<FromGitter> <j8r> https://github.com/crystal-lang/crystal/pull/6110 ready to merge :)?
<FromGitter> <asterite> shouldn't it error? It seems it just prints that info and lets you do it anyway
<RX14> I dislike that PR
<RX14> it's the totally wrong approach
<FromGitter> <j8r> It print an information because it seems some may statically link on macOS
<FromGitter> <straight-shoota> @j8r it prints this message whenever you are running the compiler with `--static` on MacOS. This is incorrect, because you can, for example, cross-compile to a target that supports static linking.
<FromGitter> <adamgotterer_twitter> Thanks @RX14
<FromGitter> <drum445> @asterite wonderful cheers mate
<FromGitter> <fridgerator> you could wrap the whole thing in a macro, but at some point Ary will yell at you for misusing macros ;)
<FromGitter> <fridgerator> https://carc.in/#/r/4hvc
<FromGitter> <j8r> The fix isn't perfect, but at least avoids us to answer this question again and again. More info is better than less
<FromGitter> <adamgotterer_twitter> What would also be helpful is just mentioning this on the Crystal Book build page - https://crystal-lang.org/docs/using_the_compiler/
<FromGitter> <j8r> 👍
rohitpaulk has joined #crystal-lang
Heaven31415 has quit [Quit: Leaving]
<RX14> I'd rather just note it on the docs page
<FromGitter> <drum445> Thanks for your help with macros, reckon this looks better now? https://github.com/drum445/objectify
<FromGitter> <drum445> seems to work as expected :)
baweaver_away is now known as baweaver
<FromGitter> <rishavs> Hi. I am trying to put my app on Heroku. WHat should go into the Procfile? I see some apps using `web: crystal run src/server.cr` but this isn't the command for the production mode, is it?
<FromGitter> <fridgerator> well you need to build it first with `crystal build file.cr --release`
<FromGitter> <fridgerator> then run the build exectuable `./file`
<FromGitter> <fridgerator> `crystal build src/server.cr --release && ./server` ?!?
<FromGitter> <rishavs> Thanks @fridgerator
<FromGitter> <fridgerator> I know amber has a heroku buildpack, you could probably look and see what is done there
<FromGitter> <rishavs> I actually used the buildpack that @bcardiff maintains. Was confused somewhat about the procfile though
<FromGitter> <rishavs> The few procfiles that I found via google didn't use release flag
akaiiro has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
spencer has joined #crystal-lang
Ven`` has joined #crystal-lang
spencer has left #crystal-lang [#crystal-lang]
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
wontruefree has joined #crystal-lang
<FromGitter> <drum445> is it bad practice to have an object where every param is ⏎ name : String? ⏎ age : Int64? ⏎ ⏎ so the question mark? [https://gitter.im/crystal-lang/crystal?at=5b4655db66c1e833a9de884f]
<FromGitter> <Daniel-Worrall> You'd have to manage calling them with knowledge that they could be nil
<FromGitter> <drum445> the issue is, I need to initialize a class object without any params then assign them afterwards
<FromGitter> <drum445> If I have an empty initialize method they all need to be nullable :(
<FromGitter> <drum445> Unless named params are available, but I can't get it to work: https://play.crystal-lang.org/#/r/4hvo
<FromGitter> <reiswindy> https://carc.in/#/r/4hvy
<FromGitter> <drum445> nice thanks
<FromGitter> <rishavs> I am having trouble deploying my app on heroku. M app is building properly without any issues. However, on deployment i getting the following error in my logs; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b465ab71c0f906b1448f0b0]
<FromGitter> <rishavs> is this likely a buildpack error?
_whitelogger has joined #crystal-lang
alex`` has quit [Ping timeout: 256 seconds]
alex`` has joined #crystal-lang
duane has quit [Ping timeout: 244 seconds]
lvmbdv has quit [Quit: Leaving.]
alex`` has quit [Ping timeout: 264 seconds]
alex`` has joined #crystal-lang
<FromGitter> <jspillers> is there a slicker way to go from NamedTuple to Hash(String, String) than this? https://play.crystal-lang.org/#/r/4hxu
<FromGitter> <bew> I don't think so, you can hide this under a method, but in the end it will be what you wrote
<FromGitter> <drum445> Is there anyway to initialize a class without having to call the initialize method, so I can then manually set the fields afterwards
<FromGitter> <jspillers> it would be cool if `#to_h` took key/value types so you could just do `named_tuple.to_h(String, String)` and have it automatically cast
<FromGitter> <bew> @jspillers it's not just a cast, it has to do a method call to get the string version of each symbols
<FromGitter> <jspillers> right
<FromGitter> <bew> Well you can always implement it yourself
<FromGitter> <drum445> I'm very much struggling to turn a SQL result set into an object or array of object without having to set all my class attributes to Foo | Nil
<FromGitter> <j8r> Try to avoid Nil unions as much as possible
<FromGitter> <j8r> Catch them early, and raise when they occurs (or something else)
<FromGitter> <drum445> I don't think this is possible due to language constraints then
<FromGitter> <drum445> well not constraints just design
<FromGitter> <drum445> shame
<FromGitter> <bew> @drum445 it depends on your usecase, really: is it ok if some fields are missing? If not then you have an error, and you should handle it too
<FromGitter> <j8r> I think you are designing like in a dynamic language rather than a static one
<FromGitter> <drum445> This is what I'm working on: https://github.com/drum445/objectify ⏎ IF you look at the part "Result set to object", see they all need to be nil union, I don't want that but can't see away around it with my current lib
<FromGitter> <drum445> @j8r I'm trying to mimic what dapper does in .net core
<FromGitter> <j8r> You can also set the String to an empty one, or the Int64 to 0
<FromGitter> <drum445> I can't as it's not being initialized in a standard way
<FromGitter> <drum445> I need an empty version of that class then I work on assigning attributes
<FromGitter> <j8r> Like `property mystring = ""` ?
<FromGitter> <j8r> You can have an empty initialize method
alex`` has quit [Ping timeout: 260 seconds]
<FromGitter> <drum445> Indeed, I've been doing this ⏎ ⏎ ``` def initialize ⏎ @id = "" ⏎ @personID = "" ⏎ @name = "" ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b4678e6866e0c6b159e2d5c]
<FromGitter> <drum445> but it seems a mess to have to give every field a default
<FromGitter> <bew> You could also define an initialize method that initializes all the fields at once, and your code will just get all the values, and create the object at the end with all the gathered fields
<FromGitter> <drum445> I did try something like that, but it doesn't work with how I'm initializing the object
<FromGitter> <drum445> I won't know what fields I have until it runs
<FromGitter> <j8r> https://carc.in/#/r/4hxz
<FromGitter> <drum445> yeah something like that, don't think I can get around having to give everything defaults
alex`` has joined #crystal-lang
<FromGitter> <j8r> All the atributes are dynamic (known at runtime)?
<FromGitter> <drum445> Yeha it comes from a sql result set
<FromGitter> <drum445> so it may only contain some of the attr
<FromGitter> <j8r> So you have no other choice, you have to deal with dynamic structures like Hash, Array
<FromGitter> <j8r> And String of course
<FromGitter> <drum445> from_json seems to achieve what I want though
alex`` has quit [Read error: Connection reset by peer]
<FromGitter> <j8r> from_json ?
<FromGitter> <drum445> yeah if you have a class with JSON.mapping you can initialize it from a json string
<FromGitter> <drum445> which can only contain some of the fields, and you don't need an initialize method
<FromGitter> <j8r> Yes, this means not all fields are dynamic after all
<FromGitter> <bew> @drum445 note that JSON.mapping will generate a initialize method
<FromGitter> <drum445> oh yeah, do you reckon it simply creates one with all the defaults?
<FromGitter> <drum445> but, some of them are nil. I don't get it lol
<FromGitter> <bew> Which defaults are you talking about ?
<FromGitter> <drum445> defaults for all object types
<FromGitter> <drum445> string, int, float etc...
<FromGitter> <drum445> Because of how Crystal deals with nil where it becomes a union type it makes it a lot different to other languages like .net or go
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <j8r> For go nil is error, no? You can also raise on nil
<FromGitter> <drum445> ah well, fighting a losing battle I think. Either my Crystal skills have peaked or I'm trying to use it in a way it wasn't intended ⏎ Seems a real shame not to be able to convert a SQL result set to a class
<FromGitter> <drum445> without pissing about with mappings
Ven`` has joined #crystal-lang
Ven`` has quit [Client Quit]
ashirase has quit [Quit: ZNC - http://znc.in]
ashirase has joined #crystal-lang
<FromGitter> <asterite> Ed: when parsing json, if a field without a default value is missing, an exception is raised. You could do the same. Basically you have to copy what JSON::Serializable does
wontruef_ has joined #crystal-lang
<FromGitter> <jspillers> @bew re: stringify keys for NamedTuples: https://play.crystal-lang.org/#/r/4hy9 thoughts?
wontruefree has quit [Ping timeout: 244 seconds]
<FromGitter> <jspillers> spent way too long on such a trivial thing, but i learned more about the types system for sure
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
<FromGitter> <drum445> I will look into how json handles it, cheers for your advice guys
<crystal-gh> [crystal] straight-shoota opened pull request #6367: Syntax: allow empty `case` without `when` (master...jm/feature/case-without-when) https://git.io/fNIXN
wontruef_ has quit [Quit: bye]
wontruefree has joined #crystal-lang
wontruefree has quit [Quit: bye]