<FromGitter>
<parruda> Hey guys, is it possible to use JSON.mapping and leave one of the keys unparsed? For example: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ This will throw an error when trying to parse the json string: `Unhandled exception: Expected string but was begin_object` [https://gitter.im/crystal-lang/crystal?at=5c9ebf496a9761361b254ffd]
<FromGitter>
<Blacksmoke16> would have to use a converter to tell it you want that as a string
<FromGitter>
<Blacksmoke16> sec
<FromGitter>
<parruda> would String::RawConverter work?
<FromGitter>
<Blacksmoke16> :0
<FromGitter>
<Blacksmoke16> TIL thats a thint
<FromGitter>
<Blacksmoke16> but yea thats what you would want
<boughtly>
is it possible to define a macro which allows variable shadowing in a block (or even do this without a macro)
<boughtly>
block scoping and no explicit variable definition syntax seems to make shadowing impossible
_whitelogger has joined #crystal-lang
<FromGitter>
<ryanstout> is there a way to ```Fiber.yield``` and pass it a file descriptor to have the scheduler ```select``` on? (or the epoll/kqueue equivalent) Using libusb and want to do something when the usb device responds.
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
boughtly has quit [Ping timeout: 256 seconds]
_whitelogger has joined #crystal-lang
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter>
<TheOnlyArtz> And it's working incredibly good :)
<FromGitter>
<Blacksmoke16> nice one
<FromGitter>
<TheOnlyArtz> The reason I've wrote a "custom" logger class is because I don't want to have an instance of Logger hopping around in my code, it's just a big mess
<FromGitter>
<Blacksmoke16> most people just do like `LOGGER = Logger.new STDOUT, Logger::Debug`
<FromGitter>
<Blacksmoke16> then just do `LOGGER.warn xxx`
<FromGitter>
<Blacksmoke16> or make it a class property on a like `Config` class
<FromGitter>
<Blacksmoke16> then can do `MyApp.settings.logger = xxx`
<FromGitter>
<TheOnlyArtz> I thought about it but it's just unnecessary
<FromGitter>
<Blacksmoke16> fair enough
<FromGitter>
<TheOnlyArtz> Btw, is it true that compiling with `--release` will cause better performance?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<TheOnlyArtz> I do see that the file's size gets 20% less in size
<FromGitter>
<TheOnlyArtz> So when I will have a production ready app I will call `--release --no-debug` for max performance
<FromGitter>
<TheOnlyArtz> Tbh it's a gameserver
<FromGitter>
<TheOnlyArtz> Performance matter
<FromGitter>
<Blacksmoke16> well `--no-debug` is arguable. If size of the binary isnt super impt then prob better to include debug info so it would be easier to debug if something happens
<FromGitter>
<TheOnlyArtz> debug in what means? like, debug flags are being written in compile time?
<FromGitter>
<Blacksmoke16> im not super sure tbh, but id prob be like things that allow backtraces to work, vs getting a bunch of `?`. Someone else can prob fact check me :p
<FromGitter>
<TheOnlyArtz> I need some help writing test units
<FromGitter>
<Blacksmoke16> well im just saying its going to be harder to test, is there a way to create an IO to read from STDOUT to read the output from puts?
<FromGitter>
<TheOnlyArtz> Guessing you are not asking me so I will just wait for someone knows the answer to that
DmitryBochkarev has quit [Ping timeout: 250 seconds]
<FromGitter>
<Blacksmoke16> yea im not super familiar with IO stuff
<FromGitter>
<kingsleyh> If anyone knows about OpenSSL I could use a hand implementing ecies for SushiChain Blockchain - another pair of eyes would be helpful to spot any stupid mistakes also
lucasb has joined #crystal-lang
<FromGitter>
<Sija> Anyone here familiar with ndb?
<FromGitter>
<j8r> @TheOnlyArtz don't use puts, always have a way to define the IO
<FromGitter>
<j8r> for loggers
<FromGitter>
<j8r> it can be as simple as having `class_property output : IO = STDOUT, error : IO = STDERR`
<FromGitter>
<TheOnlyArtz> Alright I will look into it
<FromGitter>
<TheOnlyArtz> I have sent a Crystal compiled executable through Discord, then downloaded it on my Linux subsystem on Windows and didn't manage to run it
<FromGitter>
<TheOnlyArtz> But then I've `git pull`ed the code I've committed, built the app again and this time it did run
<FromGitter>
<TheOnlyArtz> That's an old version of the project but at least I know it works now
<FromGitter>
<TheOnlyArtz> A couple of days ago I ask about Crystal and embedded device, what functionalities Crystal can have on embedded devices?
<FromGitter>
<r00ster91> you could host something on a raspberry pi with Crystal
<FromGitter>
<TheOnlyArtz> I mean.. Raspberry pi is just another Linux machine in the size of a palm, isn't it?
<FromGitter>
<r00ster91> yes
<FromGitter>
<parruda> Heys guys, if I wanted to manipulate process capabilities (CAP_EFFECTIVE, CAP_INHERITABLE, etc), how would you recommend me to go about it? I've looked through the docs and couldn’t find anything, so I am guessing I have to import functions from `sys/capability.h`?
<FromGitter>
<TheOnlyArtz> Do you have another embedded device for an example (Except of Arduino)
<FromGitter>
<TheOnlyArtz> You can always link it if you want @parruda
<FromGitter>
<parruda> Not very experienced with C programming here =/ ⏎ can you recommend something I could read? ⏎ ⏎ I’ve used `lib LibC` and `fun` to be able to use `setuid`. But to use something like `cap_set_flag`, it expects some types (like `cap_t`) and I have no idea how to create them [https://gitter.im/crystal-lang/crystal?at=5c9fba7f8148e555b21ef181]
<FromGitter>
<ryanstout> ok, simple question I'm having trouble finding the answer to. What's the best way to get a slice to a struct? (doing some c bindings)
<FromGitter>
<ryanstout> anything better than ```Slice.new(my_struct.to_unsafe, sizeof(my_struct))```
ua has joined #crystal-lang
<FromGitter>
<TheOnlyArtz> @parruda I'm super glad to see!
<FromGitter>
<parruda> I think I got it working but the process ID doesn’t seem right
<FromGitter>
<TheOnlyArtz> It looks like `cap_t` exists just for the sake of being a type, it doesn't hold any values
<FromGitter>
<TheOnlyArtz> @ryanstout Can you be a little bit more descriptive than that?
<FromGitter>
<TheOnlyArtz> Oh
<FromGitter>
<TheOnlyArtz> Sorry Paulo didn't see the source you've put above
<FromGitter>
<TheOnlyArtz> A union is a special data type available in C that allows to store different data types in the same memory location.
<FromGitter>
<ryanstout> sure, thanks for the help. I'm working with a C library wrapper (libusb) that takes a Slice for a few places where the C function takes a pointer and size. I'm wanting to get a slice to a crystal struct (the struct that the C function takes) I'm assuming the memory layout on crystal structs mirrors what you would get in C.
<FromGitter>
<ryanstout> I ended up doing this: ```req_slice = Bytes.new(pointer: pointerof(req).as(Pointer(UInt8)), size: sizeof(PTPOperationRequest))```
<FromGitter>
<TheOnlyArtz> Union types in Crystal for example: `Int32 | String`
<FromGitter>
<ryanstout> where ```req``` is an instance of my PTPOperationRequest struct
<FromGitter>
<TheOnlyArtz> I can't manage to figure this out too, interesting.
<FromGitter>
<TheOnlyArtz> I will probably be able to figure this out once I will understand what's that `u` before `[_LINUX_CAPABILITY_U32S_1]`
DTZUZO has joined #crystal-lang
<FromGitter>
<r00ster91> it stands for unsigned 32 bit integer
<FromGitter>
<TheOnlyArtz> Well.. `_LINUX_CAPABILITY_U32S_1` is `1`
<FromGitter>
<TheOnlyArtz> So it's an array with the length of... `1`?
<FromGitter>
<ryanstout> ok, looks like Struct's have two extra bytes when doing sizeof(MyStruct)
<FromGitter>
<ryanstout> so I'm guessing I can't pass a pointer to a crystal struct directly to C?
<FromGitter>
<TheOnlyArtz> I'm returning Pointers and receiving them on Crystal's end
<FromGitter>
<TheOnlyArtz> And doing otherwise look at `bufferToX` functions
<FromGitter>
<TheOnlyArtz> @parruda I will ask about your issue in a dedicated place, it's really hard to figure out what's going on in there
<FromGitter>
<ryanstout> @TheOnlyArtz thanks, checking it out
<FromGitter>
<ryanstout> @TheOnlyArtz is there an example of converting a crystal struct to a pointer or slice and passing that to C? (sorry, maybe I'm missing it) The examples I see are using structs defined on the C side.
<FromGitter>
<ryanstout> @TheOnlyArtz also, thanks for the help. Always fun to be a n00b again
<FromGitter>
<TheOnlyArtz> Why would you want to parse a struct to any of the things you've pointed out
<FromGitter>
<TheOnlyArtz> How about passing the struct directly?
<FromGitter>
<TheOnlyArtz> Wouldn't it be easier and way more efficient?
<FromGitter>
<ryanstout> the C library wrapper takes a ```buffer : UInt8*, length : Int``` (int is ```LibC::Int```)
<FromGitter>
<ryanstout> so I am trying to pass my crystal struct to it, but sizeof(MyStruct) adds 2 bytes
<FromGitter>
<ryanstout> so crystal is adding 2 bytes
<FromGitter>
<TheOnlyArtz> Maybe the struct weighs a bit
<FromGitter>
<ryanstout> maybe aligning the first UInt16 to a word boundry
<FromGitter>
<ryanstout> yea
<FromGitter>
<ryanstout> that too, maybe some internal crystal data?
<FromGitter>
<TheOnlyArtz> Idk tbh, I don't really know how much memory Crystal allocates for each type
<FromGitter>
<j8r> @TheOnlyArtz what's the purpose of taking a screenshot of carc.in/play.crystal.org? That's the whole purpose of the site 😆
<FromGitter>
<TheOnlyArtz> Yea sorry about that :)
<FromGitter>
<j8r> sending a link to show the code & result
<FromGitter>
<TheOnlyArtz> It looks like a struct takes only 1 byte
<FromGitter>
<ryanstout> ok, yea, setting that first UInt16 to UInt32 keeps it at sizeof == 32. So I'm guessing Crystal (or LLVM) is aligning fields to word boundries.
<FromGitter>
<ryanstout> @TheOnlyArtz where do you see that?
<FromGitter>
<Blacksmoke16> what would you guys rather have, a config file that gets rendered via ECR to set env vars, or be able to set the config file at runtime, which you could just use ENV vars to pass in that path
<FromGitter>
<Blacksmoke16> im thinking the latter would be more helpful...and easier for me to test :P
<FromGitter>
<TheOnlyArtz> Idk, I tend to avoid runtime stuff since it just calls for error
<FromGitter>
<Blacksmoke16> well it would be when you go to start your server, so any errors would be quickly caught and error out
<FromGitter>
<TheOnlyArtz> And another question, how do you use the `property` macro without having a constructor in your struct @ryanstout
<FromGitter>
<ryanstout> I took out the constructor for clarity
<FromGitter>
<TheOnlyArtz> Gotcha
<FromGitter>
<ryanstout> sorry for the confusion
<FromGitter>
<TheOnlyArtz> Can you send the whole struct in playground link?
<FromGitter>
<ryanstout> its all assigned externally right now
<FromGitter>
<ryanstout> actually, sorry, I had a session_id initializer in there also
<FromGitter>
<vladfaust> What is the most efficient (and maybe hacky) way to turn `MessagePack::Any` to `JSON::Any`? Currently doing `JSON.parse(MessagePack.unpack(payload).to_json)`
lucasb has quit [Quit: Connection closed for inactivity]