<crystal-gh>
[crystal] chris-huxtable reopened pull request #5627: Adds System Users and Groups (master...users-groups) https://git.io/vNVfn
wontruefree has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
<woodruffw>
is there an idiomatic way to handle envelopes with `JSON.mapping`? i.e., if i have an API that wraps every response, what's the right way to declare a mapping that only returns the relevant inner data?
<FromGitter>
<Blacksmoke16> i.e. ignore certain fields from `to_json`?
<woodruffw>
well, the problem is that i can't quite ignore them -- the envelope includes a TTL field, which i need to check against for staleness
<FromGitter>
<Blacksmoke16> no i mean still consume the value into the object when using .from_json but ignore the field when outputting the object using .to_json
<FromGitter>
<Blacksmoke16> or do i not follow what you are asking?
<woodruffw>
yeah, i think you're solving a different problem. i'm not emitting any JSON, i just want to strip away some of the layers of this object before handing it to the user
<FromGitter>
<Blacksmoke16> do you have an example?
<woodruffw>
e.g., `object.data.things.first` should just become `object.things.first`
<FromGitter>
<Blacksmoke16> ah
<woodruffw>
i might be explaining myself poorly
<FromGitter>
<Blacksmoke16> and how are you returning it to the user? just like return object.things.first?
<woodruffw>
yup, ideally
<FromGitter>
<Blacksmoke16> could you define a method that news up a new object based on params in main object and returns the other object with what you want to return?
<woodruffw>
yeah, i'm trying something like that now
<woodruffw>
it feels a little unidiomatic, but i guess it'll work
<FromGitter>
<Blacksmoke16> not sure you have a choice since you dont want to return the whole thing
<woodruffw>
mhm
<FromGitter>
<Blacksmoke16> if you returned JSON there is some neat things you could do
<FromGitter>
<Blacksmoke16> but would be same concept, defining a custom deserialization
<woodruffw>
i'll give this approach a shot and report back ;)
<woodruffw>
maybe it'll end up being cleaner than i think
<wontruefree>
yeah I was hoping to have something more local to my machine
<wontruefree>
there is an html dir you can create
<wontruefree>
but I was hoping there was something not as dependent on the browser
<FromGitter>
<mtn> Hey -- just trying out crystal and I have a few (probably very straightforward) questions
<FromGitter>
<mtn> I have a integer array, Array(Int32), and I want to read a character from stdin, cast it to an integer, and set a value to be it in the array. However, the type of the result of reading from stdin is Char | Nil.
<FromGitter>
<mtn> I thought to put it in a begin/rescue block, and call`.to_i` on `STDIN.raw &.read_char`, but we can't call `.to_i` on nil of course, so that fails at compile time
<FromGitter>
<mtn> What's the straightforward way to do what I'm attempting
<FromGitter>
<mtn> I also see that `not_nil` is a thing -- not sure if that's appropriate
<FromGitter>
<mtn> (fwiw, I used `not_nil` and compiled my first program -- a brainfuck interpreter!) but definitely interested in potentially better ways of doing things
moei has joined #crystal-lang
akaiiro has joined #crystal-lang
<FromGitter>
<Timbus> You can use `.is_a` and/or `.nil?` on a variable to ensure a type is not nil.
<FromGitter>
<Timbus> You can also use `.try` in a lot of scenarios where you're okay with the final result still being potentially nil, eg: `result = STDIN.raw &.read_char.try &.to_i` (`result` is now an `Int | Nil`)
snsei has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
<FromGitter>
<Timbus> ah.. and of course there's just the classic `if result`. Only `false` or `nil` will fail that check. hope that helps @mtn
early has quit [Quit: Leaving]
early has joined #crystal-lang
wontruefree has quit [Quit: bye]
khubo has joined #crystal-lang
<FromGitter>
<mjago> wontruefree: run crystal docs in a local crystal source directory and you have local crystal api docs (localhost)
<FromGitter>
<mjago> ah you don't want browser
<FromGitter>
<talbergs> I just saw a talk from 2017february there is said that until 1.0 windows support and paralellism is needed. Same as today. Im curious what sidetracked the team? Or does it really takes so much time, or we miss more coders?
<FromGitter>
<talbergs> If sidetracked, what is gained
<FromGitter>
<mjago> @talbergs a big backer with deep pockets would surely help 😏
mindcrimes has joined #crystal-lang
<mindcrimes>
hi, im trying to make a hash with String and Functions
<mindcrimes>
is that possible?
<FromGitter>
<rishavs> Need some advice on implementing dyamic routes in my simple case-when based router. ⏎ ⏎ ``` case path ⏎ when {"/about/", "GET"}``` ⏎ ⏎ Does the case-when support regex or pattern matching? [https://gitter.im/crystal-lang/crystal?at=5b406e2be534eb69a5cf6d9b]
<FromGitter>
<rishavs> > *<mindcrimes>* hi, im trying to make a hash with String and Functions ⏎ ⏎ Isn't that just a class? Maybe classes would be better here
* mindcrimes
shrugs
<mindcrimes>
was trying to think of a way to handle events and thats the first thing that came to mind
<mindcrimes>
idk if classes would work well
<FromGitter>
<mjago> I guess it depends on your usecase. I use that technique in a state-machine with a Hash(Enum, Proc(String)) within a class which works for me
<FromGitter>
<mjago> But there may be better ways 😄
<FromGitter>
<kolyaio> Do you know any library in cr that deals with dates ?
<FromGitter>
<kolyaio> Date format
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 256 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 264 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 256 seconds]
alex`` has joined #crystal-lang
<FromGitter>
<decal> 0plll
<crystal-gh>
[crystal] sdogruyol closed pull request #6347: Error if using `return` inside a constant's value (master...bug/5391-return-from-constant) https://git.io/fNeAi
<FromGitter>
<asterite> woodruffw just define class Wrapper(T), see for example
<woodruffw>
@asterite: that's what i ended up doing :)
<crystal-gh>
[crystal] chris-huxtable opened pull request #6350: Switches Darwin to arc4Random (master...darwin-arc4random) https://git.io/fNv8l
snsei has joined #crystal-lang
alex`` has quit [Ping timeout: 268 seconds]
alex`` has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
olbat has quit [Ping timeout: 264 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]
alex`` has quit [Ping timeout: 260 seconds]
alex`` has joined #crystal-lang
<rocx>
is there anything involving reading formatted input like c's scanf()?
<rocx>
then again, maybe if the data is stricly line-oriented, maybe IO#each_line would be a better idea and check what the first token is.
zachk has joined #crystal-lang
zachk has joined #crystal-lang
<crystal-gh>
[crystal] asterite opened pull request #6351: Revert: Don't automatically virtualize two types in the same hierarchy, unless one is deeper than the other (master...feature/revert-dont-virtualize) https://git.io/fNvEs
<FromGitter>
<fridgerator> though I think those are just header files, I dont see any libs
<FromGitter>
<fridgerator> so nvmd
wontruefree has joined #crystal-lang
duane has joined #crystal-lang
jcs has left #crystal-lang [#crystal-lang]
<wontruefree>
when I try to use HTTP::Client on some urls it fails but I can curl them and they are fine
<wontruefree>
so HTTP::Client.get("https://www.facebook.com") fails with #=> Unhandled exception: Invalid encoding: "utf-8" (ArgumentError)
<wontruefree>
am I doing something wrong?
<FromGitter>
<asterite> it's a bug, the content-type header is `text/html; charset="utf-8"` and crystal chokes on it... I didn't know quotes were allowed there
<wontruefree>
I tried to add accpet with `text/html; charset="utf-8"` but I must of had it wrong
<wontruefree>
oh interesting
<FromGitter>
<asterite> You can maybe patch your program with that change, in the meantime... or patch `IO#set_encoding` to remove the quotes :-P
<wontruefree>
I might just have crystal build from HEAD
<wontruefree>
have not figured it out yet
<livcd>
Are crystal apps behaving correctly in docker containers ? I remember there was an issue with a huge performance hit for crystal binaries
<wontruefree>
but crystal HEAD seems to be fixing things I run into anyways
<wontruefree>
what behavior are you seeing ?
<wontruefree>
I have some apps I have given to people in docker containers and have not hear anything about them
<wontruefree>
but I dont know if they are really using them
<livcd>
I remember reading about crystal apps being very slow in docker
<crystal-gh>
[crystal] asterite opened pull request #6355: Encoding: compare with case insensitive UTF-8 to avoid using iconv when not necessary (master...feature/dont-use-iconv-for-case-insensitive-utf8) https://git.io/fNv2P
<wontruefree>
I mean maybe it was the docker config
<FromGitter>
<Timbus> livcd: I have a half dozen or so crystal services running in kubernetes and none of them seem to have any performance issues regarding docker, to my knowledge.
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
<FromGitter>
<Timbus> I also can't see how crystal would run slower compared to any other language in a container.. Only issue I had was crystal handles signals strangely as the PID1 process, so now I use dumb-init to start the crystal apps
<crystal-gh>
[crystal] RX14 closed pull request #6346: Fix: incorrect debug info for closured self (master...bug/6195-incorrect-debug-info) https://git.io/fNeAv