RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <dscottboggs_gitlab> anyone have any ideas on testing what happens when a websocket receives a message?
kandayo has joined #crystal-lang
sp3ncer has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <kandayo> I'm having some trouble understanding why DB.mapping raising "can't cast Nil to UInt64". The column has a not null constraint.
<FromGitter> <kandayo> could someone have a look?
<FromGitter> <Blacksmoke16> could it be returning no rows
<FromGitter> <dscottboggs_gitlab> wouldn't that just give an empty `[] of Tag`?
<FromGitter> <kandayo> year that's weird
<FromGitter> <Blacksmoke16> is that what it was?
<FromGitter> <kandayo> I tried to guard with `return unless res.move_next` and `return unless res` but nah
<FromGitter> <kandayo> how can I check if it's returning no rows?
<FromGitter> <Blacksmoke16> look in the db?
<FromGitter> <Blacksmoke16> and/or the query its making and run the query in the db itself
<FromGitter> <kandayo> it's working fine on psql
<FromGitter> <kandayo> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bfb40ded24f9324d252d7d8]
<FromGitter> <Blacksmoke16> content looks empty tho
<FromGitter> <Blacksmoke16> and in your mapping you have it as not null
<FromGitter> <Blacksmoke16> but is just empty string i imagine...
<FromGitter> <kandayo> it's a empty string ("")
<FromGitter> <Blacksmoke16> hm
kandayo has quit [Quit: Lost terminal]
_whitelogger has joined #crystal-lang
<FromGitter> <kandayo> funny if I set the fields as nilable (guild_id: UInt64?, ... so on)
<FromGitter> <kandayo> it gives "PG::ResultSet#read returned a Int64. A (UInt64 | Nil) was expected"
<FromGitter> <kandayo> wew got it
<FromGitter> <kandayo> pg doesn't support unsigned ints
<FromGitter> <dscottboggs_gitlab> nifty!
<FromGitter> <Qard> @bararchy What I'm trying to do is make an API to add functions to a lua stack. The current design requires procs like `->(stack : Lua::Stack) {}` and then you get the arguments by indexing stack like an array `stack[1]`. I tried implementing range indexing so I could just get all the elements and pass them into `proc.call(*args)`, but splat only accepts tuples, so I need to convert it to a tuple somehow, I guess?
<FromGitter> ... Here's the stack object I'm working with: https://github.com/veelenga/lua.cr/blob/master/src/lua/stack.cr
<FromGitter> <dscottboggs_gitlab> why not just pass it as an array?
<FromGitter> <Qard> I'm trying to have a signature like `->(first : String, second : Int32) {}` when the first and second items in the stack are a string and number.
<FromGitter> <Qard> I basically already have it as an array with the stack, with some extra benefits. I was just hoping I could make something a little more user-friendly than needing to navigate an array to get their function arguments.
<FromGitter> <dscottboggs_gitlab> so the thing about the Array type in crystal is that it doesn't have a set length so there isn't (*yet*) a way to splat arrays or do multiple assignment from an array.
<FromGitter> <dscottboggs_gitlab> you could do proc.call(args[0], args[1]) or restrict args to being a Tuple to make anyone using it use that.
<FromGitter> <dscottboggs_gitlab> I feel like StaticArray (which has a fixed size) might help you but I don't know from experience, maybe someone else does
<FromGitter> <m-o-e> urgh
<FromGitter> <m-o-e> pp MyModel.from_json( "{\"foo\": 32768 }").foo # => -32768_i16
<FromGitter> <Blacksmoke16> got a playground link?
<FromGitter> <m-o-e> that's crecto
<FromGitter> <Blacksmoke16> ah, :shrug:
<FromGitter> <dscottboggs_gitlab> ouch
<FromGitter> <m-o-e> a bit difficult to extract. but in a nutshell: no matter the column data type (int32 here), from_json interprets numbers as int16
<FromGitter> <Qard> The problem is I don't want a fully static size. I want to make a generic method of accepting a proc accepting an arbitrary number and type of parameters and matching that to basically an array that *should* contain that same number of arguments of the same types. I would do some type unwrapping to ensure they match, or raise an exception.
<FromGitter> <m-o-e> looking at the crecto source, i can't find where that even happens, sigh
<FromGitter> <Blacksmoke16> :/
<FromGitter> <dscottboggs_gitlab> @Qard what about something like `->(T) forall T`?
<FromGitter> <dscottboggs_gitlab> the last section here https://crystal-lang.org/docs/syntax_and_semantics/type_restrictions.html
<FromGitter> <m-o-e> found it. if anyone here uses crecto, stick with v0.9.0! => https://github.com/Crecto/crecto/issues/226
<FromGitter> <dscottboggs_gitlab> good to know, thanks!
<FromGitter> <m-o-e> phew, just glad it wasn't always broken. ripping crecto out of this project would've been painful
<FromGitter> <dscottboggs_gitlab> you could always fix crecto ;) that's a big part of why I switched to Crystal, it's approachable the whole way down
<FromGitter> <m-o-e> no time atm unfortunately. also this json stuff looks really hairy.
DTZUZO has joined #crystal-lang
sp3ncer has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <Qard> Hmm...maybe? I'll have to do some experimenting with `forall T` to see if I can figure out a way to make that work.
sp3ncer has quit [Read error: Connection reset by peer]
rohitpaulk has quit [Ping timeout: 272 seconds]
jemc has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @j8r I found this digging around in the compiler today, makes our earlier example a bit more generic for variables: https://carc.in/#/r/5mj8
<FromGitter> <dscottboggs_gitlab> I wonder if there's something similar for methods
jemc has quit [Ping timeout: 268 seconds]
<FromGitter> <j8r> @dscottboggs_gitlab yes i know this, but i takes all ivars. It's used in JSON::Serializable
<FromGitter> <j8r> Depends of the use case
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <bew> @Qard are you aware of the existing Lua for Crystal binding?
<FromGitter> <bew> With notably https://github.com/veelenga/lua.cr/issues/15
sz0_ has joined #crystal-lang
early` has joined #crystal-lang
sz0 has quit [*.net *.split]
FromGitter has quit [*.net *.split]
OvermindDL1 has quit [*.net *.split]
early has quit [*.net *.split]
omninonsense has quit [*.net *.split]
maxpowa has quit [*.net *.split]
sz0_ is now known as sz0
FromGitter has joined #crystal-lang
maxpowa has joined #crystal-lang
[spoiler] has joined #crystal-lang
<FromGitter> <greenbigfrog> Thanks @j8r and @dscottboggs_gitlab got it to work.
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
<jokke> hey
<jokke> any idea what this means? BUG: already had enclosing call
<FromGitter> <vladfaust> Could this code be dried? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bfbd8e1f048fa105125e3e3]
<jokke> yeah
<jokke> i fixed it by definining multiple methods for the different types
<FromGitter> <vladfaust> What?
<FromGitter> <drum445> Where is the best place to store go/crystal release binaries on a server?
<FromGitter> <drum445> atm they just sit in home/ed/, should they be in /var/www...
<FromGitter> <vladfaust> IDK, I always use Docker
<FromGitter> <straight-shoota> @drum445 There is no "best place"
<FromGitter> <straight-shoota> It depends
<FromGitter> <straight-shoota> you should put them where it fits for your setup
<FromGitter> <straight-shoota> for example in project-specific bin directories, or global in /usr/local/bin
<FromGitter> <j8r> how do I pass temp vars to another macro? I have `%var{somevar}`, and I want that in another macro that `%var{somevar}`has the same reference
<FromGitter> <j8r> little example: https://carc.in/#/r/5mkz
<FromGitter> <j8r> I mean this https://carc.in/#/r/5mlc
<FromGitter> <j8r> I expected to be `__temp_23` and not a new `__temp_24`
Vexatos has joined #crystal-lang
<FromGitter> <j8r> I've found this trick to print a temp var `puts {{'"'.id}}%var{var}{{'"'.id}}`
<FromGitter> <j8r> I think I would simply use underscore, like `__myvar` instead of `%vars{myvar}`
<FromGitter> <j8r> side note: strange to only have only regex for `StringLiteral#gsub` https://crystal-lang.org/api/master/Crystal/Macros/StringLiteral.html#gsub%28regex%3ARegexLiteral%2Creplacement%3AStringLiteral%29%3AStringLiteral-instance-method
<FromGitter> <greenbigfrog> How would I go about generating Timespans depending on userinput?
<FromGitter> <greenbigfrog> Regex?
<FromGitter> <j8r> @greenbigfrog look at https://crystal-lang.org/api/master/Time/Span.html
<FromGitter> <greenbigfrog> I guess I didn't ask my question clear enough 😄 ⏎ I want to parse stuff like `10 days` `1 month` etc ⏎ Should I regex it and simply call a Time::Span then, or is there a better way?
<FromGitter> <j8r> from 10, you want make a 10-days time span?
<FromGitter> <greenbigfrog> if user gives `10 days` I basically want the result of `10.days`
<jokke> j8r i think he want's the "days" part to be user inputtable as well
<FromGitter> <greenbigfrog> yep
<jokke> you make a case
<jokke> and yeah, you can parse via regex
<FromGitter> <j8r> yes, `case/when`
<jokke> but maybe splitting is easier
<FromGitter> <j8r> yes, better to avoid regex for this parsing
<jokke> the to_i will fail, if it's not a number
<FromGitter> <j8r> https://carc.in/#/r/5mlj
<jokke> so something like `input = gets(chomp: true); raise ... if input.nil?; split_input = input.split(/\s+/); raise ... unles input.size == 2; amount, unit = split_input; case unit.downcase; when "days" then amount.to_i.days; ...`
<FromGitter> <j8r> the `limit` isn't mandatory - more efficient to define it
<FromGitter> <greenbigfrog> ```code paste, see link``` ⏎ ⏎ sth like this? [https://gitter.im/crystal-lang/crystal?at=5bfbf599d24f9324d25727a7]
<FromGitter> <greenbigfrog> oh. ok. cool. thanks
<FromGitter> <Qard> @bew Yep. That's the exact thing I'm working on, as that task appears to have been abandoned.
Flipez has quit [Quit: The Lounge - https://thelounge.github.io]
Flipez has joined #crystal-lang
Flipez has quit [Client Quit]
Flipez has joined #crystal-lang
<FromGitter> <bew> Well i wouldn't say abondoned, just inactive, you can share your thoughts and talk about what you're doing if you want :)
jemc has joined #crystal-lang
akaiiro has joined #crystal-lang
Renich has joined #crystal-lang
<jokke> is there some oauth server implementation for crystal?
<FromGitter> <kinxer> @jokke I haven't heard of any (and can't find one on GitHub), but there's this (https://forum.crystalcommunity.org/t/implementing-one-time-passwords-in-crystal/57).
<FromGitter> <kinxer> Not an OAuth implementation, but it should help with writing one, yes?
<jokke> hm not sure what otp have to do with oauth :)
<FromGitter> <kinxer> ... Alternately I could properly spell "oauth" in my GitHub search terms and find this (https://github.com/c910335/pineauth) and this (https://github.com/msa7/multi_auth).
<jokke> yeah i found that
<jokke> but it looks prettty abandoned
<FromGitter> <kinxer> Yeah, then I'm out of my depth to help... Sorry.
<jokke> thanks though :)
<jokke> hm seems like i'll have to write my own oauth provider then
akaiiro has quit [Ping timeout: 252 seconds]
<FromGitter> <kinxer> How does `JSON.mapping` interact with inheritance? Can a mapping safely be added to by a subclass?
<FromGitter> <j8r> For this you can use `JSON::Serializable`
<FromGitter> <kinxer> Thank you.
Vexatos has quit [Quit: ZNC Quit]
akaiiro has joined #crystal-lang
jemc has quit [Ping timeout: 252 seconds]
non-aristotelian has joined #crystal-lang
pbodev1 has joined #crystal-lang
<FromGitter> <omidathari> Hello ⏎ I am hoping to get some help with returning an array from a C library into a Crystal program. ⏎ Is there a way to convert a "C" array to a proper Crystal Array? ⏎ Thanks in advance. ⏎ Example code: ... [https://gitter.im/crystal-lang/crystal?at=5bfc4c81a115c91ef798bdc8]
<FromGitter> <bew> In crystal do you know the size of the array? Or do you have the read the C array until some value that marks the end?
WA9ACE has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<FromGitter> <omidathari> @bew No. The C allocates an unknown size and returns it. I was hoping to not have to return the size of the array from C and instead have Crystal handle determining the size. Is that possible?
<FromGitter> <bew> Well, possible, yes but how will you determine the size? Is there some kind of null value at the end?
<FromGitter> <bew> Or 0, or -1 as we're talking about int32w
<FromGitter> <bew> -w
<FromGitter> <bew> Also do you need an Array or a Slice is enough in Crystal world? (do you need to later extend it? Or do you simply want to read from it?)
<oprypin> omidathari, it's really not possible, you have to provide the size as well
<FromGitter> <omidathari> @bew No there is array end indicator. I simply need to read it in Crystal. I have seen that if a C function returns a char* which is actually an array of (Uint8)s indicating a string, In crystal we can use the returned char pointer to create a proper String with "String.new( Uint8*). I was hoping to do the same sort of a thing with array of other types. Thanks for all your help
<FromGitter> <omidathari> @bew No there is no array end indicator of any sort.
<FromGitter> <omidathari> @FromIRC Thanks I'll check it out
<oprypin> omidathari, here's an example with array end indicator, and don't be confused by `Char` - this is actually UInt32 - though the end result is still a string ....
rohitpaulk has joined #crystal-lang
<FromGitter> <bew> @omidathari a string in C is terminated by a NUL char (value 0), that's how `String.new(c_string)` does its thing, if you don't have a way to find the end and you don't have the size, there is no hope ^^
<FromGitter> <omidathari> @bew Thanks very much. So if we are passed the size of the array, what is the syntax to convert the int32* form C to Array(Uint32) in Crystal or do we have to just create and populate ( copy the data passed from C) a new Array in Crystal. Thanks again for all your help
<FromGitter> <bew> If you have the size, the first example from @oprypin can help you
<FromGitter> <bew> You create an array of the specified size, then initialize each slot with a value from the C array
<FromGitter> <bew> This will do a copy of the C array into Crystal world
<FromGitter> <omidathari> @bew got you. Thanks very much.
rohitpaulk has quit [Ping timeout: 250 seconds]
jemc has joined #crystal-lang
jemc has quit [Quit: WeeChat 2.2]
druonysus has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]