alexherbo2 has quit [Remote host closed the connection]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
zorp has quit [Ping timeout: 272 seconds]
postmodern has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 240 seconds]
f1refly has joined #crystal-lang
<postmodern>
how do you define an instance variable at the top-level? trying to use ivars in spectator specs for objects that need to be allocated at the beginning and closed at the end
<FromGitter>
<Blacksmoke16> you cant
<FromGitter>
<Blacksmoke16> would have to use a class var in a module
sagax has quit [Ping timeout: 260 seconds]
<postmodern>
how do you escape #{{ macro_here }}?
<postmodern>
\#{{ ... }} isn't doing the trick
<postmodern>
(using macros to generate spectator spec descriptions)
<FromGitter>
<Blacksmoke16> pretty sure you can just do like `"str {{macro_var}} bar"`
<postmodern>
`describe "\#{{ name.id }}" do` is the problem line
<FromGitter>
<Blacksmoke16> and whats the error?
<postmodern>
it's not being interpolated. Spectator is printing out literal `"#{{name.id}}"`
<FromGitter>
<Blacksmoke16> what happens if you get rid of the `\#`
<FromGitter>
<Blacksmoke16> or do like `"\##{{{ name.id }}}"`
<postmodern>
#{{name.id}} and ##{{name.id}}, respectively
<FromGitter>
<Blacksmoke16> can you share some more code?
<FromGitter>
<Blacksmoke16> pretty sure this works
<postmodern>
hmm still getting ##{meta_output} for "\#{{{ name.id }}}", using crystal 0.35.1 and spectator 0.9.23
<FromGitter>
<Blacksmoke16> Hm
<postmodern>
im guessing spectator's macros are double evaluating the string or something?
<FromGitter>
<Blacksmoke16> :shrug: never used it. Not worth the extra dependency/learning the new syntax
<postmodern>
i'm used to rspec syntax, so more of a comfort thing
<FromGitter>
<Blacksmoke16> Fair enough
<FromGitter>
<Blacksmoke16> Granted I also a testing shard that uses a more unit test approach. But it just boils down into standard spec module stuff so :shrug:
<FromGitter>
<Blacksmoke16> Have a*
<FromGitter>
<Blacksmoke16> anyway, im off to bed o/
<FromGitter>
<mattrberry> Hey all, I'm trying to do something a little fun with macros. I don't thing it's actually possible in crystal's macro system, but I just wanted to double check. I'm effectively trying to fill an array with function pointers, almost exactly like this (not my repo, but same idea): https://github.com/wheremyfoodat/Beeg-Advanced/blob/master/src/ARM/arm.rs#L26 ⏎ I'm already doing this at runtime, but I figured
<FromGitter>
... I'd experiment with the macro system just for fun. Is this possible?
<FromGitter>
<naqvis> @mwlang `is_a?` expects a class, not an object or instance. you can use `typeof` in this case. like `is_a?(typeof(fc))` or `as(typeof(fc))`
<FromGitter>
<naqvis> I would suggest to constraint the method arg to some specific parent type, so that compiler can reject calls which doesn't fall under specific hierarchy
<repo>
mattrberry: i'd argue if you're using macros to generate methods, there's no need fill an array with it. You could just as well define them on a class or a module
<repo>
if you _really_ want to have them in something you can later iterate over, you might want to store them in a tuple instead. This way you still have max type safety
<repo>
but imho even then you should just define the methods on a class and just use a macro context to iterate over them (if you need to)
<repo>
but to answer your question: sure it's possible
<repo>
as naqvis pointed out: please use `Channel`
<FromGitter>
<Dan-Do> Okay, I am new :)
<repo>
no problem :)
<repo>
just a thing to keep in the back of your head: when you need sleep because otherwise something doesn't work (regardless of the programming language), you're probably doing it wrong
<repo>
z64: i think it'd be cool to have something like zeromq in native crystal
<repo>
Dan-Do: maybe you should also explain in more detail what exactly you're after. I'm just assuming that you want to have a non blocking way of reading the lines from a process
<repo>
(on stdout)
<FromGitter>
<Dan-Do> I am creating a crystal program that interact with node cli. Normally we use STDIN & STDOUT of terminal
<FromGitter>
<Dan-Do> > *<repo>* in any case i'd go with compile-time template building ⏎ ⏎ compile-time template is not flexible, I also want to build SPA on front-end but still server well when browser disable javascript. Moreover it's better for SEO
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo22 is now known as alexherbo2
postmodern has quit [Quit: Leaving]
alexherbo27 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 272 seconds]
alexherbo27 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 272 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter>
<extremety1989> hey guys
<FromGitter>
<extremety1989> how can i create static method inside class ?
<FromGitter>
<extremety1989> when i loop i and j is type of Int32 how can i fix this error ?
<FromGitter>
<codic12> I have a method that accepts `::Bytes | Nil`, and i want to pass it a String, so I tried `"abc".bytes[..]` (the [..] for converting to a slice) but it still says that it's an Array of UInt8's
<FromGitter>
<naqvis> @codic12 `"abc".to_slice`
<FromGitter>
<codic12> ah, thanks!
<FromGitter>
<naqvis> `#bytes` returns the string bytes as an `Array(UInt8)`
<FromGitter>
<codic12> well, then I get this:
<FromGitter>
<codic12> `Error: undefined method 'to_unsafe' for Nil (compile-time type is (Slice(UInt8) | Nil))`
<FromGitter>
<naqvis> its because you are invoking this method on object which could be null
<FromGitter>
<naqvis> so you need to handle cases where that object is null
<FromGitter>
<codic12> ah, with begin rescue?
<FromGitter>
<naqvis> no
<FromGitter>
<naqvis> exceptions are runtime behavior
<FromGitter>
<naqvis> but Nil handling is compile time behavior
<FromGitter>
<naqvis> you need to either use `if var` or use `try`
<FromGitter>
<naqvis> where `obj` is on what you are calling the `to_slice` method
<FromGitter>
<naqvis> and if you are 100% confident that `obj` will never be nill and willing to accept runtime exceptions then go with `obj.not_nil!.to_slice`
<FromGitter>
<naqvis> i won't suggest this, because in this way you are telling compiler to leave you alone and you know what you are doing :P
<FromGitter>
<codic12> Passing in `"abc".not_nil!.to_slice` doesn't work; so my full line is now `term.feed("abc".not_nil!.to_slice)`, but I get the same erro
<FromGitter>
<codic12> It's hardcoded in the code so I'm sure it will not be nil
<FromGitter>
<naqvis> if hardcoded, then you needn't to call `not_nil!` :P
<FromGitter>
<naqvis> you better make a playground link
<FromGitter>
<codic12> Yeah, but this code is autogenerated, I have no control over it
<FromGitter>
<codic12> I'll file a bug upstream
<FromGitter>
<codic12> Thanks!
<FromGitter>
<RespiteSage> More explicitly (which I sometimes do if code might be read by someone who's not used to Crystal or Ruby): https://play.crystal-lang.org/#/r/9q6u
<FromGitter>
<RespiteSage> No problem. Hope that issue gets fixed for you.
<FromGitter>
<grkek> Crystal 1.0.0 when?
<FromGitter>
<grkek> also I added a preview of the Control gallery to my UI framework https://github.com/grkek/iu
<FromGitter>
<grkek> :)
<FromGitter>
<extremety1989> @Blacksmoke16 i made it :D
<FromGitter>
<Blacksmoke16> 👍 nice!
<FromGitter>
<extremety1989> how can i make
<FromGitter>
<extremety1989> from
<FromGitter>
<extremety1989> [[1,2,3]] to [1,2,3]
<FromGitter>
<extremety1989> ?
<FromGitter>
<Blacksmoke16> `.first`?
<FromGitter>
<grkek> [[1,2,3]].[0]
<FromGitter>
<grkek> export the flatten code to a function
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
postmodern has joined #crystal-lang
<deimos_>
hi, question i can't find an answer to in the docs or source (or maybe i must misunderstood the source). about crystal-db, trying to query 100k items in a hash against psql, it seems crystal-db is doing the queries serially, rather than using the pool size (50). is this correct?
<deimos_>
and should I be able to use Fibers to make this sort of threaded, or at least use up the pool size to run 50 queries at a time?
<FromGitter>
<Blacksmoke16> got some code to share?
<FromGitter>
<Blacksmoke16> afaik (correct me if im wrong) the pool is to allow multiple connections to the db, think two separate http requests
<FromGitter>
<Blacksmoke16> the pool isnt there to allow a single connection to do multiple queries in parallel (but there are some methods defined that do this)
<deimos_>
that's what i thought aobut the pool too, it's there to "parallelize" the queries up to the pool limit
<FromGitter>
<Blacksmoke16> it also depends on what methods you're using, some are scoped to a specific connection, others allow getting a connection from the pool
<FromGitter>
<Blacksmoke16> if you can share some code i can take al ook
<deimos_>
i'm using db_scalar calls, because the query results should be 1 value
<FromGitter>
<Blacksmoke16> alright good so you are using `db`
<deimos_>
there's plenty of other thigns i can clean up
<FromGitter>
<Blacksmoke16> are you passing anything to `.open`? there are some query params
<FromGitter>
<Blacksmoke16> to control the pool
<deimos_>
no, i took the default, which i think is 5
<deimos_>
err, it's 1 pooled connection by default, unlimited pool_size
<deimos_>
psql is limited to 50 per connection
<deimos_>
so in theory, pool_size should grow to 50
<FromGitter>
<Blacksmoke16> could try upping the initial size and see if that makes a diff
<deimos_>
err, max_pool_size
<FromGitter>
<Blacksmoke16> otherwise, fibers would prob be the way to go
<FromGitter>
<Blacksmoke16> the db pool afaik is more focused around the connections to the db, i.e. like if you had two requests come in at the same time that needed to run this code
<deimos_>
if this was ruby, i'd use the parallel gem to run Parallel.each(customer_details) do |cust|
<deimos_>
which does fill the pool and keeps it full until the each was exhausted
<FromGitter>
<Blacksmoke16> again the db pool i think is more so for the connections of the db itself, not as an alternative for you to have concurrent code persay