RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
jemc has quit [Ping timeout: 246 seconds]
jemc has joined #crystal-lang
<FromGitter> <girng> hello
<FromGitter> <Blacksmoke16> o/
<FromGitter> <Sija> any1 cares for a game of chess? (:
PixeLInc has joined #crystal-lang
ua has quit [Ping timeout: 246 seconds]
ua has joined #crystal-lang
<FromGitter> <proyb6> Checkmate.
sp3ncer has joined #crystal-lang
sp3ncer has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <talbergs> @girng Hello m8 ;)
<FromGitter> <talbergs> @Sija Yes chess is my cup of tea...
marmotini_ has joined #crystal-lang
<FromGitter> <girng> hahaha
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 250 seconds]
jemc has quit [Ping timeout: 240 seconds]
marmotini has quit [Remote host closed the connection]
marmotini has joined #crystal-lang
<FromGitter> <sdogruyol> Have a nice week everyone πŸ‘‹
<FromGitter> <drum445> And you sir
<FromGitter> <mavu> I think I will make it my mission to support crystal development by posting at least once per day how nice the standard library is. That is almost the most impressive part for me.
<FromGitter> <HarrisonB> @mavu It is really wonderful! I especially love the `HTTP` namespaced modules & classes
<FromGitter> <mavu> I used the JSON over the weekend. and the mapping module is just great.
<FromGitter> <sdogruyol> @mavu that'd be really cool :)
<FromGitter> <sdogruyol> I'd be happy to share you posts
<FromGitter> <sdogruyol> your*
_whitelogger has joined #crystal-lang
<FromGitter> <sdogruyol> πŸ‘
<FromGitter> <girng> @mavu πŸ‘ x100!
<FromGitter> <j8r> @mavu what about JSON::Serializable? :P
DTZUZO has joined #crystal-lang
<FromGitter> <Prutheus> How to convert a Time object to a string with that format: "Feb 2, 2019 7:15 PM” ?
ashirase_ has quit [Ping timeout: 250 seconds]
ashirase has joined #crystal-lang
ua has quit [Ping timeout: 244 seconds]
<FromGitter> <drum445> JSON mapping and serializable are what got me into Crystal to begin with
<FromGitter> <maximvl> Hello everyone :)
<FromGitter> <maximvl> I'd like to check with you what is the status of Crystal? I come to check the language once in a while but never really learned or tried it
<FromGitter> <luislavena> @bew hey! I moved to Paris back in June, so around pretty much all the time now πŸ˜†
<FromGitter> <Prutheus> How to convert a Time object to a string with that format: "Feb 2, 2019 7:15 PM” ?
sagax has quit [Ping timeout: 250 seconds]
<FromGitter> <mavu> @maximvl Thats a hard to answer question. Its great? Everything is groovy?
<FromGitter> <maximvl> @mavu I wonder how is it from your point of view :)
<FromGitter> <mavu> @maximvl Pretty awesome. I'm about to deploy it a small crystal application in production on RaspberryPi in several Banks. (fingers crossed. so far internal testing seems ⏎ good :) )
<FromGitter> <maximvl> for myself I'm coming from Erlang background looking for a language to write desktop GUI with
<FromGitter> <maximvl> in crystal I like static typing, decent type system and memory management
<FromGitter> <mavu> have not used desktop gui with crystal, can't say anything about it.
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <maximvl> I'm wondering mostly because crystal is not a wide spread language, even compared to erlang %)
<FromGitter> <mavu> Question: What is a usual pattern to handle this: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ How do I catch exceptions and still get this to compile? [https://gitter.im/crystal-lang/crystal?at=5c615321ecef85660b87dc9a]
<FromGitter> <mavu> I tried re-raising the exception, and even exit. still complaining.
<FromGitter> <drum445> @Prutheus https://play.crystal-lang.org/#/r/682n/edit
<FromGitter> <drum445> Then use this page to format it how you want: https://crystal-lang.org/api/0.27.2/Time/Format.html
<FromGitter> <kingsleyh> @mavu you are deploying onto raspberryPI ? Are they being used in branches - I suppose they must be cheaper than full computers but I guess depends how much power is needed for whatever job they are doing
ua has joined #crystal-lang
<jokke> hey there o/
<jokke> following example code: https://paste.marcusmichaely.com/RXm9M/
<jokke> an idea why this is blocking forever?
<jokke> *any
<jokke> i've tried what feels like every permutation of read/write_blocking and closing the pipe manually
sagax has joined #crystal-lang
<FromGitter> <bararchy> maybe try flush ?
<FromGitter> <bararchy> or IO.synce = true
<FromGitter> <bararchy> `IO.sync`
<FromGitter> <Blacksmoke16> @mavu Might be interested in https://github.com/Blacksmoke16/CrSerializer/tree/master/docs as well. Adds some easy validation/more features to the serialization side of things
<FromGitter> <Blacksmoke16> @Prutheus https://crystal-lang.org/api/0.27.0/Time/Format.html would have to figure out what set of directives to use then use them on a `to_s` call
gangstacat has joined #crystal-lang
<FromGitter> <mavu> @Blacksmoke16 that looks cool, but overkill for what I used the json mapping for. ⏎ I noticed that the web-radio I usually listen to has updated their website (and broke my old script that grabs the current playing artist/song and writes it to a file when I request it). ⏎ In this updated they added metadata (in json) to the currently playing song, and to my great delight it includes a url to the youtube
<FromGitter> ... version of the song (if available). ⏎ SoI just wrote a little program that grabs the info, downloads the audio from youtube and converts it to mp3 with tags etc. [https://gitter.im/crystal-lang/crystal?at=5c61769d7502282258daa4b5]
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <Blacksmoke16> prob would be for that :p
<jokke> barachy: i'm not sure what you mean. where should i set IO.sync = true. I've tried flushing but that just blocks for ever
<FromGitter> <mavu> btw, https://www.fip.fr/player ⏎ best radio on the internet.
<FromGitter> <mavu> @kingsleyh Raspberries are not that slow actually. I had Intel Atom boxes that feel much worse.
<FromGitter> <alex-lairan> Hi, I want to build methods automatically from a template type, I've write this : ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ This code give me `undefined constant T::FIELDS` (It's `T` who is undefined) ... [https://gitter.im/crystal-lang/crystal?at=5c617d15dc3f0523cc986f49]
<FromGitter> <girng> hmmm was thinking about this dilemma today. for example, if a player loots some copper or silver (tons of it), i don't want to update their mysql column each time. it would destroy the database. however, i can increase client.gold += amount, then have a method running in the background that updates every xx seconds instead. and just check if any client's `gold` has changed and update them. would work quite well
<FromGitter> ... actually. ⏎ ⏎ however, one downside is f the gameserver disconnects, that player will lose that amount they just looted. it would be xx seconds worth (or how long the db update interval is set for). i was thinking of doing this with items, but i definitely don't want a player to loot something nice and it be gone. so tho ... [https://gitter.im/crystal-lang/crystal?at=5c617d22ecef85660b88fa5d]
<FromGitter> <mavu> @girng have the world simulation run on the server not the client. if the client disconnects, it does not matter because the state of the world is on the server. This also avoids problems with cheating players.
<FromGitter> <drum445> @girng you should never trust input from the client, all actions should be verified on the server ideally. This would also solve your issue with the server going down
tankf33der has joined #crystal-lang
<tankf33der> o/
<tankf33der> is broken.
<tankf33der> known right ?
marmotini has quit [Ping timeout: 246 seconds]
<tankf33der> and voidlinux is broken too.
<tankf33der> you broke the internet :)
<FromGitter> <alex-lairan> `@types.type_vars` give me an array of generics, but it's `[T]` and not the real object (I want `[User]` for example)
<tankf33der> 0.27.2 released 6 days ago and no one cares. perfect.
<FromGitter> <alex-lairan> And `T` is a `MacroId`, I cannot loop over methods
<tankf33der> classics.
<FromGitter> <j8r> @alex-lairan you can do `.first`
<FromGitter> <j8r> nvm
<FromGitter> <j8r> try maybe with a macro hook
<FromGitter> <alex-lairan> There is no hook for generic :(
<FromGitter> <alex-lairan> The full context. ⏎ ⏎ I'm creating an Entity Repository ORM for MongoDB. ⏎ ⏎ I want to do things like this : ... [https://gitter.im/crystal-lang/crystal?at=5c6184d23608b004a0a8d54f]
rohitpaulk has joined #crystal-lang
<FromGitter> <Blacksmoke16> are you going to have everything inherit from `Repository`?
<FromGitter> <alex-lairan> It can be `class AdminRepo < UserRepository`
<FromGitter> <alex-lairan> But yes, `Repository` will be the root class
<FromGitter> <Blacksmoke16> problem with `T` is that at compile time its not defined unless a T is set
<FromGitter> <Blacksmoke16> sec
<FromGitter> <alex-lairan> Sample of my entity : ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c61860a80df6804a187f90e]
<FromGitter> <j8r> there is https://carc.in/#/r/684s
<FromGitter> <Blacksmoke16> also annotations to avoid the mutable constants
<FromGitter> <alex-lairan> @j8r I can declare new methods on `new` ?
<FromGitter> <j8r> @alex-lairan can you send an example to fix in carc.in?
<FromGitter> <j8r> a simple one
<FromGitter> <alex-lairan> (ps: My `Repo` don't have theses methods, it's the `WhereBuilder` but it's not important :) ) ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I do the carc :) [https://gitter.im/crystal-lang/crystal?at=5c618757d1e3093ab500eca9]
<FromGitter> <alex-lairan> https://carc.in/#/r/685a
<FromGitter> <j8r> I see better, thanks
<FromGitter> <j8r> Have you evaluated alternatives to this approach?
<FromGitter> <j8r> Like using composition, or using structs to represent the data model?
<FromGitter> <alex-lairan> Yes, https://luckyframework.org/guides/querying-the-database/ Avram ORM build a new class directly from the entity.
<FromGitter> <Blacksmoke16> why not just use properties
<FromGitter> <Blacksmoke16> then you get getter/setters included by default
<FromGitter> <alex-lairan> An entity will have a changeset generated, it's not just data :)
DTZUZO has quit [Ping timeout: 250 seconds]
marmotini has joined #crystal-lang
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <j8r> you approach seems wrong
<FromGitter> <j8r> It seems logical, but we are fighting against the language
<FromGitter> <j8r> @alex-lairan Isn't possible to directory use the macro inside `class User`?
<FromGitter> <j8r> It would be so much easier
<FromGitter> <j8r> https://carc.in/#/r/685v :P
<FromGitter> <alex-lairan> It's how Avram work, and it's one possibility I will explore if there is no way to use Generics
<FromGitter> <alex-lairan> (But creating another class)
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> sadly no way to do that with annotations either :(
<FromGitter> <Blacksmoke16> dont have access to ivars outside of a method :/
<FromGitter> <alex-lairan> Do you think is possible to do this ? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I have an Idea ! Do something like this, what do you think? [https://gitter.im/crystal-lang/crystal?at=5c618c2fef98455ea4196581]
<FromGitter> <alex-lairan> ```code paste, see link``` ⏎ ⏎ This work `UserRepo(UserModel).new.builder` [https://gitter.im/crystal-lang/crystal?at=5c618c85253c2b5ea3f43d3b]
rohitpaulk has joined #crystal-lang
jemc has joined #crystal-lang
marmotini has quit [Ping timeout: 268 seconds]
<FromGitter> <alex-lairan> New problem :) ⏎ ⏎ I've build this : ⏎ ⏎ ``` abstract class Entity ⏎ FIELD_MAPPINGS = {} of Nil => Nil ⏎ ⏎ macro inherited``` [https://gitter.im/crystal-lang/crystal?at=5c619536604f233ab6f0391f]
<FromGitter> <alex-lairan> New problem :) ⏎ ⏎ I've build this : ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5c61957c8328315decd7e798]
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> 😬
* FromGitter * Blacksmoke16 isnt a fan of those mutable constants
<FromGitter> <Blacksmoke16> make sure that file/class is required/defined before its used
<FromGitter> <alex-lairan> I have this : `require "./where_builder"`
<FromGitter> <alex-lairan> (For mutable constants, I'm not fan too, but I need to build methods from something ^^)
<FromGitter> <alex-lairan> A minimal `carc` for this problem : https://carc.in/#/r/6886
<FromGitter> <j8r> agree with @Blacksmoke16 , avoid using mutable constants, specially if they are no use outside the macro
<FromGitter> <alex-lairan> Should I freeze them inside the `finished` ?
Yxhuvud has joined #crystal-lang
<FromGitter> <Blacksmoke16> yea sadly mutable constants allow for stuff that annotations cannot do, so dont have much choice in some cases
<FromGitter> <Blacksmoke16> at least without totally rethinking how something should look/be done
marmotini_ has joined #crystal-lang
<FromGitter> <alex-lairan> I found ! ⏎ ⏎ ```class Foo(T) ⏎ def initialize ⏎ @find = T.builder.new # Work``` [https://gitter.im/crystal-lang/crystal?at=5c61a93c16e4682259977505]
<jokke> is there a way to create an empty named tuple?
<FromGitter> <j8r> why O.o?
<jokke> just as a default value
<jokke> i merge it to another named tuple
<FromGitter> <j8r> `NamedTuple.new` ?
<jokke> j8r: :)
<jokke> thanks
<FromGitter> <j8r> no sure it'll work in your case
tankf33der has left #crystal-lang [#crystal-lang]
<FromGitter> <girng> possible dumb question incoming:
<FromGitter> <girng> is it possible to communicate with crystal by using php?
<FromGitter> <j8r> through a socket or file descriptor
<rkeene> I'm going to say "Yes"
<rkeene> Anything you can sufficiently define is possible
<rkeene> Most things are a bad idea, though
<FromGitter> <j8r> that's common to communicate through a socket
<FromGitter> <j8r> for example PHP <=> MySQL
<FromGitter> <j8r> it can be PHP <=> Crystal
<FromGitter> <girng> hmm gonna look into sockets
<FromGitter> <j8r> usually they are created in /run and end with `.sock` if you wonder
<FromGitter> <girng> oh so php has sockets already. i can just use that when i need to send something to my crystal process
<FromGitter> <girng> just connect and send message? do i have to do that every time? i wonder if it's possible to keep it open so i don't have to connect each time
<FromGitter> <girng> but i guess this is more of a php question
<FromGitter> <girng> end goal: when someone purchases an item from the auction house, i need php to send a message to my crystal process (master server) that the item was bought, which then notifies that player. i can code the auction house in my master server, but i really don't want to because i want it to be web based as well, and the entire site/forum is already written in php
<FromGitter> <girng> or.. scratch the web based auction house and just have it in-game. prob better
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <j8r> You can create the socket in Crystal, like /run/myapp.sock`
<FromGitter> <j8r> Send your PHP app send data to it
<FromGitter> <girng> i spoke too soon, sorry
<FromGitter> <johanalkstal> If I understand things correctly, `require` is only used to tell the compiler about other files that are needed? Does that mean that you only need `require`calls in a single root file? It's not like `require()` and `import` from JavaScript for example?
<FromGitter> <johanalkstal> Trying to learn Crystal by reading Programming Crystal and so far am liking it but some things are still not "crystal clear"... :P
cyberarm has quit [Ping timeout: 240 seconds]
<FromGitter> <johanalkstal> Another one is when to use `private` or `protected`?
<FromGitter> <j8r> Sure you can do everything in a single file or require the world
<FromGitter> <johanalkstal> What does that mean? :D
<FromGitter> <j8r> It's considered best practise to modularize, then require what you nees
<FromGitter> <j8r> *need
<FromGitter> <j8r> You can `require "./**"` :(
marmotini has quit [Ping timeout: 272 seconds]
<FromGitter> <j8r> Why this exists :(
<FromGitter> <johanalkstal> Perhaps my question and understanding is a bit off. `require` doesn't bring the required module into scope like it does in JavaScript? It's not "I need this module in this file so I will require it", or is it? ⏎ The way I read the book is that `require` is only for the compiler to compile all files into a single file in the end, is that right?
<FromGitter> <jwoertink> @johanalkstal You are correct that the require is not like javascript. You require once, and then get access to that in all your files. The order of your require also matters.
<FromGitter> <j8r> Use private if the method must not be used publicly
<FromGitter> <johanalkstal> @jwoertink The order of require matters?
<FromGitter> <j8r> Yes, for the AST
<FromGitter> <jwoertink> Yes
<FromGitter> <j8r> The tree built by the compiler
<FromGitter> <jwoertink> ```require "file_a" ⏎ require "file_b"``` [https://gitter.im/crystal-lang/crystal?at=5c61bdfbecef85660b8af71f]
cyberarm has joined #crystal-lang
<FromGitter> <jwoertink> if you had this, you couldn't access anything in file_b from within file_a because file_b hadn't been required at that time
<FromGitter> <johanalkstal> Okay. So then it would make sense to use a `require` at the point a file actually "requires" another file
<FromGitter> <jwoertink> however, you could access file_a stuff inside file_b because file_a had already been required
<FromGitter> <johanalkstal> Hmm okay. So basically require anything that will be needed by anything further down the tree from that point.
<FromGitter> <johanalkstal> A require is a new branch
<FromGitter> <j8r> Yep. When writing tests, you usually only require the tested methods in a file, that eventually have requires inside
<FromGitter> <johanalkstal> Okay, thanks for helping out
<FromGitter> <j8r> IIRC there is a command to inspect the AST
fullforce has joined #crystal-lang
<fullforce> is there a way to use OR with namedtuple?
<fullforce> trying to make something where if the namedtuple key doesnt exist, it defaults to another value
<oprypin> t[:key]? ||
<fullforce> thank you.
<fullforce> ill make sure to read the docs more harder next time lol
Kero has left #crystal-lang [#crystal-lang]
DTZUZO has joined #crystal-lang
<FromGitter> <vivus-ignis> is there anything like python's `if *name* == '__main__':` in crystal? i would like my app to run in a "library mode" when i do `crystal spec`
<FromGitter> <j8r> what do you mmea
<FromGitter> <vivus-ignis> right now, when i do crystal spec
<FromGitter> <vivus-ignis> it evaluates the main logic, which is to parse commandline parameters and then detect the current linux distro
<FromGitter> <vivus-ignis> which is not what i want for testing
<FromGitter> <vivus-ignis> so... is there a way to detect that my app is being run as a binary instead of being loaded in a spec file?
<FromGitter> <Blacksmoke16> could maybe use a compile time flag that you pass to `crystal spec`
<FromGitter> <bew> @vivus-ignis no there isn't
<FromGitter> <Blacksmoke16> or within your main file...
<FromGitter> <j8r> @vivus-ignis just create a `cli.cr`
<FromGitter> <j8r> which require you `main_app.cr`, which you use in the specs
<FromGitter> <Blacksmoke16> how would that be any diff to just requiring the main app?
<FromGitter> <vivus-ignis> i think i can try with the compile flag
<FromGitter> <vivus-ignis> i already had to do that to help with static build
<FromGitter> <j8r> look at other projects
<FromGitter> <j8r> they separate cli and the actual program
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <vivus-ignis> thank you @Blacksmoke16 @j8r
<FromGitter> <Blacksmoke16> can you have a method with a type def of a specific enum member?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/689t :(
<FromGitter> <vivus-ignis> build flag was an easy one to solve this question
<FromGitter> <vivus-ignis> thanks again!
<FromGitter> <Blacksmoke16> np
<FromGitter> <bararchy> @Sija found another one:) https://github.com/crystal-lang/crystal/issues/7415
<FromGitter> <Sija> no shit, again...?!
<FromGitter> <Sija> at the first sight date looks fine though...
<FromGitter> <bararchy> it won't recognize httponly flag
<FromGitter> <bararchy> sends the whole cookie to the "extenstion" string
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c61edc783f3873903891373]
<FromGitter> <Sija> r you sure you're using Crystal from `master`?
<FromGitter> <bararchy> oh no
<FromGitter> <Sija> :)
<FromGitter> <bararchy> it's stock 0.27.2, but, is this the same issue?
<FromGitter> <Sija> that's exactly the same format as in IIS fuckup last time
<FromGitter> <Sija> (I'm 99% sure)
<FromGitter> <bararchy> Ohhhh I see, I guess the server is IIS behind some apache proxy
<FromGitter> <bararchy> we allow case-insensitive httponly right?
<FromGitter> <bararchy> because it's also something I'm seeing here
<FromGitter> <Sija> yep
<FromGitter> <bararchy> cool
<FromGitter> <bararchy> I'll try master
<FromGitter> <Sija> If anyone is willing to go through https://sija.pl/en/notes/crystal-error-tracking-with-sentry and critique the shit out of it I'd be most grateful, cheers! :)
<FromGitter> <straight-shoota> @Sija looks great πŸ‘
<FromGitter> <Sija> @straight-shoota Thanks, happy to hear that!
<FromGitter> <bararchy> Yeha, looks real nice :) will also try it out
<FromGitter> <straight-shoota> IIRC `raven.cr` automatically reads the `SENTRY_DSN` env var, right?
<FromGitter> <straight-shoota> You should mention that in DSN muß sein section
<FromGitter> <Sija> yep, it does.
<FromGitter> <Sija> hmm, it's there maybe not clear enough...
<FromGitter> <straight-shoota> Yeah, I think it should better be explicit
<FromGitter> <straight-shoota> In sentry's Ruby integration, it says "Like most Sentry libraries it will honor the SENTRY_DSN environment variable."
<FromGitter> <Sija> good point, will do!
PixeLInc has left #crystal-lang ["WeeChat 2.1"]
badeball_ has joined #crystal-lang
<fullforce> hi
<fullforce> ive run into a snag ive been working on for a while that i cant get out of
<fullforce> 1sec lemme haste it
badeball has quit [*.net *.split]
<fullforce> I have a nil check right under the declaration too that raises an error if @sock is nil