Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:18
    HertzDevil review_requested #11504
  • Nov 28 23:58
    HertzDevil synchronize #11504
  • Nov 28 16:33
    HertzDevil labeled #11504
  • Nov 28 16:33
    HertzDevil labeled #11504
  • Nov 28 16:33
    HertzDevil labeled #11504
  • Nov 28 16:32
    HertzDevil opened #11504
  • Nov 28 14:42
    oprypin review_requested #11496
  • Nov 28 14:41
    oprypin review_requested #11495
  • Nov 28 14:41
    oprypin synchronize #11395
  • Nov 28 14:28
    HertzDevil synchronize #11503
  • Nov 27 19:45
    mohd-akram synchronize #11439
  • Nov 27 19:14
    straight-shoota synchronize #11499
  • Nov 27 18:48
    mgomes ready_for_review #11482
  • Nov 27 18:20
    HertzDevil labeled #11482
  • Nov 27 18:20
    HertzDevil labeled #11482
  • Nov 27 18:17
    HertzDevil synchronize #11495
  • Nov 27 18:02
    HertzDevil labeled #11503
  • Nov 27 18:02
    HertzDevil labeled #11503
  • Nov 27 18:02
    HertzDevil labeled #11503
  • Nov 27 18:02
    HertzDevil opened #11503
mfiano
@mjfiano:matrix.org
[m]
Thanks
George Dietrich
@Blacksmoke16
:thumbsup:
hightower4: that's quite the macro you got there
From IRC (bridge bot)
@FromIRC
<hightower4> yeah, probably {% debug %} would be the next thing
George Dietrich
@Blacksmoke16
would that help? idt it's even going to run because it doesnt even expland
expand
From IRC (bridge bot)
@FromIRC
<hightower4> Wouldn't it print if it was placed above the place of error?
George Dietrich
@Blacksmoke16
the error is the macro itself so no
mjfiano
@mjfiano:matrix.org
[m]
About the code in the above thread...they seem to overload =~ for the language's Float type. I was hoping to not monkey patch the whole language, if that is what this is doing, and only introduce this overload when used in my specific module.
George Dietrich
@Blacksmoke16
there are no specific scope overloads
other option would be to use a decorator
mfiano
@mjfiano:matrix.org
[m]
Perhaps my concerns are nothing, but I am hesitant to do such a thing, if the library I am writing is to be used with third party code expecting different behavior for =~ of 2 floats.
I don't know how the language behaves in this regard
George Dietrich
@Blacksmoke16
would be better off defining a new method in such case
mfiano
@mjfiano:matrix.org
[m]
Fair enough. Should I subclass the builtin float type and use that everywhere in my domain, or is there a more idiomatic approach?
George Dietrich
@Blacksmoke16
a decorator type is usually the better way to go afaik
mfiano
@mjfiano:matrix.org
[m]
I'll look that up
Thanks
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