jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.28.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
DTZUZU has quit [Ping timeout: 246 seconds]
teardown has joined #crystal-lang
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
ShalokShalom has joined #crystal-lang
ShalokShalom has left #crystal-lang [#crystal-lang]
<FromGitter> <chussenot> I spend a lot of time to write loops to parse an XML document... I don't thing that;s it's the best approach ... If someone knows an efficient library, please share it. I did not see much valuable solution in the doc, the specs or on the awesome crystal repo :|
<FromGitter> <kaukas_gitlab> @chussenot, what's wrong with the plain XML module (https://crystal-lang.org/api/0.28.0/XML.html)?
<FromGitter> <chussenot> :) @kaukas_gitlab Nothing... I use this util to do the job https://github.com/taylorfinnell/awscr-s3/blob/master/src/awscr-s3/xml.cr and do not need help anymore
<FromGitter> <chussenot> thx
alex`` has quit [Ping timeout: 248 seconds]
alex`` has joined #crystal-lang
<FromGitter> <watzon> Just finished implementing a Naive Bayes classifier in Cadmium
sz0 has quit [Quit: Connection closed for inactivity]
chemist69 has joined #crystal-lang
<FromGitter> <pynixwang> make Response generic works.
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <pynixwang> `Def#abstract?` exported?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <pynixwang> macro method
<FromGitter> <Blacksmoke16> yes, what about it?
<FromGitter> <pynixwang> is a method abstract or not
<FromGitter> <Blacksmoke16> thats what it does yes
<FromGitter> <pynixwang> do some funny thing in macro
<FromGitter> <Blacksmoke16> example?
<FromGitter> <pynixwang> implement a abstract class with macro
<FromGitter> <Blacksmoke16> sorry i dont follow
<FromGitter> <pynixwang> override abstract method in macro
<FromGitter> <pynixwang> eg
<FromGitter> <pynixwang> ``````
<FromGitter> <pynixwang> ``````
<FromGitter> <pynixwang> def xxx
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr do it here, would be easier
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> what about it?
<FromGitter> <Blacksmoke16> the method is defined when including the module
<FromGitter> <pynixwang> yes
<FromGitter> <pynixwang> implement it with macro to call another method
<FromGitter> <pynixwang> eg a http get
<FromGitter> <pynixwang> or post
<FromGitter> <pynixwang> maybe with annotation
<FromGitter> <pynixwang> @[GET]
<FromGitter> <pynixwang> but now method annotation is not works
<FromGitter> <pynixwang> just make an api like `retrofit`
<FromGitter> <pynixwang> java use dynamic proxy.
<FromGitter> <pynixwang> the key point is `get metadata from method and implement it`
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> kinda lost me
<FromGitter> <Blacksmoke16> you can get info from an annotation in a def if that is what you're after
rohitpaulk has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.4]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 258 seconds]
<FromGitter> <jwoertink> Anyone here happen to know the crystal equivalent to PHP's `openssl_encrypt("some text", "aes-256-cbc", $key, null, $iv)` ?
<FromGitter> <jwoertink> My guess is using `OpenSSL::Cipher.new("aes-256-cbc")`, but I'm not sure
<FromGitter> <Blacksmoke16> but kinda have to build it all out on its own
<FromGitter> <jwoertink> Yeah, that's what I'm seeing too. I'm getting different results, so I assumed I was doing something wrong
<FromGitter> <tenebrousedge> yeah, if I recall correctly, someone working on it last week found it to be ridiculously involved
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab ^
<FromGitter> <jwoertink> It does feel that way. Looking around in Ruby it seems to be the same
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <tenebrousedge> PHP is better than Ruby and Crystal! D:
<FromGitter> <jwoertink> lol
alex`` has joined #crystal-lang
lucasb has joined #crystal-lang
<oprypin> hol up
<FromGitter> <jwoertink> ok, next one is PHP's `hash_pbkdf2("sha1", "secret", "salt", 1024, 48, false)`. I'm using `String.new(OpenSSL::PKCS5.pbkdf2_hmac_sha1("secret", "salt", 1024, 48))`
<FromGitter> <jwoertink> In PHP I get `string(48) "2733bc2dec4604bcffd043cde0cc72f0135f95712dca20cc"`, but in crystal I get `"'3\xBC-\xECF\u0004\xBC\xFF\xD0C\xCD\xE0\xCCr\xF0\u0013_\x95q-\xCA ̡m\xA5\xFF\x9F8a\xB4m~\xCE\u0015޸\xC2\xFB\xD8\u007Fq\xD4\u0016\xBA\x9D\xC0"`
<FromGitter> <jwoertink> Anyone know how I can convert this properly?
<FromGitter> <jwoertink> The `pbkdf2_hmac_sha1` method actually returns bytes, so maybe passing to String.new is wrong here?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/String.html#new%28bytes%3ABytes%2Cencoding%3AString%2Cinvalid%3ASymbol%3F%3Dnil%29%3AString-class-method should work
<FromGitter> <Blacksmoke16> maybe try specifying encoding? :shrug:
<FromGitter> <jwoertink> hmm... I'll try a few random encodings to see if that makes a difference
<FromGitter> <jwoertink> nope. I just get invalid byte sequence errors
<FromGitter> <Blacksmoke16> lol setting it to UTF-16 made the string `"㌧ⶼ䛬밄탿쵃쳠弓熕쨭찠涡ᆬ㢟둡繭ᗎ룞﯂翘푱먖삝"` :P
<FromGitter> <jwoertink> lol
<FromGitter> <kinxer> @jwoertink Is `OpenSSL::PKCS5` in stdlib?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <tenebrousedge> just seeing "UTF-16" makes me twitch. A few years back, I was writing interfaces for a few dozen mostly undocumented APIs. I got a bug report about random garbage characters in data from one source, and spent a day or two going over the code with a fine-toothed comb before realizing that the data was being returned as UTF-16 rather than UTF-8. Since then, I've had some strong opinions about API
<FromGitter> ... documentation, or the lack thereof
<FromGitter> <z64> @jwoertink https://www.php.net/manual/en/function.hash-pbkdf2.php ⏎ "Returns a string containing the derived key as lowercase hexits unless raw_output is set to TRUE in which case the raw binary representation of the derived key is returned." ⏎ i believe crystal is giving you this (the raw binary repr), and you're comparing it to the safe lowercase hexits output
<FromGitter> <jwoertink> @kinxer yeah it is
<FromGitter> <kinxer> @Blacksmoke16 Is that the package that somehow dropped out of the API documentation like 6 versions ago?
<FromGitter> <Blacksmoke16> yea, it got added back in master
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/OpenSSL.html can see it in the master docs
<FromGitter> <jwoertink> @z64 I was looking at that. If I set that flag to true, it gives me that binary output.
<FromGitter> <kinxer> Oh, okay. So this is an edge feature.
<FromGitter> <jwoertink> `string(48) "'3�-�F���C���r�_�q-� ̡m���8a�m~�޸���q����"`
<FromGitter> <Blacksmoke16> no its been there the whole time, but was a recent PR that just adds it back to public docs
<FromGitter> <jwoertink> so maybe these are the same, and PHP echo just prints it differently?
<FromGitter> <Blacksmoke16> @kinxer https://github.com/crystal-lang/crystal/pull/7803
<FromGitter> <jwoertink> it does sort of look that way now that I'm staring at it
<FromGitter> <z64> yes, PHP is doing something like base64 encoding by default ⏎ crystal doesn't do this
<FromGitter> <kinxer> Ah... It turns out I wasn't doing the require correctly.
<FromGitter> <z64> actually its literally just the hex values of each byte back to back
<FromGitter> <Blacksmoke16> that would do it
<FromGitter> <z64> yeah that
<FromGitter> <jwoertink> yup. I just broke out the PHP one and passed each char to `ord` to match up the bytes
<FromGitter> <jwoertink> I guess I should have done that the first time lol
<FromGitter> <jwoertink> thanks for the help all!
<FromGitter> <z64> 👍
alex`` has quit [Ping timeout: 244 seconds]
<FromGitter> <jwoertink> Ok, I got the crystal function returning the same as the PHP one! That was pretty tough
<FromGitter> <jwoertink> In case anyone is curious, the PHP function I had to port was `$encryptedBytes = openssl_encrypt($clearBytes, self::CIPHER, $derived->key, null, $derived->iv);`
<FromGitter> <jwoertink> The crystal version is
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf024285de053468be56318]
<FromGitter> <Blacksmoke16> be nice if there was a nice `encrypt/decrypt` methods
<FromGitter> <jwoertink> That would be handy. I have this in a method for my use case
alex`` has joined #crystal-lang
<FromGitter> <wontruefree> is there a way to see all functions/methods on an object?
<FromGitter> <wontruefree> like `.methods` in ruby
<FromGitter> <r00ster91> yep: https://carc.in/#/r/70h2
<FromGitter> <Blacksmoke16> can use a macro
<FromGitter> <r00ster91> you can do that at compile time
<FromGitter> <Blacksmoke16> https://carc.in/#/r/70h4 would want to map on name, otherwise you would get an array of the actual bodies as well
<FromGitter> <wontruefree> thanks :)
<FromGitter> <watzon> I don't get why I
<FromGitter> <wontruefree> I have been looking for that for a while
alex`` has quit [Ping timeout: 245 seconds]
<FromGitter> <watzon> I don't get why I'm getting a `superclass mismatch` while trying to make my PragmaticTokenizer (https://github.com/watzon/cadmium/blob/master/src/cadmium/tokenizer/pragmatic_tokenizer.cr) inherit from my Tokenizer (https://github.com/watzon/cadmium/blob/master/src/cadmium/tokenizer/tokenizer.cr) class. The only constraint that `Tokenizer` has is the requiring of a `#tokenize` method, which `PragmaticTokenizer`
<FromGitter> ... has.
<FromGitter> <Blacksmoke16> whats the exact error?
<FromGitter> <watzon> I keep getting this error: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5cf02b2ff3a60a79a427d867]
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <watzon> I think I figured it out
<FromGitter> <Blacksmoke16> 👍
alex`` has joined #crystal-lang
<FromGitter> <watzon> I declare `class PragmaticTokenizer` multiple times, but only inherit from `Tokenizer` once.
<FromGitter> <watzon> Yup. That was it.
<FromGitter> <girng> Hello
<FromGitter> <Blacksmoke16> o/
rohitpaulk has joined #crystal-lang
<FromGitter> <jwoertink> hey @girng
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <girng> hi @jwoertink what are you creating with crystal?
<FromGitter> <jwoertink> Right now I'm working on porting over this API from PHP to crystal
<FromGitter> <girng> oh really
<FromGitter> <girng> I was thinking of porting fluxbb to crystal
<FromGitter> <girng> but, not sure why i would need to, out of boredom / learning experience probably
<FromGitter> <girng> keep my mind occupied
<FromGitter> <jwoertink> Yeah, we need to generate a token that this PHP lib does but in crystal
<FromGitter> <jwoertink> We have a Lucky app in production and adding in some new stuff
<FromGitter> <girng> very cool / interesting
<FromGitter> <j8r> @girng I'm afraid that just porting a software won't give the project popularity
<FromGitter> <j8r> can be useful, nevertheless, if your goal is to learn
<FromGitter> <girng> yeah
<FromGitter> <girng> i know php well so i like to look at it and then think of the code in crystal. very cool experience. same for javascript lol
<FromGitter> <watzon> You're going to find that PHP and Crystal are very different in every way, but have fun :)
<FromGitter> <girng> all roads lead to crystal though, i don't think i'll never use another language
<FromGitter> <tenebrousedge> 👍
<FromGitter> <girng> @watzon lol yeah
<FromGitter> <tenebrousedge> PHP has improved by leaps and bounds since I first started using it though. Laravel + Psy shell is a very nice dev environment, and the PHP 7 interpreter is blazing fast
<FromGitter> <j8r> @girng anything interest you in https://github.com/crystal-community/crystal-libraries-needed/issues?
<FromGitter> <watzon> That's definitely a good place to start. That's where I got the idea for Cadmium
<FromGitter> <girng> i like this https://github.com/crystal-community/crystal-libraries-needed/issues/58. can use godot for client / ui and crystal on backend
<FromGitter> <girng> godot has a tab manager ui node, would be similar to how filezilla looks like
<FromGitter> <Blacksmoke16> but wouldnt that require the user to have godot as well?
<FromGitter> <girng> yah, nvm. derp
<FromGitter> <j8r> I think by FTP client, he means at first a low level FTP client in Cyrstal
<FromGitter> <girng> https://github.com/vonKingsley/ftp looks like someone already started something
<FromGitter> <Blacksmoke16> prob doesnt work anymore
<FromGitter> <girng> i think ftp stuff beyond my scope of knowledge. example, code from here https://github.com/vonKingsley/ftp/blob/master/src/ftp.cr#L744 and below I have no idea what's going on
<FromGitter> <tenebrousedge> what I want in Crystal is `scanf`
<FromGitter> <j8r> It would be so cool to have this https://github.com/matrix-org/synapse in Crystal, but way toooo much work 😢
<FromGitter> <girng> example, `MUTEX.synchronize ` i've never seen this before wtf
<FromGitter> <Blacksmoke16> its from https://crystal-lang.org/api/master/Mutex.html
<FromGitter> <Blacksmoke16> he just assigned an instance of it to a const
<FromGitter> <girng> ```code paste, see link```
<FromGitter> <j8r> Can be useful with IO stuff, for example
<FromGitter> <girng> i thought crystal is single threaded, so why is a mutex being used?
<FromGitter> <j8r> to avoid having simultaneous writes on a given IO
<FromGitter> <Blacksmoke16> its for fibers
<FromGitter> <Blacksmoke16> i think
<FromGitter> <j8r> yes
<FromGitter> <j8r> fibers are used for concurrency. multi threads are essentially for perf
<FromGitter> <girng> why use a mutex, when you can spawn a fiber lol
<FromGitter> <j8r> that's precisely why they are useful
<FromGitter> <Blacksmoke16> so two fibers dont write to the same file at the same time
<FromGitter> <girng> oooh
<FromGitter> <Blacksmoke16> my understanding it would make it so only 1 fiber could write at a time for example
<FromGitter> <j8r> I think @Blacksmoke16 may have used Mutex in his logger library
<FromGitter> <j8r> to avoid having at the same time 2 log lines writing to an IO
<FromGitter> <girng> well how many damn fibers is needed to write to a damn file
<FromGitter> <Blacksmoke16> i actually didnt but should prob go make it use it :p
<FromGitter> <Blacksmoke16> kinda forgot about that
<FromGitter> <girng> it's usually instant isn't it
<FromGitter> <tenebrousedge> maybe. Maybe you're trying to log a series of web requests, where you're waiting on other IO
<FromGitter> <tenebrousedge> those could run into each other
<FromGitter> <Blacksmoke16> like a log file
<FromGitter> <Blacksmoke16> where each request has its own fiber
<FromGitter> <tenebrousedge> ^
<FromGitter> <Blacksmoke16> all writing to the same log file
<FromGitter> <girng> yeah if they are in its own fiber, it should be fine already? so you need to use multiple fibers and a MUTEX? or what happens if you don't use a mutex, you'll get file writing errors?
<FromGitter> <Blacksmoke16> tbh im super familiar with it but yea id imagine something would error
<FromGitter> <girng> i was under the impression the OS just queues the requests internally to write to the file, and performs them in order they are received. this way, you can spawn multiple fibers asynchronously while logging the file.
<FromGitter> <tenebrousedge> one possibility is that log file entries get inserted out of order due to race conditions
<FromGitter> <Blacksmoke16> id be interested to see some sample code with that causes two fibers to write to same file
<FromGitter> <Blacksmoke16> before/after using a mutex
<FromGitter> <j8r> yes, it would likely be mixed
<FromGitter> <girng> then when MT gets added.. my mind will become blown even moreso
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/70i5
<FromGitter> <Blacksmoke16> id have to study this more but that's apparently an example (from mutex_spec)
<FromGitter> <Blacksmoke16> w/o mutex first, then with
<FromGitter> <tenebrousedge> I'm still puzzled by the non-deterministic proc bug :( #7577
<DeBot> https://github.com/crystal-lang/crystal/issues/7577 (Error creating Proc with explicit receiver)
<FromGitter> <Blacksmoke16> 😬
<FromGitter> <j8r> mmm, I don't think there will be a problem I we write a string to an IO
<FromGitter> <j8r> because the IO will be busy and won't be usable by others
<FromGitter> <j8r> but if we use several `<<` to write to an IO, between those writes another one may write too
<FromGitter> <girng> that mutex stuff seems too low level for me. too confusing
<FromGitter> <girng> i'ma just spawn fibers like i usually do. simple, and fast enough / works for my use cases
<FromGitter> <Blacksmoke16> 😐
<FromGitter> <Daniel-Worrall> Mutex? Low level?
<FromGitter> <Daniel-Worrall> Hmmm
<FromGitter> <j8r> But mutex isn't linked to fibers
<FromGitter> <j8r> You can use it to "lock" something, to prevent any action
<FromGitter> <j8r> It's safer than using a Boolean class var
blassin9 has joined #crystal-lang
blassin has quit [Ping timeout: 244 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <girng> i mean low level in the sense how c's memory management is low level, but in LUA you don't have to worry about memory management, it's all high level and easier to work with
<FromGitter> <Daniel-Worrall> I know the context but I disagree with the sentiment
_whitelogger has joined #crystal-lang