jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
_whitelogger has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <3n-k1> how does shards figure out what commit to check out, does it use git tags?
<FromGitter> <3n-k1> oh it's in the shard.yml file
<FromGitter> <3n-k1> lmao sorry
zorp has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
<FromGitter> <nolyoi> is there a capistrano alternative for deployments with crystal?
<FromGitter> <nolyoi> or how do you guys deploy your projects?
postmodern has joined #crystal-lang
<FromGitter> <Blacksmoke16> build a docker imagine a static binary in it and just deploy a new tag
<FromGitter> <nolyoi> gotcha. was thinking docker. but was just curious if there was a similar option to cap.
postmodern has quit [Quit: Leaving]
postmodern has joined #crystal-lang
<oprypin> here we go again, Error: expecting identifier 'end', not 'EOF'
<oprypin> i always stick to correct indentation but i dont know where in the entire program i missed an `end`
<oprypin> found manually.. but actually my text editor helped with code folding 😊
<FromGitter> <Blacksmoke16> ansible could prob do it as well? Have a deploy playbook which builds the binary, copies to to remote server starts it and stops the other one :shrug:
<postmodern> is there an option to just evaluate the macros and output the result? trying to debug a macro issue
<oprypin> postmodern, {% debug %} at the bottom of the macro
<oprypin> and then there's `crystal tool expand` but nobody knows how to use it
<postmodern> nice!
<yxhuvud> after implementing support for tool expand in the crystal emacs mode, I think I can say that I know how to use it (and of its limitations, which there are many).
<postmodern> holy cow, totally got video_output working with v4l2.cr and v4l2loopback. can spam MJPEG frames into a loopback video dev and watch the other end with mpv
<postmodern> probably need to insert some sleeps based on timeperframe fract
<yxhuvud> bascially it takes two arguments, one which represents the place you want to expand and the other some file that requires everything that needs to be required to expand it.
<postmodern> don't suppose crystal has something like V4L2Fract for representing fractional values?
sagax has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> prob be fairly trivial to make a record with that info
<postmodern> hmm sleep(Float) isn't allowed?
<FromGitter> <Blacksmoke16> should be?
<postmodern> ah typo
<postmodern> is there no fork()?
<postmodern> trying to be fancy and execute a blocking process (mpv /dev/video0) in the background, but trigger an exit when it exits
<postmodern> suppose that can be done via Channels?
<oprypin> postmodern, yea dont do fork
<oprypin> u can have a fiber that waits for it to finish
<oprypin> "it" being Process.new
<oprypin> i have an object of type B which is a subclass of A
<oprypin> how can I call A's implementation of the method `foo` rather than B's implementation, on an object of type B
<FromGitter> <Blacksmoke16> does `B` override the method? or is it only defined on `A`?
<oprypin> yes, overrides
<FromGitter> <Blacksmoke16> `super` or `previous_def` then
<oprypin> this works only inside the override
<oprypin> but i need it elsewhere
<FromGitter> <Blacksmoke16> then expose it as another method? or conditionally within `B#foo`
<FromGitter> <Blacksmoke16> idt theres a way to just skip a method implementation on an obj like that
<oprypin> https://carc.in/#/r/9jsv except "base_foo" has no business being in A
<FromGitter> <Blacksmoke16> whats the ultimate goal here?
<FromGitter> <Blacksmoke16> seems kinda odd to override a method on `B`, but not want to use it when you call it?
<FromGitter> <Blacksmoke16> ^ still not following why you need to do this
<postmodern> for libraries that are meant to only work on a specific OS, what's the best way for that?
<postmodern> doesn't appear there's an option in the shard.yml to specify OS. I think there's a macro to check OS, but do I guard certain files or certain methods or what?
<oprypin> postmodern: {% if flag?(:linux) %} {% raise "oh no" %}
<oprypin> postmodern: don't do that here though, like, your binding requires that lib's api to work, but who are you to say that people won't make an implementation for another platform
<postmodern> oprypin, well this is for the V4L2 UAPI
<postmodern> oprypin, although it could be possible that someone only wants to use the structs to parse some captured data, and not mess with any of the VIDIOC ioctls() methods.
<oprypin> seriously though how do i debug these errors "expecting identifier 'end', not 'EOF'"
<oprypin> aha.. add `end` until it's happy and run `crystal tool format` can sometimes help
<oprypin> this is the problem, wtf
<oprypin> had to switch it out to `property val_p : Void*; @val_p = uninitialized Void*`
sagax has joined #crystal-lang
<postmodern> is there a way to force IO::Hexdump to output a dump of a Slice without reading from the IO::Memory
<oprypin> postmodern, the io::memory adds no overhead, just use it
<FromGitter> <j8r> @dscottboggs_gitlab jenerator is like https://app.quicktype.io/
<oprypin> happily used quicktype just yesterday ^^
<postmodern> oprypin, kind of weird to have to .read from the hexdump into a buffer, when i already have a buffer of the bytes i want to dump
<postmodern> oprypin, but got it working
<oprypin> i dont understand the problem, maybe show the code
<oprypin> io::memory is just a pair of (buffer, current position)
<oprypin> is your complaint then that current position is stored in io::memory rather then in hexdump function?
<postmodern> er wait there's a .hexdump method...
<postmodern> i was doing https://play.crystal-lang.org/#/r/9jt1 which is stupid
<postmodern> hmm well maybe not, since i'm dumping a 640x480 frame buffer. Better to stream the hexdump output instead of building a string.
<oprypin> oh wow thats quite a juxtaposition. i ws expecting the inverse relation between these
<postmodern> weird IO::Hexdump relies on Slice#hexdump, not the other way around?
<postmodern> when i have time i might try to refactor that into a streaming hexdump
<postmodern> once upon a time i wrote this hexdump implementation https://github.com/postmodern/hexdump/blob/master/lib/hexdump/dumper.rb
<postmodern> is there an easy way to get the argument count of a Tuple class?
<FromGitter> <Blacksmoke16> `tup.class.types.size`?
<FromGitter> <Blacksmoke16> but wouldnt that actually be the same as `tup.size`?
<postmodern> ah ha tup.types.size
<FromGitter> <Blacksmoke16> hows that any diff than just the size of the tuple? since the types would be specific to each element
<postmodern> forgot to mention it's a NamedTupe, which apparently MyTuple.size isn't defined
<postmodern> am doing something tricky with generics and tuples
<FromGitter> <Blacksmoke16> 😬
<postmodern> attempting to write a Pixel array and eventually something that lazily converts YUYV pixels to RGB pixels
<FromGitter> <dscottboggs_gitlab> @j8r wish I'd known about that, woulda saved me a lot of time 😅
duane has quit [Ping timeout: 256 seconds]
duane has joined #crystal-lang
<FromGitter> <alexherbo2> how to declare the following type? https://code.visualstudio.com/api/language-extensions/snippet-guide
duane has quit [Ping timeout: 240 seconds]
<postmodern> alexherbo2, i'd checkout JSON::Serializable https://crystal-lang.org/api/0.35.1/JSON/Serializable.html
postmodern has quit [Quit: Leaving]
Xeago has quit [Ping timeout: 265 seconds]
Xeago has joined #crystal-lang
<FromGitter> <alexherbo2> thanks
<FromGitter> <alexherbo2> what is wrong with my code?
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f383ec787848e2119ea3cc3]
<FromGitter> <alexherbo2> ``` walk(snippets_path) do |files| ⏎ puts files ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f383ee15ccdf30c584a715b]
<FromGitter> <alexherbo2> `Error: wrong number of block arguments (given 1, expected 0)`
<FromGitter> <alexherbo2> error happens for `walk(snippets_path) do |files|`
Xeago has quit [Ping timeout: 264 seconds]
Xeago has joined #crystal-lang
<FromGitter> <Blacksmoke16> im not sure you can use recursive methods with yield like that?
<FromGitter> <dscottboggs_gitlab> maybe remove the parens in the `yield` statement? That's a keyword, not a method call
<FromGitter> <alexherbo2> how can I ?
<FromGitter> <dscottboggs_gitlab> I would do ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f384908ba27767ee5f28918]
<FromGitter> <dscottboggs_gitlab> well, actually...
<FromGitter> <Blacksmoke16> whats the goal here? just have each file yieled recursively?
<FromGitter> <alexherbo2> is my code wrong?
<FromGitter> <alexherbo2> yield all files yep
<FromGitter> <alexherbo2> the structure of my snippets are
<FromGitter> <dscottboggs_gitlab> I think the problem with your code was to combine the use of `yield` with passing a block like `&block`
<FromGitter> <dscottboggs_gitlab> those generally don't work so well together
<FromGitter> <Blacksmoke16> ```Dir.glob "./**/*" do |file| ⏎ puts file ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f38497d4d3fd87ee7d86500]
<FromGitter> <Blacksmoke16> ?
<FromGitter> <alexherbo2> `ruby/rails/controller/validates`, where `ruby.rails.controller` is the scope
<FromGitter> <alexherbo2> `ruby/def`, where `ruby` is the scope, and `def` the snippet file
<FromGitter> <alexherbo2> I want to build a hash of `scopes` with the snippets in it (a snippet is a hash with `name` and `content`)
sorcus has quit [Ping timeout: 272 seconds]
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f384a5f083f3b79c332d8ff]
<FromGitter> <dscottboggs_gitlab> yup, either the code I posted or what @Blacksmoke16 posted will work
<FromGitter> <alexherbo2> @Blacksmoke16 How do you build that hash with your method?
<FromGitter> <alexherbo2> with my method I have the scope `ruby/rails/controller` and all snippets in it at once
<FromGitter> <alexherbo2> with you method I have to deal with existency of the scope
zorp has quit [Ping timeout: 260 seconds]
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f384b403e6ff00c28965959]
<FromGitter> <alexherbo2> @dscottboggs_gitlab I don't understand your `walk` def
<FromGitter> <alexherbo2> it yield each directory and each file individually?
<FromGitter> <dscottboggs_gitlab> is there a particular part you're confused about?
<FromGitter> <dscottboggs_gitlab> each file from each directory
<FromGitter> <alexherbo2> ``` walk child do |p| ⏎ yield p ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f384c50ba27767ee5f2917d]
<FromGitter> <alexherbo2> this step
<FromGitter> <alexherbo2> you all walk by defining your own block, yielding the path
<FromGitter> <alexherbo2> call*
<FromGitter> <dscottboggs_gitlab> yes, that's a recursive call to the same method. Since the method only yields when it encounters a file, the files in the child directory are yielded to the internal block as `p`.
<FromGitter> <dscottboggs_gitlab> then yielding inside that block yields to whatever called walk (which might be walk)
<FromGitter> <dscottboggs_gitlab> sorry recursion is hard and yielding out of a recursive function makes it even more confusing
<FromGitter> <alexherbo2> I'm lost yep
<FromGitter> <alexherbo2> I don't understand how my code is executed
<FromGitter> <dscottboggs_gitlab> sorry I'm typing just a sec
<FromGitter> <alexherbo2> to me, `yield p` execute my code on every child node
<FromGitter> <dscottboggs_gitlab> lets say you have a directory like ⏎ ⏎ ```foo ⏎ foo/bar ⏎ foo/baz/boo``` ⏎ ⏎ If you call `walk Path["foo"] do |path|`, walk will check each file in `foo` if it's a directory. When it gets to `bar` it will say "this isn't a directory", go to the else block, and `Path["foo", "bar"]` will be yielded. ... [https://gitter.im/crystal-lang/crystal?at=5f384e6f60892e0c6973fd9a]
<FromGitter> <dscottboggs_gitlab> > yield p execute my code on every child node ⏎ ⏎ isn't that the idea?
<FromGitter> <alexherbo2> no
<FromGitter> <alexherbo2> I wanted that behaviour:
<FromGitter> <alexherbo2> foo -> yield ["foo/bar", "foo/baz"]
<FromGitter> <dscottboggs_gitlab> that's just `Dir.each_child`
<FromGitter> <alexherbo2> foo/baz -> yield ["foo/baz/foo"]
<FromGitter> <alexherbo2> at each step, yield all children path
<FromGitter> <alexherbo2> as an array
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <dscottboggs_gitlab> I see why you were confused now
<FromGitter> <alexherbo2> your implementation, it executes my block for each file individually, but also dir?
<FromGitter> <dscottboggs_gitlab> no, only files
<FromGitter> <alexherbo2> oki
<FromGitter> <alexherbo2> the `yield p` is delegate
<FromGitter> <alexherbo2> can you confirm me if I understand your code correctly? At each step, when encountering a directory, you create your own anonymous function, calling *my* function with the child path --there can be file or directory--, but you yield that code only on the file
<FromGitter> <dscottboggs_gitlab> yes, I think you've got it
<FromGitter> <alexherbo2> the function definition is growing at each iteration no?
<FromGitter> <alexherbo2> instead of passing my block, you encapsulate in another function
<FromGitter> <dscottboggs_gitlab> well, that would be the case, but Crystal inlines all blocks that aren't explicitly cast to a `Proc`
<FromGitter> <alexherbo2> oh
<FromGitter> <alexherbo2> your method is quite elegant
<FromGitter> <dscottboggs_gitlab> thank you!
<FromGitter> <alexherbo2> so I need to adapt to yield an array
<FromGitter> <alexherbo2> do you think your method yielding individual will not make hard to build my hash?
<FromGitter> <dscottboggs_gitlab> I think the easiest way is ⏎ ⏎ ```array = [] of Path ⏎ walk parent &->array.<<(Path)``` [https://gitter.im/crystal-lang/crystal?at=5f38528dc7637c27000886df]
<FromGitter> <alexherbo2> xd
<FromGitter> <dscottboggs_gitlab> not sure, but usually yielding creates pretty versatile APIs
<FromGitter> <dscottboggs_gitlab> for collections anyway
<FromGitter> <alexherbo2> but my yield does not retain the result
<FromGitter> <alexherbo2> your code is
<FromGitter> <alexherbo2> ```walk(parent) do |path| ⏎ array << path ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f385348367ff60c32b62b90]
<FromGitter> <alexherbo2> ?
<FromGitter> <alexherbo2> I wanted a list to be sure to have all the "scope" collection
<FromGitter> <alexherbo2> because I cannot build my hash without checking if the key exists or not
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3853eba1190a2e95f511d0]
<FromGitter> <dscottboggs_gitlab> > I cannot build my hash without checking if the key exists or not ⏎ ⏎ what do you mean by this?
<FromGitter> <alexherbo2> by constructing my hash there will be "ruby/rails/routes" key
<FromGitter> <alexherbo2> I will need to create it for the first call
<FromGitter> <alexherbo2> and populate for the second
<FromGitter> <alexherbo2> that's why I wanted my yield to yield a list
<FromGitter> <dscottboggs_gitlab> > by constructing my hash there will be "ruby/rails/routes" key ⏎ ⏎ what?
<FromGitter> <alexherbo2> the final return value is a hash of "scope" of "name", "content"
<FromGitter> <dscottboggs_gitlab> if it has known keys, why is it a hash instead of a class?
<FromGitter> <alexherbo2> "ruby/rails/routes" is the scope, "collection" the name and the file content the "content"
<FromGitter> <alexherbo2> I want to export to json then
<FromGitter> <alexherbo2> the scope keys are unknown
<FromGitter> <dscottboggs_gitlab> do you mean ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5f3854d3b7818b3998fcc901]
<FromGitter> <alexherbo2> more like this
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f38550ec7637c2700088b3b]
<FromGitter> <dscottboggs_gitlab> so `Hash(String, Hash(String, Hash(String, String)))`?
<FromGitter> <alexherbo2> yep
<FromGitter> <dscottboggs_gitlab> what are the contents of `ruby/rails/controller`? Like ⏎ ⏎ ```{"validates_presence": {"content": "..."}}``` [https://gitter.im/crystal-lang/crystal?at=5f3855725ccdf30c584aa01e]
<FromGitter> <alexherbo2> it's the snippet
<FromGitter> <dscottboggs_gitlab> oh so you're parsing Ruby code?
<FromGitter> <alexherbo2> no I want to build snippets json from a dir structure
<FromGitter> <alexherbo2> currently it is only <language>, but I want to add subdir for the scope
<FromGitter> <dscottboggs_gitlab> where does the json come in?
<FromGitter> <alexherbo2> so if I edit a eruby in rails, I get the "eruby" and "eruby/rails" snippets
<FromGitter> <alexherbo2> it is easier to work with json
<FromGitter> <alexherbo2> that manipulate the file structure directly
<FromGitter> <dscottboggs_gitlab> oh you're outputting the thing you sent me from a dir of JSON docs?
<FromGitter> <alexherbo2> my goal is to compile an intermediate data easy to manipulate for external editors
<FromGitter> <alexherbo2> `snippets-build` binary that outputs json from the dir snip paths you give to it
<FromGitter> <dscottboggs_gitlab> oh ok so `validates_presence` in this case is like a descriptor of the snippet, and `content` is the contents of the file?
<FromGitter> <alexherbo2> exactly
<FromGitter> <dscottboggs_gitlab> 👍
<FromGitter> <alexherbo2> and the parent key, the scope to apply them
<FromGitter> <alexherbo2> but the structure is not correct
<FromGitter> <alexherbo2> it should be "<lang>/rails" instead of "rails/<lang>"
<FromGitter> <dscottboggs_gitlab> where are you going to get the descriptor string from?
<FromGitter> <alexherbo2> the filename
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3857ade8eb3939a494a052]
<FromGitter> <alexherbo2> what is `record`?
<FromGitter> <dscottboggs_gitlab> https://crystal-lang.org/api/0.35.1/toplevel.html#record(name,*properties)-macro
<FromGitter> <dscottboggs_gitlab> actually you'd want to do ⏎ ⏎ ```require "json ⏎ record Snippet, content : String do ⏎ include JSON::Serializable ⏎ end``` ⏎ ⏎ then you could just do `snippets.to_json` [https://gitter.im/crystal-lang/crystal?at=5f385847a1190a2e95f51b00]
<FromGitter> <dscottboggs_gitlab> gonna play some no man's sky now tho 😛
<FromGitter> <alexherbo2> struct is the same than class no?
<FromGitter> <alexherbo2> and record an inline struct
<FromGitter> <dscottboggs_gitlab> a class is a reference to a struct
<FromGitter> <dscottboggs_gitlab> structs are passed by copy
<FromGitter> <alexherbo2> how `snippets[file.parent][file.basename] = Snippet.new File.read file` work?
<FromGitter> <alexherbo2> your
<FromGitter> <alexherbo2> ```snippets = Hash(Path, Hash(String, Snippet)).new do ⏎ Hash(String, Snippet).new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f385a0a083f3b79c332fa2a]
<FromGitter> <alexherbo2> the `.new` blocks
<FromGitter> <dscottboggs_gitlab> when you call `snippets[file.parent]` it default-constructs a `Hash(String, Snippet)`
<FromGitter> <alexherbo2> ruby has this?
<FromGitter> <dscottboggs_gitlab> no idea, I've barely written any ruby
<FromGitter> <alexherbo2> where is the doc for that code?
<FromGitter> <dscottboggs_gitlab> https://crystal-lang.org/api/0.35.1/Hash.html#new(block:Hash(K,V),K-%3EV?=nil,*,initial_capacity=nil)-class-method
* FromGitter * alexherbo2 is amazed e_e
<FromGitter> <alexherbo2> I would have built it with my ifs xd
<FromGitter> <alexherbo2> I have all pieces to build my app thanks!!!
<FromGitter> <dscottboggs_gitlab> glad to help 😀
<FromGitter> <alexherbo2> in ruby it would be ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5f3860d1a1190a2e95f52b98]
<FromGitter> <alexherbo2> ```snippets = Hash.new do |hash, key| ⏎ hash[key] = {} ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f3860f8ce98da26eccd03a8]
<FromGitter> <Blacksmoke16> Pretty sure that would also work in crystal. But would have to type the object
<FromGitter> <alexherbo2> isn't the same than what scott posted in crystal?
<FromGitter> <Blacksmoke16> It is yea
<FromGitter> <alexherbo2> it's a bit different no?
<FromGitter> <alexherbo2> my ruby code assign
<FromGitter> <alexherbo2> and his crystal code just specify the default constructor
<FromGitter> <Blacksmoke16> In his example the block is called when the key doesn't exist
<FromGitter> <alexherbo2> it's called for doing a `=`?
<FromGitter> <alexherbo2> or just returning a value
<FromGitter> <Blacksmoke16> Look at the example in the API docs
<FromGitter> <alexherbo2> yep
<FromGitter> <alexherbo2> in his code I do not see as in the api example the `hash[key] = something`
duane has joined #crystal-lang
duane has quit [Ping timeout: 256 seconds]