ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.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
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Groogy> well this is interesting, I wonder if sizeof has gotten broken as of late
<FromGitter> <Groogy> ah here we go
DTZUZU has joined #crystal-lang
<FromGitter> <Groogy> on Struct's it will return the proper size of that type, on classes it will return the size of the pointer
<FromGitter> <Groogy> even though I am giving them the type
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <mattrberry> So I have a ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ But I'm not sure how to grab the properties and getters from the block in order to define an initialize method with them. ... [https://gitter.im/crystal-lang/crystal?at=5e015755c5a23938b46f474b]
<FromGitter> <Blacksmoke16> `{{yield}}`
<FromGitter> <Blacksmoke16> instead of `{{block.body}}`
DTZUZU has joined #crystal-lang
<FromGitter> <mattrberry> Okay, I can do that. Why is that preferred?
<FromGitter> <Blacksmoke16> should work how you want it more
<FromGitter> <Blacksmoke16> is essentially the same idea as blocks in normal methods
<FromGitter> <mattrberry> Yield seems to be producing the same result as block.body, at least in my limited testing of it so far
<FromGitter> <Blacksmoke16> oh i see what you wan
<FromGitter> <mattrberry> Regardless, do you know how I might go about getting the property and getter definitions out of the body of the code block so that I can define an initialize method with them?
<FromGitter> <Blacksmoke16> i think you would have to take a diff approach and do like
<FromGitter> <Blacksmoke16> `macro dataclass(typename, *properties)` then you can iterate over the properties to do what you want
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> yes
<FromGitter> <mattrberry> I'd like to keep the syntax similar to a class if possible, but that is definitely an option
<FromGitter> <mattrberry> Do you think what I'm looking for would be achievable if I instead put it in a module that I included?
<FromGitter> <Groogy> couldn't find anything similar so went and reported it
<FromGitter> <mattrberry> That was one of the other suggestions from earlier today
DTZUZU has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> prob not a bug?
<FromGitter> <Blacksmoke16> i mean tbh is there a reason to not just use a `record` or do they have to be classes?
<FromGitter> <Groogy> huh it used to work
<FromGitter> <Blacksmoke16> or even just manually type out the initializer? prob could have been done by now :P
<FromGitter> <Groogy> oh there's an instance_sizeof now
<FromGitter> <Groogy> that's new
<FromGitter> <Blacksmoke16> well there yo ugo
DTZUZU has joined #crystal-lang
<FromGitter> <Blacksmoke16> in other news, check this out
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e015a3e3e3f133894e7fd85]
<FromGitter> <Blacksmoke16> implementation is still WIP but 💯
<FromGitter> <Groogy> There we go now the memory profiler works again
<FromGitter> <Groogy> oh that's nice
<FromGitter> <Groogy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e015a8d8897197969e94240]
<FromGitter> <Groogy> and here's the profiler running as it's supposed to again
<FromGitter> <Blacksmoke16> fancy
<FromGitter> <Blacksmoke16> whats with the backtrace?
<FromGitter> <mattrberry> Yeah I totally could just do that haha. I was just curious about crystal macros, and thought that this would be a fun way to learn some more about macros while also cleaning up my syntax just a little bit :p ⏎ ⏎ Here's a little more detailed spec of what I'm trying to accomplish ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5e015b063e3f133894e803be]
<FromGitter> <Blacksmoke16> you could do some hacks with like iterating over methods to find setters and use those minus the `=` to build the initialize method maybe/
<FromGitter> <mattrberry> Really I'm just trying to achieve some of what I like about Python's dataclasses
<FromGitter> <Blacksmoke16> although i wouldnt suggest it...
<FromGitter> <mattrberry> Eh but that wouldn't work with just getters :/
<FromGitter> <Groogy> @Blacksmoke16 the backtrace is where the allocation was done
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e015badc5a23938b46f62be]
<FromGitter> <Blacksmoke16> tada?
<FromGitter> <Blacksmoke16> but with a struct having a setter isn't ideal
<FromGitter> <Blacksmoke16> as they should be immutable
<FromGitter> <Blacksmoke16> @Groogy 👍
<FromGitter> <mattrberry> I'll look into that some more, thanks @Blacksmoke16 !
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Groogy> also with tags like that I could do pretty nice things with my serialization system
<FromGitter> <Groogy> !date "1st October"
<FromGitter> <Groogy> etc.
<FromGitter> <Blacksmoke16> prob yea
<FromGitter> <Blacksmoke16> it'll only work for scalar values tho
<FromGitter> <Blacksmoke16> `Bool | Float64 | Int64 | String | Time | Nil`
<FromGitter> <Blacksmoke16> is going to be its limitation
<FromGitter> <Groogy> oh so it can't convert String into object Foo?
<FromGitter> <Blacksmoke16> i.e. so couldnt have like `some_var: !create Foo` which would create an set `some_var` to an instance of `Foo`
<FromGitter> <Blacksmoke16> no
DTZUZU has joined #crystal-lang
<FromGitter> <Blacksmoke16> possibly could change the implementation to support it but idk
<FromGitter> <Blacksmoke16> didnt get that far yet
<FromGitter> <Blacksmoke16> in that case you would prob be better off using a custom converter anyway
<FromGitter> <Blacksmoke16> i also have a serialization shard 😉
<FromGitter> <Groogy> ah man as I thought I was finishing up. I do a small little test and found a new edge case ;_;
<FromGitter> <Groogy> for some reason, somehow... @type.type_vars are somehow MacroId and not TypeNode
<FromGitter> <Groogy> even though documentation says it is TypeNode
<FromGitter> <Blacksmoke16> is possible to give an int as a generic arg
<FromGitter> <Blacksmoke16> idk what would happen there...
<FromGitter> <Groogy> Hmm true
<FromGitter> <Groogy> so now need to figure out how to test the annotation on a MacroId
<FromGitter> <Groogy> > _>
<FromGitter> <Groogy> Hmm source on github though says it should be TypeNode
<FromGitter> <Blacksmoke16> got an example of when its not?
DTZUZU has quit [Ping timeout: 265 seconds]
<FromGitter> <Groogy> Not a small example no, gonna dig out the old example and see if I can wreck it up to make it happen
<FromGitter> <Blacksmoke16> worst case just add a check to make sure its a type node first
<FromGitter> <Groogy> Hmm it's a weird one though
DTZUZU has joined #crystal-lang
<FromGitter> <Groogy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e015faf8dfce538b5faa2cb]
<FromGitter> <Blacksmoke16> generic maybe?
<FromGitter> <Groogy> can't reproduce it in a small test
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Groogy> works just fine
<FromGitter> <Blacksmoke16> :shrug:
DTZUZU has joined #crystal-lang
<FromGitter> <Groogy> Oh there is a difference
<FromGitter> <Groogy> the \
<FromGitter> <Groogy> so @type in this case is the generic, not the resolved class
<FromGitter> <Groogy> I thought the `{% verbatim do %}` would solve that for me though
<FromGitter> <Blacksmoke16> it just makes it so you dont have to escape using `\`
<FromGitter> <Groogy> hmm
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Groogy> so then it should work with that
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e01619bb1701e50ca767ac0]
<FromGitter> <Blacksmoke16> made the env ones proper
<FromGitter> <Blacksmoke16> `{"real" => "5", "fake" => nil}`
<FromGitter> <Blacksmoke16> symfony framework has one where you can do `!php/const CONST_NAME`
<FromGitter> <Blacksmoke16> but idt you can do that w/o reflection, or having something that stores constant values
DTZUZU has joined #crystal-lang
DTZUZU has quit [Client Quit]
bougyman has quit [Ping timeout: 252 seconds]
bougyman has joined #crystal-lang
<FromGitter> <randiaz95> guys, is it weird to do exercism while I am coding my app after work? or is that too much?
<FromGitter> <randiaz95> Im thinking I should stop studying for fun, but its still fun to me :(
<FromGitter> <Groogy> are you performing an exorcism? or am I missreading that?
<FromGitter> <Blacksmoke16> :p
<FromGitter> <Groogy> Anyway I am a bit stuck because Time now reads from a file meaning when I try to do that during allocation it makes everything go boom
<FromGitter> <Groogy> somehow
<FromGitter> <Groogy> (or well not somehow, it needs to lock a thread or something which results in the boom)
<FromGitter> <Groogy> I just want something to measure "how many cpu cycles since allocation?"
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <randiaz95> lol
<FromGitter> <randiaz95> Exercism
<FromGitter> <randiaz95> my computer cannot detect if it is not malware...
<FromGitter> <randiaz95> so I cant even do it..
<FromGitter> <randiaz95> @Groogy does your computer explode?
<FromGitter> <randiaz95> how many computers do you buy a week?
<FromGitter> <Groogy> haha no but my compiler likes to explode :D
<FromGitter> <Groogy> I sorta abuse it with all the macro stuff
<FromGitter> <randiaz95> lol
<FromGitter> <randiaz95> some times I like interpreted Langs
<FromGitter> <randiaz95> cause fun
<FromGitter> <firejox> morning /
f1reflyylmao has joined #crystal-lang
<FromGitter> <randiaz95> What? where are you?
<FromGitter> <randiaz95> its night here
f1refly has quit [Ping timeout: 268 seconds]
yukai has quit [Ping timeout: 265 seconds]
<FromGitter> <randiaz95> Hey guys...
<FromGitter> <randiaz95> Can you guys help me out with improving my implementation of this algorithm for finding sum of multiples?
<FromGitter> <randiaz95> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e0193d00cb24d1d441015f7]
<FromGitter> <randiaz95> or is this fluent Crystal?
_whitelogger has joined #crystal-lang
<FromGitter> <c910335> ```s = Set(Int32).new ⏎ {3, 5}.each { |p| p.step(to: 999, by: p) { |i| s << i } } ⏎ p s.sum``` [https://gitter.im/crystal-lang/crystal?at=5e019d7fe0131f50c997bf94]
<FromGitter> <randiaz95> OMgash
<FromGitter> <randiaz95> Whats with that .step method?
<FromGitter> <randiaz95> Seems powerful.
_whitelogger has joined #crystal-lang
<FromGitter> <c910335> https://crystal-lang.org/api/0.32.1/Number.html#step(*,to=nil,by=1,&)-instance-method
<FromGitter> <firejox> Taiwan, it's UTC+8
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <grkek> Hello
<FromGitter> <grkek> @Blacksmoke16 So I disabled logging in and the rps went up to 21k
<FromGitter> <grkek> now I am at 51150
<FromGitter> <grkek> almost at your mark
<FromGitter> <grkek> 2 instances bring it up to 70k/s
<FromGitter> <grkek> so yeah that might be the top of it so far
return0__ has joined #crystal-lang
<FromGitter> <Groogy> Hello o/
return0e has quit [Ping timeout: 268 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <j8r> @grkek one strategy is not to flush everyline, perhaps each x second of x lines
return0__ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
alexherbo2 has joined #crystal-lang
Human_G33k has joined #crystal-lang
Human_G33k has quit [Remote host closed the connection]
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 240 seconds]
<FromGitter> <christopherzimmerman> @randiaz95 there's a mathematical solution to that problem that will be much faster than a brute force approach.
<FromGitter> <christopherzimmerman> You shouldn't need any iteration.
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <randiaz95> @christopherzimmerman Do you think the formula will need iteration any ways since I will need to compute the various multiples?
<FromGitter> <randiaz95> Or your saying there is a function that results in the sum of multiples of 3 and 5 as output? That sounds like rocket science lol.
<FromGitter> <christopherzimmerman> You don't need to compute the various multiples, it's a gaussian sum.
<FromGitter> <randiaz95> Interesting. I <3 gauss
<FromGitter> <randiaz95> Thats the guy that invented the exponential normal distribution curve right?
<FromGitter> <christopherzimmerman> I won't spoil the solution since this is (I'm assuming?) the project euler one. But to get the sum of the first `n` multiples of a number, the formula is: ⏎ ⏎ ```k(n*(n+1)/2)``` [https://gitter.im/crystal-lang/crystal?at=5e022a7fcf771f770821e5af]
<FromGitter> <randiaz95> :o wow looks pretty simple...
<FromGitter> <Daniel-Worrall> sum of n x (from x=1 to x=m) = 1/2 m (m + 1) n
<FromGitter> <Daniel-Worrall> so not quite what chris put
<FromGitter> <christopherzimmerman> Are you sure? What I posted above should work fine.
<FromGitter> <Daniel-Worrall> oh wait, it's the same yeah, I was confused cause I used n to represent a different variable
<FromGitter> <christopherzimmerman> @randiaz95 just remember that your `n` will need to change based on the value of `k`.
<FromGitter> <Daniel-Worrall> we have the identity sum 1 to n = n(n+1)/2 and then the distributivity identity to pull out k
<FromGitter> <randiaz95> That means we still have to iterate though..
<FromGitter> <randiaz95> just less times.
<FromGitter> <randiaz95> Guys... Lost in Space Season 2 came out today
<FromGitter> <randiaz95> Get your popcorn ready!!
<FromGitter> <Daniel-Worrall> No it doesn't
<FromGitter> <Daniel-Worrall> You have a max value, you just need to find the highest multiple
<FromGitter> <Daniel-Worrall> for example. from 1 to 10 is 3,6,9 ⏎ 3+6+9 = 3*(1+2+3)
<FromGitter> <Daniel-Worrall> So your max value is 10, you need to get 9, then turn it into 3
<FromGitter> <randiaz95> True, I meant the number of multiples, but we only have 2 in the case of project Euler.
<FromGitter> <Daniel-Worrall> Trust me, no iteration
<FromGitter> <randiaz95> I will have faith.
Human_G33k has quit [Quit: Leaving]
dwdv has joined #crystal-lang
<FromGitter> <grkek> Anyone knows a great ORM ?
<FromGitter> <grkek> for SQLite
<FromGitter> <Blacksmoke16> i like granite, are others as well
<FromGitter> <grkek> Can you give me docs for granite since I have my eyes on it as well
<FromGitter> <Blacksmoke16> docs for what?
<FromGitter> <grkek> Model creation
<FromGitter> <grkek> and interaction with the framework
<FromGitter> <grkek> orm*
<FromGitter> <grkek> Oh found it
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <grkek> how did I even miss that
<FromGitter> <grkek> still, thank you for it
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> afaik is the only one that supports annotations on columns
<FromGitter> <Blacksmoke16> so can work well with some of the shards i made 😉
<FromGitter> <grkek> What is the most successful shard you have made so far ?
<FromGitter> <Blacksmoke16> probably `oq`
<FromGitter> <Blacksmoke16> ever hear of `jq`?
<FromGitter> <jwoertink> Anyone know there's a crystal-pg or crystal-db method that would turn `5` in to `"5"` as well as `"yo"` in to `"'yo'"`? I found `PQ::Param.encode` which does the first part, but it doesn't seem to encase strings with single quotes
<FromGitter> <jwoertink> Other than doing `String === val ? "'#{val}'" : PQ::Param.encode(val)`
<FromGitter> <grkek> nope
<FromGitter> <grkek> what does it do ?
<FromGitter> <Blacksmoke16> https://stedolan.github.io/jq/
<FromGitter> <grkek> Damn nice
<FromGitter> <Blacksmoke16> `oq` wraps `jq` and allows for additional input/output formats like `XML` or `YAML`
<FromGitter> <Blacksmoke16> converts input to json, feeds it to `jq`, convert json to desired output format
<FromGitter> <grkek> A lovely feature indeed
<FromGitter> <Blacksmoke16> yea is pretty slick
<FromGitter> <grkek> :ok what type does this have in Crystal ?
<FromGitter> <grkek> Are they faster than strings ?
<FromGitter> <jwoertink> @grkek new to crystal?
<FromGitter> <grkek> like in elixir ?
<FromGitter> <grkek> yeah very new tbh
<FromGitter> <jwoertink> welcome!
<FromGitter> <grkek> couple of weeks in crystal
<FromGitter> <grkek> thank you !
<FromGitter> <grkek> Check out my framework as well https://github.com/grkek/grip
<FromGitter> <grkek> ;)
<FromGitter> <jwoertink> One thing that may help you out when working with types and stuff... https://play.crystal-lang.org/#/cr
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter> <jwoertink> you can do `puts :ok.class` or `puts typeof(:ok)`
<FromGitter> <grkek> the .class property is so lovely
<FromGitter> <jwoertink> the `.class` method as well as the `typeof()` will show you the type of something specific. This way you know where to start looking in the documentation
<FromGitter> <Blacksmoke16> just use strings, only real use for symbols is a type for namedTuple keys and autocasting enums
<FromGitter> <jwoertink> https://crystal-lang.org/api/latest
<FromGitter> <grkek> I am not that new I know couple of things :D
<FromGitter> <Blacksmoke16> @jwoertink could you add your own method like `PQ::Param.encode(value : String)`?
<FromGitter> <Blacksmoke16> to keep a common api?
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter> <jwoertink> I think that overload exists already
<FromGitter> <grkek> It would be nice to have a keyword for overriding something
<FromGitter> <grkek> in crystal
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <grkek> :>
<FromGitter> <jwoertink> Ah, yeah, I guess it's just a fallback to not typed
<FromGitter> <jwoertink> We actually have something in Lucky that sort of handles this already, but I'm running in to an issue with the compiler not knowing the type
<FromGitter> <jwoertink> but I'm dealing with an array of who knows what, so I can't really cast it to something specific
<FromGitter> <randiaz95> Hi guys has anyone installed libvoidcsfml-graphics?
<FromGitter> <randiaz95> I think it stands for libvoid Computer science fuck my life I don't know how to install this graphics library
<FromGitter> <jwoertink> lol
<FromGitter> <grkek> lol
<FromGitter> <jwoertink> @randiaz95 is that similar to https://github.com/oprypin/crsfml ?
<FromGitter> <randiaz95> yes
<FromGitter> <randiaz95> thanks for that link!
<FromGitter> <randiaz95> Let me try to debug
<FromGitter> <jwoertink> Good luck
<FromGitter> <randiaz95> ahh.. Can't install CrSFML directly through shards.
<FromGitter> <jwoertink> I've done it...
<FromGitter> <jwoertink> I mean, it's been a while, but that worked for me
<FromGitter> <randiaz95> I was installing a crsfml from another git repo
<FromGitter> <randiaz95> most likely just to increase malware in my computer.
<FromGitter> <jwoertink> This may be a bad idea, but is there a way to tell a variable to cast as the first type in a union? 😂
<FromGitter> <randiaz95> hmm..
<FromGitter> <Blacksmoke16> i wouldnt bet on it tho :S
<FromGitter> <jwoertink> haha awesome
<FromGitter> <jwoertink> yeah, probably a bad idea to use 😅
<FromGitter> <jwoertink> I have this `params = args.map { |arg| arg.class.adapter.to_db(arg) }`
<FromGitter> <jwoertink> which I think will do what I want
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e024c508dfce538b500eab5]
<FromGitter> <jwoertink> but it doesn't know which overload to cast to
<FromGitter> <jwoertink> Maybe I should just roll with my initial gut feeling and use a ternary to catch strings. `PQ::Param.encode` works for all other types it seems
<FromGitter> <jwoertink> I thought about making the overload, but I'm not sure what else that might mess with
<FromGitter> <jwoertink> oh.. actually.. Maybe I'm not using this right..
<FromGitter> <jwoertink> I need all of the values to be a string representation of their actual values. `PQ::Param.encode(arg)` will give me access to a Slice. So I was passing that in to `String.new()`
<FromGitter> <jwoertink> `params = args.map { |arg| String.new(PQ::Param.encode(arg).slice) }`
<FromGitter> <jwoertink> Is there a way to tell the compiler that a type is what it's class is? `value.as(value.class)` doesn't work, but maybe something similar to this?
return0e has quit [Ping timeout: 260 seconds]
<FromGitter> <grkek> can I have private classes ?
<FromGitter> <grkek> like
<FromGitter> <grkek> private class Example
return0e has joined #crystal-lang
<FromGitter> <jwoertink> yup
<FromGitter> <grkek> niceee
<FromGitter> <grkek> How can one turn this into a class oriented version
<FromGitter> <grkek> &@proc : WebSocket, Server::Context ->
<FromGitter> <grkek> > &@proc : WebSocket, Server::Context ->
<FromGitter> <grkek> `&@proc : WebSocket, Server::Context ->`
<FromGitter> <grkek> that requires a block right ?
<FromGitter> <grkek> What I want to do is that I want to implement the on_message on_connect and etc. methods for the class
<FromGitter> <grkek> how do I do that ?
<FromGitter> <jwoertink> I've never worked with websockets before, but https://crystal-lang.org/api/0.32.1/HTTP/WebSocket.html
<FromGitter> <jwoertink> if this is the `on_message` you're looking for, then it would be `def on_message(&proc : String ->)`
<FromGitter> <grkek> Yeah I know that but here is the problem
<FromGitter> <grkek> I have that calss
<FromGitter> <grkek> class*
<FromGitter> <grkek> w8
<FromGitter> <grkek> here it is better
<FromGitter> <grkek> and I want to replace the proc.call to map to local functions
<FromGitter> <grkek> in the class
<FromGitter> <grkek> how does the websocket know what to execute ?
Yxhuvud has joined #crystal-lang
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e025d4ab1701e50ca7d2293]
<FromGitter> <jwoertink> maybe something like this?
<FromGitter> <grkek> no no
<FromGitter> <grkek> here is an example
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e025dbc44e1fb33f6204f19]
<FromGitter> <grkek> Ill try something else
<FromGitter> <grkek> w8
<FromGitter> <grkek> here is what I have as my websocket class
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e025e1984c21677095a30c2]
<FromGitter> <grkek> and here is what I want to achieve
<FromGitter> <grkek> how do I map the on_message function of the Http::WebSocket to my class function
<FromGitter> <jwoertink> ah ok
<FromGitter> <grkek> its like I don't understand how does crystal do it
<FromGitter> <jwoertink> So in that block on line 50, it calls `ws_session.run`
<FromGitter> <jwoertink> that method calls the `on_message` internally
<FromGitter> <jwoertink> so line 48 needs to be your custom websocket class
return0e has quit []
<FromGitter> <grkek> oh sweet
<FromGitter> <grkek> thank you
<FromGitter> <grkek> ;)
<FromGitter> <jwoertink> Hope that works 😂
<FromGitter> <grkek> prolly it will
<FromGitter> <grkek> I've got the websocket part working
<FromGitter> <grkek> now just the mappings
<FromGitter> <grkek> and done
<FromGitter> <grkek> Oh I know
<FromGitter> <grkek> I'll just include the websocket class as well
<FromGitter> <grkek> that would work probably
<FromGitter> <grkek> how do I deal with this crap ?
<FromGitter> <grkek> Error: undefined method 'receive' for Nil (compile-time type is (HTTP::WebSocket::Protocol | Nil))
<FromGitter> <grkek> what a bugger 😠
<FromGitter> <grkek> @Blacksmoke16 can you help ?
<FromGitter> <jwoertink> @grkek if that value is really not nil, then you can use `value.not_nil!.receive`
<FromGitter> <jwoertink> otherwise throw it in an `if`.
<FromGitter> <jwoertink> ```if value ⏎ value.receive ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e0263efc0c8ef301b09906b]
<FromGitter> <grkek> aw that is sick
<FromGitter> <grkek> doesn't work
<FromGitter> <grkek> :(
<FromGitter> <jwoertink> What's the error? Same?
<FromGitter> <jwoertink> You can also do `value.try(&.receive)`
<FromGitter> <grkek> that is an interesting one
<FromGitter> <grkek> let me try something
return0e has joined #crystal-lang
<FromGitter> <grkek> yayyy
<FromGitter> <grkek> I got it working
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e0267cdc0c8ef301b09a962]
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e0267db260751301c0363f6]
<FromGitter> <grkek> when it receives a message
<FromGitter> <grkek> via web sockets
<FromGitter> <grkek> it prints a message received
<FromGitter> <grkek> is it okay to use a dummy_io
<FromGitter> <grkek> ?
<FromGitter> <grkek> > @dummy_io = IO::Memory.new
<FromGitter> <grkek> will this cause any performance issues ?, it gets initialized only once when I call the constructor at the start of the app
<FromGitter> <Blacksmoke16> What's it used for
<FromGitter> <grkek> nothing
<FromGitter> <grkek> just initializing another thing
<FromGitter> <grkek> which gets re initialized afterwards
<FromGitter> <grkek> since I couldn't find a way to do it properly
<FromGitter> <grkek> here is how I am doing it please correct me if I am wrong
<FromGitter> <Blacksmoke16> Why does it need to be an Ivar?
<FromGitter> <grkek> I forgot to close off the dummy_io as well
<FromGitter> <grkek> lvar ?
<FromGitter> <grkek> Ivar
<FromGitter> <grkek> ?
<FromGitter> <Blacksmoke16> Versus just passing a new memory io to it?
<FromGitter> <grkek> can u elaborate ?
<FromGitter> <grkek> I did everything from crystal source files
<FromGitter> <grkek> of http stuff
DTZUZU has joined #crystal-lang
<FromGitter> <grkek> so basically here is my echo server
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e0269938897197969f05268]
<FromGitter> <jwoertink> `ivar` means "instance variable". When you have `@thing` vs a "local variable" without the @ symbol
<FromGitter> <Blacksmoke16> HTTP::WebSocket::Protocol.new(IO::Memory.new)
<FromGitter> <grkek> oh damn that is clever as hell
<FromGitter> <grkek> Beautiful
<FromGitter> <grkek> works like a charm
<FromGitter> <grkek> thank you all
<FromGitter> <jwoertink> Anyone have a clever solution to make this work? https://play.crystal-lang.org/#/r/89t6
<FromGitter> <jwoertink> I see why it doesn't work, but without getting in to crazy regex, I
<FromGitter> <grkek> You probably need to split them up via " "
<FromGitter> <grkek> spaces
<FromGitter> <grkek> and then do the matching ?
<FromGitter> <jwoertink> hmm... that may work
<FromGitter> <grkek> since $ matches the end side
<FromGitter> <grkek> or you're just using it as a character
<FromGitter> <grkek> literal
<FromGitter> <jwoertink> oh, nevermind. I got it!
<FromGitter> <Blacksmoke16> im assuming in the real example there is other stuff in between the strings?
<FromGitter> <jwoertink> I never knew what the `g` in `gsub` meant 😅
<FromGitter> <jwoertink> `str.sub` is what I wanted
<FromGitter> <jwoertink> but yeah, there's a lot more stuff in the real code
<FromGitter> <Blacksmoke16> this for pg placeholder values/
<FromGitter> <jwoertink> yeah
<FromGitter> <Blacksmoke16> doesnt the driver handle argument substitution like this?
<FromGitter> <jwoertink> it does when it makes the SQL call. I need a way to generate that SQL but without actually making the call to PG
<FromGitter> <jwoertink> I didn't see how to do that with the SQL and args being separate objects
<FromGitter> <Blacksmoke16> might not be a bad method to add to the base db shard?
<FromGitter> <Blacksmoke16> like `get_sql`
<FromGitter> <Blacksmoke16> pass it the string and the args and returns the final string
<FromGitter> <jwoertink> Yeah, that would be awesome
<FromGitter> <Blacksmoke16> would be helpful for caching queries as could generate sql, see if it exists in a hash, if so return that value, otherwise run, store, and return the result
<FromGitter> <jwoertink> oooo yeah!
<FromGitter> <Blacksmoke16> maybe make an issue about it ?
<FromGitter> <grkek> https://github.com/grkek/grip updated the framework
<FromGitter> <grkek> @Blacksmoke16 what do you think so far ?
<FromGitter> <Blacksmoke16> seems to be coming along
<FromGitter> <grkek> the websocket part is an improvement over kemal
<FromGitter> <grkek> since it only supports dsl websockets
<FromGitter> <Blacksmoke16> i never really used websockets, dont know much about them
<FromGitter> <grkek> Does your framework have them ?
<FromGitter> <grkek> currently where I work we are rewriting the entire stack from python to elixir
<FromGitter> <grkek> because of web sockets
<FromGitter> <grkek> rip
<FromGitter> <grkek> and I have to learn elixir in like 2-3 days
<FromGitter> <grkek> and I am slacking off doing crystal stuff which is totally fine with me
<FromGitter> <Blacksmoke16> it doesnt no
<FromGitter> <grkek> That sure is interesting to hear my friend
<FromGitter> <grkek> Wish I knew your project a lot more I would help you implement it
<FromGitter> <grkek> its not really that hard
<FromGitter> <Blacksmoke16> dont think websockets are common in REST APIs?
<FromGitter> <grkek> most of them switch to ws for a keep-alive connection
<FromGitter> <grkek> also I found something interesting about muffled white noise
<FromGitter> <grkek> helping me with my concentration
<FromGitter> <grkek> for chatting and whatever
alexherbo2 has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.6]
<FromGitter> <mattrberry> Say I want ⏎ ⏎ ```class Parent ⏎ include SomeModule ⏎ end ⏎ class Child < Parent ⏎ end``` ⏎ ⏎ Is there a way for the module to know that it has been effectively included in the Child class? [https://gitter.im/crystal-lang/crystal?at=5e027ed1c62fdf33f74a1387]
<FromGitter> <Blacksmoke16> ```macro included ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e027ee40cb24d1d44164e81]
<FromGitter> <Blacksmoke16> ?
<FromGitter> <Blacksmoke16> oh wait
<FromGitter> <mattrberry> No, because that only gets called when it's included in the parent :/
<FromGitter> <Blacksmoke16> maybe nest them like ⏎ ⏎ ```macro included ⏎ macro inherited ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e027f238897197969f0e110]
<FromGitter> <mattrberry> I tried that and couldn't seem to get that to do what I wanted either
<FromGitter> <Blacksmoke16> no?
<FromGitter> <grkek> I fucking love metaprogramming
<FromGitter> <grkek> go and try to do that in any other language
<FromGitter> <grkek> out there
<FromGitter> <grkek> the thing youre trying to do now
<FromGitter> <mattrberry> Building ⏎ ⏎ ``` ⏎ "included" ⏎ "nested inherited" ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5e027f81e0131f50c99da4f2]
<FromGitter> <mattrberry> 1) plus an extra newline that isn't rendering in markdown
<FromGitter> <Blacksmoke16> isnt that what you want?
<FromGitter> <Blacksmoke16> module was included in parent and child inherits from that
<FromGitter> <grkek> Made me think about it @Blacksmoke16 :D
<FromGitter> <grkek> it seems like working ?
<FromGitter> <mattrberry> Really, my goal is to do something with @Groogy's crystal-clear (https://github.com/Groogy/crystal-clear). I'd like the parent to `include CrystalClear`, then have the child define invariants. In its current state, though, only the class including crystal-clear directly is able to actually use the invariant macro
<FromGitter> <Blacksmoke16> where you the one on reddit?
<FromGitter> <Blacksmoke16> asking about obj validation?
<FromGitter> <mattrberry> Haha yeah I was
<FromGitter> <Blacksmoke16> i figured :p
<FromGitter> <Blacksmoke16> so why isnt your example working?
<FromGitter> <Blacksmoke16> dont all you have to do is replace the `p "nested inherited" with `include CrystalClear`?
<FromGitter> <mattrberry> Oh, duh. Just found that in JSON::Serializable too since I was confused why that was working https://github.com/crystal-lang/crystal/blob/41bd18fbea4aec50aad33aa3beb7a0bf30544186/src/json/serialization.cr#L149
<FromGitter> <mattrberry> Thanks!
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <mattrberry> Now I can define a dataclass Tile with runtime contract checking like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e028235c5a23938b4772ce6]
<FromGitter> <Blacksmoke16> nice
<FromGitter> <Blacksmoke16> can shorten that 2nd assertion to `@rotation.divisible_by? 90`
<FromGitter> <mattrberry> Assuming https://github.com/lbarasti/dataclass/pull/1 gets merged. But until then I'll just use my fork :)
<FromGitter> <mattrberry> Oh nice, thanks :)
<FromGitter> <Blacksmoke16> np
teardown has joined #crystal-lang
yukai has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 268 seconds]
<FromGitter> <Groogy> Oh man I'm happy to see someone using Crystal clear:D
<FromGitter> <Groogy> Oh I see the pull request
<FromGitter> <Groogy> @mattrberry I am a bit worried if it might make invariants apply twice using this?
<FromGitter> <Groogy> or you've found it to be fine?
<FromGitter> <Groogy> (if you have an invariant in the parent class instead of only in child)