RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.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
commavir has joined #crystal-lang
non-aristotelian has quit [Quit: non-aristotelian]
_whitelogger has joined #crystal-lang
<FromGitter> <pitosalas> What does this error mean? "clang: error: linker command failed with exit code 1 (use -v to see invocation) ⏎ Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/pitosalas/.cache/crystal/crystal-run-hue.tmp' -rdynamic `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs
<FromGitter> ... --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.26.1_1/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`"
<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
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
zorp_ has quit [Ping timeout: 246 seconds]
<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> <proyb6> When I ran this script in wrk tool, on Crystal HTTP was no change in improvement
DTZUZO has quit [Ping timeout: 246 seconds]
rohitpaulk has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter> <straight-shoota> @rishavs CORS is implemented client side. Your server doesn't need to do anything besides sending approriate headers.
DTZUZO has joined #crystal-lang
<FromGitter> <rishavs> Thanks Johannes.
<FromGitter> <rishavs> btw, does anyone have any example of `build_middleware` for plain crystal servers? The docs arent much help in that.
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <icyleaf> @rishavs Crystal built-in handlers: https://github.com/crystal-lang/crystal/tree/master/src/http/server/handlers
lvmbdv has quit []
<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> <Blacksmoke16> πŸ‘
<FromGitter> <vladfaust> πŸ‘
<FromGitter> <rishavs> ```code paste, see link``` ⏎ ⏎ :D I offload a lot of validations on the db itself [https://gitter.im/crystal-lang/crystal?at=5bd30c06271506518d72d9cd]
<FromGitter> <alex-lairan> Hi everyone ! ⏎ ⏎ I have files with `js.ecr`and I want to uglify it. ⏎ ⏎ Do you know any shards for this? :) ... [https://gitter.im/crystal-lang/crystal?at=5bd30dd36e5a401c2dd2ff9a]
<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.
<FromGitter> <yxhuvud> ie http://jsonapi.org
<FromGitter> <Blacksmoke16> oh no, i just meant an api that uses json :p
<FromGitter> <Blacksmoke16> as i was wondering if he came across how Crecto handles serialization/deserialization from model => json and vice versa
<FromGitter> <fridgerator> Crecto models import `JSON::Serializable` (probably the same as Granite), so you can `.to_json`
<FromGitter> <fridgerator> from json, the models have `cast` and `cast!` methods
<FromGitter> <fridgerator> similar to ecto
<FromGitter> <Blacksmoke16> πŸ‘ gotcha
<FromGitter> <drum445> Anyone know why that keeps happening please?
<FromGitter> <drum445> Kemal and https
zorp_ has joined #crystal-lang
<FromGitter> <schoening> I'm a bit tired of NodeJS + Express + MySQL hehe :P Does this tutorial also work for mysql? https://manas.tech/blog/2017/01/16/from-a-db-to-json-with-crystal.html
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
<jokke> ummm
<jokke> why is this always true?
<jokke> also when compiled with --release
<FromGitter> <straight-shoota> jokke: `--no-debug`
<jokke> ah
<jokke> i'm stupid
<jokke> thx
<FromGitter> <straight-shoota> ^^
<jokke> would've thought --release implies this
<FromGitter> <fridgerator> @schoening Its easier to use `DB:Mapping` and `JSON::Serializable` with classes
<FromGitter> <rishavs> How do I do something like this? ⏎ ⏎ ``` if services.has_key?(url) ⏎ services[url](context)``` [https://gitter.im/crystal-lang/crystal?at=5bd342fa1c100a4f29ea6f37]
<FromGitter> <schoening> @fridgerator is there a good tutorial for that? Otherwise it'll be harder ^^
<FromGitter> <straight-shoota> jokke, yeah the naming is a bit misleading. `flag?(:debug)` and `--no-debug` refer to debug symbols in the binary
<FromGitter> <rishavs> thanks!
non-aristotelian has joined #crystal-lang
zorp_ has quit [Ping timeout: 250 seconds]
<jokke> is there some container in crystal that does insertion sorting?
<jokke> hm maybe i don't need that if i use an iterator
<jokke> oh
<jokke> no sort_by for Iterator
<FromGitter> <ljuti> Took surprisingly little time to convert spec2.cr specs back to stdlib specs
<FromGitter> <ljuti> Suggestions for a solid HTTP router library?
<jokke> router.cr
<FromGitter> <ljuti> Yeah, looked into that as a possible solution
<jokke> orrrr there was another good one i wanted to give a try
<jokke> or at least it looked good
<jokke> but i can't remember the name
<FromGitter> <ljuti> router.cr sounds and looks a fine choice for my use case
<jokke> πŸ‘
<FromGitter> <ljuti> Kemal wouldn’t be a bad choice either as I need to serve a web application, too
<jokke> html?
<jokke> or just json
<FromGitter> <ljuti> Just JSON
<jokke> hm
<jokke> then i'd just stick with router.cr
<FromGitter> <ljuti> It’s fairly mature and supports all HTTP verbs
<jokke> um
<jokke> and router.cr doesn't?
<FromGitter> <ljuti> Most likely does :)
<jokke> kemal is a whole framework. it does already too much for my taste
<jokke> i usually just use something like this: https://p.jokke.space/esLr/
<FromGitter> <ljuti> Looks concise and simple, thanks for sharing!
<jokke> and here's what an implementation of an action might look like: https://p.jokke.space/XuYT6/
rohitpaulk has joined #crystal-lang
<jokke> in case you're interested in the param handling: https://github.com/jreinert/paramnoia
<FromGitter> <ljuti> Yeah, will definitely check that out πŸ‘
<jokke> unfortunately it's quite the macro mess. I'm struggling to find ways to extract complexity... :/ But there are some specs at least :)
<FromGitter> <rishavs> Did something change with the way we parse params in POST requests? ⏎ when I do ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5bd368e5bbdc0b2505a4cdfe]
<z64> @rishavs it looks like you're being given a JSON response and trying to parse it as HTTP params
<FromGitter> <rishavs> yep, the js code for the request is; ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ How do I consume the json data? [https://gitter.im/crystal-lang/crystal?at=5bd36aaebbdc0b2505a4da0f]
<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> <rishavs> thanks
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/CrSerializer could also be handy if you wanted to do some validations on the incoming json
<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. ;)
<FromGitter> <bew> You're welcome :D
<non-aristotelian> ^_^
<FromGitter> <fenicks> @bew Ok, will try Alpine
<non-aristotelian> I remember when I first realized this was how Rack worked; quite the treat; https://pastebin.com/raw/tZZmTpyj
<non-aristotelian> Gonna admit; kinda excited about this.
<FromGitter> <j8r> @fenicks armhf not supported, but aarch64 is https://github.com/crystal-lang/crystal/issues/5467
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
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> ... be able to contribute when I have the chance. ... [https://gitter.im/crystal-lang/crystal?at=5bd3a2d0ef4afc4f28d945e2]
<FromGitter> <j8r> @dscottboggs_gitlab what's your initial command?
<FromGitter> <dscottboggs_gitlab> `make`
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd3a327435c2a518e0ea9c0]
<FromGitter> <j8r> have you `make clean`?
<FromGitter> <dscottboggs_gitlab> trying that now
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <j8r> on my side, it works ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bd3a3da600c5f642312d284]
<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
notdaniel has joined #crystal-lang