<FromGitter>
<eliasjpr> “True, linux is monolithic, and I agree that microkernels are nicer. With a less argumentative subject, I’d probably have agreed with most of what you said. From a theoretical (and aesthetical) standpoint linux looses. If the GNU kernel had been ready last spring, I’d not have bothered to even start my project: the fact is that it wasn’t and still isn’t. Linux wins heavily on points of being
<FromGitter>
... available now.” ⏎ ⏎ — Linus Torvalds, in a 1992 post on the Usenet group comp.os.minix, responding to a post by MINIX author Andrew S. Tanenbaum that claimed that Linux was already obsolete, in part because it used a more traditional monolithic kernel, in which most basic parts of the operating system are managed within the kernel itself, ... [https://gitter.im/cryst
<FromGitter>
<eliasjpr> I find this interesting and wanted to share with the crystal community
jemc has quit [Ping timeout: 268 seconds]
<FromGitter>
<whitenoiseoss> that is interesting, I did not know all of that.
<FromGitter>
<whitenoiseoss> I used to work at Linux Foundation as a Linux Engineer. My team met Linus!
<FromGitter>
<whitenoiseoss> I knew he basically made Linux in a hurry to make something "available now"
<FromGitter>
<whitenoiseoss> but didn't know about the kernel debate
<FromGitter>
<whitenoiseoss> i have to run off and cook dinner for the wife and such, but when i get back
<FromGitter>
<whitenoiseoss> i plan on starting a very informative discussion around immutable vs mutable data types and when you use them or if at some point you're doing safety tradeoffs for speed and how Crystal interacts with this space.
<FromGitter>
<whitenoiseoss> mostly for my own education, as I am not an expert on such and I bet there are some in here.
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter>
<whitenoiseoss> you mean like a shared library?
<FromGitter>
<whitenoiseoss> .so and all that
<FromGitter>
<whitenoiseoss> yeah, Crystal doesn't do that.
f1refly has quit [Ping timeout: 264 seconds]
f1refly has joined #crystal-lang
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Quit: Leaving...]
okami has left #crystal-lang [#crystal-lang]
_whitelogger has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #crystal-lang
<FromGitter>
<r00ster91> is it possible to trap IOT with signal 6? I have `Signal::IOT.trap { puts "IOT" }` on the top of my program but I never get the output "IOT". I only get `Program received and didn't handle signal IOT (6)` when I get the signal
<FromGitter>
<r00ster91> is someone able to trap it?
azuri5 has joined #crystal-lang
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 255 seconds]
flaviodesousa has joined #crystal-lang
_whitelogger has joined #crystal-lang
laaron has quit [Read error: Connection reset by peer]
laaron has joined #crystal-lang
ternarysolo has joined #crystal-lang
ternarysolo has quit [Ping timeout: 245 seconds]
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
marmotini_ has joined #crystal-lang
azuri5 has quit [Quit: azuri5]
azuri5 has joined #crystal-lang
lucasb has joined #crystal-lang
_whitelogger has joined #crystal-lang
marmotini_ has quit [Remote host closed the connection]
_whitelogger has joined #crystal-lang
cyberarm has quit [Ping timeout: 250 seconds]
cyberarm has joined #crystal-lang
Gasher has joined #crystal-lang
<Gasher>
hi, do you have any examples of this method? I'm not sure how to use it
<FromGitter>
<Blacksmoke16> id vote its used for the DB.mapping macro
<FromGitter>
<dscottboggs_gitlab> You're supposed to use the overload for the type expected. so if the column you're trying to read is a text type then you would use `rs.read String`, if it's an Integer type, you'd use `rs.read Int32`, etc
<Gasher>
yeah
azuri5 has quit [Quit: azuri5]
<Gasher>
but there is another one for types
<Gasher>
underneath
<FromGitter>
<dscottboggs_gitlab> oh, the last one, with the `*`?
<Gasher>
there is def read(type : T.class) : T forall T
<wakatara>
I'm new to Crystal (from Ruby) after reading the Crystal lang book but am having trouble bending types to my will. I tryingt to read a yaml file (an array of hashes) and then force it into either an array of Hashes or a struct of the form string:int64 but failing miserbly. I would have thought a simple thing << yaml.parse(path) would have sufficed but keep getitng told the overload operator doesn't work that way. I'm assuming this is
<wakatara>
a typesafe thing, but is there a good way to do this? (that doesn't involve me setting the property value on each element?).
<FromGitter>
<Blacksmoke16> got a playground link?
<wakatara>
Blacksmoke16: I have been looking at that, but it unfortuantely does not seem to be supporting my use case (using yaml as a config file where each of the keys are their own unique property. The yaml file is used as a config file for an array of habits with a defined period - As an exercise i'm reimplmenting habitctl in crystal.)
<FromGitter>
<dscottboggs_gitlab> OH I know what you're trying to do
<FromGitter>
<dscottboggs_gitlab> You have a set of unique keys mapped in yaml to a set of predefined-structure objects, no??
<FromGitter>
<Blacksmoke16> prob could use the `read_file` macro
<FromGitter>
<dscottboggs_gitlab> So you would need to define a YAML::Serializable struct/class then you want to try `Hash(String, MySerializable).from_yaml(contents)`
<wakatara>
The yaml just seemed to be an easy way to make the config file, but if I have to write something tricky, I could use a straight up text file to split the hash and just feed them into the array.
<FromGitter>
<Blacksmoke16> yea so you're running into a type error obs
<wakatara>
Out of curiosity though, even with a straight Array of {String => Int64} though, why does the << overload operator not work to push the maps into the array?
<FromGitter>
<Blacksmoke16> your array has a type of `Array(Hash(String.class, Int64.class))` when you're trying to push `YAML::Any` into it
<FromGitter>
<Blacksmoke16> i.e. you would have to push a Hash of `String.class => Int64.class` to it
<FromGitter>
<Blacksmoke16> which i dont think is what you want
<wakatara>
Baclksmoke16: Right, so how do I convert the YAML::Any to that Hash format to pour it ito the waiting array? (and sorry if this sis a stupid question)
<wakatara>
Ah, gotcha! Thnak you! (I"m assuming there is no eay to serialize without naming the properties in the yaml directly then though, correct? My original idea had been to simply have a file like habits: with a - eat daily: 1 type thing on it.
<wakatara>
Seriously though, this is super helpful> I can move forward with the other logic and come back to the file load issue later.
<FromGitter>
<dscottboggs_gitlab> That would just be a `Hash(String, Array(Hash(String, Int32)))` -- if it's so predictable
<FromGitter>
<dscottboggs_gitlab> also making a property nullable (I.E. the type ends in `?`) means you can leave it out...
<wakatara>
Very helpful. Thank you... I will play around with it some more, get the basic working and swing back to it. thank you!!!
<FromGitter>
<dscottboggs_gitlab> yeah heredocs are nice
azuri5 has quit [Quit: azuri5]
<FromGitter>
<whitenoiseoss> does anyone have an example of sanitizing to_json? Let's say you have an "Account" class that has things like password, UUID, or other data that you don't want to export in the JSON object. How do you tell it not to dump certain things?
<FromGitter>
<whitenoiseoss> sort of like the `json: "-"` in Go
<FromGitter>
<Blacksmoke16> do you care that that field wouldnt get read on `from_json`?
<FromGitter>
<whitenoiseoss> hm. I don't have anything specific in mind, so let's say no on this one.
<FromGitter>
<whitenoiseoss> I think in most cases (like a password hash) you would receive the password from some sort of input, you wouldn't just blindly make a User object from the JSON
<FromGitter>
<whitenoiseoss> so yeah, that should be fine
<FromGitter>
<Blacksmoke16> are you using `JSON::Serializeable`?
<FromGitter>
<whitenoiseoss> no, I was just playing with JSON.mapping
<FromGitter>
<Blacksmoke16> then just do `ignore: true`
<FromGitter>
<Blacksmoke16> that should work
<FromGitter>
<whitenoiseoss> oh look!
<FromGitter>
<whitenoiseoss> JSON::Serializeable does exactly what I want
<FromGitter>
<Blacksmoke16> yea, then could just add `@[JSON::Field(ignore: true)]`
<FromGitter>
<whitenoiseoss> yeah, nice, cool
<FromGitter>
<whitenoiseoss> I was only seeing JSON.mapping( <all fields> )
<FromGitter>
<whitenoiseoss> and was like "hmm...this is lacking a lot of options"
<wakatara>
When you have an array of structs, you cannot simply append to them in a form like array[2] = Struct.new(this, that)?
<FromGitter>
<j8r> why array of a given struct would differ with an array of a given class?
<wakatara>
I am confused as to why I'm seeing the error : undefined method '[]=' for Array(Harsh::Habit).class
<FromGitter>
<j8r> do you forgot the `.new`?
<wakatara>
effectively I have habits = Array(Habit), but habuts doesn't seem to like the << or the []= being used for it if it was simply a standard type
<wakatara>
habits[line] = Habit.new(name = habit[0], every = habit[1].to_i)
<wakatara>
in a block
<FromGitter>
<maiha> `habits = Array(Habit).new`
lucasb has joined #crystal-lang
<wakatara>
Doh. It is obviously time to call it a night. Thank you maiha:
<wakatara>
works fine now.
<FromGitter>
<j8r> @vivus-ignis hum. usually you have `src/mymodule.cr` that has `require "./mymodule/*"`
<FromGitter>
<vivus-ignis> i wanted it to be bit more explicit
<FromGitter>
<j8r> but what the point of `src/lib_tar/lib_tar`? Isn't redundant?
<FromGitter>
<j8r> you can have `src/lib_tar/types.cr`, `src/lib_tar/header.cr`
<FromGitter>
<arnavb> This issue came up for me when I was doing crystal spec with contains. Is there an equivalent for `has_key?`? Not sure why `includes?` doesn't have the same behavior...
lvmbdv has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> ok.. so `#includes?` is inherited from `Enumerable`... so to use `includes?` (and hence `should contain`) you have to do it like this... https://carc.in/#/r/6egi
<FromGitter>
<dscottboggs_gitlab> so it looks for the pair, not either the key nor the value
lvmbdv has quit [Remote host closed the connection]
<FromGitter>
<j8r> @arnavb as @dscottboggs_gitlab shows, an hash element is both a key and a value.
<FromGitter>
<j8r> Maybe we might have in the future `Hash#includes?(element : Tuple(K, V))`
lvmbdv has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> just to document it?
<FromGitter>
<j8r> Note there is also `#has_value?` as well
<FromGitter>
<arnavb> Gotcha. I feel like the docs should have been clearer about this.
<FromGitter>
<dscottboggs_gitlab> I agree they definitely could be
<FromGitter>
<j8r> It's not really documented
<FromGitter>
<j8r> For hash
<FromGitter>
<Sija> @arnavb usually you want to check for the either, key or the value, to check both at once you can do `hash[key]? == value`
<FromGitter>
<Sija> noone rly uses `Hash#includes?` I guess that's why it's not documented
<FromGitter>
<dscottboggs_gitlab> I think the confusion arose more from the `contain` spec macro
<FromGitter>
<arnavb> ^
<FromGitter>
<Sija> just because it's `Enumerable` it doesn't mean all its methods are in perfect sync with the class implementing it (although they should work - and they do)
<FromGitter>
<Sija> and it *is* documented quite clearly - `Enumerable({K, V})`
<FromGitter>
<dscottboggs_gitlab> I'm not sure I would agree that that's super clear, it's kinda hard to find if you're new to the language.
<FromGitter>
<Sija> once you know the language it is, but for the newcomers might be pretty cryptic indeed
<FromGitter>
<dscottboggs_gitlab> I think it would be cool if there were a way to do like `.should contain key: "some key"` or `.should contain value: "some value"`
<FromGitter>
<Sija> 👍
<FromGitter>
<Sija> agreed, was looking for that too some time ago, ended up doing `hash[key].should eq(value)`
<FromGitter>
<Sija> 2 hrs of horse riding (after some considerable break) made me walking like a drunk sailor who just came off the ship :D signing off to lay my corpse onto some soft, cushy riprap, have a gnight guys!
<FromGitter>
<dscottboggs_gitlab> good night @Sija
<FromGitter>
<Sija> @dscottboggs_gitlab I'd rather use `contain({ "key" => "value" })` notation
<FromGitter>
<dscottboggs_gitlab> you could still do that in my recommended change
<FromGitter>
<dscottboggs_gitlab> it would still act the same unless you specified the `key` or `value` parameters
<FromGitter>
<Sija> IMHO it doesn't make much sense to check for the key or value alone since this can be already easily achieved by using `hash.has_key?` and `hash.has_value?`
<FromGitter>
<Sija> without a need for refactoring
<FromGitter>
<Sija> the only case which is not cover is checking for both at once and usually for more than one KV pair
<FromGitter>
<dscottboggs_gitlab> yeah but in specs that would be `hash.has_key?("some key").should be_true` which is nowhere near as nice
<FromGitter>
<Sija> nice is… subjective ;) for me it's pretty readable and clear
<FromGitter>
<dscottboggs_gitlab> fair enough.
<FromGitter>
<Sija> that's what this methods are for in the end...
<FromGitter>
<Sija> for single KV pair you can do `hash[key]?.should eq(value)`
<FromGitter>
<Sija> it's enough
<FromGitter>
<dscottboggs_gitlab> just thought I'd raise the suggestion, I'm pretty sure that's not something the core devs would be a fan of.
<FromGitter>
<dscottboggs_gitlab> I agree about checking for a pair.
<FromGitter>
<Sija> only case which is troublesome would be checking for a subset like `contains({ "key1" => "value1", "key2" => "value2" })`
<FromGitter>
<dscottboggs_gitlab> but if you want to check for a key I think `contain key:` would be nicer
<FromGitter>
<dscottboggs_gitlab> yeah I wonder if that would work...
<FromGitter>
<Sija> IMO that's overcomplicating it
<FromGitter>
<Sija> I wouldn't be sure what's *key* in this case