ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.21.1 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<FromGitter> <Sija> there's `String#encode` which might be your alley
<FromGitter> <eliasjpr> I want to decode
<FromGitter> <fridgerator> @elorest I hear you. The place I work uses mainly python, so a lot of Django, so I deploy django apps using capistrano, lol
<FromGitter> <Sija> Like that `String#new(str, encoding: “…”)`?
<FromGitter> <carsonbaker> @eliasjpr ```String.new("\xC3".to_slice, "iso-8859-1").encode("utf-8")```
<FromGitter> <carsonbaker> I don't know what you're trying to do though.
<FromGitter> <carsonbaker> or use ```.bytes``` if you want the value as an Array(UInt8)
<FromGitter> <eliasjpr> That works Carson
<FromGitter> <eliasjpr> Thank you
<FromGitter> <carsonbaker> sure
<FromGitter> <eliasjpr> Very much appreciated
<FromGitter> <exts> So I'm trying to figure out if this is normal behavior from crystal https://gist.github.com/exts/96b288a220469c4af519df0721f57b5b and why does this run? ⏎ ⏎ Is it because the include puts the whole file inside the Root namespace?
<FromGitter> <bew> I think this is a bug (for reference: https://carc.in/#/r/1wgt)
<FromGitter> <carsonbaker> what is the expected output/error?
<FromGitter> <bew> this: https://carc.in/#/r/1wgx
<FromGitter> <exts> I was expecting it to error out since that's a protected method, in the docs it says when you include inside a module you have access to protected methods, but when i include in a file directly it still works which means im assuming it puts that whole file inside that module?
<FromGitter> <carsonbaker> yeah. and, as expected, it errors when trying the same thing with private methods.
<FromGitter> <exts> yeah but this isn't about private methods
<FromGitter> <exts> is that expected behavior?
<FromGitter> <exts> when you include outside of a module i still have access to protected methods?
<FromGitter> <carsonbaker> it seems like a real subtle thing. i don't know. what does ruby do?
<FromGitter> <exts> i don't know, not a ruby programmer
<FromGitter> <bew> No I don't think it's expected, the protected should apply to `Test1` scope, not `Root`
<FromGitter> <exts> should I create a new issue? to see what asterite and co thinks?
<FromGitter> <carsonbaker> ```code paste, see link```
<FromGitter> <bew> yes, open an issue!
<FromGitter> <exts> will do
<FromGitter> <exts> well first let me search :), i'm bad at that sometimes
<FromGitter> <bew> you can include my carc in links for easy proof in the issue
<FromGitter> <exts> thanks, will do
<FromGitter> <exts> Alright I posted it #4315 hopefully I was descriptive enough, haven't ran into an issue like this before (not that it stops me from working) - possibly found my first compiler bug? :D
<DeBot> https://github.com/crystal-lang/crystal/issues/4315 (Calling a protected method outside of module doesn't produce an error when you include that module in the same file)
<FromGitter> <bew> in your issue, for crystal source highlighting you can add `cr` after the 3 first backticks
<FromGitter> <exts> oh, thanks :)
<FromGitter> <exts> lol why does it show every edit :| on the sidebar
<FromGitter> <bew> ?
<FromGitter> <bew> like: http://i.imgur.com/iYQCmxD.png
<FromGitter> <exts> oh im on glitter, it shows all activity including every edit it seems
<FromGitter> <exts> is it gitter? or gltter, can't tell
<FromGitter> <bew> I'm also on gitter but I don't have edit notification (even with full notifications activated)... so... weird
<FromGitter> <exts> ah, maybe i can disable it
<FromGitter> <bew> @exts finally, it's expected behavior.... weird (see asterite's reply)
<FromGitter> <exts> @bew yeah it's definitely weird, don't really see a point in using protected anymore then tbh.
Cyrus has joined #crystal-lang
gewo has joined #crystal-lang
<Yxhuvud> I wonder what the reason for the different behaviour is.
<FromGitter> <CodelessFuture> Thanks for sharing. This week I write the follow. @sdogruyol
<FromGitter> <codenoid> can i found sublime snippets for crystsal ?
Philpax has quit [Ping timeout: 240 seconds]
Philpax has joined #crystal-lang
<olbat> Hi ! I have an issue converting a SomeType* I get from a C binding to a Crystal Array can someone help me ? (I know the size of the array too)
<olbat> (I would like to get a Array(SomeType) or a StaticArray(SomeType))
Qchmqs__ has joined #crystal-lang
mark_66 has joined #crystal-lang
Qchmqs__ is now known as Qchmqs
<FromGitter> <bew> @olbat you could use `Slice.new(your_pointer, your_size).to_a`
<olbat> it works like a charm, thank you !
<FromGitter> <bew> wow, I just compiled crystal (master) in 40s, and... 897.29MB ??? Little time ago it took almost 2Go..
<FromGitter> <bew> what kind of changes reduced the RAM used for full compilation by 2?
gloscombe has joined #crystal-lang
jfontan has quit [Quit: ZNC - http://znc.in]
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
jfontan has joined #crystal-lang
jfontan has quit [Remote host closed the connection]
jfontan has joined #crystal-lang
elia has joined #crystal-lang
elia has quit [Client Quit]
bjz has joined #crystal-lang
A124 has joined #crystal-lang
jfontan has quit [Quit: jfontan]
jfontan has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 255 seconds]
Qchmqs has quit [Ping timeout: 260 seconds]
<Papierkorb> Looks like someone from you all passed my info on to their company's HR department. I hope you enjoy your bonus. ;P
<FromGitter> <sdogruyol> what?
<Papierkorb> ?
<FromGitter> <drosehn> passed info to an HR office? whose HR office?
z64 has joined #crystal-lang
<z64> anyone seen any rethink ORMs about? going to be using CT's driver, but some basic class mapping would be great
<Papierkorb> drosehn, the person gave my information to a HR/recruiter of their company
NIk-- has joined #crystal-lang
<FromGitter> <nicck> I've recently found StaticArray in API docs, and now I'm not sure when I should use StaticArray and when Tuple if I need fixed-size stack-allocated sequence of values of the same type. Is there any difference between them in such case?
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v9el9
<crystal-gh> crystal/master 919bc4c Jonne Haß: Rename HTTP::Params.from_hash to HTTP::Params.encode and add an overload...
<crystal-gh> [crystal] bcardiff pushed 1 new commit to master: https://git.io/v9eEv
<crystal-gh> crystal/master 24c8321 Brian J. Cardiff: Document WeakRef...
<crystal-gh> [crystal] bcardiff closed pull request #3926: Add WeakRef to docs_main (master...patch-2) https://git.io/vMQfy
<crystal-gh> [crystal] bcardiff closed pull request #3958: Get backtrace function names from DWARF sections (master...core-backtrace-function-names) https://git.io/vDkzH
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v9euu
<crystal-gh> crystal/master 0f65ea4 Ary Borenszweig: Fixed #4318: Array.each_product fails on empty arrays
<crystal-gh> [crystal] bcardiff merged changelog into master: https://git.io/v9ezf
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<BlaXpirit> nicck, if u need 10 items you're not gonna write `{Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32}`, hopefully that answers your question
<BlaXpirit> tuple is fixed size, different types; staticarray is compiletime size, same types
<BlaXpirit> note that compiletime is less strict than fixed, you can factor things out into a constant and stuff like that
McSoFake has joined #crystal-lang
mark_66 has quit [Remote host closed the connection]
<FromGitter> <CodelessFuture> Part II of the series on Crystal/Kemal
<FromGitter> <codenoid> @CodelessFuture thanks sir
<FromGitter> <codenoid> ===request please write about mongodb & crystal :sparkles:===
McSoFake has quit [Ping timeout: 245 seconds]
<FromGitter> <CodelessFuture> @codenoid In next article I start to add dynamic content….mongodb or postgresql…..
<FromGitter> <codenoid> mongo please.. <3 :smile: :clap:
<RX14> postgres please
<RX14> it's much more mature
<RX14> SQL is a useful tool
<RX14> and the queries are much more powerful
<RX14> in adition it allows you to transfer much more work to the DB with constraints
<FromGitter> <codenoid> both please
<FromGitter> <codenoid> nosql and sql
<RX14> nosql is fine but it's useful in less situations than SQL
<RX14> SQL should be the default tool you pick up, usually postgres
gloscombe has quit [Remote host closed the connection]
<FromGitter> <codenoid> @FromIRC but i have a big ideas
<FromGitter> <schoening> "At least for now, WebAssembly does not support garbage collection at all. " ⏎ Oh gee :( No crystal for my web stuff then I suppose..
<FromGitter> <codenoid> successfully relationship https://s1.postimg.org/t6lxjl2zj/kemalmongo1.png
<FromGitter> <codenoid> crystal (kemal) <3 mongo
<FromGitter> <schoening> congratz @codenoid !
<FromGitter> <codenoid> @schoening <3
<FromGitter> <bew> @schoening yeah, wasm is not yet ready gc-ed language, but I know that there are discussions about that... The time will come!
<FromGitter> <schoening> I sure hope so! Cross platform app and good performance would be great :D
<FromGitter> <exts> Working on an Algolia api wrapper for work, not sure if I'll use it though https://github.com/exts/Crolia was interesting writing most of it. Didn't realize how good the crystal standard library was until yesterday.
greengriminal has joined #crystal-lang
<FromGitter> <codenoid> thank you so much https://github.com/f/kamber
<FromGitter> <mverzilli> @exts why wouldn't you use it? did you hit any roadblocks?
<FromGitter> <exts> oh, none so far
<FromGitter> <exts> i'm just under a time constraint lol
<FromGitter> <mverzilli> lol :P
<FromGitter> <exts> and my primary language already has a wrapper, but I think crystal would be faster which is why i started the project. eventually i want to convert w/e I write to use some of my crystal code in the backend :)
<FromGitter> <exts> plus I just find it fun writing crystal code so that's the biggest reason :)
fryguy9 has joined #crystal-lang
zipR4ND has joined #crystal-lang
unshadow has joined #crystal-lang
<zipR4ND> hi all, two weeks ago we spoke about regexps and performance. no I implemented a NFA/DFA https://github.com/ziprandom/crystal-dfa. Like expected it beats PCRE on pathologic expressions, but for the practical ones it still lacks behind slightly. I'm new to this, so any feedback is appreciated :)
<FromGitter> <bew> awesome
<FromGitter> <bew> !
<unshadow> I want to pass around a logger object between my classes (all under the same module name), in Ruby, I usually just inject the object I want everywhere to the Object class, but in Crystal it seems to raise an Invalid mem access. Except from setting it as a global, any other ideas ?
<zipR4ND> unshadow: do you instanciate these classes? then you could pass the logger to the instances via some set_logger method ...
<RX14> unshadow, use a global
<RX14> just class_property on some module
<RX14> and then YourNamespace.logger
<RX14> simple
<unshadow> RX14: Good idea !
<unshadow> thanks
xmonader has joined #crystal-lang
<RX14> zipR4ND, why do you add alphanum? to Char
<RX14> ascii_alphanumeric? exists
<zipR4ND> RX14: yeah already found out about that ..
<zipR4ND> I will fix that ...
<zipR4ND> don't even use it anywhere ..
<RX14> and each_char.all(&.ascii_alphanumeric?) is a better implementation for the one on String
<zipR4ND> where?
<RX14> all? sorry
<zipR4ND> ah ok string and char are already gone
<RX14> oh
<zipR4ND> relicts I didn't use anymore ..
<zipR4ND> this is the algorithm that does the matching: https://github.com/ziprandom/crystal-dfa/blob/master/src/crDFA/dfa.cr#L22
<zipR4ND> I use {begin, end} Tuples to represent segments: a = {97, 97}, [a-z] = {97,122}
<unshadow> RX14: Is there someplace with examples on the usage of class_property , can't find it in the docs or api
<RX14> zipR4ND, nice
<FromGitter> <codenoid> YASSSSSSSSSSSSSS ... finally i can do each view in ecr file @sdogruyol @fridgerator
<zipR4ND> so It would be really nice if this could be sped up: https://github.com/ziprandom/crystal-dfa/blob/master/src/crDFA/dfa.cr#L24
<zipR4ND> the keys are already ordered but I don't get bsearch to work ..
<RX14> allocations are your enemy here
<RX14> .keys allocates memory
<RX14> you're doing that for each char
<zipR4ND> interesting!!
<RX14> that's going to kill your performance already
<FromGitter> <fridgerator> @codenoid :thumbsup:
<zipR4ND> so instead I iterate the whole hash?
<RX14> you can use each_key, which returns an iterator
<zipR4ND> ok
<RX14> for even better performance, reimplement find using each_key
<RX14> but LLVM might make that negligable
<RX14> you want to find everywhere where you do needless memory allocations
<RX14> or memory copies
<RX14> obviously your algorithmic complexity will dominate
<RX14> but thats already optimized i'm sure
<RX14> so after that you need to think like a C programmer
<zipR4ND> nice already down from 2.67xPCRE to 1.64x
<zipR4ND> and this is where the problems start: never been a C programmer
<zipR4ND> I'm this new generation of programmers crystal will create ...
<FromGitter> <codenoid> you twice RX14 and zipR4ND talkng to me ?
<zipR4ND> yeah, atm. it's pretty simple already. you have the DState who is identified by a list of nfa states and has the next hash which holds the next state for a given input segment .. thats all
<zipR4ND> the rest of the code is parsing and building NFA and then DFA
<zipR4ND> which could be optimized, I'm sure but the priority is matching speed, not parsing
marius has quit [Quit: leaving]
<RX14> @codenoid ??
<FromGitter> <codenoid> oh, i dont think so
<RX14> zipR4ND, the pcre source code will have all sorts of dirty C tricks you'll never imagine in i'm sure
<RX14> zipR4ND, that article isn't exactly relevant but it gives you an idea of what goes on in these kind of tools
<RX14> decades of optimizations
<RX14> they're almost impossible to beat without taking a entirely different approach or algorithm
<RX14> but your crystal shard is a "better" algorithm vs pcre right?
<zipR4ND> i suppose
<zipR4ND> it's thompson which at least garantees you linear scaling
<zipR4ND> comment out line 9 & 10 here: https://github.com/ziprandom/crystal-dfa/blob/master/benchmark/compare.cr#L9 to see how good it can be at winning :)
<RX14> thats good
<RX14> you have a chance to beat it then :)
<zipR4ND> I don't know, maybe there are situations in which this is already more suited than pcre ...
<zipR4ND> whats missing atm. is: ^$, capturegroups and look(behind|ahead)
<zipR4ND> btw. to have nice syntax I hijacked the Regex class to return a RegExp version of its @source on /a[a-z]/.cr
<zipR4ND> the PCRegex still get's initialized though ..
<RX14> zipR4ND, I imagine that using a 128byte lookup table for DState.next would work well for mostly-ascii
<RX14> you'd have to include a fallback for unicode though
Renich___ has joined #crystal-lang
<zipR4ND> RX14: what is a lookup table compared to the hash it's using atm?
<RX14> i'm a bit confused about the hash
<RX14> you iterate it to find an AtomType... then use that to look up the next value
<RX14> why not just a Array({AtomType, DState}) in that case
<RX14> you match on tuple[0] and then you immediately have tuple[1]
<zipR4ND> interesting!
<RX14> hash is the wrong datatype here
<RX14> also a lookup table is basically a chunk of memory
<RX14> you allocate say 128 bytes of memory
<RX14> then you do
<RX14> if char.ord < 128; table[char.ord]
<RX14> and it's an O(1) operation to get the value you're looking for
<RX14> however on 64bit that lookup table might get large
<RX14> so it's probably better to list your dstates and have a seperate lookup table which maps to the index of the tuple in the array
<RX14> which can be a UInt8, which makes the lookup table smaller
<RX14> which means it fits in CPU cache more and makes your regex take wayt less memory
<RX14> you'll have to benchmark it
<RX14> but it might get you a speedup
<zipR4ND> wow
<zipR4ND> the url regexp :
<zipR4ND> runs two times faster now than PCRE!!
<zipR4ND> thanx RX14
<RX14> nice!
<zipR4ND> you made my day!!
<RX14> was that just with the Array()
<zipR4ND> yes
<RX14> cool
<zipR4ND> no time now to implement the lookuptable
<RX14> lookup table will turn your core match loop into like 10 instructions for ascii maybe
<RX14> although you'll probably want to perform optimizations for large linear lookups eventually too
<RX14> using the algorithm used in that grep article
<RX14> when there's no matching apart from "find this string" you'll want to implement that kind of stuff from the article, but that kind of optimization can probably wait
<RX14> you should use Pointer(UInt8).malloc for the lookup table
<RX14> then you can get rid of the bounds check and replace it with your own
<zipR4ND> ok
<zipR4ND> will look into that soon
<zipR4ND> atm. it seems im two times faster thats what I want because the end boss is libgraphqlparser
<RX14> nice
<zipR4ND> haha, ok thanks very much RX14 I have to go now ... I will look into your advice for implementing the lookup table. what I learnde from russ cox is that there are situations in which the nfa runs faster
<RX14> ok
<RX14> glad to help
<zipR4ND> we have both, so we can run @nfa in this situations .. (RE2 style ..)
ltran has joined #crystal-lang
ltran has quit [Client Quit]
huggles has joined #crystal-lang
zipR4ND has quit [Ping timeout: 260 seconds]
<FromGitter> <exts> has anyone written any cool articles on macros? i feel like that's my weak point in crystal atm
<FromGitter> <fridgerator> https://vimeo.com/190927958
<FromGitter> <dmitryrck> +:+1:
huggles_ has joined #crystal-lang
huggles has quit [Ping timeout: 260 seconds]
fryguy9 has quit [Ping timeout: 260 seconds]
<FromGitter> <exts> will check it out, not sure if I've seen this one
fryguy9 has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
bjz has joined #crystal-lang
fryguy9 has quit [Quit: Leaving.]
greengriminal has quit [Quit: Leaving]
Renich___ is now known as Renich
xmonader has quit [Ping timeout: 258 seconds]
unshadow has quit [Ping timeout: 240 seconds]
unshadow has joined #crystal-lang
<FromGitter> <eliasjpr> Im trying to compile a crystal program and Im getting this output `Error: file 'demo' is not a valid Crystal source file: Unexpected byte 0xfa at position 1, malformed UTF-8`
<FromGitter> <eliasjpr> any ideas?
NIk-- has quit [Quit: Textual IRC Client: www.textualapp.com]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter> <dmitryrck> no idea, did you check the encoding of the file?
<FromGitter> <dmitryrck> try removing some "non-ascii" character, maybe that is the problem :|
xmonader has joined #crystal-lang
xmonader has quit [Ping timeout: 240 seconds]
<FromGitter> <eliasjpr> Yeah looking line by line now go figure
huggles_ has quit [Quit: Lost terminal]
<FromGitter> <drosehn> Are you compiling the file that you intended to compile? Are you compiling 'demo' or 'demo.cr', for instance?
<FromGitter> <eliasjpr> Ahh! Never mind, I'm running the compiled program with crystal command
<FromGitter> <bew> aahahahahaha (sorry)
<FromGitter> <eliasjpr> Brain fart🙅🏻‍♂️
<FromGitter> <eliasjpr> After 8 hours of work can think clearly
<FromGitter> <eliasjpr> We all have had that moment
<FromGitter> <eliasjpr> So we good
<FromGitter> <eliasjpr> 😀
<FromGitter> <codenoid> > We all have had that moment
<FromGitter> <bew> yeah^^
<FromGitter> <dmitryrck> ;)
xmonader has joined #crystal-lang
<FromGitter> <exts> i've tried so many languages in the last 2 years. only one's i like right now is crystal and nim. something about just being able to get up and going in a matter of seconds w/ the build tools is nice and the syntax, simple/elegant :sparkles:
<FromGitter> <bew> totally agree (but that I never really tried nim :) )
<FromGitter> <exts> nims pretty cool, did some fun SDL2 stuff in it