RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | 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> <codenoid> hey
<FromGitter> <codenoid> are you ok ?
<FromGitter> <Blacksmoke16> o/
<FromGitter> <codenoid> is crystal development ok ?
<FromGitter> <Blacksmoke16> is going well for me yes
<FromGitter> <codenoid> great, have fun ! :flyaway:
<FromGitter> <silmanduin66> @Blacksmoke16 could you tell me how to get back data with granite
<FromGitter> <silmanduin66> i managed to save my data
<FromGitter> <Blacksmoke16> `Model.find PK`?
<FromGitter> <Blacksmoke16> or `Model.first`
<FromGitter> <silmanduin66> oh that simple
<FromGitter> <Blacksmoke16> yes
<FromGitter> <silmanduin66> haha thanks
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> is also the bang versions of those `User.find!` or `User.first!` that will raise if a record is not found
<FromGitter> <Blacksmoke16> while non bang ones will return `Nil | Model`
<FromGitter> <silmanduin66> that's even better
<FromGitter> <Blacksmoke16> depends on context of which would be best to use
<FromGitter> <silmanduin66> yeah but i was looking for that too ^^
<FromGitter> <Blacksmoke16> 👌
<FromGitter> <Blacksmoke16> are also a few others
<FromGitter> <Blacksmoke16> like .where or .find_by
<FromGitter> <Blacksmoke16> or .all
<FromGitter> <Blacksmoke16> etc
<FromGitter> <silmanduin66> and if i want to get all with ID below 50 ?
<FromGitter> <silmanduin66> should i iterate ?
<FromGitter> <Blacksmoke16> could do like `Model.where(:id, :lt, 50)`
<FromGitter> <silmanduin66> ok i ll use that
<FromGitter> <Blacksmoke16> iirc its lazily loaded, so wont actually execute the query until you need it
<FromGitter> <Blacksmoke16> by like doing a `.each` or `.to_a` on it
<FromGitter> <Blacksmoke16> was thinking of doing a blog post/tutorial for a blog json api using athena
<FromGitter> <Blacksmoke16> give it a little playtest
<FromGitter> <silmanduin66> can i save JSON into my granite database using ```.to_s``` ?
<FromGitter> <silmanduin66> i have a ```String``` field
<FromGitter> <Blacksmoke16> sure
<FromGitter> <Blacksmoke16> would be returned as a string tho
<FromGitter> <silmanduin66> but is it how it should be done
<FromGitter> <Blacksmoke16> vs like `JSON::Any`
<FromGitter> <Blacksmoke16> you using PG?
<FromGitter> <silmanduin66> yes
<FromGitter> <silmanduin66> then how to convert back to json
<FromGitter> <Blacksmoke16> would have to manually do a like `Model.from_json` or `JSON.parse`
<FromGitter> <silmanduin66> oh
<FromGitter> <Blacksmoke16> depending on what you're storing might be a better idea to make another table and setup a relationship
<FromGitter> <silmanduin66> can I / should I directly save as json ?
<FromGitter> <Blacksmoke16> ^^
<FromGitter> <silmanduin66> it's a message
<FromGitter> <silmanduin66> with user id, textfield, time
<FromGitter> <Blacksmoke16> why not just have a `Message` table with those columns?
<FromGitter> <silmanduin66> hmm i create a message model but my problem is that i want to make them accessible to my javascript
<FromGitter> <silmanduin66> so for the moment i only know how to deal with json
<FromGitter> <Blacksmoke16> using a front end framework as well?
<FromGitter> <Blacksmoke16> or server rendered using like amber or something?
<FromGitter> <silmanduin66> hand made
<FromGitter> <silmanduin66> oh yes amber framework of course
<FromGitter> <silmanduin66> but i made the basic javascript i needed
<FromGitter> <silmanduin66> amber.js yes
<FromGitter> <Blacksmoke16> normally you would have an endpoint that you can make an HTTP request from the js to get the data
<FromGitter> <Blacksmoke16> but i remember @dscottboggs_gitlab mentioning there is something you can do with amber.js and websockets?
<FromGitter> <silmanduin66> yes that's exactly what i'm trying
<FromGitter> <Blacksmoke16> but i never used it and dont know anything about it :/
<FromGitter> <silmanduin66> my websockets are working
<FromGitter> <dscottboggs_gitlab> it's just a minimal wrapper around websockets
<FromGitter> <dscottboggs_gitlab> like 100 lines or something, I just happened to notice it the other day
<FromGitter> <silmanduin66> the only thing left i need to do (for the moment ) is to get the data from the database and send it
<FromGitter> <silmanduin66> just idont know if i shoudl save as json or what
<FromGitter> <silmanduin66> i have actually never used json before today :-P
<FromGitter> <dscottboggs_gitlab> yeah either json or that binary format @Sija mentioned earlier if you don't mind adding the JS dependency
<FromGitter> <dscottboggs_gitlab> json is the easiest
<FromGitter> <silmanduin66> i lookd but i dont' understand anything XD
<FromGitter> <Blacksmoke16> yea json is nice, matches up with js objects pretty much
<FromGitter> <dscottboggs_gitlab> just `send Array(SerializableStruct).to_json` on the server and `JSON.parse(recievedContent)` on the client
<FromGitter> <silmanduin66> but can i directly save json via granite ?
<FromGitter> <dscottboggs_gitlab> @silmanduin66 https://crystal-lang.org/api/0.27.2/JSON/Serializable.html
<FromGitter> <dscottboggs_gitlab> Any struct or class
<FromGitter> <Blacksmoke16> would be better to store them in a separate table
<FromGitter> <Blacksmoke16> then you could do like `User.messages!.to_json`
<FromGitter> <Blacksmoke16> tada
<FromGitter> <Blacksmoke16> where the bang would raise if they dont have any messages, so prob might want to check if its empty or not first
<FromGitter> <dscottboggs_gitlab> yes, or I often use a struct namespaced under the one that I'm working with
<FromGitter> <Blacksmoke16> where your messages table would be like `id, user_id, message, etc`
<FromGitter> <dscottboggs_gitlab> so if you have a users model you could add a `Users::Serialized` struct, then use `user.serialize.to_json`
<FromGitter> <Blacksmoke16> not needed, `Granite` has the serializable stuff built in
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <Blacksmoke16> to `.to_json` on your model obj would work just find
<FromGitter> <dscottboggs_gitlab> nice
<FromGitter> <Blacksmoke16> also supports third party annotations so could use CrSerializer or something if you needed additional features
<FromGitter> <Blacksmoke16> like limiting what gets serialized and such
<FromGitter> <dscottboggs_gitlab> woah, you should have an example for that in CrSerializer, that's super useful
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6b5bf735c7a5042274cb1b]
<FromGitter> <Blacksmoke16> woudl be something like that
<FromGitter> <Blacksmoke16> *magic*
<FromGitter> <dscottboggs_gitlab> interesting that it goes on the class
<FromGitter> <silmanduin66> ok i just did the simplest solution for me with .to_s and it worked
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab the class annotation basic tells it *only* serialize properties that have `expose: true` vs all properties *except* ones with `expose: false`
<FromGitter> <Blacksmoke16> @silmanduin66 fair enough, i dont think thats the best solution but prob works for now
<FromGitter> <dscottboggs_gitlab> to_s worked?? I'm surprised that worked at all..
<FromGitter> <dscottboggs_gitlab> I see, I didn't notice the annotations note on the macros below at first
<FromGitter> <Blacksmoke16> like do you have a `messages` column thats just like json encoded array of messages on the user record?
<FromGitter> <Blacksmoke16> yea, no other way to add the annotation since they are added by macro :/
<FromGitter> <silmanduin66> no i had to convert to_s and back to json
<FromGitter> <silmanduin66> just one column "content"
<FromGitter> <silmanduin66> maybe i ll change later, i just wanted to see if my app was working so far
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <Blacksmoke16> always optimize it later
johndescs has quit [Ping timeout: 250 seconds]
johndescs has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 255 seconds]
DTZUZO_ has quit [Ping timeout: 268 seconds]
[spoiler] has quit [Ping timeout: 268 seconds]
[spoiler] has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
DTZUZO_ has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
laaron has joined #crystal-lang
laaron- has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
marmotini_ has joined #crystal-lang
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
hightower2 has joined #crystal-lang
ashirase has quit [Ping timeout: 250 seconds]
DTZUZO_ has quit [Ping timeout: 255 seconds]
ashirase has joined #crystal-lang
fanta7531 has joined #crystal-lang
fanta7531 has quit [Quit: fanta7531]
fanta7531 has joined #crystal-lang
sz0 has joined #crystal-lang
fanta7531 is now known as fanta7531|away
gwosix has joined #crystal-lang
<FromGitter> <silmanduin66> @Blacksmoke16 is there a way i can directly get the ID of something that i save in the database with granite? ( I mean not having to query it )
<gwosix> simple question: how do i download a video? maybe i've been doing it wrong
<gwosix> http::client and then copy the .body_io to some file right?
<FromGitter> <Blacksmoke16> @silmanduin66 after you call `.save` it sets the `id` property on the model
<FromGitter> <Blacksmoke16> i.e.
<FromGitter> <Blacksmoke16> ```model.id # => nil ⏎ model.save ⏎ model.id # => 1``` [https://gitter.im/crystal-lang/crystal?at=5c6c0445c776985d8f1b3af3]
<FromGitter> <Blacksmoke16> or whatever the is
<FromGitter> <silmanduin66> oh ok
<FromGitter> <silmanduin66> sorry i feel my questions are really dumb :-P
<FromGitter> <Blacksmoke16> np
<FromGitter> <saturn-network> Hello! I'd like to start by thanking both crystal and amber devs for the incredible product that you have created. Migrating from rails was a joy, and we got a more lightweight and 100x faster API with minimal rewrites
<FromGitter> <saturn-network> The only thing that's really missing is proper redis caching. Using crystal-redis library in production turned out to be a nightmare. The dynos would run out of memory, despite following advice of using pooled connections
<FromGitter> <saturn-network> I would appreciate if someone would share some pointers on either of these two topics: ⏎ ⏎ 1) how to use redis caching in production with amber ⏎ 2) how to create a crystal shard that's a wrapper around a C library [https://gitter.im/crystal-lang/crystal?at=5c6c0651c82c68509e00aa98]
<FromGitter> <spTorin> <gwosix> ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c6c069ea7d733509d905f0d]
<FromGitter> <gwu_gitlab> yeah
<FromGitter> <gwu_gitlab> i'm writing a ytdl
<FromGitter> <gwu_gitlab> that seams to screw up the endings for some reason
<FromGitter> <gwu_gitlab> @spTorin also that crashes.
<FromGitter> <gwu_gitlab> https://ptpb.pw/VIZz.png
<FromGitter> <saturn-network> I suspect this might be the issue https://github.com/ysbaddaden/pool/issues/2
<FromGitter> <asterite> @saturn-network You mean https://github.com/stefanwille/crystal-redis ? If there's a problem I would report it there. I can try to see what can be improved. About a shard around a C library, there's a section in the docs (specific to binding to C): https://crystal-lang.org/reference/syntax_and_semantics/c_bindings/ (you need to know C, more or less)
<FromGitter> <saturn-network> know C is not a big problem
<FromGitter> <asterite> @saturn-network "proper redis caching" -> is this something the crystal library doesn't support, or what is it?
<FromGitter> <saturn-network> learn the quirks of hiredis is harder :)
<FromGitter> <saturn-network> proper = without memory leaks :)
<FromGitter> <saturn-network> I can't tell what exactly is leaking in crystal-redis
<FromGitter> <saturn-network> people with similar issues have pointed out that using PooledClient supposedly solves the problem
<FromGitter> <saturn-network> pooled client relies on pool shard
<FromGitter> <saturn-network> and perhaps the problem is here https://github.com/ysbaddaden/pool/issues/2
<FromGitter> <saturn-network> now I am battling ⏎ ⏎ 1) either figure out where the memory leak is in crystal-redis (no idea where to start) ⏎ 2) or figure out how to write a hiredis wrapper (sounds hard) ⏎ 3) or set a cronjob to restart heroku dynos every 30 minutes (lol) [https://gitter.im/crystal-lang/crystal?at=5c6c0c58c82c68509e00d2a3]
<FromGitter> <asterite> oooh... the pool issue is bad :(
<FromGitter> <saturn-network> yeah I think that's what's up
<FromGitter> <saturn-network> I think what's happening is that amber's router spins up a coroutine to handle the HTTP request, hence the need for thread-safe connection pool
<FromGitter> <saturn-network> and the connection pool just creates the connections without doing any maintenance afterwards
<FromGitter> <saturn-network> does this sound reasonable to you? maybe you have other ideas
<FromGitter> <asterite> to be honest, I'm not really familiar with any of the code in there (amber, pool, crystal-redis)
<FromGitter> <asterite> I'm just giving ideas about how to debug it or fix it :-)
jemc has joined #crystal-lang
<FromGitter> <asterite> but Id try to consistently reproduce the problem first... somehow
<FromGitter> <saturn-network> haha. it's really hard
<FromGitter> <saturn-network> since the author claims to have written the fastest redis client ever https://github.com/stefanwille/crystal-redis
<FromGitter> <saturn-network> and he benchmarked it a lot
<FromGitter> <saturn-network> the only way I know to reproduce the bug is to deploy redis cache to production
<FromGitter> <saturn-network> and wait 4 hours :)
<FromGitter> <asterite> and that only happens when pooling? and never locally?
<FromGitter> <saturn-network> without pooling there are worse issues
<FromGitter> <saturn-network> because every request is processed in a coroutine
<FromGitter> <saturn-network> I presume locally I can reproduce with enough load testing and if I let my machine run for a little while
<FromGitter> <saturn-network> pools seem to be very tricky
<FromGitter> <saturn-network> https://github.com/ysbaddaden/pool/issues/3
<FromGitter> <gwu_gitlab> @saturn-network how should i deal with my exceptions, and hopefully fully transferred files
<FromGitter> <asterite> > because every request is processed in a coroutine ⏎ what's the problem with that? HTTP::Server does that by default
<FromGitter> <bararchy> Is anyone else have issues with specs and CircleCI, things that work locally won't work on circle
<FromGitter> <gwu_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6c0fecab952d308558a6d1]
<FromGitter> <gwu_gitlab> i'm getting a lot of this.
<FromGitter> <saturn-network> @asterite there is no problem with that
<FromGitter> <saturn-network> but accessing a socket from coroutines without a mutex does not sound like a great idea to me
<FromGitter> <saturn-network> @gwu_gitlab `try..catch` ?
<FromGitter> <gwu_gitlab> should i not worry about the files being transferred? (i can probably assume that the file ends there, right?
<FromGitter> <saturn-network> no clue, honestly. I'd rather admit I'm not qualified than give bad advice
<FromGitter> <gwu_gitlab> totally fine
<FromGitter> <asterite> @saturn-network ah, right. So yes, redis should use a connection pool to checkout a new connection on every different fiber, and then return it back to the pool after the request is done. So I guess the problem is that the connection doesn't return to the pool for some reason?
devil_tux has joined #crystal-lang
<FromGitter> <saturn-network> something along those lines
<FromGitter> <saturn-network> I think the app might run out of memory because of amber's request buffer
<FromGitter> <saturn-network> the symptom is that the web server stops responding - redis.get just freezes
<FromGitter> <saturn-network> saw your ping on the gh issue
<FromGitter> <asterite> the main issue is that we don't know where the problem is. Maybe amber is doing something wrong
<devil_tux> is there native transformation of json to xml in crystal without previous mapping?
<FromGitter> <asterite> no, there's no much support for xml in the std except for reading an xml
<FromGitter> <bararchy> @asterite We are getting some stragne issues ourselves with HTTP::Client and HTTP::Server playing together in specs
<FromGitter> <asterite> probably the changes to them in the last releases broke something
<devil_tux> asterite: gotcha, ty
Jenz has joined #crystal-lang
<FromGitter> <j8r> better to use Proof Of Stake then
<FromGitter> <saturn-network> :)
<FromGitter> <saturn-network> proof of work is actually the cheapest of viable alternatives
<FromGitter> <saturn-network> consider how much energy is being spent on traditional banking
<FromGitter> <saturn-network> plus, PoW mining pushes miners towards cheaper renewables (although that's not without externalities either). It's a global competition to reduce energy cost, and miners arbitrage it
<FromGitter> <saturn-network> the whole point of PoW is that you need to burn some real world physical asset, i.e. a lump of coal, in order to create a digitally scarse good
<FromGitter> <j8r> That's still a waste :|*
<FromGitter> <saturn-network> proof of stake is still in researcher's testbeds (eth2.0 and cardano being the two chains closest to production rollout), and it is a bit of a perpetuum mobile - it tries to become valuable by being a fuel for valuable apps. if price of a PoS token drops significantly an attack can be easily executed
<FromGitter> <j8r> exactly like producing money, coins and banknotes :/
<FromGitter> <saturn-network> it's a waste-by-design: you burn something IRL in order to produce a digital commodity
<FromGitter> <saturn-network> yes, PoS is closer to fiat in terms of its monetary policy and how it derives value
<FromGitter> <j8r> but nowadays more and more money is entirely virtual
<FromGitter> <saturn-network> fiat, however, has useful "apps", i.e. buy groceries
<FromGitter> <saturn-network> and blockchains are only starting to venture into usefulness
<FromGitter> <saturn-network> you might want to follow #defi on twitter: things like MakerDAO, Dharma Lever, compound
<FromGitter> <saturn-network> and you can follow us, of course :)
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter> <saturn-network> if you want to write "dApps" in crystal, I believe EOS's smart contracts are wasm compiled
<FromGitter> <j8r> looks like you know the topic well :)
<FromGitter> <saturn-network> so it's definitely possible
<FromGitter> <saturn-network> @j8r gotta be good at something
<Jenz> Seen https://sushichain.io, @saturn-network? Looks quite cool
<FromGitter> <saturn-network> did see it
<FromGitter> <saturn-network> the value proposition is "hey we're writing a blockchain IN CRYSTAL"
<FromGitter> <saturn-network> they'd be better off writing an alternative implementation of Ethereum or Bitcoin in crystal rather than a new blockchain
<FromGitter> <saturn-network> unless you've got some insanely good marketing wizards who can spin sushichain as ETH killer blockchain v7.75
<Jenz> > a blockchain IN CRYSTAL
<Jenz> Yeah exactly :D
<FromGitter> <saturn-network> well that's a financially useless value proposition
<FromGitter> <saturn-network> it is a toy project, nothing serious
<FromGitter> <saturn-network> as long as devs are having fun and learning new things it's all good tho
<rkeene> I wrote a Blockchain in Tcl
<rkeene> It's much cooler.
<Jenz> rkeene: O_o
<Jenz> And we agree all's good saturn-network
<Jenz> And btw your nick is a pain to type XD
<FromGitter> <saturn-network> bind a key
<Jenz> Haha
<FromGitter> <saturn-network> that's more like it!
* Jenz :o Nice docs
<rkeene> It looks better using man(1) -- there's actually no good man->html tools
fanta7531|away has quit [Quit: fanta7531|away]
<Jenz> And fossil eh? Never tried it, how is it?
<rkeene> It's good -- I've been using it for a while and host chiselapp.com
<rkeene> I also migrated the Tcl project from CVS to Fossil, after SourceForge was down for like a month
<Jenz> Huh, very cool
<FromGitter> <asterite> @saturn-network I suggest you post an issue in amber
<FromGitter> <saturn-network> currently tracking here https://github.com/stefanwille/crystal-redis/issues/79
return0e_ has quit [Remote host closed the connection]
return0e has joined #crystal-lang
<FromGitter> <bajro17> I have problem on Manjaro
<FromGitter> <bajro17> I cant install anymore crystal
<FromGitter> <bajro17> every mirror return 404 not found
marmotini_ has joined #crystal-lang
moei has quit [Quit: Leaving...]
<Jenz> @bajro: sudo pacman -Syu
<Jenz> Will synchronize and update all packages
<Jenz> Unless manjaro does it differently
<Jenz> But I think not
<Jenz> Uh, I mean @bajro17, with the 17 yes
<FromGitter> <kinxer> @Jenz, yeah it definitely seems like someone who just doesn't have experience with statically-typed, compiled languages and is complaining that they're different from dynamically-typed languages.
<rkeene> I think they're complaining that it's hard to express the dynamicness at times
<FromGitter> <kinxer> I don't understand what you mean, @rkeene. Could you explain?
<Jenz> The most irritating part is when straight-shoota (very cool guy), comes with a working example, and OP just responds with the part that makes it work cut of, pretty much saying *but* look at this! It doesn't work anymore!
<FromGitter> <j8r> the biggest issue with dynamic languages is for me refactoring. It's a hard with static languages, and a pain with dynamic one
<rkeene> kinxer, His example seemed pretty clear -- he wants to be able to store any type of object in a hash for later retrevial
<Jenz> Yeah but then just don't store any type of object in a hash... Or restrict the types that is to be stored
<Jenz> Use and ORM, whateve
<Jenz> -r
<rkeene> IIRC, Crystal has an object boxer so you can do this ? He just doesn't know about it and is having trouble expressing his idea in Crystal because of it
<rkeene> I seem to recall using this when writing my Crystal<->Tcl interface
<Jenz> I don't think it's a good idea too store any type of object in a hash, at the very worst you could use an union of a dozen types, but it just seems stupid
<Jenz> bindings you mean? He doesn't seem to be the low-level type
<Jenz> And Crystal<->Tcl you say? Care to share a link? Sounds interesting
<FromGitter> <j8r> I don't think it's worth bother with people like this
<mps> OP doesn't understand _strong_ typed (statically, sometimes called) paradigm and it's advantages
<FromGitter> <j8r> If he is unhappy, that's. We can just tell him to try another compiled language
<FromGitter> <kinxer> I agree with @Jenz. It may be that Crystal simply isn't the right tool for what he is trying to accomplish, but I think he's probably just not structuring his code in a way that makes sense for Crystal (or likely any statically-typed language). It just seems to me that he's condemning Crystal for being a statically-typed language that doesn't let you write fully dynamically-typed code. Granted, type inference is
<FromGitter> ... a huge benefit of using Crystal, but static typing is a feature, not a bug.
<rkeene> j8r, Tcl can be AOT compiled *AND* it can do what he wants ;-)
<Jenz> rkeene: Oh shut up with the Tcl will ya XD (just kidding)
<Jenz> IMO Tcl's ugly, crystal's not :P
<Jenz> Though I have to admit I never tried the lang myself
<FromGitter> <j8r> not AOT, compiled to machine language
<rkeene> j8r, Tcl can be AOT compiled to machine language.
<oprypin> j8r, thats what AOT stands for, as opposed to JIT
<oprypin> but so can Python, lol
<FromGitter> <j8r> ha yes
<rkeene> It uses LLVM
<rkeene> I'm pretty sure Python is compiled to Python bytecodes, where Tcl is compiled to x86_64 or whatever your CPU is
<Jenz> AOT is compilation of vm-bytecode to machine code, yes?
<FromGitter> <j8r> it can be compiled with an embedded VM?
<Jenz> If it's directly from Tcl to machine code I don't think it's AOT, but just normal compilation, though I dunno
<rkeene> j8r, It gets compiled to LLVM IR, which is then turned into whatever LLVM supports
<rkeene> Jenz, AOT just means ahead-of-time, so you can compile it without ever running it
<Jenz> Hmm
<FromGitter> <j8r> ok, let him to try TCL then lol
<rkeene> I was not specific enough initially, Tcl can be AOT compiled into native code
<FromGitter> <j8r> If he struggles with Crystal, he would be certainly happy with Tcl 😀
<Jenz> Haha
<Jenz> rkeene: alright thanks, now I'm following
<rkeene> As a bonus, he would get Threads, many more platforms, better distribution mechanisms, and a whole lot more :-D
<Jenz> OP would not like Java, hehe
<Jenz> rkeene: it sounds like you're talking about C
<Jenz> At least that last message there
<rkeene> Jenz, Nope, Tcl
<Jenz> ik, 'twas an attempt at a joke
<Jenz> Quite unsuccesful
* Jenz XD
<Jenz> I mean, I'm pretty confident C has threads, more platforms, better distribution mechanisms, and a whole lot more than Tcl. Though much unsafer
<Jenz> Needless to get into here though
<rkeene> But with Tcl, hash tables can hold any type.
<Jenz> True :)
<z64> yeah, you can have tables of pointers in crystal to get "around" unions and store anything of whatever type but this has limitations / isn't safe
<Jenz> Nice chatting with y'all, gtg
Jenz has quit [Quit: leaving]
oprypin has quit [Remote host closed the connection]
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <Prutheus> Can someone please help me fast? This is a very big security issue in a running product … I hope I can fix it fast.
DTZUZO_ has joined #crystal-lang
<rkeene> ?
<FromGitter> <Blacksmoke16> @Prutheus try doing `_email == email & _password == password`
<FromGitter> <Blacksmoke16> that query is getting resolved to something like `select * from users where true = true`
<FromGitter> <Blacksmoke16> https://imdrasil.github.io/jennifer.cr/docs/query_dsl `&` is the operator for an AND clause
rohitpaulk has joined #crystal-lang
<FromGitter> <Prutheus> @Blacksmoke16 then I get a compile error: ⏎ ` ⏎ in controller/auth_controller.cr:16: instantiating 'User.class#where()' ⏎ ⏎ pp User.where {_email == email & _password == password}.results ... [https://gitter.im/crystal-lang/crystal?at=5c6c4580a7d733509d92299f]
<FromGitter> <Blacksmoke16> try just comma separated then?
<FromGitter> <Prutheus> unexpected token @Blacksmoke16
<FromGitter> <Blacksmoke16> how about `.where { and(_email == email, _password == password) }`
<FromGitter> <Blacksmoke16> or `.where { (_email == email) & (_password == password) }`
<FromGitter> <Prutheus> the first with `and(a,b)` rescues in an error `Condition tree can't be blank.`
<FromGitter> <Prutheus> `.where { (_email == email) & (_password == password) }` returns no results from the database
<FromGitter> <Blacksmoke16> omg how about
<FromGitter> <Blacksmoke16> `.where { *email == email}.where {*password == password}`?
<FromGitter> <Prutheus> oh wait
<FromGitter> <Prutheus> my mistake, `.where { (_email == email) & (_password == password) }` works well, thanks!
<FromGitter> <Blacksmoke16> cool
<FromGitter> <Prutheus> thanks
<FromGitter> <Prutheus> man just caused by my mistake ...
<FromGitter> <Prutheus> xD
<FromGitter> <Prutheus> your answer have I found in the docs before, too
<FromGitter> <Prutheus> haha
<FromGitter> <Blacksmoke16> :p
<FromGitter> <asterite> wow. despite the `&` maybe being a bit confusing, jennifer.cr looks really cool and powerful. It seems type-safe too (when using underscores to refer to columns), right?
<FromGitter> <Blacksmoke16> not super sure, havent used it much
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
druonysus has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
Creatornator has quit [Client Quit]
<mps> RX14: is that right in specs spec/std/kernel_spec.cr:249 for 0.27.2 'Failure/Error: error.should contain("Stack overflow")'
<mps> we expect 'Stack overflow'?
oprypin has joined #crystal-lang
Creatornator has joined #crystal-lang
marmotini_ has quit [Ping timeout: 255 seconds]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter> <girng> i'm curious why the bottom way (using a property in a class doesn't work), but without using a property of a class, it works? ⏎ https://play.crystal-lang.org/#/r/6aql ty in advance
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Blacksmoke16> prob because local vars like that arent as strictly typed
<FromGitter> <girng> i changed it to `p1.gold -= fee_amount.to_i` and now i'm a happy camper
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6aqr same error when you strictly type the local var
<FromGitter> <Blacksmoke16> not better to have it as a float from beginning? what if they get cents back or something?
<FromGitter> <girng> is `Int64 = 2000_i64` different than `user_gold = 2000_i64`?
<FromGitter> <girng> what's the _i64 do then
<FromGitter> <j8r> that's why more we can avoid floats, better it is
<FromGitter> <j8r> for perf too
<FromGitter> <Blacksmoke16> ```class Client ⏎ property gold = 2000_i64 ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c6c5f91b6c74f1e2e7b4ff4]
<FromGitter> <Blacksmoke16> in this case `gold` is implicitly assigned type of `Int64` i.e. same as doing `property gold : Int64 = 2000_i64`
<FromGitter> <Blacksmoke16> but local vars like you had above that are not as strictly type checked as ivars
<FromGitter> <Blacksmoke16> i.e. if you dont supply a type restriction like `user_gold : Int64 = 2000_i64` it can be anything
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6aqs
<FromGitter> <Blacksmoke16> vs
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6aqu
<FromGitter> <girng> okay i thought `_i64` was implicitly assigning that var to the type then. i got it now
<FromGitter> <Blacksmoke16> it is, but w/o the type restriction on it, its not enforced
<FromGitter> <Blacksmoke16> since its a local var not an ivar/class var
<FromGitter> <girng> alright, yeah makes sense now
<FromGitter> <girng> @Blacksmoke16 and @j8r regarding the floats: i have to use a float because i'm wanting to get 3% of the total amount they are listing an item for ( a fee ). and a user's gold is a Int64
<FromGitter> <girng> i'm not very good at math however, so i have no idea if i need to use a float at all. i just am using whatever works lmao
<FromGitter> <Blacksmoke16> dont really have a choice if you care about decimal prices
<FromGitter> <Blacksmoke16> i.e. would need a float for something to cost 23.98 gold
<FromGitter> <Blacksmoke16> or 0.22
<FromGitter> <Blacksmoke16> etc
<FromGitter> <girng> i had to watch a couple yt videos about floats the other day "why do they exist?, etc". really interesting
<FromGitter> <girng> had a massive brain fart when doing the market fee %
<FromGitter> <Blacksmoke16> :p
<FromGitter> <sergiotapia> Hi everyone - do you know if restarting `amber watch` is supposed to delete all my DB records? https://stackoverflow.com/questions/54771799/records-all-delete-when-i-restart-amber-watch
<FromGitter> <Blacksmoke16> sure you're not clearing them somewhere in your code and it just happens to run it?
<FromGitter> <sergiotapia> Not to my knowledge, it's a brand new app I'm just following the guide to get a feel for Amber.
<FromGitter> <sergiotapia> As soon as postInstall things happen in my terminal, the records disappear.
<z64> @girng @Blacksmoke16 its not so much that local vars are "less strictly typed"; what is actually happening is shadowing - you're defining a *new* variable with the same name (the old variable is gone), and that new variable still only has one type
<FromGitter> <sergiotapia> I think I found something.... on `amber watch` it's running my specs for some reason. And in these specs, because I used scaffold it's running `MyModel.clear` for each model. ⏎ ⏎ What's confusing is: 1. Why it would run tests. 2. Why it's not connecting to the test.yml test and affecting my development.yml database.
<FromGitter> <Blacksmoke16> yea pretty much, would be the more accurate way to explain t
<FromGitter> <girng> @z64 i see
<FromGitter> <Blacksmoke16> not sure @sergiotapia :/
<FromGitter> <Blacksmoke16> make sure your env is right maybe? idk
<FromGitter> <sergiotapia> I just removed the command to run the spec tests from `amber watch`.
<FromGitter> <sergiotapia> test.yml isn't being respected by amber for some reason
<FromGitter> <sergiotapia> Wondering if I should just use Kemal....
<FromGitter> <Blacksmoke16> maybe file a bug on their repo?
<FromGitter> <sergiotapia> Is Kemal faster than Amber?
<FromGitter> <Blacksmoke16> what are you working on?
<FromGitter> <sergiotapia> api backend app
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> otherwise kemal and amber use different routers so depends on the route
<FromGitter> <Blacksmoke16> has some cool features you might like, namely the serialization stuff and the `Exists` and `RequestBody` param converters
<FromGitter> <j8r> @girng you don't really need, depends of the precision you want
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
<FromGitter> <theretromaniac> @sergiotapia for API is better to use athena
<FromGitter> <Blacksmoke16> was actually planning on writing a blog post on a blog REST API using Athena + Granite, prob start on it tonight, post it later this week
<FromGitter> <j8r> @girng
<FromGitter> <Blacksmoke16> created it with the intent of using it for JSON APIs, so will also act as a "play test"
<mps> Blacksmoke16: waiting for docs about athena .... hope not to long
<FromGitter> <Blacksmoke16> docs already exist? check out that link
<FromGitter> <j8r> or https://carc.in/#/r/6are
<mps> Blacksmoke16: did already, I mean some with examples
<FromGitter> <girng> @j8r isn't 123456 / 300 = 41.15? why does it return an Int32?
<FromGitter> <Blacksmoke16> anything in specific you'd want to see? as i said will have a blog post out this week. That will go build out a demo app using it. prob be pretty helpful
Creatornator has joined #crystal-lang
<mps> no, docs are good, but some kind of more descriptive 'prose' would be nice. Hope that the blog post fill the gap
<FromGitter> <j8r> @girng because Int32 / Int32 returns Int32
<FromGitter> <j8r> it may change in the future if floor division `//` is introduced
<FromGitter> <Blacksmoke16> like a "how everything fits together" and "how it would be used in the real world" type of thing? Yea the blog post should deff cover that
<FromGitter> <girng> but the result is a float? i'm so confused lol
<mps> Blacksmoke16: right, something like you wrote
<FromGitter> <girng> the actual result of the mathematical operation*, e.g: windows calculator
<FromGitter> <j8r> @girng you need to round for some operation, like `10 / 3`
<FromGitter> <Blacksmoke16> 👍 ill link it around when its done
<FromGitter> <girng> @j8r yah, that equals `3.3`. but what will it return if both are Ints? 3?
<FromGitter> <j8r> depends of the language, Crystal returns the same type. `T#/(Int32) : T`
<FromGitter> <j8r> no, it doesn't even equals to `3.333333333333333333333333333`
<FromGitter> <girng> yep: https://carc.in/#/r/6aro, 3
<FromGitter> <girng> mind blown
<FromGitter> <j8r> because of https://crystal-lang.org/api/master/Int.html#%2F%28other%3AInt%29-instance-method
<FromGitter> <j8r> you would like to return a rounded Float32, or Float64?
<FromGitter> <j8r> or BigDecimal?
<FromGitter> <Blacksmoke16> fixed some issues i found in the docs when rereading them
<FromGitter> <Blacksmoke16> should be more accurate now
<mps> Blacksmoke16: thanks for your work
<FromGitter> <girng> @j8r i just thought it wold return the actual value of the operation, not another int
<FromGitter> <Blacksmoke16> np :) deff isn't as feature rich as amber or lucky but for its purpose i think it would make for a good dev experience
<FromGitter> <Blacksmoke16> will get there eventually ;)
<FromGitter> <Blacksmoke16> i also need to revisit the spec shard i was working on
<FromGitter> <Blacksmoke16> would be a good introduction to crystal land iom
<FromGitter> <j8r> @girng lol what's "the actual value?" A BigDecimal, like in Perl6?
<FromGitter> <j8r> look at https://carc.in/#/r/6as4 too hehe
<FromGitter> <j8r> I let you doing the search on internet to figure all of this, this is a wide and very interesting topic
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <girng> @j8r yeah floats are too much for me hahaha
<devil_tux> can I get some help over json(any) over here: https://play.crystal-lang.org/#/r/6atb, trying to detect class of subelement but always getting json::any
<z64> if you're implementing a generic JSON interface, you should look into using `JSON::PullParser` instead of `JSON.parse`; it is better for parsing JSON structures in a strongly typed manner
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<devil_tux> z64: wasnt aware of this, yeha im unaware of json structure therefore cant map it
<FromGitter> <delef> Sorry, why I can't call #to_slice for Int32 hex? ⏎ `0x0001.to_slice` # => undefined method 'to_slice' for Int32
<z64> you basically want to create a PullParser and check `parser.kind`. this will return `:string`, `:object`, `:int`, etc based on what kind of JSON value you are *about* to read. typically you do a `case parser.kind` and then handle encoding each type to XML in each `when` branch
<devil_tux> z64: that will help! ty
<z64> @delef that isn't special to hex integer literals (https://carc.in/#/r/6atq). an integers byte representation is ambiguous; typically you need to describe how you want the integer encoded (endianess): https://carc.in/#/r/6att
<z64> woops, or rather: https://carc.in/#/r/6atx
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jemc has quit [Ping timeout: 240 seconds]
<FromGitter> <vladfaust> Yay, we've got a new job from Cambridge (universirty in England)
<FromGitter> <vladfaust> But looks like someone got confused Crystal Reports with the language :)
<devil_tux> vladfaust: oh how much I hate googling an issue and getting results for crystal reports >.<
jemc has joined #crystal-lang
<FromGitter> <vladfaust> Indeed!
<devil_tux> "crystal lang" in search term usually helps tho
<devil_tux> (quoted)
<FromGitter> <Blacksmoke16> `crystal -reports`
<FromGitter> <Blacksmoke16> would remove any results that have to do with reports
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
Creatornator has joined #crystal-lang
<devil_tux> z64: i think i'm close: https://play.crystal-lang.org/#/r/6azm
<devil_tux> not pullparser tho
<devil_tux> https://play.crystal-lang.org/#/r/6azq completed working patch
gwosix has quit [Ping timeout: 268 seconds]
gwosix has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]