RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <Timbus> @jspillers .. Neat. I would consider defining it as `.to_h(stringify: true)`, or something. Your broader 'conversion' suggestion ( `.to_h(String,String)` ) would require a whole converter suite.. similar to dlang's excellent std.conv toolkit.
pabs has quit [Ping timeout: 240 seconds]
pabs has joined #crystal-lang
<FromGitter> <fridgerator> @drum445 whats wrong with mappings?
<FromGitter> <jspillers> @Timbus oh right... great suggestion - i forgot method signature overloading is a thing here (solid name btw - i approve :) )
hplar has joined #crystal-lang
<FromGitter> <Timbus> Just as a side note, you can also simplify a little bit: `string_keys = keys.map {|k| k.to_s }.to_a` -> `string_keys = keys.flat_map &.to_s`.. and yes, rare to see another Jarrod :)
<FromGitter> <bew> Huh why did you change `map` to `flat_map`?
<FromGitter> <bew> Ah it directly builds an array
<FromGitter> <bew> That's weird, and looks like a bug
<FromGitter> <Timbus> oh, yeah
<FromGitter> <bew> I mean, it's not meant to be used to solve this problem, and just reading the code using it, it's not clear what it's doing and why..
<FromGitter> <Timbus> I didn't even think about it, I just figured "flatmap always returns arrays"
<FromGitter> <aisrael> TIL `&.method` shortcut
<FromGitter> <Timbus> its super nice ey
<FromGitter> <aisrael> I mean I knew about `&:method` in Ruby, just didn't realize the Crystal equivalent 👍
<FromGitter> <Timbus> it's not exactly the same, eg: `[1,2,3].map &.* 2`
<FromGitter> <Timbus> unless ruby can do that?
duane has joined #crystal-lang
<FromGitter> <vlazar> yes, you can make Ruby do the same but Crystal's version is better
<FromGitter> <aisrael> `[1,2,3].map &.* 2` nice!
<FromGitter> <jgaskins> Yeah, Ruby can do it, but it requires a monkeypatch to `Symbol` :-D https://twitter.com/jamie_gaskins/status/1000056004321701888
<FromGitter> <Timbus> erk
_whitelogger has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
duane has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
lvmbdv has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<FromGitter> <rishavs> Need help with setting my server on Heroku. :( ⏎ Logs show this error and I am not sure why it is happening. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b46e59a897d514b3c45daaa]
pabs has quit [Ping timeout: 244 seconds]
ikk- has joined #crystal-lang
ikk- has quit [Quit: Page closed]
rohitpaulk has joined #crystal-lang
pabs has joined #crystal-lang
<FromGitter> <drum445> @fridgerator nothing wrong with mapping just having to add DB mapping and JSON mapping to each class makes them look very messy
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <drum445> How do you guys go about getting data from a db? Do you use the ? syntax and rs.read(T)
rohitpaulk has quit [Ping timeout: 240 seconds]
<crystal-gh> [crystal] straight-shoota opened pull request #6369: Add location as required argument for Time.parse (master...jm/feature/time-parse-location) https://git.io/fNLJm
<FromGitter> <aisrael> @drum445 What do you mean "? syntax"? I just go `db.query_all("SELECT foo FROM bar") do |rs|` and then, yes, `rs.read(T)`
<FromGitter> <drum445> So "select * from foo where bar = ? and x = ? and y = ?", "bar", 32, 45 do |rs|
<FromGitter> <drum445> I guess my trouble is that when selecting a lot of data rs.read becomes a bit unreadable
<FromGitter> <aisrael> Yeah. Well, that's why I'm writing something like Ruby's Sequel or Java's jOOQ. While I appreciate e.g. Granite ORM 1) I think there's room for an alternative approach (not AR-style ORM, just SQL generation and mapping), 2) I'm wary about how far the macro approach can go. ActiveRecord is able to work its magic because Ruby. jOOQ and Sequel use purely OO approach (no meta programming).
<crystal-gh> [crystal] straight-shoota opened pull request #6371: Add ECR.render for rendering without setting up an IO (master...jm/feature/ecr-render) https://git.io/fNLUc
<FromGitter> <aisrael> So far I have query generation (PostgreSQL only), working on mapping next. Will probably have something like Sequel's `Dataset`
rohitpaulk has joined #crystal-lang
<FromGitter> <drum445> @aisrael I'm trying to do something similar here: https://github.com/drum445/objectify
<FromGitter> <drum445> Just hit a wall though where every class attr needs to be union type nil for it to work which isn't ideal
<FromGitter> <drum445> But no idea of a way around it
<FromGitter> <aisrael> Use the constructor route? I mean, that's how I
<FromGitter> <drum445> What do you mean sorry?
<FromGitter> <aisrael> Um... admittedly Crystal doesn't (yet) have reflection but maybe you can do it at compile time with macros. Like, `Objectify.to_object(rs, klazz)` ends up calling `klazz.new(*args)`
<FromGitter> <drum445> Yeah I was banking on reflection, something like .send in ruby. ⏎ How would the initializer look on klazz if I'm passing args?
<FromGitter> <aisrael> No different from normal? I mean, you (obviously) can't introspect the class to find out it's attributes and look for an appropriate constructor—but using macros maybe you can, or you can just go ahead and generate one
<lvmbdv> > Crystal doesn't (yet) have reflection
<lvmbdv> hwat
<lvmbdv> crystal has great reflection
<FromGitter> <codenoid> how to do bcrypt hash, and bcrypt verify in crystal
<FromGitter> <codenoid> it's too hard to find simple documentation about that
ashirase has quit [Ping timeout: 260 seconds]
ashirase has joined #crystal-lang
<FromGitter> <rishavs> @codenoid here is what I am doing; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b471a3e1c0f906b144aedf8]
<FromGitter> <aisrael> @LVMBDV At compile-time, you mean?
<lvmbdv> yeah
<lvmbdv> compile-time is best time :>
<FromGitter> <codenoid> Crypto::Bcrypt::Password.new(user["password"].to_s)
<FromGitter> <aisrael> @LVMBDV Sure. Yeah, I guess I meant to say it doesn't have as rich (runtime) reflection (though, I'll settle for compile-time and macros if it serves my needs) as Ruby or Java—enumerate a class' methods, constructors, etc.
<lvmbdv> runtime reflection would add a lot of overhead tho
<lvmbdv> but i see your point
<FromGitter> <aisrael> I understand. Which is why I thought maybe Crystal can its magic at compile-time. That, or maybe make it a flag of some sort. Maybe even a mixin/module, e.g. `include RuntimeReflection` ;)
<FromGitter> <drum445> @LVMBDV yeah we meant runtime reflection
<lvmbdv> You could make a shard for that :)
<FromGitter> <aisrael> How to redefine `def` though. A macro (`def_with_reflection`), somehow?
<lvmbdv> to keep a record of macros?
<lvmbdv> could add a `method_added` hook to Class/Object/Value (iunno which) instead
<FromGitter> <aisrael> 💡
<FromGitter> <aisrael> So... if I wanted to avoid having to type `Module::Foo` everywhere, is the recommended way still `alias Foo = Module::Foo`?
<FromGitter> <Grabli66> Hi! I tried to cross-compile my program to arm. I got an object file and string which i need launch on target OS. And i saw a "/usr/share/crystal/src/ext/libcrystal.a" in that string. But there is no librystal.a on target OS. Where i can find it? :)
<FromGitter> <SamualLB> Hello, I am trying to create an ncurses macro to generate the F keys. I am currently trying to declare this in a Lib enum.
<FromGitter> <SamualLB> ```{% for n in (0...64) %} ⏎ F{{n}} = 0o410 + {{n}} ⏎ {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5b472ee1d1428e5aefe082fc]
<FromGitter> <SamualLB> I have tried this inside and outside the enum but I get errors for reopening an enum and can't declare type inside enum, does anybody know an solution? Thanks
rohitpaulk has quit [Ping timeout: 248 seconds]
<crystal-gh> [crystal] myfreeweb opened pull request #6373: Add support for FreeBSD/aarch64 (master...freebsd-aarch64) https://git.io/fNL8q
<crystal-gh> [crystal] straight-shoota opened pull request #6374: Add pp! and p! macro methods (master...jm/feature/macro-pp) https://git.io/fNL0u
alex``` has joined #crystal-lang
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
lvmbdv has quit [Ping timeout: 240 seconds]
<FromGitter> <fridgerator> @drum445 You can do both mappings at the same time with a macro
lvmbdv has joined #crystal-lang
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
duane has joined #crystal-lang
<FromGitter> <martinos> I am wonder if there's a way to write generic procs. I would like to create some Proc as such: `id = ->(a) {a}`. Is this possible ?
<FromGitter> <straight-shoota> @Grabli66 Run `make libcrystal` in Crystal directory on target platform.
wontruefree has joined #crystal-lang
<FromGitter> <straight-shoota> @martinos Procs need to be fully typed because of their nature, the types can't be automatically inferred.
wontruefree has quit [Client Quit]
wontruefree has joined #crystal-lang
<FromGitter> <straight-shoota> Depending on what you want to do, there might be workarounds, though
<FromGitter> <martinos> Compiled functional languages can do it. It's possible to do but maybe not with Crystal.
<FromGitter> <martinos> I wished that I could translate a lib that I have done in Ruby. Thanks
<FromGitter> <straight-shoota> Yes, it's not systematically impossible, but Crystal can't do it (currently).
<FromGitter> <straight-shoota> This is somewhat similar to ivar types. Theoretically, you should be able to have a ivar type `Object`, but it's not possible yet.
wontruefree has quit [Quit: bye]
alex``` has quit [Quit: WeeChat 2.1]
wontruefree has joined #crystal-lang
lvmbdv has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] ysbaddaden opened pull request #6376: Proof of Concept: detect stack overflows (x86_64-linux-gnu target only) (master...poc-detect-stack-overflow) https://git.io/fNLDg
<crystal-gh> [crystal] ysbaddaden closed pull request #6367: Syntax: allow empty `case` without `when` (master...jm/feature/case-without-when) https://git.io/fNIXN
<crystal-gh> [crystal] sdogruyol pushed 1 new commit to master: https://git.io/fNLyE
<crystal-gh> crystal/master 6a30458 Johannes Müller: Add pp! and p! macro methods (#6374)
lvmbdv has joined #crystal-lang
alex``` has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 2.1: ¡Chau!]
<robacarp> another disaster with npm dependency management: https://github.com/eslint/eslint-scope/issues/39 "Virus in eslint-scope?"
<travis-ci> crystal-lang/crystal#bec784d (master - Merge pull request #6367 from straight-shoota/jm/feature/case-without-when): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/403160136
<DeBot> https://github.com/crystal-lang/crystal/pull/6367 (Syntax: allow empty `case` without `when`)
<travis-ci> crystal-lang/crystal#6a30458 (master - Add pp! and p! macro methods (#6374)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/403162543
<DeBot> https://github.com/crystal-lang/crystal/pull/6374 (Add pp! and p! macro methods)
<FromGitter> <fridgerator> holy shit
<wontruefree> I dont know much about segfaults except it happens when you try to access protected memory. If you are in the segfault handler is it ok to allocate a new object?
<FromGitter> <bararchy> Good question wontruefree I was also thinking what would that help at
<FromGitter> <bararchy> TBH if I could at least rescue from something like that, it would be nice
<FromGitter> <bararchy> Or sigfault
<FromGitter> <bararchy> `sigfault do `
<FromGitter> <bararchy> Etc..
Raimondi has joined #crystal-lang
wontruefree has quit [Quit: bye]
alex``` has quit [Quit: WeeChat 2.1]
alex``` has joined #crystal-lang
<robacarp> wow
rohitpaulk has joined #crystal-lang
wontruefree has joined #crystal-lang
<wontruefree> wow
<FromGitter> <fridgerator> The Benevolent Dictator For Life - No More
wontruef_ has joined #crystal-lang
<wontruef_> yeah no joke
wontruef_ has quit [Client Quit]
wontruef_ has joined #crystal-lang
wontruefree has quit [Ping timeout: 256 seconds]
<FromGitter> <asterite> I understand him. Discussions in issue trackers make you really tired. You want to create a language, or change something in it because you learned from past mistakes, but there will be many that will argue those decisions, and then you get angry, furious, etc. I actually did the same him as he, I just didn't announce it. I give my comments, I send PR, but I don't merge code anymore not approve PRs.
<FromGitter> <asterite> I let the community direct the language, which seem to know better how to do things
<Yxhuvud> well, lets hope it ends up working out. sometimes controversial changes must be made and those are hard to get past a design that is by commitee
<FromGitter> <asterite> like `case` without `when` and `else` :-P . I'm not sure about that change, but I don't care much anymore, it's just a tool
<Yxhuvud> well, that one is pretty uncontroversial in that it doesn't break anything and noone is expected to write code like that manually.
<FromGitter> <asterite> true
duane has quit [Ping timeout: 244 seconds]
wontruef_ has quit [Quit: bye]
wontruefree has joined #crystal-lang
lvmbdv has quit [Ping timeout: 268 seconds]
duane has joined #crystal-lang
<FromGitter> <solisoft> Hi there
<FromGitter> <solisoft> I would like to convert an ISO-8859-15 string to UTF8
<FromGitter> <solisoft> I tried mystring.encode "UTF8" but it raise an error
<FromGitter> <solisoft> any help will be welcome
<FromGitter> <solisoft> the error is : `#<ArgumentError:Invalid multibyte sequence>`
<FromGitter> <straight-shoota> It looks like your string contains an invalid multibyte sequence and can't be converted to ISO-8859-15. The API docs explain this: You need to specify `:skip` as parameter to skip invalid sequences. https://crystal-lang.org/api/0.25.1/String.html#encode%28encoding%3AString%2Cinvalid%3ASymbol%3F%3Dnil%29%3ABytes-instance-method
<FromGitter> <solisoft> well running ` iconv -f ISO-8859-15 -t UTF-8 demo.txt` in my terminal works fine
<FromGitter> <solisoft> I don't want to loose some chars
<FromGitter> <solisoft> it's a french text with some accents
<FromGitter> <solisoft> there is a way to do that ?
<FromGitter> <solisoft> if not, I'll create a big file and I'll will convert it using iconv
<FromGitter> <straight-shoota> can you show a minimal reproducible sample?
<FromGitter> <straight-shoota> `String#encode` uses `libiconv`. I'm pretty sure that the `iconv` CLI tool can only do things the lib can do.
<FromGitter> <bew> Looks like his string is initially in iso-xxxxxx format, and you want it in utf8 right?
<FromGitter> <bew> So it should be decode instead of encode?
<FromGitter> <solisoft> Ah maybe
<FromGitter> <bew> Hmm doesn't exist..
<FromGitter> <bew> Where is your string coming from?
<FromGitter> <solisoft> from this website
<FromGitter> <solisoft> I use ⏎ ⏎ ``` if response.status_code == 200 ⏎ doc = response.body.gsub(/[\r\n]/, "")`````` [https://gitter.im/crystal-lang/crystal?at=5b47b750d1428e5aefe24650]
<FromGitter> <straight-shoota> Oh, you wan't to encode *from* iso to utf
<FromGitter> <straight-shoota> `String#encode` can only convert from utf because the string in Crystal is expected to be utf
<FromGitter> <solisoft> so there is no way ?
<FromGitter> <straight-shoota> Not with `String#encode`
<FromGitter> <straight-shoota> But with `IO#encoding`
<FromGitter> <straight-shoota> set `response.body_io.encoding = "ISO-8859-15"`
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <solisoft> undefined method 'encoding=' for IO::ARGF (compile-time type is IO+) ⏎ ⏎ ```response.body_io.encoding = "ISO-8859-15" ⏎ ^~~~~~~~``` [https://gitter.im/crystal-lang/crystal?at=5b47b8c11c0f906b144ce8ba]
<FromGitter> <straight-shoota> Oh, sry it's `set_encoding`
<FromGitter> <solisoft> response = HTTP::Client.get "http://www.allo-medecins.fr/modifie.php?id=#{i}" ⏎ if response.status_code == 200 ⏎ ⏎ ```response.body_io.set_encoding "ISO-8859-15" ⏎ doc = response.body.gsub(/[\r\n]/, "")``` [https://gitter.im/crystal-lang/crystal?at=5b47b9749a612333aa5b1669]
<FromGitter> <solisoft> raise ; Unhandled exception: Nil assertion failed (Exception) ⏎ from /usr/local/Cellar/crystal-lang/0.25.0_1/src/nil.cr:106:5 in 'not_nil!' ⏎ from /usr/local/Cellar/crystal-lang/0.25.0_1/src/http/client/response.cr:9:3 in 'body_io' ⏎ from src/fetch_data.cr:14:5 in '__crystal_main' ⏎ from /usr/local/Cellar/crystal-lang/0.25.0_1/src/crystal/main.cr:104:5 in 'main_user_code' ...
<FromGitter> <solisoft> ok nevermind ... saving raw output in a file
<FromGitter> <solisoft> i'll convert it then i'll load it in an another script
<FromGitter> <solisoft> thanks
<FromGitter> <straight-shoota> That's strange, why is `body_io` not set...
<FromGitter> <straight-shoota> Anyway, if you have a string in non-utf-8, you can just decode it using `String.new(iso_string.to_slice, "ISO-8859-1")`
<FromGitter> <solisoft> Great worked just fine
<FromGitter> <solisoft> Thanks
<FromGitter> <asterite> body_io only works in the block form
<FromGitter> <asterite> so something like: `HTTP::Client.get("...") { |response| response.body_io.set_encoding("..."); if response.status_code == 200; etc. }` should work
<FromGitter> <asterite> I find it funny the the encoding comes in an html tag, but to understand that you need to know the encoding...
<FromGitter> <asterite> we can probably improve `body_io` to raise a description like "body_is is only available in the block form" if it's nil...
ashirase has quit [Ping timeout: 244 seconds]
<FromGitter> <straight-shoota> yeah, I suspected something like that
<FromGitter> <straight-shoota> Some API documentation would already help ;)
ashirase has joined #crystal-lang
johndescs_ has joined #crystal-lang
johndescs_ is now known as johndescs
johndescs has quit [Ping timeout: 264 seconds]
alex``` has quit [Ping timeout: 248 seconds]