ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
jmdaemon has quit [Quit: ZNC 1.8.2 - https://znc.in]
jmdaemon has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
Sankalp has quit [Ping timeout: 264 seconds]
Sankalp has joined #crystal-lang
straight-shoota has quit [Ping timeout: 256 seconds]
straight-shoota has joined #crystal-lang
dmgk has quit [Quit: ZNC - https://znc.in]
dmgk has joined #crystal-lang
dmgk has quit [Remote host closed the connection]
dmgk has joined #crystal-lang
dmgk has quit [Remote host closed the connection]
dmgk has joined #crystal-lang
_ht has joined #crystal-lang
jmdaemon has quit [Ping timeout: 264 seconds]
hightower2 has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
hightower2 has joined #crystal-lang
hightower2 has quit [Read error: Connection reset by peer]
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Remote host closed the connection]
<FromGitter> <djberg96> Does something like this already exist in core?
<FromGitter> <naqvis> don't believe stdlib have one
<FromGitter> <djberg96> ok, thanks
<FromGitter> <djberg96> and if there's a nicer way to do what I'm doing there, I'm all ears
<FromGitter> <naqvis> all good, few suggestions ⏎ ⏎ 1) you can follow stdlib api style for params i.e accept `file` as `Path | String`, accept `encoding` etc params ⏎ 2) you can use `open` with block so you don't have to deal with closing file while you are done with reading [https://gitter.im/crystal-lang/crystal?at=63820ef5f9491f62c9cf700a]
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63820f1d25ca105c88d37310]
<FromGitter> <djberg96> Excellent, thanks!
<FromGitter> <naqvis> 🌹
<FromGitter> <djberg96> Just curious, why Int32 over Number?
_ht has quit [Ping timeout: 260 seconds]
__ht has joined #crystal-lang
<FromGitter> <naqvis> `Int32` is the default type, but sure you can expand param type to more broader type like `Int` or `Number`
<FromGitter> <naqvis> though I doubt `Number` will work, as `Number` includes floating points as well
__ht is now known as _ht
<FromGitter> <naqvis> while `Bytes` size is restricted to `Int`
<FromGitter> <naqvis> so you can restrict `nbytes` to `Int` instead, to allow other integer types
<FromGitter> <naqvis> ```code paste, see link```
<FromGitter> <naqvis> will make it accept any of the signed/unsigned integer types
<FromGitter> <djberg96> fantastic, thank you
taupiqueur has joined #crystal-lang
__ht has joined #crystal-lang
taupiqueur has quit [Quit: WeeChat 3.7.1]
_ht has quit [Ping timeout: 264 seconds]
__ht is now known as _ht
taupiqueur has joined #crystal-lang
hightower2 has joined #crystal-lang
__ht has joined #crystal-lang
_ht has quit [Ping timeout: 260 seconds]
__ht is now known as _ht
__ht has joined #crystal-lang
_ht has quit [Ping timeout: 264 seconds]
__ht is now known as _ht
DeBot has quit [Quit: Crystal IRC]
jhass has quit [Quit: Bye]
straight-shoota has quit [Quit: ZNC 1.8.2 - https://znc.in]
DeBot has joined #crystal-lang
jhass has joined #crystal-lang
straight-shoota has joined #crystal-lang
<FromGitter> <azurelmao> Is it possible to call the initialize method of the inherited class in crystal?
<FromGitter> <azurelmao> like in java you would do super(params)
<FromGitter> <azurelmao> I see
<FromGitter> <Blacksmoke16> so yes, should work just like java
gordea has joined #crystal-lang
gordea has quit [Client Quit]
gordea has joined #crystal-lang
jmdaemon has joined #crystal-lang
ur5us has joined #crystal-lang
renich has joined #crystal-lang
ur5us has quit [Quit: Leaving]
<FromGitter> <djberg96> What's the equivalent of `"\xBA\xB4\u0000\u0000".unpack('i').first` in Crystal?
<FromGitter> <djberg96> I'm poking around the String class, but just not seeing it I guess
<FromGitter> <djberg96> (use case: i'm reading magic numbers out of image files)
<FromGitter> <Blacksmoke16> what kind of image?
<FromGitter> <Blacksmoke16> but it would be something with IO, where you do something like `io.read_bytes(Int32)` or `io.read_bytes Int32, IO::ByteFormat::BigEndian` depending on the type/endianess you want to read
jmiven has quit [Quit: reboot]
jmiven has joined #crystal-lang
_ht has quit [Quit: _ht]
<FromGitter> <djberg96> In this particular case, bitmaps. First 2 bytes should be "BM", next 4 are the file size.
<FromGitter> <djberg96> so i'm just validating that those 4 bytes line up with the actual file size
<FromGitter> <Blacksmoke16> could do something like: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ think that should work [https://gitter.im/crystal-lang/crystal?at=638289d52cb657024046089d]
<FromGitter> <djberg96> Yep, got something like that using the block above from @naqvis, byte slice like `Bytes[66, 77, 186, 180, 0, 0]`. First 2 bytes are "BM", now i just need to conver the last 4 to an number.
<FromGitter> <Blacksmoke16> dont even really need that method, can just open the file and call methods on the io and call it a day
<FromGitter> <Blacksmoke16> just tried it: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63828daa473cf96648038713]
<FromGitter> <djberg96> well, i'm trying to use that method as a general solution, because I'm also reading magic values for other formats, like jpg, png, etc
<FromGitter> <djberg96> so, just for the sake of argument, how would I convert a byte slice like `Bytes[186,180,0,0]` to an int?
<FromGitter> <Blacksmoke16> first way that comes to mind is like `IO::Memory.new(bytes, writeable: false).read_bytes Int32`
<FromGitter> <Blacksmoke16> wait
<FromGitter> <Blacksmoke16> `IO::ByteFormat::LittleEndian.decode Int32, bytes`
<FromGitter> <Blacksmoke16> using the correct endianness of whatever format you're parsng
<FromGitter> <djberg96> that works, thanks!
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <stellarpower> Looks like Complex doesn't have a method to raise it to a power. Am I missing something?
<FromGitter> <stellarpower> Github is getting worse, I sweat. Finally found it anyway
wwalker has quit [Remote host closed the connection]
<FromGitter> <stellarpower> *Github search