<FromGitter>
<bararchy> Hi @sdogruyol :) how was your talk ?
<FromGitter>
<sdogruyol> @bararchy ıt's good, the feedback from the audience was great
<FromGitter>
<sdogruyol> Great to see more people getting interested in Crystal
<Groogy>
Hello!
<Papierkorb>
Yo
<FromGitter>
<sdogruyol> @Groogy hey!
<FromGitter>
<sdogruyol> how's your new shiny PC? :D
<Groogy>
It's great! :D THough I still emotionally see it as still my old one, didn't replace any part
<Groogy>
yes I am sentimental about my computer
<FromGitter>
<sdogruyol> haha
<Groogy>
every part*
<FromGitter>
<sdogruyol> you just reminded me of my youth and PC days
<FromGitter>
<sdogruyol> I was kinda lunatic about pc parts
<Groogy>
yeah, it was kind of fun nerdingt out for a week on what parts to pick out :P But now its time to finally get my first crystal project on github
<FromGitter>
<bararchy> @bew Working now, thanks for the tip :)
<FromGitter>
<sdogruyol> @Groogy yeah, it's a lot of fun back in the days
<FromGitter>
<sdogruyol> did you get the new AMD Ryzen CPU?
<FromGitter>
<bew> @bararchy glad it worked ;) Have fun!
<Groogy>
Yepp I did, gonna be interesting to see how it goes when I really put stress on it
<FromGitter>
<sdogruyol> great
<FromGitter>
<sdogruyol> @Groogy what's your first Crystal project is about?
<Groogy>
Contracts, the thing I talked about before. I'm too lazy to use specs, I like to inline the specis in the code instead :P
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<Groogy>
though question, I am trying to convert static macro data to some type I can retrospectively look at in runtime
<Groogy>
the array is empty outside of finished while inside of finished it prints what I expect
<Groogy>
also order of how things run seems to be all other code -> code generated by finished
<Groogy>
doesn't seem to matter where finished is expanded
<oprypin>
well that's the point, isnt it
<Groogy>
yeah I thought it was just that it was a macro that got called last but it got expanded where it was written
<Groogy>
hmm can I somehow define this statically so the compiler has to run this first?
<Groogy>
oooh I got an idea, this should force the compiler to run this code first
<FromGitter>
<bew> declare a constant
<Groogy>
yeah what I was gonna do
<Groogy>
a class constant for the class which I am also wrapping functions around
<Groogy>
and the constant can then register itself with the global class runtime data constant
<Groogy>
how do I do a spec that is "should raise"?
<Papierkorb>
expect_raises(TheErrorClass) do do_something_that_raises end
<Groogy>
nice thx
<Groogy>
ow yeah for crystal-clear project name, crystal generates the module Crystal::Clear, should it be that or just simply CrystalClear?
<Papierkorb>
Don't use ::Crystal
<Groogy>
yeah thought that would be kind of bad
<Papierkorb>
Avoid `crystal` if referring to the crystal language
<oprypin>
huh weird
<Groogy>
how you mean?
<oprypin>
> for crystal-clear project name, crystal generates the module Crystal::Clear
<oprypin>
just not a behavior i would expect, regardless of the actual name
<Papierkorb>
foo-bar is Foo::Bar, foo_bar is FooBar
<oprypin>
Groogy, i think you're just not supposed to put crystal- prefix even in project name, not just the namespace
<Groogy>
should I go with contracts.cr instead of crystal-clear?
<Papierkorb>
Groogy: That at least better describes what it is
<oprypin>
i don't know
<Groogy>
names I came up with was crystal-clear, contracts.cr, contractium
<Papierkorb>
is the technology, a pattern, an external service, or similar, the origin of the word `crystal` in your project name, or is it referring to the language?
<Groogy>
well just found it funny to be in the name as it is for crystal + "it is supposed to make things clearer" on what stuff do
<oprypin>
Papierkorb, "crystal clear" is a phrase you say, you know
<Groogy>
^
<Papierkorb>
oprypin: I know.
<oprypin>
it's a decent name, you're just running into hurdles because there's no precedent naming things as crystal-something
<oprypin>
people would name the repository like that, i like it, but in shard.yml you dont have crystal-
<Groogy>
I'll jsut go with contracts.cr
<Groogy>
there are a few projects actually called crystal-* though I think being clear in the name is worth more than some small pun :P
<oprypin>
puns are the most important
<Papierkorb>
Half my public projects have pun names, or reference names .. and all of my private ones lul
<Groogy>
fack it I'll go with crystal clear xD I like that name
<Groogy>
will see if it causes problems
<FromGitter>
<bararchy> How can I generate all hex code from "\x00" to "\xff" "\x99" ?
<Papierkorb>
What do you mean? Do you want iterate over 0..255, or do you want to iterate through the ASCII table?
<FromGitter>
<bararchy> It's not all ASCII so no, I guess , is there a way to go from (0.255) to "\x**" ?
<Papierkorb>
Do you mean the first 256 codepoints of unicode?
<oprypin>
bararchy, what are you actually trying to do?
<crystal-gh>
[crystal] MakeNowJust opened pull request #4690: Format: fix to place only a newline between call-comment-newline and def (master...fix/crystal-format/4672-double-newlines-before-def) https://git.io/vQiYa
<oprypin>
bararchy, strings cannot hold arbitrary bytes. here's what's actually happening when you reach codepoints after 128 https://carc.in/#/r/2bqd (scroll to bottom)
<oprypin>
to work with bytes, you, well... work with `Bytes`
<FromGitter>
<codenoid> and, why you wrote the crystal syntax inside {% %} ?
<FromGitter>
<codenoid> can i write that in anywhere place inside my cr file ?
<oprypin>
codenoid, which part are you referring to? please don't be alarmed by the things you see on carc.in from the IRC bot
<oprypin>
this is boilerplate to print the last expression. basically turns `{"я😍".size, "я😍".bytesize}` into `puts({"я😍".size, "я😍".bytesize}.inspect)` but in a really complicated way
<oprypin>
you would get that message without running the program. it's a compile-time `puts`
<FromGitter>
<codenoid> and btw, i still confused about @string @@string,
<Groogy>
is there a method in hash that let's me ensure that I get either object in the hash or a newly constructed object?
<Papierkorb>
Groogy: You're looking for the default-value feature of Hash
<Groogy>
working in constants so not sure if I can use that?
<Groogy>
macros*
<Groogy>
meh my macro will have to be extra ugly Iguess
<oprypin>
Groogy, well one way i know is `(hsh[key] ||= [] of String) << "asdf"`
<Groogy>
hmm
therubi has joined #crystal-lang
<therubi>
cool
sagax has joined #crystal-lang
<Groogy>
huh this is kind of cool, this implementation is going to be faster I think than my C++ variant. I.e more is done at compile time in comparison
therubi has quit [Read error: Connection reset by peer]
<Groogy>
alright finally, the base is done :) time to write readme and examples
jihantoro has joined #crystal-lang
<Groogy>
how do I check for th flag if release is set?
<oprypin>
Groogy, {% if flag?(:release) %}
<Groogy>
thanks
<Groogy>
do the macro have any way to check if a constant has been defined?
jihantoro has quit [Read error: Connection reset by peer]
<oprypin>
maaaaybe some really hacky way, i dont know
<FromGitter>
<bararchy> @sdogruyol we are going to integrate cryload into our test env :)
<Groogy>
are specs always run in release mode?
<FromGitter>
<sdogruyol> @bararchy that's great to hear
<FromGitter>
<sdogruyol> Is there anything that I can help you with
<oprypin>
Groogy, i dont think so
<oprypin>
if ever
<Groogy>
hmm because if I removed a part of my code with a flag?(:release) then the spec couldn't run anymore
<Groogy>
because of undefined constant
rohitpaulk has joined #crystal-lang
<oprypin>
Groogy, how about you try it with {% if true %} instead
<Groogy>
nah it works as expected
<Groogy>
if I do run it with --release
<Groogy>
the specs fails
<Groogy>
(since the code it is validating is not run anymore)
<Groogy>
so it just seems like the compiler can know "Hey this reference to this constant won't exist in release, so here's a compile error"
<Groogy>
which is kind of cool
jihantoro has joined #crystal-lang
jihantoro has quit [Client Quit]
<Groogy>
now I just need to do the boring part of writing usage examples
<FromGitter>
<bararchy> @sdogruyol Maybe I'll PR you for some minor changes if I see something, else, it's perfect the way it is ;)
<FromGitter>
<sdogruyol> awesome! :)
<FromGitter>
<sdogruyol> thanks @bararchy
<FromGitter>
<picatz> Does anyone know how to check if a socket ( raw ) connection has succeeded or failed?
<FromGitter>
<bararchy> NP, thank you for written it
<oprypin>
picatz, when you're dealing with sockets and what to check whether something has failed, the answer often is it's impossible
<FromGitter>
<picatz> Not sure if that's even what I'm looking for exactly: but, essentially I'm looking to write a port scanner in crystal; and I'm having an interesting time of figuring out how to check if a socket connection succeeded. 😄
<oprypin>
want*
<oprypin>
picatz, there are so many pitfalls when doing a port scanner, probably dont wanna get into that :|
<oprypin>
but yeah, if you try a connection and you get a "connection refused", isn't it supposed to raise an exception?
<FromGitter>
<picatz> Well, the thing is, I do want to get into it. 😸
<FromGitter>
<picatz> I'm not seeming to get a raised exception for what I'd assume would be a failed connection ( closed port ).
<oprypin>
what will often happen is for "additional security" connections will succeed and hang indefinitely
<oprypin>
are you trying this on localhost or perhaps on your internet router?
<FromGitter>
<picatz> Ok, interesting. I wasn't using a TCPSocket; and I was actually just initializing a socket like : `s = Socket.new(family, type, protocol, false)`
<FromGitter>
<picatz> Then I did something like this:`addr = Socket::IPAddress.new("ipaddresshere", port)`
<FromGitter>
<picatz> and then finally `s.connect addr`
<FromGitter>
<picatz> '\( ' o ')/' Do I need to use TCPSocket?
<oprypin>
no idea, basically thats all i know
<FromGitter>
<picatz> gotch'a. In ruby, I don't seem to need to specify a TCP socket type, at least from what I can tell. I'm not much of an expert on how that stuff works under the hood. 😅
<FromGitter>
<picatz> TCPSocket does seem to get me where I want to go though.
<oprypin>
except for the part where it doesnt scan UDP ports
<FromGitter>
<picatz> So I'd need to have a separate TCP scan and UDP scan.
<FromGitter>
<picatz> I wonder if a port scanner like nmap does TCP + UDP out of the box.
<FromGitter>
<picatz> If I'm not mistaken ( too lazy to man page ) there's an option for something like that.
<FromGitter>
<picatz> OH
<FromGitter>
<picatz> OK
<FromGitter>
<picatz> I read some documentation and figured something out I think.
<oprypin>
can i clarify that somehow so people don't jump to the same conclusion?
<FromGitter>
<picatz> 😎 Nice
<Groogy>
yeah but for me to get it to work on windows with GLFW what I did was setup a windows x server
<Groogy>
which then the application could connect with
<RX14>
Groogy, SFML takes care of it ebcause it's built for windows
<Groogy>
I know but so was GLFW
<RX14>
well clearly not properly
<Groogy>
or well right I built GLFW in ubuntu for windows
<RX14>
yeah well then
<oprypin>
well that's not Windows then
<FromGitter>
<mverzilli> great article! "You can try out other examples just as well, though not all of them will work." => Is this because the examples themselves are broken or is it because they use some std features that we currently won't work on Windows?
<oprypin>
mverzilli, one example happens to use libyaml and i guess nobody has tried it on windows yet, and another uses some math function that's not on windows
<RX14>
"Install Crystal's dependencies" i'd clarify to build dependencies
<RX14>
oprypin, also would be nice to center the bash/cmd text in the center of the page not the center of the element but thats just a blog css thing
<RX14>
like div.code .name
<FromGitter>
<picatz> It's seems like I can't iterate over a `Range` and `spawn` for my port scanner without first turning the `Range` into an `Array` with `.to_a`.
<oprypin>
no-debug thing seems to be required. must be something txe messed with
<FromGitter>
<bew> pwned, the brackets are not properly balanced (too much `]` ), please try again
<oprypin>
or not
<FromGitter>
<bew> ^^
<pwned>
I'm sorry, kid got the keyboard
<pwned>
he's 2 year old and still can't code
Groogy has joined #crystal-lang
<pwned>
although he can guide a turtle manually
<Groogy>
exit
<Groogy>
ops
Groogy has quit [Quit: WeeChat 1.9]
rohitpaulk has quit [Remote host closed the connection]
<crystal-gh>
[crystal] bew opened pull request #4691: Do not exit `crystal init` when directory is the current directory (master...tool-init-allow-in-current-dir) https://git.io/vQi21
sp4rrow has joined #crystal-lang
<FromGitter>
<jsilverMDX> pwned: cute lol
<crystal-gh>
[crystal] bew opened pull request #4692: kernel: Refactor after_fork_child_callbacks, remove unnecessary nils (master...refactor-kernel-after-fork-callbacks) https://git.io/vQiwU
<Papierkorb>
Groogy: You don't need to do that. The way most serializers do it is to have an Object#to_stuff for the generic implementation, and then have a SpecialClass#to_stuff if needed, like for Int or Bool
<Papierkorb>
Groogy: See JSON, YAML from the stdlib, my Cannon stuff does it like this too
<Groogy>
I know but then that means my SpecialClass#to_stuff will be inside SpecialClass
<Groogy>
I like to have a SerializerClassForSpecialClass instead
<Groogy>
(not that long name though)
<Groogy>
and in a generic way so the compiler solves the linkage for me
<Groogy>
i.e idea is "the game logic shouldn't understand what serialization is", because that's a different subsystem
<Papierkorb>
The logic class should have no serialization at all, it's logic code, not data code
<Papierkorb>
That's where I make the split, so I don't see much of an issue
<Groogy>
I agree, but as far as I understand, that would put the serialization logic in the class that owns the data we want to serialize?
<Papierkorb>
It's OOP. You ask that object to give you a different representation of it. And as long the split is done correctly, there's not much real code in it, so if it even needs special logic for de/serialization, it's not much. Serializer(T) for that sounds like a mess in no time
<Papierkorb>
If you don't want to modify Object (Which I can understand), put it into a Base class of all your data classes (if you have that), or use a Module and include that. That way, you can easily modify the logic if needed.
<Groogy>
yeah I'll go with that if this thread I am running with shows to not pay off
<hightower2>
Am I seeing it right that there is no way to retrieve #step, once a #step(N) is defined? E.g. if I have v= (1..10).step(3), there does not appear to be a way to detect in 'v' that step is 3
<crystal-gh>
[crystal] mverzilli pushed 1 new commit to master: https://git.io/vQiDm
<crystal-gh>
crystal/master b3c8f87 TSUYUSATO Kitsune: Fix a typo of the context name of parsing asm options
<FromGitter>
<bew> By defining a setter with multiple arguments, I can call it with: `Mod.coords = *{1, 2, 3, 4}` but it crashes on `Mod.coords = **{x: 1, y: 2, width: 3, height: 4}` too bad :/ it would be so cool to have/read setters like this WDYT? https://carc.in/#/r/2bsr
<oprypin>
bew, this is not a good idea at all.
<FromGitter>
<bew> why not?
<Papierkorb>
bew, 1) crashes the compiler? Please file an issue about it! 2) Please no, that's hard to use, and hard to read
<oprypin>
bew, please use `set_coords`.
<FromGitter>
<bew> no the compiler doesn't crash, just `unexpected token **`
<oprypin>
any hacks you've been able to do to make the compiler accept multiple arguments for a method ending with `=` are just hacks
<Papierkorb>
bew, if a property consists of multiple data values, then you were probably looking to create a struct or class to hold these values
<FromGitter>
<bew> yeah I know, was trying to see if I could get ride of that and still have a minimal code without `set_*` or `get_*` stuff
<Papierkorb>
why would you get rid of that?
<oprypin>
your code is literally longer than if you had `set_*`
<Papierkorb>
A `Geometry` (or whatever name) struct sounds perfectly reasonable
<oprypin>
just dont call it `AABB`
<FromGitter>
<bew> oprypin true, but I wanted to not use `set_*`, to keep the code crystal-ish (in a certain way)
<FromGitter>
<bew> `Geometry` is a good name, thx :)
<oprypin>
you cannot call something crystal-ish if to do it you need to trick the compiler.
<FromGitter>
<bew> ahah, by crystal-ish I mean without using `get_` or `set_` terminology, and directly use `Mod.value` & `Mod.value =`
hightower2 has quit [Read error: Connection reset by peer]
<oprypin>
i get the concept
<crystal-gh>
[crystal] RX14 opened pull request #4696: improved error message in raise_not_initialized_in_all_initialize (master...feature/better_not_initialized_message) https://git.io/vQiD9
<FromGitter>
<bew> Using geometry is quite long, but it'll do: `builder.coords = XCB::Geometry.new 20, 20, 300, 150`
<Papierkorb>
Doesn't XCB even call it Geometry too?
<FromGitter>
<bew> no, its plain x, y, width, height
<oprypin>
`set_coords` still seems best to me in this context
<hightower2>
If I define def compare( a : Type1, b : Type2), and the comparison is such that compare(a,b)==compare(b,a), is there a way to make this be handled by the shown compare() function without overloading it with types (Type2, Type1)? And if not, am I better off basically just copying the code, or calling compare(b,a) from it?
<FromGitter>
<bew> Is there a way to do something like this? https://carc.in/#/r/2bsw (iterate from a macro on a lib-struct fields)
<Papierkorb>
hightower2: def'ine your compare methods, and as last method, define a compare method taking a, b (without a type there), and have that one call `compare(b, a)`. This alone can lead to infinite recursion though.
<FromGitter>
<bew> it's a function without mangling and clear types
<oprypin>
oh.
<oprypin>
well the syntax is not such a big deal
<oprypin>
`lib` can even stay, but the only thing it would do is make this distinction between declaration and definition, otherwise a normal namespace
<oprypin>
my problem with this is you need to duplicate structs everywhere
<FromGitter>
<bew> well, as lib-struct cannot be re-open'ed, my macro for should work, and the duplication would almost not exists
<oprypin>
sure, except whenever you deal with a lib-struct, you run into all kinds of limitations
<oprypin>
like this one - macro methods just werent implemented for them
<FromGitter>
<bew> hmmm don't know what to do now that I know all of this...
<oprypin>
bew, the easy way out is just forget about iterating on lib struct fields. can still do a macro but make a list to iterate over manually
<FromGitter>
<bew> good idea for now, thanks!
<oprypin>
or, if during development you notice that you wish to reuse more and more stuff directly from the lib, remember my words, and check https://github.com/oprypin/crystal-chipmunk where i went nuts with that