ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.1 | 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
mbarbar has joined #crystal-lang
mbarbar has quit [Remote host closed the connection]
mbarbar has joined #crystal-lang
<FromGitter> <iambudi> How to replace all occurences of a given string? sub and gsub only replace first occurences.
p0p0pr37 has quit [Read error: Connection reset by peer]
p0p0pr37 has joined #crystal-lang
Creatornator has joined #crystal-lang
<FromGitter> <watzon> @iambudi `gsub` should work. What's your code?
<FromGitter> <watzon> Is there a way to do dynamic includes?
snsei has joined #crystal-lang
<FromGitter> <iambudi> @watzon ⏎ ⏎ ```"*test*".sub("*", "-“) ⏎ #-test*``` [https://gitter.im/crystal-lang/crystal?at=59fa789b51915d962afb636c]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <watzon> @iambudi try this
<FromGitter> <iambudi> Yes, gsub works good
<FromGitter> <watzon> `"*test*". gsub(/\*/, "-")`
<FromGitter> <watzon> @iambudi oh good
snsei has quit [Remote host closed the connection]
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
Creatornator has joined #crystal-lang
snsei_ has joined #crystal-lang
alex`` has joined #crystal-lang
gcds has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
gcds has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <watzon> Ok, I have run in to this several times now
<FromGitter> <watzon> If I define a custom type alias `alias Options = Hash(Symbol | String, String | Int32 | Float64 | Symbol | Nil | Time | Options)`
<FromGitter> <watzon> Why can't I do `options = {} of Options`?
<FromGitter> <faustinoaq> Because syntax ? try `options = {} of Symbol | String => String | Int32 | Float64 | Symbol | Nil | Time | Options`
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <marksiemers> How about this: https://play.crystal-lang.org/#/r/30lo
<FromGitter> <marksiemers> It compiles and seems more readable: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59faa96c5a1758ed0f7af9cc]
Creatornator has joined #crystal-lang
mbarbar has quit [Ping timeout: 248 seconds]
alex`` has quit [Ping timeout: 240 seconds]
<crystal-gh> [crystal] lachlan opened pull request #5233: Change URI#to_s to handle default ports for more schemes than http/https (master...uri_default_port) https://git.io/vFsug
<FromGitter> <watzon> @marksiemers funny I actually did that already
<FromGitter> <watzon> Still not as nice as just being able to alias a whole hash though
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
lacour has quit [Quit: Leaving]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mbarbar has joined #crystal-lang
tdc has joined #crystal-lang
snsei_ has quit [Remote host closed the connection]
snsei_ has joined #crystal-lang
mark_66 has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 252 seconds]
claudiuinberlin has joined #crystal-lang
snsei_ has quit [Remote host closed the connection]
<FromGitter> <crisward> Just been reading through the 0.24.0 release notes - lots going on. Tons of stuff fixed!
<FromGitter> <sdogruyol> yeah
alex`` has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Papierkorb_ has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
<FromGitter> <crisward> @sdogruyol you ready to cut a new version of Kemal ?
<FromGitter> <salzig> @mgarciaisaia dns dosen't work. :)
<FromGitter> <sdogruyol> @crisward I'm still not sure about https://github.com/kemalcr/kemal/pull/378
gcds has joined #crystal-lang
<FromGitter> <watzon> Does anyone know if there is a reason `sort` and `sort_by` haven't been added to `Enumerable`?
<FromGitter> <watzon> It would be really nice to be able to sort things that aren't arrays
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gcds has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
gcds has joined #crystal-lang
gcds has quit [Client Quit]
<FromGitter> <Rinkana> In what way would you sort enums?
<FromGitter> <watzon> I'm more worried about sorting Hashes
<FromGitter> <watzon> It's possible in Ruby http://ruby-doc.org/core-2.4.2/Enumerable.html#method-i-sort_by
<Papierkorb_> Rinkana, "sort enums"?
<FromGitter> <watzon> Yeah Enumerable != Enum
<FromGitter> <watzon> I've been trying to adapt the `Array#sort_by!` method to work with Hash to no avail
<FromGitter> <watzon> I just don't understand the way Hash works well enough underneath
gewo has joined #crystal-lang
<Papierkorb_> watzon, as you see by the naming prefix, I asked @Rinkana
<Papierkorb_> watzon, though you also didn't say what you actually wanted to do.
<FromGitter> <watzon> I want to be able to sort things, like Hash, that include Enumerable
<FromGitter> <watzon> Although right now I'm primarily focused on Hash
<FromGitter> <watzon> I need to sort a hash by its keys, but with a block. Not alphabetically.
<Papierkorb_> Hash#to_a
gcds has joined #crystal-lang
<FromGitter> <crisward> @sdogruyol, no what you mean. Still slower?
<FromGitter> <sdogruyol> yeah
<FromGitter> <crisward> No luck pinning down the reason, any ideas?
<FromGitter> <sdogruyol> more objects = more gc
<FromGitter> <cryst10> Hi all I have a Hash called ```options``` and I invoke the function ```options.has_key?("params")``` I get ```undefined method 'has_key?' for Hash(String, String | Nil):Class```
<FromGitter> <cryst10> any help
<FromGitter> <yxhuvud> @cryst10 please show your code.
<FromGitter> <cryst10> ok
<FromGitter> <cryst10> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fafa5d2a69af844b3bba04]
<FromGitter> <cryst10> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fafa7932e080696e564ab6]
<FromGitter> <cryst10> @yxhuvud
<FromGitter> <yxhuvud> You could have used a pastebin ..
<FromGitter> <cryst10> @yxhuvud I could if you want
<FromGitter> <yxhuvud> But the issue is that you don't instantiate the hash - you are trying to call a method on the class itself and not an instance of it.
<FromGitter> <codem4ster> Hi folks, ⏎ What is the problem in this code: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=59fafbc85a1758ed0f7c7e65]
<FromGitter> <codem4ster> Error in line 2: can't cast Hash(Symbol, String) to GenericHash
<FromGitter> <yxhuvud> You are trying to cast incompatible types to each other. `Nil | String | GenericHash` don't have the same memory representation as `String`.
tdc_ has joined #crystal-lang
<FromGitter> <cryst10> @yxhuvud the hash in my code is already instantiated, I'll provide a pastebin now
<FromGitter> <codem4ster> so how is `Json::Type works
<FromGitter> <codem4ster> or how can I achieve this?
<FromGitter> <cryst10> @yxhuvud https://pastebin.com/80RhZn8k
tdc has quit [Ping timeout: 260 seconds]
shelvacu has quit [Quit: Goodbye for now]
<FromGitter> <yxhuvud> @cryst10 : In any case, your default values seems as if they should be type declarations and not defaults.
<FromGitter> <cryst10> @yxhuvud which lines
tdc__ has joined #crystal-lang
tdc_ has quit [Ping timeout: 240 seconds]
shelvacu has joined #crystal-lang
<Papierkorb_> I was wondering if there was a free CI solution (like travis) for a BSD. There's not apparently (Ok, their userbase *is* much smaller than the linux crowd). But people advise to run QEMU on Travis. u wot m8.
<Papierkorb_> If I was travis, I wouldn't be thrilled about such a waste of resources
<FromGitter> <codem4ster> with this code; ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ it works for a but not b [https://gitter.im/crystal-lang/crystal?at=59fb0222976e63937e19f9c9]
<FromGitter> <codem4ster> I think there is a bug about Hash or Implementation of Hashes are very different form general types.
<Papierkorb_> it's not a bug. your typing is just off.
<Papierkorb_> `{ foo => bar } of Symbol => GenericType`
<Papierkorb_> in general, you don't have to type your local variables
<Papierkorb_> And you shouldn't just because you can
<FromGitter> <codem4ster> I need to force that hash to a MyHash
<Papierkorb_> Then construct a "MyHash".
<Papierkorb_> that has nothing to do with type restrictions
<FromGitter> <codem4ster> ok I will try
<FromGitter> <codem4ster> with your typing it works
<FromGitter> <codem4ster> can I do something like this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fb04872a69af844b3bf802]
tdc_ has joined #crystal-lang
<FromGitter> <codem4ster> because MyHash really doesn't have any logic beyond holding another types
<FromGitter> <codem4ster> I just want to build a hash for sending elasticsearch as json string
<Papierkorb_> Then why do you need strict restrictions?
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb_> Hash#to_json will generate a json string out of almost anything you stuff into it
tdc__ has quit [Ping timeout: 246 seconds]
<FromGitter> <codem4ster> ok, may be my mindset is wrong, this is the case; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fb055fd6c36fca31c8d8d9]
<FromGitter> <codem4ster> last line is the problem
<Papierkorb_> You should avoid using Symbol, it has a much much lower standing than it has in Ruby
<FromGitter> <codem4ster> no overload matches 'Array(Hash(Symbol, Hash(Symbol, String)))#<<' with type Hash(Symbol, Hash(Symbol, Hash(Symbol, Hash(Symbol, Hash(Symbol, String | Nil)))| String)) ⏎ Overloads are: ⏎ ⏎ 1) Array(T)#<<(value : T) [https://gitter.im/crystal-lang/crystal?at=59fb05a6976e63937e1a0a61]
<FromGitter> <codem4ster> will string keys resolve this?
<Papierkorb_> You'd have to type it explicitly in that case, yes. And it feels wrong, right?
<Papierkorb_> It's because you're not using JSON.mapping
<FromGitter> <codem4ster> I cannot use json mapping
<Papierkorb_> ...why?
<FromGitter> <codem4ster> here is very complicated
<Papierkorb_> ..?
<FromGitter> <codem4ster> this is a little simple part of may elastic query
<FromGitter> <codem4ster> ```code paste, see link``` ⏎ ⏎ this is another part [https://gitter.im/crystal-lang/crystal?at=59fb0621e44c43700aaaa0bb]
<FromGitter> <codem4ster> there is so much filter to map
<FromGitter> <codem4ster> and some of them are dynamic
<Papierkorb_> Use json.mapping for the parts which have a static definition, and hash for everything else.
<Papierkorb_> That alone will help you massively ending up with clean code
<Papierkorb_> And not that
<FromGitter> <codem4ster> that's the question: how can I use `hash for everything else` already
<FromGitter> <ziprandom> hey all, there still don't seem to be deb packages available for the last crystal release, or am I missing something?
<Papierkorb_> by typing it, as I already showed above.
<FromGitter> <unreadable> I
<FromGitter> <unreadable> Typo*
<FromGitter> <sdogruyol> @ziprandom no release yet
<FromGitter> <ziprandom> ah ok, now it's tagged a prerelease
<FromGitter> <ziprandom> thanks @sdogruyol
<FromGitter> <faustinoaq> @mgarciaisaia Is possible to distribute ARM binaries too?, https://github.com/crystal-lang/crystal/releases/tag/0.24.0 or Do We need to solve some LLVM issues?
<FromGitter> <watzon> Why does this ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Give me the error `Can't infer the type of class variable '@@parent_name'`? [https://gitter.im/crystal-lang/crystal?at=59fb0b8bb20c6424297af5e6]
tdc__ has joined #crystal-lang
<FromGitter> <sdogruyol> why is inheriting from `String` is disallowed @asterite ?
<FromGitter> <sdogruyol> any other approach to achieve inheriting from `String` behaviour?
tdc_ has quit [Ping timeout: 248 seconds]
<Papierkorb_> sdogruyol, String has a special memory layout, inheriting (and adding @ivars) would break that
<Papierkorb_> sdogruyol, String is a reference to this structure: `[byte_size : Int32][unicode_size : Int32][byte_data : UInt8...]`
<Papierkorb_> As in, that "byte_data" thing there has variable length. It's *not* a Slice(UInt8), or a pointer, it's literally copied there. Thus, you can't know how long an instance of String will be at compile-time
<Papierkorb_> Well, at least not for run-time created Strings
<FromGitter> <sdogruyol> from what I understood this is impossible to port from Ruby? https://github.com/rails/arel/blob/master/lib/arel/nodes/sql_literal.rb
<Papierkorb_> sub-classes store their data *after* the parent structure. "Ok", one might say, "but what if we would put the sub-classes @ivars *before* the parent?" This would indeed 'fix' it in this special case. But now you broke down-casting by doing a simple pointer cast.
<Papierkorb_> (uargh, Arel)
<FromGitter> <sdogruyol> haha
<Papierkorb_> sdogruyol, use a @ivar to store the String, then delegate to, or use forward_missing_to
<Papierkorb_> Not really the same, but hopefully near enough semantics wise
<Papierkorb_> If you intend to port something-like-Arel, does that class there really need to be a String?
<FromGitter> <sdogruyol> that's complext to answer..
<Papierkorb_> Or is there a legit use-case where e.g. a plain getter wouldn't suffice? Does SqlLiteral#each_char make sense?
<FromGitter> <fernandes> `forward_missing_to @value` is interesting, but didn't work
<FromGitter> <fernandes> @Papierkorb_ thank you for your suggestion :)
<FromGitter> <fernandes> > If you intend to port something-like-Arel, does that class there really need to be a String? ⏎ I'm just trying to port AS IS what I can
<FromGitter> <fernandes> if doesn't work, I'm gonna change the class
<FromGitter> <fernandes> (probably what's gonna happen heheh)
<Papierkorb_> Porting a lib is also a great time to question what of it is actually good, and what of it is "historically grown"
<Papierkorb_> Well, that file there doesn't look historically grown
<FromGitter> <fernandes> yeah, sure
claudiuinberlin has joined #crystal-lang
<FromGitter> <straight-shoota> @sdogruyol I had a similar issue when I needed a `SafeString` class (which is marked as html safe) for crinja.
<FromGitter> <sdogruyol> @straight-shoota how did you solve it?
<FromGitter> <straight-shoota> It wouldn't even necessarily require an additional ivar, the type would be enough to mark it.
<FromGitter> <straight-shoota> I created a new class that wraps a string and delegates (almost) everything
<FromGitter> <sdogruyol> that's interesting
<FromGitter> <straight-shoota> But of course you need to use `String | SafeString` everywhere it might come up
<FromGitter> <straight-shoota> Maybe it would make sense to have a module `Stringlike` (or similar) to make this easier compatible across shards
<FromGitter> <fernandes> do you have any kind of test for SafeString ?
<FromGitter> <fernandes> st = SafeString.new('hello') ⏎ st.should eq('hello') ⏎ ⏎ works for you? I couldn't get it working here, not sure if I did something wrong or not possible [https://gitter.im/crystal-lang/crystal?at=59fb124ab20c6424297b21c9]
twisterghost has quit [Quit: Connection closed for inactivity]
<FromGitter> <sdogruyol> @fernandes not `'` use `"`
<FromGitter> <sdogruyol> in Crystal a String uses `"`
<Papierkorb_> straight-shoota, why didn't you use plain #delegate for those which could be delegated as such?
<FromGitter> <straight-shoota> No, I currently there are no dedicated specs for this (memo to self) but it is used everywhere, so it should be covered.
<Papierkorb_> And/or custom macro code to do the unpacking of `other : String | SafeString` -> `other : String` to do `@string.{{method}}(other)` ?
<FromGitter> <straight-shoota> the eq expectation should work because `SafeString#==(other)` compares `other` with `@string`
<FromGitter> <fernandes> @sdogruyol oh yeah hahahha vicious, not the problem, the problem is the test itself hahaha
<FromGitter> <straight-shoota> Papierkorb, I'm not sure I understood your first question...
<Papierkorb_> straight-shoota, I see there are many manual delegator methods in your code
<gcds> ahm I bit struggling with linking Crystal with other stuff... ./??:(.text+0x0): multiple definition of `__crystal_main' I open object file and I see only one __crystal_main
<FromGitter> <straight-shoota> they should return `SafeString` if the string was only modified in a safe way
<FromGitter> <straight-shoota> putting that in a special macro might be better, that's true
<Papierkorb_> gcds: are you trying to link an crystal object with another crystal object?
<gcds> nope thats a point...
<gcds> oh wait
<gcds> wtf
<gcds> for some reason there was duplicate in object list
<FromGitter> <fernandes> st = Arel::Nodes::SqlLiteral.new("hello") ⏎ puts st
<FromGitter> <fernandes> puts `#<Arel::Nodes::SqlLiteral:0x10bab6cc0>` not `hello`
<FromGitter> <fernandes> maybe this is what I'm missing heheh
<FromGitter> <fernandes> I checked SafeString but could not figure out heheh
<gcds> Yay got successful working setup for Cortex-M4 + Crystal
<Papierkorb_> implement #to_s and #inspect. Note that in Crystal, both take a *io* argument into which you write what you want to show
<FromGitter> <sdogruyol> @gcds woot! Congrats
<gcds> I had to combine with C drivers and stuff
<gcds> ofcourse it has no stdlib just plain crystal
<FromGitter> <fernandes> iahuhuullll!!! test passing!!
<FromGitter> <yxhuvud> It's not possible to inherit from string? urgh, that may complicate getting ok performance out of my parser (I really really need to not do repeated calls to String#[start, legnth] as that would turn things quadratic on input string size). having to work on character by character is not nice :(
<FromGitter> <fernandes> thanks you @sdogruyol @straight-shoota and Papierkorb
<FromGitter> <sdogruyol> @fernandes awesome 👍
<Papierkorb_> gcds: You can btw prepend `@[Link(ldflags: "X")]` to a `lib` module to link to stuff
<Papierkorb_> gcds: While not actually documented as such, you can put anything as X. Heck, things in stdlib even use it to run pkg-config.
<gcds> nah I need to run it with linker scripts and shit
<gcds> its not so simple :)
<Papierkorb_> I meant, do you invoke ld manually? Or can you pass what you need to be passed to it through gcc?
<gcds> I use makefile now
<gcds> just a minute I am pushing :D
<gcds> STM32 drive lib 1.5gb... :D
<FromGitter> <codem4ster> how can I use this for creating a Term instance ⏎ ⏎ ```class Term ⏎ JSON.mapping( ⏎ status: String ⏎ ) ⏎ end``` ⏎ ⏎ Term.new(status: "blah") not working [https://gitter.im/crystal-lang/crystal?at=59fb15b75a1758ed0f7d10da]
<Papierkorb_> https://crystal-lang.org/api/0.23.1/JSON.html#mapping%28properties%2Cstrict%3Dfalse%29-macro
<FromGitter> <codem4ster> I didn't understand PullParser
<Papierkorb_> You .. don't have to?
<FromGitter> <codem4ster> document only says about from_json
<Papierkorb_> your problem now being?
<gcds> Papierkorb_ In future I will need to create somekind of logic to see which drivers are used and include them in make process :D
<gcds> or just port everything to Crystal but I dont want to because drivers updates usually pretty often
<FromGitter> <codem4ster> it only says `house = House.from_json(%({"address": "Crystal Road 1234", "location": {"lat": 12.3, "lng": 34.5}}))`
<Papierkorb_> Please, just say: What do you want to do?
<FromGitter> <codem4ster> I need something like this `house = House.new(...)`
<FromGitter> <codem4ster> I'm building not parsing
<Papierkorb_> Just write a simple #initialize
<Papierkorb_> it's not auto-generated
<FromGitter> <codem4ster> in src/ht_mobile/searcher.cr:118: missing argument: __temp_57 ⏎ Overloads are: ⏎ ⏎ 1) ElasticParser::Term.new(__temp_57 : ::JSON::PullParser) ⏎ ... [https://gitter.im/crystal-lang/crystal?at=59fb16ed2a69af844b3c6d55]
<Papierkorb_> ‎[14:00] ‎<‎Papierkorb_‎>‎ Just write a simple #initialize
<FromGitter> <codem4ster> ah at the end
<FromGitter> <codem4ster> it worked
<Papierkorb_> gcds: If you don't need/want debug symbols in the Crystal object, add `--no-debug` to your CRFLAGS
<Papierkorb_> Usually I wouldn't recommend debugging on release builds, but a debug build may be simply too large in your case, so..
<gcds> 13k size now its ok
<Papierkorb_> With --no-debug your stacktraces won't point to the source locations anymore either. But you probably don't even have exceptions right now, so ...
<gcds> with --no-debug was zero change to size
<Papierkorb_> In your case there should be about no change yet
<FromGitter> <codem4ster> @Papierkorb do you know a way simplify this on Crystal; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fb18d1d6c36fca31c94a17]
<Papierkorb_> We don't have a "with" grouping thing like in some other langs
<Papierkorb_> there's `with X yield`, but that wouldn't help you here
<Papierkorb_> your code looks fine the way it is
<crystal-gh> [crystal] MakeNowJust opened pull request #5234: Format: indent multiline call chaining with 4 spaces (master...fix/crystal-format/multiline-call-4-space-indent) https://git.io/vFGkv
<gcds> hmm maybe someone tried to replace Crystal main?
<gcds> I get this in src/init.cr:11: undefined method 'main_user_code' for Crystal:Module
<gcds> shit fire alarm in office
<gcds> :D
<Papierkorb_> Heh, An IRL GTFO maneuver
<gcds> everyone went out
<gcds> over 5k people :D
<gcds> 20 floor building
<gcds> sorry guys its malfunction u can come back :D
<gcds> ok so back to my problem
<gcds> I tried to make this
<gcds> but I got that error
<FromGitter> <bararchy> Hi Guys, would you help bump us up a bit in ycombinator ? ⏎ https://news.ycombinator.com/item?id=15610356
d1rewolf has joined #crystal-lang
<FromGitter> <sdogruyol> @bararchy done 👍
<FromGitter> <sdogruyol> great post good luck
<FromGitter> <bararchy> Thanks man :)
<gcds> ok apparently its a bug...
<d1rewolf> all, I'm trying to kill a process with "Process.kill(Signal::INT, mypid)", but I get "no overload matches 'Process.kill' with types Signal, Process." What am I doing wrong? per what i've read, this syntax should be supported
<FromGitter> <Shalmezad> Not an expert (only played with crystal 3 days), but I'm guessing from the error mypid is a Process, not an int like it's expecting. Try `Process.kill(Signal::INT, mypid.pid)`
<FromGitter> <bararchy> ^ This
<Papierkorb_> ... Or just `Process#kill`
<FromGitter> <Shalmezad> Yeah, `mypid.kill(Signal::INT)` would work too.
<d1rewolf> woops...yeah...it is a Process. my bad
<d1rewolf> thanks guys
snsei has joined #crystal-lang
Papierkorb_ has quit [Ping timeout: 252 seconds]
gcds has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Papierkorb_ has joined #crystal-lang
<d1rewolf> is there an equivalent to ruby's Process.wait with no args, or do I have to call it with myprocessobject.wait?
<Papierkorb_> What's wrong with a (for the most part) proper OOP API?
<d1rewolf> I'm porting a ruby program which has a simple little method for calling out to the shell: https://pastebin.com/YKN9uVw8
<d1rewolf> the ruby version works perfectly, but in crystal, some of my commands never seem to return. I see the first puts on line #2, but never the second on line #4. this is on linux.
<d1rewolf> any changes in shell out semantics which would require me to do it differently?
<d1rewolf> Papierkorb_: Process.wait, without args, is meant to be called without a process iirc.
<Papierkorb_> you can call wait on `0` to wait for any child process to have something to tell you
<Papierkorb_> while %x() (Please prefer using `) should return only once the command has ran to completion, returning all of what it wrote to standard output
<d1rewolf> Papierkorb_: yeah, I get that. the command returns almost immediately in ruby, but not in crystal. same command
<d1rewolf> if I set a breakpoint with "debugger" and run with lldb, I know a variable is set, but "p varname" on the lldb command line returns empty. is this a potential bug or am I using lldb incorrectly? I know 100% that the variable contains a value.
<Papierkorb_> Never used lldb, only gdb
<Papierkorb_> Does the spawned child process still exist, or disappear?
<d1rewolf> Papierkorb_: it still exists. I can continue it
<d1rewolf> oh, wait, ignore that content
<d1rewolf> I was responding to the wrong "thread" ;)
mbarbar has quit [Ping timeout: 260 seconds]
d1rewolf has quit [Ping timeout: 240 seconds]
d1rewolf has joined #crystal-lang
<d1rewolf> Papierkorb_: so what I'm calling out to the command line to execute is an "ip route" command. I can watch it, and see it succeed (the route is added) but the second CMD is never reached and the program hangs
<d1rewolf> so it seems as if whatever triggers crystal to realize the command has finished isn't happening
<d1rewolf> now, I have multiple Process's running, so perhaps I'm causing something interesting? if I isolate this in a test program, it doesn't happen
<d1rewolf> Papierkorb_: any thoughts?
gcds has joined #crystal-lang
<gcds> Papierkorb sorry if u have already answered my question but I got disconnected from IRC
<d1rewolf> Papierkorb_: I think it's related to the Process use. If I remove the other processes, it works
<d1rewolf> Papierkorb_: I think it's related to the Process use. If I remove the other processes, it works
d1rewolf has quit [Ping timeout: 260 seconds]
d1rewolf has joined #crystal-lang
<d1rewolf> all, I have a program which is freezing up when making calls to the shell. it works fine in ruby, but freezes in crystal
<d1rewolf> the interesting thing is that my program launches two Process instances. If I take away the subprocesses, it no longer hangs
<d1rewolf> when stracing to the processes created by crystal when hung, it looks like this: https://pastebin.com/dG16A2AL
<d1rewolf> I'm assuming that "resuming interrupted restart_syscall" is my shell out. Any ideas why this would happen, or something else i can try?
<Papierkorb_> gcds: Function-like macros are skipped
<gcds> fck...
<gcds> its like 40% of them are like this
<Papierkorb_> d1rewolf: Haven't used Crystal with many processes yet
<gcds> I guess its not many process but its subroutine
<gcds> spawn
<d1rewolf> gcds: are you referring to my problem?
<gcds> yes
<d1rewolf> gcds: sorry...40% of what are like this?
<gcds> function like macros
<d1rewolf> gcds: oh, ok. I thought that comment was to me
<Papierkorb_> d1rewolf: if you have another fiber that deadlocks, other fibers will never run
<d1rewolf> Papierkorb_: not doing anything that fancy. I'll try to hack up a version which I can share. It's doing hacky networking stuff, so I don't want to share something which will muck with others
<d1rewolf> and by hacky, I mean thrown together ;)
<d1rewolf> here's the code: https://pastebin.com/NTiHmenN. it generally freezes up after executing line #83
<d1rewolf> Papierkorb_: gcds ^^
<Papierkorb_> That's ruby
<d1rewolf> i know it's ugly code, but it's for personal use and fairly straightforward
<d1rewolf> Papierkorb_: sorry...strip the hashbang off. I converted it from ruby but it's been made to work with crystal
<gcds> its ruby code :D
<d1rewolf> well, it's ruby that's been modified to work in crystal
<d1rewolf> switched 'fileutils' to file_utils...changed Process.kill syntax, etc
<d1rewolf> i put the sleep 1 on line #21 in for troubleshooting
<d1rewolf> Papierkorb_: gcds going to try it again. will be disconnected for a few (likely). brb
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
<d1rewolf> Papierkorb_: gcds : ok, so two different tries. The first hung after line #85, the second after line #84
<Papierkorb_> d1rewolf: Try to reproduce it in pure Crystal (without network commands)
<Papierkorb_> also check your process tree, if those child processes hang or are cleaned up
Creatornator has joined #crystal-lang
<d1rewolf> Papierkorb_: gcds : If I change the code to https://pastebin.com/g7ssxP2V (removing the two Process calls) it no longer hangs
snsei has quit [Remote host closed the connection]
<d1rewolf> sorry, ignore that pastebin
snsei has joined #crystal-lang
<Papierkorb_> Reduce it to something we can run
<Groogy> If you guys want to see what I do for a living :P https://forum.paradoxplaza.com/forum/index.php?threads/eu4-dev-clash-9-happy-three-friends-tuesdays-15-00-cet.1052952/
<Papierkorb_> Can't (Won't) run your random iptable script
<d1rewolf> if I change it to this it doesn't hang: https://pastebin.com/NM0B6Ev6
snsei has quit [Remote host closed the connection]
<Groogy> could barely call it work ;D
snsei has joined #crystal-lang
<d1rewolf> Papierkorb_: yes, and I don't blame you. i wouldn't either ;)
Creatornator has quit [Client Quit]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
mark_66 has quit [Remote host closed the connection]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
Papierkorb_ has quit [Quit: Konversation terminated!]
snsei has quit [Remote host closed the connection]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
d1rewolf has quit [Ping timeout: 240 seconds]
d1rewolf has joined #crystal-lang
Creatornator has joined #crystal-lang
d1rewolf has quit [Ping timeout: 248 seconds]
lacour has joined #crystal-lang
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
d1rewolf has joined #crystal-lang
<d1rewolf> guys, I have this code: https://pastebin.com/CTPryJLX
<d1rewolf> if I run it as is, it freezes up randomly, usually somewhere around line 60-64. However, if I simply comment out lines 28-32, it finishes fine
<d1rewolf> Papierkorb: gcds: ^^ I stripped out all networking stuff. It still freezes
<d1rewolf> well, I left a ping in, but that's harmless
<d1rewolf> it's very likely a bug, but I'm not sure exactly where to start
<d1rewolf> I've been scratching my head though...it seems that code in particular is pretty straightforward
claudiuinberlin has quit [Quit: Textual IRC Client: www.textualapp.com]
<d1rewolf> could someone please verify this for me?
<d1rewolf> I've narrowed down the freeze to this: https://pastebin.com/yq9A81Y1
<d1rewolf> if I comment out line 9, it runs all the way through to completion. if I leave it uncommented, it hangs
<d1rewolf> it appears the `` are the culprit, but not certain
<gcds> lol, my local tv website player added anti adblock shit... found out that they chech api to allow adblock. Rerouted ajax request to my server set allow adblock win :D
qard has joined #crystal-lang
<FromGitter> <r3bo0t> > @r3bo0t You can't use utf8mb4 as utf8 is hard coded. But you could patch it. Think the issue kind of explains how. Though if you need more help just ask. Sorry for slow replies, at work gmt 8-5. ⏎ Thanks @crisward. Lost this message in so many here :P. Yeah got the same working with patching it to utf8mb4 and its working as exepected (at least for the moment)
<d1rewolf> gcds: do you happen to have time to try that code? Getting ready to submit a bug report but would love someone else to verify that it freezes for them too.
<FromGitter> <marksiemers> Question: Is there a resource or post somewhere that will walk through the steps and best practices for creating a shard? ⏎ I plan to build one in the next week or so, and I want to make sure I do certain things correctly from the beginning, and I have a bunch of questions and probably there are things I'm not anticipating. If someone can point me to a good resource, it would be greatly appreciated. A few
<FromGitter> ... of the questions I want to find answers to: ⏎ ⏎ 1) Should the binary be gitignored ⏎ 2) Should it be in a `bin` directory ... [https://gitter.im/crystal-lang/crystal?at=59fb5635f7299e8f536428a0]
<FromGitter> <marksiemers> I want to try to get all the little details with config and versioning correct if I can.
tdc__ has quit [Read error: Connection reset by peer]
<d1rewolf> oh well, ticket submitted: https://github.com/crystal-lang/crystal/issues/5236
<d1rewolf> hopefully it will get some attention
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 258 seconds]
<FromGitter> <codem4ster> hi folks, is there any method to access instance variables without getter while writing specs?
<FromGitter> <codem4ster> like instance_variable_get
<FromGitter> <faustinoaq> Plain crystal web server without frameworks looks pretty good, better that I thought 😄 ⏎ ⏎ https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Crystal/crystal/server.cr
<FromGitter> <marksiemers> Looks like `crystal init lib [name]` makes sure you do a lot of things right.
<FromGitter> <unreadable> Guys, that's a pretty great playground for a Go Game Engine
<FromGitter> <unreadable> https://ebiten-playground.github.io/
<FromGitter> <unreadable> It uses webgl on the browser
Ven has joined #crystal-lang
Ven is now known as Guest34073
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
<FromGitter> <faustinoaq> @unreadable Oh, very interesting, I wondering if would be possible a webgl playground for Crystal ? 😄
<FromGitter> <unreadable> hmm
<FromGitter> <unreadable> for SDL or SFML??
<FromGitter> <faustinoaq> SDL, maybe? 😅 What do you think would be easier ? ⏎ ⏎ Perhaps raw OpenGL? https://github.com/oprypin/crystal-raw-gl
<FromGitter> <unreadable> raw opengl would be the greatest, but it's not that easy and in the most cases is not worth the performance trade...
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
d1rewolf has quit [Ping timeout: 240 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
d1rewolf has joined #crystal-lang
Creatornator has joined #crystal-lang
d1rewolf has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> @codem4ster no, why not add a getter?
<FromGitter> <codem4ster> I'm using instance variables as private sometimes
<FromGitter> <codem4ster> no setter nor getter outside of class
<FromGitter> <codem4ster> increases encapsulation
<FromGitter> <marksiemers> What's the test? If it isn't a public facing property or getter, does it need to be tested?
<FromGitter> <bew> maybe it's not something you should test then? or for the specs only extend the class to add a getter to be able to access it?
<FromGitter> <codem4ster> there may be a public method
<FromGitter> <codem4ster> and it changes the inst. variable in a different way
<FromGitter> <codem4ster> not just set
<FromGitter> <codem4ster> when writing test to it
<FromGitter> <codem4ster> I need to look that private inst. variable in test
<FromGitter> <codem4ster> this is common in Ruby world :)
<Papierkorb> No?
<Papierkorb> if you can't test what you want to test, then your class needs an overhaul
Guest34073 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
d1rewolf has joined #crystal-lang
<FromGitter> <codem4ster> @bew I think your offer is acceptable :) But that would be great if Crystal has instance_variable_get :(
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb> there is. `foo.@bar`. it's just not what you want to use
notdaniel has joined #crystal-lang
<FromGitter> <codem4ster> omg really :)
Creatornator has joined #crystal-lang
<FromGitter> <codem4ster> let me try
<FromGitter> <codem4ster> 👏
<FromGitter> <codem4ster> thanks @Papierkorb. I just want to use it on specs. That's not a big deal
<Papierkorb> It is a big deal
<Papierkorb> Specs are a significant amount of code, easily more code than the logic that is tested
<Papierkorb> Using that notation should be the absolute exception to the norm
<FromGitter> <codem4ster> So you say, I need to use getter always?
<Papierkorb> No, but that if you end up constantly using that, that there's something wrong with your code
<Papierkorb> There are plenty of non-getter solutions. If the value can be directly controlled from the outside (best through an #initialize), and you have a #== (or could have one if it makes sense for this object), use that.
<Papierkorb> If what value you're trying to verify is so important, then yes, a getter isn't even half bad. Apparently it's important to your object/class, and thus, important to the client. May be a test client, or some other logic
<FromGitter> <codem4ster> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=59fb724832e080696e592322]
<FromGitter> <codem4ster> step1 and step2 couldn't be on initializer
<Papierkorb> why are those values @ivars? Are they needed elsewhere later on?
<Papierkorb> oh, they are
<FromGitter> <codem4ster> and I simply don't want any setter or getter for steps
<Papierkorb> Why not?
<FromGitter> <codem4ster> because another developer looking to my code needs to know that it must not change or get them
<Papierkorb> that reads like security by obscurity
<FromGitter> <codem4ster> because encapsulation
<FromGitter> <codem4ster> because I don't want an extra 2 method on my class
<FromGitter> <codem4ster> bla bla...
Ven has joined #crystal-lang
<Papierkorb> Ah ok, you don't need help it seems.
Ven is now known as Guest7149
<FromGitter> <codem4ster> you helped me :) I thank you for that :)
<FromGitter> <codem4ster> foo.@bar saves the day for me. Thanks again for that information.
<FromGitter> <exts> which text editor do you use for crystal sublime or vsc?
<FromGitter> <exts> wondering if i should switch to vsc if the crystal plugin is better
<FromGitter> <codem4ster> I'm using vsc
<FromGitter> <exts> does vsc plugin have auto complete?
<FromGitter> <codem4ster> very very basic
<FromGitter> <exts> can't wait for a proper ide
<FromGitter> <codem4ster> using some snippets and history of your code
<FromGitter> <codem4ster> nothing extra
<FromGitter> <exts> i'd pay to use a traditional ide for crystal
<FromGitter> <faustinoaq> @exts If you are using sublime, you can try https://github.com/TechMagister/cracker
<FromGitter> <exts> starred, will play with that later
<FromGitter> <faustinoaq> VSCode still needs some work to implement cracker, also Scry (https://github.com/crystal-lang-tools/scry/issues/28)
<FromGitter> <exts> heard vsc 2018 is going to introduce a better language api to support other languages better
<FromGitter> <faustinoaq> 👍
linuksz has joined #crystal-lang
linuksz has quit [Quit: WeeChat 1.9.1]
linuksz has joined #crystal-lang
<FromGitter> <codem4ster> hey @faustinoaq there is only syntax highlight plugin here https://packagecontrol.io/search/Crystal
<FromGitter> <codem4ster> am I missing something
<FromGitter> <codem4ster> https://github.com/TechMagister/CrystalAutoComplete says; ⏎ Install the Crystal syntax highlighting package from Package Control: crystal-lang/sublime-crystal
<FromGitter> <codem4ster> but this plugins settings doesn't have a cracker default setting
linuksz has quit [Quit: WeeChat 1.9.1]
linuksz has joined #crystal-lang
<FromGitter> <codem4ster> ah I got it
<FromGitter> <codem4ster> need to add CrystalAutoComplete as repository
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ducklobster has joined #crystal-lang
linuksz has quit [Ping timeout: 248 seconds]
notdaniel has quit [Remote host closed the connection]
linuksz has joined #crystal-lang
Creatornator has joined #crystal-lang
<FromGitter> <exts> dumb question: is there a simpler way to deal with checking if a string is nil/empty or is this essentially the only way to check that for union types https://play.crystal-lang.org/#/r/30s5
<Papierkorb> `string.try(&.empty?)` -> nil == false == blank
<Papierkorb> err
<Papierkorb> `if string.try(&.empty?) == false`
<Papierkorb> that'll work.
<FromGitter> <exts> thanks
<FromGitter> <exts> where can i read more about .try ?
<Papierkorb> `Object#try`
<FromGitter> <exts> hmm, only works for nil
<linuksz> What is faster for working with binary data: Slice or BitArray?
<Papierkorb> ... BitArray is for working with bitmaps.
<linuksz> What is the difference between the two?
<linuksz> If I see well, a Slice can contain any type?
<FromGitter> <paulcsmith> @exts there is also https://github.com/kostya/blank
<FromGitter> <paulcsmith> So you can do `string.blank?`
<FromGitter> <faustinoaq> https://crystal-lang.org/api/0.23.1/String.html#blank%3F-instance-method ?
<FromGitter> <exts> oh there's a blank
linuksz has quit [Quit: WeeChat 1.9.1]
<FromGitter> <exts> nice, will try that
<FromGitter> <exts> @faustinoaq that only works on string types, a union string/nil won't work. seems like i'll have to use what @paulcsmith posted which works how I want it to :)
<FromGitter> <faustinoaq> 👍 Well, if you have `String | Nil` you can use `foo.to_s.blank?`
<FromGitter> <exts> hmm, might try that
<FromGitter> <bew> whats wrong with `if !blah || blah.empty?` ?
<FromGitter> <exts> nothing
<FromGitter> <exts> but the line does get long when you're checking for a string to not be nil and empty and other stuff in that same if statement
<FromGitter> <exts> which makes `if !blah.blank? && (something_else() || something_something_else())` much nicer to type
<FromGitter> <watzon> Is there a way, using a macro or something, to turn a String into a CONST?
<Papierkorb> watzon, No
<FromGitter> <watzon> Didn't think so
<Papierkorb> watzon, use-case?
<FromGitter> <bew> in what way watzon?
<FromGitter> <exts> are you trying to define a variable, assign to it and make it immutable after assignment?
<FromGitter> <exts> like um, in C/C++ essentially
<FromGitter> <exts> err not like in C/C++, forget the language that did that.
<FromGitter> <watzon> Attempting to make a `parent` method that will return the CONST parent of an Object. For instance `Regex::MatchData.parent` would return `Regex`
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <watzon> Maybe CONST was the wrong term to use
<FromGitter> <watzon> Object might be better
<Papierkorb> you're looking for active supports String#constantize
<FromGitter> <bew> as runtime value?
<FromGitter> <watzon> More like trying to port String#constantize haha
<FromGitter> <watzon> Just wondering it it's even possible
<Papierkorb> String#constantize can't be ported :)
<FromGitter> <watzon> Yeah I thought not
<Papierkorb> After seeing too many lines of rails code being infested by that method, it's for the better
<FromGitter> <watzon> Yeah you're probably right
<FromGitter> <exts> quick question https://github.com/crystal-lang/crystal-db/blob/master/src/db/error.cr shouldn't `Rollback` and `MappingException` extend from `DB::Error` ?
<FromGitter> <exts> might do a pr to fix, so you can catch all db errors using DB::Error
claudiuinberlin has quit [Quit: Textual IRC Client: www.textualapp.com]
<crystal-gh> [crystal] RX14 pushed 1 new commit to master: https://git.io/vFZuL
<crystal-gh> crystal/master bf3dd80 Ary Borenszweig: Syntax: check `Expressions#keyword` in `to_s` and add `If#ternary?` (#5226)
Kug3lis has joined #crystal-lang
Kug3lis is now known as gcds_
<gcds_> Is there a way to define crystal "fun" as weak? :D
<travis-ci> crystal-lang/crystal#bf3dd80 (master - Syntax: check `Expressions#keyword` in `to_s` and add `If#ternary?` (#5226)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/296513888
<DeBot_> https://github.com/crystal-lang/crystal/pull/5226 (Syntax: check Expressions#keyword in to_s)
Guest7149 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<crystal-gh> [crystal] RX14 closed pull request #5227: Can't use `self` in toplevel method (master...fix/crystal/no-self-in-toplevel-method) https://git.io/vFOAt
<21WAAPIFE> [crystal] RX14 pushed 1 new commit to master: https://git.io/vFZiN
<21WAAPIFE> crystal/master 7acedf8 TSUYUSATO Kitsune: Can't use `self` in toplevel method (#5227)...
<DeBot_> https://github.com/crystal-lang/crystal/pull/5227 (Can't use `self` in toplevel method)