jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.7.3 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
vikaton has joined #crystal-lang
havenwood has joined #crystal-lang
jtarchie has quit [Quit: Connection closed for inactivity]
NeverDie has joined #crystal-lang
waj has quit [Quit: waj]
waj has joined #crystal-lang
waj has quit [Quit: waj]
waj has joined #crystal-lang
waj has quit [Remote host closed the connection]
havenwood has quit [Ping timeout: 265 seconds]
jonahR has joined #crystal-lang
fowlduck_ is now known as fowlduck
waj has joined #crystal-lang
datanoise has joined #crystal-lang
Cidan is now known as zz_Cidan
jonahR has quit [Quit: Nos vemos corillo!]
zz_Cidan is now known as Cidan
willl has quit [Quit: Connection closed for inactivity]
waj has quit [Quit: waj]
willl has joined #crystal-lang
havenwood has joined #crystal-lang
havenwood has quit [Ping timeout: 258 seconds]
vikaton has quit [Quit: Connection closed for inactivity]
NeverDie has quit [Quit: Textual IRC Client: www.textualapp.com]
bcardiff has quit [Quit: Leaving.]
jbye has joined #crystal-lang
Ven has joined #crystal-lang
datanoise has quit [Ping timeout: 246 seconds]
Ven has quit [Read error: Connection reset by peer]
datanoise has joined #crystal-lang
BlaXpirit has joined #crystal-lang
datanoise has quit [Ping timeout: 264 seconds]
Cidan is now known as zz_Cidan
zipR4ND has joined #crystal-lang
BlaXpirit has quit [Quit: Quit Konversation]
BlaXpirit has joined #crystal-lang
zipR4ND has quit [Ping timeout: 276 seconds]
izzol has quit [Read error: Connection reset by peer]
fowlduck has quit [Read error: Connection reset by peer]
fowlduck has joined #crystal-lang
BlaXpirit has quit [Read error: Connection reset by peer]
BlaXpirit has joined #crystal-lang
datanoise has joined #crystal-lang
datanoise has quit [Ping timeout: 258 seconds]
zz_Cidan is now known as Cidan
havenwood has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Ping timeout: 258 seconds]
Ven has joined #crystal-lang
waj has joined #crystal-lang
Ven has quit [Ping timeout: 245 seconds]
Ven has joined #crystal-lang
BlaXpirit has quit [Read error: Connection reset by peer]
BlaXpirit has joined #crystal-lang
Ven has quit [Ping timeout: 265 seconds]
waj has quit [Quit: waj]
mdz_ has joined #crystal-lang
datanoise has joined #crystal-lang
jtarchie has joined #crystal-lang
datanoise has quit [Ping timeout: 265 seconds]
leafybasil has joined #crystal-lang
waj has joined #crystal-lang
thor77 has joined #crystal-lang
Benoist has joined #crystal-lang
BlaXpirit has quit [Quit: Quit Konversation]
bcardiff has joined #crystal-lang
vikaton has joined #crystal-lang
<thor77> hey, i'm just trying to learn some crystal... just ran into a problem: i want to build a json-string from a Hash: https://gist.github.com/Thor77/da43b38e1be7512cb582 but the compiler says 'json_array' is not defined for JSON::Builder:Class
BlaXpirit has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> Hi thor77. What's a json-string from a Hash?
<thor77> uhm, smth like "{'key': value}" <- json_string
<thor77> Hash: {"key" => "myvalue"}
<thor77> i want it to convert that
<thor77> (so i can send it via a HTTPResponse
<thor77> )
<asterite> Oh, JSON::Builder is a module that's include in IO
<asterite> You can do this: http://play.crystal-lang.org/#/r/2x3
<thor77> uh
<thor77> thanks
<asterite> Do you always need one key and one value?
<thor77> that seems to work, but i thought it is possible to convert all crystal-types into a json-string (like in other languages)?
<thor77> oh... seems to work fine, too
<thor77> now i'm even more confused of this language...
<asterite> You can do this too: http://play.crystal-lang.org/#/r/2x5
<asterite> My confusion is that you say "I want to generate a hash with key value" but I don't know what's your source
zipR4ND has joined #crystal-lang
<thor77> yeah, that looks fine
<thor77> was looking for smth like that
<asterite> Cool :)
<thor77> thanks :)
<asterite> :)
<thor77> uhm, that means... most modules just add some methods to existing types?
<thor77> never saw smth like that in other languages
<asterite> In Ruby it's like that too. But it's not done that much. Here it's the standard library so you can think of that as if it comes with the language
<asterite> There probably won't be any other JSON library other than the standard one because it's pretty good and also super fast, so adding `json_object` to IO is probably fine because nobody would need to define something like that
strcmp1 has quit [Remote host closed the connection]
asterite has quit [Ping timeout: 246 seconds]
<jhass> >> Hash(String, Hash(String, String)|String).from_json(%({"foo": {"bar": "baz"}}) # :/
<DeBot> jhass: Syntax error in eval:6: expecting token ')', not 'end' - http://carc.in/#/r/2xa
<jhass> >> Hash(String, Hash(String, String)|String).from_json(%({"foo": {"bar": "baz"}})) # :/
<DeBot> jhass: Error in line 4: undefined method 'from_json' for Hash(String, (String | Hash(String, String))):Class - http://carc.in/#/r/2xb
<jhass> ffs
<jhass> >> require "json"; Hash(String, Hash(String, String)|String).from_json(%({"foo": {"bar": "baz"}})) # :/
<DeBot> jhass: JSON::ParseException: expected string but was begin_object at 1:10 - more at http://carc.in/#/r/2xc
asterite has joined #crystal-lang
<asterite> jhass: yes, it's because we made it possible to call a method on a union type as long as all types respond to it, but you only get the first one
<asterite> Mmm... For example
<asterite> >> (1 || 1.5).class.zero
<DeBot> asterite: # => 0 - http://carc.in/#/r/2xd
Benoist has quit [Ping timeout: 246 seconds]
<asterite> >> (1 || 1.5).class.zero.class
<DeBot> asterite: # => Int32 - http://carc.in/#/r/2xe
<asterite> >> typeof((1 || 1.5).class.zero)
<DeBot> asterite: # => (Int32 | Float64) - http://carc.in/#/r/2xf
<asterite> That. But with that addition the from_json with union, which previously gave a compile-time error, now works but wrongly
<asterite> We still don't know what's a good solution. In any case I believe unions in JSON aren't that common
<jhass> I know how to work around it, but that pull parser in a fake class new boilerplate feels redundant :/
<asterite> but what's your JSON?
BlaXpirit_ has joined #crystal-lang
BlaXpirit has quit [Killed (verne.freenode.net (Nickname regained by services))]
<jhass> doing a small cli wrapper for changing the config because I'm lazy
<asterite> :)
<asterite> Probably JSON.parse is better there... I think for dynamic cases like that I'd use it
mdz_ has quit [Remote host closed the connection]
<asterite> Or maybe a new type HashOrString, but yeah, feels redundant...
mdz_ has joined #crystal-lang
<asterite> it's worse if you want to handle for example Array(Int32) | Array(String) (but not Array(String | Int32))
<asterite> Don't know how other statically types language deal with this... I think just something like JSON.pase
datanoise has joined #crystal-lang
<jhass> right, I should just cast it
<thor77> is there something implemented to easily parse http-form-data?
<thor77> or.. uhm, is there some kind of package-manager?
<thor77> *module-manager
mdz_ has quit [Ping timeout: 250 seconds]
<asterite> thor77: you mean this? http://play.crystal-lang.org/#/r/2xg
BlaXpirit has quit [Ping timeout: 276 seconds]
<jhass> eh, with_object not taking a block and not returning its arguments makes it loose all of its elegance...
<asterite> Ah, I'm not familiar with that
<asterite> jhass: what do you mean?
<jhass> well, what usecase does the current with_object solve? I never used the on both sides chained one in ruby
waj_ has joined #crystal-lang
<jhass> just things like each_with_object(..) {|a, b| and .with_object(...) {|a, b|
<jhass> where the call returns its argument
<asterite> I think that's the use case
<jhass> well, neither exists
<asterite> Are you talking about each_with_object or with_object?
<jhass> both?
<jhass> maybe there's Array#each_with_object? I only checked Hash tbh
waj has quit [Ping timeout: 264 seconds]
waj_ is now known as waj
<asterite> Well, the example in the docs is good: http://crystal-lang.org/api/Enumerable.html#each_with_object%28obj%2C%20%26block%29-instance-method
NeverDie has joined #crystal-lang
<jhass> in ./bxctl.cr:12: undefined method 'each_with_object' for Hash(String, JSON::Type)
<asterite> Ah, Hash is not Enumerable in our case
<jhass> ah, :/
<jhass> I guess because we don't have autosplatting tuples (yet)
<jhass> anyway, I still don't get the with_object returning iterator usecase
asterite has quit [Ping timeout: 246 seconds]
BlaXpirit has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> jhass: me neither, I added it to parallel with_index, but it's probably not very useful
<asterite> We can remove it
<asterite> We can also add Hash#each_with_object until we have autosplatting of tuples
<asterite> if we ever do that
<jhass> I'm biased regarding the autosplat, I know it's hated by many rubyists as too subtle behavior
<jhass> but I can see clear usecases, in crystal even more than in Ruby
<jhass> though actually tuple destructuring in block args etc would be even better I guess
<jhass> each_with_object(foo) do |(key, value), foo|
mdz_ has joined #crystal-lang
<asterite> jhass: yes, that's another alternative I've been considering
<asterite> we'll probably need do |(*args)|
<asterite> and yield *args
<asterite> so we can make Hash be Enumerable... maybe
<jhass> mmh
<jhass> can we do overload matching on block args?
<jhass> so we can have def each; yield k, v; end; end def each; yield {k, v}; end; ?
<jhass> the former for the user the latter for enumerable ?
asterite has quit [Ping timeout: 246 seconds]
leafybas_ has joined #crystal-lang
shaderslayer is now known as shadeslayer
leafybasil has quit [Ping timeout: 252 seconds]
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
unshadow has joined #crystal-lang
<unshadow> datanoise: Sent you a PR for openssl.cr
<unshadow> check it out ;)
<datanoise> unshadow: will do. when do_handshake and renegotiate are useful?
zipR4ND has quit [Ping timeout: 265 seconds]
<unshadow> datanoise: when you want to enforce a renegotiation on the server, lets say you suspect a malformed connection, or a MITM attacks, and you dont want to give people the opurtinty to crack the session key (like POODLE,CRIME,etc..) , you can set your client to do a renegotiation every 10 min, 20 min or 5 min etc..
<datanoise> unshadow: i see
<unshadow> f**k my English is terribly :(
<tkrajcar> unshadow: i understood you perfectly :)
<tkrajcar> "opportunity" not "opurtinty" though :D
waj_ has joined #crystal-lang
waj has quit [Ping timeout: 244 seconds]
waj_ is now known as waj
aguynamedryan has joined #crystal-lang
bhishma has joined #crystal-lang
flaviu has quit [Read error: Connection reset by peer]
sandelius has joined #crystal-lang
waj_ has joined #crystal-lang
waj_ has quit [Remote host closed the connection]
waj has quit [Ping timeout: 258 seconds]
NeverDie has joined #crystal-lang
Cidan is now known as zz_Cidan
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
leafybasil has joined #crystal-lang
leafybas_ has quit [Ping timeout: 256 seconds]
leafybasil has quit [Ping timeout: 258 seconds]
mdz_ has quit [Remote host closed the connection]
mdz_ has joined #crystal-lang
zz_Cidan is now known as Cidan
sandelius has joined #crystal-lang
mdz_ has quit [Ping timeout: 252 seconds]
NeverDie has quit [Quit: I'm off to sleep. ZZZzzz…]
<vikaton> asterite, when will that video be public ?
mdz_ has joined #crystal-lang
<jhass> yesterday :p
NeverDie has joined #crystal-lang
* vikaton cries
<vikaton> jhass, do u know haskell ?
<jhass> no
bhishma has quit [Ping timeout: 256 seconds]
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
shama has joined #crystal-lang
<jiriki-> hmh
<jiriki-> are there any real-world applications made in crystal btw?
<jhass> real world is a vague term
<vikaton> jiriki-: Crystal itself
<jiriki-> hmh okay
<jhass> that was meant as "what do you mean by real world"
leafybasil has joined #crystal-lang
datanoise has quit [Ping timeout: 276 seconds]
datanoise has joined #crystal-lang
aguynamedryan has quit [Quit: aguynamedryan]
miah has quit [Ping timeout: 276 seconds]
bcardiff1 has joined #crystal-lang
miah has joined #crystal-lang
bcardiff has quit [Ping timeout: 272 seconds]
havenwood has quit [Ping timeout: 265 seconds]
Benoist has joined #crystal-lang
havenwood has joined #crystal-lang
<Benoist> can anyone help me out generating strings from bytes. From ruby I can do puts nil.to_msgpack which returns 0xC0. How can I write 0xC0 to a string in crystal so I the string lexer I'm creating can read it from the string or IO?
<Benoist> I'm asking so I can put it in the test case
<jhass> mmh
<jhass> >> "\u00c0"
<DeBot> jhass: # => "À" - http://carc.in/#/r/2xx
<jhass> >> "\u00c0".to_unsafe[0]
<DeBot> jhass: # => 195 - http://carc.in/#/r/2xy
<jhass> mmh
<Benoist> thats not correct :(
<jhass> >> "\x0c0"
<DeBot> jhass: # => "x0c0" - http://carc.in/#/r/2xz
<Benoist> it should be 192
<jhass> >> "\xc0"
<DeBot> jhass: # => "xc0" - http://carc.in/#/r/2y0
<jhass> heh
<jhass> >> "\xC0"
<DeBot> jhass: # => "xC0" - http://carc.in/#/r/2y1
<jhass> odd
<jhass> >> 0xC0.chr.to_s
<DeBot> jhass: # => "À" - http://carc.in/#/r/2y2
<thor77> is there an option to get only the url without args from a http-request?
<jhass> thor77: .split("?", 2).first ?
<thor77> uhm. good idea
<jhass> or we got some URI.parse already
<thor77> oh, just found that. thanks
<jhass> benoist: crystal strings really aren't meant for byte sequences :/
<Benoist> what can I use beter?
<jhass> a Slice
<Benoist> ok
<willl> Slice(UInt8)
<Benoist> Yeah I got it to work with that
<Benoist> but what will it be if you read from a file?
<jhass> IO has interfaces to read into slices, no?
<Benoist> IO can read bytes
<Benoist> which is what I would need I suppose
<Benoist> can I convert a Slice(UInt8) to an IO?
bcardiff1 has quit [Quit: Leaving.]
<jhass> which looks like it does zero bounds checking, so meh
<jhass> SliceIO would be a good thing to do
<jhass> just copy PointerIO and add bounds checking
ddfreyne has quit [Ping timeout: 272 seconds]
asterite has joined #crystal-lang
<asterite> We were talking with waj the other day about this
<asterite> We didn't include the \x escape in strings because we want them to be utf-8
<jhass> yeah makes sense
<asterite> In Ruby you'd use string as any byte sequence
<jhass> I think the tooling around Slice just needs some improvements
<asterite> But in Crystal that's possible too, as long as you don't treat the string as an utf-8 string
<asterite> For example creating a string from bytes doesn't do any utf-8 check
<asterite> There's also StringIO, which should maybe be called MemoryIO and from that you could get a String or a Slice
ddfreyne has joined #crystal-lang
<jhass> >> b :: UInt8[1]; b[0] = 0xC0u8; p String.new(b.to_unsafe)
<DeBot> jhass: "InvalidByteSequenceError: Invalid byte sequence in UTF-8 string - more at http://carc.in/#/r/2y3
<asterite> We probably need to refine these things and decisions
<asterite> b :: UInt8[1]; b[0] = 0xC0u8; p String.new(b.to_unsafe).bytesize
<asterite> >> b :: UInt8[1]; b[0] = 0xC0u8; p String.new(b.to_unsafe).bytesize
<DeBot> asterite: 10 - more at http://carc.in/#/r/2y4
<jhass> well StringIO doesn't have a constructor for Slice or Pointer
<jhass> oh, shit nvm :D
<jhass> regarding my example
<asterite> >> b :: UInt8[1]; b[0] = 0xC0u8; puts String.new(b.to_unsafe)
<asterite> inspect goes char by char, decoding them, and shows some chars as \u{...} or \n, etc. But puts not
<jhass> why didn't the bot reply...
<Benoist> if I pipe the output from my ruby script and use STDIN.read.bytes, I do get the correct byte array
<asterite> benoist: what's your high-level task?
<Benoist> messagepack :)
<asterite> serialize or deserialize?
<Benoist> I need to parse a message pack object from a Sqlite binary column
<jhass> ERROR: invalid byte sequence for encoding "UTF8": 0xc0 0x01
<jhass> *PG::Connection#check_status<PG::Connection, Pointer(Void)>:Nil +206 [3078195737]
<jhass> sigh
<asterite> benoist: For now I'd read a String from sqlite, then... mmm... jhass is right, we need SliceIO
<jhass> I'd still argue the sqlite binding should return a Slice for a binary column
<Benoist> @jhass it does already
<asterite> jhass: I agree
havenwood has quit [Ping timeout: 252 seconds]
<jhass> well then just quickly do the SliceIO
<asterite> me?
<jhass> nah benoist :P
<asterite> Hahaha
<Benoist> haha I'd love to do it :)
<asterite> I'll do it anyway later, I think we need it
<Benoist> i'm still prepared to write the messagepack lexer
<Benoist> I've looked at the JSON and TOML implementations and I think I can create something similar
<jhass> cool
<Benoist> big difference is that JSON and TOML are textbased
<Benoist> and MessagePack is binary
<Benoist> but I think I can get pretty far with the SliceIO
<jhass> if you don't want to do SliceIO you can probably start of with PointerIO and later drop in SliceIO as the safer variant
<jhass> (don't know how messagepack is structured though)
<Benoist> that was the initial attempt without the lexer
asterite has quit [Ping timeout: 246 seconds]
NeverDie has quit [Read error: Connection reset by peer]
NeverDie_ has joined #crystal-lang
bhishma has joined #crystal-lang
sandelius has joined #crystal-lang
havenwood has joined #crystal-lang
BlaXpirit_ has joined #crystal-lang
BlaXpirit has quit [Killed (sendak.freenode.net (Nickname regained by services))]
BlaXpirit_ is now known as BlaXpirit
mdz_ has quit [Remote host closed the connection]
sandelius has quit [Quit: Textual IRC Client: www.textualapp.com]
BlaXpirit has quit [Quit: Quit Konversation]
BlaXpirit_ has joined #crystal-lang
BlaXpirit is now known as Guest73938
BlaXpirit_ has joined #crystal-lang
Guest73938 has quit [Killed (card.freenode.net (Nickname regained by services))]
NeverDie_ has quit [Ping timeout: 265 seconds]
kulelu88 has joined #crystal-lang
NeverDie has joined #crystal-lang
NeverDie has quit [Ping timeout: 250 seconds]