markoong has quit [Quit: Konversation terminated!]
<FromGitter>
<anamba> so i'm trying to figure out some issues with memory usage that appears to grow without bound over a period of several hours. i tried to see if `GC.collect` would help, but it causes a segfault within a few minutes. as i understand it, ideally, GC.collect should not need to be called manually, but... doing that should not cause segfaults, right?
<FromGitter>
<iambudi> > I actually checked out https://github.com/robacarp/mosquito and it was really easy to add in! ⏎ The name remind me of MQTT
<FromGitter>
<iambudi> @anamba on my microservice app, i even add a scheduler to just call GC.collect every 5 minutes.
<FromGitter>
<konung> Hello. I'm playing with Crystal and love it very much. I'm looking into macros and I'm trying to wrap my head around making it work for namespaced constants. Something similar to Rails's / Ruby's `contantize / Object.get_const` . Here is a somewhat contrived Ruby example ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I tried various approaches with macros, but so far I hit a wall.
<FromGitter>
<dscottboggs_gitlab> @konung Crystal macros are very different from ruby metaprogramming. Its more like a templating language that outputs code.
<mps>
to me, crystal macros more like C macros
<mps>
or, if you like, more like assembly languages macros
<FromGitter>
<konung> @konovod Excellent! Thank you I will look into it and specifically what `id` does. I wast trying to use stingify and but would get nowhere trying to `stringify` `Var & Call`
<FromGitter>
<konung> @konovod @dscottboggs_gitlab Still running into the same issue. I didn't explain it right. The problem is that macro setup that way expects a StringLiteral. But I'm trying to pass a Var. And I'm not sure how I can cast it as String literal if at all possible. See this example
<FromGitter>
<j8r> In Crystal you do the interpreter, unlike in Ruby where we can use it's interpreter to convert Strings to method calls: https://play.crystal-lang.org/#/r/699u
<FromGitter>
<r00ster91> what are those comment pragmas like `#<loc:pop>#<loc:push>` for? Are macros implement using these?
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter>
<konung> @j8r Lightbulb moment . Thank you
<FromGitter>
<konung> So even thou some sights say that Crystal's macros are an answer to metaprogramming. They are not really. That's what was confusing. I see you can use them to - *pre-generate* code instead of writing it out by hand, but the not to eval it dynamically. Am I getting that right?
<z64>
well, it *is* metaprogramming - it is code that generates more code. but it does not have some of the features of ruby's metaprogramming; that can be only "emulated" as you saw above, in a "strict" manner. and yes, that's a way to think about it - pre-generating code instead of writing it out
<z64>
highly recommend asterite's talk on macros. its a bit dated (2016) but the thinking behind macros and when to use them still applies: https://vimeo.com/190927958
<mps>
z64: I would add to you good explanation: generate code at compile time, not at execution time
<FromGitter>
<konung> Thank you
<FromGitter>
<konung> Yep that takes a bit of an ajustment in thinking
<z64>
mps, yep good note :). yw konung
<mps>
macros are confusing for programmers coming from interpreters 'world'
<FromGitter>
<j8r> they are powerful enough to cover virtually all use cases, minus really edge cases
<FromGitter>
<konung> @j8r I thought somebody just mentioned that it should be avoided ( just a few dozen messages above)?
<FromGitter>
<konung> Huh. It was you. I'm going to take a close look right now
<FromGitter>
<konung> Thank. you
<FromGitter>
<j8r> that's me
<FromGitter>
<j8r> and maybe other too like z64
<FromGitter>
<j8r> If you need a full blown interpreter, that's fine. But we usually don't
<FromGitter>
<j8r> better to writing our own case/when to have control, and good perf
Raimondi has joined #crystal-lang
<FromGitter>
<Sija> @anamba yo, what's up with this raven ssl error you had?
<z64>
anyone around that is familiar with StaticArray internals? i can't find where `@buffer` is typed. i'm building a similar type for a special use case, so i was referencing its implementation
<FromGitter>
<Blacksmoke16> so tl;dr you want to read from a csv and have the values be casted to the given types?
<FromGitter>
<Fryguy> You have this line, which is your expectation: ⏎ ⏎ > puts Items[1]["required_level"] should return a String type, with a value of 1, not a union (Int32 | Float64 | String) ⏎ ⏎ but it will always be a union because that's how you declared your Hash [https://gitter.im/crystal-lang/crystal?at=5c67296929bd7b606eb227db]
<FromGitter>
<girng> yeah!
<FromGitter>
<Fryguy> The compiler can't know runtime values, so it can only know but all of the possible types
<FromGitter>
<girng> @Fryguy i could use to_type on them tho right?
<FromGitter>
<girng> to make a new/fresh hash statically typed?
<FromGitter>
<Fryguy> you will always have a union type at the getter, because that's how you defined the values: Items = `Hash(Int32, Int32 | Float64 | String).new`
<FromGitter>
<Fryguy> you would have to create separate hashes *or* cast them after you get them
<FromGitter>
<girng> yeah, i guess that's what i mean, "cast them after"
<FromGitter>
<Fryguy> yes, you can cast them after
<FromGitter>
<Fryguy> but you will have to deal with exceptions if the values are not castable
<FromGitter>
<Fryguy> like if someone put a "string" in the item_id section or whatever
<FromGitter>
<girng> yah hmm
<FromGitter>
<Fryguy> it would be cool if the YAML mapper and JSON mapper had a similar mapper for CSV but I don't think it has it
<FromGitter>
<Blacksmoke16> it doesnt
<FromGitter>
<Blacksmoke16> would be tricky as there isnt a defined schema
<FromGitter>
<Blacksmoke16> would like have to know which index to fetch each value
<FromGitter>
<Blacksmoke16> vs key
<FromGitter>
<Fryguy> yeah, it would have to assume headers
<FromGitter>
<Fryguy> then map header names to index positions or somsething
<FromGitter>
<Blacksmoke16> mhm
<FromGitter>
<Blacksmoke16> probably doable
<FromGitter>
<Fryguy> actually, without headers, I could see just index positions as the key
<FromGitter>
<Blacksmoke16> but you would need a way to map index value to property name if you wanted it to work like json/yaml
<FromGitter>
<Blacksmoke16> could be annotation
<FromGitter>
<Fryguy> yeah true
<FromGitter>
<Fryguy> or if indexes, it just creates fake accessors like "index_0"
<FromGitter>
<Blacksmoke16> @girng any chance you could store this as json/yaml then just do `from_*`?
<FromGitter>
<girng> i do that for levels, quests, and other data, but for items.. all the redudant keys with json result in a huge .txt file. , 40kb compared to just 7kb, and that's only with 82 items in the db, it'll be much larger once i start adding more items. i plan to have hundreds if not thousands. so i really want to stick with csv
<FromGitter>
<girng> for items*. for other data, like levels and quests it's fine
<FromGitter>
<Blacksmoke16> 😐
<FromGitter>
<Blacksmoke16> fair enough
<FromGitter>
<Fryguy> another option is to just zlib compress the data (json duplicated keys should compress really nicely), then feed that Zlib wrapper io into JSON
<FromGitter>
<girng> @Blacksmoke16 let me show you what i wrote so far, one second
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<girng> @Blacksmoke16 for example, look here: https://play.crystal-lang.org/#/r/69dk i casted those properties in the csv, and they are still a union!
<FromGitter>
<Blacksmoke16> well yea it doesnt know at runtime what type it is
<FromGitter>
<Blacksmoke16> sec
<FromGitter>
<girng> that's what @Fryguy is talking about lol
<FromGitter>
<Fryguy> yeah, that's what I was saying about the getter
<FromGitter>
<Fryguy> you have to do a to_i or the like *after* the getter to get the type you want
<FromGitter>
<girng> yeah exactly, i hate that lol
<FromGitter>
<girng> tbut i mean, i'll do it i have to...
<FromGitter>
<girng> i do it all over already hahahahah
<FromGitter>
<girng> i do all this work to get my types casted and then i hve to write .to_xxx.. feels like i'm stabbing myself each time xD
<FromGitter>
<Fryguy> yeah, unfortunately that's the nature of serializing to things that don't support native types
<FromGitter>
<Fryguy> hence why @Blacksmoke16 asked about json
<FromGitter>
<Blacksmoke16> give me a min
markong has joined #crystal-lang
markoong has quit [Ping timeout: 245 seconds]
<FromGitter>
<Fryguy> OMG, LOL, I'm playing around trying to get an example for @girng and nothing's working and I can't figure out why
<FromGitter>
<Fryguy> turns out I typed `irb` instead of `icr` 😂
<FromGitter>
<girng> only reason i'm complaining cause when a player equips an item ineed to check required_level against client.level.. and i wrote `["required_level"].to_i > client.level` and was like EWWW this feels wrong. since i already have my csv_to_dict method and casting them
<FromGitter>
<Fryguy> In that case instead ofusing a Hash -> Union of stuff I woulduse a Hash -> Struct
<FromGitter>
<Fryguy> that way you can define those fields individually
<FromGitter>
<girng> yeah
<FromGitter>
<Fryguy> so it would be `Items[0].required_level` and there you can control the type
<FromGitter>
<girng> basically, i'm wanting a csv.mapping lol
<FromGitter>
<Fryguy> yeah 😄
<FromGitter>
<girng> errr. should i say CSV.mapping 😆
<FromGitter>
<girng> i'm weird though. i don't do thinks conventional or normal in programming. which really, can be a good thing because it allows me to subconsciously write code and makes me feel good. but on the other hand, 95% of the time i end up not being able to solve certain issues and then ultimately confuse myself
<FromGitter>
<girng> but then, if i see fancy code like from lead devs, blacksmoke, or whoever.. my mind is like O_O
<FromGitter>
<girng> @Fryguy nice website 🆒 i thought it was an image at first LOL
<FromGitter>
<Fryguy> oh haha
<FromGitter>
<girng> then i highlighted it all and was like ayyeee
<FromGitter>
<Fryguy> I did that with some gif => ascii tool ages ago, and totally forgot about it 😆
<FromGitter>
<girng> much better than 90% of the websites out there! nowadays, sites are riddled with too much stuff, i hate it
<FromGitter>
<drum445> Anyone mind checking out my (very early) attempt at a kanban app - zaybul.com/kanban ?
<FromGitter>
<Blacksmoke16> content never loads :trollface:
<FromGitter>
<drum445> oh nah ignore that landing page ;)
<FromGitter>
<Fryguy> @girng Here's an example where I used the Zlib class to acts as a compression layer on the json data, should you choose to store it in json instead of CSV - https://play.crystal-lang.org/#/r/69fq
<FromGitter>
<drum445> create a random account (top right) then you can create a board and have a play about :)
<FromGitter>
<Fryguy> I tried to use similar values to show the type of compression you get when there's a lot of duplicated data (in this example roughly 90%)
<FromGitter>
<Fryguy> so, if you were store it in JSON, you could leverage the JSON.mapping, but still not have to worry as much about the size-on-disk
<FromGitter>
<Blacksmoke16> any reason to not use a db for this?
<FromGitter>
<Blacksmoke16> even sqlite wouldn't be too bad
<FromGitter>
<drum445> not sure how much data there is, but sqlite would probably be more performant
<FromGitter>
<Blacksmoke16> > i plan to have hundreds if not thousands. ⏎ ⏎ so not much data
<FromGitter>
<Blacksmoke16> in the grand scheme of things
<FromGitter>
<girng> @Fryguy interesting, thx for the example
<FromGitter>
<drum445> yeah that's very small - if you ever need to update a row though
<FromGitter>
<Fryguy> I agree with the rest on sqlite, though
<FromGitter>
<Fryguy> depends on how static/dynamic the data is
<FromGitter>
<girng> i use also use csv because in godot, parsing a 100kb+ json with redundant keys is much slower than a csv one. i did tests on this. i want the game client to open fast and with csv, it's much faster
<FromGitter>
<girng> so.. i use csv on server file Items data as well, keep it consistent
<FromGitter>
<Blacksmoke16> you do you
<FromGitter>
<Sija> I was pretty sure there was sth like a class initializer `self.init`, anyone had experience with this?
<FromGitter>
<Blacksmoke16> `self.new`?
<FromGitter>
<Fryguy> @Sija or do you mean .allocate?
<FromGitter>
<Sija> no no, I mean a method which gets called just once for a Class
<FromGitter>
<Blacksmoke16> @girng so like does the sever send the client the csv file?
<FromGitter>
<Sija> not *instances* of that class, just the class itself
<FromGitter>
<Sija> seems I was wrong since I can't find any reference to such concept… (many `self.init` definitions but they're all executed manually l8r in the code)
<FromGitter>
<girng> i had to add `LimitNOFILE=655360` under `[System]` in my .service file to get around that limit
<FromGitter>
<anamba> @Sija Thanks for following up. I still haven't had a chance to dig deeper, was just hoping you had some troubleshooting tips, since I was trying to fix a particular issue in my app that was only being reported sometimes by raven. But I ended up fixing that issue in my app yesterday.
<FromGitter>
<Sija> ah, I see.
<FromGitter>
<Sija> my only hunch it was related to crystal ssl handling itself.
<FromGitter>
<Sija> recently there were several ssl-related issues opened on the crystal issue tracker
<FromGitter>
<Sija> sorry I can't help more :/
<FromGitter>
<anamba> @Sija i think you may be correct. i have been having some general ssl issues that i can't quite pin down. i'll check the crystal issues later when i encounter them again