RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | 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> <codenoid> when 0.28.* released
<FromGitter> <parruda> Hey guys, I am trying to create a FIFO and I saw a very old IRC suggesting I could use `LibC.mkfifo`. I was wondering what the arguments are?
<FromGitter> <parruda> Name of the fifo and permissions?
<oprypin> parruda: first of all, "create a first in first out" does not make much sense in general. also, what are you trying to do?
<FromGitter> <parruda> I am trying to do in crystal the same thing I can do when I run the command mkfifo
<oprypin> i don't know that command and no, that's not an end goal
<FromGitter> <parruda> The goal is exactly what I described: create a named pipe
<FromGitter> <parruda> Ok I figured it out, the permissions are in https://crystal-lang.org/api/0.27.0/File/Permissions.html
<FromGitter> <parruda> But I am having trouble writing to the named pipe. I have tried `File.open(“./pipe”, “w+”).puts “test”` and some other variations, but it hangs.
<FromGitter> <parruda> What’s the correct way of doing this?
<FromGitter> <icyleaf> Sorry @j8r i missed message, I want reflecting Object without instance it, fake code like this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf7659fb6c0701052722370]
<FromGitter> <icyleaf> This is now I’m working on it: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf76ee1fa7bbb3fe0ecdb84]
<FromGitter> <dscottboggs_gitlab> @icyleaf I think this might be what you're looking for in regards to your `Mirror` class? https://crystal-lang.org/api/0.27.0/Object.html#forward_missing_to%28delegate%29-macro
<FromGitter> <icyleaf> `forward_missing_to` is used inside of Object, i want use outside of it and without passed nothing instance vars
blove has joined #crystal-lang
blove has quit [Quit: WeeChat 2.2]
_whitelogger has joined #crystal-lang
<FromGitter> <proyb6> ::HTTP::Server.new
<FromGitter> <proyb6> I'm always curious what is the :: before the HTTP?
<FromGitter> <proyb6> just seen in Icyleaf swagger code as well
<FromGitter> <anamba> @proyb6 think of it like a leading / in a file path. in this case, it refers to the top level HTTP in stdlib (there is probably another HTTP in the same scope as that call that would take precedence without the ::)
<FromGitter> <proyb6> @anamba I see, I prefer to clearly declare from stdlib to avoid devs misassuming and use the wrong scope, is there a way to fully declare naming?
<FromGitter> <proyb6> X
<FromGitter> <anamba> i guess you could always write it as `::HTTP::Server` but that would be sort of unusual i think?
rohitpaulk has joined #crystal-lang
<FromGitter> <proyb6> Yeah, looks a bit alien to me and for newbies
sp3ncer has joined #crystal-lang
<FromGitter> <icyleaf> This is also use in Ruby :)
<FromGitter> <proyb6> Oh, could be fine 😁
<FromGitter> <Qard> Is there a good way to recursively convert a JSON::Any to the corresponding primitive types?
<FromGitter> <Qard> Maybe there's a module that does that already somewhere?
<FromGitter> <jemc> There's not really a good way to do that if you don't statically know the shape of the object you want to deal with. The `JSON::Any` abstraction is sort of a necessary part of dealing with that uncertainty in the type system
<FromGitter> <jemc> If you *do* statically know the shape of the object, you can use `JSON.mapping` to map it to a concrete type at parse time: https://crystal-lang.org/api/0.27.0/JSON.html#mapping-macro
<FromGitter> <Qard> Are union types no sufficient to cover that ambiguity?
<FromGitter> <Qard> My specific use-case is passing an arbitrary JSON blob (of unknown form) into lua, which has a type mapping thing here: https://github.com/veelenga/lua.cr/blob/master/src/lua/stack.cr#L77-L94
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <Qard> When it hits a hash, it circles back into itself through this: https://github.com/veelenga/lua.cr/blob/master/src/lua/stack/table_support.cr#L24-L31
<FromGitter> <Qard> In theory I could make a pull request to add support for JSON::Any to that module, but I figured there might be a simpler way than manually writing my own conversion, whether that be in my own code or in a PR to that.
<FromGitter> <jemc> hm, you know I guess I was assuming that type aliases couldn't be directly recursive, but apparently, they can: `crystal eval 'alias JSON = Nil | Bool | Int64 | Float64 | Array(JSON) | Hash(String, JSON); p [nil, true, [false, [true] of JSON] of JSON] of JSON'`
<FromGitter> <jemc> I'm coming from another language (Pony) where we did JSON the same way as `JSON::Any` because of that limitation, but in Crystal the direct type alias recursion seems to work (unless there are other pitfalls I'm not seeing)
<oprypin> Qard: 1) https://crystal-lang.org/api/0.27.0/JSON/Any.html#raw%3AType-instance-method 2) for arbitrary blobs consider JSON::PullParser
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <kingsleyh> hi - I'm trying to build crystal_lib on my mac - and getting this error - could anyone point me in the right direction to fix it?
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf7b59487c4b86bcc03334d]
<FromGitter> <kingsleyh> looks like some LLVM kind of issue
<FromGitter> <kingsleyh> I guess I need to export the LLVM_CONFIG after I figure out what should go in it
<FromGitter> <kingsleyh> ok this seems to fix it `export LLVM_CONFIG=/usr/local/opt/llvm/bin/llvm-config`
<FromGitter> <kingsleyh> thanks for the help :)
sp3ncer has quit [Quit: Textual IRC Client: www.textualapp.com]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 250 seconds]
rohitpaulk has joined #crystal-lang
ashirase has quit [Ping timeout: 252 seconds]
rohitpaulk has quit [Ping timeout: 272 seconds]
rohitpaulk has joined #crystal-lang
ashirase has joined #crystal-lang
moei has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
Vexatos has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
t1|Mike has joined #crystal-lang
<FromGitter> <vladfaust> It would be so great if we had some kind of knowledge base where developers could share such tips
<jokke> anyone in the vicinity of frankfurt germany who'd be interested in a crystal meetup?
<jokke> i'm pretty sure i could organize one at our offices
<jokke> would be cool to meet people and exchange ideas
return0e has quit [Ping timeout: 268 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
return0e has joined #crystal-lang
<FromGitter> <asterite> @jemc Yes, it was recursive before but it's a bit more cumbersome and unintuitive to work with. There's an explanation here: https://github.com/crystal-lang/crystal/pull/5183 . To this day I can't choose which alternative is better, but not having recursive aliases in the language (I'd like to remove them) simplifies the language a lot
<FromGitter> <DRVTiny> Hello4all! ⏎ How to implement structure for usage with libc which will be aligned to "long" type boundary?
<FromGitter> <DRVTiny> I mean sem_t: ⏎ ⏎ ```typedef union ⏎ { ⏎ char __size[__SIZEOF_SEM_T]; ⏎ long int __align; ⏎ } sem_t;`````` [https://gitter.im/crystal-lang/crystal?at=5bf8053197a8982b9a50ded8]
<FromGitter> <DRVTiny> I want to implement POSIX::Semaphore class, but i dont know how to declare sem_* functions, which operates on/with sem_t
Jenz has joined #crystal-lang
<Jenz> >> p +-+-10
<Jenz> How was it, did we have a bot in here?
<Jenz> (That can eval crystal code)
<FromGitter> <DRVTiny> Oh, yes. I have to do it, because i need to implement "guarding thread" to do cleaning work after program finished by some exit signal like TERM, INT, etc. ⏎ Standard Crystal implementation of signal handlers is awful, because signal handlers useless with any spawned code which is doing long calculations.
<FromGitter> <DRVTiny> @FromIRC 10
* Jenz O_o
<jokke> is there any ETA for 0.27.1
<jokke> ?
<jokke> for those thinking crystal isn't suited for anything but small projects or micro services: my current project has a codebase with >3k lines of code (not including the lib and spec directory) and it works like a charm.
<jokke> including lib and spec it's a whooping 33k lines
* Jenz :O
<Jenz> How long does it take to compile?
<FromGitter> <kingsleyh> great question!
<jokke> without --release: 0.52s user 0.10s system 6% cpu 9.506 total
<Jenz> 0.52s user? What shell (framework) do you use!
* Jenz XD
<jokke> :D that's because it's run in docker
<Jenz> Oh
<jokke> i have to compile for 0.26.0 because that's the only version working in alpine
<Jenz> Haha, ok, either 9.5 is really nice
<Jenz> s/either/either way/
<jokke> yeah it's quite ok
<Jenz> On my old MacBook Air though...
<jokke> (i need alpine, because i'm statically linking and deploying as a docker image based on the scratch image)
<jokke> with --release it takes ages though
* Jenz doesn't know what a scratch image is
<jokke> Jenz: it's empty
<jokke> there's nothing there
<Jenz> oh ok
<jokke> so you can just copy the statically linked binary into the image and then set CMD to ["/bin/your-program"]
<jokke> with --release: 0.56s user 0.10s system 0% cpu 1:38.63 total
<jokke> but that's done by the CI anyway
<FromGitter> <Blacksmoke16> depends on what your project is doing, my project + ameba (is the only lib) and is ~14k lines
<FromGitter> <Blacksmoke16> but build in release takes like less than a sec
<FromGitter> <Blacksmoke16> granted most of those lines are specs
<FromGitter> <DRVTiny> crystal supports multithreaded compilation, doesn't it?
<jokke> Jenz: i have a thinkpad x270 so it's not a beast either
* Jenz :)
<FromGitter> <kingsleyh> is there a difference between `crystal run src/x.cr` and `crystal src/x.cr`
<Jenz> no
<FromGitter> <kingsleyh> ok good - one less word to type
<jokke> i'd love crystal run to output something when it's done compiling
<jokke> it's annoying when you start up something that it blocking (waiting for input or listening on a socket)
<jokke> sure, you can add output to your program but still :P
<Jenz> haha
<FromGitter> <DRVTiny> Does anybody hear me? :) I don't know, whether bots checker accepts my messages or no
<Jenz> Haha we do
<FromGitter> <DRVTiny> Oh, it's cool! How to patch KDE2 on FreeBSD? :)
* Jenz O_o
<Jenz> I wouldn't know
<FromGitter> <DRVTiny> How to align "struct" inside "lib C" blocks? :)
<FromGitter> <DRVTiny> To, say, 4-bytes boundary?
<Jenz> I've no idea
<FromGitter> <DRVTiny> ```code paste, see link``` ⏎ ⏎ OMG... Maybe, there are some sinpler ways to do so? [https://gitter.im/crystal-lang/crystal?at=5bf8101c66213138940766c5]
<FromGitter> <j8r> I've just further improved the performance of https://github.com/j8r/con#benchmarks, 10% faster than stdlib's JSON for parsing, 50% faster for building
<Jenz> Oh wow, I like, @j8r!
<jokke> j8r: nice! starred
<FromGitter> <j8r> thanks :) I hope the work could be reused to improve the JSON parser back
<Jenz> _Cretin_ Object Notation, huh
<jokke> j8r: hm any reason you're implementing mapping instead of serializable?
<jokke> i _love_ JSON::Serializable
<FromGitter> <j8r> (my mapping implem still need work like specs) Because I think it's too complicated
<jokke> hmm
<jokke> it is much more flexible though
<jokke> and it's not that complicated
<FromGitter> <j8r> we can already use what we already have
<FromGitter> <j8r> getter, setter, property and ivars with type annotation
<FromGitter> <j8r> to defined them as `String`, or `String?` if nillable etc
<Jenz> Anyone got around to play with annotations yet?
<Jenz> (user defined ones)
<jokke> sure
<jokke> check out env_config
<FromGitter> <j8r> please jokke tell me in https://github.com/j8r/con/blob/master/src/mapping.cr#L19 what's missing, because annotation are quite powerful
<FromGitter> <j8r> I may miss something
<jokke> ah i see you do it this way
<jokke> hm
<jokke> well it doesn't support inheritance
<jokke> or am i missing something
<FromGitter> <j8r> Why inheritance, for what purpose?
<jokke> well if you have common attributes
<jokke> idk. something like id, created_at, updated_at for instance. Something that's there for all subclasses.
<jokke> tedious to define it again and again
<Jenz> Yeah, I can imagine a number of scenarios where inherintance'd be useful
<jokke> this was the main reason for JSON::Serializable afair
<FromGitter> <j8r> inheritance or composition
<FromGitter> <j8r> i see
<jokke> yeah
<jokke> also i think it's always nicer to have a common interface
<jokke> if you know how to use JSON::Serializable you know how to use env_config
<FromGitter> <j8r> I will think to solve this. At then end, merging two namedtuples in a macro would do the trick
<FromGitter> <j8r> But it has to be simple for the user
<jokke> it doesn't get much simpler than with the Serializable interface
<FromGitter> <j8r> Thanks jokke, that's a good point
<jokke> except of course when you need to set key or converters
<FromGitter> <j8r> I disagree
<FromGitter> <j8r> We have to learn annotations to use Serializable
<jokke> but then it helps if it behaves the same way as JSON::Serializable
<jokke> sure
<jokke> but in your case i have to learn your api
<FromGitter> <j8r> CON is an experimentation, I wasn't even sure it would end up faster than stdlibs JSON.
<jokke> i'm glad it did :) it's a cool format
<FromGitter> <j8r> the API isn't that hard: only a macro with `method_name => CON key` association
<FromGitter> <j8r> Perhaps I'll end up doing CON::Serializable - not sure as now
<Jenz> Yeah, though personally I very much enjoy the JSON.mapping where I just need to specify key, and type
<Jenz> And the method name'll be the same as the json key
<FromGitter> <j8r> does anyone use/know the purpose of https://crystal-lang.org/api/master/JSON/PullParser.html#read_raw-instance-method and https://crystal-lang.org/api/master/JSON/PullParser.html#on_key%28key%2C%26block%29-instance-method ? ⏎ I've replaced the `on_key` by a `case/when`
<jokke> j8r: but what if i want to use camel cased keys and store them in snake cased vars?
<jokke> and what about converters?
<FromGitter> <j8r> like `"CamelCase_var": somekey`
<jokke> of course the simple scenario is always simple. With JSON::Serializable even more so since you literally don't have to do anything else than include it.
<jokke> j8r: i mean if your serialized format uses camelCaseThing and your model has the attribute camel_case_thing
<FromGitter> <j8r> which will iterate in all instance vars.
<jokke> yeah
<jokke> you will have to use @[JSON::Field(ignore: true)] to ignore something, that's correct
<FromGitter> <j8r> jokke: this is white listing vs black listing.
<FromGitter> <Blacksmoke16> there are some downfalls of serializable i tried to overcome with my shard
<FromGitter> <Blacksmoke16> like if you use `key` it uses that for both deserialization and serialization
<FromGitter> <Blacksmoke16> ignore does on both as well
<FromGitter> <Blacksmoke16> id really like to implement like a `path` annotation that would traverse the JSON structure and set the ivar to that value, but is WIP
<FromGitter> <jemc> Regarding `JSON.mapping` vs `JSON::Serializable`- I tried to switch to the latter, but it seems to still be buggy in some cases (or maybe it's annotations themselves that are buggy?): https://github.com/crystal-lang/crystal/issues/6663#issuecomment-434129657
<FromGitter> <j8r> @Blacksmoke16 that's a powerful approach for serialization :)
<FromGitter> <Blacksmoke16> thanks man :)
<FromGitter> <Blacksmoke16> is pretty slick
akaiiro has quit [Remote host closed the connection]
akaiiro has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
blassin has quit [Read error: Connection reset by peer]
blassin has joined #crystal-lang
return0e has quit [Ping timeout: 245 seconds]
return0e has joined #crystal-lang
<Jenz> How can I make this work? https://play.crystal-lang.org/#/r/5m5a
<Jenz> Do I have to use classes instead of modules?
<FromGitter> <Blacksmoke16> well yea, including modules wouldnt be a subclass
<Jenz> Yeah I realized that was the problem, but, is there no way to get all including types?
<FromGitter> <Blacksmoke16> i dont think so?
<Jenz> Ok, thanks, @Blacksmoke16!
<FromGitter> <Blacksmoke16> because in your example including Foo doesnt really do anything as `Foo` doesnt have any methods
* Jenz ¯\_(ツ)_/¯
<Jenz> Classes'll do fine
<FromGitter> <Blacksmoke16> 👍
Jenz has quit [Quit: byeee]
<FromGitter> <DRVTiny> How to get known the word size on a current running system (64, 32)?
<FromGitter> <DRVTiny> Without something like ⏎ ⏎ ```i : LibC::Int ⏎ i.size``` [https://gitter.im/crystal-lang/crystal?at=5bf8418187c4b86bcc06d3d1]
<FromGitter> <DRVTiny> Hmm... It doesn't work too
<FromGitter> <j8r> The word size?
<FromGitter> <DRVTiny> @j8r 64 on 64bit and 32 on 32bit system
<FromGitter> <j8r> https://carc.in/#/r/5m5n
<FromGitter> <DRVTiny> ```sizeof(LibC::Int)```
<FromGitter> <DRVTiny> @j8r Hmm... sizeof() doesn't work in a macroses. Flags is much better, thank you!
<FromGitter> <DRVTiny> @j8r https://carc.in/#/r/5m5q
<oprypin> DRVTiny, how about, like, `sizeof(LibC::Int)`
<oprypin> also thats not even the right type to use
<oprypin> use `sizeof(LibC::SizeT) * 8`
<FromGitter> <DRVTiny> @FromIRC It's OK but not work at compile time
<FromGitter> <DRVTiny> I need WORD_SIZE to correctly implement sem_t here: https://github.com/DRVTiny/crystal-by-example/blob/master/semaphores/lib/posix_semaphores.cr ⏎ So i need it in compile time
non-aristotelian has joined #crystal-lang
DTZUZO has quit [Ping timeout: 245 seconds]
akaiiro has quit [Remote host closed the connection]
DTZUZO has joined #crystal-lang
sp3ncer has joined #crystal-lang
sp3ncer has quit [Quit: Textual IRC Client: www.textualapp.com]
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 268 seconds]
<FromGitter> <drum445> What is the preferred way to store things like db credentials or ports to listen on, in PHP I would use a .env file and load from there?
<FromGitter> <Blacksmoke16> env would prob best best bet yea
<FromGitter> <Blacksmoke16> if you use docker thats easily configurable
<FromGitter> <drum445> Is there a way in std lib to load a .env file into your https://crystal-lang.org/api/0.19.2/ENV.html?
<FromGitter> <Blacksmoke16> could just run a bash command like `source .env`
<FromGitter> <drum445> ah right, so just ⏎ $ source .env && ./app
<FromGitter> <drum445> should do it fine?
<FromGitter> <Blacksmoke16> should do
<FromGitter> <drum445> Just made this is anyone is interested :) https://github.com/drum445/dotenv
<FromGitter> <Blacksmoke16> that was quick :p
<FromGitter> <drum445> haha, beauty of crystal I guess
<FromGitter> <drum445> Do you know why I use my libs as a shard it shows the commit instead of the version in the shard.lock? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf8705697a8982b9a53be0b]
<FromGitter> <Blacksmoke16> prob since you dont have a version released on github just uses latest commit?
<FromGitter> <drum445> Imagine so, how would I release a version please/
<FromGitter> <Blacksmoke16> and make the version `v0.1.0`
<FromGitter> <Blacksmoke16> then in `shard.yml` and do `version: 0.1.0`
<FromGitter> <drum445> Yeah that got it, thanks a lot good sir
<FromGitter> <Blacksmoke16> np
<FromGitter> <j8r> @ed if you use systemd you can use `EnvironmentFile`
<FromGitter> <drum445> oh right, will look into that cheers
<FromGitter> <drum445> I'm still just running my services on servers by doing ./app tbh
<FromGitter> <drum445> Do you put nginx in front of it?
<FromGitter> <j8r> How do you do then?
<FromGitter> <j8r> On my side I use caddy
<FromGitter> <drum445> I just build a release binary, upload to my server and run in the background on a certain port
<FromGitter> <DanilaFe> I use nginx to reverse proxy
<FromGitter> <DanilaFe> with the benefit that the same server can serve different crystal programs on the same IP and outward port
<FromGitter> <drum445> Yeah that does sound nice, I've got a few apps running on the same server so I have to have diff ports
<FromGitter> <drum445> Any documentation on how to get it up and running with nginx @DanilaFe ?
<FromGitter> <drum445> @j8r caddy looks clean
<FromGitter> <DanilaFe> To be honest with you I just googled around a while ago
<FromGitter> <DanilaFe> caddy looks interesting
<FromGitter> <j8r> You'll have https and simple conf :)
<FromGitter> <drum445> so if I'm using kemal, I would serve it on port 3000, then nginx/caddy would reroute an http(s) call to 3000 without having to specify the port?
<FromGitter> <j8r> @ed i strongly recoend you setting up services - if your app/server crash/reboot, your app will be down
<FromGitter> <DanilaFe> What you can do with nginx (and probably caddy) is to accept requests on port 80 / whatever the ssl port is, and route them to 3000 etc depending on what the URL even is
<FromGitter> <DanilaFe> and yeah, I personally use systemd to manage my running kemal instances
<FromGitter> <drum445> @j8r yeah I will do thanks mate. So Nginx basically just reroutes requests from port 80/443 to a localhost:PORT depending on the requet's path?
<FromGitter> <j8r> @ed by default Caddy will expose https/443. If you write example.com, it's https://example.com(:443)
<FromGitter> <drum445> Yeah I'm using let's encrypt/apache for most my stuff currently
<FromGitter> <j8r> Yes, that a reverse proxy
<FromGitter> <drum445> so you'd still run it in the same way I am ⏎ $ nohup ./app & ⏎ but you'd make that not face the internet and nginx route to it instead?
<FromGitter> <drum445> well a service actually instead of that nohup stuff
<FromGitter> <DanilaFe> Yeah, a service
<FromGitter> <j8r> The good point of nginx/caddy and even haproxy is loadbalancing. You told me you have multiple servers. If one goes down, your app will still be available :)
<FromGitter> <DanilaFe> you can configure it to auto-restart if it crashes
<FromGitter> <drum445> ah lovely, think I've got it now - will get it running as a service and behind nginxor caddy tomorrow. Thanks fellas!
<FromGitter> <DanilaFe> Good luck!
<FromGitter> <drum445> It's the problem with just letting our ops team sort most of the server side stuff out ;)
<FromGitter> <j8r> You have an app in prod running with nohup with no reverse proxy @ed ?!
<FromGitter> <drum445> In golang, my crystal stuff is just personal use for now
<FromGitter> <drum445> Work uses Python/Nginx etc..
<FromGitter> <drum445> But our ops guys have set that up
<FromGitter> <drum445> Tah for that link