<FromGitter>
<solisoft> @Porcupine96 you should consider ArangoDB also ... AQL is very useful
snsei_ has quit [Remote host closed the connection]
Tuxified has joined #crystal-lang
Tuxified has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DTZUZO has quit [Ping timeout: 240 seconds]
<oprypin>
kyku, omg so that's the answer to everything
<FromGitter>
<jose-rodrigues> Hello guys. I'm trying to use iconv with crystal but il looks like a little low level is there any other way to convert encodings in crystal?
<FromGitter>
<jose-rodrigues> @oprypin I've look but found nothing to convert. I tryed to use scrub but I get a lot of weird characters
<oprypin>
jose-rodrigues, ok please explain what exactly you're trying to achieve. I haven't seen such a description
bmcginty has quit [Ping timeout: 248 seconds]
bmcginty has joined #crystal-lang
<FromGitter>
<jose-rodrigues> I've a string in windows-1252 and want to convert it to utf-8
<oprypin>
jose-rodrigues, ah perfect, the example i was brewing up is almost exactly matching https://carc.in/#/r/2nn5
<FromGitter>
<kyku> @oprypin , might be, but be sure to catch it....
<oprypin>
i think a crash is appropriate tbh
<oprypin>
it's almost always the behavior i want, clearer than .not_nil! too
<FromGitter>
<sdogruyol> Morning everyone
<oprypin>
python's IO avoids nils in all cases i think. if you expect a string but get EOF, that's the definition of an exceptional case. why return nil, especially if it's at such a huge price of confusion for beginners
<oprypin>
confusion about `gets` is actually a very high percentage of questions here
<oprypin>
i was gonna suggest not returning `nil` from it but with `read_line` already doing that it's a harder case
<oprypin>
just storing arbitrary bytes in a string, that always triggers me
ShalokShalom has quit [Ping timeout: 252 seconds]
<oprypin>
so you're taking bytes, illegally storing them in a string only to immediately get the bytes back, then converting it to a text string properly
<oprypin>
and the 2nd line you're converting text to bytes and back to the same exact text, so it's a no-op
<FromGitter>
<sdogruyol> not everyone is so knowledgable about strings
<FromGitter>
<sdogruyol> and bytes for sure
<oprypin>
it's not even about knowledge, it's blind assumptions of bad practices from ruby
<FromGitter>
<sdogruyol> Ruby makes it so easy to do so ..
<oprypin>
jose-rodrigues, the thing to understand here is that `String` in Crystal is strictly for text. it always must have valid text in it (that internally happens to be represented as UTF-8)
<oprypin>
what went wrong in the first place: texts[0] appears to be bytes illegally stored in a string. they should have been stored in a Slice(UInt8) aka Bytes
<oprypin>
then all you need is `profile.description = String.new(actually_bytes, encoding: "windows-1252").strip`
<FromGitter>
<bew> @jose-rodrigues what is ˋtextsˋ type?
<oprypin>
> texts[0] appears to be bytes illegally stored in a string
<FromGitter>
<bew> Oh that would explain the inner_text thing
<FromGitter>
<jose-rodrigues> @bew text is an object from `myhtml` library
<oprypin>
jose-rodrigues, that's the thing, instead of letting the parser produce illegal strings and dealing with the mess, you should just read the input document in that encoding in the first place
<FromGitter>
<jose-rodrigues> I'm getting them with http::client so i thing in can play woth the ios
<oprypin>
> If a response has a Content-Type header with a charset, that charset is set as the encoding of the returned IO (or used for creating a String for the body). Invalid bytes in the given encoding are silently ignored when reading text content.
<oprypin>
it's too bad that you can't detect when it failed to get the info from content-type
<oprypin>
so will have to hardcode `response.body_io.set_encoding("cp1252")`
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
<FromGitter>
<bararchy> I want to create bindings for TensorFlow for Crystal, this project exists: https://github.com/fazibear/tensorflow.cr , but looking at the code & last time the owner has added code I feel like I should spin a new one
Groogy has joined #crystal-lang
<Groogy>
Morning!
<FromGitter>
<bararchy> Hi Groogy, how goes your day m8 ?
<Groogy>
just woke up, no coffee in bloodstream yet
<Groogy>
;D
<Groogy>
you then?
<FromGitter>
<bararchy> Big mistake XD
<FromGitter>
<bararchy> no coffie in the Praradox office ?
<FromGitter>
<bararchy> hahah
<Groogy>
no I'm at home, it's Sunday
<FromGitter>
<sdogruyol> it's sunday lol
<FromGitter>
<sdogruyol> hahaha
<Groogy>
no but I need to go and buy milk, which means I need to put on pants
<Groogy>
First world problems
<FromGitter>
<sdogruyol> lol
<FromGitter>
<sdogruyol> aint delivery service?
<FromGitter>
<bararchy> Oh, the places where Sunday is day off
<FromGitter>
<bararchy> haha
<FromGitter>
<bararchy> I'll never get used to it
<FromGitter>
<sdogruyol> @bararchy do you officially work on Sunday?
<FromGitter>
<bararchy> ofc
<Groogy>
isn't sabbath on sundays?
<FromGitter>
<sdogruyol> what
<FromGitter>
<bararchy> Exactly
<FromGitter>
<sdogruyol> that's weird
<FromGitter>
<bararchy> Sabbath is day off
<FromGitter>
<sdogruyol> saturday and sunday is off
<FromGitter>
<bararchy> as in Firday
<Groogy>
oh lol
<FromGitter>
<bararchy> Friday & saturday
<FromGitter>
<sdogruyol> a bit different :D
<Groogy>
do you guys also have like USA that the week starts on sunday?
<FromGitter>
<bararchy> Yeha
<FromGitter>
<sdogruyol> oh
<FromGitter>
<sdogruyol> makes sense
<FromGitter>
<bararchy> Sunday even called "First Day" in Hebrew
<FromGitter>
<bararchy> יום ראשון
<FromGitter>
<bararchy> actually translated to "the first day"
<FromGitter>
<sdogruyol> :D
<FromGitter>
<bararchy> lol
<Groogy>
lol
<FromGitter>
<sdogruyol> Monday is literally "After Sunday" in Turkish
<FromGitter>
<bararchy> yeha, not much thought putten into it hahah
<FromGitter>
<bararchy> hahah
<FromGitter>
<bararchy> nice
<Groogy>
Saturday(Lördag) for us means "The day you clean yourself"
<Groogy>
i.e take a shower
<FromGitter>
<sdogruyol> haha
<FromGitter>
<bararchy> Oo
<FromGitter>
<sdogruyol> that's weird
<FromGitter>
<bararchy> LOL really ??
<FromGitter>
<sdogruyol> Cleaning day
<Groogy>
Vikings were really clean compared to other groups during that age ;D
<FromGitter>
<sdogruyol> :D
<FromGitter>
<sdogruyol> respect the beard
<FromGitter>
<sdogruyol> 👍
<Groogy>
Yeah the beard doesn't become so nice and lish without hard effort put in
<Groogy>
lush*
<FromGitter>
<bararchy> XD
<FromGitter>
<sdogruyol> i once had some beard
<FromGitter>
<sdogruyol> it's hard to keep it clean
ShalokShalom_ is now known as ShalokShalom
<Groogy>
either way I am getting quite done in basic for graphics to just "work", wondering if I should implement UI or try and port someone else UI in somehow
<Groogy>
didn't find much in shards that seemed interesting :/
<FromGitter>
<bararchy> Groogy , does you graphic engine is Crystal native ?
<Groogy>
yeah
<FromGitter>
<bararchy> Maybe I'll try doing a simple UI to my port scanner ? Tried in the QT binding but it was too much code for such a small task
<FromGitter>
<bararchy> Is it looking for the shader in a specific dir ?
<FromGitter>
<bararchy> on same dir maybe ?
<Groogy>
the executable needs to be in the dist folder when you run it
<Groogy>
couldn't find a way to tell crystal "build and run this but with this work directory"
<Groogy>
I have a script in VS Code that does it for me
<FromGitter>
<bararchy> Yap, got it to work, horrible red screen and badly drawn smily face :)
<Groogy>
exact ;D
<Groogy>
try to add this to the render method
<Groogy>
@sprite.rotate delta.to_f * 10
<Groogy>
should make it rotate over time
<FromGitter>
<sdogruyol> haha thanks @bararchy :D
<FromGitter>
<bararchy> ? What for
<FromGitter>
<bararchy> Groogy sent you a PR, making your life easy haha
<FromGitter>
<kyku> @oprypin : are you still here?
<Groogy>
oh have you also tried to compile it?
<Groogy>
but yeah to make my workflow make sense, in VS Code I have two batch scripts, one in Boleite that copies over the files so I don't need to commit them all the time
<Groogy>
and then one in Ego that copies the generated executable to where I want to run it
<Groogy>
bash scripts*
<FromGitter>
<bararchy> We can just shove anything intop the Makefile
<FromGitter>
<bararchy> soa single `make` command will do it all
<FromGitter>
<bararchy> I love make files
<Groogy>
I usually use Cmake yeah
<Groogy>
I should redo this to be a cmake script instead
<Papierkorb>
CMake is scary. Until you try other solutions, and suddenly, it's not that scary anymore ;)
<Papierkorb>
I moved, so wasn't near a computer the last days
<FromGitter>
<kyku> Hi
<FromGitter>
<bararchy> Nope, as it might not succed in reading
<FromGitter>
<bararchy> then it will return nil
<Groogy>
Papierkorb also it's what I've always used so ¯\(°_o)/¯
<Groogy>
easier to use the devil you already know
<FromGitter>
<kyku> @bararchy : it will throw if it fails to read...
<Papierkorb>
Absolutely, why change what works just fine
<FromGitter>
<bararchy> Hm.... true
<FromGitter>
<bararchy> my bad
<FromGitter>
<bararchy> Yeha, it should be String then
<Groogy>
isn't nil if it doesn't read anything?
<FromGitter>
<bararchy> it seems it will raise then
<FromGitter>
<bararchy> because if gets fail, it's `raise EOFError.new`
<Groogy>
oh right
<FromGitter>
<bararchy> Got me too hahah
<Groogy>
so might just be that in the source it doesn't ensure String type when returning?
<FromGitter>
<bararchy> so the right return type should be String and not String?
<Groogy>
yeah looking at the source
<Groogy>
oh they specifically define the String?
<FromGitter>
<kyku> Funny thing is that the compiler does not require to use not_nil! on read_line.to_i as it was smarter than what the function "declaration" says
<Groogy>
so guessing just copy paste error
<FromGitter>
<kyku> I will try filling a bug report for that...
<FromGitter>
<bararchy> @kyku You can open an issue, and a PR is like 2 sec
<FromGitter>
<bararchy> btw, what is the return type of gets ?
<FromGitter>
<kyku> String?
<FromGitter>
<bararchy> Hm...
<Groogy>
yeah but the || raise would remove that I think
<Groogy>
the ?
<FromGitter>
<bararchy> What's the code in `gets` ?
<FromGitter>
<bararchy> so there the `String?` makes sense
<FromGitter>
<bararchy> in read_line it does not make sense
<FromGitter>
<kyku> of course it can... but the point of read_line is to throw in situations where gets returns nil (end of file)
<FromGitter>
<bararchy> but wouldn't the better way to handle this is return nil or String , so that you can handle this better then Exceptions ?
<FromGitter>
<bararchy> Exceptions are pricy
<Papierkorb>
So sharing a short fun fact: Recently, bindgen learned how to "transfer" default argument values over - Including string literals now. after that I was baffled that now QFileDialog::getFileOpenName() wasn't wrapped anymore, Crystal complained (rightfully) that `Qt::FileDialog.get_file_open_name` doesn't exists ("did you mean Qt::FileDialog.get_file_open_url"). Upon invastigation, turns out that the now-missing C++ function uses a `QString*
<Papierkorb>
`, as in, a QString *pointer*. I added rules before that that it should ignore methods if the wanted pass-type (Which is by-value for `String`) doesn't match the C++ type (In this case, by-pointer). So .. in any case, I'll have to figure out a way of checking (?) or specifying the direction of a pointer-argument >_>;
<FromGitter>
<kyku> @bararchy : if you want such behaviour, you can use "gets" and handle the nil case.
<Papierkorb>
Mh what about a `Object#not_nil!(message)`? If it's nil, it raises the message. Bonus points if it lets me define the exception class as well.
<Papierkorb>
Would make not_nil! a bit more end-user oriented. Now if *that* is a good thing is another question
<FromGitter>
<bararchy> If it can recive an Exception.new("my message") It could be cool :)
<Papierkorb>
Think that'd be too pricy by itself, as in the likely case of it not being nil you'd allocate an object for nothing
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
<Groogy>
hmm so I've hada thing I've needed to tackle all the time in Boleite
<Groogy>
for now I have Vector, matrices etc as generics so there are Matrix44f32, Matrix44f64 and then Matrix44f (the default)
<Groogy>
but question is what should that default be?
<Papierkorb>
Is a "default" type of matrix necessary?
<Papierkorb>
And, does it make sense to use a full double for graphics?
<Groogy>
well it's just a shorthand for one of the other because defining type every time is kind of annoying
<Groogy>
it doesn't but matrix and vector are just linear algebra, not inherently in themselves part of graphics
<Groogy>
right now I have so interacting with a sprite will use a Float64 but when it uploads the data to the graphics card it is 32bit
<Groogy>
just so you don't have to do sprite.rotate 25f32 but simply 25.0 works
<Groogy>
I don't like it being not coherent though
<Papierkorb>
I'd define the type as `Float` (if defining any type) in the argument, and then `.to_f32` if required. One might argue "oh noes now it's implicitly casted, like in C!111" but honestly, writing the `f32` suffix isn't fun either.
<Papierkorb>
But that's not the kicker to me.
<Papierkorb>
The important thing is, will it be important in the future?
<Groogy>
no I am just worried about accidentally uploading doubles
<Groogy>
and such offset the data and suddenly we are not reading the data as we defined it
<Groogy>
since you can just give the graphics card any kind of data but you have to tell it how you are supposed to read it
<Papierkorb>
What do 3d model file types use?
<Groogy>
32bit floats definetly
<Groogy>
you can be more fancy and use 64 bits
<Groogy>
you can also do some fancy stuff with 16bit floating point textures
<Groogy>
think CryEngine uses 16bit floating point textures
<Papierkorb>
Then that'd be what I use honestly, with ("implicit") casting through #to_f32 so the user, if required at all, doesn't have to write the suffix.
<Groogy>
hmm actually I might have done what you say by mistake
<Papierkorb>
I mean, have a stern note in your documentation.
<Groogy>
ah yeah I just have before creating the transformation matrix I convert the types
<Groogy>
though no idea what would happen if @rot here is float 32
<Groogy>
PI / 180.0 is Float64
<Papierkorb>
@rot is Float64
<Papierkorb>
As defined in line 7
<Groogy>
true but let's say the type is not defined
<Groogy>
and someone assigns a Float32
<Groogy>
how does the math work out there or is it a compile error?
<Papierkorb>
It does compile, and gives you a Float32
<Groogy>
ah cool
<Groogy>
hmm so if I am just super strict in the actual interfaces that work with OpenGL it might work out fine?
<Papierkorb>
Probably
chamar has joined #crystal-lang
<crystal-gh>
[crystal] Sija opened pull request #4921: Changed IO.read_line to return String rather than String? (master...fix-io-read_line-return-type) https://git.io/v50xe
_4d47 has joined #crystal-lang
<_4d47>
hi guys, how do you write ( /[[:alpha:]]/ === a && a.upcase == a ) for a case expression ?
rohitpaulk has quit [Quit: Ping timeout (120 seconds)]
rohitpaulk has joined #crystal-lang
chamar has quit [Quit: Konversation terminated!]
<RX14>
so you want to check if a is a capital unicode alphanumeric?
<crystal-gh>
[crystal] akzhan opened pull request #4922: Fixes to bigint 32bit (master...fixes-to-bigint-32bit) https://git.io/v50pM
<FromGitter>
<picatz> Interestingly, I can't get a case statement to work with that either ... but I can get a simple if to work.
<FromGitter>
<picatz> I'm not sure why that'd be *the case* ( pun intended, but also still confused ).
<FromGitter>
<picatz> I think regardless of what they're trying to achieve with that --- that should be, like, a thing they should be able to do, right?
<RX14>
@picatz because one checks equality and one evaluetes a condition?
<_4d47>
check that it has a letter and is all upcase
<RX14>
if you put an expression as a case when
<RX14>
it's going to return true or false
<RX14>
which usually isn't === to whatever the case var is
snsei has quit [Remote host closed the connection]
<oprypin>
sorry
<txdv>
so yeah, they are going to address this, but linux just doesn't provide any *usable* primitives for async file io
<txdv>
libuv uses a threadpool to deligate run reads/writes for files
<txdv>
windows has async file read/write but not open/close
<txdv>
o yeah, reading from /dev/urandom blocks for a long time
<RX14>
oprypin, even if you use O_NONBLOCK, for filedescriptors associated with files, instead of sockets, it's a no-op on linux
<RX14>
which sucks
<oprypin>
:(
<RX14>
because obviously
<RX14>
you couldn't block on a file
<RX14>
it's "instant"
<RX14>
and as txdv said
<RX14>
linux provides absolutely no usable primatives for it
<RX14>
it's impossible to do without a threadpool
<txdv>
linux has aio
<RX14>
yes
<RX14>
i said usable
<RX14>
:)
<Papierkorb>
kinda hilarious considering that network attached storage has always been popular in enterprise
<RX14>
^
<oprypin>
so that's why my text editor freezes
<RX14>
if it uses libuv it uses a threadpool for file IO
<RX14>
"The kernel aio interface is not wrapped by libc, only works on some file systems, has some odd-er alignment+size requirements and only supported by linux"
<RX14>
basically the alignment requirements kill it
<RX14>
you need to align your file reads and writes or something
<RX14>
which makes it unusable for general-purpouse applications
<txdv>
and nobody is willing to fix it
<txdv>
because that would mean breaking file io on linux and nobody wants to deal with that
<RX14>
how would it beak file IO?
<RX14>
surely you can produce both old and new behaviousr with a new syscall, or even just a new IOCTL
<RX14>
or a FD option
<txdv>
you can, but it would mean that you need to rewrite all of the file io code
<txdv>
o man
<txdv>
i need to get into kernel developing
<Papierkorb>
AIO is a completely separate kernel API. Both APIs already co-exist
snsei has joined #crystal-lang
Tuxified has joined #crystal-lang
<crystal-gh>
[crystal] mverzilli opened pull request #4923: Remove empty string as alias for --no-debug (master...fix/empty_no_debug_option_alias) https://git.io/v5EkQ
hightower4 has joined #crystal-lang
hightower3 has quit [Ping timeout: 246 seconds]
<crystal-gh>
[crystal] RX14 closed pull request #4923: Remove empty string as alias for --no-debug (master...fix/empty_no_debug_option_alias) https://git.io/v5EkQ