<FromGitter>
<anamba> Interesting... it's like, a server-side client-side framework? (I'm assuming there's nothing particularly Kotlin-specific about this concept.) http://kweb.io
<FromGitter>
<bhargavrpatel> https://crystal-lang.org/docs/guides/concurrency.html ⏎ This page says that if we introduce a sleep for 1 second and spawn a Fiber to print hello, it will do so for 1 second and exit. However, when I copy paste said snippet, I just see a spam of Hello message until I send a KeyboardInterrupt.
<FromGitter>
<bhargavrpatel> > This program will now print "Hello!" for one second and then exit. ⏎ Wondering if this verbiage is just being misread by myself
<FromGitter>
<anamba> @bhargavrpatel I wonder if your terminal might just be slow
<FromGitter>
<anamba> Crystal can output stuff pretty fast
<FromGitter>
<bhargavrpatel> Yeah that might be it, but wouldn't it only do that for 1 second?
<FromGitter>
<greenbigfrog> it should exit after one second
<FromGitter>
<greenbigfrog> you sure you got the exact same code?
<FromGitter>
<bhargavrpatel> It exists after like 10 seconds.
<FromGitter>
<bhargavrpatel> But I am starting to put together what @anamba might be saying. It likely is only executing for 1s then existing but the amount of output just renders slowly.
<FromGitter>
<bhargavrpatel> Actually I do not think that is the case
<FromGitter>
<bhargavrpatel> My vagrant CPU is at 100% and the uptime of the process is way north of 30s
<FromGitter>
<Blacksmoke16> remove the puts and just see if it runs for 1 sec
<FromGitter>
<Blacksmoke16> then it wouldnt be bound by IO
<FromGitter>
<bhargavrpatel> Same thing
<FromGitter>
<bhargavrpatel> Here is a little video https://streamable.com/xujuu; I tried piping to less and redirecting to file as well. You can see on HTOP that the process is running for minutes. Also shown using `ps aux`.
<FromGitter>
<girng> what's your cpu `cat /proc/cpuinfo`?
<FromGitter>
<bhargavrpatel> The only thing I can do to get it to quit is to amend the code and put an explicit break.
<FromGitter>
<bhargavrpatel> ```code paste, see link``` ⏎ ⏎ Interesting, I wanted to see how many seconds I see there so I changed to do time. As soon as I added a pipe, it started executing indefinitely again. [https://gitter.im/crystal-lang/crystal?at=5c0dce81f992693c7a4c2c56]
<FromGitter>
<girng> @bhargavrpatel same cpu as you, but non-K. OS: Ubuntu 16.04.2 LTS, on WSL
<FromGitter>
<girng> @bhargavrpatel so how did you ever find a fix?
Raimondi has joined #crystal-lang
<FromGitter>
<girng> i just tested it on debian 8.5 64-bit minimal ( my vps ), stops after 1 second
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
<FromGitter>
<girng> https://play.crystal-lang.org/#/r/5qzh/edit im trying to recursively iterate over all objects in json, but am not sure how to check if JSON::Any is a hash
<FromGitter>
<girng> am gonna try Serializable instead and see if i can add my own .each method
<FromGitter>
<Blacksmoke16> what you trying to do
<FromGitter>
<girng> i just want to statically type `({"1":{},"2":{"modifications":{"increased_hp_percent":5},"value":5},"3":{"value":10},"4":{"modifications":{"increased_hp_percent":15,"increased_strength":20}}} ` this json. and be able to loop over it. but if i use the serializable stuff. i can't do `.as_h.each`
<FromGitter>
<Blacksmoke16> why not use a struct vs a hahs...
<FromGitter>
<Blacksmoke16> then just do `from_json`
<FromGitter>
<girng> but if i simply do JSON.parse, then it does it all for me (which is nice), but some some value types are not correct. for example the "value" keys are set to Int64, but i want them to be parsed as a Float32
<FromGitter>
<girng> yeah i tried that, but then my hash looks like this
<FromGitter>
<Blacksmoke16> why use a hash in the first place?
<FromGitter>
<girng> so i can iterate over them
<FromGitter>
<girng> if i do the struct, and use serializable, i can't iterate the json
<FromGitter>
<girng> or, i could but am not sure how
<FromGitter>
<Blacksmoke16> but why would you need to iterate over the json? just iterate over the structs?
<FromGitter>
<girng> what you mean "iterate over the structs"?
<FromGitter>
<Blacksmoke16> assuming you'd be parsing an array of json?
<FromGitter>
<girng> if i do from_json, the struct holds all the json info
<FromGitter>
<girng> 1 second let me give you an example in code
<FromGitter>
<Blacksmoke16> have a like parent struct with a `modifications` array with an array of `Modification` struct?
notdaniel has joined #crystal-lang
<FromGitter>
<anamba> today's AoC was especially fun. the solution was not as immediately obvious as some of the other ones (many of them consist of simply picking the most appropriate data structure and implementing it).
<FromGitter>
<Blacksmoke16> what about something like that?
<FromGitter>
<girng> yah the entire reason why i wanted to do serializable was to stay away from json.parse
<FromGitter>
<girng> but i mean it works...
<FromGitter>
<Blacksmoke16> yea, its a catch 22 since you have to iterate over it to build out the property structs, but cant do that unless you json parse it
<FromGitter>
<girng> it's msotly just so you can use as_h and loop i guess
<FromGitter>
<Blacksmoke16> yea
<FromGitter>
<Blacksmoke16> but if each of your numbers does mean something you could i guess have a separate struct for each of those (using inheritance most likely as well) and then on your main struct have each property use that numbered key if you know what i mean
<FromGitter>
<Blacksmoke16> but depends on what you trying to do with this i guess
<FromGitter>
<girng> 👍
<FromGitter>
<DanilaFe> what the hell is today's AoC problem
<FromGitter>
<DanilaFe> My own, that is :) but I do appreciate it
<FromGitter>
<nagash> @DanilaFe Sure, just sharing :)
<FromGitter>
<DanilaFe> Interesting, I got my simulation a little differently
<FromGitter>
<DanilaFe> you seem to check if the points touch, but I just found the maximum distance between two points, then found the speed at which it decreases, and then simply took one step to where it's reduced
<FromGitter>
<DanilaFe> O(1) step
<FromGitter>
<DanilaFe> then printed 10 frames, 5 before, and 5 after
<FromGitter>
<girng> @nagash damn, dat code. noiceee!!!
<FromGitter>
<anamba> interesting, i considered an approach like that at first, but then decided to go with my hunch that the solution would be the smallest configuration. once it started diverging again, i went back one step from there and printed it
<FromGitter>
<anamba> it was readable so i went with it
<FromGitter>
<girng> yah why i posted here cuz i kept getting errror lol
<FromGitter>
<DanilaFe> yeah, one line if doesn't work as well as you'd think: the variable you declare in the one-line if isn't available in the left hand side
<FromGitter>
<anamba> yeah, i would avoid the one line style
<FromGitter>
<anamba> for a break or next i guess it works
<FromGitter>
<DanilaFe> The way idiomatic crystal is written, you get a lot of indents. I think it's nice to be able to avoid indents in places where one is not really necessary
<FromGitter>
<anamba> ok, so i forgot what my point was. haha. it is good for guards.
<FromGitter>
<DanilaFe> what kind of game are you making, @Girng?
<FromGitter>
<girng> top down arpg inspired by diablo and path of exile
<FromGitter>
<DanilaFe> nice!
<FromGitter>
<DanilaFe> How's crystal for you so far?
<FromGitter>
<DanilaFe> I've only used it on web projects and a parser generator, and it's great for those
<FromGitter>
<girng> developed by crystal's gitter channel XD
<FromGitter>
<girng> i like it haha. i use it for the main master server and the tick rate server
<FromGitter>
<DanilaFe> you have a tick rate server that's separate? is that common?
<FromGitter>
<mach_potpurri_twitter> Haha ok, im at my wits end here
<FromGitter>
<mach_potpurri_twitter> I'm trying to get this blog up and running, but crystal seems to not want to write files
<FromGitter>
<girng> am not sure if common but i'm doing it so i can ahve servers in diff locations so players won't lag as much
<FromGitter>
<girng> @DanilaFe you have a parser generator ?
<FromGitter>
<DanilaFe> I made one, yes. It's not yacc-tier, though
<FromGitter>
<girng> interesting
<FromGitter>
<DanilaFe> I had to get something out of my Theory of Computation class :D
<FromGitter>
<girng> @mach_potpurri_twitter is there an error emitted?
<FromGitter>
<anamba> maybe i have AoC on the brain, but this thing i'm about to do looks a lot like an AoC puzzle https://publicsuffix.org/list/
<FromGitter>
<mach_potpurri_twitter> Yes, i get the typical "No such file or directory", which is right, because crystal is supposed to make the public file before it reads it
<FromGitter>
<DanilaFe> huh, it does kind of
<FromGitter>
<girng> hmm maybe it's not "making it public" correctly?
<FromGitter>
<mach_potpurri_twitter> yeah for some reason when I compile the app it doesnt do any File or folder creation. It's supposed to check if
<FromGitter>
<mach_potpurri_twitter> the public folder exists, and remove and remake it
<FromGitter>
<girng> did you chmod the executable to give it proper stuff to write it?
<FromGitter>
<mach_potpurri_twitter> Ahh i did not
<FromGitter>
<girng> am not sure if that will fix but could try :/
<FromGitter>
<mach_potpurri_twitter> it doesn't
<FromGitter>
<mach_potpurri_twitter> can i post a pastebin of the lines?
<FromGitter>
<mach_potpurri_twitter> ok i fixed it
<FromGitter>
<girng> haha awesome what was it
<FromGitter>
<mach_potpurri_twitter> it just needed a case for if the file didnt exists, im dumb sometimes lol
<FromGitter>
<girng> like `if !File.exists?` then create the file/directory?
<FromGitter>
<mach_potpurri_twitter> yeah just like that
<FromGitter>
<girng> oh hah good job
<FromGitter>
<girng> sory i wasn't much help lol
<FromGitter>
<mach_potpurri_twitter> no problem, im thankful for any help, im now one step closer, i just now have to figure out how im going to do multiple posts
<FromGitter>
<girng> what ya making? (just curious) to me looks like a blog/flat file forum?
<FromGitter>
<mach_potpurri_twitter> yeah, it's supposed to be a simple blog for my art, i've never done web dev before so everything is new to me
<FromGitter>
<kingsleyh> @girng have you used GoDot before - looks like you can write a Crystal binding for it
<FromGitter>
<girng> yeah, it's great. if you mean me specifically, i'm not smart enough haha. plus, not sure if it's even needed cause gdscript is greatly interwined already
Renich has quit [Quit: Renich]
DTZUZO has joined #crystal-lang
<FromGitter>
<girng> i posted on stackoverflow. ne1 got time plz take a look
* FromGitter
* mpcjanssen still impressed by the performance.
<jokke>
asterite: yeah i had an epiphany when i stumbled across deque :P
<FromGitter>
<mpcjanssen> With some care you don't even need to track the current marble
<FromGitter>
<anamba> Deque is still not the most natural data structure for that problem :)
<FromGitter>
<asterite> anamba: you mean a linked list or circular buffer would be better? I originally coded it that way and it turns out to be slower than deque for that problem :-)
<FromGitter>
<anamba> Really? Ha. I used a double linked list and didn't have any performance issues
<FromGitter>
<anamba> Doubly
<FromGitter>
<mpcjanssen> A deque is a circular structure with rotate!
<jokke>
yeah
<jokke>
current is simply the first element
<FromGitter>
<mpcjanssen> I used the last element.
<jokke>
yeah it's just a matter of pop vs shift i guess
<FromGitter>
<mpcjanssen> But both work
<jokke>
asterite: that's interesting. i would've thought deque is implemented as a doubly linked list
<FromGitter>
<anamba> Also Crystal API docs say Deque is implemented as an array which doesn't sound like what you want for something that is going to have a lot of random insertions. But hey, if it works, it works.
<FromGitter>
<mpcjanssen> @anamba a deque is backed by a circular data structure and the rotate! Method is enough to fake it for day9
<FromGitter>
<anamba> Usually those don't do too well with growing datasets
<FromGitter>
<bew> cool I have your private key now 😇
<FromGitter>
<kingsleyh> ok - don't steal all by bitcoin ;)
<FromGitter>
<kingsleyh> it's for my bitcoin account
<FromGitter>
<kingsleyh> hahahahah!
<FromGitter>
<bew> ah perfect, thank you
<FromGitter>
<kingsleyh> so the code looks like it should work - but it doesn't :(
<FromGitter>
<kingsleyh> I don't know C very well and the OpenSSL API is all over the place - so it's possible I'm using the OpenSSL API in the wrong way
<FromGitter>
<bew> hmm are you following a tutorial?
<FromGitter>
<kingsleyh> but It does seem logical to me anyway that EC_POINT_hex2point should give me a point from a hex string
<FromGitter>
<kingsleyh> no not following a tutorial
<FromGitter>
<bew> hm maybe try with upper case hexstring?
<FromGitter>
<kingsleyh> they get the group from the key: `group = EC_KEY_get0_group(key);`
<FromGitter>
<bew> did you check that the point new and group new doesn't return a null pointer?
<FromGitter>
<kingsleyh> I've tried by getting the group from the key - but same issue still
<FromGitter>
<kingsleyh> yeah they all return a Pointer
<FromGitter>
<kingsleyh> how do you pass a NULL into a function?
<FromGitter>
<kingsleyh> ooooh!!
<FromGitter>
<kingsleyh> success!!
<FromGitter>
<kingsleyh> thanks for the help @bew
<FromGitter>
<kingsleyh> I missed off the final arg on this: ` fun EC_POINT_hex2point(x0 : EcGroup, x1 : LibC::Char*, x2 : EcPoint, x3: Void*) : EcPoint`
<FromGitter>
<kingsleyh> and now putting nil as the last arg makes it work
<FromGitter>
<girng> what is "subtyping" in crystal?
<FromGitter>
<proyb6> Parent class is the super type, child is the subtype
<FromGitter>
<girng> hmm that seems normal to me. i wonder why that guy thinks its bad
<mps>
trying to build static crystal I've got a lot of " undefined reference to `llvm::"
marmotini_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
<RX14>
mps, you need llvm-static
<mps>
RX14: in meantime all is finished ok
<RX14>
nice
<mps>
but, yes, llvm-static was there
<mps>
I will prepare patches and APKBUILD and post it, I hope today
<RX14>
what was the problem?
<mps>
I messed a little build system on lxc container, mounted with some wrong paths
<RX14>
oops
<mps>
after fixing mount points and restarting lxc, build was ok
<mps>
have a hope that 0.27 will be accepted for next stable alpine, which should be released in about two weeks
<RX14>
nice
<mps>
btw, thanks for nice language. is it your idea?
<RX14>
no lol
<RX14>
mostly asterite's and those at manas
<mps>
anyway, very nice language. I 'fall in love' at first sight. till then I learned go and wrote some service in it, but now I'm converting them to crystal
<mps>
I'm only missing graceful restart for web (REST) services, but hope that will be solved soon
<FromGitter>
<girng> welcome @mps
<mps>
girng: thanks
<jokke>
can someone confirm: running a statically linked crystal binary which runs a HTTP::Server in a docker scratch image cannot be killed with ctrl+c (also not by using sudo killall name_of_binary)
<FromGitter>
<greenbigfrog> yep, any kind of HTTP::Server or WS. (Didn't bother looking into whether this was intended or anything)
<FromGitter>
<drum445> i3 only in tab mode :)
<RX14>
mps, i'm not aware of any issues with graceful restart currently
<RX14>
if you could try again on 0.27.0 and report back whats broken that'd be fantastic
<mps>
RX14: I will try but not now, I have some other things to do in next days
<mps>
usually at the of the year I'm short in time
<mps>
s/at the/at the end/
<FromGitter>
<bcardiff> Hi all! Ready to sneak peek the discourse forum at https://forum.crystal-lang.org ? ⏎ ⏎ We haven't broadcast the news yet. Give us a couple of hours :-), but feel free to sign up and start using it.
<FromGitter>
<girng> registering now
<FromGitter>
<j8r> I figured out we can more or less mimic sparse arrays with hash, if we put the keys are `Int`
<FromGitter>
<mpcjanssen> day 10 was very nice
akaiiro has quit [Ping timeout: 245 seconds]
<FromGitter>
<yxhuvud> @j8r That works, unless you expect to have *performant* sparse arrays.
akaiiro has joined #crystal-lang
<FromGitter>
<straight-shoota> Nice, @bcardiff
Raimondi has quit [Ping timeout: 240 seconds]
<jokke>
jhass: any idea why this is happening? (HTTP::Server in scratch docker image not killable)
<FromGitter>
<kinxer> @bcardiff I already have a feature suggestion. Where do I direct that?
<FromGitter>
<bcardiff> @kinxer related to the forum? There is a Meta category for that.
<Jenz>
Well, then I'll join in: thanks for the forum guys! :D
rohitpaulk has quit [Ping timeout: 252 seconds]
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter>
<girng> after Jonne Haß and @Blacksmoke16's help. gonna revamp a lot of my json data. disgonnabegood.jpg
<FromGitter>
<Blacksmoke16> 🚀
<FromGitter>
<girng> btw @Blacksmoke16 you really helped last night i just was thrown off by the json.parse again sorry hahahah
<FromGitter>
<Blacksmoke16> np, having a good data structure would be quite helpful in long run
<FromGitter>
<elorest> @Blacksmoke16 I believe you mentioned yesterday that I could add annotations to a method? How would I access or loop over those? I rewrote a lot of my code using Annotations instead of CONSTANTS. Unfortunately I'm creating a bunch of i_vars which aren't necessary outside of the macros.
marmotini_ has joined #crystal-lang
<FromGitter>
<Blacksmoke16> you *can* but im not sure what you could use them for, other than like getting a list of methods with a specific annotation
<FromGitter>
<Blacksmoke16> `@type.methods`
<FromGitter>
<Blacksmoke16> same way the instance_vars one works
<FromGitter>
<Blacksmoke16> would be helpful if you could get the *current* annotation off the method you're currently in
non-aristotelian has joined #crystal-lang
rohitpaulk has joined #crystal-lang
marmotini_ has quit [Ping timeout: 240 seconds]
gangstacat has quit [Ping timeout: 252 seconds]
rohitpaulk has quit [Ping timeout: 272 seconds]
gangstacat has joined #crystal-lang
<FromGitter>
<elorest> Yeah that would be more helpful. However since in need to create methods but not instance variables at least I'm not creating something just to store annotations on. I think that will work. Thanks.
<FromGitter>
<bew> like `@def.annotation(Foo)` ? you can already do it :D
<literal>
when I define an object that consists only of a JSON.mapping() call, am I not supposed to be able to instantiage the class with #new (in addition to #from_json) ?
<FromGitter>
<Blacksmoke16> could get a list of all defined methods with the route annotation, to build out route list, also to do some pre processing on each request before activating the route, for example auto resolve the user param to a user obj from db or something
<FromGitter>
<Blacksmoke16> would have to define an initialize as well iirc
<FromGitter>
<bew> literal: the json mapping macro does not generate a default initializer, so yes as @Blacksmoke16 says you need to make one
<FromGitter>
<bew> Using the JSON::Serializer variant may be easier, depends on your mapping (eg if you have defaults to your ivars)
JuanMiguel has joined #crystal-lang
<FromGitter>
<bew> Nice idea btw (web framework) @Blacksmoke16
<literal>
alright
JuanMiguel has quit [Client Quit]
<FromGitter>
<Blacksmoke16> yea, like we need more of those @bew :P
<FromGitter>
<elorest> @Blacksmoke16 why would that syntax be more useful than current methods/macro's in kemal/amber/lucky? ⏎ ⏎ They seem less pleasant to read/write so I'm assuming there must be some sort of performance or compiler time gain?
<FromGitter>
<Blacksmoke16> im not saying it would, just that it would be pretty slick
<FromGitter>
<Blacksmoke16> as like a "see if i can be done" type of thing
<FromGitter>
<elorest> Got it thanks. I only started playing with annotations yesterday. Mostly because I was told that dynamic constants in macro's would be removed from the language and that annotations are better. So far I've gotten my code to work this way but it seems a bit more convoluted. Is there anything I could read about why this pattern is better?
<FromGitter>
<elorest> Cool. Yeah I was under the impression from yesterday that it was the new hot thing that all macro's should be using for storing values. Like when rspec switched to expectations lol.
<FromGitter>
<Blacksmoke16> oops sorry yea, they still in early stages as well
<FromGitter>
<Blacksmoke16> that they would have some fancy features in future but dont exist yet
Jenz has quit [Ping timeout: 252 seconds]
<FromGitter>
<elorest> Ok that makes sense. Still good to play with and understand what good use cases would be.
<FromGitter>
<Blacksmoke16> im personally a big fan of them
<FromGitter>
<Blacksmoke16> but as you said, depends on use case of if they would be helpful or more trouble
<FromGitter>
<elorest> The main thing I need annotations or mutable constants for is to be able to tell how many times the macro has been called before... in the case of bitfields I need to know how many bits have been defined before. Is it maybe possible to do this without annotations or constants?
<FromGitter>
<bew> Wow it looks like way too much code for this feature ><
<FromGitter>
<elorest> I'd obviously prefer less, at one point it was less but wasn't able to handle fields that started half way through a byte and ended on the next byte or 2.
<FromGitter>
<elorest> `{{field.type}}.new(buffer)` is better. Thanks
akaiiro has joined #crystal-lang
<FromGitter>
<elorest> I'll consider refactoring the DSL after I finish this refactor. ⏎ ⏎ I already wrote the library with some of your suggestions on friday and it has all the functionality I need. https://github.com/elorest/bitfields ⏎ ⏎ I'm to refactoring it right now to parse data out of bits on the fly instead of on initialize. That works but I need to create setters and come up with a way to print out the string
<FromGitter>
<elorest> @bew if you have an idea how I could get rid of line 26-45 I'd be really happy.
<FromGitter>
<elorest> <oprypin> I can see how using the pattern from JSON.mapping could remove my need to store values and the DSL would look almost as nice.
<oprypin>
elorest, dont you want to obtain the data once and then just continue with a completely normal object?
<FromGitter>
<elorest> That's what I'm doing currently. (parsing the data on initialize and then generating new bytes from changed values in `to_slice`. It seemed like it might be cleaner to parse the fields out of the bits when they're called though rather than copying them all out into instance vars.
<FromGitter>
<elorest> @bew I was planning on caching a lot of that but first I was trying figure out how much of it I could remove entirely or replace with macros. ⏎ ⏎ My first approach already avoided those inefficiencies: https://github.com/elorest/bitfields/blob/master/src/bitfields.cr
<FromGitter>
<elorest> Thanks you for looking through it.
<FromGitter>
<bew> Oh ok 👍
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 244 seconds]
<FromGitter>
<omidathari> Hello
<FromGitter>
<omidathari> Hello ⏎ I need to print the binary value of an 8 bit negative number which should be the ⏎ 2s complement of its corresponding positive value. The following code simply puts ⏎ a negative sign on the binary representation of the positive value. ⏎ Can some suggest a way to do this correctly. ... [https://gitter.im/crystal-lang/crystal?at=5c0ef2d528907a3c7bfd151a]
<FromGitter>
<bhargavrpatel> > @bhargavrpatel so did you ever find a fix? ⏎ Nope. I went to bed 😁