RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
DTZUZO has quit [Ping timeout: 246 seconds]
DTZUZO has joined #crystal-lang
Heaven31415 has joined #crystal-lang
<Heaven31415> Hey, I want to create a string with float embedded in it, how can I control how many digits after dot are shown?
<Heaven31415> Is sprintf the only option?
<FromGitter> <Blacksmoke16> wouldnt it be easier to just use a float and call like `.round(NUM_DIGITS).to_s` on it?
<FromGitter> <Blacksmoke16> that wouldnt *add* 0s to the end tho
<Heaven31415> that's a nice trick, thanks
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4x4j example
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4x4k example
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4x4y is prob more what you want tho
<FromGitter> <Blacksmoke16> using sprintf
<Heaven31415> thanks dude, but I already did it with sprintf xD
<FromGitter> <Blacksmoke16> :p
<Heaven31415> but you are really helpful which is good
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> hello all
Heaven31415 has quit [Quit: Leaving]
<FromGitter> <girng> gona be working on my gameserver here soon. not the master server, but the tick rate one. this is gonna be fun :D
<FromGitter> <girng> will most likely do a 15hz or 20hz tickrate server per crystal instance. not sure how many players it will handle, but should be a good amount. am excited!!!
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <Blacksmoke16> over 9000 players
<FromGitter> <girng> LOL
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <codenoid> hi
<FromGitter> <codenoid> how to get yesterday date in crystal
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <Blacksmoke16> hm
<FromGitter> <Blacksmoke16> `Time.now - 1.day`
<FromGitter> <Blacksmoke16> `or
<FromGitter> <Blacksmoke16> `1.day.ago`?
<FromGitter> <codenoid> oh, it's working
<FromGitter> <codenoid> Day
<FromGitter> <Blacksmoke16> 👍
_whitelogger has joined #crystal-lang
<FromGitter> <codenoid> thankyou crystal doesn't have `Date` (like ruby)
<FromGitter> <Blacksmoke16> its called `Time`
rohitpaulk has joined #crystal-lang
<FromGitter> <codenoid> Time.yesterday
<FromGitter> <codenoid> error
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> yea its not a method
<FromGitter> <Blacksmoke16> would have to do either `Time.now - 1.day` or `1.day.ago`
<FromGitter> <Blacksmoke16> how would you humanize a number, like add commas
<FromGitter> <codenoid> okay
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter> <girng> when you call functions inside a fiber what happens to that function. is it duplicated to be used inside that fiber? or does the fibers just reference the method and use the code inside of it?
<FromGitter> <girng> for example in my example above in the handle_login method, let's say i use a `db` to query some info etc. and other modules. and let's just pretend the handle_login is a very large method. now. go look at the spawn handle_connection part. let's say 100 users log in, all their connections are fiber'd. ⏎ ⏎ now, is the handle_login duplicated so each of those fibers can use it? or, do all of the fiber'd
<FromGitter> ... connections just reference the handle_login and use it instead?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <girng> what i guess i'm trying to ask (and apologize if i'm not explaining it clearly). but do the amount of the methods i have in fiber'd `handle_connection` ultimately determine how many users that can connect? because i assume the larger my `message_handler` becomes, each new fiber will have to make room for all of it's methods. am not sure lol
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
moei has quit [Ping timeout: 260 seconds]
return0xe has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter> <jrfondren> no, that memory is shared.
lvmbdv has joined #crystal-lang
<FromGitter> <jrfondren> it would be shared even if you fork()ed a bunch of processes instead of using fibers
<FromGitter> <jrfondren> in general, don't worry about code. worry about data
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> ty
lvmbdv has quit [Quit: WeeChat 2.2]
rohitpaulk has quit [Ping timeout: 240 seconds]
hightower2 has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <codenoid> i have 2 employe, and i told them to learn Crystal !, xD
<FromGitter> <codenoid> they both from python
<FromGitter> <girng> noice
DTZUZO has quit [Ping timeout: 244 seconds]
Raimondii has joined #crystal-lang
ashirase has quit [Ping timeout: 244 seconds]
Raimondi^1 has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi^1 is now known as Raimondi
Raimondii has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
<FromGitter> <girng> how can i specify the types for the values being iterated on the json??
<FromGitter> <girng> i don't want to do House.from_json because then i can't access them with `[]` notation
<FromGitter> <Blacksmoke16> could always just add an override for `[]`
<FromGitter> <Blacksmoke16> or a macro
<FromGitter> <girng> thought we had to re-compile src code to modify syntax?
<FromGitter> <girng> we can add [] functionality?
<FromGitter> <girng> to whatever?
<FromGitter> <girng> is it bad practice to do an "override"? or perfectly fine
DTZUZO has joined #crystal-lang
<FromGitter> <Blacksmoke16> hmm well an override would have the same issue
<FromGitter> <Blacksmoke16> why do you need `[]` notation?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4x9v
<FromGitter> <Blacksmoke16> tada :)
<FromGitter> <Blacksmoke16> but at that point whats the point of the JSON.mapping?
<FromGitter> <girng> cause i like to do Items[item_id]["field_name"] or w/e, cause in godot i do the same thing i want to be consistent
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <girng> oh WOW
<FromGitter> <girng> thanks @Blacksmoke16 man that actually is np
<FromGitter> <girng> actually is very nice* and namedtuples are fine too, since my items don't need to be changed
<FromGitter> <Blacksmoke16> otherwise using a hash you would have to do a union of types
<FromGitter> <Blacksmoke16> like you had but `Hash(String, String | Float32)`
<FromGitter> <girng> here, let me show just a couple lines of my Items that gets generated from adminer.php to .json file
<FromGitter> <girng> https://play.crystal-lang.org/#/r/4x9x this is how it looks
<FromGitter> <girng> what i do now is just `Items = JSON.parse(File.read "./src/Data/Items.nexus")`
<FromGitter> <girng> However, this creates JSON::Any on every frield, and i have thousands of times
<FromGitter> <girng> of items*, can't be efficient
<FromGitter> <girng> i'm getting closer: https://play.crystal-lang.org/#/r/4xa6/edit
<FromGitter> <Blacksmoke16> yea, your index numbers are now getting you
rohitpaulk has quit [Ping timeout: 246 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
Jenz has joined #crystal-lang
<Jenz> I don't get how I can pass a file as an IO to an IO::Multiwriter, without using File.open(file, &block)
<Jenz> This file io is to be used in the whole program, and I'd think there would be a better way than to wrap the entire program an a File.open block
_whitelogger has joined #crystal-lang
<oprypin> Jenz, why does it have to be a block?
<Groogy> if you don't provide a block it just returns the file object
<Groogy> but you have to close it manually as well
<Jenz> orypin: I just can't get it to work any other way, wait a sec, I'll provide an example
<Jenz> Nvm. haha, thanks Groogy, it seems the only thing I forgot was a File#close
<Groogy> np
return0e has joined #crystal-lang
DTZUZO has quit [Ping timeout: 272 seconds]
Jenz has quit [Quit: leaving]
sevensidedmarble has quit [Ping timeout: 252 seconds]
Jenz has joined #crystal-lang
sevensidedmarble has joined #crystal-lang
<FromGitter> <girng> is it possible to loop through a JSON::Any?
Jenz has quit [Quit: Lost terminal]
<FromGitter> <bajro17> @girng I was try and I cant
<FromGitter> <bajro17> Then I use .to_a
<FromGitter> <girng> the end is nigh :D
<FromGitter> <bajro17> Crystal is accepted to make this API for production yaaaaayyyyy
<FromGitter> <bajro17> I will keep working on promoting this awesome language
sevensidedmarble has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
moei has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> yuhuuu @bajro17 !
<FromGitter> <j8r> this can interest @codenoid
<FromGitter> <j8r> @bajro17 better to use `as_a` instead `to_a` for `Any`
<FromGitter> <bajro17> @j8r I still learn this things about performance, thank you for this trick I dont even know about this as_a until now
<FromGitter> <girng> what am i doing wrong?
<FromGitter> <j8r> this isn't an array, but a Hash
<FromGitter> <j8r> use `as_h` instead
<FromGitter> <girng> ic, ty it works
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter> <drum445> How can I read an image as a binary array please?
<FromGitter> <bajro17> maybe this can help
<FromGitter> <bajro17> check little source code
<FromGitter> <bajro17> or maybe you can use it like image = FIle.open("image.jpg")
<FromGitter> <bajro17> image.each_byte
<FromGitter> <bajro17> I see this in API but I dont test I dont know how to use it :)
<FromGitter> <drum445> Cheers mate, yeah got it just File.read gave me a byte string
<FromGitter> <drum445> Will do nicely
<FromGitter> <jrfondren> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b9543667ce5f5314f87c556]
<FromGitter> <drum445> Don't suppose anyone knows the best way to aes encrypt a string ?
<FromGitter> <bajro17> @drum445 you work on blockchain?
<FromGitter> <jrfondren> you could use libgcrypt maybe: https://gnupg.org/documentation/manuals/gcrypt/
<FromGitter> <drum445> @bajro17 steganography
<FromGitter> <drum445> is encryption not in stdib
<FromGitter> <drum445> I must just be blind
<FromGitter> <bajro17> Same is here https://crystal-lang.org/api/0.26.1/OpenSSL.html
<FromGitter> <drum445> I can't see anything there about encrypting a string with a passphrase :(
<FromGitter> <drum445> I've used that lib for https before but not string encryption
<FromGitter> <drum445> What we reckon? https://play.crystal-lang.org/#/r/4xd7
_whitelogger has joined #crystal-lang
pabs has joined #crystal-lang
<FromGitter> <codenoid> @bajro17 in indonesia ?
<FromGitter> <codenoid> how about your crystal successor ?
lvmbdv has joined #crystal-lang
<FromGitter> <bajro17> They accept rework to crystal @codenoid :)
<FromGitter> <Blacksmoke16> @codenoid you ever exp `No address found for xxx:443 over TCP` when using `HTTP::Client` in your docker containers?
lvmbdv has quit [Quit: brb reboot]
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> @bajro17 how many devs will be on the project?
<FromGitter> <bajro17> right now 25
<FromGitter> <j8r> 25 devs will do Crystal?! :o
<FromGitter> <j8r> wow, what was their thought on it?
<FromGitter> <bajro17> no no
<FromGitter> <bajro17> Only I do crystal
<FromGitter> <bajro17> and help them to learn it
<FromGitter> <bajro17> they work on other stuff
<FromGitter> <bajro17> my job is API
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> ha ok, so finally what did they think of Crystal?
<FromGitter> <j8r> either the boss and the 25 devs (if they are aware). This devs are on PHP/Java or maybe Python now?
<FromGitter> <bajro17> They use PHP and Java
<FromGitter> <bajro17> They think its awesome language
<FromGitter> <bajro17> with so beautiful syntax and so good performance
<FromGitter> <codenoid> i'm never facing that @Blacksmoke16
<FromGitter> <codenoid> or can you give me example rqeuest
<FromGitter> <codenoid> yeah, bcoz there is a bunch of PHP & Java Tutorial in indonesian @bajro17
<FromGitter> <Blacksmoke16> was a swarm networking issue
<FromGitter> <Blacksmoke16> containers were on limited network that didnt have access to outside
<FromGitter> <codenoid> ```echo "nameserver 30.30.30.1 ⏎ nameserver 1.1.1.1 ⏎ nameserver 1.0.0.1" > /etc/resolv.conf``` [https://gitter.im/crystal-lang/crystal?at=5b9570b6f3c26b08f65176ae]
<FromGitter> <codenoid> @Blacksmoke16 , change 30.1 to your local dns
<FromGitter> <codenoid> i use echo, while there is no text editor (nano, vim, ed, etc)
<FromGitter> <Blacksmoke16> yea i fixed it
<FromGitter> <Blacksmoke16> thanks
<FromGitter> <codenoid> 👍
<FromGitter> <Blacksmoke16> or maybe not
<FromGitter> <Blacksmoke16> yea http client cant connect for whatever reason
<FromGitter> <codenoid> :/
<FromGitter> <Blacksmoke16> trying github api just to make sure its not the host im trying to connect to
<FromGitter> <Blacksmoke16> `Unhandled exception: No address found for api.github.com:443 over TCP (Socket::Error)`
<FromGitter> <Blacksmoke16> nope
<FromGitter> <j8r> Sounds like a dns problem
<FromGitter> <Blacksmoke16> hmm plan b
<FromGitter> <Blacksmoke16> can curl those apis within container just fine
return0xe has joined #crystal-lang
thews has quit [Ping timeout: 252 seconds]
<FromGitter> <Blacksmoke16> well got it working, using the crystal imagine as a base
return0e has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> so guess there is some dependency http client needs there that doesnt get statically compiled, as it doesnt work on alpine/scratch image bases
<FromGitter> <Blacksmoke16> is there a way to figure out what that dependency would be?
<FromGitter> <j8r> There is an issue about dns and docker
<FromGitter> <j8r> It might be related, dunno
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> could it be related to alpine using musl-libc vs glibc?
<FromGitter> <Blacksmoke16> i dont know much about this stuff but that seems to be a possibility
<FromGitter> <Blacksmoke16> since that seems to be the only major diff dependency wise between the crystal image and alpine image
<FromGitter> <Blacksmoke16> yea its deff the issue, ill file a bug
thews has joined #crystal-lang
<FromGitter> <j8r> No it's not related to the libc
<FromGitter> <Blacksmoke16> sure seems like it
<FromGitter> <Blacksmoke16> but you prob know more about it than i do, just reporting what i find
<FromGitter> <Timbus> I see dns problems all the time with alpine so it's a fair assumption. That said, you compiled with --static so I can't understand how it's the libc
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <drum445> all languages should compile to single binaries like Crystal and Go
<FromGitter> <j8r> It's more related to Docker containers than Alpine itself
<FromGitter> <j8r> Alpine is neat. On ubuntu, that's dnsmasq that can cause problems. IIRC it's installed by default
<FromGitter> <Timbus> The only problem Ive ever had with dnsmasq is docker trying to circumvent it :-/
_whitelogger has joined #crystal-lang
DTZUZO has joined #crystal-lang
hightower2 has quit [Ping timeout: 252 seconds]
<FromGitter> <girng> i'm having trouble with this json. if i only have like 2 keys it works. but if i start adding more than that, i get index out of bounds error
<FromGitter> <girng> https://play.crystal-lang.org/#/r/4xfj what could possibly be going wrong here?
<FromGitter> <Timbus> .. You're iterating the 'items' hash, but using that index to access 'item'
DTZUZO has quit [Ping timeout: 245 seconds]
druonysus has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
<FromGitter> <girng> yeah i'm trying to do that but it gives error
<FromGitter> <girng> oh i see
<FromGitter> <girng> i still get error though. my lord. why is this so hard??
<FromGitter> <girng> all i want to do it loop through a JSON:Any
<FromGitter> <Timbus> `item` will be set to the nested element. if you want to get the contents of each `item` you need a second loop
<FromGitter> <girng> oh i see what it's doing look
<FromGitter> <girng> look: https://play.crystal-lang.org/#/r/4xg3
<FromGitter> <girng> ok so i was thinking the `as_h` was going to do `{"1" => {"item_id" => 1_i64}}`, not `{"1", {"item_id" => 1_i64}}` that's what confused me
<FromGitter> <girng> my bad. sorry ty for help
<FromGitter> <xababafr> Hi everyone :) I'm looking for a way to go through a crystal code's ast and look for variables and methods, to get their types.. Is there any way to do it with the Transformer class? I have no idea how type is handled in Ast Nodes
DTZUZO has joined #crystal-lang
<FromGitter> <girng> ```code paste, see link``` ⏎ ⏎ but when i select the `slot_position` from the query, it still shows `""`, not `0,0` [https://gitter.im/crystal-lang/crystal?at=5b95b2fa33ebb72e37f3a121]