Guest56511 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<johnjansen> it only happens when a virtual class is used within another class too
<FromGitter>
<renich> good day, Crystalians!
<FromGitter>
<renich> Well, evening here
<FromGitter>
<renich> Hey, wait. If we use crystal... does that make us drug addicts?
Dreamer3 has joined #crystal-lang
<FromGitter>
<renich> Hey guys, I have this: https://play.crystal-lang.org/#/r/2bcv. I'd love to be able to pass it either every parameter of a NamedTuple which contains all the parameters. How?
<FromGitter>
<martincsimpson> Anyway, just offering a hand if needed. :)
<FromGitter>
<sdogruyol> wow, thanks @martincsimpson I'll keep that in my mind :P
hightower2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<crisward> @sdogruyol yes, we need a session store and we already use mysql with our sites, so this should hopefully a drop in replacement for the kemal-session/fileEngine we currently used. Think it'll probably be my weekend project. I'll update the readme when its done and tested.
<FromGitter>
<crisward> For lowish traffic sites mysql is fine. For bigger sites we tend to lean towards redis, but that's already taken care of.
Groogy_ is now known as Groogy
<Groogy>
Morning!
<FromGitter>
<sdogruyol> @crisward that's great to hear. Please feel free to reach me for any help
<FromGitter>
<codenoid> :satisfied: still playing with the db
mark_66 has joined #crystal-lang
<FromGitter>
<crisward> @sdogruyol Think I should be ok, but I'll let you know if I get stuck.
<Groogy>
one my new parts are DOA so all my crystal projects been delayed as I've been debugging that :( I was hoping to play around with the language the entire week
<Groogy>
computer parts*
<Groogy>
working through the ubunutu shell on windows 10 is not directly the best
<jokke>
hi
<jokke>
i'm having trouble with IO.copy
<jokke>
the source and destination contents differ
<jokke>
i'll put together a minimal example
rohitpaulk has joined #crystal-lang
<jokke>
hm it seems to be another problem, since i can't reproduce it in a minimal example
<Groogy>
function used by IO.copy though is the #write which calls @output.write and I see a #flush method used with that before the headers are written.
<Groogy>
wonder where the unbuffered version is used though
<jokke>
it's called by IO::Buffere
<jokke>
d
<jokke>
this is most definately a bug in that class
<Groogy>
yeah I see
<Groogy>
yeah because it's definetly weird, because the IO.copy does potentially several writes to the buffer
<Groogy>
if you have a file over 4k bytes
<jokke>
sure
<Groogy>
it will do more htan one
<jokke>
that's how it's supposed to work
<Groogy>
yeah but it sets the size afterwards
<jokke>
it's weird though: in #close the content length is set. but only if the headers aren't written but it ensures that headers are written before writing anything to the io
<Groogy>
though this is only if the @sync variable is set though
<Groogy>
in the function reset it sets reset to false again, and the default is false as well
<Groogy>
but not sure if something else might set it to true
<Groogy>
otherwise the unbuffered_write is delayed until certain things happen
<Groogy>
i.e if we pass by the buffer size
<Groogy>
which is 8192 bytes
<jokke>
yeah
<Groogy>
so back to the problem, my guess is encoding problem? There is a byte extra of data which gives you the number of 4?
<jokke>
i also wonder why not setting content_length at all doesn't result in Transfer-Encoding: chunked as the code suggests
<Groogy>
maybe UTF-8 bom character or something?
rohitpaulk has joined #crystal-lang
hightower2 has joined #crystal-lang
<jokke>
okay it seems to be a problem with small files
<jokke>
i just tried with 1M of random data
<jokke>
has the same md5sum as the original
<Groogy>
the small one was with text right? Is the 1M of random data done binary or also text?
<Groogy>
because from what I see, what you will be writing is binary so if you have a weird encoding in the text it is gonna just write that "straight"
<jokke>
mh could be
<jokke>
but still
<jokke>
crystal shouldn't make assumptions
<jokke>
a text file is a "binary" as well
<jokke>
as in: it consists out of bytes
<jokke>
this seems to be a kemal issue
<jokke>
can't reproduce with pure HTTP::Server
<jokke>
yup
<jokke>
definately kemal
<FromGitter>
<sdogruyol> @jokke can you report an issue please?
<FromGitter>
<sdogruyol> i didn't follow the whole thread
<Groogy>
Yeah they are binary, but if whatever editor think it is some weird encoding then when reading it back binary and then with ASCII nothing is going to make sense
<jokke>
sure
<jokke>
but IO.copy copies bytes
<jokke>
it doesn't care about encodings
<Groogy>
yeqah but you are setting an encoding in the header right? :P
<jokke>
no
<jokke>
content type is application/octet-stream
<Groogy>
eh not encoding
<Groogy>
content type
<Groogy>
yeah so when you end up receiving it in the webbrowser, it has no idea what encoding the text is
<Groogy>
and probably just defaults to UTF-8 or ASCII
<jokke>
i'm not using a browser
<jokke>
no
<jokke>
octet stream is binary
<jokke>
no encodings whatsoever
<Groogy>
yes, but the source file has an encoding
<jokke>
that doesn't matter :D
<Groogy>
it does, because you are sending it binary
<Groogy>
i.e byte for byte
<jokke>
sigh
<jokke>
you're not really making sense
<Groogy>
If you are sending let's say Latin1 text binary, but the receiving end does not know it is latin1 text it will get some unknown weird characters
<jokke>
wouldn't you agree that if i copy a file byte by byte the result should be _exactly_ the same
<Groogy>
yes it is exactly the same
<jokke>
see
<jokke>
and it isn't
<jokke>
hence it's a bug
<Groogy>
But it is
<jokke>
no!
<Groogy>
Character count is not the same as byte size
<jokke>
dud
<jokke>
e
<jokke>
you think i'm counting chars?
<jokke>
im looking at the _bytes_ of the original and resulting files
Raimondii has joined #crystal-lang
<Groogy>
no I didn't say that, but I am just pointing out that you took two different kinds of data and saw behavioural change and then putting that as the cause of problem is between small sets of data and big sets of data
<jokke>
and they differ
<jokke>
NO!
<Groogy>
No you said one is text and one is binary
<Groogy>
source file that is
<jokke>
dude
<jokke>
you don't understand the problem
<jokke>
let's put it this way
<jokke>
what makes a text file text and what makes a binary?
<jokke>
what's the difference?
<Groogy>
there's no difference, it is all a matter how you view the data contained within the file.
<jokke>
exactly!
Raimondi has quit [Ping timeout: 268 seconds]
<jokke>
and crystal is not an editor
Raimondii is now known as Raimondi
<Groogy>
What I said does not contradict that
<Groogy>
You wrote a file manually
<Groogy>
and the 1m data is generated I am guesisng by some tool?
bjz has joined #crystal-lang
bjz has quit [Client Quit]
<Groogy>
guessing*
<jokke>
it's just from /dev/urandom
<jokke>
now:
<Groogy>
yes but the file you wrote manually might as well have extra characters in it
<jokke>
what if /dev/urandom would've outputted a "text file"
<jokke>
totally possible
<jokke>
not probable but possible
<Groogy>
that's what I said
<Groogy>
That is literally what I said, seeing random numbers or unknown characters in a scenario in this is very probably to be encoding
<Groogy>
I know because I've been through this before
<Groogy>
Assuming two different sets of data being generated completley differently are equivalent is very false assumption to make
<jokke>
...
<jokke>
input is "foo"
<jokke>
sorry "foo\n"
<jokke>
output is "foo\n4"
bjz has joined #crystal-lang
<jokke>
content-length is 5
<jokke>
hence: content-length is _wrong_
<jokke>
nothing to do with encoding
<Groogy>
no it obviously gets a fifth character from somewhere
<jokke>
of course
<jokke>
from ram
<jokke>
it's just a random byte which happens to be in ram
<jokke>
if you've worked with C before, you know what i mean
<Groogy>
Yes I have, but nothing in the code implies that it reads past the given string
<Groogy>
since it gets the size of the string from the source itself
<jokke>
.......
<jokke>
look. at. the. strings.
<Groogy>
though it probably isn't a BOM character since it is 3 bytes big
<Groogy>
I am looking at the code Jokke
<jokke>
count the characters
<jokke>
count the bytes
<Groogy>
a character in Crystal is 4 bytes big
<jokke>
what!?
<jokke>
count the bytes of my input and output strings above, please
<Groogy>
No I don't, I am trying to explain to you visible characters does not mean that you don't have more characters there and when you then transfer that data binary and hence losing the context of those bytes at the destination it will show up wrong
<FromGitter>
<bew> weird*
<FromGitter>
<bew> bytesize and size is the same here
<Groogy>
I do not have specifically the file being used where the fault lies in
<jokke>
i will upload it for you :D
<Groogy>
@bew the string is pretty smart, it depends on the encoding
<Groogy>
like if you need multibyte chars it will do that
<jokke>
i'm telling you. my file contains _exactly_ the characters i've shown you
<jokke>
i'm not stupid
<Groogy>
For instance there is a lot of characters that are pretty rare for you to use, we for instance as a DLC ownership protection method used non-breaking spaces to see that files hadn't been tampered with
<jokke>
i know about encoding. i've got a degree in computer science. i should know...
<jokke>
and i'm telling you now. it has _nothing_ to do with this problem
<Groogy>
And? I've taught at Universities?
<jokke>
what have you taught?
<Groogy>
and I am not saying it has to do wwith that problem, I am saying doing the correleation that you did was faulty
<Groogy>
Game development
<Groogy>
or rather it was one class I was invited to because of my book
<jokke>
mh
<jokke>
and you have studied computer science?
<Groogy>
no
<jokke>
well it's beyond the point anyway
<Groogy>
I started working when I was 15 instead
<jokke>
i don't want to get personal
<FromGitter>
<bew> please don't fight!
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Groogy>
sorry wasn't my intention bew
<jokke>
it kind of insults my intelligence to be told that my problem is something very trivial which every 1st semester would figure out easily. I've now tried to explain for like half an hour or longer how it clearly isn't the case here but i'm at my limit of patience now so i'll just stop and you are free to believe what you will.
<Groogy>
At no point where I infering on your intelligence, trivial problems happen all the time
<jokke>
and i'll feed my cats :D
<Groogy>
And because they are trivial you usally overlook it
<Groogy>
99% of a progammers life is going to be "Oh damned I'm an idiot, that's so simple"
<jokke>
you're right of course.
<Groogy>
and I don't believe anything about you since I do not know you, I was just trying to give you a pointer on that it might not be related to actual size data since the data sets came from two different sources
<jokke>
encoding is a good bet as any in this case but what bugged me was that despite me arguing against it being the problem here you kept going
<jokke>
actually i need to apologize. i've been a dick and i really appreciate people helping out on irc. I'm the reason why someone might not want to by reacting like this.
<Groogy>
Nah it's fine, I should have let it go when it became clear I wasn't helping anymore
<Groogy>
Eitherway codenoid, I am going on lunch right now but what socket is it that closes? (that you marked out with comment), the http params or the mysql?
* jokke
shakes hands with Groogy
<FromGitter>
<codenoid> oh sorry, it's different problem, i'll remove that
<FromGitter>
<codenoid> yayyy :sparkles:
<FromGitter>
<codenoid> updated with `my simple query :`
bjz has joined #crystal-lang
<FromGitter>
<bew> jokke, using `send_file context, DATA.to_slice` instead of using `IO.copy` works well
<jokke>
because this is a little script i wanted to try out
<FromGitter>
<bew> that's cool, I always forget about fibers...
<Groogy>
and back, long lunch for getting my fried MoBo replaced. @bew did you get help with your thing?
<Groogy>
or wait no that was @codenoid
<Groogy>
sorry
<FromGitter>
<bew> np
<FromGitter>
<suvendusamanta> Can I create a subclass in an inner (sub-)directory which inherit from a class defined outside the (sub-)directory. If yes, How?
<Papierkorb>
Directories and their structure don't matter to the language. Module paths are global, and can be accessed from anywhere
<FromGitter>
<suvendusamanta> thanks, in above example, can I define MatrixDense in matrix_dense.cr which will be derived from Matrix class defined in Matrix?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Papierkorb>
If both files are require'd, of course.
bjz has joined #crystal-lang
bjz has quit [Client Quit]
<Groogy>
It works like in Ruby right? If it's been defined and loaded you can use it however right?
<Groogy>
there's no rules on the language based on file/compile units etc.? Like D for instance
<FromGitter>
<bew> it returns the size of the file named *filename*
<Groogy>
^
<FromGitter>
<chyzwar> .size(filename) : UInt64 ⏎ Returns the size of filename bytes.
<FromGitter>
<chyzwar> then docs should be diffrent. It should say Return size of file with filename
<FromGitter>
<chyzwar> I think that #size should be uzed
<FromGitter>
<chyzwar> ``````
<FromGitter>
<schoening> Is my_array[ index ] lookup speed 0(n) ? :(
<FromGitter>
<schoening> Tried writing a loop that would only do comparison between all its values once, but if arrays gotta iterate every check anyways then that seems pointless? ⏎ https://play.crystal-lang.org/#/r/2bh8
hightower2 has quit [Ping timeout: 240 seconds]
<Papierkorb>
Array#[] is O(1)
<Groogy>
I mean the loop itself is O(n) though?
<Groogy>
actually the loop you linked is O(n^2) unless I misunderstood something?
<FromGitter>
<schoening> Yeah the loop is not the problem I was worried about array itself, it didnt occur to me that the #[] I was looking for is specified deeper into the hirachy and not on array.
<Groogy>
ah you were worried it was a linked list?
<FromGitter>
<schoening> The loop will grow yeah. But less so than if I did just iterater twice over game_objects :) . better implementations are ofc welcome!
<Groogy>
it depends on what you want to do, there is no generic "this is better" Reading it as "game objects" is this for the main loop of a game?
<Papierkorb>
You'd have to tell us what you're trying to solve, not show what you're doing
<FromGitter>
<schoening> Maybe? :) I'm not good on the sematics of things.. I only saw the #[] range() definition and got scared
<Groogy>
Actually here's my advice, just go with it and when it becomes a problem, solve it then ;)
<Groogy>
there's no point in solving a potential problem without knowing if it will be a problem for you
<FromGitter>
<schoening> Sorry yeah, thats just iteration in the main loop. This works fine, I can't think of a faster way of looping while having to compare two things. So I only mentioned an optional "feel free to tell me it can go faster" haha
<FromGitter>
<schoening> Yeah agree @Groogy
<Groogy>
There are a bunch of things you can do to improve it actually, depending on what it needs to do
<Groogy>
for instance we at Paradox have very smart lists that divide the world into different things based on various conditions. Like we have in our script language you can do every_province = {} or owned_provinces = {}
<Groogy>
guess which one is fastest :P
<Groogy>
but it becomes very specific on what is it that this specific thing needs to do, where "can I find a shortcut"
<FromGitter>
<schoening> Ahh
<Papierkorb>
That's bascially an index or cache
<Groogy>
but yeah get to the performance problem and don't be afraid of refactoring stuff
<Groogy>
don't solve things just to solve them
<Groogy>
just for the sake of solving*
<FromGitter>
<schoening> Exactly :p I'm not that worried. But im sitting on a bus and the best I could do was trying out a new loop in crystal
<Papierkorb>
Choose the naive implementation, but not the stupid one ;)
<Groogy>
^
<FromGitter>
<schoening> Sound good yeh
<Papierkorb>
schoening, comparing one to every other element will always be O(n²). You can't get better than that. The trick is not having to do it :)
<Papierkorb>
But then, comparing is quite fast, and as long your list is small, you probably won't even notice
<Groogy>
and as long as the comparison is simple enough
<Groogy>
but if it is planned to be like collission testing for objects in a large world with a lot of entities, I would look into Quad trees schoening, or Oct Tree's if 3D
<Groogy>
actually read up on it anyway, it's still good to know
<FromGitter>
<schoening> Yeah exactly. Was thinking of learning to do a quad tree next
<FromGitter>
<schoening> Ofc! Learning for the sake of it is nice. Just gotta find a balance between that and actually getting something done :D
<FromGitter>
<umutuluer> Hi i have a question
<FromGitter>
<umutuluer> why does crystal support windows? i have any idea about this
<FromGitter>
<umutuluer> @sdogruyol me too, for choosing this name, because i admire mustafa kemal
<Groogy>
Atatürk? am I missing some context? xD
<FromGitter>
<sdogruyol> @Groogy Mustafa Kemal Ataturk
<FromGitter>
<mverzilli> the T there is a free variable, so it needs to be quantified
<FromGitter>
<sdogruyol> forall is kind of underdocumented :P
<FromGitter>
<mverzilli> if you were inside a class (like `Array(T)`) it would mean "the same T as this instance"
<oprypin>
sdogruyol, it's related. just trying to run my lib on Windows. it's a good candidate for being the first useful thing actually working because external libs dont use standard library's I/O and exceptions
<FromGitter>
<mverzilli> @sdogruyol yep
<oprypin>
C lib
<FromGitter>
<sdogruyol> @oprypin wow, is there anything to help?
<crystal-gh>
[crystal] MakeNowJust opened pull request #4687: Get version number from CHANGELOG.md when cannot get it from git (master...fix/crystal/4642-version-build-tar-ball) https://git.io/vQK0u
greengriminal has joined #crystal-lang
<oprypin>
well.. help me import those variables. though i could rework to export a setter function instead of a global
<oprypin>
on POSIX if a library exports a global variable, you can link to it and just use it. on Windows apparently you must explicitly specify that it's being imported
<oprypin>
and Crystal is not doing that import thing and I have no idea how to do it, because the docs keep saying "yeah, just use `__declspec(dllimport)`" - but that applies only to MSVC
<oprypin>
obj is produced on Linux through cross compile, then using `link` from "Microsoft Build Tools"
<Papierkorb>
Or rather, for crsfml, you're compiling through MSVC?
<oprypin>
Papierkorb, no C compiler is involved
<oprypin>
Papierkorb, I compile the C bindings to a C++ library usign MSVC, yes
<Papierkorb>
And that works I assume?
greengriminal has quit [Client Quit]
<oprypin>
I know it works on Linux but i've yet to try it on Windows
<oprypin>
could try compiling a basic C program using those bindings, but it's not trivial so i've not done that yet
<Papierkorb>
Well, it should if correctly use the dllimport stuff in there
<Papierkorb>
+you, and re-order the words. oh well.
<oprypin>
so now i need to find a way to compile a thing on Windows and specify include + library path
<oprypin>
just to confirm that it's Crystal missing something
<Papierkorb>
Just write a C program which calls some kind of init function from VoidSFML. If that runs, it'll work for Crystal as far the C end is concerned
<oprypin>
Papierkorb, I have the C program
<oprypin>
> so now i need to find a way to compile a thing on Windows and specify include + library path
<Papierkorb>
MSVC project?
<oprypin>
cl -I include test.c getting syntax errors on header files which were just compiled into a lib just fine
<oprypin>
nvm..
<oprypin>
yep it works
<oprypin>
cl -I include voidcsfml-window.lib voidcsfml-system.lib -Tp test.c easy enough
<FromGitter>
<sdogruyol> Woot
<oprypin>
sdogruyol, to clarify, no Crystal is involved in the thing that works. just eliminating errors in other components
<oprypin>
so it's back to how to do the equivalent of `__declspec(dllimport)` in Crystal
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter>
<konovod> Hi all. No idea on how to do `dllimport` but wow, crsfml working on windows would be awesome. Crystal on windows still use `gc`\`libevent`\`pcre` without any additional specifiers, so maybe problem isn't in `dllimport`?
<oprypin>
konovod, the problem is specifically with using exported globals. using exported functions works without dllimport
greengriminal has quit [Client Quit]
<oprypin>
globals that you would write like lib Lib; $global_var : Type; end
<FromGitter>
<konovod> oh. exported vars.
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter>
<konovod> I don't see them in voidcsfml. What they are used for? Can't you just replace them with functions?
<oprypin>
konovod, I can indeed replace globals with setter functions
<oprypin>
it would be good to get it working though. that may not always be an option
<oprypin>
they are used to set a callback which is used to fake class inheritance
<FromGitter>
<konovod> Now I see. well, exported vars are not very common imho. I know app have to *export* two vars to enforce discrete video on laptops though.
<oprypin>
i'm failing to find an example that fails to work due to sfml failure. one is missing libGL and one is missing libyaml
<oprypin>
(because I happened to use them in that particular example)
<oprypin>
hm got a first one `slither.o : error LNK2019: unresolved external symbol __powisf2 referenced in function .Float32....Int32..Float32`
<oprypin>
that's just a posix math function apparently
<Papierkorb>
Ah yeah the Windows libc is sh.. I mean not up to POSIX standard
<FromGitter>
<mverzilli> "CrSFML works!" <- wtf how's that possible!?
<oprypin>
as i was saying, "just trying to run my lib on Windows. it's a good candidate for being the first useful thing actually working because external libs dont use standard library's I/O and exceptions"
<FromGitter>
<schoening> ```AABB.for_each_intersect_between players do |p1, p2| ⏎ puts "#{p1}, #{p2}" ⏎ end``` ⏎ ⏎ Hehe.. I might be going a bit far with it but I love this pseudocode syntax right now as a beginner haha. Too bad I never tried out Ruby, had to get tortured with php instead [https://gitter.im/crystal-lang/crystal?at=595ff4e3c101bc4e3a61f2e2]
<FromGitter>
<bararchy> @fridgerator Hi, just saw your fantasy football genetic project, really really cool !
greengriminal has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter>
<renich> How do I convert a Hash into a NamedTuple? I mean, is there a mapping method or something?
<FromGitter>
<fridgerator> thanks :thumbsup:
<Papierkorb>
renich, not possible to do automatically
<Renich>
Papierkorb: so I need to map it manually?
<Renich>
with a map?
<Renich>
oh... no, that won't work, right?
<oprypin>
{a: hash["a"].as(Int32), .........}
<oprypin>
you have to have the full knowledge of predefined field names and types
<Renich>
oprypin: yeah, they can't be arbitrary... oh, well, it seems I will be stuck with Hashes then
<Renich>
oprypin: maybe I can just convert it to yaml and back to NamedTuple? Everything would be a string, though...
<oprypin>
Renich, you can do that but there's nothing to gain from that
<Renich>
why?
<oprypin>
> you have to have the full knowledge of predefined field names and types
<oprypin>
no workaround, no hack
<oprypin>
if you're looking for a way to do it under this condition, i just showed it. if you're looking for a more compact way, you can write a macro
<Papierkorb>
Renich: why do you need that?
<FromGitter>
<straight-shoota> Actually there is `NamedTuple.from(hash: Hash)`
<oprypin>
<a particular class of namedtuple>.from
<FromGitter>
<straight-shoota> of course this only works if you know the keys and their types beforehand
tzekid has quit [Remote host closed the connection]
<oprypin>
>> {a : Int32}.from({"a" => 5})
<DeBot>
oprypin: no overload matches 'Tuple(Nil)#from' with type Hash(String, Int32) - https://carc.in/#/r/2bjr
<oprypin>
i must have forgotten how to specify namedtuple
<Renich>
Papierkorb: I want all my methods to be able to use splat
<FromGitter>
<straight-shoota> does DeBot only evaluate from IRC?
<oprypin>
straight-shoota, yes
<Papierkorb>
Renich: You can..? Defining them through Hash is weird, and if you do that from inside Crystal, needlessly slow
<Renich>
Papierkorb: RESTful API returns json. Then, I need to add stuff to that json and convert it to a NamedTuple
<Renich>
I create order, it returns only the success message, saying that order #n was created, I need to parse the message to extract the order # and put it into the order again, which is a NamedTuple for now. So, I convert it into a hash, merge, and... I get stuck