<FromGitter>
<pitosalas> (I'm porting a small program from ruby to crystal)
<FromGitter>
<pitosalas> it does away when I remove the line "require "http/client"
sevensidedmarble has joined #crystal-lang
<FromGitter>
<pitosalas> Another question: is "spec" the right shard to use for writing tests? I am getting this error which I don't really understand: in spec/rule_spec.cr:5: can't use instance variables at the top level
DTZUZO has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @pitosalas you shouldn't have to use a shard for writing specs
<FromGitter>
<Blacksmoke16> assuming you are wanting to use Crystal's built in lib
<FromGitter>
<Blacksmoke16> https://play.crystal-lang.org/#/r/5cee is it by design you cant take a union of mismatched typed arrays, but intersection works?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
jhass|off has joined #crystal-lang
omninonsense has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
commavir has quit [*.net *.split]
RX14 has quit [*.net *.split]
jhass has quit [*.net *.split]
jsn- has quit [*.net *.split]
[spoiler] has quit [*.net *.split]
jhass|off is now known as jhass
rohitpaulk has joined #crystal-lang
<FromGitter>
<rishavs> I am thinking of adding CORS to my plain crystal server. Very basic question on that. Is CORS at the end of the day just an IP whitelist? Can I just add a customHandler which checks if the incoming request is from a reliable IP?
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter>
<proyb6> How do you handle pipelines for HTTP for better throughput?
<FromGitter>
<rishavs> Unfortunately nothing about `build_middleware` in there. -__- β my thought here was to use `build_middleware` as a pipeline of sorts. β one middleware chain would have auth check and another would be without it and my server could subscribe to either based on the output of another handler.
<FromGitter>
<pitosalas> @Blacksmoke16 Yes I am using the built-in spec library. And I am not using a shard for testing, the code that is being tested uses one. It looks like some installation problem
rohitpaulk has joined #crystal-lang
lvmbdv has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter>
<KevinSjoberg> How do I get the ID from a PostgreSQL `INSERT`-statement using `crystal-db`?
<FromGitter>
<KevinSjoberg> I know I can't use `exec` but is it possible using `query` and `RETURNING id`?
<FromGitter>
<Blacksmoke16> @pitosalas then in that case check your spec, are prob trying to declare like `@var = 123` outside of a class or something
<FromGitter>
<vladfaust> @KevinSjoberg yes, `query` will work
<FromGitter>
<KevinSjoberg> @vladfaust how? I've managed to get the ID by doing the following `db.query(stmt, "value") { |rs| rs.move_next ? rs.read(Int32) : 0 }`
<FromGitter>
<KevinSjoberg> Is there a better way?
rohitpaulk has joined #crystal-lang
<FromGitter>
<vladfaust> Yep, using an ORM :)
<FromGitter>
<KevinSjoberg> @vladfaust so the above is idiomatic without an ORM?
<FromGitter>
<vladfaust> You also try `scalar`
<FromGitter>
<KevinSjoberg> I managed to get it working doing the following
<FromGitter>
<Blacksmoke16> `db.scalar(statement, params).as(Int32 | Int64).to_i64` is how granite handles it
<FromGitter>
<Blacksmoke16> for int pk at least
<FromGitter>
<KevinSjoberg> `db.query_one("INSERT INTO images (filename, lat, lng) VALUES ($1, $2, $3) RETURNING id", filename, lat, lng, &.read)
<FromGitter>
<leolanavo_gitlab> @Blacksmoke16 Thanks a lot
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<leolanavo_gitlab> My final essay will be writing a large distributed system, and I'm very excited to use crystal, but I'm taking a lot of care while selecting the stack, for now I've decided to use Kemal for HTTP requests, and GraphQL to standardize the network calls, I have yet to decide the ORM. And currenctly I'm torn apart between Granite and Crecto, but honestly, I'm leaning on Granite since it has support from
<FromGitter>
... Amber
<FromGitter>
<Blacksmoke16> sounds like a plan
<FromGitter>
<Blacksmoke16> can join the amber gitter if you have any questions about granite, i'm quite familiar with it
<FromGitter>
<leolanavo_gitlab> I'll do it, thanks a lot
<FromGitter>
<Blacksmoke16> np
rohitpaulk has quit [Ping timeout: 276 seconds]
<FromGitter>
<Blacksmoke16> going to be using JSON api i imagine @leolanavo_gitlab ?
moei has joined #crystal-lang
<FromGitter>
<yxhuvud> huh, he wrote that he would use graphql..
<FromGitter>
<Blacksmoke16> so? GraphQL isnt an ORM afaik
<FromGitter>
<Blacksmoke16> oh
<FromGitter>
<Blacksmoke16> nvm so yea, it wouldn't be json then, nvm :p
<FromGitter>
<Blacksmoke16> well kinda would
<FromGitter>
<yxhuvud> What I mean is that jsonapi is a separate thing.
<z64>
well, you should be reading the `Content-Type` header which will tell you what form the body is in (as your js is sending). then you just use crystal's json api https://crystal-lang.org/api/0.26.1/JSON.html
<z64>
you can do `JSON.parse(io)` if you want. or, if the data you are receiving is of a strict format, you should use `JSON::Serializable` or `JSON.mapping` and do `MyClass.from_json(io)`
akaiiro has joined #crystal-lang
<z64>
well, "strict" is the wrong word - rather if you know the possible structures you'll be handling ahead of time
<FromGitter>
<Blacksmoke16> say ensuring password is not blank and of a given length etc, also allows for consuming password on `from_json` but not showing it on `to_json`
<FromGitter>
<Blacksmoke16> if you give it a try, will want to user master branch, been working on it and want to get some more stuff done before 0.2.0 release
<FromGitter>
<rishavs> Thanks @Blacksmoke16
<FromGitter>
<Blacksmoke16> np, any issues/ideas/suggestions feel free to let me know
<FromGitter>
<Blacksmoke16> still in WIP stage
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
sevensidedmarble has quit [Ping timeout: 252 seconds]
sevensidedmarble has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
<FromGitter>
<fenicks> Is someone using crystal on Raspberry Pi2+ ? I need to known which arm linux distrib is working with crystal apps.
<FromGitter>
<bew> All of them i guess? Unless you have a weird kernel with some missing syscalls (but i highly doubt it)
<FromGitter>
<bew> The important thing is the kernel (Linux in this case), not the distribution
<FromGitter>
<bew> Hmm not entirely true actually
<FromGitter>
<bew> (e.g: alpine), but anyway it should work with most (if not all) distribs. And it's known to work on RPi (but never tried myself)
sevensidedmarble has quit [Ping timeout: 250 seconds]
<non-aristotelian>
I have the following Crystal: https://pastebin.com/raw/RWrm0PEc ;; regardless of the URI I go to, I always get response "This is root." What am I missing?
sevensidedmarble has joined #crystal-lang
<non-aristotelian>
Oi... either Salt/Router don't work, or I seriously misunderstand how to use it.
<non-aristotelian>
Seems like the Router is directing all requests to the first custom-middleware... https://pastebin.com/raw/Ha4vZNs4 Always prints "OK".
<non-aristotelian>
Whatever is going on, my interpretation of the syntax is obviously incorrect; and I'm pretty upset about that. This feels _really basic_ -- if the basics are this foobar, wtf am I to expect later down the road?
<non-aristotelian>
Okay. I get it. This makes sense; it's like Rack's "Pipeline design pattern" -- so telling Salt to use "my app" as a middleware made no sense -- not in the way I was using it.
<non-aristotelian>
Okay. I feel better. Thanks all. ;)
non-aristotelian has quit [Quit: non-aristotelian]
<FromGitter>
<dscottboggs_gitlab> @j8r I still haven't been able to compile crystal. I tried using your docker alpine image and am getting this error: β β ```code paste, see link``` β β I also tried going FROM the offiicial docker image, installing build dependencies (including compiling libgc) and it gave me an error about libgc not being able to be found. have you any idea how I can get crystal to compile? I'd like to
<FromGitter>
<dscottboggs_gitlab> yup that did it. thank you
<FromGitter>
<j8r> you'll likely had old `.o` objects used
<FromGitter>
<dscottboggs_gitlab> yeah, I had tried compiling in that directory on the local system before trying it in containers. As soon as you said "clean" I was just like oh shit *facepalm* haha
<FromGitter>
<j8r> :)
<FromGitter>
<dscottboggs_gitlab> holy crap these specs are kicking my HDD's ass lol
<FromGitter>
<dscottboggs_gitlab> them fans are spinnnin up a bit haha