RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
<FromGitter> <Blacksmoke16> seems i have to include the var in the macro, else it doesnt get applied
<FromGitter> <snadon> I need a cron job that fetches files everyday. Is it possible to do it with Crystal? If so, where should I look first? Thank you, developing with Crystal has been amazing so far!
<FromGitter> <Blacksmoke16> at a specific time?
<FromGitter> <bew> @snadon why not simply use `cron` for that?
<FromGitter> <snadon> @bew I have a project written with Lucky, and I was planning to create a Task so I can trigger the download whenever I need it if something goes wrong. But you are right, I guess I should just use cron with the ftp command.
<FromGitter> <Blacksmoke16> https://github.com/robacarp/mosquito could be nice if you dont care about running the task at a specific time vs once every x time
chkilroy has joined #crystal-lang
duane has joined #crystal-lang
akaiiro has quit [Ping timeout: 244 seconds]
akaiiro has joined #crystal-lang
<FromGitter> <fridgerator> @Blacksmoke16 have you used mosquito vs sidekiq.cr ?
<FromGitter> <Blacksmoke16> i used ruby sideqkiq
<FromGitter> <Blacksmoke16> i like mosquito because it has scheduled jobs, like cronesque run this task every x minutes or what have you
<FromGitter> <Blacksmoke16> havent gotten *super* deep into it yet but so far i like
<FromGitter> <fridgerator> eek "There is the potential for multiple instances or fibers running background jobs to interfere with each other, resulting in duplicate task executions"
<FromGitter> <fridgerator> I just started implementing sidekiq.cr today, i'll stick with it for now
<FromGitter> <Blacksmoke16> πŸ‘
duane has quit [Ping timeout: 240 seconds]
duane has joined #crystal-lang
rohitpaulk has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
<FromGitter> <HCLarsen> Hey guys. What's the deal with the Hash.new that takes a block? What's the block do?
<FromGitter> <Timbus> Uh, looking at the source code, it appears to run the block when a key isn't found
<FromGitter> <Timbus> and returns whatever the block outputs
<FromGitter> <aisrael> It’s a way for you to provide a dynamic β€œdefault” value for when the key is not found.
pbodev1 has joined #crystal-lang
DTZUZO has joined #crystal-lang
<FromGitter> <bararchy> RX14 great news regarding the windows port and rainforestQA sponsorship! Congratz
<FromGitter> <codenoid> why crystal doesn't have string encrypt-decrypt library
<FromGitter> <aisrael> Encrypt how? AES? There's Crypto::Blowfish (https://crystal-lang.org/api/0.25.1/Crypto/Blowfish.html) but very sparse documentation on how to use it.
<FromGitter> <Timbus> There's a half-written libsodium wrapper that does pubkey encryption: https://github.com/andrewhamon/cox but you might need the symmetric-key bindings.
rohitpaulk has quit [Ping timeout: 244 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Client Quit]
alex`` has joined #crystal-lang
<FromGitter> <Grabli66> RX14, Why only alpine linux? https://github.com/crystal-lang/crystal/wiki/Static-Linking . Everything is worked in 0.24 on my host linux. But now i have to install alpine linux?
<FromGitter> <straight-shoota> @Grabli66 Nothing has changed, only the documentation.
<FromGitter> <straight-shoota> If it has worked for you before, it should still work.
<FromGitter> <Grabli66> Ok
<FromGitter> <straight-shoota> But you probably don't get a fully-static binary, do you?
<FromGitter> <Grabli66> I dont know :)
<FromGitter> <straight-shoota> what does `ldd your-binary` say? =)
<FromGitter> <bararchy> @straight-shoota did we added the thing with `--static` "takes what it can" and uses dynamic for what it can't find?
<FromGitter> <straight-shoota> Afaik it has always been like this
<FromGitter> <Grabli66> I cant do that right now. But i got several warnings from linker yesterday when i used --static.
<RX14> no, --static means the executable is always static
<FromGitter> <straight-shoota> ah, yes. It's been a long time since I used it...
<FromGitter> <kolyaio> ```code paste, see link``` ⏎ ⏎ What am I doing wrong? :O [https://gitter.im/crystal-lang/crystal?at=5b4daee3ad8d085553a82ada]
<FromGitter> <Grabli66> Wrong password?
<FromGitter> <straight-shoota> RX14, but ldd differs between `not a dynamic executable` and `statically-linked`
<RX14> does it
<RX14> are you sure thats not just different messages?
<RX14> i can't understand what the difference would be
<RX14> it either has an interpreter or no
<FromGitter> <straight-shoota> yeah it's a bit weird
<FromGitter> <straight-shoota> it says the officially released compiler built on Alpine is `statically-linked`
<FromGitter> <straight-shoota> a hello world program built on Ubunutu with `--static` is `not a dynamic executable`
<RX14> but you're compareing alpine ldd vs ubuntu ldd then surely
<RX14> or is it the same ldd
<FromGitter> <straight-shoota> same ldd, on Ubuntu
<RX14> oh okay
<RX14> "weird"
<RX14> go ead the source :P
<FromGitter> <straight-shoota> ha, not desperate enough
<FromGitter> <straight-shoota> this is the only thing I could find on it: https://www.linuxquestions.org/questions/linux-general-1/ldd-command-570529/#post2828753
rohitpaulk has joined #crystal-lang
<RX14> regarding windows exceptions i've rewritten most of the windows exceptions stuff and it's very nearly compiling
<RX14> all the hard codegen errors seem to be gone (cross fingers), just some naming issues left
<RX14> and who knows if it'll actually fix the segfaults
<FromGitter> <straight-shoota> ❀️
<FromGitter> <Grabli66> RX14, you are great. :)
vegai has joined #crystal-lang
<FromGitter> <bew> @RX14 awesome work!! PR is coming soon? I'd like to see how Windows handles exceptions and how you implemented that :)
<RX14> no timeframe on a PR because i've not got it to compile yet let alone not segfault at funtime
<RX14> lol nice typo
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter> <bararchy> `funtime errors` the only errors which are `fun`
rohitpaulk has joined #crystal-lang
gewo has quit [Quit: WeeChat 1.6]
hightower3 has joined #crystal-lang
<hightower3> Is there a type of quote inside which "\" is literal?
<FromGitter> <Timbus> %q() , I think?
<hightower3> Indeed, thanks!
alex`` has quit [Ping timeout: 268 seconds]
alex`` has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
jokke1 has quit [Ping timeout: 245 seconds]
duane has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
<jokke> i need to pass the pointer to a struct to a c function, how can i do this in crystal. i instanciate the struct on the stack but how do i do the equivalent of &struct?
<jokke> s/\./?/
<jokke> ah
<jokke> pointerof
jokke1 has joined #crystal-lang
<FromGitter> <straight-shoota> exactly
<FromGitter> <robacarp> @fridgerator re mosquito, it's designed to be essentially a sidekiq.cr. The only thing preventing it from isolating and preventing duplicate runs of the same job is using a redis transaction to pop/push the job.
duane has joined #crystal-lang
duane has quit [Ping timeout: 248 seconds]
<FromGitter> <fridgerator> @robacarp gotcha, thanks
<hightower3> Is there a way to define a value for a constant unless already defined?
<hightower3> How can I declare a variable that will hold a class? If I do @@var : Xyz, it expects an instance of Xyz, and if I do @@var : Class, it says "can't use Object as the type of a class variable yet, use a more specific type"
<FromGitter> <drum445> @Blacksmoke16 on the JSON::Serializable thing I think that is what I went with here: https://github.com/drum445/objectify/blob/master/src/objectify/to_object.cr
<FromGitter> <drum445> I guess that's a decent approach then considering Granite have done something similar?
<FromGitter> <straight-shoota> hightower3 `{% if @type.constant?(MY_CONSTANT) %}` should work to conditionally define a constant if it doesn't exist
<hightower3> Nice one, thanks!
<FromGitter> <straight-shoota> You can use use `Foo.class` as ivar type, where `Foo` is the base type of all possible types
duane has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<crystal-gh> [crystal] straight-shoota opened pull request #6404: Add API docs for StaticArray (master...jm/docs/static-array) https://git.io/fNsTf
<FromGitter> <bararchy> is anyone working on a Swagger client?
<FromGitter> <rishavs> How do I cast an Array(String) which I am getting from a postgres db query_each to another Array(String)? ⏎ In my code; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b4df706cad358639d5f2a56]
<FromGitter> <Blacksmoke16> prob be much easier to use an orm but yea...
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter> <rishavs> having tried my hand at running bare db queries, i can't agree more. :p ⏎ But my current project is mainly for learning so I think it will be a good experience to stay away from ORMs
<FromGitter> <Blacksmoke16> i mean if you want to learn the internals of how the DB works i guess :p
<FromGitter> <rishavs> Just to add, my db column for children_ids has postgres array of type ` children_ids TEXT [],` and has data like `'{"cid110", "cid120" }'`
<FromGitter> <rishavs> > i mean if you want to learn the internals of how the DB works i guess :p ⏎ Well I have moved from learning to masochism in the last few days but I am still a bit stubborn. :D
<FromGitter> <Blacksmoke16> @drum445 im not sure what you are trying to do?
<FromGitter> <drum445> @Blacksmoke16 Turn a sql result set into an object or array of object (predefined classes)
<FromGitter> <drum445> I used JSON::Serializable so the dev doesn't need to make any changes to their class apart from include it
<FromGitter> <Blacksmoke16> oh, i didnt notice that was your repo
<FromGitter> <drum445> ah apologies
<FromGitter> <Blacksmoke16> that'd prob work yea
<FromGitter> <Blacksmoke16> Granite just has some syntax to make it prettier i.e.
<FromGitter> <drum445> sweet, yeah seems to do the trick nicely but was a tad worried that JSON::Serializable could push breaking changes
<FromGitter> <Blacksmoke16> `field name : String, json_options: {key: "foo"}`
<FromGitter> <drum445> But it's stdlib so I doubt it will change much
<FromGitter> <Blacksmoke16> after macro is like
<FromGitter> <Blacksmoke16> ```[@JSON::FIELD(key: "foo")] ⏎ property name : String``` [https://gitter.im/crystal-lang/crystal?at=5b4dfdf18578203ee739b81d]
<FromGitter> <Blacksmoke16> something like that
<FromGitter> <Blacksmoke16> anything in crystal could push breaking changes ;P
<FromGitter> <Blacksmoke16> just look at last release haha
<FromGitter> <drum445> oh I see, so the class attr doesn't have to match the result set
<FromGitter> <drum445> Yeah true hah
<FromGitter> <drum445> That's nice, I guess it should work with my lib as it also uses json serialize
<FromGitter> <Blacksmoke16> id have to look how Granite actually handles the parsing from db result into object tho
<FromGitter> <drum445> Someone want to help me on a very strange issue
<FromGitter> <drum445> https://play.crystal-lang.org/#/r/4jka - works fine (notice 3 vars in init call) ⏎ https://play.crystal-lang.org/#/r/4jkb - compilation error (notices < 3 vars in init call)
<FromGitter> <drum445> I have no idea what that is happening :(
<FromGitter> <drum445> maybe a bug?
<FromGitter> <Blacksmoke16> i think you dont need the init method
<FromGitter> <drum445> you don't in the example, but my code does
<FromGitter> <Blacksmoke16> to do what?
<FromGitter> <drum445> It can be initialized not using JSON.
<FromGitter> <Blacksmoke16> ah
<FromGitter> <drum445> Not sure why having 2 params is causing compile error when any other number of params is fine (hmm)
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <drum445> bug?
<FromGitter> <Blacksmoke16> maybe?
<hightower3> Can I define a default value for a method argument in runtime? E.g. I'd like to modify the X in def some_method( arg = X )
<hightower3> Actually, yeah
yopp has quit [Ping timeout: 265 seconds]
<robacarp> hightower3: yeah, you can make it the value of another method call
<jokke> is there any way to parse json into objects where the type of the object is depending on the value for a field "kind"
<jokke> i already tried overwriting self.from_json but it won't work in nested objects because they only call initialize(pull_parser)
<jokke> if there was a way to override the initialize(pull_parser) method while preserving the macro generated one...
<FromGitter> <bmulvihill> Do they have different JSON mappings?
<jokke> yeah
<jokke> partly equal
<FromGitter> <bmulvihill> not exactly your use case but maybe similar
<FromGitter> <bmulvihill> using an alias
<jokke> hmmm
<jokke> ok
<jokke> how does that work?
<jokke> i mean how does crystal know which class it will parse?
<FromGitter> <bmulvihill> Seems to work based on the mapping https://play.crystal-lang.org/#/r/4jkt
<jokke> ok that's way cleaner
<jokke> i do it like that
<jokke> hm except i don't know if it always works
<jokke> sometimes they might have the same mapping
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
<FromGitter> <rogics> Hi everybody! I am new to Crystal prog lang and I have a problem with exception handling inside EACH block, for example : SOCKETS.each { |socket| socket.send "Hi" } . How can I write code inside EACH block so I can catch errors on socket.send call. ?
wontruefree has joined #crystal-lang
DTZUZO has quit [Ping timeout: 276 seconds]
akaiiro has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> welcome @rogics ! https://carc.in/#/r/4jl7
nathanj has quit [Ping timeout: 276 seconds]
alex`` has joined #crystal-lang
nathanj has joined #crystal-lang
cyberarm has quit [Ping timeout: 248 seconds]
cyberarm has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
nathanj has quit [Quit: WeeChat 2.1]
nathanj has joined #crystal-lang
wontruefree has quit [Quit: bye]
wontruefree has joined #crystal-lang
<FromGitter> <fridgerator> Its so refreshing working with crystal after spending time in python and node
<FromGitter> <fridgerator> It makes the time fly by
<hightower3> It's awesome
<FromGitter> <yorci> hi peoples
<FromGitter> <yorci> where am i doing wrong? ⏎ ⏎ https://carc.in/#/r/4jmd
<FromGitter> <yorci> oh i see now :D
<hightower3> We are glad to help :)
<FromGitter> <yorci> what if i want change the format?
<FromGitter> <Blacksmoke16> `dateTime.to_s("%F")`
<FromGitter> <Blacksmoke16> https://carc.in/#/r/4jmq
<FromGitter> <Blacksmoke16> for list of possible options
<FromGitter> <Blacksmoke16> @yorci
<FromGitter> <yorci> alright, i get it
<FromGitter> <yorci> ```Time.parse(date.to_s, "%FT%X%z").to_s(newformat)``` ⏎ ⏎ thats the easiest way right? [https://gitter.im/crystal-lang/crystal?at=5b4e40b31539a7040ce5b703]
<FromGitter> <bew> huh why not just `date.to_s(newformat)`?
<FromGitter> <yorci> bcuz date value is string already but i guaranteed string type anyway :D
DTZUZO has joined #crystal-lang
<FromGitter> <bew> ah ok, I thought `date` was a `Time` object
<FromGitter> <fridgerator> is not possible to use JSON::Serializable `@[JSON::Field]` on a method?
<FromGitter> <bew> @fridgerator a method is not serializable?
<FromGitter> <fridgerator> true
<FromGitter> <fridgerator> I thought if I defined a property, then a method with the same name it woudl overritde the getter, but I guess not
<FromGitter> <bew> it doesn't use a the getter to get the value to serialize
<FromGitter> <fridgerator> ok
<FromGitter> <bew> but yeah, would be nice to be able to use a method instead of having to have to deal with ivars
<FromGitter> <fridgerator> yep
DTZUZO has quit [Ping timeout: 240 seconds]
DTZUZO has joined #crystal-lang
pbodev1 has quit [Quit: ChatZilla 0.9.93 [Firefox 56.0/20170903140023]]
<FromGitter> <jspillers> i know there has to be a better way to guard against nilable instance variables right? https://play.crystal-lang.org/#/r/4jn3
<FromGitter> <fridgerator> ```if t = @test ⏎ # t wont be nil ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b4e49b94b583a74a7239a6b]
<FromGitter> <jspillers> do we know if the compiler will eventually be able to detect guards on nilable instance vars in the future?
<FromGitter> <fridgerator> if you're going to initialize test every time though, then it doesn't need to be nil
<FromGitter> <jspillers> in my real code i have two different initialize definitions
<FromGitter> <jspillers> where there is the possibility of nil
<FromGitter> <fridgerator> afaik you have to check for nil every time you use it
<FromGitter> <fridgerator> and I dont think there are plans to change htis
<FromGitter> <fridgerator> this*
<FromGitter> <jspillers> i wish this would work: https://play.crystal-lang.org/#/r/4jn5
<FromGitter> <jspillers> would be cleaner
<FromGitter> <bew> @jspillers what if the value of `@test` changes between the nil check and the use?
<FromGitter> <straight-shoota> @jspillers This is impossible because of race conditions
<FromGitter> <jspillers> sorry - https://play.crystal-lang.org/#/r/4jn7
<oprypin> it's funny to keep saying that for like 5 years under which those race conditions are still not actually possible
<oprypin> jspillers, it's not something to think of for "future", as it's not a shortcoming
<FromGitter> <fridgerator> ```if t = @test ⏎ t + " property wasnt nil" ⏎ else ⏎ "" ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b4e4b808578203ee73ab032]
<FromGitter> <straight-shoota> yes, currently, it would probably be safe. but it can easily fail if there happens to be a fiber switch in between
<FromGitter> <straight-shoota> ```if @test ⏎ @test.foo gets ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b4e4bcff046ba6aca5f2c56]
<oprypin> fiber switches are not possible in between those, not now, not in the future
<FromGitter> <bew> @jspillers consider this https://play.crystal-lang.org/#/r/4jn8 the value of `@test` could change, and thus the type after the check would still be `String?`
<oprypin> but threads tho
<FromGitter> <straight-shoota> see my example
<oprypin> oh. it's the most insidious example
<oprypin> good stuff
<FromGitter> <jspillers> @bew that makes sense - thank you
<FromGitter> <bew> you're welcome ;)
<FromGitter> <bew> @straight-shoota your example is good, fiber switch can be a big problem here too
<FromGitter> <jspillers> oh this is nice actually: ⏎ ⏎ ```@a.try do |a| ⏎ # here `a` can't be nil ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b4e4f5d03a5fa639e619f26]
<FromGitter> <straight-shoota> `if a = @a` is shorter and more clearly shows it's purpose
<FromGitter> <straight-shoota> Though `.try` is good for short blocks like invoking a method: `@a.try &.to_i`
<FromGitter> <straight-shoota> as long as you need a return value
<FromGitter> <straight-shoota> if not, use `if`
<FromGitter> <bew> (note: `if` also return a value)
<FromGitter> <straight-shoota> absolutely
DTZUZO has quit [Read error: Connection reset by peer]
<FromGitter> <straight-shoota> but it looks weird as a one-liner or embedded in an expression
t-richards has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter> <fridgerator> 40MB docker containers <3
<hightower3> Is there a way to use YAML.mapping() or similar to set class variables, rather than to create instances with instance variables?
akaiiro has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <straight-shoota> hightower3, no. You need a manual parser for this.
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<oz> Hugh... I hope the next crystal release does not break the JSON API. πŸ™
<FromGitter> <bew> @oz what if it's better? ^^
<oz> Better is nice, but if I don't enjoy chasing JSON::Type, and type casts. ;)
<hightower3> straight-shoota: I looked at yaml/mapping.cr in the source and it looks like it would be trivial to copy & change it to work with class vars
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <straight-shoota> yeah, but why?
t-richards has quit [Quit: Leaving]
DTZUZO has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
wontruefree has quit [Ping timeout: 264 seconds]
DTZUZO has quit [Read error: Connection reset by peer]
alex`` has quit [Ping timeout: 240 seconds]
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang