ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<FromGitter> <andrewhamon> Anyone know of any crystal libraries for easy encryption?
<FromGitter> <andrewhamon> I'm thinking something kind of like the NaCl box API
<FromGitter> <andrewhamon> I can *probably* get openssl to work, but I'm hoping theres something out there that doesn't have quite so many footguns
<FromGitter> <bigtunacan> Does the built-in crypto not work for you?
<FromGitter> <andrewhamon> Well, Bcrypt is just a hashing library
<FromGitter> <andrewhamon> I'm looking for public key crypto of some sort
<FromGitter> <andrewhamon> or maybe even symmetric, I'm mostly just toying around
<FromGitter> <johnjansen> anything in SSL?
<FromGitter> <andrewhamon> Which should have all the facilities needed
<FromGitter> <andrewhamon> But its just a wrapper around openssl, which is not the friendliest API
xiljin has quit [Read error: Connection timed out]
xiljin has joined #crystal-lang
sp4rrow_ has joined #crystal-lang
sp4rrow has quit [Ping timeout: 255 seconds]
greengriminal has joined #crystal-lang
ephemera__ has joined #crystal-lang
sp4rrow_ has quit [Quit: Textual]
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter> <picatz> Does anyone know how I might achieve the `"string".crypt` method in Crystal as in Ruby?
greengriminal has quit [Quit: Leaving]
<FromGitter> <fridgerator> check here: https://crystal-lang.org/api/0.23.0/Crypto/Bcrypt.html
<FromGitter> <picatz> That doesn't seem to be what I'm looking for ( if I'm not mistaken ).
<FromGitter> <picatz> If it helps, I'm essentially looking for something like a way to achieve something along these lines: https://github.com/ruby/ruby/blob/6bc742bc6d0dc6b1777d28484f4694af846bfb79/spec/rubyspec/core/string/crypt_spec.rb
<FromGitter> <picatz> The source code for Ruby points to this link as well for more information: https://docstore.mik.ua/orelly/networking/puis/ch08_06.htm
<FromGitter> <picatz> I'm a bit lost with it right now.
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
<bmcginty> picatz: if you're here, you basically subclass String and call out to the crypt method, and link to the crypt library.
<FromGitter> <renich> @oprypin here's a minimal example that breaks `crystal play`. It is not showing the var values and types. https://play.crystal-lang.org/#/r/2c3z
<FromGitter> <johnjansen> how is it broken?
<FromGitter> <johnjansen> @renich if you move the `data` and `orders = …\norders.result …` out of the module to the top level it works just fine
<FromGitter> <renich> OK
<FromGitter> <johnjansen> otherwise all you did was define it
<FromGitter> <johnjansen> https://play.crystal-lang.org/#/r/2c40
<FromGitter> <johnjansen> ergo … play is not broken
<FromGitter> <johnjansen> at least not by this code
<FromGitter> <renich> Ah, it works
<FromGitter> <renich> OK, I get it now.
<FromGitter> <renich> btw, what's the difference between `p` and `pp`?
<FromGitter> <johnjansen> try it out and see https://play.crystal-lang.org/#/r/2c44
<FromGitter> <renich> OK. One aliases puts?
<jplatte> Hey! Crystal was recently mentioned on the /r/rust subreddit and so I had a look at it. One thing I'm curious about that I didn't find in the docs is generics. I don't mean generic types, that is covered in the docs, but rather generic functions.
<FromGitter> <johnjansen> https://crystal-lang.org/api/0.23.0/toplevel.html#p%28%2Aobjects%29-class-method ⏎ https://crystal-lang.org/api/0.23.0/toplevel.html#pp%28%2Aexps%29-macro
<jplatte> Does Crystals stdlib have concepts such as "hash-able"?
<jplatte> And if yes, how are they implemented? Does Crystal have interfaces or sth. like that?
<FromGitter> <johnjansen> by hashable do you mean "Hashable objects which compare equal must have the same hash value"
<FromGitter> <johnjansen> which seems likely overlapping with https://crystal-lang.org/api/0.23.0/Comparable.html
<jplatte> @johnjansen: Hashable was just an example, the exact definition is not what I care about.
<jplatte> I guess Comparable would be another generic concept that needs some kind of generics.
<jplatte> okay, so it's a "mixin".
<jplatte> I'll look for that in the docs
thews has quit [Ping timeout: 268 seconds]
<jplatte> Hm, there is no chapter on mixins
<jplatte> I don't want to know how they are declared, I want to know about the mechanics behind them
<FromGitter> <johnjansen> what timezone are you in
<FromGitter> <johnjansen> you are probably about 6-12 hours from all the knowledge at that level
<jplatte> uhh, currently Melbourne, will be back in Germany (CET) later this week
<jplatte> what?
<FromGitter> <johnjansen> hmm so that 2pm ish
<FromGitter> <johnjansen> without me looking
<FromGitter> <johnjansen> ;-)
<jplatte> uhh yeah?
<jplatte> I don't know what you're talking about
<FromGitter> <johnjansen> this place will fill up with the knowledge you in a few hours time … there is never anyone around at this time
<jplatte> ohh
<jplatte> alright
<FromGitter> <johnjansen> sorry for the confusion … i can help with a bunch of practical stuff, but the underlying mechanics is best explained by others
<jplatte> okay, well maybe I can ask a few practical questions to get an idea of how the mechanics work :D
<FromGitter> <johnjansen> @RX14 is very knowledgeable
<FromGitter> <johnjansen> haha, you can give it a whirl
<FromGitter> <johnjansen> ill be here for a bit
<jplatte> So, first off, if I wanted to define e.g. a clamp function, how would I do that?
<jplatte> If you don't know what clamp does, this is how I would write it in Rust:
<jplatte> yeah :)
<FromGitter> <johnjansen> lets just talk behavior not implementation ;-)
<FromGitter> <johnjansen> ok give me a couple of minutes … clamp what data type?
<jplatte> well any data type that can be compared of course!
<FromGitter> <johnjansen> so hack Comparable, you can reopen the module and add to it … give me a couple of minutes
<FromGitter> <johnjansen> i did this https://play.crystal-lang.org/#/r/2c4d then realized that clamp is already defined all over the place https://github.com/crystal-lang/crystal/blob/a431a57b37d149a3536b7cb184356279b490aeda/src/number.cr#L242
<jplatte> Huh, that's weird
<jplatte> Why is it part of Number instead of Comparable?
<FromGitter> <johnjansen> yeah, thats what im wondering
<jplatte> I don't really know anything about mixins in other languages, but shouldn't Number "be a" Comparable?
<FromGitter> <johnjansen> ill see if my version works for other comparables … hold on
<FromGitter> <johnjansen> well my hack works fine https://play.crystal-lang.org/#/r/2c4f
<FromGitter> <johnjansen> https://play.crystal-lang.org/#/r/2c4g
<jplatte> maybe you should open a PR on crystal-lang/crystal :D
<FromGitter> <johnjansen> haha … i better check im not getting lucky and its floating around somewhere that i havent seen yet
<FromGitter> <johnjansen> did that help though???
<jplatte> no issues or PRs about it, other than the PR that introduced it for Number: https://github.com/crystal-lang/crystal/issues?utf8=%E2%9C%93&q=clamp
<jplatte> Kinda..
<jplatte> So with that "hack" as you described it, would any other portion of your code now automatically have the clamp function for comparable types, or does it need to be imported somehow?
<FromGitter> <johnjansen> anything that includes Comparable now has the code
<jplatte> okay
<FromGitter> <johnjansen> so Char and String do, we proved that
<jplatte> well that was in the same scope as your Comparable "extension" though
<jplatte> I was asking whether this extension would be visible in other modules of your project
<FromGitter> <johnjansen> i really just reopened the module, which is not really a hack … by hack i mean … i should poke around and make sure im not reinventing the wheel
<jplatte> or, if you were to put this extension into a library (shard?), if it would be visible in dependents without importing it
<jplatte> okay
<FromGitter> <johnjansen> shard yes
<FromGitter> <johnjansen> this is pretty easy to test, 1 minute or 3
<jplatte> ooooh, crystal init creates a .editorconfig :)
<jplatte> that's pretty cool
<jplatte> lol even .travis.yml
<FromGitter> <johnjansen> try adding this to your shard file ⏎ ⏎ ```dependencies: ⏎ clamp: ⏎ github: johnjansen/clamp``` [https://gitter.im/crystal-lang/crystal?at=5964575ec101bc4e3a71d31b]
<FromGitter> <johnjansen> then `require “clamp"`
<jplatte> hm, there are three different crystal extensions for vscode :/
<jplatte> I guess I'll just go with the one with the most downloads for now
<FromGitter> <johnjansen> just an FYI, autocomplete etc is not done yet
<FromGitter> <johnjansen> at least not fully
<jplatte> I really only wanted syntax highlighting
<jplatte> I'm not used to autocomplete working anyway :D
<jplatte> the only languages I have used for a long enough time to even want a full IDE are C++ and Rust, and those both have a horrible IDE experience, with stuff regularily breaking
<jplatte> so my standards are not very high ^^
<FromGitter> <johnjansen> yeah so syntax hilighting is easy … since its very close to ruby its basically already pretty well covered
<jplatte> uhhh, why do "crystal build" and "crystal run" give me the usage thing without an error message when I run them in a directory with shard.yml? I was kind of expecting crystal to just build / run my project, and I don't even get an error message..
<FromGitter> <johnjansen> try this plugin https://github.com/faustinoaq/vscode-crystal-lang
<FromGitter> <johnjansen> its valid to build without a shard file
<jplatte> well yeah if you give the cr file as an argument
<jplatte> but giving it my main file, it doesn't download my dependencies
<FromGitter> <johnjansen> you need to do a `shards install`
<jplatte> is there no build command that downloads deps from shard.yml, and then builds the main file that is set as the main of my taget in shard.yml?
<jplatte> I always hated "install" as the command for installing dependencies
<jplatte> but alright
<FromGitter> <johnjansen> i think there is another command thats the same … let me check
<jplatte> Guess I should install shards first :D
<FromGitter> <johnjansen> `crystal deps`
<jplatte> hey, I can do "shards build"
<jplatte> and it does what I wanted :)
<FromGitter> <johnjansen> oh cool
<jplatte> okay, so my current understanding is that require is basically the equivalent of `#include` in C / C++
<jplatte> as in, it really operates on files, rather than modules, right?
<jplatte> I can't say `require some_function from "my-shard"`?
<jplatte> or sth. like that
<FromGitter> <johnjansen> cant say myself ...
<FromGitter> <johnjansen> you can probably figure it out faster than i can
<jplatte> haha okay
<FromGitter> <johnjansen> @elorest Travis is still playing up https://travis-ci.org/johnjansen/clamp/builds/252267336
<FromGitter> <johnjansen> @jplatte ive added tests to that shard, just so you can see that stuff too
<FromGitter> <johnjansen> you might well want to install `guardian` which can effective auto test and auto build etc, whenever you make changes
<FromGitter> <johnjansen> also try `crystal play` if you havent already, and we often use https://carc.in/#/cr to communicate runnable code
<FromGitter> <johnjansen> between us
<FromGitter> <johnjansen> and `crystal spec` will run your tests ...
snsei has joined #crystal-lang
pwned has joined #crystal-lang
<jplatte> @johnjansen: I'm really more interested in getting a feeling for the language before learning how to use the tooling
snsei has quit [Ping timeout: 258 seconds]
<FromGitter> <johnjansen> no problem … if in doubt, find a ruby example … ok thats my night … good luck with it
<jplatte> thanks! good night!
baweaver has quit [Quit: Off to do something important-sounding]
baweaver has joined #crystal-lang
baweaver is now known as Guest12773
Guest12773 has quit [Changing host]
Guest12773 has joined #crystal-lang
Guest12773 is now known as lemur
lemur is now known as baweaver
<FromGitter> <tarvit> .
<FromGitter> <izwanefendi> hi everybody
<FromGitter> <izwanefendi> why : character not escaped while i use HTML.escape
<FromGitter> <oprypin> what character
<FromGitter> <izwanefendi> :
<FromGitter> <oprypin> because there's no need to escape it, you can use it safely as is in HTML
<FromGitter> <oprypin> if you disagree feel free to make your point
<FromGitter> <izwanefendi> hmm, ok, i will use gsub, thanks
<FromGitter> <oprypin> what are you trying to do?
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 248 seconds]
<FromGitter> <sdogruyol> Hey everyone
snsei has joined #crystal-lang
<FromGitter> <umutuluer> Hey
<FromGitter> <umutuluer> I have a basic problem :)
<FromGitter> <umutuluer> In kemal, i use mysql connector for db connection and it returns as json, but i dont fix utf8 problem
<FromGitter> <umutuluer> i tried MYSQL.exec SET NAMES, SET CHARACTER vb commands
<FromGitter> <umutuluer> but it doesnt work
<FromGitter> <sdogruyol> @umutuluer is it from your DB encoding?
<FromGitter> <umutuluer> yes
<FromGitter> <umutuluer> i tried in phpstorm sql tools, it is okey, but in crystal it is not
minus has quit [Quit: Bye]
<FromGitter> <sdogruyol> is the behaviour same in another language / framework?
<FromGitter> <sdogruyol> Crystal is UTF8 by default
Groogy has quit [Disconnected by services]
Groogy_ is now known as Groogy
<Groogy> morning! o/
Groogy2 has joined #crystal-lang
<FromGitter> <sdogruyol> Morning @Groogy
<FromGitter> <bararchy> Hi all :)
<FromGitter> <sdogruyol> hey
mark_66 has joined #crystal-lang
<Groogy> sdogruyol do you do any serialization in your projects?
<Groogy> just curious on what kind of is the "crystal way" to do it
<FromGitter> <sdogruyol> you mean for json e.g?
<FromGitter> <bew> Good morning here!
<FromGitter> <sdogruyol> morning
<FromGitter> <elorest> Morning!
<FromGitter> <sdogruyol> @elorest good night :P
<FromGitter> <bararchy> Does someone knows if the Crystal http client do auto html escaping for the post data ?
<FromGitter> <bararchy> body: "blabla blabla" will become blabla%27blabla ?
<Groogy> sorry morning meeting
<Groogy> yeah sdogruyol
<Groogy> or yaml
<FromGitter> <sdogruyol> ugh, i think it does not @bararchy
<Groogy> Like how do you architect it?
<FromGitter> <sdogruyol> well there's `JSON.mapping`
<FromGitter> <sdogruyol> you can directly serialize / unserialize using those
<FromGitter> <sdogruyol> which leads to a clean api
<Groogy> can it serialize, unserialize anything?
<Groogy> when does the type become too complex so you have to write your own code?
<FromGitter> <sdogruyol> that's probably what you want :P
snsei_ has joined #crystal-lang
<Groogy> I'l lread through it
<FromGitter> <sdogruyol> 👍
snsei_ has quit [Remote host closed the connection]
<FromGitter> <bararchy> @sdogruyol that's good new in my case XD :)
snsei_ has joined #crystal-lang
snsei has quit [Read error: Connection reset by peer]
<FromGitter> <sdogruyol> haha :D
<FromGitter> <sdogruyol> talk is cheap, show me the code :D
<FromGitter> <bararchy> Nice !
<FromGitter> <bararchy> so just shoving the header and sending as is
<FromGitter> <bararchy> good good
<FromGitter> <bararchy> hahaha
<Groogy> eeeeh sdogruyol I don't get it
<Groogy> so the json mapping creates those variables in the class?
<Groogy> not really what I would want though :/ I would want the serialization logic seperated from the logic
<FromGitter> <bararchy> Groogy what about using msgpack ?
<Groogy> doubt switching language that I serialize to will change where the logic for serialization is made :P
<Groogy> cna you get an IO object sort of from YAML or JSON that you can just do "json << type" and it will serialize that type and put it into the stream?
<Groogy> sometihng in style with this should be good right?
<Groogy> split the code but also let the serializer access protected data?
<FromGitter> <sdogruyol> looks good enough
<Groogy> though realized, like this I can create an entire tree of just data, and seperate out what actually serializes it into a different class
<Groogy> of just simplified data*
<FromGitter> <sdogruyol> are you trying to serialize vectors?
<Groogy> no just gamestate data
<Groogy> and configuration files
<Groogy> which can have a variadic complexity depending on what it needs to serialize :P
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> how do you normalize that data?
<Groogy> you mean make it so it can apply same thing to every structure or how do you mean?
<Groogy> because in that case, I don't know that's what I am trying to do
<FromGitter> <sdogruyol> i mean how do you store the actual game data :P
<FromGitter> <sdogruyol> not directly related to your question though haha
<Groogy> In the running game or on the disk?
<FromGitter> <sdogruyol> persisted on disk / db e.g
<Groogy> ah well nothing is in DB, that would be too slow it is kept in RAM until saved
<Groogy> and game states generally can be kept small enough it can fit under 2GB memory so
hightower2 has joined #crystal-lang
<FromGitter> <sdogruyol> eh, i was actually talking about the backend (if any)
<FromGitter> <sdogruyol> hey @RX14 this might interest you https://brson.github.io/2017/07/10/how-rust-is-tested
<Groogy> Doesn't work the same as it does with web
<Groogy> games like MMO's have to store the persistent data in databases etc, though like normal games like Civ just keep it in memory
<FromGitter> <sdogruyol> yeah, I'm mostly interested in MMOs like WoW :P
<Groogy> yeah they don't need to have direct access to most of their data at runtime though, but while Civ you have data that the AI need to be able to access easily for instance
<FromGitter> <sdogruyol> i'm really curious how do WoW scale
thews has joined #crystal-lang
snsei has joined #crystal-lang
Raimondii has joined #crystal-lang
snsei_ has quit [Ping timeout: 268 seconds]
Raimondi has quit [Ping timeout: 255 seconds]
Raimondii is now known as Raimondi
<FromGitter> <bew> @sdogruyol your link on rust testing is very interesting!
<RX14> @sdogruyol i did see that
snsei has quit [Remote host closed the connection]
<FromGitter> <sdogruyol> thanks @bew
<FromGitter> <bararchy> Well , wow servers work with c++ and hosted on Linux machines , currently the cluster servers pet region , each server has in men data for each loged in user and on login process it loads it from DB cluster for that region
<FromGitter> <sdogruyol> i thought about something like that
<FromGitter> <bararchy> They had lots of men leaks and memory issues in the beggining , and in the big raise of users
<FromGitter> <sdogruyol> really makes sense
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> i remember the login servers being hammered and down for a long time
<FromGitter> <sdogruyol> :/
<Groogy> yeah with those sorts of things I don't have much experience
<FromGitter> <sdogruyol> how do you guys handle Multiplayer stuff @Groogy ?
<Groogy> everything the AI or player does is sent through a command system
<Groogy> so like moving a unit from here to there is done through a command structure/class
<Groogy> which is serialized through our system that we use for pretty much everything
<Groogy> even our scripts
<Groogy> though it's not the.... best architecture
<FromGitter> <sdogruyol> how performant it is
<Groogy> ¯\(°_o)/¯ no idea
<Groogy> probably not that bad, depends though I guess if you are serializing to text format or binary format
<FromGitter> <sdogruyol> it works™
<Groogy> yepp that's why it is still alive
<Groogy> it's caused tons of problems over the years though
<FromGitter> <sdogruyol> makes sense
<Groogy> as we've expanded it to do things it wasn't meant to do and just like it is so easy to make a mistake in
minus has joined #crystal-lang
<Groogy> it is also why I very strongly discourage having the code for serialization inside the class itself, it's not that it solves the problem but you have to adopt a different mentality when working with stuff if you very clearly make it "not part of game logic"
<FromGitter> <sdogruyol> how long does it take to compile?
<Groogy> our entire project?
<Groogy> like worst it's ever been ever, think an hour
<FromGitter> <sdogruyol> ugh, how many LoC? Over 1mm?
<Groogy> no idea, but we have files that are 50k+
<FromGitter> <sdogruyol> holy cow!
<FromGitter> <sdogruyol> How do you even navigate them?
<Groogy> Visual Assist is key :P
<FromGitter> <sdogruyol> :D
<Yxhuvud> Groogy: your current game engine is getting pretty old. Are you managing to make continous bigger imrpovements or will you be forced to do a total rewrite eventually?
<Groogy> The engine is not the proble mactually
<Groogy> The bleeding edge version of the engine (Stellaris/HOI4, new projects) is rewritten completly and quite modern
<Groogy> there's some new features that are just now getting ready to be used
<Groogy> The problem is rather we have Game directors who think they can code :P
<Yxhuvud> :D
<Groogy> I got enough influence(friends with the game directors) at the company now though so I can tell them off when it comes to code and they have trust in my capabiliteis
<Groogy> but since we've gron immensly, 90% of our coders are pretty much juniors or somehow new to the company
<Groogy> grown*
<Groogy> it's way harder for them to have the same courage to stand up
<FromGitter> <sdogruyol> @Groogy good job!
<Groogy> I had a conversation the other day in a code review "Why is this code commented out, will it be ever used again?" "No, but it might be useful at some point maybe... " "remove it now"
<Groogy> you gotta be strict to ensure code debt don't increase
<Groogy> and that's more of our problem than the actual engine Yxhuvud
<Groogy> old company, that suddenly exploded
<Yxhuvud> IF someone needs it, use the version control, or just rewrite it.
<Groogy> if you're interested in fixing it for us Yxhuvud, feel free to apply ;D
<FromGitter> <bararchy> soo , I have an [Class, Class, Class] each Class has a `.score` method, I want to get the Class with the biggest score, how can I do that without creating a Hash for mapping ?
<Yxhuvud> nah, the world is better with me not writing c++
<FromGitter> <sdogruyol> @bararchy are you kidding????
<FromGitter> <sdogruyol> I'm just writing the same code of sorting users with score
<Groogy> bararchy you can't have references to classes I think?
<FromGitter> <bararchy> XD
<Groogy> or at least when I've tried I've totally filed to make it work
<FromGitter> <sdogruyol> @bararchy
<FromGitter> <bararchy> Well, I can create a tmp Hash with {Class => score}, but it's slow I think
<Yxhuvud> groogy: but I may apply the day you start looking for crystalites. ;)
<FromGitter> <bararchy> @sdogruyol Nice ! HAHAHAH
<FromGitter> <sdogruyol> rofl :D
<Groogy> Yxhuvud if I get my project up and running and get Paradox to fund it
<Groogy> sure
<Groogy> :P
<Groogy> though if I don't have a prototype running already they are gonna want it to be C++ in Clausewitz, since otherwise it's impossible to move resources within the company to the project
<Groogy> we work very much by moving around people to where the hotspot is "right now" if need be
<Groogy> and question is if I even want that, ever since I met DF's creator and how he funds his project I've been kinda inclined in doing something ismilar
<Groogy> similar*
<FromGitter> <bararchy> ```code paste, see link``` ⏎ ⏎ This is my Array, how do I get the bigget score without creating a tmp Hash or something ? :) [https://gitter.im/crystal-lang/crystal?at=5964aa7176a757f808fbc152]
<FromGitter> <sdogruyol> ```sort_by! { |bar| bar.score }.reverse!```
<FromGitter> <bararchy> @sdogruyol Nice !
<FromGitter> <bararchy> thanks :)
<FromGitter> <sdogruyol> :)
<FromGitter> <sdogruyol> i just wrote the exact same code 2 mins ago :D
<FromGitter> <sdogruyol> Are we telepathically pair programming @bararchy :O
<Groogy> this won't create any temp array or modify the array
<FromGitter> <sdogruyol> yeah
<Groogy> can also do .first on array instead of nil to initial highest value
<Groogy> to avoid the nil type
<FromGitter> <sdogruyol> you're definitely a gamer @Groogy :D
<Groogy> yepp :P
<FromGitter> <sdogruyol> haha
<FromGitter> <sdogruyol> cool
<Groogy> we do these kind of searches a lot in our code
<FromGitter> <sdogruyol> makes sense you know
<Groogy> especially in the AI
<Groogy> "What's most important to take first, etc. etc."
<Groogy> ops don't need to check if it is nil anymore
<Groogy> there final code :P
<Yxhuvud> array.max_by &.score
<FromGitter> <sdogruyol> wow
<FromGitter> <sdogruyol> that's more idiomatic :D
<FromGitter> <sdogruyol> thanks @Yxhuvud
<Groogy> oh cool
<Yxhuvud> Enumerable <3
<FromGitter> <bew> I have way shorter: https://play.crystal-lang.org/#/r/2c51
<Groogy> I need to learn this stdlib inside out
<FromGitter> <bew> ah
<FromGitter> <bew> ...
<Groogy> haha ninja'd by Yxhuvud
<FromGitter> <bew> you got me Yxhuvud :P
<FromGitter> <sdogruyol> hahahu
<FromGitter> <sdogruyol> I like learning this way
<Groogy> so is your name "Yxhuvud" because of "Goddag Yxskaft" or because you'r sharp like an axe? ;D
<FromGitter> <bew> we need vimgolf-like chanllenge => crystalgolf !!
<Yxhuvud> the former.
<Groogy> haha
<FromGitter> <peterschols> Hi, I'm working on my first Crystal shard and looking for the best way to write a Hash(Int32, Int32) to json using JSON::Builder. There don't seem to be Hash-related methods in JSON::Builder, do I just iterate the hash and add the scalar values?
<FromGitter> <sdogruyol> meanwhile how i can do the same for a hash @Yxhuvud?
<FromGitter> <sdogruyol> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5964acc53230e14f3a492fba]
<FromGitter> <bew> why not use `your_hash.to_json` ?
<FromGitter> <bew> (@peterschols)
<FromGitter> <peterschols> @bew That would make sense :) I looked in the Hash source and could not find a to_json, but it's probably defined elsewhere?
<Yxhuvud> @sdogruyol: &.[:score] ?
<FromGitter> <peterschols> @bew that works, but the only issue is that the keys are converted to strings. I'd prefer to keep them Int32, just like the values.
hightower2 has quit [Ping timeout: 255 seconds]
<FromGitter> <bew> in a JSON you can't have non-string keys
<FromGitter> <sdogruyol> @Yxhuvud i'm actually doing this in Ruby
<FromGitter> <bew> i guess
<FromGitter> <peterschols> @bew I see, thanks a lot for the help!
<Yxhuvud> @sdogruyul: ah, then it'd be max_by {|h| h[:score]} I'm afraid.
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> :(
flaviodesousa has joined #crystal-lang
<Yxhuvud> ruby is a lot less powerful in this department, even if it is quite possible to define methods like to_proc on things to make weird things work. Symbol#to_proc first came from the community after all
<FromGitter> <bararchy> Oh, btw, RX14, congrats :)
<Yxhuvud> @sdogruyol: for example, https://thepugautomatic.com/2014/11/array-to-proc-for-hash-access/ can be done for hashes as well, so it is quite possible to implement somehting that does what you want there.
<oprypin> &.[:score] should work
<Groogy> no that's been covered, they are talking about doing equivalent in ruby right now
<FromGitter> <sdogruyol> yeah
gewo has quit [Quit: WeeChat 1.6]
greengriminal has joined #crystal-lang
<FromGitter> <bararchy> So, why can't the Crystal compiler use more then just one core for compiling ? is it because Crystal is single threaded right now ?
<FromGitter> <bew> yeah mostly
<FromGitter> <sdogruyol> compiling std e.g is single-threaded
<FromGitter> <sdogruyol> other than that LLVM probably uses all the juice
<FromGitter> <bew> and because the sources cannot be compiled file by file, the whole code needs to be compiled together
<FromGitter> <bararchy> Can't the compiler split the work for file by file and then join the obj files or something ?
<FromGitter> <bew> no because the type inference must work on the whole code, to find all invocation of a method for example
<FromGitter> <sdogruyol> if i'm not wrong Rust followed the same path
<FromGitter> <bew> but from what I've seen, Rust handle incremental compilation, which fasten up the compilation on small changes
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> they even implemented MIR
<FromGitter> <sdogruyol> but still compilation is slow compared to Go e.g
<FromGitter> <sdogruyol> everything is slow compared to Go though :P
<FromGitter> <bew> never tried Rust or Go actually, just read a lot about them
<FromGitter> <sdogruyol> Go lives up to its' promise of compiling really really fast
<FromGitter> <sdogruyol> sometimes i feel like it's faster than starting up a Ruby script
<FromGitter> <fridgerator> lol
<FromGitter> <bew> wow ^^
<FromGitter> <fridgerator> 🔥
<FromGitter> <sdogruyol> wish we had some of the resources of Google :/
<FromGitter> <sdogruyol> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5964c933c101bc4e3a73b315]
<FromGitter> <sdogruyol> P.S: Go compiles and runs the code
<FromGitter> <bew> nice!
<FromGitter> <sdogruyol> here's Crystal
<FromGitter> <sdogruyol> ```crystal run hello.rb 0.70s user 0.17s system 116% cpu 0.738 total```
<FromGitter> <codenoid> :|
<FromGitter> <bew> the language is better :P *naaa I don't want to see the compilation time difference*
<FromGitter> <sdogruyol> yeah @bew i agree :)
<FromGitter> <fridgerator> compilation time is not a deal breaker for me, it is for some people though
<FromGitter> <sdogruyol> still we need to improve :P
<FromGitter> <fridgerator> makes development with a large application more difficult
<FromGitter> <sdogruyol> well compiling large programs takes time
<FromGitter> <fridgerator> ^
<FromGitter> <bararchy> Yeha, got 30-40k lines and I need to wait for ever for --release compile
<FromGitter> <sdogruyol> @bararchy what? 30-40k LoC of Crystal?
<FromGitter> <sdogruyol> without release actually it's good
<FromGitter> <bararchy> XD yeha
<FromGitter> <sdogruyol> ```crystal build src/kemal.cr 0.80s user 0.23s system 112% cpu 0.915 total```
<FromGitter> <bararchy> without release it's really fast
<FromGitter> <bararchy> but then I eat dirt in the run time
<FromGitter> <sdogruyol> ```crystal build --release src/kemal.cr 6.21s user 0.25s system 98% cpu 6.546 total```
<FromGitter> <sdogruyol> thanks LLVM :D
<FromGitter> <sdogruyol> @bararchy what're you guys actually building there?
<FromGitter> <bararchy> well .................
<FromGitter> <bararchy> hahahah
<FromGitter> <bararchy> it's complicated to answer right now in this public chat
<FromGitter> <bararchy> XD
<FromGitter> <sdogruyol> oh ok :D
<Groogy> >
<Groogy> > compilation time is not a deal breaker for me, it is for some people though
<Groogy> you sweet summer children don't know what compilation time is ;_;
<FromGitter> <sdogruyol> it's ok for me
<FromGitter> <sdogruyol> < Rubyist :P
<FromGitter> <straight-shoota> There is much room for improvement as far as I understand... an optimized rewrite of the type inference algorithm, multithreading, improved incremental builds etc.
<FromGitter> <sdogruyol> yeah, indeed
<FromGitter> <sdogruyol> everything takes time (resources) :P
<FromGitter> <straight-shoota> And I don't think it is too bad already for small and medium sized projects
<FromGitter> <sdogruyol> it's good enough
<FromGitter> <straight-shoota> And for really large projects I'd actually worry more about memory requirements :D
<FromGitter> <straight-shoota> I don't know if this could be significantly lowered with better implementation...
<FromGitter> <sdogruyol> you mean for compilation or runtime?
<FromGitter> <straight-shoota> compiler
<FromGitter> <sdogruyol> ah yes
<FromGitter> <domgetter> I just upgraded crystal from 0.21.1 to 0.23.0 and when I try to run a file, I get " version `GLIBCXX_3.4.20' not found". Is upgrading glibc the solution here or should I be looking elsewhere?
<FromGitter> <sdogruyol> @domgetter ugh, are you on linux?
<FromGitter> <domgetter> Yes, Linux Mint 17.2
<FromGitter> <fridgerator> I think thats the same error in travic ci right now
<FromGitter> <straight-shoota> Runtime memory is not a big deal at all, I think. If you require really low memory consumption, you can always throw out stdlib :D
<FromGitter> <straight-shoota> @domgetter This is the issue: https://github.com/crystal-lang/crystal/issues/4647
<FromGitter> <sdogruyol> :D
<FromGitter> <sdogruyol> hopefully we'll get a 0.23.1 release this week
<FromGitter> <straight-shoota> In the meantime you can use these packages manually: https://github.com/crystal-lang/crystal/issues/4647#issuecomment-313876137
<Groogy> does stdlib really take that much memory at runtime? At most I can think it bloats executable size and that in turn increases memory usage?
<FromGitter> <bew> Groogy the functionnalities you don't use are not included in the final library, so the binary is not that bloated
<FromGitter> <straight-shoota> the GPG signing error seems to be resolved, macro resolver is fixed so just the static linked glibc seems to be missing for 0.23.1. But it looks promising ;)
<FromGitter> <straight-shoota> Groogy, I don't know if it is that much, just remembered a discussion about a micro stdlib somewhere...
<FromGitter> <bew> micro stdlib? I'd like to here more about that, do you remember where?
<FromGitter> <straight-shoota> might've been here in chat :thinking:
<Groogy> could be useful for embedded systems
<Groogy> just the bare minimum stdlib
<FromGitter> <straight-shoota> my memory extension google.com served just a few links in that direction... :D
<FromGitter> <straight-shoota> https://news.ycombinator.com/item?id=13213631
<FromGitter> <straight-shoota> https://github.com/kubo39/tinycr
<FromGitter> <bew> Groogy, yes was thinking about that
<FromGitter> <straight-shoota> https://github.com/lbguilherme/os-crystal
<FromGitter> <bew> @straight-shoota that's not really a stdlib, is it?
<Groogy> OH I RECOGNIZE THAT NAME
<FromGitter> <sdogruyol> lol
<Groogy> lbguilherme helped me out creating a RubyCpp wrapper template system
<FromGitter> <straight-shoota> No, this is just about running crystal without stlib but not directly a replacement for it
<Groogy> that must be like 6-7 years ago or something
<FromGitter> <bew> I see, tinycr was a mini project to have the most little binary possible iirc
<Groogy> also when is Linux gonna be remade in Crystal huh?
<FromGitter> <bew> probably after 1.0 is out \o/
<FromGitter> <bew> *only after
<FromGitter> <straight-shoota> The thing is, without CG Crystal is probably gonna loose much of its slickness
<FromGitter> <straight-shoota> maybe even 1.2 :P
<FromGitter> <bew> ahah
<Groogy> CG? you mean GC?
<FromGitter> <bew> Without GC it still have the awesome syntax, and it feel way better that writing C
<FromGitter> <straight-shoota> yes
<Groogy> if structs just have a destructor call when destroyed
<Groogy> you can do smart pointers
<FromGitter> <bew> than*
<Groogy> solves the entire problem ;D
<FromGitter> <straight-shoota> bew, https://github.com/lbguilherme/os-crystal/tree/master/src/core has a very minimalistic stdlib ^^
<Groogy> *hint hint* I want destructors on structs
<Groogy> yepp saw
<FromGitter> <straight-shoota> then open an issue^^
<Groogy> donno if that fits int othe language though?
<Groogy> wanting it for my selfish needs doesn't nesseciarly mean it is a good idea
<Groogy> finalizers in itself in GC environment is only there out of nessecity because of boilerplate things
nikkkk has joined #crystal-lang
<FromGitter> <straight-shoota> there are already quite a lot of low level and unsafe features... at least more than I'd comfortably require^^
greengriminal has quit [Quit: This computer has gone to sleep]
Philpax has joined #crystal-lang
<FromGitter> <bew> nice micro-lib
<FromGitter> <bew> so now we need crystal lang, and typing system with rust's ownership management for the next YAPL (yet another perfect language)...
<FromGitter> <sdogruyol> lol
<FromGitter> <domgetter> @straight-shoota that did it! thank you :_
greengriminal has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> why is there no "load" in crystal?
<FromGitter> <LuckyChicken91_twitter> is there an replacement for this
<FromGitter> <sdogruyol> why do you need it?
<FromGitter> <LuckyChicken91_twitter> you want to tell me that theres no 'load' in crystal..?
<FromGitter> <sdogruyol> I mean what's your use case because I've never used `load` before even in Ruby :P
<FromGitter> <LuckyChicken91_twitter> in ruby you can load other ruby files directly into the program
<FromGitter> <sdogruyol> oh
Philpax has quit [Ping timeout: 240 seconds]
<FromGitter> <sdogruyol> well, Crystal requires everything at compile time so it's normal not to have `load`
<FromGitter> <LuckyChicken91_twitter> and what can i do now?
<FromGitter> <LuckyChicken91_twitter> maybe require_relative?
<Groogy> yes require relative
<FromGitter> <LuckyChicken91_twitter> ok
<FromGitter> <LuckyChicken91_twitter> because i just want to reload the program with require_relative(__FILE__)
<Groogy> you can't reload the program
<Groogy> it's not dynamically interpreted
<Groogy> it's compiled at runtime
<Groogy> eh
<Groogy> I mean it is not compiled at runtime
<FromGitter> <LuckyChicken91_twitter> oh
<FromGitter> <LuckyChicken91_twitter> uh im getting undefined method 'require_relative'
<Groogy> no you just do require("./file.cr")
<Groogy> ./ denoting "this directory" of the file it's typed in
Philpax has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> hmm he cant require inside def
<FromGitter> <LuckyChicken91_twitter> so i cant reload the program at this point
<FromGitter> <straight-shoota> No you can't.
<FromGitter> <straight-shoota> A Crystal program is compiled and the executed. You can't change the program at execution.
<FromGitter> <LuckyChicken91_twitter> hm ok
<FromGitter> <LuckyChicken91_twitter> just possible with interpreters i think
<FromGitter> <straight-shoota> yes
<FromGitter> <straight-shoota> If you explain what you want to do, maybe we can assist you in finding a way to implement this in Crystal.
<FromGitter> <paulcsmith> @sdogruyol Thanks for https://github.com/kemalcr/spec-kemal/blob/master/src/spec-kemal.cr#L24-L34 it helped me a ton when writing my own spec helpers!
<FromGitter> <sdogruyol> hey, thanks for using @paulcsmith 💯
<FromGitter> <sdogruyol> you're using that for Lucky?
<FromGitter> <paulcsmith> Yep! Not published yet though. I'm using it on a project and will port a bunch of stuff over later
<FromGitter> <paulcsmith> Still a lot of work to do before it's ready for use, but it's getting closer :)
<FromGitter> <LuckyChicken91_twitter> "for Lucky"? do you mean me?
<FromGitter> <sdogruyol> @LuckyChicken91_twitter no, lucky is a web framework that @paulcsmith is building :P
<FromGitter> <LuckyChicken91_twitter> oooh okay
<FromGitter> <paulcsmith> I didn't realize anyone knew about it actually :P
<FromGitter> <sdogruyol> I'm aware of it for a long time :P
<FromGitter> <sdogruyol> guess I'm stalking too much haha
<FromGitter> <paulcsmith> Haha it's ok I do too. It's exciting to see all the activity going on in Crystal land
<FromGitter> <sdogruyol> indeed, we've got some exciting times ahead for Crystal 💎
<Groogy> AAA game when? ;D
<FromGitter> <bew> only after 2.0 ? :D
<Groogy> nah need it earlier
<Groogy> wasn't there a game done in Rust?
<Groogy> I think Firefox been switching over to it at least
<FromGitter> <bew> I count on you to defy my statement
<Groogy> Alright I will make it happen
<Groogy> or rather I'll have a prototype before 1.0
<Groogy> how does that sound ;D
<Groogy> playable prototype
<FromGitter> <bew> really good!
<FromGitter> <straight-shoota> I'll play :D
<FromGitter> <sdogruyol> haha
<FromGitter> <sdogruyol> @Groogy that'll be fantastic you know
<FromGitter> <bew> I've made a game in C++ last year in school, I'd love to see real way to do things like you do in your business, and reading crystal will be perfect :)
<FromGitter> <sdogruyol> I've never earned money doing game dev
<FromGitter> <sdogruyol> it must be harder than web-dev
<Groogy> no idea, only web-dev I've done has been like as a hobby
<FromGitter> <bew> your game engine might be better than mine x)
<Groogy> tried to make a webbased mmo on my freetime a frew years ago
<Groogy> Oh wait now I am lying
<Groogy> I did when I was 17 do SOAP protocol stuff in PHP as a consultant
<Groogy> *shudders*
<Groogy> never again
<Groogy> a piece of me gone that I can never recover again
<FromGitter> <bew> ahahah don't even need to talk about it
Philpax has quit [Ping timeout: 248 seconds]
<FromGitter> <pglombardo> Is there a way to get a backtrace in Crystal? e.g. Something similar to Kernel.caller in Ruby?
<FromGitter> <bararchy> Well, not everyones cap of tea, but I started a MOD MMO :) a few months ago
<Papierkorb> pglombardo, Most naive code: `def backtrace : Array(String); raise(""); rescue ex : Exception; ex.backtrace; end`
<Papierkorb> Note that that code is ugly, however, what do you need it for?
<FromGitter> <pglombardo> Papierkorb: Ah nice solution for now.
<Groogy> huh that's kinda cool actually Papierkorb
<FromGitter> <pglombardo> I write language instrumentation for Instana and we occasionally take backtraces
<FromGitter> <pglombardo> We’re adding support for Crystal ;-) Happy to be adding Crystal support.
<FromGitter> <fridgerator> cool 👍
<Papierkorb> pglombardo, Proper code would involve using libUnwind, which is what crystal does under the hood
<FromGitter> <pglombardo> Right and I assume that’s not exposed by crystal yet?
<Papierkorb> Sure it is
<FromGitter> <pglombardo> I couldn’t find anything in docs or api
<FromGitter> <pglombardo> Slick :-) CallStack.new works and I got a backtrace. Thanks!
<FromGitter> <pglombardo> What is the strategy with documentation? Is there a reason that’s not in the API docs?
<Papierkorb> Probably a case of it being forgotten
<FromGitter> <pglombardo> I could add but not sure if the API docs are auto generated or hand-picked
<Papierkorb> The in-source docs are manually written. I don't see any reason for any code to not have docs, so go ahead
<FromGitter> <pglombardo> The API portal is generated from code? I see crystal-book but I think that is just /docs/ right?
<Papierkorb> The API docs are generated through `crystal docs`
<oprypin> not exactly
<oprypin> same tool but docs are in fact picked
<oprypin> docs_main.cr or something
<oprypin> check Makefile
<FromGitter> <pglombardo> ok will do thanks for the info.
<oprypin> doc: ## Generate standard library documentation
<oprypin> $(BUILD_PATH) ./bin/crystal doc src/docs_main.cr
<FromGitter> <bew> @pglombardo use can also use `caller` :D
<FromGitter> <pglombardo> doh hidden in plain sight :-) I may take a swipe at adding documentation… let’s see.
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <bew> I think that adding the doc on top of this method should be enough ;)
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
<crystal-gh> [crystal] pglombardo opened pull request #4702: Add documentation for CallStack "caller" method (master...documentation) https://git.io/vQMoX
<FromGitter> <pglombardo> Ok - had to read guidelines and how the doc syntax worked but here the small PR. https://github.com/crystal-lang/crystal/pull/4702
<FromGitter> <bew> nice thanks! did you try to generate the docs and see how in turns out?
<FromGitter> <pglombardo> Ok you caught me :-) I’m going to figure out where my llvm-config is and get the build working so I can contribute docs more often. I’ve been keeping a local list of issues converting ruby code and a few undocumented things I found.
<FromGitter> <bew> cool!
<FromGitter> <pglombardo> If we want to hold on that PR until I test locally - that’s ok with me.
flaviodesousa has quit [Ping timeout: 246 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
snapcase has quit [Ping timeout: 240 seconds]
mark_66 has quit [Remote host closed the connection]
<FromGitter> <watzon> So has anyone figured out a GUI framework for crystal yet? Or QT bindings or something?
<FromGitter> <johnjansen> anyone got a good way to get the username from a UID?
<FromGitter> <watzon> Sorry I’ve been out of the loop for a while lol
<FromGitter> <fridgerator> @watzon not that I know of
<FromGitter> <watzon> 😭 we need to make one
<FromGitter> <watzon> Lol
<FromGitter> <konovod> there are libui bindings: https://github.com/Fusion/libui.cr
<FromGitter> <konovod> didn't tried them though
dzv has quit [Quit: WeeChat 1.6]
marcosdsanchez has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> is there an gui framework for crystal?
<FromGitter> <fridgerator> look up 6 lines
dzv has joined #crystal-lang
marcosdsanchez has quit [Quit: leaving]
<FromGitter> <LuckyChicken91_twitter> uh
<FromGitter> <LuckyChicken91_twitter> ehm wasnt there a shards.xyz website where are all crystal shards are listed?
<FromGitter> <LuckyChicken91_twitter> oh its crystalshards.xyz
<FromGitter> <LuckyChicken91_twitter> is crystalshards.xyz the official shards website?
<FromGitter> <konovod> i don't think so
<FromGitter> <LuckyChicken91_twitter> hm ok
<FromGitter> <LuckyChicken91_twitter> how can I make my own shard?
<FromGitter> <hugoabonizio> @LuckyChicken91_twitter it's not official, it's maintained by @f https://github.com/f/crystalshards
<FromGitter> <konovod> `crystal init lib <coolname>` then push to github. There is no centralized repository.
<FromGitter> <konovod> There is also https://github.com/veelenga/awesome-crystal - not all shards are there, but at least categorized there are categories.
<FromGitter> <eliasjpr> Hello everyone, we are trying to get Nanobox to support Crystal and with it Amber, Kemal please submit your vote to this trello card https://trello.com/b/4zbckEIY/nanobox-roadmap
<FromGitter> <straight-shoota> Are there any recommendations for a nice terminal for Ubuntu on Windows? It sucks to run bash in cmd or powershell...
<FromGitter> <renich> o/
<FromGitter> <fridgerator> does git bash work with ubuntu on windows?
<FromGitter> <renich> Guys, when using JSON.mapping(), I find myself using `myjson.not_nil!.some_property` a lot. What am I doing wrong? I don't want to use `not_nil!` every time.
<FromGitter> <fridgerator> its better than cmd, but I haven't used it with ubuntu
<oprypin> renich, show code
<FromGitter> <renich> oprypin: complicated but will try to compile something
<oprypin> probably doing something wrong and it probably isnt specific to json but i cant guess
<FromGitter> <LuckyChicken91_twitter> how can I test my shard?
<oprypin> LuckyChicken91_twitter, in what sense
<FromGitter> <LuckyChicken91_twitter> how can I require my shard in another file while its not published
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <johnjansen> @renich you need to ensure that the vars cannot possibly be nil … somewhere, which in your case is probably *before* you ever get near serializing the object …
greengriminal has joined #crystal-lang
<FromGitter> <renich> @johnjansen yeah, will analize that...
* FromGitter * renich is trying to get some code together in order to be able to post an example
<oprypin> LuckyChicken91_twitter, you can make another application that is supposed to require that shard, see example https://github.com/crystal-lang/shards#usage
<oprypin> but you do `file: /full/path/to/your_unpublished_shard` and not `github: ` or something
<oprypin> LuckyChicken91_twitter, a simpler way is to make a `lib` folder and put your shard in it and make a source file near the `lib` folder
<oprypin> an even simpler way is to put a file anywhere and `require "./src/something.cr"`
<FromGitter> <johnjansen> anyone know the magic incantation that will let you `run` with OptionParser options … ala `crystal run src/some_file.cr [-l]`
<FromGitter> <johnjansen> or some options you have in parser :-)
<oprypin> johnjansen crystal run src/some_file.cr -- --asdfg
<FromGitter> <johnjansen> thanks @oprypin
<FromGitter> <LuckyChicken91_twitter> hm this is not working
<FromGitter> <LuckyChicken91_twitter> im trying to execute the file in the src folder directly
<FromGitter> <LuckyChicken91_twitter> do i need to use a module in the file of the src folder?
<oprypin> LuckyChicken91_twitter, make a file with `require "./local_file"` and `crystal that_file.cr`
<FromGitter> <LuckyChicken91_twitter> i dont need to use a module in the file of the src folder which is named to the shard, right?
<oprypin> what
<FromGitter> <LuckyChicken91_twitter> in the src folder is a file and in this file you are putting all the code in, right?
<FromGitter> <LuckyChicken91_twitter> and in this file was from beginning a module. Do i need to put my code in this module? or can i remove this prewrited module and write the code then there?
<oprypin> LuckyChicken91_twitter, you dont need to put your code in this module. you can use ThatModule.function and ThatModule::class
<oprypin> thats how users of the shard will do it
<FromGitter> <LuckyChicken91_twitter> but i want to write my code directly there without ThatModule.function and ThatModule::class
<FromGitter> <LuckyChicken91_twitter> im not sure if the shard is later not working if im writing the code not in the prewrited module
<FromGitter> <sdogruyol> @eliasjpr what's required to vote?
<FromGitter> <fridgerator> just sign in to trello
<FromGitter> <fridgerator> and you can upvote
<FromGitter> <fridgerator> thats what I did anyways
<FromGitter> <eliasjpr> @sdogruyol yes, just sign in and click vote
<oprypin> i mean... they're gauging interest from actual users, not just bandwagon, but whatever
<oprypin> nah don't mind me
<RX14> too many votes is likely to have the opposite effect lol
<RX14> i'd just think "oh they arrived as a group so thats basically 1 vote"
<FromGitter> <LuckyChicken91_twitter> uh do i not need to write my code in the module?
<RX14> have you tried testing it?
<RX14> doing it wrong win't eat your computer
<RX14> spoiler alert: it's not wrong
<FromGitter> <johnjansen> haha … @RX14 im thinking of writing a worm, is there anything i can do that will eat a computer ;-)
<FromGitter> <renich> ah... can't reproduce...
<FromGitter> <renich> hehehe
<FromGitter> <renich> Damn, this is fun but exhausting
<oprypin> renich, gee, just paste the whole thing as one file and point out where the problem is?
<FromGitter> <renich> oprypin: OK
<oprypin> i appreciate the effort you put into your questions. i often say give a reproducible example but really, it has to be minimal only for a bug report
<FromGitter> <renich> So, basically, line 56 needs `not_nil!`
<FromGitter> <johnjansen> @renich its inside a while, so it might not be initialized
<FromGitter> <renich> but, In my test example, it doesn't. https://play.crystal-lang.org/#/r/2c9x
<FromGitter> <johnjansen> totally different
<oprypin> renich, do you actually pop all items from the array but use only the last one?
<oprypin> or rather the "first" one
<FromGitter> <renich> oprypin: no, just enough of them to meet the expectation. There're hundreds.
<oprypin> `while 0 == 0; a = 5; end; use(a) # might be nil`
<oprypin> `while 0 != 0; a = 5; end; use(a) # might be nil`
<FromGitter> <johnjansen> if `while order.limit > accumulated` is never true, then `rival_order` is never init'd
<FromGitter> <renich> OK, what about the JSON.mapping. It does have type String | Nil. I need it that way so I can have a placeholder to be populated later. What is the alternative?
<RX14> you can redefine >
greengriminal has quit [Quit: This computer has gone to sleep]
<RX14> what if you defined it as always false
<FromGitter> <renich> For example, order is to be populated later on, after order creation
<RX14> the compiler simply can't optimise this
<oprypin> renich, https://play.crystal-lang.org/#/r/2ca1 but it throws an exception if you forget to initialize
<oprypin> basically a getter with a built in not_nil!
greengriminal has joined #crystal-lang
<FromGitter> <renich> The error I get when tremoving `not_nil!` reads: `Error in line 56: undefined method 'id' for Nil (compile-time type is (Arby::Mapping::Order | Nil)) ⏎ `
<FromGitter> <renich> oprypin: OK, looking at it
<FromGitter> <johnjansen> @renich please read my comment
<oprypin> renich, yes, everything in order there. it might be nil if loop iterated 0 times
greengriminal has quit [Client Quit]
<FromGitter> <renich> @johnjansen sure... errr... sorry
<FromGitter> <renich> @johnjansen so, I need to init rival_order, right?
<FromGitter> <johnjansen> as it stands, it can be nil, therefore you need to handle that
<FromGitter> <renich> OK
<RX14> just use not_nil! here
<FromGitter> <johnjansen> thats what he’s complaining about having to do
<FromGitter> <renich> Crystal sure helps on making sure you take care of things, eh? Cool...
<RX14> it's fine as-is unless you have some kind of action to preform if it's nil
<oprypin> the construct is weird even if you ignore the not nil part
<FromGitter> <johnjansen> this would happen in almost any language …
<FromGitter> <johnjansen> but at runtime in alot
<FromGitter> <johnjansen> which would be a big problem unless you caught it
<FromGitter> <renich> Thanks for the suggestions, guys. Really, I appreciate it a lot
greengriminal has joined #crystal-lang
<FromGitter> <crisward> Oh crystal has gone top of bounty source - https://salt.bountysource.com/
<FromGitter> <sdogruyol> Wow cool
<FromGitter> <johnjansen> well well
<FromGitter> <sdogruyol> It's neovim before
<FromGitter> <renich> It's been like that for a long time, hasn't it? Top 5?
<FromGitter> <sdogruyol> Let's push it to $2.5k+ :)
<FromGitter> <sdogruyol> Yeah
<FromGitter> <renich> :D
<FromGitter> <bew> last time I checked it was! cool it's still there!
<FromGitter> <renich> There should be some big corporation willing to support them with ~4k a month or something
<FromGitter> <sdogruyol> Support who? Crystal?
<FromGitter> <crisward> I opened an issue on gitlab - thought they should use crystal. We run gitlab ce and it eats memory. Their support could make a big difference. Think they're quite conservative though.
<FromGitter> <renich> @sdogruyol yep
<FromGitter> <sdogruyol> @crisward gitlab is way too conservative
<FromGitter> <sdogruyol> I've a close friend of mine working there
<FromGitter> <bew> @crisward agree, it would be great to improve performance and size of Gitlab installs!
<FromGitter> <crisward> Its such a big app, I'm sure the could slip it into one of their background workers or something.
<FromGitter> <sdogruyol> Yeah agree
<FromGitter> <sdogruyol> @crisward thanks for opening an issue
<FromGitter> <crisward> Feel free to annoy them with up-votes here - https://gitlab.com/gitlab-org/gitlab-ce/issues/23417 😉
<FromGitter> <johnjansen> can anyone point me in the right direction … im trying to convert `33188` to `-rw-r--r—` from `File::Stat#mode`
<FromGitter> <johnjansen> im assuming thats the approach
<Papierkorb> Lots of private people supporting crystal in there, interesting
<oprypin> johnjansen, wait.. what's that 33188 supposed to mean
<FromGitter> <sdogruyol> I guess have a lot of great supporters waiting for 1.0 :)
<FromGitter> <johnjansen> thats the problem @oprypin … these are the relevant methods in Stat i believe ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59653626329651f46e79536c]
<Papierkorb> johnjansen, 33188dez == 100644oct. Of these, 0o644 are the permission flags
<FromGitter> <johnjansen> thanks @papierkorb … thats a direction to head
<Papierkorb> Crystal should have a flags enum for that flying around, yes. If not, it's not too bad, but try to find it first.
<FromGitter> <johnjansen> i havent seen anything yet … doesnt mean it doesnt exist, but its not obvious how to even search for that
<oprypin> johnjansen, couldnt be anywhere other than File:: and it isnt there
<FromGitter> <johnjansen> that was my assumption
<FromGitter> <johnjansen> someone should add that ;-) … clearly not me though
<FromGitter> <bew> look at file/stat.cr to determine the first character of the result you want
<Papierkorb> johnjansen, have a flags enum, with Read = 4, Write = 2, Execute = 1 (rwx). Each octal digit is a category like user, group, other. Use that to figure out who has which rights, and turn that into a string. First digit (from the right) is other, then group, then user.
<Papierkorb> This is really the only remaining place where octal digits are useful.
<FromGitter> <johnjansen> @bew ??? you lost me
<Papierkorb> protip: An octal digit is represented as 3bits in binary
<FromGitter> <johnjansen> @papierkorb, thanks, im hacking on it now
<FromGitter> <renich> if `crystal play` had the ability to write changes and vim-like navigation, it would make for a great primal IDE for Crystal, definitely.
<FromGitter> <bew> was talking about the first `-` in your example result, `-` is for a regular file, `d` is for a directory, `s` is for a socket, and so on for the different file types...
<FromGitter> <renich> The workbook is really cool
<FromGitter> <johnjansen> oh yeah, got that thanks @bew
<FromGitter> <elorest> If vim commands worked in crystal play or play.crystal-lang.org I would love crystal even more than I do now. 👍
<FromGitter> <bew> ahah that's for sure, I think the easy way is to port crystal play functionnalities to vim :P
<FromGitter> <elorest> The js plugin that crystal play uses already has a vim plugin.
<FromGitter> <elorest> FYI
<FromGitter> <johnjansen> @elorest you have some spare time dont you ;-)
<FromGitter> <bew> I don't get it @elorest , that vim plugin does what?
<FromGitter> <bew> ah yes
<FromGitter> <elorest> Code mirror has a plugin that emulates vim.
<FromGitter> <bew> then THAT would be the easy part I guess..
<FromGitter> <elorest> It would definitely make my life easier. Would need a way to turn it of though for people who don’t use vim. :(
<FromGitter> <elorest> The vim mode and editor in general is a bit better with https://ace.c9.io/
<oprypin> johnjansen, Papierkorb, unfortunately messier than i expected https://carc.in/#/r/2cbh
<FromGitter> <bew> it could check the EDITOR environment variable to activate it by default or not
<Papierkorb> Erm, I wouldn't use a macro for 3x3 enum fields ...
<oprypin> well you see what you're trading for it on the right, probably
<FromGitter> <johnjansen> thanks @oprypin @papierkorb
<oprypin> it's silly that macros allow building up arrays but not incrementing a counter
<FromGitter> <bew> not incrementing counter? why not?
<FromGitter> <renich> https://play.crystal-lang.org/#/r/2cbj @ line 4: nil : Nil??? huh?
<oprypin> sorry what?
<FromGitter> <johnjansen> +1
<FromGitter> <renich> I think that is what's causing me the Nil issue
<FromGitter> <renich> line 4, in `crystal play`, shows: `nil : Nil`.
<oprypin> johnjansen, had an off by one in previous example https://carc.in/#/r/2cbu
<oprypin> renich, no it isnt what's causing
<FromGitter> <johnjansen> @renich your problem is as follows ⏎ ⏎ ```while something ⏎ x = a_value ⏎ end ⏎ x # might be nil``` [https://gitter.im/crystal-lang/crystal?at=59653b7a1c8697534a146810]
<FromGitter> <renich> OK... how do I prevent that, then?
<FromGitter> <elorest> I have a friend who might be interested in adding a vim mode to crystal play.
<oprypin> renich, it's saying that the return value of array.each is nil, which you don't care about at all
<FromGitter> <johnjansen> @renich you need to either a) suck it up and use not_nil! or b) initialize x with a value outside of the while
<FromGitter> <renich> @elorest that would be awesome
<FromGitter> <renich> I've seen vim mode in some web interfaces. Namely codewars.com
<FromGitter> <elorest> Is there any reason that code mirror was choosen as the JS editor instead of ace?
<FromGitter> <elorest> Ace seems much more supported and full feature.
<FromGitter> <renich> @johnjansen I thought I did that already, but let me check... I think I will end up sucking it up, hehe...
<FromGitter> <bew> @johnjansen about your permissions display, this is what I got so far (no enum though): https://carc.in/#/r/2cbv
<FromGitter> <johnjansen> hey @bew whats how does the mapping from `1 => -` `4 => d` happen btw
<FromGitter> <johnjansen> @bew thats nice, thanks
tzekid has joined #crystal-lang
<FromGitter> <renich> @johnjansen it worked, man! Cool!
<FromGitter> <johnjansen> btw im writing a version of `ls` with regex build in, trying to copy the output format of `-l` … this is entirely experimental of course
<FromGitter> <renich> wow... I've heard of a dude; from Helsinki, that started some odd project like that in the early nineties... the project went overboard...
<FromGitter> <bew> @johnjansen you can get a file type with methods like `Stat#blockdev?` (https://github.com/crystal-lang/crystal/blob/master/src/file/stat.cr#L134 and below)
<FromGitter> <bew> for the whole list of correct chars, see https://unix.stackexchange.com/a/59133/159811
<FromGitter> <johnjansen> nice … im neck deep in Stat, but there is alot hidden away in `c/sys/stat` that i dont want to peek in
<FromGitter> <renich> https://groups.google.com/forum/#!topic/comp.os.minix/dlNtH7RRrGA%5B1-25%5D
<FromGitter> <johnjansen> nice, must help knowing what to search for ;-)
<FromGitter> <renich> ;)
<FromGitter> <bew> nice project! I did a simple `ls` with some basic flags (`-Rla` iirc) in C for a school project 2 years ago, too bad they still don't accept Crystal :P
<FromGitter> <johnjansen> @bew I might hit you up for a few more morsels since some of the features are cryptic at best
<FromGitter> <bew> Feel free, I'll be happy to try to help ;)
<FromGitter> <johnjansen> Did you cover 'links' btw?
<FromGitter> <bew> yep
<FromGitter> <johnjansen> Oh good ... that one I'm yet to figure
<FromGitter> <bew> you should look at `man 2 stat` there are a lot of useful information about files for you!
greengriminal has quit [Quit: Leaving]
<FromGitter> <johnjansen> thanks @bew thats really useful
<FromGitter> <bew> yw ;)
<FromGitter> <johnjansen> a bit better on the documentation front than the crystal wrapper
<FromGitter> <johnjansen> im still wondering about the mapping from the first character to ‘-‘ ‘d’ etc … since its a 1 or a 4 or what else
<FromGitter> <johnjansen> from the nice list you linked, i have the chars, but not what the mapping is … having said that, should i be grabbing last 4 chars and whats left after that is the code … hmm
<FromGitter> <bew> it's the file type (`-` is for regular file, other chars specify what kind of special file it is), you can check the file type given a `Stat` object with `Stat#directory?` (would be `d`), or `Stat#socket?` (would be `s`)
<FromGitter> <bew> etcetera
<FromGitter> <bew> sorry but I don't get what you mean in your last message
<FromGitter> <johnjansen> yeah, sorry, i get that, im just wondering about how we arrived at that from the perms i.e. `100644` => ‘l’ etc …
<FromGitter> <johnjansen> and i thank you for your patience as i attempt to reverse engineer the world
<FromGitter> <bew> well, how did you get the perms?
<FromGitter> <johnjansen> File::Stat#mode.to_s(8) more or less
<FromGitter> <johnjansen> i can check directory? file? socket? etc, but I’m really just trying to figure out the mechanics of it under the hood
<FromGitter> <johnjansen> using a flashlight and a pickax
<FromGitter> <bew> then look at the code :D
<FromGitter> <bew> (for `Stat#directory?` and others)
<FromGitter> <bew> I almost always do that, even before I look at the documentation above the code or on the api website x)
<FromGitter> <elorest> Since http response body can/should be io/slice instead of string can response headers also be binary slice data?
<FromGitter> <johnjansen> should have known id wind up at wiki[something] @bew https://en.wikibooks.org/wiki/C_Programming/stat.h
<oprypin> elorest, response headers can't be binary data according to HTTP.
<oprypin> you can use base64 if you really want that
<FromGitter> <elorest> Yeah I usually use base64 for that but I build a way to gzip data and output it as a string so that I could make headers smaller if necessary. It worked fine but when I shared here yesterday everyone said you should never gzip a string just io. https://github.com/elorest/str_compressor
<oprypin> this makes me very sad
<oprypin> don't you understand that the output of gzip is not text?
<oprypin> strings can only contain text. you are doing a very dirty hack to work around that, for no reason whatsoever.
<oprypin> just drop the `to_s` and `to_slice` and everything's perfect
<FromGitter> <elorest> Except that I can’t use that in headers, which is what I just asked. That’s fine but that’s why I was doing it to string similar to how ruby stores gzip data.
<oprypin> you cannot look at how ruby stores gzip data
<oprypin> ruby has bytestrings, crystal has text-only strings and then Slice(UInt8) to work with bytes
<FromGitter> <elorest> I get that I can base64 encode it but then it’s smaller rather than bigger. Personally I don’t think large amounts of data should be store in cookies but it still makes sense to me to store it in as small a maner as possible.
<FromGitter> <elorest> Hence why I asked about sending byte data in headers.
<oprypin> you can technically send them but any sane client will reject that
<FromGitter> <elorest> Got it. I’m sorry I’m making you sad but could you just try one more time to explain to me why storing gzip bytes in a string for transmission accross text only communication is so bad? It works, and results in a smaller string… What am I missing?
<oprypin> elorest, Crystal's strings must contain only UTF-8 encoded text.
<oprypin> elorest, HTTP headers must consist of ASCII (or latin1 who knows) text.
<oprypin> gzip bytes are not text
<oprypin> HTTP::Headers does not accept bytes for a reason
hightower2 has joined #crystal-lang
<oprypin> normally you can deal with bytes using `Bytes` which is `Slice(UInt8)`. and put them wherever you like. but it's not valid for 3 reasons, so don't do that maybe?
<oprypin> i mean making broken strings to work around an intentional safety barrier is not valid
<oprypin> working with bytes is valid
<Papierkorb> elorest, you know those kids toys where you have to put geometric shaped objects into the same shaped hole in a box? You're hammering the triangle one into the circle hole. You can do it with enough force, but that doesn't make it fit.
<FromGitter> <elorest> So `"\xF3H\xCD\xC9\xC9/W(\xCF/\xCAI\u0001\u0000”` looks like text and can be sent through text and decoded on the other end.
<Papierkorb> No it can't.
<oprypin> `"\x**"` is a syntax to make broken string literals
<FromGitter> <elorest> <papierkorb> True but then usually the toy breaks.
<oprypin> introduced in crystal 0.21.0 under god knows what justification
<oprypin> elorest, well yes, anything that would look at your broken headers should just bail on you
<Papierkorb> elorest, well here, the HTTP connection breaks or does something unexpected or unpredictable.
<oprypin> the fact that it doesnt is just a technical detail of that particular browser or server
<oprypin> man i'm triggered
<oprypin> like ... intentionally adding syntax for broken string literals
<oprypin> and in the last few days i see 2 people doing hideous things justified by it and arguing with me that it's just fine
<FromGitter> <elorest> Basically it just stores that string in the cookies and sends it back and I ungzip it. While developing it wasn’t aware that it was a bad idea since it was an expectation I had from ruby (my bad there), and worked in crystal. You’re basically say that it shouldn’t work in crystal though and that adding `\x**` was a really bad idea.
<RX14> oprypin, does this look cortrect to you? https://gist.github.com/RX14/e79134d1d9964334d6c111e9a5193c90
<oprypin> yeah sure. the gist of it, don't put bytes in strings, keep them to Slices. and HTTP headers really don't accept bytes.
<oprypin> RX14, well that came out of nowhere. no idea
<RX14> i want to extract seconds and microseconds from a Time::Span
<oprypin> RX14, it's good
<FromGitter> <bew> looks right & clean
<oprypin> it is not necessary to use `uninitialized`
<RX14> it's what the other two methods use
<RX14> it's a lib struct so .new should do the same, right?
<oprypin> just have LibC::Timeval.new(tv_sec: , tv_usec:) at the end, it's cleaner too
<RX14> does that work with lib structs?
<oprypin> yeah they have that magically defined
<FromGitter> <elorest> Sorry for ruining your day. I understand the concept of (it doesn’t matter if something solves the problem and works, because it’s bad). I just like to understand why it’s bad.
<FromGitter> <elorest> Thanks for your help
<RX14> @elorest are you asking why you can't put binary in HTTP headers?
<RX14> because binary could just happen to contain two consecutive newlines...
<RX14> and then you have a malformed HTTP request
<RX14> in fact newlines are valid utf8, so http headers are more restrictive than just binary
<FromGitter> <elorest> Got it so even though `"\xF3H\xCD\xC9\xC9/W(\xCF/\xCAI\u0001\u0000” ` this works there’s a good chance another string wouldn’t?
<RX14> oh yes very possible
<RX14> i remember why asterite added it now oprypin
<oprypin> RX14, i know why but it's not justified
<RX14> previously inspecting strings which contained binary data segfaulted
<RX14> we should just have \x syntax when inspecting binary strings
<RX14> and make it restricted in the language
<FromGitter> <elorest> I see. It existing lead me to believe I could use it withoug the world ending. I’ll reconsider my ways.
<RX14> so it errors out but doesn't work
<oprypin> RX14, https://carc.in/#/r/2ccv s/milli/micro/
<RX14> oprypin, cool
<RX14> i guess i'll refactor the other two methods?
<oprypin> as I understand it, the conversion is also done the same way as you did before
<oprypin> probably but perhaps confirm that you don't need the .whatevertype.new
<RX14> oprypin, honestly with the typeof(x).new thing it gets ugly
<RX14> so i'll just s/uninitialized X/X.new
<oprypin> RX14, no but my point is you don't need the typeof(x).new !
<oprypin> that's implied
<RX14> it converts?
<RX14> interesting
<oprypin> (but i'm not 100% sure, please check)
<FromGitter> <johnjansen> hey @RX14 how can i get a particular bit out of an int
<RX14> int.bit(n)
<FromGitter> <johnjansen> haha … well how about that
<RX14> we really need a set bit function though
<RX14> it's a bit lopsided
<oprypin> | (1<<n)
<RX14> and then you need to branch to unset it
<RX14> which is a bit tiresom on functions which take a bool
ryanf_ is now known as ryanf
<RX14> oprypin, i was half-expecting this to happen: https://carc.in/#/r/2cdn
<RX14> i.e. it to overwrite y with the tail of the Int64
<FromGitter> <johnjansen> dang i asked the wrong question
<oprypin> nah apparently it cuts off high bits which is what type.new does
<RX14> yup
<FromGitter> <johnjansen> ok smart people, i have 0o700 and i need to get the bits that are set for the 7 in it … any nice shortcuts for that process
<FromGitter> <johnjansen> im thining there must be a cleaner way than `x.to_s(8)[0].to_i.to_s(2)`
<Papierkorb> See my protip above
<FromGitter> <bew> `x & 0o700` I guess?
<FromGitter> <johnjansen> i did, thats what led me here ;-)
<Papierkorb> ...
<FromGitter> <johnjansen> haha
<Papierkorb> johnjansen, please read up on bitwise operators.
<FromGitter> <johnjansen> i totally need to …
<FromGitter> <johnjansen> thanks people
hightower2 has quit [Ping timeout: 255 seconds]
hightower2 has joined #crystal-lang