ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.22.0 | Fund Crystal's development: | Paste > 3 lines of text to | GH: | Docs: | API: | Logs:
Kug3lis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Kug3lis has joined #crystal-lang
Philpax has joined #crystal-lang
txdv has quit [Ping timeout: 240 seconds]
Kug3lis is now known as Kug3lis_off
zipR4ND has quit [Ping timeout: 240 seconds]
txdv has joined #crystal-lang
<FromGitter> <arc512> how do I parse a data structure like this:
<FromGitter> <arc512> ```code paste, see link``` []
<FromGitter> <drosehn> might be of some help to get you started.
<FromGitter> <arc512> I've noticed crystal compile time is very slow, is there a reason for this?
<FromGitter> <AustinPaquette> :point_up:
<FromGitter> <AustinPaquette> Desperately want a solution for this as well. Super excited about using it, but compiling needs to be faster :/
<FromGitter> <arc512> Golang is quite fast at this, I'm wondering if Crystal binaries are fatter than Go's
<FromGitter> <arc512> how does Crystal binaries compare to Go?
<FromGitter> <fridgerator> I don't know much about the compiler process, otherwise I would try and answer your questions
<FromGitter> <fridgerator> A sample web app with the entire amber web framework is 4.4 mb ?!?
<FromGitter> <fridgerator> I don't know if that helps at all
<adam12> If you compare binary sizes, make sure you do so with the --release flag on Crystal. It can be 1/3 less the size than non-release flag.
<FromGitter> <drosehn> For the kinds of programs I write, crystal compiles pretty fast if you don't use the `--release` flag. But then `--release` does do a really good job of speeding up your program.
svenskunganka has joined #crystal-lang
<svenskunganka> Hey guys, I'm getting a syntax error and I really can't figure out why. I don't see any immediate syntax issues in my code:
<FromGitter> <AustinPaquette> I want to use it for a pretty sizable application but it’s just not possible cause compiling already takes a while (even out of the box)
<FromGitter> <AustinPaquette> I do agree though that it’s super fast when it *is* compiled. I just need dev time not to suffer as a result of it.
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 246 seconds]
hightower2 has quit [Ping timeout: 258 seconds]
<FromGitter> <bigtunacan> @drujensen I see you are working on a mailer shard. What's the status on that one? You used it with anything yet?
<FromGitter> <bigtunacan> Was wondering since that smtp lib hasn't been updated in quite awhile if it's working with the latest version of Crystal.
<FromGitter> <bigtunacan> Would be good to see smtp in the core APIs
rohitpaulk has joined #crystal-lang
pleiosau1 has quit [Remote host closed the connection]
Kug3lis_off is now known as Kug3lis
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
Kug3lis is now known as Kug3lis_off
rohitpaulk has quit [Ping timeout: 268 seconds]
<crystal-gh> [crystal] MakeNowJust opened pull request #4591: Semantic: specify Void alias type as yiled output restriction (master...fix/crystal/type-alias-restriction-yield)
olek_poz has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Yxhuvud> svenskunganka: what happens if you use crystal tool format on the file
<FromGitter> <bew> svenskunganka, I think it's because how you define blocks: `register_up |db| do` should be `register_up do |db|`
rohitpaulk has joined #crystal-lang
pleiosaur has joined #crystal-lang
<FromGitter> <bew> Also, your variable `Migrations` should be a hash not an array, as you do `Migrations[ver] = mig`, and additionally identifiers starting with an Uppercase (like `Migrations` denotes a type, you should use class variables for this imo
<FromGitter> <bew> @AustinPaquette can you give examples? What time is slow for you?
<crystal-gh> [crystal] MakeNowJust opened pull request #4592: Parser: fix #4590, correct to parse empty parenthesis "()" (master...fix/crystal/4590-wrap-paren-nop)
<FromGitter> <bigtunacan> @fridgerator I'm trying out Crecto and running into some errors.
<FromGitter> <bigtunacan>
<FromGitter> <bigtunacan> error expanding macros on `schema "users"`
<FromGitter> <bigtunacan>
<FromGitter> <bigtunacan> Macro didn't expand to valid program...
hightower2 has joined #crystal-lang
<svenskunganka> @bew thanks for the response. Is class variables mutable from "another file"? I don't come from a Ruby background so the whole syntax is new to me
<svenskunganka> On the `Migration.migrations[ver] = migration` line, `ver` is an `Int` so I add the migration to the index `ver`.
<Yxhuvud> They are.
<Yxhuvud> I can recommend doing a dupe check on the versions, by the way
<svenskunganka> Yeah I have some error checking and blanks yet to fill in of course
hightower2 has quit [Ping timeout: 246 seconds]
olek_poz has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> svenskunganka, in crystal you cannot insert a new value at a specific index of an array
<svenskunganka> @bew isn't that what this method does:
<FromGitter> <bew> If you create an empty array, the array has a size of 0.
<FromGitter> <bew> From the doc you linked: Raises IndexError if trying to set an element outside the array's range.
<svenskunganka> Ah yeah, I think I need to use Macros to create the size of the array at compile-time, since the size of the array will be known at compile-time.
<Yxhuvud> no, just use << to insert new elements and make certain you insert them in the order you want to
<Yxhuvud> (or use a hash table or whatever)
olek_poz has joined #crystal-lang
<svenskunganka> @Yxhuvud: Alright, I've made some changes now which I feel better about, but I still run into an error: The problem is that I want the code to pretty much run at compile-time, so that the `@@migrations` hash in `Project::Migration` is already populated at runtime, which was why I thought I might need to use a macro.
<Yxhuvud> the problem there is that the code assume that there is a migration in the next slot, but there is no such guarantee. Put it in a variable, and check it for nil and the problem go away.
<Yxhuvud> Hmm, actually no. That is not the issue. I have no idea what
<svenskunganka> I'm just unsure what code the compiler "optimizes" away
<FromGitter> <bew> Yxhuvud it's part of it at least, because if he doesn't call `register_up` the `@up` won't be set, and be defaulted to Nil
<Yxhuvud> bew: Right, but neither up or down is declared or initialized in the initializer. @svenskunganka: what version of crystal do you use?
<svenskunganka> I've made some changes to the gist now with nil checking.
<svenskunganka> 0.22
<svenskunganka> Same error tho
<FromGitter> <arc512> is this a good way to call an external json file:
<FromGitter> <arc512> ```file ="./blocks.json") ⏎ blocks = JSON.parse(file)``` []
<Yxhuvud> apart from your strange way of words, yes that would *read* the json file unless it is really huge
<svenskunganka> Yxhuvud: in, I explicity set the type of `@up` variable to be a `Proc(DB::Database, Bool)`, but why does it then assume it's a union type of `(Proc(DB::Database, Bool), Nil)`? Is it because the procs are not passed in the `initialize` method?
<Yxhuvud> yeah, they can be uninitialized.
<svenskunganka> From my testing, it is not possible to pass multiple procs to a method, if I were to pass the up & down procs directly to the initializer
<svenskunganka> Instead of using the `register_up` and `register_down` methods
<svenskunganka> I.e this does not work: `def initialize(@version : Int32, &up, &down) { @up = up; @down = down }`
<svenskunganka> Ish
<svenskunganka> Psuedocode
<FromGitter> <bew> svenskunganka, usually a migration is defined by a class that defines 2 method `up` and `down`
rohitpaulk has quit [Ping timeout: 240 seconds]
<svenskunganka> Yeah, but that seems very inefficient to me. Having to create `Project::Migration1` `Project::Migration2` etc?
rohitpaulk has joined #crystal-lang
<FromGitter> <bew> it's quite the same as having versions, and it should force you to name your migration against what your migration do, instead of just a number (which desn't mean a lot in my sense)
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <arc512> @yxhuvud what do you mean by huge json, my json is 200 lines but I get runtime errors like:
<FromGitter> <arc512> ```code paste, see link``` []
<FromGitter> <arc512> ```code paste, see link``` []
<FromGitter> <arc512> ```code paste, see link``` []
<svenskunganka> @arc512: That error says that it can't find the file `./blocks.json`.
<svenskunganka> @arc512: what Yxhuvud means is that if your JSON files is large in size (say, 200MB) it would require the machine where your program runs to have at least 200MB of available memory to use.
<FromGitter> <arc512> the file is in the same folder as the executable
<crystal-gh> [crystal] ysbaddaden opened pull request #4594: Fix: use platform specific Pointer sizes (master...fix-platform-specific-pointer-sizes)
splitty__ has joined #crystal-lang
splitty_ has quit [Ping timeout: 240 seconds]
svenskunganka has quit [Read error: Connection reset by peer]
svenskunganka has joined #crystal-lang
<FromGitter> <drosehn> Before the read, try: `p Dir.current`
zipR4ND has joined #crystal-lang
zipR4ND has quit [Ping timeout: 260 seconds]
<FromGitter> <arc512> what is the best way to cast unstructured json data from a file
<FromGitter> <arc512> I've tried ```blocks = JSON.parse(file).as(Array)``` but doesn't work
davidbe[m] has quit [Ping timeout: 264 seconds]
<FromGitter> <straight-shoota> `JSON.parse` returns an `JSON::Any` ( so you can use `#as_a` to cast it's raw value to an Array if you're sure it is always an Array
<FromGitter> <straight-shoota> You can also iterate it directly (`JSON::Any` is an `Enumerable`)
zipR4ND has joined #crystal-lang
davidbe[m] has joined #crystal-lang
<FromGitter> <sdogruyol> 7 stars to pass Scala on GH programming languages list :P
<FromGitter> <arc512> how does async work in crystal
<FromGitter> <ultra2mh> @sdogruyol ⏎ now 8.374 :D
<FromGitter> <sdogruyol> @ultra2mh thanks
<FromGitter> <sdogruyol> @arc512 ⏎ ⏎ ```spawn do ⏎ puts "ASYNC" ⏎ end``` []
<FromGitter> <ultra2mh> :pray:
<Yxhuvud> svenskunganka: no, I mean that if it is larger than 2GB then doesn't work anymore.
splitty___ has joined #crystal-lang
splitty__ has quit [Ping timeout: 240 seconds]
svenskunganka has quit [Quit: leaving]
zipR4ND has quit [Ping timeout: 240 seconds]
<FromGitter> <bararchy> I just made a CSV db of 4.2Gb using Crystal , it was fun hahah :)
_whitelogger has joined #crystal-lang
<FromGitter> <sdogruyol> @bararchy how's the speed
<FromGitter> <bararchy> well .... It's a huge text processeor, the CSV has 2 tables ⏎ Huge text | small string ⏎ the huge text is begin converted to array of int32 based on `char.ord`, so each char is tested and converted, all in all it's a big effort on CPU and a huge mem eater, I do think that right now MultiThreading would have been nice :)
olek_poz has quit [Ping timeout: 255 seconds]
A124 has quit [Quit: '']
A124 has joined #crystal-lang
<FromGitter> <bigtunacan> @fridgerator I'm just starting to try out Crecto in a project I'm working on. I was wondering if it supports custom validators in the models and if so how that would look?
<FromGitter> <fridgerator> @bigtunacan There are, here is the docs on those:
<FromGitter> <fridgerator> There are a couple examples of usage in the crecto readme
Philpax_ has quit [Ping timeout: 240 seconds]
<FromGitter> <bigtunacan> Yeah; I looked over the readme.
<FromGitter> <bigtunacan> I'm probably missing something here.
<FromGitter> <bigtunacan> What I'm trying to do is validate some password requirements.
<FromGitter> <bigtunacan> So I'll hash the password before I write it back to the database.
<FromGitter> <bigtunacan> I want the password to be at least 10 characters for example
<FromGitter> <bigtunacan> I'm not sure that I can use `validate_length :password, min: 10` for this
<FromGitter> <bigtunacan> The hashed version would always be valid.
<FromGitter> <fridgerator> right, the check would have to be done on the pre hashed password
<FromGitter> <fridgerator> if you need a custom validation, you can use the generic validator and pass a proc
<FromGitter> <bigtunacan> Thanks; I think that's what I need
<FromGitter> <fridgerator> :thumbsup:
jfontan has quit [Remote host closed the connection]
jfontan has joined #crystal-lang
<crystal-gh> [crystal] ysbaddaden closed pull request #4594: Fix: use platform specific Pointer sizes (master...fix-platform-specific-pointer-sizes)
hightower2 has joined #crystal-lang
<FromGitter> <nickbclifford> how does one use `Slice#move_to`? I'm trying to use this to convert a `Slice` (used in a ``) into a C `struct`.
<FromGitter> <nickbclifford> I'm not convinced that this is the right way though, so feel to tell me if there's a better way to read bytes into a C `struct`
<RX14> @nickbclifford why do you want to do that?
<RX14> reading directly into a struct sounds like a bad idea to me
<FromGitter> <drujensen> @bigtunacan yes, it works. sorta. I will be adding multi-part support so you can send text/html/attachments soon.
<FromGitter> <nickbclifford> it probably is, but I was looking at this documentation for the Joystick API ( and was trying to figure out how to read those events in Crystal
<RX14> you should just read the values using io.read_bytes(UInt32) for example
<RX14> and then place those values in a crystal struct
<FromGitter> <nickbclifford> gotcha, let me try that out
saadq has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> It feels I'm missing something...
<FromGitter> <bew> When I run that kind of code without spec-related methods it works perfectly, the types are ok, and I can call `target_result.succ`. But in the spec's `it` block the types are somewhat broken..
<FromGitter> <bew> without describe/it blocks:
<FromGitter> <sdogruyol> @bew i guess blocks kind of swallow the type info there
<RX14> it captures the block
saadq has joined #crystal-lang
<RX14> but i don't know why
<FromGitter> <bew> ok, but I don't get why the block capture will make it behave like that
<FromGitter> <bew> my 2 `if`s are in the block
<FromGitter> <bigtunacan> @drujensen is that a change in the SMTP shard layer or is that a change that needs to happen in your shard?
<RX14> @bew because any variable which is in the block closure can be changed at any time
<RX14> it's essentially like an instance variable
<FromGitter> <bew> oh
Kug3lis has joined #crystal-lang
<RX14> make copies of the variables
<RX14> inside the closure
<FromGitter> <bew> ok I'll try
<FromGitter> <bew> works now, thanks RX14 ;)
<FromGitter> <bew> now I'm having a hard time to find another name for the original variable (which will be closured), I have `_target_result` or `outer_target_result` or `target_result_original` which are quite ugly...... I take any suggestion!
<FromGitter> <bigtunacan> @bew are usually just use the same name and add an __in at the front
<FromGitter> <bew> so be it! thanks
olek_poz has joined #crystal-lang
saadq has quit [Ping timeout: 246 seconds]
<FromGitter> <bigtunacan> @fridgerator I tried inserting a duplicate record where I have a unique constraint on a column with Crecto to see what would happen.
<FromGitter> <bigtunacan> It completely freezes the application. Just hangs and never finishes.
saadq has joined #crystal-lang
omninonsense has joined #crystal-lang
jfontan has quit [*.net *.split]
krigare[m] has quit [*.net *.split]
[spoiler] has quit [*.net *.split]
stnly has quit [*.net *.split]
stnly has joined #crystal-lang
zipR4ND has joined #crystal-lang
jfontan has joined #crystal-lang
krigare[m] has joined #crystal-lang
yopp has quit [Ping timeout: 240 seconds]
<FromGitter> <fridgerator> @bigtunacan there is an open (aging) issue about it in crystal-db :
<FromGitter> <fridgerator> submitted March 28th
yopp has joined #crystal-lang
Papierkorb has quit [Ping timeout: 260 seconds]
pduncan has joined #crystal-lang
pduncan has quit [Ping timeout: 258 seconds]
<FromGitter> <johnjansen> WTF
<FromGitter> <johnjansen> anyone got any insight on this ??? its `0.22.0`
<oprypin> johnjansen, they renamed it, apparently it's `rchop` now
olek_poz has quit [Ping timeout: 246 seconds]
<FromGitter> <johnjansen> ok, good idea to check legacy code every so often i suppose
<FromGitter> <johnjansen> docs are out of date
pduncan has joined #crystal-lang
olek_poz has joined #crystal-lang
<FromGitter> <schoening> Is there a way to clear the terminal with crystal?
<hightower2> schoening: seems it is, at least with the curses/crt bindings -
<FromGitter> <johnjansen> ok, anyone want to enlighten me on this one … feeling like i left my brain at home today
<oprypin> there's a way easier way to clear the terminal. it's always just a special byte sequence away
<oprypin> johnjansen, i don't know what's up with the error but the code is certainly invalid. you can't put code outside a method
<oprypin> assuming the top level is a special method-like case
hightower2 has quit [Ping timeout: 246 seconds]
qard has joined #crystal-lang
<FromGitter> <johnjansen> crap i knew i left the brain at home …
<FromGitter> <johnjansen> thanks @oprypin … dont know how i missed that …
<FromGitter> <schoening> oprypin good point! "\33[2J" did it
binBASH has quit [*.net *.split]
mrus has quit [*.net *.split]
olbat has quit [*.net *.split]
g3funk has quit [*.net *.split]
tliff has quit [*.net *.split]
tliff_ has joined #crystal-lang
olbat has joined #crystal-lang
g3funk has joined #crystal-lang
olek_poz has quit [Quit: Konversation terminated!]
mrus has joined #crystal-lang
binBASH has joined #crystal-lang
binBASH has quit [*.net *.split]
mrus has quit [*.net *.split]
binBASH has joined #crystal-lang
mrus has joined #crystal-lang
<FromGitter> <drujensen> @bigtunacan It should be my shard but not sure if there is something needed at the SMTP level that is missing yet.
<FromGitter> <elorest> SMTP
hightower3 has joined #crystal-lang
hightower4 has quit [Ping timeout: 240 seconds]
hightower2 has joined #crystal-lang
Philpax_ has joined #crystal-lang
<FromGitter> <ziprandom> it's ready to be played with: :D