<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
<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.
<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>
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>
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> 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
<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>
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>
<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>
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>
<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?
<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
<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> 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
<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>
<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
<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>
<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>
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
<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
<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
<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
<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>
<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>
<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!
<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)
<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.
<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.