Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:09
    straight-shoota closed #11747
  • 01:09
    straight-shoota closed #11745
  • Jan 17 19:16
    straight-shoota synchronize #11716
  • Jan 17 19:11
    straight-shoota synchronize #11715
  • Jan 17 18:34
    straight-shoota milestoned #11747
  • Jan 17 14:31
    straight-shoota synchronize #10416
  • Jan 17 14:27
    straight-shoota synchronize #11715
  • Jan 17 14:04
    straight-shoota milestoned #11750
  • Jan 17 13:57
    straight-shoota labeled #11750
  • Jan 17 13:57
    straight-shoota labeled #11750
  • Jan 17 12:53
    mamantoha edited #11750
  • Jan 17 12:52
    mamantoha edited #11750
  • Jan 17 12:51
    mamantoha synchronize #11750
  • Jan 17 11:26
    mamantoha synchronize #11750
  • Jan 17 11:01
    mamantoha synchronize #11750
  • Jan 17 10:54
    mamantoha synchronize #11750
  • Jan 17 10:48
    mamantoha edited #11750
  • Jan 17 10:48
    mamantoha edited #11750
  • Jan 17 10:48
    mamantoha opened #11750
  • Jan 16 23:10
    skurhse closed #11739
mfiano
@mjfiano:matrix.org
[m]
Do you mean defining an annotation?
George Dietrich
@Blacksmoke16
more like something like
struct FloatWrapper
  @value : Float64

  forward_missing_to @value

  def initialize(@value : Float64); end

  def special_method
  end
end
mfiano
@mjfiano:matrix.org
[m]
Hmm, I don't really understand how that is delegating, but I'll study that code some. Thanks
mfiano
@mjfiano:matrix.org
[m]
Yeah that was my first stop. Just trying to figure out how this is different than inheritance. The docstring/example could be better imo
Taupiqueur
@alexherbo2
@Blacksmoke16 what is the % in the macro?
George Dietrich
@Blacksmoke16
hm?
Taupiqueur
@alexherbo2
%v1
Taupiqueur
@alexherbo2
it looks to work without the %
Rishav Sharan
@rishavs
How would one go about converting a hex string to normal string?
George Dietrich
@Blacksmoke16
what do you mean by "normal string"?
a hex string is just a string of hex characters
Taupiqueur
@alexherbo2
so I should replace my value with %value to avoid side effects?
George Dietrich
@Blacksmoke16
@alexherbo2 idt it would matter
that's not what fresh vars are for
Rishav Sharan
@rishavs
I am trying to convert a hexstring to base64. I am assuming that i need to first convert the hex to slice and then to base64
George Dietrich
@Blacksmoke16
hexstring.hexbytes
Rishav Sharan
@rishavs
Thanks :heart:
mfiano
@mjfiano:matrix.org
[m]
Is there a shorthand form for when you have the same type restriction for adjacent parameters, to make something like (a : Float64, b : Float64, c : Float64, d : Float64) more concise?
oprypin
@oprypin:matrix.org
[m]
mfiano: no
mfiano
@mjfiano:matrix.org
[m]
Ok, thanks
mfiano
@mjfiano:matrix.org
[m]
# src/origin/common.cr

require "math"

module Origin
  def foo(x, y, rel_tol, abs_tol)
    (x - y).abs <= Math.max(abs_tol, rel_tol * Math.max(x.abs, y.abs))
  end
end
# src/origin.cr

require "./origin/*"

Origin.foo 1.2, 3.4, 1e-7, 1e-7 # Error: undefined method 'foo' for Origin:Module
Can someone tell me what I am doing wrong here?
oprypin
@oprypin:matrix.org
[m]
mfiano: u defined an instance method but there's no instance involved
class A
include Origin
end

A.new.foo
but you probably want to just define a class/module method by writing def self.foo
mfiano
@mjfiano:matrix.org
[m]
Oh I see.
Yes, I think I just want self.foo here
Rishav Sharan
@rishavs

How should I go about converting this weird string into a normal one?

