ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.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
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ur5us has quit [Read error: Connection reset by peer]
zorp has quit [Ping timeout: 265 seconds]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
darkstardev13 has quit [Remote host closed the connection]
<FromGitter> <3n-k1> Is there a reason this code doesn't work?
<FromGitter> <3n-k1> Is there a reason this code doesn't work? ⏎ ⏎ ```macro mymacro(name, value) ⏎ {{name.id}} = {{value}} ⏎ end ⏎ mymacro(b, 10) ⏎ puts b``` [https://gitter.im/crystal-lang/crystal?at=5e9d180574bfed5a1b4dc058]
<FromGitter> <3n-k1> I would expect the macro call to expand to `b = 10`, but it doesn't.
<FromGitter> <3n-k1> alright, using `def` instead works, so I assume it's a scoping thing
<FromGitter> <watzon> Hmm I'd actually expect that to work
<FromGitter> <watzon> Surprised it doesn't
<FromGitter> <neutrinog> How do you type a method that receives a type as an argument? E.g. https://play.crystal-lang.org/#/r/8x3k
<FromGitter> <watzon> @neutrinog https://play.crystal-lang.org/#/r/8x3m
<FromGitter> <neutrinog> I don't want it to be tied to any particular class though
<FromGitter> <neutrinog> or at most, only to a base class
<FromGitter> <neutrinog> ah thanks @watzon. I can use that with a base class. That's perfect.
ur5us has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <neutrinog> ok related question. Is there any way to pass a variable of type `Object.class` to a generic? e.g. https://play.crystal-lang.org/#/r/8x3y
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
ur5us has quit [Ping timeout: 252 seconds]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 265 seconds]
<jhass> neutrinog: No. Think about it, cls is a runtime value, how should the compiler type this if I do cls = rand > 0.5 ? String.class : Range.class?
<jhass> however you may be able to use Generic(typeof(some_var)) in some cases
<FromGitter> <grkek> That doesn't work as well
<jhass> >> x = "foo"; Array(typeof(x)).new << x
<DeBot> jhass: # => ["foo"] - https://carc.in/#/r/8x4f
<jhass> I said in some cases
<FromGitter> <grkek> That's some black magic macro right there
<jhass> it's how a lot of stdlib containers are able to work :)
<jhass> ["foo"] gets rewritten to (something like) the above
Flipez has quit [Quit: The Lounge - https://thelounge.github.io]
Flipez has joined #crystal-lang
<yxhuvud> There is also `Array(Int32){1,2,3}` which works on anything implementing `<<`
<yxhuvud> though that might be answering a different question :P
<yxhuvud> Actually, the (Int32) part doesn't seem to be necessary, so it may actually answer the right one :P
<jhass> [1, 2, 3] and Array(Int32) { 1, 2, 3 } get rewritten to the same thing really. The latter syntax is just more general and works for any class
<yxhuvud> Right.
<FromGitter> <ImAHopelessDev_gitlab> hi
chachasmooth has quit [Ping timeout: 265 seconds]
<FromGitter> <neutrinog> thanks that got me in the right direction.
ur5us has joined #crystal-lang
chachasmooth has joined #crystal-lang
MasterdonX has quit [Ping timeout: 256 seconds]
MasterdonX has joined #crystal-lang
alexherbo2 has joined #crystal-lang
zorp has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
ur5us has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <kingsleyh> hi - when writing C bindings - if the function can take a NULL - e.g. `fun go(param : Void*)` - if I want `go(NULL) ` can I do `go(nil)` and it will get turned into NULL when it runs the binding?
<jhass> yeah :)
<jhass> Crystal codegens nil as a null pointer, so for Lib calls it just bypasses the semantic checks :)
<FromGitter> <kingsleyh> thanks :)
zorp_ has joined #crystal-lang
zorp has quit [Ping timeout: 256 seconds]
<FromGitter> <torvim> Can someone help me
<FromGitter> <Blacksmoke16> with?
<FromGitter> <torvim> i'm trying to find the dimensions of the user's terminal
<FromGitter> <torvim> i've tried a few different solutions but none of them have worked
<FromGitter> <kingsleyh> did I get this right? `int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub, size_t *len)` from C into Crystal: `fun EVP_PKEY_get_raw_public_key(pkey : Void*, pub : LibC::Char*, len : LibC::Int*) : LibC::Int`
<FromGitter> <torvim> ayy i got it, nvm
<FromGitter> <kingsleyh> or maybe it should be `len : LibC::SizeT*`
<jhass> +1 for SizeT
<jhass> unsigned char probably ought to be UChar
<jhass> I don't know the rest of the API, but a type EvpKey = Void* might make things a bit neater and safer
<FromGitter> <ImAHopelessDev_gitlab> good morning
<FromGitter> <ImAHopelessDev_gitlab> crystal time baby
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #crystal-lang
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#bf6630a (master - Parser: allow combination of anonymous splat and block arg (#9113)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/677262116
<DeBot> https://github.com/crystal-lang/crystal/pull/9113 (Parser: allow combination of anonymous splat and block arg)
<FromGitter> <neutrinog> does anyone know why doing something like `(&block : (*args : *U)) forall U` doesn't work? https://play.crystal-lang.org/#/r/8x7d
<FromGitter> <Blacksmoke16> im not sure if you can have variable amount of block arguments like tht?
<FromGitter> <tenebrousedge> nope
<FromGitter> <Blacksmoke16> also thats not really the right syntax for block restrictions either
<FromGitter> <neutrinog> but you can with procs. and isn't a captured block sort of like a proc?
<FromGitter> <Blacksmoke16> idt you can with procs either?
<FromGitter> <Blacksmoke16> as you have to know all the types
<FromGitter> <tenebrousedge> you can have variable args with a block, but I don't think you can type it
<FromGitter> <tenebrousedge> well, you can use a generic I guess
<FromGitter> <tenebrousedge> like how Enumerator do
<FromGitter> <neutrinog> I've seen this in another lib `def connect_{{ method_name.id }}(proc : *U ->) forall U`
<FromGitter> <Blacksmoke16> thats via a macro tho
<FromGitter> <neutrinog> sure. In my case I'm also writing a macro.
<FromGitter> <Blacksmoke16> moment
Andriamanitra has quit [Ping timeout: 272 seconds]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8x7g
<FromGitter> <Blacksmoke16> syntax for the block types were just wrong
<FromGitter> <Blacksmoke16> but unless you're using `U` for something, why both typing it at all?
<FromGitter> <neutrinog> ug.. sorry abuut the crummy syntax.
<FromGitter> <neutrinog> I don't have to type it. I'm just trying to get it to work. Just following what i've seen elsewhere.
<FromGitter> <neutrinog> but I can't seem to get it to take variable arguments
<jhass> why capture it at all vs just yield'ing?
<FromGitter> <Blacksmoke16> yea i dunno, i didnt think that was possible, keep me posted :p
<FromGitter> <neutrinog> I've never really grasped the concept of yield'ing, so I stuck with the familiar callback paradigm. I'm not sure yielding would work well in this case though since I want to subscribe to events. But maybe my thinking about yield's is all wrong.
<FromGitter> <Blacksmoke16> working on an event dispatching lib?
<jhass> I don't quite get where you expect the argument types to actually come from
<jhass> ah from the argument list of the call?
<FromGitter> <neutrinog> yeah
<FromGitter> <neutrinog> i was actually hoping to use https://github.com/firejox/CrSignals, but it couldn't handle passing class types
<FromGitter> <neutrinog> e.g. `cr_signal value_changed(Thing.class)` = boom
<FromGitter> <Blacksmoke16> hm
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
<FromGitter> <neutrinog> ok well this is annoying. I ended up with the same problem I was getting with the CrSignals lib. https://play.crystal-lang.org/#/r/8x89
<FromGitter> <neutrinog> `Error: type must be Animal+.class, not Dog.class`
<FromGitter> <neutrinog> even changing Animal to an abstract class doesn't work
<FromGitter> <Blacksmoke16> whats the usecase for giving a class arg/
<FromGitter> <neutrinog> I'm porting an entity component system library to crystal and it uses the types to filter differnents things.
<FromGitter> <neutrinog> e.g. give me all Animal entities.. etc.
<jhass> no idea how turn that into magic though
<jhass> would need to assume stuff about argument order I guess
<FromGitter> <Blacksmoke16> event stuff i did so far, i opted for syntax like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e9dc411c38aa05a1a8b5054]
<FromGitter> <Blacksmoke16> so then you only have to worry about there being the one argument
<FromGitter> <Blacksmoke16> and context related to the event could be within that obj
<FromGitter> <Blacksmoke16> https://github.com/crystallabs/event_handler uses a similar approach
<FromGitter> <neutrinog> thanks @Blacksmoke16 I got focused on that one library and forgot to expand my search query.
<FromGitter> <neutrinog> I'll check this one out
<FromGitter> <Blacksmoke16> https://github.com/athena-framework/event-dispatcher is the one from the first example as well
<FromGitter> <Blacksmoke16> is also https://github.com/onyxframework/eda but idt its maintained anymore
<FromGitter> <neutrinog> so event_handler solved all of my problems in 5 minutes. Awesome!
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <kingsleyh> jhass - thanks - I do actually have a type for that - just I omitted it for brevity
<FromGitter> <kingsleyh> jhass I can't @ you in Gitter because you come from IRC lol
<jhass> good thing my IRC client just highlights on my name being in a message ;)
<FromGitter> <kingsleyh> jhass excellent - I'm having issues with crystal bindings from C still
<FromGitter> <kingsleyh> jhass if you know about this area and you have 5 mins - I wouldn't mind asking you some questions
<jhass> no need to look for an expert, just ask the channel :)
<FromGitter> <kingsleyh> jhass well I can try - but I find not many people know about this stuff
<FromGitter> <kingsleyh> ok am I assuming the right things here: https://play.crystal-lang.org/#/r/8x8v
<FromGitter> <kingsleyh> 1) creating a pkey and then running EVP_PKEY_new_raw_public_key will populate the pkey
<FromGitter> <kingsleyh> and then I should be able to get the raw public key out again using EVP_PKEY_get_raw_public_key
<FromGitter> <kingsleyh> and I should make a new pointer to store the public key in so I can make it into a String
<FromGitter> <kingsleyh> this code gives : Invalid memory access (signal 11) at address 0x110
<FromGitter> <kingsleyh> so I definitely messed something up
<FromGitter> <kingsleyh> here is the code including the binding bit: https://play.crystal-lang.org/#/r/8x8y
<FromGitter> <kingsleyh> I'm referring to these docs: https://www.openssl.org/docs/man1.1.1/man3/EVP_PKEY_new_raw_public_key.html
<jhass> what's hex_public_key ?
<FromGitter> <kingsleyh> it's a string: pub_key = "04cbca172be23b65ecd2ac5c84f15fd82640421b01b502e3df2f225e51d286273396b63648cfc98b7b93f6e86a49147bcaf6b8c0cdbe370e66d9bbcabe8d2c5630"
<FromGitter> <kingsleyh> it was generated with an openssl keypair generation
<FromGitter> <kingsleyh> this is the first part of a verify_signature I'm writing that uses the EVP stuff
<jhass> where did you get 714 from?
<FromGitter> <kingsleyh> my original code uses ECDSA_do_verify (and do_sign) which are both being deprecated - so trying to move to EVP - https://github.com/SushiChain/crystal-ecdsa/blob/master/src/crystal-ecdsa.cr#L113
<jhass> ah I see NID_secp256k1
<FromGitter> <kingsleyh> yeah
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<jhass> I don't see it listed in evp.h though
<jhass> and the manpage only references definitions from there I think?
<FromGitter> <kingsleyh> what is not listed in evp.h?
<jhass> Algorithm types that support raw public keys are EVP_PKEY_X25519, EVP_PKEY_ED25519, EVP_PKEY_X448 or EVP_PKEY_ED448.
<FromGitter> <kingsleyh> hmm
<FromGitter> <kingsleyh> well that's disappointing - surely I can verify a signature using EVP with the sec256k1 curve±
<FromGitter> <kingsleyh> maybe I can - but I just can't use the raw public key method
alexherbo27 has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#8a79317 (master - Allow to_json for Log::Context (#9101)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/677301796
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9101 (Allow to_json for Log::Context)
<jhass> yeah or maybe it'll even work? openssl docs aren't great tbh
<jhass> but it's not exactly promising
<FromGitter> <kingsleyh> this is ultimately what I want to do: https://www.openssl.org/docs/manmaster/man3/EVP_PKEY_verify.html
<FromGitter> <kingsleyh> but you see there it needs an EVP_KEY - so I was hoping to create one using that raw public key
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo27 is now known as alexherbo2
<FromGitter> <kingsleyh> the example there only shows RSA tho
<jhass> you say you could generate it with the CLI?
<jhass> I found looking at the source code for the CLI helpful
<FromGitter> <kingsleyh> do you know where the cli code is in this repo? https://github.com/openssl/openssl
<jhass> I forgot but figured it out in the past, let me try again
<FromGitter> <kingsleyh> such a huge project!
<jhass> one file per subcommand
<jhass> but maybe a purpose built library like https://github.com/bitcoin-core/secp256k1 (quick google, no expierence with it) might be easier to bind
ht_ has joined #crystal-lang
_ht has quit [Ping timeout: 258 seconds]
ht_ is now known as _ht
<FromGitter> <kingsleyh> that bitcoin lib looks interesting too - although I don't see any documentation1
<FromGitter> <randiaz95> Have you guys seen that new peer to peer database on hackernews?
<FromGitter> <randiaz95> https://github.com/orbitdb/orbit-db for decentralized internet
<FromGitter> <randiaz95> no server required :)
<FromGitter> <randiaz95> Great for blockchain apps
<jhass> @kingsleyh: https://github.com/openssl/openssl/blob/master/apps/lib/apps.c#L662 seems to be the main path to read the key? might be worth to just wrap/generate your key into PEM encoding. There's in memory support for BIO https://www.openssl.org/docs/manmaster/man3/BIO_s_mem.html
<jhass> idk if this really is the easiest way
<jhass> actually you probably can hook up an IO::Memory to https://github.com/crystal-lang/crystal/blob/master/src/openssl/bio.cr
alexherbo20 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo20 is now known as alexherbo2
<FromGitter> <kingsleyh> Thanks jhass
<FromGitter> <kingsleyh> @randiaz95 orbitdb looks very cool
<FromGitter> <sam0x17> I'm happy to see this works as I expected: ⏎ https://play.crystal-lang.org/#/r/8xbf
<FromGitter> <sam0x17> (ensure blocks don't affect return value)
<FromGitter> <kingsleyh> would it be an enum?
<jhass> you could make it a @|Flags] enum, but just assigning constants is also fine
<jhass> I think I would actually start with that, something simple https://p.jhass.eu/7r.cr
<jhass> maybe actually removing the prefix in the names since it's redundant when you access it like LibSecp256k1::CONTEXT_VERIFY
<FromGitter> <kingsleyh> jhass and what would my ldflags look like? would I have to compile that bitcoin lib first to creaate all the *.o files - and then do something like this: `@[Link(ldflags: "`printf %s '#{__DIR__}/../bitcoin_lib/*.o'`")]`
<FromGitter> <kingsleyh> that didn't print very well lol
<FromGitter> <kingsleyh> ```@[Link(ldflags: "`printf %s '#{__DIR__}/../encryption/*.o'`")]```
<FromGitter> <kingsleyh> like that but for all the o files from the bitcoin lib
<FromGitter> <randiaz95> Does any1 know where I specifyport in Athena?
<FromGitter> <randiaz95> In the ART.run method?
<FromGitter> <kingsleyh> actually it didn't make o files - it made libsecp256k1.la and libsecp256k1.pc
<FromGitter> <kingsleyh> oh I see - I don't need to compile it - just read in the headers
Deuns has joined #crystal-lang
<Deuns> hello
<FromGitter> <Blacksmoke16> o/
<FromGitter> <kingsleyh> back later
<FromGitter> <randiaz95> George!
<FromGitter> <Blacksmoke16> yes?
<FromGitter> <randiaz95> How are you feeling bro? I have some questions about athena specifically integrating with Granite, but if you are not busy.
<FromGitter> <Blacksmoke16> sure, if you want feel free to jump in https://gitter.im/athena-frameworkcr/community
<FromGitter> <watzon> With the db shard is it possible to determine what driver is being used?
<FromGitter> <watzon> I need to handle an upsert, but the different SQL varieties have different ways of doing it
<FromGitter> <sam0x17> when statically compiling, how can I ensure I get proper stack traces, not like this?: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e9dfa4ec38aa05a1a8c307b]
<FromGitter> <Blacksmoke16> compile with debug symbols included
<FromGitter> <Blacksmoke16> i.e. `--debug`?
<FromGitter> <sam0x17> I did that -- do I also need the source code with the binary?
<FromGitter> <sam0x17> ah I just removed my --no-debug
<FromGitter> <Blacksmoke16> im just guessing so gl :p
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#7e06c6e (master - Log: allow nil as context raw values (#9121)): The build has errored. https://travis-ci.org/crystal-lang/crystal/builds/677233044
<DeBot> https://github.com/crystal-lang/crystal/pull/9121 (Log: allow nil as context raw values)
<FromGitter> <kingsleyh> jhass are you still around?
<FromGitter> <kingsleyh> or anyone else who know about C bindings - what would this look like in Crystal? https://github.com/bitcoin-core/secp256k1/blob/96d8ccbd16090551aa003bfa4acd108b0496cb89/src/secp256k1.c#L68
<FromGitter> <j8r> @sam0x17 you can't unfortunately
<FromGitter> <sam0x17> ahhh well at least there is a reason
<FromGitter> <kingsleyh> and not sure how the secp256k1_context should look in Crystal
<raz> so, i have two slices and i want to merge them into one
<raz> what's the method that i'm missing?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Slice.html#move_to(target:self)-instance-method maybe
<FromGitter> <Blacksmoke16> but it seems that doesnt merge the two
* raz sobs
<raz> i guess i can piece it together with move_to or copy_to, just surprised there isn't a helper for that (or i'm not seeing it)
<FromGitter> <Blacksmoke16> could maybe go to pointer, then back to slice?
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Pointer/Appender.html TIL this is a thing
ur5us has joined #crystal-lang
<oprypin> hm noo this is the opposite
<FromGitter> <jwoertink> Is the `preview_mt` flag still a thing? Or is the MT stuff just default on for 0.34 now?
alexherbo24 has joined #crystal-lang
<FromGitter> <Blacksmoke16> its still a thing
<FromGitter> <jwoertink> cool
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo24 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo2 has joined #crystal-lang
_ht has quit [Remote host closed the connection]
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo26 is now known as alexherbo2
<raz> boo, base62.cr is a lie, it can only encode integers :<
zorp_ has quit [Ping timeout: 256 seconds]
alexherbo2 has quit [Ping timeout: 265 seconds]
<oprypin> raz, lol what is even the point then, u just use `to_i` normally instead
<raz> oprypin: i need to encode a Bytes
<oprypin> no im just criticizing that shard
<raz> oprypin: oh, yes. indeed. my forehead made contact with my hand when i realized that... ;)
<raz> especially as it _does_ take a String | Bytes as input
<raz> i think i must've been an april 1st thing... ;)
<raz> it*
<oprypin> raz, no its still a nice shard
<oprypin> it can actually be used for any baseN at all
<raz> hmm maybe, but i'm not smart enough to see how to use it encode a Bytes
<oprypin> raz, eh first convert it to bigint and then use that shard
<oprypin> i remember probaly like 10 years ago i think i wrote base62 in php 😂
<raz> hum, is that how it's done? even when it's like a megabyte slice?
<oprypin> well no, then there are better ways
<oprypin> u can find an algo online easily, while i'll take this as a coding challenge
<raz> yeh i don't feel like writing that myself
<raz> but if you can come up with a nice base62 shard i'm sure i'm not the only one who would use it ;)
<oprypin> its a tough one, math challenge
zorp_ has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
<FromGitter> <randiaz95> Just lost electricity for 4 hours
<FromGitter> <randiaz95> What the French toast
<FromGitter> <Blacksmoke16> f
<oprypin> raz, i concluded that yes, this is the only way
<raz> weird, i never looked at the baseXX stuff, but always thought it works blockwise in a way
<oprypin> base64 does
<oprypin> it works only when there is a reasonable common power, 64**M = 256**N
<oprypin> the solution is 4, 3 here
<oprypin> for 62**M = 256**N the solution is ridiculously huge, the brote forcesearch is still going after 3 minutes
<raz> isn't that bigint method slow tho? i may just be irrational, but converting a multi-megabyte binary to bigint just feels wrong to me lol
<oprypin> well dont do base62 the
<raz> the data i want to be compatible with comes as base62 :(
<oprypin> raz, so do *they* have a way to turn it into base62?
<raz> yes. in ruby, python, golang, elixir, js and a bunch other languages. i'm trying to port to crystal ;)
<oprypin> like u already have megabytes of base62 data?
<raz> nah, it's not megabytes, it's https://branca.io/
<oprypin> well then just do big int
<raz> that feels so silly :/
<FromGitter> <watzon> Wait wait wait. Who uses Base62 and why?
<oprypin> https://branca.io/ uses
<FromGitter> <straight-shoota> @watzon Base62 uses only alphanumericals, exactly *all* of them. Base64 aligns nicer but you need two characters in the target alphabet that are not ASCII alphanumeric.
<FromGitter> <straight-shoota> So it's easy to use in URLs or other places where other characters might need to be escaped
<FromGitter> <watzon> Hmm makes sense
zorp_ has quit [Ping timeout: 250 seconds]