RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | 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
<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> https://github.com/Blacksmoke16/CrSerializer/releases/tag/v0.5.0 version `0.5.0` is now released
<FromGitter> <bhargavrpatel> Yea i think something is not working. I have a video . ⏎ trusty 64 vagrant ⏎ 1 processor ⏎ 8 gb ram [https://gitter.im/crystal-lang/crystal?at=5c0dc90fe4787d16e3708d0b]
<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``` [https://gitter.im/crystal-lang/crystal?at=5c0dcaa828907a3c7bf57d80]
<FromGitter> <girng> hmm def not slow
<FromGitter> <girng> that's weird. prob rare edge caase with ubuntu trusty w/ vagrant
<FromGitter> <bhargavrpatel> Should I create an issue? Just toying around with Crystal at this stage, would not be able to resolve this just yet.
<FromGitter> <greenbigfrog> ```puts Time.now ⏎ sleep 1 ⏎ puts Time.now``` ⏎ ⏎ Does this work? [https://gitter.im/crystal-lang/crystal?at=5c0dcc058b656e2b04eccdf7]
<FromGitter> <girng> `This program will now print "Hello!" for one second and then exit` doesn't do that for me
<FromGitter> <girng> it prints indefinitely like your example
<FromGitter> <bhargavrpatel> Yeah I think thats a bug in the understanding of the document author
<FromGitter> <girng> i'm using ubuntu as well
<FromGitter> <bhargavrpatel> Yeah, I feel like there is some misunderstanding or the verbiage on the document should be adjusted a bit.
<FromGitter> <bhargavrpatel> @greenbigfrog Here is the output. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0dcc8626de6f0822ad1b97]
<FromGitter> <greenbigfrog> the code out of the docs works perfectly fine for me
<FromGitter> <bhargavrpatel> It quits after 1s?
<FromGitter> <greenbigfrog> a tad more because printing takes a tad longer, but in theory yes
<FromGitter> <Blacksmoke16> works for me too
<FromGitter> <bhargavrpatel> What are both of your hardware specs?
<FromGitter> <Blacksmoke16> `Linux 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux`
<FromGitter> <bhargavrpatel> Switched to a different terminal (Hyper.js) and its terminating sooner. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0dcd998336e22a7d0a6561]
<FromGitter> <bhargavrpatel> 1) 439 vs indefinately
<FromGitter> <greenbigfrog> `Linux thebar 4.19.4-arch1-1-ARCH #1 SMP PREEMPT Fri Nov 23 09:06:58 UTC 2018 x86_64 GNU/Linux`
<FromGitter> <greenbigfrog> for crystal run: ⏎ ⏎ ```real0m1.695s ⏎ user0m0.752s ⏎ sys0m0.891s ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5c0dce235e4095250340ae49]
<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> here (https://i.gyazo.com/586e9eee4a79d7c92330a4fbb5869309.gif) is what my console does lol
<FromGitter> <bhargavrpatel> RIP
<FromGitter> <girng> 😆
<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> <Blacksmoke16> https://crystal-lang.org/api/0.27.0/JSON/Any.html#as_h%3F%3AHash%28String%2CAny%29%3F-instance-method
<FromGitter> <girng> @Blacksmoke16 https://play.crystal-lang.org/#/r/5qzk, got it thanks!!
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
<FromGitter> <girng> jeez this is going well
<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> <girng> `Hash(String, Hash(String, String | Float32 | Hash(String, String | Float32)))`
<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> <girng> here @Blacksmoke16 https://play.crystal-lang.org/#/r/5r10 check comments
<FromGitter> <girng> how can i modify the value types in the serialize thing recursively (and deeply). if the key is inside another object
notdaniel has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> do the keys `3`, `4` have any significance?
<FromGitter> <girng> they will (once i finish my tree in game). they just are blank atm
<FromGitter> <Blacksmoke16> i guess i just dont follow the data structure, i would have done something like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0dfd6c3de4e816e239564a]
<FromGitter> <girng> i'm just exporting skill tree data from godot's `dictionary` json and trying to read it *statically* in crystal.
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> so dont really control the input data structure then
<FromGitter> <girng> basically but i mean i could do it that way i'd have to redo / modify some code in godot lol
<FromGitter> <girng> it's working so nice already i don't wanna fiddle with it
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <girng> but ya u are correct
<FromGitter> <girng> from what i understand, the `@increased_hp_percent : Float32?` will only work on the first object, not the nested ones, right?
<FromGitter> <girng> https://play.crystal-lang.org/#/r/5r17 i guess so hahahah
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5r19
<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> can anyone read this?
<FromGitter> <DanilaFe> I'm pretty sure this is an answer, but I'm getting timeouts trying to understand what it says
<FromGitter> <DanilaFe> Looks like PhFhhhF7, I've also tried P.hFhhhF7 an RhFhhhF7
<FromGitter> <DanilaFe> @anamba you seem to have already completed the problem, how can you read this??
<FromGitter> <girng> it's a candy cane, chair. something to do with christmas/holidays
<FromGitter> <DanilaFe> darn, it's upside down
Renich has quit [Remote host closed the connection]
Renich has joined #crystal-lang
Renich has quit [Remote host closed the connection]
<FromGitter> <anamba> @DanilaFe hehe yeah seems like you got the reducing part right, but the printing part was just a little off. 😂
<FromGitter> <DanilaFe> I didn't like this one, to be honest.
<FromGitter> <nagash> @DanilaFe This was my solution https://play.crystal-lang.org/#/r/5r1w
<FromGitter> <DanilaFe> I already have a solution
<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> <anamba> https://github.com/anamba/adventofcode2018/blob/master/day10/skymessage.cr if you want to see the code
<FromGitter> <DanilaFe> here's mine
<FromGitter> <anamba> somewhat more more brute force than @DanilaFe 's
<FromGitter> <DanilaFe> https://carc.in/#/r/5r20
<FromGitter> <DanilaFe> ah, named tuples
<FromGitter> <DanilaFe> a man of culture
Renich has joined #crystal-lang
<FromGitter> <anamba> heh... just trying to make things readable. since i put it on github and someone might actually look at it...
<FromGitter> <girng> is it possible to assign a local variable in 1 line, while that if line statement depends on 2 adjacent conditions??
<FromGitter> <DanilaFe> Could you elaborate, Girng?
<FromGitter> <DanilaFe> @anamba I push my solutions to my own git server, but I try keep them clean for myself. https://dev.danilafe.com/DanilaFe/AdventOfCode-2018
<FromGitter> <girng> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0e0e855e40952503422b54]
<FromGitter> <girng> i want to remove those 2 ifs and do it in one line if possible
<FromGitter> <anamba> yes you can condense all 3 ifs into one
<FromGitter> <girng> O_O
<FromGitter> <f1refly_gitlab> Really? I think the compiler would complain about the type check..
<FromGitter> <anamba> `if (modifications = skill_obj["modifications"]?) && modifications.is_a?(Hash)`
<FromGitter> <DanilaFe> https://carc.in/#/r/5r21
<FromGitter> <DanilaFe> something like that?
<FromGitter> <girng> OMG thx!!
<FromGitter> <girng> @anamba
<FromGitter> <girng> it worked
<FromGitter> <DanilaFe> you could do it without an &&
<FromGitter> <DanilaFe> because Nil responds to is_a?
<FromGitter> <girng> did not know we could do local variable in one if and then conditions... that's super awesome
<FromGitter> <anamba> ah, true. slightly less clear what's going on, but not so bad. i'll have to remember that one.
<FromGitter> <girng> i could change some other code hahahaha
<FromGitter> <anamba> just don't forget the () around the assignment
<FromGitter> <DanilaFe> https://carc.in/#/r/5r23
<FromGitter> <anamba> i've done that one before
<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> the suffix if
<FromGitter> <DanilaFe> it's neat in places like ⏎ ⏎ ```break if condition?``` [https://gitter.im/crystal-lang/crystal?at=5c0e0fb11e86c30823547a72]
<FromGitter> <DanilaFe> significantly easier to read
<FromGitter> <anamba> yeah. i guess i just mean for guards.
<FromGitter> <anamba> err, specifically type or nil guards.
<FromGitter> <girng> i'm not going back now, too late :D
<FromGitter> <DanilaFe> I still think it's pretty nice there, again: ⏎ ⏎ ```break unless value = hash["weird"]? ⏎ value.do_something # value is already non-nil here``` [https://gitter.im/crystal-lang/crystal?at=5c0e10155e40952503423354]
<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> <girng> i use it alot like this (https://i.gyazo.com/d9e6af87feed2837950c41bd9eea1152.png)
<FromGitter> <anamba> true
<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> https://pastebin.com/p69ST3zY
<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> <anamba> in case anyone else needs to parse a hostname and extract the public suffix (e.g. .com, .co.uk, 東京.jp, etc.), i extracted the code into a shard: https://github.com/anamba/public_suffix.cr (there are a LOT of suffixes, it turns out: https://publicsuffix.org/list/public_suffix_list.dat)
<FromGitter> <asterite> jokke: yes, finished day 9 and 10 (today was fun). A hint for day 9: you can't do it with an array
<FromGitter> <asterite> (well, you can, if you are willing to wait maybe a year or two)
ashirase has quit [Ping timeout: 268 seconds]
ashirase has joined #crystal-lang
<FromGitter> <mpcjanssen> jokke: as a point to aim for: `time ./day9 ⏎ Day 9-1: xxxxxxxxx ⏎ Day 9-2: xxxxxxxxx ⏎ ⏎ real 0m0.280s ... [https://gitter.im/crystal-lang/crystal?at=5c0e3c2f28907a3c7bf844ec]
* 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> A deque is circular?
<jokke> well kinda
<jokke> it has a rotate! method
<FromGitter> <anamba> I didn't bother timing mine since it was more or less instant
<jokke> yeah
<jokke> you can multiply by 10k :P
<jokke> or 100k! :)
<jokke> heh 10k is quite enough :D
<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> <girng> i'm trying to set values with certain keys to Float32 using JSON::Serializable. but i also want to be able to enumerator over the json like how we could with json.parse here (https://stackoverflow.com/questions/53702898/how-to-iterate-and-statically-type-values-using-jsonserializable) is my problem(s) explained
DTZUZO has quit [Ping timeout: 245 seconds]
<FromGitter> <kingsleyh> how do I convert a Pointer(String) to a Pointer(UInt8)
<FromGitter> <bew> Can I ask how you got a Pointer(String)
<FromGitter> <bew> ?
<FromGitter> <bew> @kingsleyh
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0e4f0c11bb5b250490d1aa]
<FromGitter> <kingsleyh> @bew I'm trying to set the public_key on my EC object
<FromGitter> <kingsleyh> I have the public key as a hexstring
<FromGitter> <kingsleyh> but `int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub);`
<FromGitter> <bew> Where is the string coming from? Why is it not String (which is already a reference)
<FromGitter> <kingsleyh> it wants a point
<FromGitter> <kingsleyh> so I'm trying to make an ec_point from the hex_public_key that I can pass to the `EC_KEY_set_public_key `
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0e4fd8178d7860a1b3b770]
<FromGitter> <kingsleyh> but here - it complains hex_public_key should be a pointer so...
<FromGitter> <kingsleyh> ` p LibSSL.EC_POINT_hex2point(eccgrp, pointerof(hex_public_key), ec_point)`
<FromGitter> <kingsleyh> results in the error:
<FromGitter> <kingsleyh> `argument 'x1' of 'LibSSL#EC_POINT_hex2point' must be Pointer(UInt8), not Pointer(String)`
<FromGitter> <bew> Whats the type of hex_public_key ?
<FromGitter> <kingsleyh> String
<FromGitter> <kingsleyh> it's passed in - as I already have the hex_public_key as a String
<FromGitter> <kingsleyh> from a previous key_pair generation which returns them as hex strings
<FromGitter> <bew> Weird the first try should work (no need for pointerof), try using hex_public_key.to_unsafe
<FromGitter> <kingsleyh> ` fun EC_POINT_hex2point(x0 : EcGroup, x1 : LibC::Char*, x2 : EcPoint) : EcPoint`
<FromGitter> <kingsleyh> ok will try to_unsafe
<FromGitter> <kingsleyh> I get a stacktrace
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0e50c6f4880a60a256d621]
<FromGitter> <bew> Can you show the whole code (or a small version)
<FromGitter> <bew> or more specifically, where is hex_public_key coming from/created
<FromGitter> <kingsleyh> ok doing it now
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0e527f1e86c30823563bb7]
<FromGitter> <kingsleyh> @bew there you go
<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> no joy
<FromGitter> <bew> what?
<FromGitter> <kingsleyh> doesn't work
<FromGitter> <kingsleyh> same error
<FromGitter> <kingsleyh> hmm
<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> <bew> 👌
<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.
<FromGitter> <kinxer> Cool, thanks.
marmotini_ has quit [Ping timeout: 268 seconds]
Jenz has joined #crystal-lang
rohitpaulk has joined #crystal-lang
marmotini_ has joined #crystal-lang
akaiiro has quit [Ping timeout: 246 seconds]
<Jenz> https://crystal-lang.org/api/0.27.0/Pointer.html#value%3AT-instance-method The example there allocates 4 i32's right?
<Jenz> Or is it that i32 occupies 4 bytes?
<FromGitter> <kinxer> I think it's the latter, because the literal integer is interpreted as an i32, so it uses the `.malloc` that takes an `Int`.
<FromGitter> <kinxer> Wait, no.
<Jenz> O_o
<FromGitter> <kinxer> The allocation is `size * sizeof(T)`, so it should be 4 int32s. I think.
<Jenz> Yeah alright, seems right
<FromGitter> <kinxer> Like it says here (https://crystal-lang.org/api/0.27.0/Pointer.html#malloc%28size%3AInt%3D1%29-class-method), which I would've told you if I'd read better.
<Jenz> Yeah, thanks
<FromGitter> <vladfaust> Thanks for the forum, guys ❤️
<Jenz> Says the creator of the forum?
* Jenz :D
<FromGitter> <ilanusse> There's a forum now?
<FromGitter> <ilanusse> Great! Thanks!
<Jenz> Very new, not many people, needs to get started, it's very properly made
<FromGitter> <vladfaust> No, no. I've created a forum at https://forum.crystalcommunity.org, but the core dev team managed to create an official one at https://forum.crystal-lang.org
<FromGitter> <vladfaust> I'll be shutting down mine
<RX14> Jenz, @ilanusse wrong forum, use https://forum.crystal-lang.org/
<FromGitter> <ilanusse> Yeah, still here
<Jenz> Oh my, I didn't realize!
<FromGitter> <ilanusse> Thanks guys
<Jenz> Aha! And now Im even more hyped
Renich has joined #crystal-lang
<FromGitter> <j8r> It should be crobot and not discobot (in the discourse forum)
<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
<FromGitter> <Blacksmoke16> wait what
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5r73
<FromGitter> <Blacksmoke16> well look at that
<FromGitter> <bew> \o/
<FromGitter> <Blacksmoke16> is there a list of what can be `@`'d in macro land?
<FromGitter> <Blacksmoke16> like `@type` now `@def` are there others?
<FromGitter> <bew> no
<FromGitter> <bew> they are the only chosen ones :P
<FromGitter> <Blacksmoke16> hmm this changes everything
<FromGitter> <bew> have fun!
<FromGitter> <Blacksmoke16> i feel like this would be brilliant for a web framework, easy way to define routes, security, etc on a specific route
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0ebbaaf4880a60a259bdc5]
marmotini_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> *boom*
<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?
marmotini_ has quit [Ping timeout: 244 seconds]
<FromGitter> <elorest> 👍
<FromGitter> <elorest> Thanks for your deleted message. I found it useful.
<FromGitter> <bew> Meh annotations doesn't solve everything :/
<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> https://github.com/crystal-lang/crystal/pull/7109#issuecomment-441625418 was the one i was looking for :p
<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> <elorest> Look at line 15 https://carc.in/#/r/5r7i
<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> @bew I'd welcome suggestions.
<FromGitter> <bew> Hmm there's that too..
<oprypin> elorest, what's up with the unused `CONVERSIONS` stuff? also it can just be Int32.new (etc.) instead
<FromGitter> <elorest> @bew I'm sure you're aware but in that carc everything after line 47 is for testing.
<FromGitter> <elorest> <oprypin> I want to be able to return defined types instead of the current UInt64 buffer on line 32
<FromGitter> <elorest> <oprypin> Ok now it's being used as I intended. https://carc.in/#/r/5r7u
<oprypin> well ok, now you can remove it and use `{{field.type}}.new(buffer)`
<oprypin> really though, this should be implemented like JSON.mapping
<oprypin> https://crystal-lang.org/api/0.27.0/JSON.html#mapping%28_properties_%2Cstrict%3Dfalse%29-macro
Renich has quit [Ping timeout: 246 seconds]
<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> ... data wit this method as well. [https://gitter.im/crystal-lang/crystal?at=5c0ec6693de4e816e23e868f]
<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> I'm running to lunch.
<FromGitter> <bew> Also, fyi: https://carc.in/#/r/5r8h
<FromGitter> <bew> (and i missed one ^^)
<FromGitter> <bew> (and another one (from String#split))
<FromGitter> <bew> Yeah, current impl' is a liiiitle bit (no pune intended) inefficient
<FromGitter> <bew> Fortunately it can be improved :)
<FromGitter> <bew> (full: https://carc.in/#/r/5r8j)
Dreamer3_ has quit [Quit: Leaving...]
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Client Quit]
Renich has joined #crystal-lang
<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 😁
Raimondi has joined #crystal-lang
akaiiro has joined #crystal-lang