ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.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
DTZUZU has quit [Ping timeout: 240 seconds]
DTZUZU has joined #crystal-lang
<alexherbo2> how to specify receiver?
<FromGitter> <Blacksmoke16> hm?
<alexherbo2> list.select(&->File.executable?)
<FromGitter> <Blacksmoke16> what about it?
<alexherbo2> it does not work
<FromGitter> <Blacksmoke16> is `list` an array of `File`?
<FromGitter> <Blacksmoke16> `list.select &.executable?`
<FromGitter> <Blacksmoke16> otherwise you would have to use the long format, `list.select { |file_name| File.executable? file_name }`
<alexherbo2> ah
<alexherbo2> my list is a string
<FromGitter> <Blacksmoke16> oh wait
<FromGitter> <Blacksmoke16> try `list.select &->File.executable(String)`
<alexherbo2> btw pathname has no #executable anyway no?
<FromGitter> <Blacksmoke16> no
<bougyman> Pathname has no executable?
<alexherbo2> I always forget the syntax for forwarding
<FromGitter> <Blacksmoke16> did that work?
<alexherbo2> yes
<FromGitter> <Blacksmoke16> πŸ‘
<alexherbo2> euh no
<FromGitter> <Blacksmoke16> no?
ur5us has joined #crystal-lang
<alexherbo2> I get something like
<alexherbo2> `[".", "..", ".", "..", ".", "..", ".", "..", ".", ".."...`
<FromGitter> <Blacksmoke16> whats the point of using `sum`?
<alexherbo2> when adding `select`
<alexherbo2> to concat the list
<alexherbo2> ?
<FromGitter> <Blacksmoke16> :thinking:
<alexherbo2> I get paths, then in each I do path.entries
<alexherbo2> I filter executable and add the result to a single list
<alexherbo2> you would do it an other way?
<alexherbo2> oh silly
<alexherbo2> I do executable on a list of file *name*
<FromGitter> <Blacksmoke16> id prob use `map` then `.join('\n')`
<alexherbo2> not the full path
<alexherbo2> but with map with get a list of list of string
<FromGitter> <Blacksmoke16> `next unless Dir.exists? path`
<alexherbo2> I think I name Dir.entries with the full path
<alexherbo2> and when passing give the file name
<FromGitter> <Blacksmoke16> doesnt make a diff
<alexherbo2> sum will not mess if I do `next` without returning a list?
<FromGitter> <Blacksmoke16> seems like File.executable is returning false all the time?
<alexherbo2> yes
<alexherbo2> unless for . / ..
<alexherbo2> it's because I use Dir.entries(path), which return the basename
<FromGitter> <Blacksmoke16> is possible you just dont have anything on path that your user can execute directly (without sudo)
<alexherbo2> I need to have the full path
<alexherbo2> then return name if executable? pass
<FromGitter> <Blacksmoke16> i tried that it doesnt make a diff
<alexherbo2> what is the equivalent of Dir.entries to return full entry paths
<FromGitter> <Blacksmoke16> idt `entries` is what you want
<FromGitter> <Blacksmoke16> `Returns an array containing all of the filenames in the given directory. ⏎ ⏎ `
<FromGitter> <Blacksmoke16> er nvm
<FromGitter> <tenebrousedge> `children` is bette
<alexherbo2> not sure
<alexherbo2> I lost the dirname part
<FromGitter> <Blacksmoke16> meh idk, some piece of logic is deff wrong
<alexherbo2> which I need for testing executable?
<alexherbo2> deff wrong?
<FromGitter> <Blacksmoke16> just use https://crystal-lang.org/api/master/File.html#expand_path(path,dir=nil,*,home=false):String-class-method
<FromGitter> <tenebrousedge> yes
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4ddf91d97c107ed2631f6e]
<FromGitter> <noaheverett_twitter> I'm trying to download a large binary file via HTTP::Client and save chunks of that file as they are received to disk. I understand I can do this by juts passing the responses body_io to a File.write call, but for my use-case I have to do it manually since I need to manipulate the data chunks as they come in.
<FromGitter> <noaheverett_twitter> I've got it kind of working, but my data ends up mangled
<FromGitter> <noaheverett_twitter> url = "https://large-file-url" ⏎ HTTP::Client.get(url) do |response| ⏎ puts "Downloading file..." ⏎ f = File.open("large-file-on-disk", "wb") ⏎ buf = Bytes.new(1024) ... [https://gitter.im/crystal-lang/crystal?at=5e4de09740ac4a7fb9f67b84]
<FromGitter> <noaheverett_twitter> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4de0c8c2c73b70a4474716]
<FromGitter> <noaheverett_twitter> I believe my issue is, my buf is a set size and the data read bytes is different sometimes yet I'm saving the entire buf byte array each time. How do I save only the bytes to disk received? or am I way off? Thanks in advance!
<FromGitter> <tenebrousedge> @noaheverett_twitter can you read either line-by-line, or using `gets(1024)` ?
<FromGitter> <tenebrousedge> and what exactly is that bit-munging intended to do?
<FromGitter> <noaheverett_twitter> @tenebrousedge I'll try gets / read by line, but my assumption is that since it's a binary file those wouldn't work? the bit-munging is basically sending the bytes back out to a different HTTP connection plus some reading on the initial bits to see what kind of data it is
djuber has quit [Remote host closed the connection]
djuber has joined #crystal-lang
djuber has quit [Ping timeout: 240 seconds]
<alexherbo2> is there a way to write in append mode?
<alexherbo2> File.open(get_history_path, 'a') do |file|
<alexherbo2> file.puts program
<alexherbo2> end
<FromGitter> <Blacksmoke16> Yes like that
<alexherbo2> how to do lazy chaining? list.sort.uniq
<alexherbo2> it seems list.each.sort.uniq does not work
<FromGitter> <Blacksmoke16> Paging @tenebrousedge
<FromGitter> <Blacksmoke16> Would probably need an iterator
<FromGitter> <tenebrousedge> :D iterators
<FromGitter> <tenebrousedge> @noaheverett_twitter `gets` for a set number of bytes will work
<FromGitter> <tenebrousedge> and you shouldn't need to do `to_unsafe` to inspect the initial bits
<FromGitter> <tenebrousedge> alexherbo2, how is lazy sorting supposed to work?
<FromGitter> <tenebrousedge> I think you want to simply use a `Set`
<FromGitter> <noaheverett_twitter> Ok thank you for the help, greatly appreciated!
<FromGitter> <tenebrousedge> @noaheverett_twitter let us know if you have any other issues with that
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> I can't find away to check if a constant is an annotation
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <watzon> Second thought, I think I'm doing this wrong
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <watzon> Basically the idea I'm having right now is to allow a handler to export a list of annotations (will probably just be one in most cases). Then those annotations will be looped over and the logic for it automatically generated based on the handler class that's exporting it.
<FromGitter> <watzon> I don't know that this will be necessary, but it doesn't look like this works https://carc.in/#/r/8le2
<FromGitter> <Blacksmoke16> what do you need to do that for?
<FromGitter> <Blacksmoke16> https://carc.in/#/r/8lec
<FromGitter> <watzon> Hmm interesting. More than anything I just wanted to know if it was possible, just in case I do need to do that
<FromGitter> <watzon> I do have a need to store a list of annotations in an array though to keep track of which annotations have been registered by a handler already, but I can't do `annotations = [] of Annotation`
<FromGitter> <watzon> I guess I could use the string representation
<FromGitter> <watzon> Also, I don't feel like the `command_class::ANNOTATIONS` part here is going to work, is it? ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Man macros are confusing haha [https://gitter.im/crystal-lang/crystal?at=5e4e0401a0aa6629f5dd4509]
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> cant you just do like
<FromGitter> <Blacksmoke16> ```{% if annotations = command_class.constant("ANNOTATIONS") %} ⏎ ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5e4e04c90c45141266792559]
<FromGitter> <watzon> Ahh I didn't know you could do that
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Crystal/Macros/TypeNode.html#constant(name:StringLiteral%7CSymbolLiteral%7CMacroId):ASTNode-instance-method
<FromGitter> <Blacksmoke16> it'll bomb if `command_class` is generic tho
<FromGitter> <watzon> Luckily it's not, so we're good
alexherbo2 has quit [Ping timeout: 255 seconds]
<FromGitter> <watzon> Haha a macro issue that wasn't made by you
<FromGitter> <watzon> Surprising
<FromGitter> <watzon> πŸ˜‰
<FromGitter> <Blacksmoke16> πŸ˜‰
<FromGitter> <watzon> Thanks for all your help btw. You're one of the few people that has a pretty good handle on macros.
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> working on my own little macro related project atm as well
<FromGitter> <Blacksmoke16> still TBD on how I'm going to do it :p
<FromGitter> <watzon> Haha, well now I'm curious
<FromGitter> <Blacksmoke16> reworking my validation shard
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4e05d3ff00c664eed36c0b]
<FromGitter> <Blacksmoke16> separates the constraints from their validators
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4e05e7a0aa6629f5dd48bc]
<FromGitter> <Blacksmoke16> so the main question is now is how to handle the instantiation of the constraint types and tie them to properties
<FromGitter> <watzon> Hmm interesting. I'll be interested to see where it goes.
<FromGitter> <Blacksmoke16> plan is to tie the annotation to the constraint class somehow
<FromGitter> <watzon> I do love annotations, just can't wait for them to come a little further
<FromGitter> <watzon> I still really want to be able to handle annotation specific logic inside of the annotation block itself
<FromGitter> <Blacksmoke16> i kinda like how PHP handles their annotations
<FromGitter> <watzon> I haven't actually looked at PHP's
<FromGitter> <Blacksmoke16> they're just classes that have an annotation :P
<FromGitter> <Blacksmoke16> ``` * @Annotation ⏎ * @Target({"PROPERTY", "METHOD", "ANNOTATION"})``` [https://gitter.im/crystal-lang/crystal?at=5e4e0728d97c107ed2635ffa]
<FromGitter> <Blacksmoke16> along with what it can be added to
<FromGitter> <watzon> Hmm yeah I'm looking at them
<FromGitter> <Blacksmoke16> so its just a type so you can do `instanceof` etc, and the constructor just gets an assoc array of arguments
<FromGitter> <watzon> I do like implementations where an annotation is just a class or a function that wraps something
<FromGitter> <watzon> Python does the same
<FromGitter> <watzon> And so does TypeScript
<FromGitter> <Blacksmoke16> thats why this is a bit more troublesome
<FromGitter> <Blacksmoke16> otherwise we could add a method to iterate over all annotations on a property/method, and do like `if ann.is_a? Constraint`
<FromGitter> <watzon> Right?
<FromGitter> <Blacksmoke16> but since there isnt that bond between the logic of the annotation and the annotation itself have to get a bit more creative
<FromGitter> <watzon> That would be so nice
<FromGitter> <Blacksmoke16> options atm are like
<FromGitter> <Blacksmoke16> 1) Use an annotation to store the metadata of the constraint ⏎ 2) Use a constant to store the annotation it maps to ⏎ 3) Do something with the name of the constraint, like map `BlankConstraint` to `Blank` annotation
<FromGitter> <Blacksmoke16> and also how to best map a constraint to the type it should be validated by
<FromGitter> <watzon> Do we know if the maintainers are open to completely changing the implementation?
<FromGitter> <watzon> Something makes me doubt it
<FromGitter> <watzon> But man would it be nice
<FromGitter> <Blacksmoke16> probably one of those just needs done?
<FromGitter> <Blacksmoke16> i.e. someone to implement it
Nicolab has joined #crystal-lang
<FromGitter> <watzon> Hmm
<FromGitter> <watzon> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4e0b43d97c107ed263676a]
<FromGitter> <watzon> Fml
<FromGitter> <watzon> Ok so weird. Renaming `annotation` to `_annotation` worked. So it was trying to call `TypeNode#annotation`
ur5us has joined #crystal-lang
maxpowa_ has joined #crystal-lang
maxpowa has quit [Ping timeout: 245 seconds]
maxpowa_ is now known as maxpowa
<FromGitter> <watzon> Holy fuck I did it
<FromGitter> <watzon> If you have any tips on cleaning it up let me know. Especially when it comes to not having trailing commas
<FromGitter> <watzon> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4e19d34609ce3a88138c0b]
ur5us has quit [Ping timeout: 258 seconds]
Nicolab has quit [Quit: Leaving.]
Nicolab has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> good lord
ur5us has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> i think that's either 1) beautiful, or 2) a monstrosity . i'm going to go with: a beautiful monstrosity
<FromGitter> <watzon> Yeah basically lol
<FromGitter> <watzon> I know there's some cleanup I could do
<FromGitter> <ImAHopelessDev_gitlab> i just alt-tabbed to gitter and was like O_o
<FromGitter> <ImAHopelessDev_gitlab> going to work for 3 days, not coding for another 3 bcz busy doing other stuff, then coming back to your code: wtf i wrote all this?? when? πŸ˜‚πŸ˜‚
_ht has joined #crystal-lang
ur5us has quit [Ping timeout: 255 seconds]
<FromGitter> <watzon> Ok so I can't figure out what the deal with this is. Maybe I'll wake up to a surprise and someone will know what's up. I'm getting the following error: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5e4e298040ac4a7fb9f715c8]
<FromGitter> <watzon> The code is the massive mostrosity above
ur5us has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter> <watzon> Ahh I think I got things wrong. It's having an issue with my proc instead. Which is still stupid considering.
_ht has joined #crystal-lang
<FromGitter> <watzon> The proc is defined as `Proc(EventContext, Void)`, so it shouldn't matter what it returns
<FromGitter> <watzon> The weird thing is, it's a non-issue if I use an actual `UpdateAction` instead of a symbol. No clue why.
_ht has quit [Quit: _ht]
_ht has joined #crystal-lang
<FromGitter> <watzon> Figured it out. Had to do something terrible, but it works. Sorry for all the spam. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ There's the monster. [https://gitter.im/crystal-lang/crystal?at=5e4e318c40ac4a7fb9f72cf2]
<FromGitter> <watzon> Sorry for all the spam, but I figured it out. Here's the finished monster: https://github.com/watzon/tourmaline/blob/master/src/tourmaline/handlers/handler.cr
<FromGitter> <watzon> If anyone wants to help me clean it up I'd be more than open to suggestions. I hate building a proc from a string, but it seemed like the most concise way to do it.
_ht has quit [Quit: _ht]
ur5us has quit [Ping timeout: 255 seconds]
gangstacat has quit [Quit: Ĝis!]
gangstacat has joined #crystal-lang
HumanGeek has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
Human_G33k has quit [Ping timeout: 265 seconds]
alexherbo2 has joined #crystal-lang
Nicolab has quit [Quit: Leaving.]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
<FromGitter> <shaurya-xyz> Hi, Does anyone know of good resource to understand how create URI Scheme ? Thanks ⏎ ⏎ I am looking at a custom URI scheme such as this custom://{resource} ⏎ ⏎ Server would serve using the above endpoint and client would have to connect the custom endpoint [https://gitter.im/crystal-lang/crystal?at=5e4e8896dafa3029f640f524]
<FromGitter> <shaurya-xyz> Any documentation or resource in any language would be helpful
<FromGitter> <shaurya-xyz> Thanks!
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <Blacksmoke16> @shaurya-xyz https://crystal-lang.org/api/master/URI.html
Nicolab has joined #crystal-lang
<FromGitter> <shaurya-xyz> @Blacksmoke16 Thank you so much
<FromGitter> <shaurya-xyz> going through it
<FromGitter> <shaurya-xyz> interesting!
<FromGitter> <shaurya-xyz> Thanks again @Blacksmoke16
<FromGitter> <Blacksmoke16> np
<FromGitter> <shaurya-xyz> This is all I need for now to work with my prototype
<FromGitter> <Blacksmoke16> πŸ‘
ancorgs has joined #crystal-lang
<FromGitter> <mavu> Does this error tell anyone anything: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e4ea0f0dafa3029f6414607]
<FromGitter> <tenebrousedge> certificate unknown suggests that it wasn't signed by any trusted authority
<FromGitter> <shaurya-xyz> @mavu the error doesn’t seem to descriptive but usually i have seen this on golang when the certificate authority is unknown or the cert has expeired
<FromGitter> <shaurya-xyz> @Blacksmoke16 Hey just a quick one ⏎ ⏎ divide = 10 / 2 ⏎ float = 10.0 / 2 ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e4ea1b88b2d4664ef14118a]
<FromGitter> <Blacksmoke16> `10 // 2 `
<FromGitter> <Blacksmoke16> // is int division
<FromGitter> <Blacksmoke16> er, but your issue is more so using diff types
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <mavu> @tenebrousedge Ah, that makes sense, as I'm using a self signed cert. ⏎ is there a way to suppress this message? I don't want it to spam my logfiles, and for this software there is no way to use a real certificate
<FromGitter> <tenebrousedge> `//` is int division, `/` is float division, πŸ• is pizza division
<FromGitter> <shaurya-xyz> @Blacksmoke16 yeah typeof as crystal docs
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8lkn yea this is correct
<FromGitter> <shaurya-xyz> @tenebrousedge nice that pie as well huh :D
<FromGitter> <Blacksmoke16> would need to use `//` to get Int versus float
<FromGitter> <shaurya-xyz> https://play.crystal-lang.org/#/r/8lkt
<FromGitter> <shaurya-xyz> makes sense
<FromGitter> <shaurya-xyz> thanks guys just picking up this language today, seems very exciting already !
<FromGitter> <Blacksmoke16> p
<FromGitter> <Blacksmoke16> np
<FromGitter> <tenebrousedge> @mavu are you using a web browser to test?
<FromGitter> <mavu> yes, firefox
<FromGitter> <mavu> nope, strike that.
<FromGitter> <mavu> was using chrome
<FromGitter> <mavu> works in firefox without producing the error.
<FromGitter> <mavu> interesting
<FromGitter> <tenebrousedge> I suspected as much
<FromGitter> <mavu> Ok, I guess I'll live with it. Does end up in STDERR, so I can redirect that into a different logfile. ⏎ thanks @tenebrousedge
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <j8r> ... interesting: https://carc.in/#/r/8lkw
<FromGitter> <Blacksmoke16> https://carc.in/#/r/8lkx
<FromGitter> <j8r> end if there is a `return`, the `ensure` is not executed
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <j8r> more interesting, if a block is involved, it will be called in the `ensure` even if there is a `return`
gangstacat has joined #crystal-lang
Nicolab has quit [Quit: Leaving.]
<FromGitter> <Daniel-Worrall> I don't think ensure is built for returns and that you're getting the exception from the rescue, not the ensure
<FromGitter> <Blacksmoke16> ^
Nicolab has joined #crystal-lang
<FromGitter> <watzon> @Blacksmoke16 did you see my evil creation? https://github.com/watzon/tourmaline/blob/master/src/tourmaline/handler.cr#L19
<livcd> is there any estimation for Windows support ?
<FromGitter> <watzon> Not that I know of
<FromGitter> <watzon> I know they've slowly been making progress release by release
<FromGitter> <watzon> In the most recent release notes they talked about some updates in the Windows department
<FromGitter> <watzon> authors/bcardiff.jpg Brian J. Cardiff 6 days ago ⏎ Crystal 0.33.0 released! ⏎ ⏎ Share ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5e4ebefeb662483a8753d888]
<FromGitter> <noaheverett_twitter> Anyone know why this form of file writing doesn't work as expected? The first block of data is always the only one written
<FromGitter> <noaheverett_twitter> ```f = File.open("file", "wb") do |f| ⏎ f.write data ⏎ f.write otherdata``` [https://gitter.im/crystal-lang/crystal?at=5e4ec20e8e726c7dc5b862b7]
<FromGitter> <noaheverett_twitter> However this one works
<FromGitter> <noaheverett_twitter> ```File.open("file", "wb") do |f| ⏎ f.write data ⏎ f.write otherdata ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e4ec23240ac4a7fb9f8e77b]
<FromGitter> <Blacksmoke16> idt the first one is valid syntax
<FromGitter> <noaheverett_twitter> err I have syntax bug I didn't mean to add in the frirst example
<FromGitter> <noaheverett_twitter> that was a mistake sorry
<FromGitter> <noaheverett_twitter> This is how it reads
<FromGitter> <noaheverett_twitter> ```f = File.open("file", "wb") ⏎ f.write data ⏎ f.write otherdata``` [https://gitter.im/crystal-lang/crystal?at=5e4ec263ff00c664eed5a3a8]
<FromGitter> <tenebrousedge> I would tend to assume that the one that doesn't work closes the file
<FromGitter> <Blacksmoke16> it shouldnt, they're essentially the same but the. block version closes the file after yield
<FromGitter> <Blacksmoke16> versus the method above it, which is the same thing just without the `ensure f.close`
<FromGitter> <noaheverett_twitter> ah ok
<FromGitter> <Blacksmoke16> id try closing the file, or `flush` maybe
<FromGitter> <Blacksmoke16> closing it would inherently flush, or really just use the block version if you dont need the file for anything else
<FromGitter> <noaheverett_twitter> ahhh you're right, I needed to do `f.close` after I was done writing :facepalm:
<FromGitter> <noaheverett_twitter> thank you!
<FromGitter> <Blacksmoke16> np, again the block version is better if thats all you need to do
<FromGitter> <noaheverett_twitter> out of curiosity, why is the block preferred?
<FromGitter> <noaheverett_twitter> is there a performance gain?
<FromGitter> <Blacksmoke16> less chance of you forgetting to close the file
<FromGitter> <tenebrousedge> ^
<FromGitter> <noaheverett_twitter> oh haha
<FromGitter> <noaheverett_twitter> good to know thank you
<FromGitter> <Blacksmoke16> which could lead to too many open files error
<FromGitter> <wout> I have a class which includes `JSON::Serializable` and created an instance of it using `.from_json`. What would be the best way to update the same instance, having a new json string with the same keys?
<FromGitter> <Blacksmoke16> not sure i follow
<FromGitter> <tenebrousedge> I would create a new struct, preferably
<FromGitter> <Blacksmoke16> oh so like given a new JSON string update the values of the obj?
<FromGitter> <tenebrousedge> unless there were a really good reason to use a mutable class, I would avoid that
<FromGitter> <Blacksmoke16> ```obj = Obj.from_json %({"id":1}) ⏎ obj.id # => 1 ⏎ obj.update %({"id":2") ⏎ obj.id # => 2``` [https://gitter.im/crystal-lang/crystal?at=5e4ec4424609ce3a881575d4]
<FromGitter> <Blacksmoke16> something like that?
<FromGitter> <Blacksmoke16> i would add a method to `Obj` that is like `def merge(other : self)`
<FromGitter> <Blacksmoke16> to apply the values of `other` onto `self`
<FromGitter> <tenebrousedge> <_<
<FromGitter> <wout> @tenebrousedge Ok, makes sense. I do no have a really good reason to make the object mutable other than convenience.
<FromGitter> <Blacksmoke16> or as @tenebrousedge said, is there any reason not to just use the obj associated with the new data?
<FromGitter> <Blacksmoke16> @watzon i have
<FromGitter> <wout> @Blacksmoke16 True, I'll do that.
<FromGitter> <Blacksmoke16> @watzon `inputs = arg.restriction.inputs` idt that would compile?
<FromGitter> <Blacksmoke16> there's no `#inputs` method on `ASTNode`
<FromGitter> <watzon> Yep it does somehow
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <watzon> Come to think of it don't know how it does
<FromGitter> <watzon> But it does lol
<FromGitter> <Blacksmoke16> oh i see
<FromGitter> <Blacksmoke16> since you check explicitly for `proc`
<FromGitter> <watzon> Ahh yeah
<FromGitter> <Blacksmoke16> could prob clean it up by doing like `for handler in Tourmaline::Handler.subclasses.select { |h| h.has_constant? :ANNOTATION }`
<FromGitter> <watzon> Ahh yeah, good idea
<FromGitter> <Blacksmoke16> @tenebrousedge I do have a use case where i need something like that
<FromGitter> <Blacksmoke16> i.e. need to load a record from the db, apply the properties of a new property, and return the original from the db
<FromGitter> <tenebrousedge> @Blacksmoke16 I believe you
<FromGitter> <Blacksmoke16> would be nicer if the serializer could handle providing the db obj and then just calls the setter for each property on it, using the getter for the other obj
<FromGitter> <noaheverett_twitter> Ok one more question: I have a Byte array that I'd like to send to a user's browser as binary however when I'm sending (via Kemal) it comes out as `Bytes[255, 216, 255, 224 ...`
<FromGitter> <noaheverett_twitter> Sending with `env.response.print buf[0, bytes_read]`
<FromGitter> <noaheverett_twitter> how do I convert that Byte array to binary representation that the user's browser can read as the file I'm sending?
<FromGitter> <noaheverett_twitter> I found https://github.com/crystal-lang/crystal/wiki/FAQ#user-content-is-there-an-equivalent-to-rubys-arraypackstringunpack but I'm having a little trouble groking it
<FromGitter> <Blacksmoke16> prob something to do with content type?
<FromGitter> <tenebrousedge> do you want to send it as a file attachment?
<FromGitter> <tenebrousedge> that would be content-disposition, IIRC
<FromGitter> <noaheverett_twitter> in this case inline, however I think it's breaking because my browser is receiving the interpretation as:
<FromGitter> <noaheverett_twitter> `Bytes[255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 219, 0, 67, 0, 5, 3, 4, 4, 4, 3, 5, 4, 4, 4, 5, 5, 5, 6, 7, 12, 8, 7, 7, 7, 7, 15, 11, 11, 9, 12, 17, 15, 18, 18, 17, 15, 17, 17, 19, 22, 28, 23, 19, 20, 26, 21, 17, 17, 24, 33, 24, 26, 29, 29, 31, 31, 31, 19, 23, 34, 36, 34, 30, 36, 28, 30, 31, 30, 255, 219, 0, 67, 1, 5, 5, 5, 7, 6, 7, 14, 8, 8, 14, 30, 20, 17, 20,
<FromGitter> ... 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, 194, 0, 17, 8, 4, 176, 3, 132, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 28, 0, 0, 2, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0 ... [https://gitter.im/crystal-lang/crystal?at=5e4ec82b4609ce3a881583b3]
<FromGitter> <noaheverett_twitter> that's what is shown in the browser, same as if I printed it out to the console via Crystal
<FromGitter> <Blacksmoke16> idt think you want print
<FromGitter> <Blacksmoke16> that just `.to_s` whatever you give it
<FromGitter> <noaheverett_twitter> oh I see
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/IO.html#write(slice:Bytes):Nil-instance-method
<FromGitter> <Blacksmoke16> prob want that that would write the bytes
<FromGitter> <tenebrousedge> this maybe should be using a websocket?
<livcd> are there any GUI apps in Crystal ?
<FromGitter> <noaheverett_twitter> I'm basically trying to implement a low level "send_file"
<FromGitter> <noaheverett_twitter> because I have to parse the chunks of the file
<FromGitter> <Blacksmoke16> like that?
<FromGitter> <noaheverett_twitter> ah ok yeah I can probably pull what I need from that, thanks! I didn't know if there was a way to convert Byte array (Slice) to some version to be sent to browser
<FromGitter> <noaheverett_twitter> thanks again
<FromGitter> <Blacksmoke16> np
<FromGitter> <noaheverett_twitter> ah ok figured it out to send the data and not convert with "to_s" is `env.response.write` instead of `env.response.print`
<FromGitter> <Blacksmoke16> right, which is what i linked, must have missed it :p
<FromGitter> <noaheverett_twitter> you're right I did miss it, sorry...I feel like a novice today! I appreciate everyone's help tremendously...coming from the ruby world and re-building parts of a web app in Crystal. Truly wonderful language!
<FromGitter> <tenebrousedge> ^_^
<FromGitter> <Blacksmoke16> athena is where its at πŸ˜‰
_ht has joined #crystal-lang
<FromGitter> <watzon> I know there's a "destructor" type thing for Crystal, but I can't remember what it is
<FromGitter> <watzon> `finalize`?
<FromGitter> <watzon> Does everything get garbage collected on SIGINT?
alexherbo2 has joined #crystal-lang
<FromGitter> <watzon> I just need a good way of making sure something runs before the program exits
<FromGitter> <tenebrousedge> https://crystal-lang.org/api/0.20.1/toplevel.html#at_exit%28%26handler%3AInt32-%3E%29-class-method
<FromGitter> <watzon> Forgot that existed!
alexherbo24 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 255 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <watzon> Hmm weird, it doesn't work with SIGINT apparently
<FromGitter> <watzon> But `Signal::INT.trap` works
<FromGitter> <watzon> Damn haha. Oh well, using Signal works for now
<FromGitter> <watzon> Just not as convenient
<FromGitter> <watzon> Is there a way on `Signal::INT` to prevent `^C` from being written to the terminal?
alexherbo2 has quit [Ping timeout: 260 seconds]
<FromGitter> <naqvis> you would need to disable the `ECHO` on terminal, via invoking `LibC.tcsetattr`
<FromGitter> <naqvis> but ensure you capture the state and restore back at exit or terminal won't display any character
Nicolab has quit [Quit: Leaving.]
<FromGitter> <eliasjpr> Does crystal has a built in function to get file tags?
ur5us has joined #crystal-lang
<FromGitter> <watzon> Tags?
<FromGitter> <tenebrousedge> 🏷️
<FromGitter> <tenebrousedge> ctags maybe?
<FromGitter> <watzon> Idk why that would be built in though, or even necessary for the most part
<FromGitter> <watzon> @eliasjpr what are you talking about?
<FromGitter> <eliasjpr> File metadata, for instance an mp3 file has artist, title, year, album etc
<FromGitter> <tenebrousedge> that's specific to MP3
<FromGitter> <eliasjpr> yes
<FromGitter> <tenebrousedge> or rather the ID3 container format
<FromGitter> <eliasjpr> but images have Exif metadata
<FromGitter> <watzon> The answer to that would be no
<FromGitter> <watzon> There's no built in way anywah
<FromGitter> <eliasjpr> so I was wondering if crystal has something similar
<FromGitter> <watzon> But there are some libraries that allow access to some metadata
<FromGitter> <tenebrousedge> Crystal doesn't have built-in support for anything except filesystem attributes
<FromGitter> <eliasjpr> Got it
<FromGitter> <eliasjpr> That's fine, just want to make sure I am not recreating work already done
<FromGitter> <watzon> Nope. Definitely something that's needed
<FromGitter> <watzon> Not easy to do
<FromGitter> <eliasjpr> I found quite few c libraries that can do this, just need to add some bindings
<FromGitter> <watzon> Especially for some formats
<FromGitter> <tenebrousedge> there are definitely c libraries that do these things
<FromGitter> <eliasjpr> Im going to try to bind one of those libs to crystal
<FromGitter> <tenebrousedge> I'd probably give some serious thought to just wrapping `exiftool`
<FromGitter> <tenebrousedge> but I'm lazy like that
<FromGitter> <eliasjpr> I think I can relate
<FromGitter> <eliasjpr> Thanks for the link very helpful
_ht has quit [Quit: _ht]
sagax has quit [Ping timeout: 272 seconds]
dostoyevsky has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> Is there still no way to export a C interface from Crystal?
<FromGitter> <watzon> I've got someone wanting to make a metacall (https://metacall.io/) loader for Crystal, but I don't know enough about making shared libraries with Crystal, or if it's even possible. I wish Crystal's compiler was more up to speed with `rustc`
dostoyevsky has joined #crystal-lang
<sorcus> Hi :-)
<sorcus> https://gist.github.com/MrSorcus/55f04bd812d20f005844d963ff6f36fc - i've rewrite some part of my script. Is this a good code now? :-D
<FromGitter> <watzon> Looking good sorcus
<sorcus> watzon: I'm happy. Thank you. :-)
<FromGitter> <eliasjpr> @watzon I think I saw a shard that tried to automatically do that
<FromGitter> <watzon> Well there is a shard that allows you to generate C bindings, as in C->Crystal, but afaik there's nothing that allows you to export a C interface *from* Crystal.
<FromGitter> <Blacksmoke16> got myself a jetbrains license for athena dev :p
ur5us_ has joined #crystal-lang
ur5us has quit [Ping timeout: 248 seconds]