Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 02 22:36
    straight-shoota synchronize #12809
  • Dec 02 22:35
    straight-shoota synchronize #12809
  • Dec 02 22:24
    straight-shoota milestoned #12779
  • Dec 02 22:24
    straight-shoota milestoned #12779
  • Dec 02 17:07
    straight-shoota milestoned #12800
  • Dec 02 17:07
    straight-shoota milestoned #12800
  • Dec 02 17:07
    straight-shoota milestoned #12773
  • Dec 02 17:07
    straight-shoota milestoned #12773
  • Dec 02 16:56
    HertzDevil labeled #12800
  • Dec 02 16:56
    HertzDevil unlabeled #12800
  • Dec 02 14:17
    HertzDevil labeled #12817
  • Dec 02 14:15
    imsofi opened #12817
  • Dec 02 14:15
    imsofi labeled #12817
  • Dec 02 13:51
    straight-shoota milestoned #12784
  • Dec 02 13:51
    straight-shoota milestoned #12784
  • Dec 02 13:50
    straight-shoota milestoned #12808
  • Dec 02 13:50
    straight-shoota milestoned #12808
  • Dec 02 13:40
    HertzDevil synchronize #12784
  • Dec 02 13:39
    HertzDevil ready_for_review #12784
  • Dec 02 13:26
    straight-shoota milestoned #12816
From IRC (bridge bot)
@FromIRC
David Blurton
@davidblurton
def get_raw_body(url) 
  HTTP::Client.get url do |response|
    length = response.headers.get("content_length")[0].to_i

    slice = Slice(UInt8).new(length)
    response.body_io.read_fully(slice)
    slice
  end
end
@oprypin How can I improve this?
From IRC (bridge bot)
@FromIRC
<oprypin> i'm at a loss, can't see an improvement
David Blurton
@davidblurton
Just leave the data in the an Array? I feel like slices are nicer though
From IRC (bridge bot)
@FromIRC
<hightower2> Hey, isn't behavior of Dir.entries( "/directory") a bit weird given that it returns "." and ".." among the results, in unclear sort order? I called it and it returned ["three", "four", "one", ".", "two", ".."]
<oprypin> but maybe you don't actually want to turn it into a slice and leave it in the IO
David Blurton
@davidblurton
That's true, I could pass the IO directly to my body parser
From IRC (bridge bot)
@FromIRC
<oprypin> hightower2, the sort order is not weird, but the .. stuff is indeed silly; unusable
<oprypin> so with the IO you can read a few bytes to a slice, then read a few bytes as a string
<oprypin> which seems to be what you want
<oprypin> but it's always weird how inconvenient it is to go from IO to slice. i guess they don't want people to be wasteful with allocations
<oprypin> like, instead of making a loop creating a new slice every time this encourages reuse
David Blurton
@davidblurton
I guess I was expecting the client response to have a raw_body property or something
From IRC (bridge bot)
@FromIRC
<oprypin> @davidblurton, but it allows streaming, it does not contain the whole response
<oprypin> abstracting streaming is the whole reason for IO to exist in addition to Slice
David Blurton
@davidblurton
right, I'm looking for a simple way to read the whole body though
I can see that IO is a nice abstraction for reading and writing, but I don't really care about streams here
From IRC (bridge bot)
@FromIRC
<oprypin> @davidblurton, but it's also a nice abstraction for protocol parsing
David Blurton
@davidblurton
I agree, I was using Char::Reader before, until I realised some of the response was binary
so should be easy to swap that for an IO
John Jansen
@johnjansen
anyone got a nice way to timeout an http get
ive done it before, now i cant find the code, or remember what i did
forget i asked … stupid me ;-/
From IRC (bridge bot)
@FromIRC
<RX14> @johnjansen you need to use HTTP::Client.new then set the timeout on that client instance
<RX14> HTTP::Client needs some love to be honest
John Jansen
@johnjansen
yep … didnt think to look first, did i ;-)
From IRC (bridge bot)
@FromIRC
<hightower2> Hey, if I need to write a 16bit unsigned int in little endian order into some buffer, then 1) What buffer do I use? StringBuilder? and 2) How do I write something like that?
John Jansen
@johnjansen
@RX14 might have an answer to that, he was here a little while ago
From IRC (bridge bot)
@FromIRC
<RX14> hightower2, you should look at the write_bytes method on IO
<RX14> String.build yields you an IO instance
<RX14> so you can use that
<RX14> however writing a raw integer to a string is unlikely to be what you want
<RX14> strings shouldn't contain binary data
<RX14> if you're working with binary data, IO::Memory and Bytes should be what you use
<hightower2> @RX14, right, was just about to say that, thanks
Chris Watson
@watzon
Anyone know where stddef.h would come from? I seem to be missing it. Reinstalled clang and gcc already
Never mind, I found it in /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/include, but clang seems to not be picking it up for some reason. I'm trying to use crystal_lib and it keeps telling me /usr/include/sys/types.h:145:10: fatal error: 'stddef.h' file not found
From IRC (bridge bot)
@FromIRC
<hightower2> I am trying to write data to a socket, and invoke some method/callback when the data is actually written out. Is there a built-in way for this?
Doug
@DougEverly
@drosehn see if https://github.com/DougEverly/daemonize.cr works for you
Chris Watson
@watzon
What would the Crystal equivilent of unsigned long be?
Would I do $var_name : Float64?
Zatherz
@zatherz
unsigned long is an integer type
long is, at least on most platforms that crystal targets, Int64
crystal doesn't have things like unsigned, it's separate types, so UInt64
@bararchy @watzon Thanks, I'm gonna use these results for https://gitlab.com/zatherz/magicjson
I'm gonna have an always_ordered option that makes it use force ordered, otherwise I'm gonna use naive w/ reset
Chris Watson
@watzon
Ooh awesome
Good going using GitLab
sevk
@sevk
make crystal as a human language , similar to short english .
Zatherz
@zatherz
what