ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.31.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
<FromGitter> <watzon> What happens in C if you try to access an array index larger than the size of the array?
<FromGitter> <Blacksmoke16> *doom*
<FromGitter> <watzon> Does it overflow? Or just return 0 or something?
<FromGitter> <watzon> Because this, in Crystal, throws an index out of bounds exception
<FromGitter> <Blacksmoke16> looks like just a garbage value?
<FromGitter> <tenebrousedge> you read further into memory
<FromGitter> <watzon> Ruh roh
<FromGitter> <tenebrousedge> lots of security errors begin this way
<FromGitter> <tenebrousedge> certainly it's the median computer security flaw in history, and may actually be the majority of all computer security flaws
<FromGitter> <watzon> Yeah that makes sense
<FromGitter> <watzon> Damn C
<FromGitter> <watzon> Maybe I'm doing this wrong
<FromGitter> <watzon> Yes I am
<FromGitter> <watzon> I'm using `0.upto(nk)` when I should be going up to nk - 1
<FromGitter> <tenebrousedge> so `(0...nk)`
<FromGitter> <watzon> Yep haha
<FromGitter> <watzon> Hmm, is there a better way to handle a for loop like this than with a while loop? ⏎ ⏎ ```for (i = 0, j = 56; i < j; i += 4, j -= 4) { ⏎ ... ⏎ }``` [https://gitter.im/crystal-lang/crystal?at=5dec45639319bb5190fae450]
<FromGitter> <watzon> Right now I have this, but it doesn't feel very Crystally ⏎ ⏎ ```i = 0; j = 56 ⏎ while i < j ⏎ ... ⏎ end ``` [https://gitter.im/crystal-lang/crystal?at=5dec459b9319bb5190fae57d]
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.31.1/Number.html#step(*,to=nil,by=1,&block)-instance-method ?
<FromGitter> <Blacksmoke16> oh nvm, are more than 1 vars
<FromGitter> <watzon> Yeah that's the issue haha
<FromGitter> <watzon> I used step in another part
<FromGitter> <tenebrousedge> `a = (0...56).step(4); a.zip(a.reverse)`
<FromGitter> <tenebrousedge> hmm, does range have reverse?
<FromGitter> <Blacksmoke16> prob would have to make it an array first?
dwdv has quit [Ping timeout: 276 seconds]
<FromGitter> <christopherzimmerman> @watzon you can just divide (j-i) by the factor you scale them by and loop that many times. Assuming they scale at the same inverse rate
<FromGitter> <christopherzimmerman> I guess it would be dividing by the factor times 2
<FromGitter> <christopherzimmerman> It also should be a minor performance tweak since you only would calculate once.
<FromGitter> <christopherzimmerman> It also assumes you don’t need i or j in the loop
_whitelogger has joined #crystal-lang
Creatornator has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 265 seconds]
<FromGitter> <watzon> What should you do if a C library you're trying to link to has a struct with uppercase field names?
<FromGitter> <anamba> hi all, long time. i'm using HTTP::Client to test for IPv4 and IPv6 connectivity. for a host that supports both, is there a way to force it to use one or the other?
<FromGitter> <anamba> i suppose i could do the DNS resolution myself, then point HTTP::Client at either the IPv6 address or the IPv4 address, making sure to set the Host header appropriately. if that's the easiest way then so be it, but in that case, my question becomes, what's the best way to do the DNS resolution step?
<FromGitter> <Blacksmoke16> er sorry, field names
<FromGitter> <watzon> Found what I was looking for actually
<FromGitter> <watzon> Apparently field names don't matter, but I'm getting a segfault somewhere
<FromGitter> <Blacksmoke16> 👍 fair enough
<FromGitter> <watzon> Got it working. Didn't like my `uninitialized` and `pointerof` for some reason
<FromGitter> <watzon> But `Pointer(U).malloc` worked
<FromGitter> <anamba> answered my own question by reading the stdlib source (still easily my favorite aspect of Crystal). HTTP::Client uses TCPSocket, which uses Socket::Addrinfo.resolve. ```
<FromGitter> <anamba> ```code paste, see link```
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <watzon> Why does working with slices have to be such a pain in the ass?
Human_G33k has quit [Remote host closed the connection]
<Yxhuvud> Is it?
_whitelogger has joined #crystal-lang
return0e has quit [Ping timeout: 265 seconds]
return0e has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
dwdv has joined #crystal-lang
DTZUZO has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 252 seconds]
_whitelogger has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
blassin has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
ua has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
blassin has quit [Client Quit]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
ht_ has joined #crystal-lang
duane has joined #crystal-lang
hightower3 has joined #crystal-lang
Creatornator has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 250 seconds]
<raz> hmm. what exactly is unsafe about String#to_slice? and is there a safe way to get the raw bytes from a string?
<FromGitter> <tenebrousedge> like `"abc".bytes` ?
<raz> no, more like "abc".to_slice
<raz> it seems to work as intended. but i wonder if the returned slice could be randomly garbage collected or such. (the docs say it's "unsafe" but not what it means)
<FromGitter> <tenebrousedge> unsafe meaning you're grabbing a pointer and the data associated with it https://github.com/crystal-lang/crystal/blob/0e2e1d067af09e7b1e4573a7258c433e3cf8fa17/src/string.cr#L4297
<FromGitter> <tenebrousedge> it's highly likely to not be garbage data
<raz> yup, i'm basically just wondering why it's marked as unsafe. like, in what scenario would it be unsafe?
<raz> (may assumption is that it wouldn't be garbage collected as long as a pointer is around?)
<raz> ahhh i see
<raz> so it's only unsafe if actively do pointer arithmetic with it
<FromGitter> <tenebrousedge> perhaps, or if you manage to grab something that's not a string
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<Yxhuvud> also you may have to handle stuff like multi-byte characters etc by yorself, but you probably don't care if you want it as a slice.
<FromGitter> <tenebrousedge> that, for sure
<raz> gotcha, thx
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us has joined #crystal-lang
<livcd> I cant wait till Crystal works on Windows :X
<FromGitter> <tenebrousedge> why?
<livcd> Because I want to deply on Windows
<FromGitter> <tenebrousedge> you know about this? https://github.com/crystal-lang/crystal/wiki/Porting-to-Windows
<FromGitter> <tenebrousedge> this seems encouraging https://github.com/crystal-lang/crystal/pull/7995
Creatornator has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ht_ has quit [Remote host closed the connection]
Creatornator has joined #crystal-lang
sagax has quit [Remote host closed the connection]
<FromGitter> <tenebrousedge> I'm debating a design decision. I have something like `Book has_many Chapter has_many Page`, where `book` has an `owner_id`. I want owners to only be able to access their own books, chapters, pages. I'm debating whether `Page` needs an `owner_id`, or whether it's acceptable to walk up the tree to find the owner. I'm concerned about the performance implications of the latter strategy
<FromGitter> <christopherzimmerman> How often do you access pages without accessing the book first?
<FromGitter> <tenebrousedge> I'm working on scoping the backend authorization, so it will only be considering the `Page` model
yukai has joined #crystal-lang
<FromGitter> <tenebrousedge> another wrinkle is that `Page` is polymorphic: `Chapter` doesn't necessarily exist
<FromGitter> <christopherzimmerman> If different users can own pages in a single book, you’d need the ID, otherwise I’d keep it at the lowest level that can differ.
<FromGitter> <tenebrousedge> at this point, only one user can own any given element
<FromGitter> <christopherzimmerman> Ever plan on changing that?
<FromGitter> <tenebrousedge> it has crossed my mind that users might want to collaborate, but I don't currently have the dev resources to enable that
<FromGitter> <christopherzimmerman> What type of DB is this stuff stored in? If it’s something like elasticsearch you’re going to have to go flat anyways.
<FromGitter> <tenebrousedge> postgres, and they're likely to only be accessed in-order
<FromGitter> <tenebrousedge> well, on the consumer side anyway. People don't usually read books out of order
ur5us has quit [Ping timeout: 250 seconds]
ur5us has joined #crystal-lang