pub_key_cert = pub_key_certs[jwt_header["kid"]] # => "-----BEGIN CERTIFICATE-----\n" +
"MIIDJjCCAg6gAwIBAgIIPLhThxCpHiEwDQYJKoZIhvcNAQEFBQAwNjE0MDIGA1UE\n" +
"AxMrZmVkZXJhdGVkLXNpZ25vbi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTAe\n" +
"Fw0yMTA3MTQwNDMwMDBaFw0yMTA3MzAxNjQ1MDBaMDYxNDAyBgNVBAMTK2ZlZGVy\n" +
"YXRlZC1zaWdub24uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wggEiMA0GCSqG\n" +
"SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCdA8H9aoYbXymMZIUZDBEtxmRxGiMcfB43\n" +
"buZXWhM154faq6rk29aJssSF6K6RU/rSddwY2mQ/89rJxhqER+8CckYtf8ixwYA4\n" +
"nrtZYWzgzzBccfqDaZOdqVwBiCak3VAMxWDPg1xYhJc1NH7wVl9aAU3gsNmArh/T\n" +
"Bc5omWH8HOH6mU8slBRfJjuZlMRWwfxffCDZ+9XQfGP8e52OAWVg90OuLU6Li8jT\n" +
"CIpXickJFn4g0fc4i8+X7TlZWNn5dNJd02Ms3Hfk0zY2lyuv1Wlnxd6DumvTCNqa\n" +
"p3/TvF8QB20XGw3oDLoRzPeTSidA/7pItEIYuswDGJ/OKK+aZp8JAgMBAAGjODA2\n" +
"MAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMBYGA1UdJQEB/wQMMAoGCCsG\n" +
"AQUFBwMCMA0GCSqGSIb3DQEBBQUAA4IBAQCaCB/WTMa79FgyczlwRtWYCH2GWJC7\n" +
"vIunI2dh3yZbzT1NBiDHx2Epp+nyz0sx1cN5s1HEsXFFTVtLa6vFl1p+O6SR/Hck\n" +
"Uj2waSiEmSXEJupzqKYXzyqgU+SE0TaaNAU9VvrSLI0HlMcSY2OReLcBgpvs8C7j\n" +
"zXyBmmlrMlUokvYE5h4Rui6JH9MahtcWARXkIPH5JwXVeXKPPie30NlqmifFPFTQ\n" +
"D3CCTbzYfk8kS4jgM5+DkYCJse3iDh4Wtfm4RuZKZ6IzgqgQr+JFkCatJcSlpgwC\n" +
"iPWtLgKNsmGDiU9Pj7KXRV5rXVygX3/Eb5m5Rug+UhXd1c3QlIlW1EF6\n" +
"-----END CERTIFICATE-----\n"

Do i need to reencode it somehow?

From IRC (bridge bot)
@FromIRC
<raz> hmm, is there a way to make from_json (JSON::Serializable) invoke my setters when populating the object
Ali Naqvi
@naqvis
converter is what you are looking for
@[JSON::Field(key: "foo", converter: FooConverter)]
.......
oops, that was not your question :)
From IRC (bridge bot)
@FromIRC
<raz> hmm right, but close :⁠)
<raz> i guess what i'm really trying to ask: is there a way to add something to the constructors that JSON::Serializable generates (short of making a custom converter for every field 🙈)
<raz> i have this really nice and rather relevant logic in my settings, but serializable doesn't care to invoke them when populating the object from json :,(
<raz> s/settings/setters/
Ali Naqvi
@naqvis
macro populate the fields, it would have been better if it would have invoked setters (if any) and fall-back to current behavior
in that way, one could just define the setters for fields which require some extra processing
for the time-being what you can do is override after_initialize and invoke your setters there, this method is invoked after macro is done with populating the fields
Ali Naqvi
@naqvis
From IRC (bridge bot)
@FromIRC
<raz> ohhh, after_initialize is a thing? that might just save my bacon here
From IRC (bridge bot)
@FromIRC
<raz> it did, thx! \o/
Ali Naqvi
@naqvis
:)
From IRC (bridge bot)
@FromIRC
<raz> is that a JSON::Serializable specific thing? i can't find anything about it on google nor api docs
George Dietrich
@Blacksmoke16
it is yea
From IRC (bridge bot)
@FromIRC
<raz> gotcha