laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
renich has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> @girng @theretromaniac carc.in is down but play.crystal-lang.org/ is up
<FromGitter>
<dscottboggs_gitlab> @j8r what do you mean nillable rchop and lchop? In what case would they return nil?
<FromGitter>
<girng> nah it's still down 4 me
<FromGitter>
<girng> i tried carc.in too
<FromGitter>
<dscottboggs_gitlab> yeah I just checked again and you're right
<FromGitter>
<girng> i didn't know how much i relied on it until now lol
<FromGitter>
<dscottboggs_gitlab> for what?
<FromGitter>
<dscottboggs_gitlab> also, I think `String# (Range)` does the most sensible thing already. If the range exceeds the size of the string, it just truncates it. So you should test the resulting substring for size if you want to check if it was successful (@j8r)
<FromGitter>
<girng> just random testing and fiddling around with code haha
<FromGitter>
<dscottboggs_gitlab> why not use `crystal play` locally?
<FromGitter>
<girng> much faster on the playground
<FromGitter>
<dscottboggs_gitlab> It's a bit nicer anyway
<FromGitter>
<girng> for me anyway
<FromGitter>
<dscottboggs_gitlab> oh?
<FromGitter>
<dscottboggs_gitlab> hm. Yeah, idk how I feel about the auto-compiling feature
<FromGitter>
<girng> wait does crystal play do? run the own play on a localhost server?
<FromGitter>
<dscottboggs_gitlab> yes
<FromGitter>
<girng> ohhh wow never knew that was a thing
<FromGitter>
<girng> WOW that's cool
<FromGitter>
<girng> let me test to see if it'
<FromGitter>
<girng> faster*
<FromGitter>
<girng> eh about the same speed. ok cool i'll just do crystal play for now
<FromGitter>
<girng> thanks @dscottboggs_gitlab
<FromGitter>
<dscottboggs_gitlab> yeah no problem, glad you've got a playground to test stuff out in
<FromGitter>
<dscottboggs_gitlab> hey @girng since carc.in is down here's a paste ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ the point is that basically everything has a `#inspect` method that (unless you override it) does the same thing [https://gitter.im/crystal-lang/crystal?at=5c4540b2ba355012a4704823]
laaron has joined #crystal-lang
<FromGitter>
<girng> ic yah
<FromGitter>
<girng> rofl i love when this happens. searching for a answer to something, stumble upon it, and crystal uses the same class naming. https://stackoverflow.com/a/20916980/7873241 just had to remove `;` and `var`
<FromGitter>
<dscottboggs_gitlab> Yeah, I've noticed a lot of common method names with JS
<FromGitter>
<girng> yep same. my fav method name so far has been `chomp` always think of pac man when i use it 😆
renich has quit [Quit: renich]
<FromGitter>
<girng> damn want to add my csv to dict code so i don't have to use union types
<FromGitter>
<girng> then i have to do `to_s` or or is_a? in code.. i want it to define my own types grrr
Raimondi has joined #crystal-lang
<FromGitter>
<girng> if anyone has some time please take a look here: https://paste.ee/p/xP2Jh ⏎ basically i'm trying to make `typeof(Items[2]["type"])` a String only type. since i did `to_s` on it already...
<FromGitter>
<girng> basically my ultimate goal is to static type every single csv value
<oprypin>
@girng: literally the very first line makes the goal unachievable
<oprypin>
and you cannot do this with a loop
<FromGitter>
<girng> -_-
<oprypin>
and I'll say what I've said before
<oprypin>
gotta just write out the code completely manually
<oprypin>
`item.item_id = row.to_i` etc etc
<oprypin>
before that, you create a class for `item`
<FromGitter>
<girng> alright i'll c what i can do
_whitelogger has joined #crystal-lang
<oprypin>
but that's very advanced even compared to other macros
<FromGitter>
<girng> o lawd
<oprypin>
but note that when you use json.parse, you get dicts of unions everywhere. same exact limitation that is useless to try and get around
<FromGitter>
<girng> yeah
<oprypin>
so it can't be a dict, has to be a class, and it's not possible to automate filling out a class with a normal loop
<oprypin>
girng: u can write a simple macro loop tho. `row.each { |item| {% for name, conv in {item_id: "to_i", ... }.items %} if header_name == {{name.stringify}}; obj.{{name.id}} = item.{{conv}}`
<FromGitter>
<girng> workin on it
<FromGitter>
<girng> ohh
<oprypin>
maybe someone can help you finish this cuz i gotta go
<FromGitter>
<girng> okay ty, ima gonna c if i can do this
<FromGitter>
<girng> damn, paste.ee used to highlight crystal too. might have to move bpaste
<FromGitter>
<girng> btw thank you. i like this better instead of unions. but unions make it so simple and easy lol
<FromGitter>
<girng> but i guess. the more knowledge you have... yeah u get my poinot
<FromGitter>
<j8r> @dscottboggs_gitlab i want to rchop/lchop if a string starts/ends with. But internally, that's what they do. Either the starts/ends wirh check is done twice or I do a non optimal `if (substring = string.lchop("prefix")) != string`
<FromGitter>
<j8r> For `String#[Range]`, like `String#[Index]`, it raises when the string is too short
<FromGitter>
<j8r> The `?` variants do the check for us
<FromGitter>
<j8r> With nillable, I simply do `if substring = string[3..9]?` and `if substring = string.rchop? '/'`
<FromGitter>
<dscottboggs_gitlab> but would `"string"[3..9]?` return nil or `"ing"`?
<FromGitter>
<dscottboggs_gitlab> that was my issue
<FromGitter>
<girng> what does 9 do
<FromGitter>
<dscottboggs_gitlab> `3..9` is a range from 3 to 9, including 3 but not 9
<FromGitter>
<dscottboggs_gitlab> `3...9` is a range from 3 to 9, including 3 and 9
<FromGitter>
<girng> but there is only 6 characters, or doesn't matter?
<FromGitter>
<girng> it just goes to the end?
<FromGitter>
<girng> last character
<FromGitter>
<dscottboggs_gitlab> that's my point, after index 5 there's no value, so should indexing that value return nil, the partial selection, or raise an exception?
<FromGitter>
<girng> oh lol
<FromGitter>
<dscottboggs_gitlab> the current behavior is for "string"[3..9] to return "ing", @j8r is saying that should raise, and that the `[]?` version should do that
<FromGitter>
<j8r> [] can raise yes
<FromGitter>
<girng> well. i personally would like it return "ing" instead. if the number is higher, just go the end of the string
<FromGitter>
<j8r> But []? can return nil or string
<FromGitter>
<girng> that's just my opinion but im not a dev hahaah
<FromGitter>
<j8r> `string` was an example variable, not a String itself
<FromGitter>
<dscottboggs_gitlab> oooh! how about if there was `[]` which acts as it does now, `[]?` which returns nil on failure, or `[]!` to raise an exception
<FromGitter>
<dscottboggs_gitlab> but we don't have a `[]!` operator so :/
<FromGitter>
<girng> wow accidentally deleted my comment, dumb gitter UI
<FromGitter>
<vivus-ignis> appreciate any hints, thank you!
<FromGitter>
<dscottboggs_gitlab> I've tried, and not really had luck using debuggers with crystal. You can single-step and see what line you're on but that's about it
<FromGitter>
<dscottboggs_gitlab> idk maybe someone else has some tricks I haven't heard of yet, I haven't used gdb/lldb a lot
<FromGitter>
<vivus-ignis> got it, thanks for sharing
<FromGitter>
<dscottboggs_gitlab> @Blacksmoke16 should run that benchmark on Athena, it doesn't use Radix
<FromGitter>
<AllanKlaus> Anyone can understand why go frameworks are slower than roda (ruby)? (on average
<FromGitter>
<girng> is it possible to use UInt8 with mysql's as {Int8} option?
<FromGitter>
<dscottboggs_gitlab> wouldn't that be an Int8?
<FromGitter>
<dscottboggs_gitlab> not a UInt8?
<FromGitter>
<AllanKlaus> Hey guys, I was wondering to use crystal in production, but someone told me that "If your team can accept break changes and keen in binding C libraries in Crystal, that would be nice." ⏎ ⏎ Do you know what libraries is not working, because use C its not an option in my team?
<FromGitter>
<dscottboggs_gitlab> @AllanKlaus crystal is relatively stable for that sort of workload. I've patched libraries based on several versions of crystal ago easily.
<FromGitter>
<girng> It's a tinyint unsigned in mysql, isn't that a UInt8?
<FromGitter>
<dscottboggs_gitlab> There are still breaking changes you have to account for occasionally and will be for the foreseeable future, but there are still plenty of people using it in production
* FromGitter
* dscottboggs_gitlab shrugs @girng
<FromGitter>
<AllanKlaus> @dscottboggs_gitlab thx guy. I will discuss with my team to adopt Crystal
<FromGitter>
<girng> 🔮
<FromGitter>
<dscottboggs_gitlab> I hope it goes well for you!
<FromGitter>
<girng> @AllanKlaus good luck!!
<FromGitter>
<dscottboggs_gitlab> @girng perhaps it's an issue with the MySql Adapter shard
<FromGitter>
<vlazar> > @vlazar because of reuse port it is more performant you think? ⏎ @j8r yes, other implementations (except for onyx and spider gazelle) are using single process unless I miss something
<FromGitter>
<dscottboggs_gitlab> @vlazar that could explain why Crystal wasn't higher in the ratings as well. I know Kemal has the option to `fork` like onyx does by default, but it's not on by default.
<FromGitter>
<drum445> Seems strange that Crystal is slower though
<FromGitter>
<drum445> Especially as web apis will be a pretty large use-case for it
<FromGitter>
<dscottboggs_gitlab> not if the benchmark emphasised multi-core responses and the default settings were used.
<FromGitter>
<dscottboggs_gitlab> Crystal is primarily single-threaded at this stage
<FromGitter>
<j8r> @dscottboggs_gitlab we could make a PR then :)
<FromGitter>
<dscottboggs_gitlab> to be fair a multi-threaded web server should probably do more than `cpu_cores.times { fork { serve_up } }`
<FromGitter>
<dscottboggs_gitlab> like maybe a bit of error checking
<FromGitter>
<j8r> totally agree, it's counter productive to fork more than the max number of cpus
<FromGitter>
<dscottboggs_gitlab> I'm off to bed, ✌️
<FromGitter>
<mavu> I am trying to use libwiringPI with crystal, and it requires me to pass a callback to C-land. I made a proc that only consists of puts "something". ⏎ That works fine, and It gets called / executed as it is supposed to. ⏎ but how can I actually "interface" this callback with the rest of my program? ⏎ As soon as I try to use outside variables or methods I get "Unhandled exception: passing a closure to C is
<FromGitter>
<mavu> I did find this "Passing a closure to a C function" chapter in the documentation, but its about passing data, and I basically want to use outside functions?
<FromGitter>
<Blacksmoke16> @dscottboggs_gitlab not a bad idea
laaron has joined #crystal-lang
laaron has quit [Client Quit]
laaron has joined #crystal-lang
<oprypin>
mavu: not sure why you say it's about data. seems like it's exactly what you're asking, maybe it's just unclear?
<FromGitter>
<mavu> @oprypin Ok apparently unclear then :) ⏎ I'll read it again and try it. Its already a help knowing it should work.
<FromGitter>
<Blacksmoke16> hm, having trouble running that locally
<FromGitter>
<mavu> Ok, I don't get it. ⏎ this is the function that wants the callback. the callback has not return and takes no arguments. ⏎ fun wiringPiISR(pin : LibC::Int, edge_type : LibC::Int, f : Void -> Void) : LibC::Int
<FromGitter>
<mavu> I don't see how I can give a proc to that function which takes an argument.
<FromGitter>
<mavu> as it seems to me is done in the "Passing a closure" chapter. ⏎ Does anyone have a link to this being done in a example? or actual code?
<oprypin>
the function must accept an arbitrary userdata pointer and then pass it back to the callback
<oprypin>
if it doesn't then indeed you can't do anything about it, at least without having some kind of global state
<FromGitter>
<mavu> Ahhh...
<jokke>
how can i display stack traces in production builds?
<jokke>
--debug ?
<oprypin>
i think so
<FromGitter>
<mavu> Ok, so if the C function that I want to use has this signature: ⏎ int wiringPiISR (int pin, int mode, void (*function)(void)) ; ⏎ which means the callback it takes has no return value and takes no arguments, then I can't do this?
<jokke>
cool thx
<oprypin>
mavu: can't do this. seems like a bad lib ;)
<FromGitter>
<mavu> ok, is there any other way to "break out" of the callback? I mean, I can put "puts something" in there and see the result.
<oprypin>
just don't access any local variables....
<FromGitter>
<mavu> as in instance variables will work?
<FromGitter>
<mavu> I thought I tried that..
<oprypin>
probably not. I'm fuzzy on the details
<oprypin>
well the thing is instance variables depends on the notion of "current object" which is exactly like a local variables
<FromGitter>
<mavu> hmm, i'm not beyond opening a socket and writing to that if it comes to that.
<FromGitter>
<Blacksmoke16> yea that benchmark thing doesnt work for me :/
<oprypin>
@mavu: just use a global variable. which in Crystal means creating a module with a class variable
<jokke>
hmmm
<oprypin>
or uh just directly use a class variable
<jokke>
Invalid memory access (signal 11) at address 0x1c
<jokke>
when i try building with --release and --debug
<jokke>
(and --static)
<oprypin>
static is broken, why u using it
<oprypin>
always been broken
<jokke>
since when?
<jokke>
not on alpine?
<jokke>
works fine
<oprypin>
well it happens to work in some cases on Alpine, whatever
<jokke>
i don't want to have a huge docker image :/
<FromGitter>
<mavu> @oprypin Just tried that, and it seems to work Thanks!
<FromGitter>
<j8r> jokke: you can use multistage build
<jokke>
yeah
<jokke>
that's what i'm currently doing with static
<jokke>
i can use scratch for the final image
<jokke>
which is awesome
<FromGitter>
<j8r> --debug will undoubtly return a larger binary
<FromGitter>
<j8r> Some Go binaries weights ~50MB because of this
<jokke>
wow
<jokke>
dang
<jokke>
but it's necessary for stack traces right?
<FromGitter>
<j8r> I guess that's the added symbols
<FromGitter>
<j8r> used in stack traces
<FromGitter>
<edwardloveall> Hi all, I'm trying to hunt down my problem and I'm wondering if this error message means anything or is just a red herring
<FromGitter>
<edwardloveall> ah right, yes. I get the error part, I was just seeing a similar but different error in the `migration.cr` file there
<FromGitter>
<edwardloveall> the User::BaseForm is expecting a User and String (record and username) which is what I think i'm giving it, but it's not matching for whatever reason
<FromGitter>
<edwardloveall> if anyone wants to dig in futher
<FromGitter>
<edwardloveall> once Lucky is setup with `bin/setup`, I was running `lucky db.migrate`
<FromGitter>
<Blacksmoke16> yea sadly i never used lucky :/
<FromGitter>
<Blacksmoke16> but i feel like that should work since types are correct and everything else has default values
<FromGitter>
<edwardloveall> no worries, thanks for letting me know I'm not crazy :D
<FromGitter>
<edwardloveall> I think I figured it out
<FromGitter>
<edwardloveall> `UserQuery` and `User::BaseForm` are defined when you create a `User` model. the User model in the migration was shadowing another User model previously defined. So i changed the class name to `TempUser` and moved all the other classes to match and it works :slight_smile:
<FromGitter>
<Blacksmoke16> that would do it
<FromGitter>
<nagash> @edwardloveall Ah. I think UserQuery is the problem, as it's global? While the others appear to be locally scoped/generated within the migration. Changing UserQuery to User::BaseQuery may have also worked.
<FromGitter>
<edwardloveall> I beleive that the problem is that UserQuery is giving me a User (of one kind) but I needed a User of a local kind
<FromGitter>
<nagash> Yeah. User::BaseQuery is also generated, so should also be locally scoped if used directly.
<FromGitter>
<nagash> And return the locally scoped Users.