jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
Elouin has quit [Read error: Connection reset by peer]
Elouin has joined #crystal-lang
<FromGitter> <mtsmmp_gitlab> guys .dwarf is mandatory on mac?
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> It stores debug info afaik
<FromGitter> <mtsmmp_gitlab> i thought it was generating even with --no-debug, but its not
<FromGitter> <mtsmmp_gitlab> my bad
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 246 seconds]
<FromGitter> <wontruefree> what is the best way to do a method alias ?
<FromGitter> <Blacksmoke16> delegate?
<FromGitter> <wontruefree> I am looking to alias a method in the same class. I think delegate delegates to another class
<FromGitter> <wontruefree> I might be wrong I am looking at the docs though
<FromGitter> <Blacksmoke16> Delegate can point to ivars and such as well
<FromGitter> <wontruefree> true but I am looking for a pure renaming for ease of API
<FromGitter> <wontruefree> I am surprised there is no method alias
<FromGitter> <Blacksmoke16> Crystal is usually against aliases
<FromGitter> <Blacksmoke16> What are the names?
<FromGitter> <wontruefree> search_for -> specifications_for
<FromGitter> <Blacksmoke16> Can you just not alias it?
<FromGitter> <Blacksmoke16> Or really just define the alias method and call the other
<FromGitter> <Blacksmoke16> Don't need to make it more complicated than it needs to be
<FromGitter> <wontruefree> true that is what I am doing now
<FromGitter> <wontruefree> I just thought there might be a more Crystal way to do it. But I guess that is the Crystal way
<FromGitter> <wontruefree> which is cool but also good to know
<FromGitter> <Blacksmoke16> The crystal way is not doing it, hence there not being a way to make it easier
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Ping timeout: 256 seconds]
alexherbo2 has joined #crystal-lang
zorp has joined #crystal-lang
_whitelogger has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo2 has joined #crystal-lang
sorcus has quit [Quit: WeeChat 2.9]
sorcus has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 256 seconds]
<FromGitter> <roduquen> Hi guys, I am a bit loss with OpenSSL ⏎ I have this error and I don't understand how to solve it ⏎ ⏎ ``` .digest(data) ⏎ ⏎ Returns the hash of data.``` [https://gitter.im/crystal-lang/crystal?at=5f58bbd6c3aa024ef9d08f1d]
<FromGitter> <roduquen> (I am creating my own JWT, because the shards doesn't work)
<FromGitter> <roduquen> My goal is just to create a hash in SHA256 from a string
<FromGitter> <naqvis> It is broken due to last change
<FromGitter> <naqvis> you want to get hexdigest? or base64digest?
<FromGitter> <roduquen> I would like to have a base64 digest but URL sage
<FromGitter> <naqvis> base64 won't be URL safe
<FromGitter> <naqvis> so you better go with hexdigest
<FromGitter> <roduquen> I am not sure URLsafe is mandatory, it is just because of the angular jwt doc
<FromGitter> <naqvis> you can go with sth like ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ but this will cause deprecation warning https://github.com/crystal-lang/crystal/issues/9699 (https://github.com/crystal-lang/crystal/issues/9699) [https://gitter.im/crystal-lang/crystal?at=5f58bed99bad075eac0a7fa4]
<FromGitter> <naqvis> if you need base64 just change last line to `dio.base64digest`
<FromGitter> <roduquen> Thank you :)
<FromGitter> <naqvis> np :)
<FromGitter> <roduquen> And there is a RSA encryption module in Crystal ?
<riffraff169> re: aliases....that always confused me too...never was sure which one was the preferred way, and which one might suddenly be deprecated (with warnings) or even entirely disappear...most times i would use reduce, but other times, umm, which ever option was the same (cant remember now)
<riffraff169> depends on which doc i was following
<FromGitter> <andrewc910> Is it possible to serialize a proc to json or some other easy to work with format? I tried the stdlib JSON::Serializable, blacksmoke's CrSerializer & jdr's Crystalizer with no success.
<FromGitter> <naqvis> what's your use-case? Crystal neither have RTTI nor any reflection
<FromGitter> <Blacksmoke16> yea how would you do that :p
<FromGitter> <andrewc910> Use case: Some objects get serialized, stored in an html doc, websocket connection is made, state of object is sent back, deserialized. Certain frontend actions trigger a websocket call, which invokes a method on that deserialized object. ⏎ ⏎ All that is working. I would like to be able to pass procs allowing components downstream to invoke methods upstream. The problem is that proc needs to be
<FromGitter> ... serialized for it to "return" after deserialization in the later steps.
<FromGitter> <andrewc910> I have no idea how that would work! That's why i just tried a couple nice libraries and then came to ask if it was possible :shrug:
<FromGitter> <Blacksmoke16> yea idk how that would work, hence why no serializer implementation supports doing that with procs
<jhass> do these procs capture state or are there mere method references?
<FromGitter> <andrewc910> I am just thinking method references right now
<jhass> then just define an enum
<jhass> and have a case/when dispatcher or such
<FromGitter> <andrewc910> Hmm, sounds tedious but ill try and see how it looks! Thanks :)
<jhass> you can picture it as serializing a method name and a basic form of RPC
<jhass> if you got the enum and have a good convention between the enum and method names going, some macro code can DRY it up
<jhass> and/or you can use a lookup hash etc
<FromGitter> <andrewc910> For that to work, the downstream object would need a reference to the upstream object, right? Or am i not understanding.
<jhass> maybe? I'm talking very generally since I don't see what you already got :)
<FromGitter> <andrewc910> Thats fair. I will at least take a look! Thanks :)
<FromGitter> <Dan-Do> Hi everyone. Is there "jump to" statement in crystal-lang? I don't want to repeat the code.
lunarkitty has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> I don't think. Got an example in what you need it for?
<FromGitter> <j8r> use a method @Dan-Do
<FromGitter> <Dan-Do> Here is the pseudocode: ⏎ START: ⏎ client.get() ⏎ parse result ⏎ if error/exception jump to START ... [https://gitter.im/crystal-lang/crystal?at=5f58d0085580fa092b5532d5]
<FromGitter> <Dan-Do> My real code is more complex with many if else and try rescue
<FromGitter> <Blacksmoke16> could do something like https://github.com/crystal-lang/crystal/issues/1736#issuecomment-241382286 instead
<FromGitter> <Dan-Do> My context is not like triable. It must jump to start and do the steps in order to parse the expected result.
<FromGitter> <Blacksmoke16> is that not what the example was doing?
<FromGitter> <Blacksmoke16> invokes the block on error, calling the block multiple times based on #retries
<jhass> Dan-Do: the basic pattern is as demonstrated in the example above, you put your code into a loop and break the loop as needed. I believe there's formal proofs that this is equivalent to goto, it certainly is for 95% of usecases. Of course in practice often a much nicer solution can be found, but is then very domain specific
<FromGitter> <Dan-Do> How about just want to jump to STEP2, not from the START?
<FromGitter> <Blacksmoke16> nested retry blocks?
<FromGitter> <Dan-Do> Maybe define multiple retry?
<jhass> yes, that sounds like a nested loop
<FromGitter> <Dan-Do> Yeap, I will look in to that further. Thank you :)
alexherbo2 has joined #crystal-lang
chachasmooth_ has quit [Quit: Quit]
chachasmooth has joined #crystal-lang
<riffraff169> i have a string: "00: blah", and i want to deconstruct (i guess) into "00", "blah"....i was thinking:
<riffraff169> [code, rest] = line.split(":"), but that isnt valid
<riffraff169> whats the best way to do that?
<FromGitter> <Blacksmoke16> `code, rest = line.split ":"`
<FromGitter> <Blacksmoke16> were close
<riffraff169> ah no brackets
<FromGitter> <Blacksmoke16> ofc `rest` would be like `" blah"`
<FromGitter> <Blacksmoke16> could split on `": "`?
<riffraff169> yeah, there will be a space, although im going to be splitting the second part further, so...
<FromGitter> <Blacksmoke16> 👍
<riffraff169> how about a regex? /^(..):(.*)/.match(line), how to assign multiple match groups to multiple vars at the same time, or is an array better (like s = )
<riffraff169> ack, emoji fail: `/^(..):(.*)/.match(line)`
<riffraff169> still, that is `: )`
<riffraff169> i mean `: (`.... i never use emojis
<riffraff169> i keep forgetting about named captures....been doing regexes since before that was a thing and never quite got used to them...ok thanks
<FromGitter> <Blacksmoke16> might be able to use the latter
<riffraff169> so which is better, regex on left or right?
<riffraff169> looks like regex should be in match, rather than match line against regex?
<FromGitter> <Blacksmoke16> hm?
<riffraff169> so more like: `line.match(/^(?<code>..):\s*(?<desc>.*)$/)` instead
<riffraff169> instead of regex.match(line) basically
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> id guess they would be equivalent, but id check the api docs to make sure
<FromGitter> <Blacksmoke16> yea the former just does the latter essentially
<riffraff169> okay, string method with regex...
<FromGitter> <Blacksmoke16> id go with whatever reads better
<riffraff169> hmmm....ok thanks
<riffraff169> crystal is close enough to ruby, but there enough differences that i find myself having to dig through docs to find proper methods
<riffraff169> but i like it
<FromGitter> <Blacksmoke16> good to hear
deavmi_ has joined #crystal-lang
deavmi has quit [Read error: No route to host]
HumanGeek has quit [Remote host closed the connection]
HumanGeek has joined #crystal-lang
<FromGitter> <wontruefree> have anyone done a flamegraph in crystal to do performance tuning? http://www.brendangregg.com/flamegraphs.html
<FromGitter> <wontruefree> I might be able to just pass the perf output but I was just curious if there was a shard out there
<riffraff169> is there a difference between `x = Array.new(Int32)` and `x = [] of Int32` ?
<FromGitter> <Blacksmoke16> other than syntax? no
<FromGitter> <Blacksmoke16> well it should be `Array(Int32).new`
<riffraff169> ok...is there a style preference? ah yes
<FromGitter> <Blacksmoke16> i tend to use both, depends on the context
<oprypin> riffraff169, some people use one whenever possible, other people use the other whenever possible
<oprypin> and yes, `[] of Int32` is just trivial syntax sugar for `Array(Int32).new`
<riffraff169> another question, i need to split on a string that may have a `;`, on the `;`....so the result will have 1 or more items...
<riffraff169> `res = line.split(/;/)`
<riffraff169> if there isn't a `;`, then thats fine, there will be one entry
<riffraff169> but trying to do that command gives me an error: `Error: undefined method 'split' for Nil (compile-time type is (String | Nil))`
<riffraff169> but my line result always seems to be a String, not sure where Nil is coming from
<FromGitter> <Blacksmoke16> there is a case where it wont be
<FromGitter> <Blacksmoke16> got some more example code?
<riffraff169> just a sec, let me put it on the playground
<riffraff169> maybe i should use ";" instead of /;/
<riffraff169> nope
<FromGitter> <Blacksmoke16> ah yea, there is no promise that the named captures would have a value of rthat
<oprypin> riffraff169, `data1.named_captures["code"].not_nil!` is just `data1["code"]`
<riffraff169> thing is, when i puts desc1.class the result is String, not String|Nil
<oprypin> riffraff169, thats normal. the runtime type will always be just one type
<riffraff169> and without the `.not_nil!`, it gives me this error `Error: undefined method 'named_captures' for Nil (compile-time type is (Regex::MatchData | Nil))`, another Nil...
<riffraff169> ah...hmm
<oprypin> `typeof(desc1)` for compile tiem type
<oprypin> riffraff169, no you're misreading my advice
<oprypin> match().not_nil! is fine as is
<riffraff169> ah i see, hmm...
<riffraff169> so what would be the best way to split on a non-existent `;`, so there will be 1 or more items in the list
<FromGitter> <Blacksmoke16> the reasoning why there was the `nil` option is because of ⏎ ⏎ > When this regex has an optional group, result hash may contain a `nil` if this group is not matched.
<FromGitter> <Blacksmoke16> and that affects the whole hash
<riffraff169> hmmm....and im doing the not_nil because i know for a fact my data will never have that problem
<FromGitter> <Blacksmoke16> correct
<FromGitter> <Blacksmoke16> another way to do it would be like
<riffraff169> ok, gotcha
<FromGitter> <Blacksmoke16> ```if match = str.match(regex) ⏎ # you know a match was made and is not nil ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f5938a0c3aa024ef9d202ab]
<riffraff169> ah
<oprypin> riffraff169, so what is the problem with `;`, i still dont get it
<riffraff169> oh my word....changing `code1 = data1.named_captures["code"]` to `code1 = data1["code"]` changed the type from String|Nil to just String
<riffraff169> so now the split is working
<FromGitter> <Blacksmoke16> ypu
<FromGitter> <Blacksmoke16> yup
<riffraff169> well, that fixes my problem now
<riffraff169> thanks
zorp has quit [Read error: Connection reset by peer]
lunarkitty has joined #crystal-lang
deavmi_ has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
<oprypin> https://crystal-lang.org/api/master/Array.html#[]=(index:Int,count:Int,values:Array(T))-instance-method reeeeeally should accept Indexable :(