jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.0 | 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
fullforce has joined #crystal-lang
<fullforce> is there an easy way to pass the class that a function was invoked from?
<fullforce> javascript had
<fullforce> Function​.prototype​.bind()
<fullforce> but the only solution I can see right now is to just pass it as another parameter, which would add to the amount of code a little
<fullforce> any ideas?
<FromGitter> <Blacksmoke16> maybe? can you make a little example with what you are expecting?
<FromGitter> <tenebrousedge> what's the goal?
<fullforce> to be able to reference that class in a function outside of that class
<fullforce> if that makes any sense rofl
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr
<FromGitter> <Blacksmoke16> will be easier to figure out :)
<fullforce> ill do that in a minute
<fullforce> brb gotta get milk
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> was wondering why my pc was being a bit slow...was using 45 Gb of RAM...15 gigs into swap ha
<fullforce> back
<FromGitter> <Blacksmoke16> have to go all the way to the farm? :p
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/athena/releases/tag/v0.6.1 new Athena version released to fix some bugs
<FromGitter> <Blacksmoke16> https://dev.to/blacksmoke16/creating-a-json-api-with-athena--granite-510i also updated the blog post and full code example to work with newest version
<FromGitter> <szutt> Hello. I tried to iterate from an YAML file but i got an error : undefined method 'each' for YAML::Any : I tested with the reference manual https://crystal-lang.org/api/0.28.0/YAML.html and I wanted tu use each but I got this : https://play.crystal-lang.org/#/r/6rza : I'm a noob and I don't know how to use it ...
<FromGitter> <Blacksmoke16> `as_a.each`
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.28.0/YAML/Any.html#as_a%3AArray%28Any%29-instance-method
<FromGitter> <szutt> It seems not working ... https://play.crystal-lang.org/#/r/6rzd
<FromGitter> <Blacksmoke16> alternative would be to use https://crystal-lang.org/api/0.28.0/YAML/Serializable.html to deserialize the yaml structure into objects
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6rzg
<FromGitter> <Blacksmoke16> need to also cast the other as a hash
<FromGitter> <Blacksmoke16> using `as_h`
<FromGitter> <szutt> Oh thanks, I got it : https://play.crystal-lang.org/#/r/6rzn !!
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6rzs also works
<FromGitter> <Blacksmoke16> 😉
<FromGitter> <szutt> @Blacksmoke16 Thanks a lot ^^
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> working with dynamic yaml/json data can be a bit of a pain, due to the typed nature of crystal
<FromGitter> <Blacksmoke16> types of everything have to be known (or casted) for them to work correctly
_whitelogger has joined #crystal-lang
<FromGitter> <szutt> oh okay
yield__ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 255 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <bew> @Blacksmoke16 nice post about athena! It's too bad you have to put annotations in strings like that though.. It would be better to add them to the macro call somehow and be able to reference them from the macro to attach them to whatever you want!
<FromGitter> <bew> (not possible currently though)
DTZUZO has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 258 seconds]
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
mntmn has quit [Remote host closed the connection]
mntmn has joined #crystal-lang
<FromGitter> <jackturnbull> Chipping in from the bleachers with a question; anyone know of a way to send a TCP RST/reset packet from a HTTP server response?
<FromGitter> <jackturnbull> Expecting the answer to be 'you can't' from what I've seen so far, but thought I'd try my luck anyway
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
dostoyevsky has quit [Ping timeout: 268 seconds]
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Client Quit]
dostoyevsky has joined #crystal-lang
dostoyevsky has quit [Ping timeout: 258 seconds]
<FromGitter> <petoem> @jackturnbull You can call `HTTP::Server::Response#upgrade` to get the socket and set `Socket#linger=` to `0`. Maybe this works for you.
<FromGitter> <petoem> https://crystal-lang.org/api/0.28.0/Socket.html#linger%3D%28val%3AInt%3F%29-instance-method
dostoyevsky has joined #crystal-lang
rohitpaulk has joined #crystal-lang
yield__ has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
<FromGitter> <Blacksmoke16> @bew yea for sure :( However im getting close to having in initial version of my name pending annotation ORM, prob do a follow up post showing what the difference would be
<FromGitter> <Blacksmoke16> would be something like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cbeffc36a84d76ed8deed48]
alexherbo2 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
go|dfish has joined #crystal-lang
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
faustinoaq has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> the CI is still using crystal 0.27.2 :(
<FromGitter> <vladfaust> @Blacksmoke16 a problem I've faced is loading model without some fields from DB. For example, SQL query which doesn't have "name" in the result set. Still, you have a non-nilable `String` for it
<FromGitter> <Blacksmoke16> @vladfaust but why wouldnt the name exist if its in in your model's fields?
<FromGitter> <Blacksmoke16> like if the user wanted to do like `select body, title, id from articles;`?
<FromGitter> <vladfaust> Yes
<FromGitter> <Blacksmoke16> either i just dont support doing that, or do something like https://play.crystal-lang.org/#/r/6s2m
<FromGitter> <Blacksmoke16> and would just blowup on user if they tried to use a field they didnt request
<FromGitter> <Blacksmoke16> there are options
<FromGitter> <Blacksmoke16> but yea its a problem i been thinking about a while, would have to figure out a way to have like "partial nilability"
<FromGitter> <vladfaust> I made all props nilable
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <Blacksmoke16> would be annoying to do like `model.age + 1` and get `unknown method + for (Nil | Int32)`, but id imagine you have a like `model.age!` to say its not nil?
<FromGitter> <Blacksmoke16> its only a prototype atm so im not certain everything i want to do is even possible yet haha
<FromGitter> <Blacksmoke16> go for best case then go from there
<FromGitter> <Blacksmoke16> plus with an ORM id be ok with forgoing *some* functionality, such as the selecting specific fields, just to reduce the complexity
hightower2 has quit [Ping timeout: 276 seconds]
<FromGitter> <j8r> is it possible to allow formatting inside macro?
<FromGitter> <j8r> If not, having a macro annotation for that would be great :D
rohitpaulk has quit [Ping timeout: 276 seconds]
<FromGitter> <Blacksmoke16> hm?
lucasb has joined #crystal-lang
<FromGitter> <j8r> code inside macros isn't formatted by default, FYI
<FromGitter> <Blacksmoke16> gotcha
<wuehlmaus> i find it a bit awkward that the shell script crystal and the binary crystal which is big aren't differentiated by name, am i the only one?
<wuehlmaus> i was linking the wrong crystal and hedron didn't compile and i didn't know why
<wuehlmaus> and the errors were confusing ....
<FromGitter> <Blacksmoke16> shell script crystal?
rohitpaulk has joined #crystal-lang
<wuehlmaus> in bin is a posix shell script here
<wuehlmaus> # Copyright (c) 2014 Michael Kropat
rohitpaulk has quit [Ping timeout: 245 seconds]
<wuehlmaus> hmmm, old
<wuehlmaus> don't know where i got this from, okay i ignore it
<FromGitter> <Blacksmoke16> :p 👍
<FromGitter> <Blacksmoke16> i think i know which you're talking about
<FromGitter> <Blacksmoke16> that one gets generated when you build crystal from source
<wuehlmaus> which i do as i am a bleeding edger :-)
<FromGitter> <Blacksmoke16> ;)
<FromGitter> <Blacksmoke16> whats the proper way to handle writing to an io. Like say i want to log something to a file on each http request. Id imagine id do like
<FromGitter> <Blacksmoke16> like do i have to worry about doing `logger.close` after each write?
<FromGitter> <tenebrousedge> do you have a dedicated `Logger` class?
<FromGitter> <Blacksmoke16> id just be using stdlib logger
<FromGitter> <Blacksmoke16> but yea, plan would be to have a class var to set the logger
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cbf79fba4ef097471ea1825]
<FromGitter> <tenebrousedge> a class var? Why not pass it in to the method?
<FromGitter> <Blacksmoke16> because its going to be global
<FromGitter> <Blacksmoke16> so anywhere you could do like `Klass.info "foo"`
<FromGitter> <Blacksmoke16> or would it be better to have my own method like `Klass.log(message, context, level)` which opens the log file and writes to it in the `File.open &block`
<FromGitter> <Blacksmoke16> or maybe instead of closing just call `#flush` on the file IO var?
<FromGitter> <tenebrousedge> I would probably prefer using a `log` method. That seems to me to be more in accord with Demeter/DI principles
<FromGitter> <Blacksmoke16> then prob just use stdlib Logger to actually handle things behind the scenes
<FromGitter> <tenebrousedge> you will be logging to `/dev/null` for testing, yeah?
<FromGitter> <Blacksmoke16> unsure yet
<FromGitter> <Blacksmoke16> just exploring some things and figuring out how i want to set this up
<FromGitter> <tenebrousedge> it will probably be useful to be able to run tests on read-only filesystems
<FromGitter> <Blacksmoke16> could be disabled via config setting so shouldn't be an issue, assuming user is aware of that and turns it off
<FromGitter> <Blacksmoke16> i can link you the RFC im working on if you'd like to read it
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/athena/issues/13#issuecomment-485975637 is the initial plan atm
<FromGitter> <tenebrousedge> I would probably stress the importance of docker-centric workflows, re: configuration
<FromGitter> <Blacksmoke16> should be fine for that, would be able to customize output directories for each env, then just use a volume to store that on host machine
<FromGitter> <Blacksmoke16> probably should do something for log rolling
<FromGitter> <Blacksmoke16> maybe check size and if its over configured rename it, then delete oldest?
<FromGitter> <tenebrousedge> I think log rotation should probably not be an application concern
<FromGitter> <Blacksmoke16> yea good call, are other tools more suited to doing that
<FromGitter> <tenebrousedge> having different log handlers is probably going to push you in a pub/sub direction
<FromGitter> <Blacksmoke16> by default would just be the log file and STDOUT if in dev mode, but would be a good feature to have available. I could see having a stage to push errors to like elasticsearch or something
<FromGitter> <Blacksmoke16> again still mostly in thinking stage
<FromGitter> <tenebrousedge> STDOUT should certainly be the default handler, but it should also be easy for models to register a handler for emailing messages for certain error conditions
<FromGitter> <Blacksmoke16> possibly could have each log handler define a like `handles?` method that returns a bool on if that handler should execute for the current message
<FromGitter> <Blacksmoke16> might be making this way more complex then it has to be tho haha
<FromGitter> <Blacksmoke16> will see how it goes
<FromGitter> <tenebrousedge> well, it can probably just pass in the event to the handler closure
<FromGitter> <tenebrousedge> the handler should probably always execute if registered, and whether or not it does anything is up to it
<FromGitter> <tenebrousedge> and I would not say that this is more complicated than it needs to be. Emailing certain error messages is pretty much a must-have
<FromGitter> <Blacksmoke16> ye, would be quite handy
<FromGitter> <Blacksmoke16> will just have to think of how i want it to work, what data gets passed to each etc
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <sbrown17> Hey all! I had a quick question. I'm looking for which visual studio code extension to get for crystal, i was wondering which one is most widely used by any of you who happen to be using vscode to do your crystal coding.. this one seems pretty popular, is it the most widely used/liked one? Because it seems like the case: https://marketplace.visualstudio.com/items?itemName=faustinoaq.crystal-lang
<FromGitter> <girng> @sbrown17 yep. works great
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> o/
<FromGitter> <sbrown17> ty :)