<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]
<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>
<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>
<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>
<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
<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
<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
<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.
<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>
<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> 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>
<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
<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>
<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