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 [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
lanodan has quit [Quit: WeeChat 2.9]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
lanodan has joined #crystal-lang
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
zorp_ has joined #crystal-lang
zorp has quit [Ping timeout: 256 seconds]
Stephanie has quit [Quit: Fuck this shit, I'm out!]
Stephie has joined #crystal-lang
Liothen has quit [Ping timeout: 260 seconds]
Liothen has joined #crystal-lang
yukai has quit [Ping timeout: 260 seconds]
andremed- has joined #crystal-lang
andremedeiros has quit [Ping timeout: 240 seconds]
andremed- is now known as andremedeiros
ua_ has quit [Ping timeout: 260 seconds]
ua_ has joined #crystal-lang
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
HumanG33k has quit [Quit: Leaving]
Vexatoast has joined #crystal-lang
Vexatos has quit [Ping timeout: 264 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
hightower2 has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
<holst> How do one access the available disk space using the standard library? Is it possible?
<FromGitter> <Blacksmoke16> i doubt it. Not without doing some shell command
<holst> I am fine with that, I like a non-bloated STD lib :)
<holst> so, doing process execution and parsing its output what API calls should I look to?
<jhass> for a static command, backticks should cut it :)
<jhass> https://crystal-lang.org/api/0.35.1/toplevel.html#%60(command):String-class-method
<jhass> then all the String and Enumerable fun stuff
<holst> oh, thats fantastic
<jhass> depending on your portability requirements you also may want to scout through /proc for the info you're after, the data in there is usually easier to parse and it's faster because you just need to read a file rather than spawning a subprocess
<FromGitter> <Blacksmoke16> looks like https://github.com/crystal-community/hardware has an issue/PR for it as well
<jhass> holst: stracing' df, it seems to make use of the statfs syscall: https://man7.org/linux/man-pages/man2/statfs.2.html, binding that could also be a fun exercise :)
<FromGitter> <j8r> there are missing bindings in the stdlib
<FromGitter> <j8r> statfs notably https://golang.org/pkg/syscall/#Statfs
<jhass> why go docs now? *confused*
<FromGitter> <j8r> because that's a language providing statfs, which is not available in Crystal :(
<FromGitter> <j8r> so, it could help I think
<jhass> not sure how it's more helpful than the man page and C bindings docs I linked :)
<jhass> it's a syscall, so it's just mapping out the struct and writing the binding definition
<FromGitter> <j8r> right I didn't see it
<FromGitter> <j8r> I was searching this
<FromGitter> <j8r> I think it will be a good addition to Crystal to have it
<jhass> I think it's an excellent thing for a shard
<FromGitter> <j8r> Maybe for the high-level API yes
<jhass> all C bindings stdlib does are internal and not be seen as a provided "low level API"
<FromGitter> <j8r> Too bad :(
<FromGitter> <j8r> I'd love to have a central place with all Linux C bindings
<FromGitter> <j8r> Like Go or Rust
<jhass> get https://github.com/ysbaddaden/posix back into shape :)
<FromGitter> <naqvis> Just released a *Data Wrangling* shard CrysDA (https://github.com/naqvis/CrysDA) with below features ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f970105a7e77a0ff1706341]
<FromGitter> <christopherzimmerman> Wow, looks fantastic!
<FromGitter> <naqvis> ❤️
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <christopherzimmerman> Do you use all runtime type checks? Any plans to support compile time type checking?
<FromGitter> <naqvis> checks are performed only at data loading time
<FromGitter> <naqvis> reason is due to dynamic nature of data loading
<FromGitter> <christopherzimmerman> Isn't it also checked each time you call an operation? https://github.com/naqvis/CrysDA/blob/master/src/crysda/columns.cr#L631
<FromGitter> <naqvis> true, but that's to deal with Unions and Nils
<FromGitter> <naqvis> how can you perform a check on data which you don't know at compile time?
HumanG33k has quit [Quit: Leaving]
<FromGitter> <j8r> that looks a powerful library :O
<FromGitter> <j8r> @naqvis your work is always impressive, you're so ahead of me in term in mathematics 😅
<FromGitter> <naqvis> thanks @j8r , indeed it is
<FromGitter> <naqvis> hahahahaha
<FromGitter> <naqvis> Crystal is really awsome, so hope such contributions can bring more audience
<FromGitter> <j8r> so, we can manipulate data to transform to another, like a Struct(s) to another one(s)?
<FromGitter> <naqvis> i wish we can, but Crystal doesn't support reflection
<FromGitter> <naqvis> and I don't like to *ab*use macros 😆
<FromGitter> <j8r> https://github.com/j8r/crystalizer could be useful for this case
<FromGitter> <j8r> (might be)
<FromGitter> <j8r> one could implement a new format, and transform any object to another one
<FromGitter> <naqvis> agree
<FromGitter> <christopherzimmerman> Yea, the closest I could get was NamedTuple mapping, and I wasn't really a fan of that to keep track of types. I guess checking once per op isn't too big a performance hit.
<FromGitter> <christopherzimmerman> What is backing your Datacols right now? Just an Array, Pointer, Slice?
<FromGitter> <j8r> I was going to ask a similar question, it is related to CSV/TSV I guess?
<FromGitter> <naqvis> Array :P
<FromGitter> <naqvis> One dimensional array of specific type
<FromGitter> <naqvis> e.g `Int32Col` is storing its data inside `Array(Int32?)`
<FromGitter> <j8r> that's `@values : Array`
<FromGitter> <naqvis> yup
<FromGitter> <christopherzimmerman> If you're interested, I would be interested in working on a PR to make the backend a bit more generic. I'm working on Apache Arrow, Vulkun / Cuda backing for my library right now, it would be cool to support Dataframe operations on a GPU.
<FromGitter> <j8r> there is a bit of duplication
<FromGitter> <naqvis> sure thing and more than welcome
<FromGitter> <naqvis> @j8r duplication in what sense?
<FromGitter> <j8r> It could be solves by using generics, like `DataCol(T)`
<FromGitter> <naqvis> I had to workaround Union hell issue which compiler throws on you :P
<FromGitter> <naqvis> initially all those were part of parent class
<FromGitter> <naqvis> but compiler won't let you pass through it
<FromGitter> <naqvis> simple example Bool doesn't have `<=>` operator
<FromGitter> <j8r> oh, maybe better chance with module?
<FromGitter> <naqvis> and even if you try to be explicit in your code and handle such cases
<FromGitter> <naqvis> but Compiler insists that Union contains this and that
<FromGitter> <j8r> at worst, a macro can also be used
<FromGitter> <naqvis> :P
<FromGitter> <christopherzimmerman> But for those edge cases you can use a bit of macro magic `{% if T == Bool %} <=> {% end %}`
<FromGitter> <christopherzimmerman> Will look a lot cleaner than having a lot of repetitive classes.
<FromGitter> <christopherzimmerman> Plus thats a compile-time check so no runtime performance hits
<FromGitter> <naqvis> tbh there is whole lot of boiler-plate code which could had omitted, only if ....
<FromGitter> <christopherzimmerman> Bools and strings are a pain to deal with when you also want to handle other types :P https://github.com/crystal-data/num.cr/blob/master/src/tensor/tensor.cr#L814-L827
<FromGitter> <naqvis> true, but again as said above, I'm not a big fan of macros
<FromGitter> <naqvis> and avoid them until there is no option left
* FromGitter * Blacksmoke16 wants his custom macro methods
<FromGitter> <naqvis> for sure, would appreciate and welcome PR
<FromGitter> <christopherzimmerman> They can muddy up code if there are a ton of conditional paths, but for just literal repetition it makes things a lot more clear I think.
<FromGitter> <naqvis> :P @Blacksmoke16 the Macro man
<FromGitter> <naqvis> I didn't try to perform any benchmarking on stdlib collection interface and also didn't want to optimize things until there is a solid need for this
<FromGitter> <naqvis> but i'm sure `num.cr` is definitely going to outperform
<FromGitter> <j8r> macro man vs dup man... not sure what's better haha
<FromGitter> <naqvis> on my macbook, whole test suite completes in 1.5s or so
<FromGitter> <naqvis> so I think, it should be reasonable enough for smaller datasets of few MBs
HumanG33k has joined #crystal-lang
<FromGitter> <naqvis> and the heaviest dataset i've tried is around 10M
<FromGitter> <christopherzimmerman> For operations on a flat array, writing the operation on a standard library container will probably be faster. The power of a `Tensor` is that it supports data in n-dimensions, so there is a lot of overhead to iterate through an arbitrarily strided and shaped array.
<FromGitter> <naqvis> agree
<FromGitter> <christopherzimmerman> I would love to see an Apache arrow backend. It's really nice for tabular data. Plus it would allow for data IO from pretty much every other popular dataframe library.
<FromGitter> <naqvis> yeah true and also looking forward to that
<FromGitter> <naqvis> as that will open crystal door to huge ecosystems of all other languages
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <wyhaines> So..... ⏎ ⏎ You have an object, a Hash or an Array or something else, that has a type like `Hash(String, Int32)` or `Array(UInt64)`, as an example. You want to programmatically access the contained types -- `String, Int32` and `UInt64` so that you can generate a union type from them. How?
<FromGitter> <Blacksmoke16> *magic*
duane has joined #crystal-lang
<FromGitter> <Blacksmoke16> ```def foo(hash : Hash(K, V)) forall K, V ⏎ # ... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f9714f9270d004bcff09879]
<FromGitter> <wyhaines> But....I don't already know that I am getting a hash.
<FromGitter> <Blacksmoke16> overloads?
<FromGitter> <naqvis> use `case`
<FromGitter> <wyhaines> I could be getting an Array, or even a data type that isn't part of the standard library.
<FromGitter> <HertzDevil> `Crystal::Macros::Generic#type_vars`?
<FromGitter> <Blacksmoke16> one overload for hash, one for array, one for everything else?
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f971546955f6d78a953a95e]
<FromGitter> <Blacksmoke16> that doesnt help you having access to the generics of a runtime hash/array hto
<FromGitter> <HertzDevil> why do you need a union tho
<FromGitter> <Blacksmoke16> hence why you need the free vars
<FromGitter> <HertzDevil> if you don't know the type, you don't know whether it contains some var whose type is in the generic argument list
<FromGitter> <HertzDevil> `Proc` for example doesn't, obviously
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9vtv
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9vtw even if its duplicated, the compiler dedups https://play.crystal-lang.org/#/r/9vtw
<FromGitter> <HertzDevil> for this particular case you don't need any free types 😎 ⏎ ⏎ ```def foo(arr : Array, new_val) ⏎ [arr.first, new_val] ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f97167298a7774f1b6a8655]
<FromGitter> <wyhaines> True. It's an effort to perform some duck typing magic. ⏎ ⏎ I have a data structure. I want to be able to `merge` anything that has an `#each` method. ⏎ ⏎ `Hash` does what @Blacksmoke16 showed, basically. But then you can only merge other hashes. You can't merge a hash with a hash-like something-else. ... [https://gitter.im/crystal-lang/crystal?at=5f9716be631a250ab293d30f]
<FromGitter> <HertzDevil> how then do you tell that a `Proc` is neither `Array`-like nor `Hash`-like?
<FromGitter> <HertzDevil> seems like it's easier to use `Enumerable` directly
<FromGitter> <HertzDevil> every `Hash(K, V)` is also an `Enumerable({K, V})`
<FromGitter> <Blacksmoke16> that would be the better option yea, overloads for non key/value types would prob work as well
<FromGitter> <wyhaines> I can do it for a `merge!` where the incoming data simply has to survive an `.as(X)` type modification into the current structure's type restrictions.
<FromGitter> <HertzDevil> (this approach then raises the question of whether `Array(Tuple(String, Int32))` should behave like `Hash(String, Int32)`)
<FromGitter> <wyhaines> Hmmm. Is every array type an `Enumerable(X)`? *thinks*
<FromGitter> <naqvis> yes it is
<FromGitter> <HertzDevil> kinda sad crystal doesn't have a module for hash-like types
<FromGitter> <wyhaines> @HertzDevil Yeah. I'm building a Splay Tree implementation that implements most of the Hash interface. In many cases the code to implement a method is the same as the Hash code.
<hightower2> O hey @HertzDevil, awesome work on bindgen !
duane has quit [Ping timeout: 258 seconds]
duane has joined #crystal-lang
louis771 has quit [Ping timeout: 260 seconds]
<holst> Is this Crystal-ideomatic or, is there a better way? spawn name: "webserver" do server.listen end
<holst> idiomatic*
<FromGitter> <Blacksmoke16> is `server` a https://crystal-lang.org/api/master/HTTP/Server.html ?
<holst> I am updating content in a worker Fiber and I want to present it on a http endpoint
<holst> yes, its the standard lib HTTP Server
<oprypin> oh wow @HertzDevil - yes, thank you for https://github.com/Papierkorb/bindgen/commits
<FromGitter> <Blacksmoke16> pretty sure it handles requests via fibers anyway
<FromGitter> <Blacksmoke16> like is there more going on after you spawn the server fiber?
<FromGitter> <j8r> yes it does
<holst> I was thinking about that. Do I need to have a spinloop that only calls Fiber.yield?
<holst> or is that redundant?
<FromGitter> <Blacksmoke16> why?
<FromGitter> <Blacksmoke16> ```server = ... ⏎ ⏎ server.listen``` [https://gitter.im/crystal-lang/crystal?at=5f9723ca270d004bcff0bf3a]
<FromGitter> <Blacksmoke16> is sufficient
<holst> hmm, you got me, maybe I did not even try that
<holst> If that works it means that server.listen indeed uses Fibers I assume
<FromGitter> <Blacksmoke16> it odes
<FromGitter> <Blacksmoke16> does
<holst> mm, indeed it works!
<FromGitter> <Blacksmoke16> 👍
<holst> I like the built in playground so much I would like all my production code to look like this. I attach to the runtime and I get to see a realtime log and metrics correlated with the code. Brilliant
<holst> Too bad the workflow does not scale to other languages
<FromGitter> <Blacksmoke16> isnt that what the log module is for? 😉
<FromGitter> <wyhaines> The Enumerable(X) approach worked well. ⏎ ⏎ I can merge anything array-like or hash-like, now, which is *perfect*.
<FromGitter> <Blacksmoke16> 👍 nice one
<oprypin> have there been any advancements in stable sort (workaround)? compared to https://gist.github.com/bcardiff/5395bfaef35ac1d14a1a#file-stable_sort-cr-L7
<FromGitter> <j8r> oprypin when running locally, I got `[{"Alan", 30}, {"Brian", 42}, {"Brian", 32}]` instead of `[{"Brian", 42}, {"Alan", 30}, {"Brian", 32}]`
<FromGitter> <j8r> both results are the same
<FromGitter> <j8r> I guess it is solved then?
<oprypin> j8r, nah must be an accident
<jhass> accidental sorting! How can we sell this?
<jhass> AccidentSort!™️ Put your big data on the blockchain
<raz> well, the probability of the original input list being in the exact order it's in is 1/(n!)
psydroid has quit [*.net *.split]
<oprypin> raz, i think that's for if all items are equal
<oprypin> actually then nothing will change hmm
<raz> :p
<raz> i'm just saying as long as his product doesn't promise a specific sort order, it could sell
<raz> InstaSort™ powered by Accident
psydroid has joined #crystal-lang
<FromGitter> <RespiteSage> @jhass You gotta put "AI" in there somewhere, too.
<FromGitter> <RespiteSage> @raz "powered by Accident" is a beautiful phrase that I want to integrate into my daily life.
<jhass> :D
<jhass> if I ever make a company I'll call it Accident Technologies
<oprypin> AccIdent anyone?
<raz> def a catchy tagline :D
<FromGitter> <RespiteSage> I think my increment to your tagline is "AccidentSort!™️ Holistically integrate your big data on the AI blockchain"
<oprypin> 😩😩😩
<jhass> while we're at it, lets put some edge computing in
<FromGitter> <RespiteSage> Ooh, yeah. Maybe tack "hosted by the IoT" on the end.
<raz> yea, we need that, it should be mobile first after all
<raz> i feel like we may have the next tiktok on our hands here
<FromGitter> <RespiteSage> @oprypin Was the capital i intentional? Is "AccIdent" a thing?
<oprypin> not a thing (i hope!) but intentional
<raz> it could be a cool name for an identity provider
<FromGitter> <RespiteSage> Yeah, it's a very clever name. The only problem is that it would be impossible to search.
<FromGitter> <RespiteSage> As I discovered when I just tried to figure out if it's a thing. :P
<raz> who needs to search when everyone is talking about you :p
<sorcus> raz: :-D
<sorcus> Hi all :-)
<FromGitter> <RespiteSage> Hey, there.
<raz> o/
louis771 has joined #crystal-lang
<sorcus> Did anyone try to create desktop app on crystal and GTK / Qt?
<sorcus> jhass: Mmm, cool. :-)
louis771 has quit [Ping timeout: 260 seconds]
<sorcus> jhass: Do you use it?
<jhass> no, but I created and sort of maintain https://github.com/jhass/crystal-gobject which it's built upon
<sorcus> jhass: Yeah, i saw it.
<sorcus> Good night :-)
louis771 has joined #crystal-lang
<oprypin> is there a one-level flatten?
<oprypin> i have an array, where each item i will map into a sub-array, but i want to join them into one
<oprypin> >> [(0...3), (1...7)].map(&.to_a).flatten
<FromGitter> <Blacksmoke16> Map &.flatten?
<DeBot> oprypin: # => [0, 1, 2, 1, 2, 3, 4, 5, 6] - https://carc.in/#/r/9vwj
<oprypin> i dont like that `map` is involved
<oprypin> also each of the sub-arrays are redundant
<oprypin> >> a = [] of Int32; [(0...3), (1...7)].each { |e| a.concat(e) }; a
<DeBot> oprypin: # => [0, 1, 2, 1, 2, 3, 4, 5, 6] - https://carc.in/#/r/9vwk
<oprypin> mmm nice
yukai has joined #crystal-lang
<jhass> Ruby's flatten takes an argument for the max depth it descends to
<jhass> might be nice to port
HumanG33k has quit [Ping timeout: 272 seconds]
<FromGitter> <asterite> agreed
zorp_ has quit [Ping timeout: 265 seconds]
<oprypin> is there any nicer way to write `(out_docs[name] ||= [] of String) << "foo"`
<oprypin> i guess https://crystal-lang.org/api/0.34.0/Hash.html#new(block:Hash(K,V),K-%3EV?=nil,*,initial_capacity=nil)-class-method