p0p0pr37 has quit [Read error: Connection reset by peer]
p0p0pr37 has joined #crystal-lang
p0p0pr37 has joined #crystal-lang
faustinoaq has quit [Ping timeout: 240 seconds]
Vexatos has joined #crystal-lang
<FromGitter>
<codenoid> poc cr managing big data
<FromGitter>
<unreadable> hacking into SFML makes such a fun :)
<FromGitter>
<unreadable> one of the best written c++ lib
mbarbar has quit [Ping timeout: 255 seconds]
alex`` has quit [Quit: WeeChat 1.9.1]
snsei has joined #crystal-lang
csk157 has joined #crystal-lang
<FromGitter>
<jwaldrip> can you define a default proc to &block on a method?
<FromGitter>
<bew> seems not, but you can have a method with and a method without block, and the method without block can call the other with the default block/proc
<oprypin>
dragonkh, but i recommend not using this at all. because you can just create a 'lib' folder and put a symlink to your other repo there
<oprypin>
and the shard file will contain only what you want to publish
<oprypin>
so you dont accidentally publish something containing a path on your computer
<dragonkh>
I'm trying to create a Kemal application and use kemal-session-redis - but the main repo was missing an update - which was supplied as a pull request - but not applied yet - so I cloned the forked repo locally
<dragonkh>
I can't seem to use either the official repo or the fork with shards though
<oprypin>
just nuke it all, restore your original shard.yml
<oprypin>
put the repo you cloned into 'lib' and you're done
<dragonkh>
yeah I will put it in lib as you suggest
<dragonkh>
I tried nuking - but whenever I add the remote repo into my shard.yml I get that same git error
<dragonkh>
if I remove it again - its all good - so must be a problem with the that lib
<oprypin>
dragonkh, could also be leftover repo in a hidden directory (i think it's called .shards)
faustinoaq has joined #crystal-lang
<dragonkh>
hmm I get the same issue if I put the cloned repo in the lib dir
<dragonkh>
if I use the shards path approach it works though
<dragonkh>
very strange
csk157 has joined #crystal-lang
<dragonkh>
hmm
csk157 has quit [Ping timeout: 240 seconds]
csk157 has joined #crystal-lang
<dragonkh>
ah got kemal-session working now - seems many of the places I was looking were using an old version and now Session lives inside Kemal
lianchu has joined #crystal-lang
csk157 has quit [Ping timeout: 240 seconds]
csk157 has joined #crystal-lang
csk157_1 has joined #crystal-lang
<FromGitter>
<Rinkana> Is there some sort of micro sleep?
<FromGitter>
<bew> like `sleep` ?
<FromGitter>
<bew> you can give it a duration
<FromGitter>
<Rinkana> Yeah but i can only give it seconds
<FromGitter>
<Rinkana> I need less then a secon
<FromGitter>
<Rinkana> second*
csk157 has quit [Ping timeout: 255 seconds]
<FromGitter>
<bew> you can `sleep 200.milliseconds`
<FromGitter>
<bew> (because `sleep` accepts a `Time::Span`)
<FromGitter>
<Rinkana> Ah yeah great
<FromGitter>
<Rinkana> That does indeed work :D
<FromGitter>
<Rinkana> Because what i have is a few fibers with infinite loops in them. And to make them act like they are threads i needed to sleep them a very short time (`1.milliseconds`)
<FromGitter>
<bew> oh no, you should use `Fiber.yield` if you want to give the control to another fiber iirc (not sure though)
<FromGitter>
<bew> yes, that's it
<FromGitter>
<Rinkana> Ah yeah, that works too, and is probably better
<FromGitter>
<Rinkana> Thanks!
<FromGitter>
<bew> ;)
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<bew> lol, looking at the actual code, all it does is `sleep 0` but that's enough to reschedule the fiber
<FromGitter>
<Rinkana> Haha
<FromGitter>
<bew> but it's better to use `Fiber.yield` as it shows your intention ;)
<FromGitter>
<Rinkana> Hmm, looking at the docs wont `loop do` overflow eventually?
<FromGitter>
<bew> the `i` you mean?
<FromGitter>
<Rinkana> Yeah
<FromGitter>
<bew> it will probably yes (in non-release at least), but it's harmless
<FromGitter>
<bew> in release mode it'll be optimized if you don't use `i`
<FromGitter>
<HCLarsen> Hey guys, got a question about Crystal coding convention. Would it be bad form to start a class name with a number? Or should I just spell the number out?
sz0 has quit [Quit: Connection closed for inactivity]
aroaminggeek has joined #crystal-lang
<FromGitter>
<bew> is there a way to determine the endianness of the computer I'm running on? can't find any method, and the only thing related to that is `alias SystemEndian = LittleEndian` in `src/io/byte_format.cr`.
<FromGitter>
<bew> Does that mean that the endianness of modern computer is always LittleEndian?
<oprypin>
but of course you should prefer the standard operations defined in byte_format
<FromGitter>
<bew> thanks @oprypin I was gonna use the `SystemEndian`ness anyway for my conversions, but I needed to know which one it was!
<oprypin>
bew, exactly what this means is that for all platforms currently supported by crystal this is the endianness
<FromGitter>
<bew> yeah I see, thank you for the precision. If I understand correctly this means that if one day Crystal is supported on a BigEndian machine, there will be a `if flag?(:something)` around that alias
<oprypin>
ye
<FromGitter>
<bew> perfect ty!
<FromGitter>
<bew> @oprypin I don't get it, why as I am on a littleendian machine (I checked), when I do `1 & 0xff` I get 1 instead of 0 ?
<FromGitter>
<bew> oh no ok nvm
<oprypin>
0b00000001 & 0b11111111 ??
<FromGitter>
<bew> 0xff is also in little endian
<oprypin>
i dont understand what you're getting at
<Papierkorb>
endianess is how integers are stored, not how you calculate with them
<oprypin>
the operation would have the same result
<FromGitter>
<bew> yeah I figured that
<dragonkh>
anyone know in Kemal how to return a bad request?
<FromGitter>
<bew> I wanted to check the least significant byte, but as `0xff` is also in little endian, this is not the way to go ^^
<FromGitter>
<bew> I ended up with `1.unsafe_as(StaticArray(UInt8, 4))`
<FromGitter>
<bew> which happily gave me `StaticArray[1_u8, 0_u8, 0_u8, 0_u8]`
<oprypin>
wtf
<oprypin>
& 0xff does give you the least significant bytw
<oprypin>
the results of that operation that you just showed, however, differ per platform
<dragonkh>
ok got it thanks: context.response.status_code = 404
<Papierkorb>
dragonkh: that's not bad request, that's not found
<dragonkh>
yeah I wanted the mechanism of how to do it - more than the specific error
<FromGitter>
<bew> yes, I badly expressed myself, what I wanted to check for myself was which was the last byte transmitted in a network operation when I send `1`, was it `0u8` or `1u8` (I already knew the answer, but wanted to see it)
<FromGitter>
<Rinkana> Hmm, i currently need `BigDecimal` but it has just recently been merged into master. So it will probably be a while untill that release
<dragonkh>
is there a way to use the Json mapping macro in Kemal from the request ? e.g. context.params.json gives me some json and I want to convert it to an object e.g. Credentials - so I tried creating a class Credentials with JSON.mapping(name: String) - and then Credentials.from_json(context.params.json) but it blows up
<oprypin>
dragonkh, that seems like the correct approach, so make it not blow up
<dragonkh>
I think from_json is expecting json as a string
<dragonkh>
and context.params.json is of type Json
<dragonkh>
but converting it to a string makes it a hashmap which is no good
<dragonkh>
in fact I think it's a hashmap coming from context.params.json
<dragonkh>
so I need to convert it to json format
<dragonkh>
yup it works like this: context.params.json.to_json
<oprypin>
dragonkh, no no no
<dragonkh>
I guess I expected context.params.json to return json not a hashmap
<dragonkh>
if I map it into an object - it will give me an object with a Type I want to work with - plus if the json is incorrect it will fail to map - so I can handle it easily - rather than checking the json structure
<oprypin>
sure, that's nice
<dragonkh>
so is there a downside to - context.params.json.to_json - as that is much easier to read and understand for me than the longer context.request.body.not_nil!.gets_to_end ?
<Papierkorb>
You're there parsing JSON, then serializing it back to JSON, and then parsing it again.
<Papierkorb>
That's a Bad Idea™, and thus simply Bad Code™.
<Papierkorb>
You can try filing a feature request for kemal for a better solution
<dragonkh>
I make a helper method then to hide it away
<dragonkh>
and see if Kemal might consider a pull request
<oprypin>
sdogruyol, please check out this use case (using json.mapping). why does kemal params provide a method for "assume the request body is json and read it and parse it and return raw" (when the body is not even related to params) but doesnt have a method for getting the body?
ShalokShalom has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]