Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:23
    caspiano edited #10531
  • Dec 08 23:04
    HertzDevil edited #12623
  • Dec 08 22:57
    Blacksmoke16 edited #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil opened #12828
  • Dec 08 22:34
    straight-shoota edited #12827
  • Dec 08 22:32
    straight-shoota edited #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota opened #12827
  • Dec 08 22:15
    straight-shoota closed #12814
  • Dec 08 17:12
    straight-shoota assigned #12814
  • Dec 08 17:12
    straight-shoota assigned #12813
  • Dec 08 17:12
    straight-shoota assigned #12809
  • Dec 08 17:12
    straight-shoota assigned #12802
  • Dec 08 17:12
    straight-shoota assigned #12797
  • Dec 08 17:12
    straight-shoota assigned #12664
George Dietrich
@Blacksmoke16
kinda yea, works quite well as the lib itself is decoupled from the CLI context
From IRC (bridge bot)
@FromIRC
<mfiano> That project seems to be structured well and very easy to read
<mfiano> (and nicely documented)
George Dietrich
@Blacksmoke16
i try :smiley:
From IRC (bridge bot)
@FromIRC
<mfiano> at least as a first real project I've seen
Jason Waldrip
@jwaldrip
Getting some weird behavior...
class Psykube::Generator::Podable < ::Psykube::Generator
  alias Resource = Pyrite::Api::Apps::V1::Deployment | Pyrite::Api::Batch::V1beta1::CronJob | Pyrite::Api::Batch::V1::Job | Pyrite::Api::Apps::V1::StatefulSet | Pyrite::Api::Apps::V1::DaemonSet | Pyrite::Api::Core::V1::Pod

  protected def result : Resource
    case manifest.type
    when "Deployment"
      Deployment.result(self)
    when "Cron"
      CronJob.result(self)
    when "Job"
      Job.result(self)
    when "StatefulSet"
      StatefulSet.result(self)
    when "DaemonSet"
      DaemonSet.result(self)
    when "Pod"
      Pod.result(self)
    else
      raise "Invalid type: `#{manifest.type}`"
    end
  end
end
given that... I am getting a strange error
George Dietrich
@Blacksmoke16
manifest.type should be an enum :)
Jason Waldrip
@jwaldrip
❯ shards build && mv bin/psykube `which psykube` --error-trace
Dependencies are satisfied
Building: psykube
Error target psykube failed to compile:
Showing last frame. Use --error-trace for full trace.

In src/cli/commands/concerns/kubectl.cr:139:20

 139 | spec = podable.spec
                      ^---
Error: undefined method 'spec' for Pyrite::Api::Admissionregistration::V1::MutatingWebhookConfiguration (compile-time type is Pyrite::Kubernetes::Object+)
George Dietrich
@Blacksmoke16
got a link to the code?
Jason Waldrip
@jwaldrip
ya, let me push
George Dietrich
@Blacksmoke16
does that spec method exist on all those types in the union?
Jason Waldrip
@jwaldrip
Let me double check
George Dietrich
@Blacksmoke16
it seems the type of that union is being collapsed into their parent Pyrite::Kubernetes::Object+ type which doesn't have that method
https://github.com/crystal-lang/crystal/issues/2661#issuecomment-877286921 is prob similar to what's going on ^ if i had to guess
Jason Waldrip
@jwaldrip
Which is strange... the return type method ensures the proper type is returned
or at least it should
George Dietrich
@Blacksmoke16
but you're doing a .as(Psykube::Generator::Podable::Resource)
where Resource is an alias to a union of other types
Jason Waldrip
@jwaldrip
so really I would have to case over each type in the union to get what I want
George Dietrich
@Blacksmoke16
or make use of overloads for specific types
Jason Waldrip
@jwaldrip
ya, let me see what I can do
Alex Kampa
@alex-kampa
Now here's a bit of a surprise:
puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }
Error: undefined method '+' for Nil (compile-time type is (Int32 | Nil))
George Dietrich
@Blacksmoke16
i think you need some parans
parens*
i think the if is making the type of acc possibly nil, because the return value of the block is used to set the acc
.reduce(0) { |acc, i| i.to_s =~ /3/ ? acc + i : acc }
is 3 the expected value here?
From IRC (bridge bot)
@FromIRC
<mfiano> Can someone ELI5 the ~> version operator?
George Dietrich
@Blacksmoke16
image.png
From IRC (bridge bot)
@FromIRC
<mfiano> I read that
<mfiano> Maybe I'm dumb
George Dietrich
@Blacksmoke16
afaik its the same as the ^ in other langs
From IRC (bridge bot)
@FromIRC
<riza> mfiano: the idea with ~> is that it allows for upgrades within the specified point but no higher
George Dietrich
@Blacksmoke16
just a shortcut to say allow versions within this range
From IRC (bridge bot)
@FromIRC
<riza> so if you ~> x.y.z, you leave room for z to increment but not y
George Dietrich
@Blacksmoke16
^
From IRC (bridge bot)
@FromIRC
<riza> and if you ~> x.y, y can increment, z can be anythnig and x cannot change
<mfiano> Oh very good. I don't see why you would want to leave room for y or x to upgrade...how can you know anything other than a patch won't break your code?
<riza> its used under the assumption that the project you're referencing follow SemVer
Alex Kampa
@alex-kampa

Thanks @Blacksmoke16 your solution works, even though

puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| i.to_s =~ /3/ ? acc + i : acc }

is a bit harder to read than

puts [1, 2, 3, 4, 5].reduce(0) { |acc, i| acc = acc + 1 if i.to_s =~ /3/ }

but ok I guess that's the price to pay for a compiled language ... and shows that the transition from Ruby to Crystal is not always that easy.

From IRC (bridge bot)
@FromIRC
<riza> mfiano: if the project is following SemVer, then you know that anything which is a breaking change is a major version increment
<mfiano> Ok I see
George Dietrich
@Blacksmoke16
@alex-kampa whats the end goal of this code?
i noticed i had acc + i instead of acc + 1, so are all you wanting to do is count the number of time 3 is in the array?
Alex Kampa
@alex-kampa
counting elements in an array that match a certain regex
at this stage just playing around with various ways to achieve that
George Dietrich
@Blacksmoke16
puts [1, 2, 3, 4, 5].count { |i| i.to_s.matches? /3/ }