daemonwrangler has quit [Ping timeout: 260 seconds]
daemonwrangler has joined #crystal-lang
marmotini_ has joined #crystal-lang
akaiiro has quit [Quit: Ping timeout (120 seconds)]
akaiiro has joined #crystal-lang
Tortice has quit [Read error: Connection reset by peer]
Tortice has joined #crystal-lang
Heaven31415 has quit [Quit: Leaving]
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Remote host closed the connection]
return0xe has joined #crystal-lang
marmotini_ has joined #crystal-lang
return0e has quit [Ping timeout: 244 seconds]
_whitelogger has joined #crystal-lang
marmotini_ has quit [Ping timeout: 245 seconds]
Tortice has quit [Ping timeout: 276 seconds]
rohitpaulk has joined #crystal-lang
return0xe has quit [Remote host closed the connection]
return0xe has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter>
<Blacksmoke16> is there a way to unset a field that was set in a JSON::Builder
<FromGitter>
<proyb6> @Blacksmoke16 in which scenario you would unset the field?
rohitpaulk has joined #crystal-lang
<FromGitter>
<proyb6> I want to know the underlying technical details of Crystal http server is rely on fiber? Does it speed up requests if we run 2 instances of http program on the same machine
<FromGitter>
<proyb6> ?
<FromGitter>
<Timbus> if you use a frontend like nginx to balance between two crystal http programs, yes it would speed up requests if the CPU was the bottleneck
<FromGitter>
<Timbus> (and you had a multi-core machine, which these days is almost a given)
akaiiro has quit [Remote host closed the connection]
<FromGitter>
<proyb6> @Timbus i tried to benchmark with wrk in macOS Mojave by running 2 wrk to 2 Crystal http of different port, it still hit the same req/s as 1 Crystal program - hello world string
<FromGitter>
<proyb6> same amount of requests of 40k+ req/s, not sure if macOS has limitations but I wish someone could test on Linux
<FromGitter>
<Timbus> .. a 'hello world' string would take like.. nanoseconds to generate. your bottlenecks would
<FromGitter>
<Timbus> would be in the core*
<FromGitter>
<Timbus> also how did you make the requests to both instances? did you use a load balancer?
<FromGitter>
<proyb6> No load balancer, just ran on 2 wrk on 2 separate terminals at the same time, I see Crystal could hit 100% (Single core) instead of 400% (4-cores) based on the top command, stress test to 200% on 2 Crystal
<FromGitter>
<proyb6> didn’t see any improvements
<FromGitter>
<proyb6> I guess by setup is not sufficient for benchmark
<FromGitter>
<proyb6> By -> my
<FromGitter>
<Timbus> how would wrk test them both? you ran two instances of it?
<FromGitter>
<yxhuvud> @timbus: the normal way to do it is to use a shared socket that both processes listen on
<FromGitter>
<rishavs> has anyone used cockroachdb? Can the current PG drivers be used for it?
<FromGitter>
<proyb6> @Timbus perhaps, I could send you the code to try in PM
<FromGitter>
<Timbus> I can't say that's something I've ever seen done, @yxhuvud .. But it sounds interesting.
<FromGitter>
<yxhuvud> @Timbus SO_REUSEPORT is a good term to look after.
<FromGitter>
<Timbus> yeah i did a quick search
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter>
<Timbus> Works well in crystal I see. Thanks @yxhuvud! I can see it being useful for a bunch of cases.
ashirase has quit [Ping timeout: 252 seconds]
ashirase has joined #crystal-lang
rohitpaulk has joined #crystal-lang
return0xe has quit [Read error: Connection reset by peer]
<FromGitter>
<aboeglin> I have a little question regarding union types
<FromGitter>
<aboeglin> say I have a type X | Y
<FromGitter>
<aboeglin> and X has a method a, Y has a method b
<FromGitter>
<aboeglin> if I know I get a X, I still need to use as ?
<FromGitter>
<bew> How do you know?
<FromGitter>
<aboeglin> because I put it there
<FromGitter>
<aboeglin> the use case is the context storage of Kemal
<FromGitter>
<aboeglin> I have an Auth handler that takes care of querying my user service for endpoints that require auth
<FromGitter>
<aboeglin> and puts the user info in the context
<FromGitter>
<aboeglin> with context.put "user", user
<FromGitter>
<aboeglin> but without as, I get `undefined method 'id' for Bool (compile-time type is (Bool | Float64 | Int32 | Int64 | String | User | Nil))`
<FromGitter>
<aboeglin> I just find it makes the code uglier to have these as everywhere
<Yxhuvud>
aboeglin: `case value; when X; value.a; when Y; value.b; end` ?
<FromGitter>
<aboeglin> what would be great would be to be able to write something like this: ⏎ user : User = env.get "user"
<FromGitter>
<aboeglin> even though get may return `Bool | Float64 | Int32 | Int64 | String | User | Nil`, it would cast it at that time.
<FromGitter>
<aboeglin> I guess using as() on a union type and getting the wrong type would lead to a runtime exception anyways no ?
<FromGitter>
<bew> Yes but then the cast is implicit, that may introduce hidden problems
<FromGitter>
<aboeglin> @yxhuvud this seems way too complex for a simple use case, here I know I'll get a User in 100% of cases.
<FromGitter>
<aboeglin> Do you guys often end up using as ?
<FromGitter>
<bew> Then yes, use as
<FromGitter>
<yxhuvud> then fix your type to something that make sense instead of someting that ca be everything.
<FromGitter>
<aboeglin> I can't in that case
<FromGitter>
<aboeglin> I don't control it, it's from Kemal
<FromGitter>
<yxhuvud> so add a layer of abstraction
<FromGitter>
<aboeglin> I added my type like this: add_context_storage_type(User)
<FromGitter>
<yxhuvud> or ,if it is possible to tell kemal what type that particular attribute is, do that.
<FromGitter>
<aboeglin> well, it'd be too much in that case, I'd rather try to follow the guidance of the web framework I use though. I'll stick with as in that case.
<FromGitter>
<aboeglin> I don't think it is
<FromGitter>
<aboeglin> I guess the env has a Map
<FromGitter>
<aboeglin> and they just provide you with put and get to access it
<FromGitter>
<aboeglin> But I can double check the docs
<FromGitter>
<aboeglin> anyways, I just wanted to know about the union types handling, I guess I have my answer, thanks guys !
<FromGitter>
<bew> Indeed you can't, you need to use as
<FromGitter>
<j8r> I'll rather check the type and restrict if with a `case`/`when`, and raise an exception
<FromGitter>
<j8r> if something goes wrong, you'l get a more meaningful error
<FromGitter>
<aboeglin> and inside that when, I wouldn't need to use as then right ?
<FromGitter>
<aboeglin> sounds good though
<FromGitter>
<aboeglin> the weird part is that I have a middleware doing exactly that, in case I wouldn't get a User it would already just return a 4xx to the client without even going through that code.
<FromGitter>
<aboeglin> one last question, when should we just the keyword `return` ?
<FromGitter>
<aboeglin> I had the compiler screaming at me once because I didn't use it, but most of the time if I do it screams at me too, I'm not sure there's a mention of that in the docs or I must have missed it.
<FromGitter>
<j8r> generally `return` is used to return the value and finish the method call. This avoids executing the code after the return
marmotini_ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @proyb6 say when you would be using `JSON::Serializable` and you want to setup some custom logic in the `on_to_json` method
<FromGitter>
<Blacksmoke16> don really have a specific use case but im not thinking you can
_whitelogger has joined #crystal-lang
marmotini_ has quit [Remote host closed the connection]
<FromGitter>
<aboeglin> @j8r my issue had something to do with captured blocks, is it common to explicitly use the return keyword ? I don't see it used anywhere in the docs.
Jenz has quit [Quit: leaving]
<FromGitter>
<bmulvihill> @aboeglin It is common to use return for guard clauses (returning early from a method if some condition is met).
Jenz has joined #crystal-lang
rohitpaulk has joined #crystal-lang
akaiiro has joined #crystal-lang
<FromGitter>
<drujensen> dumb question. When I ran `crystal -v` a couple week ago, the version was `Crystal 0.26.1 (2018-08-27) LLVM: 6.0.1` but now I get `Crystal 0.26.1 (2018-09-26) LLVM: 6.0.1`. The reason I’m asking is its ~15% slower on my benchmark and I’m wondering if there was a change. I checked the tagged released but there is no bump in date or version so not sure. I did update my Mac OS to mojave so maybe that
<FromGitter>
... would explain it but just curious why the date changed. I’m using `brew` to install it.
<FromGitter>
<Blacksmoke16> that should work i think..
<FromGitter>
<j8r> if you have only an union of two types, this is a good solution @Blacksmoke16 :)
<FromGitter>
<bew> @Blacksmoke16 with long lines, it's hard to see the condition, i always put it as a boock in this case (`unless xxx; raise... ; end` with newlines of courses, not `;`)
<FromGitter>
<drujensen> hhmm, need to make sure you don’t allow someone to update fields you don’t want updated but its pretty cool idea!
<FromGitter>
<drujensen> I guess if the field isn’t annotated, you won’t be able too update it
<FromGitter>
<Blacksmoke16> `readonly: true`
<FromGitter>
<Blacksmoke16> can add that annotation to not set that property from the json
<FromGitter>
<drujensen> 👍
<FromGitter>
<Blacksmoke16> but thats a good point, i should look into how to best handle an update case
<FromGitter>
<Blacksmoke16> currently if its readonly it just sets that field to the default value, which could override a saved record if you dont have logic to set that field
<FromGitter>
<drujensen> yeah, i guess it depends on your business logic on how that would work. Usually you use params validation to avoid directly updating a model. Github was hacked because Rails didn’t have param validation for a while.
<FromGitter>
<Blacksmoke16> but i think that's outside the scope of the project, update/create would be user/orm specific i think
<FromGitter>
<Blacksmoke16> ^^ year
<FromGitter>
<drujensen> right, that would be the dev’s responsibility to avoid it
<FromGitter>
<Blacksmoke16> but if it isnt possible to iterate over each annotation, there would be quite bit more boilerplate to define each assertion annotation macro var manually
helaan has joined #crystal-lang
<FromGitter>
<j8r> there is no doc about annotations :(
<FromGitter>
<Blacksmoke16> yea, what i know is just from going thru the JSON::Serialization stuff
<helaan>
I'm trying to get a piece of Crystal code running on my RPi2 with both my devbox and the RPi2 running Gentoo, but I'm having issues getting a cross-compiler going: I installed LLVM with LLVM_TARGETS="ARM" set, but when I try to crosscompile I get "ERROR: LLVM was built without ARM target (Exception)". Anyone has experience with crosscompiling/Crystal on ARM?
<FromGitter>
<api984> hello
<FromGitter>
<api984> is there any shard for LDAP?
<FromGitter>
<j8r> helaan: you'll need to be aarch64
<jokke>
Hey! Is anyone using traefik as reverse proxy infront of a crystal webapp? I'm experiencing a bug with a webapp run like this: after a while (a few minutes) responses that write json to a reponse object (i.e. object.to_json(context.response)) fail with Broken pipe. Weirdly other requests that access files bundled into the binary with BakedFileSystem work fine. I'm super confused...
<FromGitter>
<j8r> armhf isn't supported yet
<helaan>
Well, that's a good excuse to get my Rpi3 going then
<FromGitter>
<j8r> the most simple is to put Alpine Linux - the edge channel is up to date for aarch64/x86
akaiiro has quit [Remote host closed the connection]
helaan has quit [Quit: WeeChat 2.2]
akaiiro has joined #crystal-lang
Heaven31415 has joined #crystal-lang
<Heaven31415>
Hi
<FromGitter>
<girng> @jenz <3
<Heaven31415>
How can I benchmark Crystal code?
<Heaven31415>
and I don't want to use Benchmark from std, I want to see for example how long do I spend in every method call.
<FromGitter>
<bew> @bajro17 you were just setting local variables
<FromGitter>
<bew> If fallthrough is the second argument, then your second argument will pass false to that argument (and a local variable directory_listing will be created..)
<FromGitter>
<bajro17> Thank you so much it work :)
<FromGitter>
<bew> Your second *exemple
<FromGitter>
<bajro17> I dont know about this hahah
<FromGitter>
<bew> About what?
<FromGitter>
<bajro17> with = and :
<FromGitter>
<bajro17> it mean if override local variable I need to use :
<FromGitter>
<bajro17> if I want follow order of all variables then I can use =
<FromGitter>
<bew> What?? No
<FromGitter>
<bew> Given `def foo(arg);end`, calling `foo(arg = "bar")` is the same as writing `arg = "bar"; foo(arg)`
<FromGitter>
<bajro17> oh I understand now
<FromGitter>
<bajro17> with directory_listing = false I just create new variable
<FromGitter>
<bajro17> Thank you for explain me
<FromGitter>
<bew> Yes exactly
<FromGitter>
<bajro17> I was work before in golang now I little mix programming languages
<FromGitter>
<bajro17> also one quick question what is & used for
<FromGitter>
<bajro17> if I have &variable
<Heaven31415>
it's a block
<Heaven31415>
You mean something like this? `def foo(&block)`
<FromGitter>
<bajro17> yes exactly
<Heaven31415>
so yes, it's a block
daemonwrangler has quit [Ping timeout: 244 seconds]
<FromGitter>
<bajro17> I know its some silly questions but thank you just my brain be little tired of so much switching between languages easy forget some stuff