<FromGitter>
<dscottboggs_gitlab> well, for more generic use case, you could do 8 << 10 but I agree that it makes sense to have 8.kb as well
<FromGitter>
<j8r> Monkey patching Int is a bad idea
<FromGitter>
<dscottboggs_gitlab> I agree, I think it should be a part of Int
<FromGitter>
<j8r> I see the usefulness of having a lib to convert MiB to MB to Mb
<FromGitter>
<j8r> It should be a shard
<FromGitter>
<dscottboggs_gitlab> idk having a shard for shifting by multiples of 10 and multiplying/dividing by 8 seems like a fast-track to node's dependency insanity. but there's already Int.second etc, why wouldn't there by an Int.kb/mb etc
faitswulff has joined #crystal-lang
moei has joined #crystal-lang
non-aristotelian has quit [Quit: non-aristotelian]
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
faitswulff has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<mwean> Let's say I have a yaml document that I know is a Hash(String, Int), is there any way to express that so I don't have to do something like iterate over it first?
<FromGitter>
<dscottboggs_gitlab> this invokes your operator and does what you intended
<FromGitter>
<girng> sweet, thanks again
faitswulff has joined #crystal-lang
faitswulff has quit [Ping timeout: 252 seconds]
francisl has quit [Quit: francisl]
<FromGitter>
<mwean> Hmm I'm having more yaml troubles
<FromGitter>
<mwean> I'd like to use `YAML::Serializable`, but I don't know what the keys will be
<FromGitter>
<mwean> I just know it's a hash of string => string
<FromGitter>
<mwean> and I'm getting `can't cast YAML::Any to Hash(String, String)`
<FromGitter>
<mwean> even though I swore that worked before...
<FromGitter>
<mwean> I can do `YAML.parse(yaml).as_h.map { |k, v| [k.as_s, v.as_i] }.to_h`, but the type of that is coming out as `Hash(Int32 | String, Int32 | String)` ๐
<FromGitter>
<rishavs> Just saw the updated results at https://github.com/the-benchmarker/web-frameworks โ Why is spider-gazelle at least 4 times faster than the next fast crystal framework?? o.0
<FromGitter>
<rishavs> Specially considering they use the same builtin Http::Server
<FromGitter>
<bew> @mwean don't use `YAML.parse`
<FromGitter>
<bew> For your usecase you can do `Hash(String, String).from_yaml(some_yaml)`
<FromGitter>
<mwean> ๐ฎ
<FromGitter>
<mwean> that's awesome, thanks!!
<FromGitter>
<bew> @dscottboggs_gitlab oh right sorry, unix sockets are supported in `HTTP::Server` but not yet in `HTTP::Client`.. It seems
<FromGitter>
<bew> @straight-shoota do you plan on adding this?
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<bew> @mwean `YAML.parse` & `JSON.parse` are the kind of things that you should almost never use unless you have no other choice
<FromGitter>
<dscottboggs_gitlab> @bew thanks, I'll just use TCP for now. :)
<FromGitter>
<girng> @bew if structs are generated on the stack, does that mean if i were to use them in a game loop, could i possibly get a stack overflow error?
faitswulff has joined #crystal-lang
<FromGitter>
<girng> i'm just trying to understand the struct vs class stuff more. for example, if you look here: https://play.crystal-lang.org/#/r/5593, the `+=` does not work if it's a `struct`. but if i were to change that `struct` to a `class` it works just fine
<FromGitter>
<girng> or, i could use d scott bogg's solution but i'm puzzled on why this is like this
<FromGitter>
<bew> Structs are passed by copy, so doing `new_player.position` will get you a copy of the vector..
<FromGitter>
<girng> "are passed by" meaning accessing it, or only by passing it as a parameter to another method?
faitswulff has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> @girng #4933
moei has quit [Read error: Connection reset by peer]
moei has joined #crystal-lang
<FromGitter>
<girng> i have an idea about a solution, can i post it there?
<FromGitter>
<bew> Sure
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<girng> i'm just going to use a class, holy smokes batman!!
<FromGitter>
<bew> If you're worried about the gc using precious time to allocate all these little classes, i may have a solution to pre-allocate a lot of them in 1 gc call, i have a working poc of this
<FromGitter>
<bew> But it's a hack of the type system in Crystal..
<FromGitter>
<bew> As in: i create a class from a pre-allocated (uninitialized) memory area
<FromGitter>
<girng> @bew i need to make an example of something was going to ask u but i figured if i make it in code it's better explained
<FromGitter>
<girng> @bew here: https://paste.ee/p/w2UXB my memory usage stays at 0.0 it doesn't even go up at all. but i'm passing the struct's by copy (duplicating), and creating a new Hash (heap memory allocation!) every new tick.
<FromGitter>
<bew> What are you trying to show?
<FromGitter>
<girng> in my mind this constitutes as a memory leak and i don't even see any increase in memory usage in `top` or `htop`
<FromGitter>
<girng> i don't understand why it's NOT leaking memory
<FromGitter>
<bew> @girng you're not storing the hash, or saving it somewhere, you use the same variable to save all the hashes, so basically when you re-assign the var, the previous hash becomes unreachable, and will be gc-ed
robacarp has joined #crystal-lang
<FromGitter>
<girng> so basically each iteration, it's re-assigning the new hash and freeing up the previous ones memory space?
<FromGitter>
<bew> It's not immediately deallocated
maxpowa has joined #crystal-lang
davic has joined #crystal-lang
sevensidedmarble has joined #crystal-lang
<FromGitter>
<bew> But yes that's the general idea
<FromGitter>
<girng> ty 4 help
<FromGitter>
<girng> i feel more confident
<FromGitter>
<bew> Yw ;)
baweaver is now known as baweaver_away
<FromGitter>
<girng> im really loving the built in benchmarking , so easy..
<FromGitter>
<j8r> Your serialize with from_json, not with JSON.parse which produces JSON::Any
<FromGitter>
<girng> TEXT
<FromGitter>
<girng> i thought json.parse shouldn't really be used
<FromGitter>
<girng> but if from_json is slower than json.parse, i don't know what to do
<FromGitter>
<j8r> but from_json is called from an object
<FromGitter>
<bew> @girng but you don't get the same data output, you still need to do some transformation from the json any to get your hash, try benching that too
<FromGitter>
<bew> I don't get it, what do you expect to get?
<FromGitter>
<j8r> having the epoch time, the time since the UNIX epoch
<FromGitter>
<j8r> which is 1970/01/01
<FromGitter>
<straight-shoota> @bew The HTTP client needs a lot of improvements, Unix sockets are just one of them. It needs some progress on #6011
<FromGitter>
<straight-shoota> @j8r take a look at what `Time::Span#seconds` returns: `the number of full seconds of the minute (0..59) in this time span.`
<FromGitter>
<straight-shoota> You're looking for `#total_seconds`
<FromGitter>
<bew> @straight-shoota I thought so too
<FromGitter>
<j8r> @straight-shoota yes but you are adding a lot more methods, for something that already exists : UNIX epoch is a `Time::Span` by essence
<FromGitter>
<straight-shoota> That's true
<FromGitter>
<straight-shoota> The question is, should it be expressed as `Time::Span` or a simple integer (which is commonly used for Unix timestamps).
<FromGitter>
<straight-shoota> It simplifies the API avoiding several methods for different return types. That's definitely a plus.
<FromGitter>
<j8r> second and milliseconds are the most widespread, yes. But there are also epoch days in some places, like in `/etc/shadow`
<FromGitter>
<straight-shoota> Such use cases are of minor relevance, since it is super easy to implement a special case yourself.
<FromGitter>
<j8r> Then some will finally end up by creating a `Time::Span` :/
<FromGitter>
<straight-shoota> Looking at the use cases in stdlib, it usually expects an integer, thus `to_unix` would need to be changed to `to_unix.total_seconds`.
<FromGitter>
<straight-shoota> That's a little more verbose, but probably okay.
<FromGitter>
<straight-shoota> But using the `Time::Span` in between also adds some overhead in terms of additional calculations including nanoseconds.
<FromGitter>
<straight-shoota> I'm not sure that can be justified by a simplified API... Getting the number of seconds since Unix epoch as integer is by far the most common use case and it is implemented as a simple integer subtraction. Putting a `Time::Span` in between adds some complexity that is often not necessary.
<FromGitter>
<straight-shoota> It's not even consistent which one is faster
<FromGitter>
<j8r> I'm wondering, we'll also need a `#from_unix` if we have `to_unix`
<FromGitter>
<straight-shoota> `Time.unix` as proposed in #6662 with an overload accepting `Time::Span`
<FromGitter>
<straight-shoota> Could be `.from_unix`, not sure if that matters
<FromGitter>
<straight-shoota> I wrapped the benchmark in loops of 1000 iterations, and it shows `#to_unix` more consistently about 10% faster than `#epoch`. Which seems odd. Might be some strong optimization.
<FromGitter>
<j8r> ?! ๐ฎ
<FromGitter>
<j8r> Despite having big performance difference, for me correctness is the more important aspect
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<straight-shoota> None of both approaches is more "correct" than the other
<FromGitter>
<vladfaust> Hello, could you please answer this question: if I'm a freelancer, can I create easy-to-distribute binaries of Crystal apps without revealing source code?
<FromGitter>
<vladfaust> And ship the to my clients
<FromGitter>
<straight-shoota> Sure. A binary never contains source code.
<FromGitter>
<vladfaust> I mean this static linking stuff
<FromGitter>
<vladfaust> Once a binary built on my Ubuntu, can it be used on a client's machine?
<FromGitter>
<rishavs> Can anyone give a short example of making a json out of an array using to_json?
<FromGitter>
<vladfaust> > Once a binary built on my Ubuntu, can it be used on a client's machine? โ โ I assume no because there could be libs mismatch, right?
<FromGitter>
<rishavs> wouldn't the libs themselves be compiled into the binary?
<FromGitter>
<rishavs> as long as the cpu architecture is the same, you should be able to use the binary
<FromGitter>
<vladfaust> I want approval of this from other users as well, thanks @rishavs
rohitpaulk has joined #crystal-lang
<FromGitter>
<j8r> @vladfaust better to build on Alpine Linux
<FromGitter>
<vladfaust> @j8r, would that work in client's Ubuntu machine?
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter>
<j8r> The only requirement is to have a libc not ancient, because calls may not exists. Maybe for systems with kernels like 2.6.x ,not sure
<FromGitter>
<j8r> If you have 3.x or 4.x, the libc isn't a problem for sure
<FromGitter>
<vladfaust> Wouldn't I experience issues with OpenSSL bindings?
<FromGitter>
<j8r> No, everything is on the binary :)
<FromGitter>
<vladfaust> Asome
rohitpaulk has joined #crystal-lang
<FromGitter>
<j8r> This also simplify deployments
<FromGitter>
<vladfaust> I believe so
<FromGitter>
<vladfaust> However been using Dokku with Dockerfile build for my projects
<FromGitter>
<vladfaust> But working with clients need another approach I guess
<FromGitter>
<j8r> Hum @straight-shoota , you may have text in a binary. for example `head /bin/sh`
<FromGitter>
<vladfaust> BTW, regarding to licensing. Apart from Ruby when source is always shipped, there can be a separate licensing model for Crystal shards - use in a developer team based on amount of employees and ship built binaries to any amount of clients
faitswulff has joined #crystal-lang
<FromGitter>
<straight-shoota> @j8r Yeah, binaries contain symbol names and stuff. But (Crystal) binaries don't contain source code.
<FromGitter>
<j8r> html is put in the binary as text for example. At the end all is binary, but this portion represents text
<FromGitter>
<straight-shoota> What? That's embedded HTML source code. It doesn't contain it's own Crystal source code.
<FromGitter>
<j8r> So crystal binaries may contain text, but not Crystal source code as text
DTZUZO has joined #crystal-lang
<FromGitter>
<straight-shoota> They may also contain Crystal source code as text. But not their *own* source code. (Unless explicitly embedded)
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
<FromGitter>
<straight-shoota> I can't edit wiki pages anymore. Has there been a change to access rights?
faitswulff has quit [Remote host closed the connection]
francisl has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> I like the idea of having `Time#to_unix` return a `Time::Span`, which can then be used to get the necessary granularity. Perhaps it could have a `#to_i` which returns the seconds? Or would that be confusing since it actually refers to the particular nanosecond value?
faitswulff has quit [Remote host closed the connection]
<FromGitter>
<codenoid> #6900 hmmm
faitswulff has joined #crystal-lang
wuehlmaus has left #crystal-lang ["Aus, die Maus"]
[spoiler] has quit [Quit: Cheers!]
[spoiler] has joined #crystal-lang
[spoiler] has quit [Client Quit]
[spoiler] has joined #crystal-lang
faitswulff has quit []
<FromGitter>
<proyb6> Have any of your Crystal app get audit by your Auditors or clients, I wonder what they are usually looking for
<FromGitter>
<bararchy> @proyb6 What do you mean by "audit"? security or technical due diligence
francisl has quit [Quit: francisl]
francisl has joined #crystal-lang
<FromGitter>
<proyb6> @bararchy On security side which I see most organisations have legacy applications with huge codebase wrote in PHP on an legacy web framework like Yii1 EOL is on 2020, how does one encourage the team to adopt alternative language like Crystal if they can reduce code complexity?
<FromGitter>
<bararchy> @proyb6 Security side is mostly bussines-logic and application level vulenrabilties, such as OWASP top 10 (XSS,SQLi,etc..) and things like Authentication bypass, access to unauthorized data via user id manipulation, cookie manipulation (injections, xss and session fixation) โ Those things are languge agnostic and depends more on the application logic and tech stack
<FromGitter>
<codenoid> it's depend on your code
<FromGitter>
<bararchy> ^ exactly
<FromGitter>
<drum445> Do you guys see many use cases for interfaces/abstract classes?
<FromGitter>
<proyb6> @bararchy I see, true is depend on our code, I think we need some articles on writing the secure app with Crystal after seeing too many introductions about Crystal.
<FromGitter>
<drum445> If you're creating a web app, kemal-session and the default sql library is a good place to start.
<FromGitter>
<bararchy> @proyb6 Well, it can be a nice writeup, maybe I'll try to do something, but it mostly revolves around "don't re-invent security features" and use common tools and configurations that have been proven
<FromGitter>
<drum445> You do see a lot of people trying to rewrite things that have already become industry standards
<FromGitter>
<proyb6> Awesome, thatโs a good ones
<FromGitter>
<straight-shoota> > use common tools and configurations that have been proven โ And that needs people talking about it
<FromGitter>
<bararchy> @straight-shoota true, I can say that as of now, we have tested multiple features of Crystal both Core and Kemal for sec issues, and posted and fixed anything we found
<FromGitter>
<straight-shoota> ๐
<FromGitter>
<straight-shoota> Yeah I think it's about knowing which common security problems need attention, which standard procedures exist to solve them and what tools are available for that in the ecosystem you're using.
<FromGitter>
<proyb6> in additional, RoboCop are a nice code checker for Ruby, we need one for Crystal
<FromGitter>
<vladfaust> We have ameba
<FromGitter>
<proyb6> Oh right, forgot about it and definitely need help on their Roadmap
<FromGitter>
<mwean> it seems like the type should be clear from that
francisl has quit [Quit: francisl]
<FromGitter>
<Sija> @vladfaust `Time | Nil` (or better `Time?`) is `Union(Time, Nil)`, not `Union(Time | Nil)`, just FYI
<FromGitter>
<bew> @mwean The error also explains how the type inference work, and what works to auto-type an instance variable. So in this case you have to declare `@next_port : Int32` in the class (outside methods)
<FromGitter>
<dscottboggs_gitlab> logically speaking wouldn't Unions flatten? so that *union of time and nil* and *union of time and time and nil* would be the same thing?
<FromGitter>
<Sija> @vladfaust `Time | Nil` itself is an `Union` itself, no need for wrapping it in another `Union`
<FromGitter>
<Sija> @dscottboggs_gitlab they do, but writing `Union(Time | Nil)` instead of `Time | Nil` is justโฆ confusing?
<FromGitter>
<dscottboggs_gitlab> I agree, but it wouldn't not work. ha
<FromGitter>
<mwean> @bew ah, so the problem is the `+ 1`. I see it works if I remove that. That's pretty strange, but thanks!
<FromGitter>
<bew> It's all explained in the error :)
<FromGitter>
<bew> But yeah, the + 1 is a method call to `Int32#+` and the compiler does go through method calls
<FromGitter>
<mwean> I guess you could say it's explained in the error, but I assumed that `arg` was just a placeholder and that a pure function and referential transparency would imply that `Int32 + Int32` could be reduced to `Int32`
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter>
<fridgerator> The author uses crystal in the Dockerfiles
baweaver_away is now known as baweaver
francisl has joined #crystal-lang
<FromGitter>
<bew> This is pretty cool!
<FromGitter>
<girng> what is a Kubernete
francisl has quit [Quit: francisl]
<FromGitter>
<fridgerator> Container orchestration software written by Google
akaiiro has joined #crystal-lang
<FromGitter>
<Blacksmoke16> what docker swarm should be
<FromGitter>
<girng> not even going to google that, im already lost
DTZUZO has joined #crystal-lang
<FromGitter>
<Blacksmoke16> docker is great
<FromGitter>
<fridgerator> Yep
<FromGitter>
<fridgerator> I'm trying to use crystal_lib to generate bindings from a .h file. The .h file is located in another directoy and the `@[Include` is just the full path to the .h file
<FromGitter>
<fridgerator> The .h file includes relative `#include` statements, but it seems crystal_lib doesn't follow these? I get fatal error file not found for those includes
<FromGitter>
<fridgerator> Do I need to move all of the .h files into my `crystal_lib` dir or something?
<FromGitter>
<vladfaust> Thanks, Sija, I didnโt know that
<FromGitter>
<vladfaust> Related to my issue in crystal, right?