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…]
<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>
<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>
<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> 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>
<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>
<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
<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
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?
<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
<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.
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>
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
<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>
<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> 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
<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