<FromGitter>
<andrewc910> So I just had my first big problem that wouldn't be a in a dynamic language. After several days of work I realized my idea wouldn't really work. The frontend would be sending a json containing a serialized object & the method we need to invoke. I would then invoke that method, rerender the component & send the state to the frontend. It's like LiveView from Phoenix Framework. ⏎ ⏎
<FromGitter>
<Blacksmoke16> make a hash mapping method name to procs that you create from the methods
<FromGitter>
<Blacksmoke16> ideally that accept a static amount of arguments
<FromGitter>
<Blacksmoke16> or generate overloads at runtime based on the type of the klass
<FromGitter>
<Blacksmoke16> prob could have some method on the parent that builds out a `case` statement, including annotated methods, that match the string name to the method to execute
<FromGitter>
<Blacksmoke16> that could work if you dont need return values and everything is nil, and/or they dont need input values either...
<FromGitter>
<andrewc910> I don't understand the first 2 suggestions. Would it be possible to ask for a small code example? ⏎ ⏎ I tried a `case` which was similar to the code i supplied above. Still just feels wrong? IDK, if it's not wrong then okay, i'll take it but just looking at it... ⏎ ⏎ No methods that I would be invoking this way accepts arguments or has return values. They only update the state and then they all
<FromGitter>
<Blacksmoke16> or do you need that other type that these get passed to?
<FromGitter>
<andrewc910> No, that looks perfect. I only had the action class just to pull the macro away from base for a moment.
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<andrewc910> I will play around with this. Thank you! :D
<FromGitter>
<Blacksmoke16> np
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo29 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo29 is now known as alexherbo2
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<lodenos> ``````
livcd has quit [Ping timeout: 264 seconds]
postmodern has joined #crystal-lang
<postmodern>
what happened to Markdown in the stdlib? Should I use markd for markdown parsing?
<FromGitter>
<lodenos> Hello Guys, ⏎ I haven't really understand my mistake, I know just `@context, params` inside the macro doesn't work, gut if I replace the notation by `{% Board.delete %} @context, params` I have an error too, like `Error: unexpected token: @context`. ⏎ And my macro is inside a class, and I use a macro nested for \{% Board......... ⏎ ⏎ ```code paste, see link``` ...
<yxhuvud>
postmodern: I think it has been moved into compiler private areas.
sagax has quit [Ping timeout: 272 seconds]
yxhuvud has quit [Remote host closed the connection]
yxhuvud has joined #crystal-lang
<FromGitter>
<lodenos> Hum,... the problem is I have a macro for generate my functions in a file and after I use a new macro in another new file, but the macro in the top level try to call the functions but the macro more down haven't yet expending the code,
<FromGitter>
<lodenos> I would like why not, but I would like forcing the compilator for executing the AST I need for it
xyhuvud has joined #crystal-lang
yxhuvud has quit [Client Quit]
iii has joined #crystal-lang
sagax has joined #crystal-lang
duane has joined #crystal-lang
<postmodern>
can shards build the executables of development dependencies, such that they're available to run them locally inside the project?
iii has quit [Quit: leaving]
<FromGitter>
<naqvis> postmodern shards are usually library, but if some shards provide some executable, then they should build that via `postinstall` hook
<FromGitter>
<naqvis> `shards install` ensure that shard and its dependencies are downloaded and made available for dependent program
<postmodern>
naqvis, what if the other shards define their own postinstall hooks to build various executable utils? are those made available somewhere in say lib/ or will they be put in bin/ ?
<FromGitter>
<naqvis> yeah, they should be
<postmodern>
naqvis, trying to think how i could make executable utils meant to be used during development, available to the developer via shards without having to install the executables globally.
<FromGitter>
<naqvis> if you are developing them as shard, wouldn't it make more better to expose that via some API?
<FromGitter>
<naqvis> i mean you can expose the functionality via an API call
<FromGitter>
<naqvis> or method call
<postmodern>
naqvis, i'm more thinking of development utils that process files in a project
<FromGitter>
<j8r> postmodern use PATH
<postmodern>
hmm actually tested it by adding cake to a project, and no cake bin got built
<postmodern>
so looks like i'd have to install the binary globally if i wanted to use it for development purposes
<FromGitter>
<j8r> you want a binary to be available in CLI but not be put in a system-wide directory like /bin?
<postmodern>
j8r, yeah, was wondering if there was a shards equivalent of `bundle exec some-dev-util`
<FromGitter>
<j8r> no, but I recommend you to have `export PATH=$HOME/.local/bin:$PATH` in your bashrc/zshrc
<FromGitter>
<j8r> This is very useful for user-binaries. `pip install --user` install there, and `npm` too IIRC
<FromGitter>
<j8r> I think it could be convenient to have a similar shortcut in `shards`
duane has quit [Ping timeout: 240 seconds]
<FromGitter>
<j8r> I confirm, `npm` does that
<postmodern>
suppose it's worth it to get more crystal dev utils on to snapcraft.io
<FromGitter>
<j8r> meh, snap is bad. No need to run this thing as root to just have a binary
<postmodern>
do people generally prefer linuxbrew here?
<FromGitter>
<j8r> anyway, you still have to edit your PATH with snap
<FromGitter>
<j8r> same with linuxbrew I guess :P
<FromGitter>
<j8r> that's just package managers that will install in a X place, and this X place need to be in your PATH
<postmodern>
do people generally download binaries off github and manually put them in their ~/bin or ~/.local/bin, or is it better to build from src?
<postmodern>
trying to feel out the preferred way to distribute binaries
<FromGitter>
<naqvis> people mostly use package managers (like apt, yum, brew etc) to download/install binaries/libraries
<FromGitter>
<naqvis> so if you plan to distribute binary, would suggest you better take those options into consideration
<FromGitter>
<j8r> you can also use asdf
<FromGitter>
<j8r> But using package managers only works if your program is packaged, of course
rocx has joined #crystal-lang
<postmodern>
can Cakefiles load dependencies in shards.yml?
<FromGitter>
<Blacksmoke16> @lodenos can you make an example in the playground?
<FromGitter>
<yorci> its okay, i can understand that its depends on iteration but its exact same process encode and decode, actually decode inverts hash also so it must be slower than encode right?
<FromGitter>
<yorci> but its vice versa
<FromGitter>
<Blacksmoke16> yea prob would have to profile it to see where the time is being spent
<FromGitter>
<asterite> `DEFAULT.invert` is called every time, creating a new hash
<FromGitter>
<asterite> Do `DEFAULT_INVERTED = Default.invert` and use that, I'm sure the times will improve by a lot
<FromGitter>
<Blacksmoke16> yea wouldnt you expect `decode` to be slower tho?
<FromGitter>
<Blacksmoke16> @yorci sure the names are switched? :P the extra mem usage by `encode` is interesting...
<FromGitter>
<j8r> @asterite the issue is encore is slower than decode, this later even calling `#invert` every time
<FromGitter>
<asterite> Yes
<FromGitter>
<asterite> The reason is that one way it goes from ascii to unicode, the other way it goes from unicode to ascii
<FromGitter>
<j8r> ho yes, there is optimization for ascii chars
<FromGitter>
<asterite> Ah, maybe not
<FromGitter>
<yorci> hmm
<FromGitter>
<asterite> This is very easy: profile it :-)
<FromGitter>
<j8r> `String#each_char` is more efficient on ascii chars
<FromGitter>
<asterite> Remember, always profile! Then you will have your answer
<FromGitter>
<asterite> `String#reverse` tries to preserve combined graphemes
<FromGitter>
<asterite> in case of unicode it will do a `scan(/\X/)`
<FromGitter>
<asterite> Profiler showed `Regex#internal_matches?` was being called a lot of times, and was the bottleneck
<FromGitter>
<asterite> No way to guess that, right? :-) ⏎ Use a profile :-)
<FromGitter>
<yorci> :D
<FromGitter>
<j8r> good job!
<FromGitter>
<yorci> alright thanks for ur time @asterite @j8r and @Blacksmoke16
<FromGitter>
<j8r> what did you used, gdb?
<FromGitter>
<asterite> Mac's Instruments (comes with XCode)
<FromGitter>
<asterite> It's really, really easy to use
<FromGitter>
<asterite> Yeah, `reverse` is a bit slow for unicode strings, but it works fine. Ideally we could find graphemes without using a regex... but it's a lot of work
<FromGitter>
<j8r> right, after removing the `reverse`, the speed is comparable
<FromGitter>
<asterite> I think it can be optimized by using more low-level code, I will try...
<FromGitter>
<j8r> Is there a guide to profile Crystal programs using tools like Valgrind or gdb?
<FromGitter>
<Blacksmoke16> adding something like that to the book would be 💯
<FromGitter>
<j8r> yeah absolutely, I am a noob in this stuff 👍
<FromGitter>
<neutrinog> a bit overkill, but I can take some pieces from it.
<FromGitter>
<naqvis> np
<FromGitter>
<neutrinog> I'm running into a different problem. I'm receiving a `Request` and trying to look at the host and port using `request.host_with_port` but the attribute is not defined. Do I need to do something special to look at the host?
<FromGitter>
<neutrinog> I'm just running a very simple grip application that's not doing anything but receiving requests at the moment.
<FromGitter>
<Blacksmoke16> are you submitting your request with a `Host` header?
<FromGitter>
<neutrinog> I'm just running the grip application and visiting `localhost:3000`
<FromGitter>
<neutrinog> so.. no?
Vexatos has quit [*.net *.split]
Vexatos has joined #crystal-lang
<FromGitter>
<j8r> makes sense then
<FromGitter>
<Blacksmoke16> via a browser or curl or something?
<FromGitter>
<j8r> the `Host` header is used when using domain names
<FromGitter>
<j8r> but you can add this header manually
<FromGitter>
<Blacksmoke16> you were missing `def self.`
<FromGitter>
<lodenos> @Blacksmoke16 Ok great, I'm completly crasy, of course it's logic, I don't know why I haven't forget that. Thx @Blacksmoke16 @j8r for your help
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<Blacksmoke16> you making a web framework too? :P
duane has joined #crystal-lang
<FromGitter>
<lodenos> yes, I do that, since I understand how work the Meta-Prog, I rewriting everything, it's so powerful, I don't know how I can programming before know that, Crystal was become my Best Partner Haha^^. I have a team of 5 persons everybody though in crystal now
<FromGitter>
<Blacksmoke16> not just easier to use one of the multitudes of frameworks that currently exist?
<FromGitter>
<Blacksmoke16> i.e. what will this new one have over the others?
<FromGitter>
<lodenos> Ho, it's not really a framework
<FromGitter>
<lodenos> it's the API I build for a compagny
<FromGitter>
<lodenos> Actually I prefer bind the libc in crystal when it's not fully binded
<FromGitter>
<Blacksmoke16> ah gotcha, but not utilizing an existing framework, essentially just building your own internal one?
<FromGitter>
<j8r> do you plan to have swagger docs?
<FromGitter>
<lodenos> @j8r I think
<FromGitter>
<lodenos> It's not a public API, but I like the docs
<FromGitter>
<Blacksmoke16> yea i would have thought it would have been easier/better/cheaper to use an existing framework versus building your own
<FromGitter>
<Blacksmoke16> plenty of options depending on what your wants and requirements
<FromGitter>
<j8r> right, agree
<FromGitter>
<j8r> maybe at the first glance the project may not require a framework, but when becoming bigger and bigger, if you are starting to build your own one - you should consider switching to a framework
<FromGitter>
<j8r> my 2c
alexherbo2 has quit [Ping timeout: 265 seconds]
<FromGitter>
<j8r> I don't even count how many hours @Blacksmoke16 could have spent on Athena O.O
<FromGitter>
<Blacksmoke16> a lot :P
<FromGitter>
<Blacksmoke16> most of it just thinking on the design/implementations
<FromGitter>
<Blacksmoke16> and how everything fits together
<FromGitter>
<RespiteSage> @asterite Re named tuples, you said, "You’ll be happier, stronger, and have better relationship with the people that surround you if you stop using them." Do you mean physically stronger? :P
<FromGitter>
<Blacksmoke16> i use it for some personal projects, is pretty legit
<raz>
gripen is the new kemal
<FromGitter>
<j8r> raz: lol, kind of :) In what sense?
<raz>
it does the same thing, just better ¯\_(ツ)_/¯
<raz>
well, it's not finished yet, but why would anyone pick kemal when it's done?
<FromGitter>
<neutrinog> > https://docs.traefik.io/ ? ⏎ oh neat. I need to point to a service based on the logged in user though. Each will have their own service. Can it do that?
<FromGitter>
<Blacksmoke16> mm like parse a jwt cookie to get uesr_id or something?
<FromGitter>
<Blacksmoke16> but im thinking no, as thats more business logicly
<FromGitter>
<Blacksmoke16> its mainly for the actual routing, like `api.mydomain.com` goes to a and `app.mydomain.com` goes to be etc
<raz>
fwiw, if you consider one of those proxies, would rather suggest to look into caddy
<raz>
(more solid in every way)
<FromGitter>
<j8r> yeah, caddy, traefik, nginx etc are nice. But if handling sessions with more little logic is needed, they can't do the work
<raz>
there's also istio, envoy, kong. and of course the venerable nginx and haproxy (if you want it to _actually_ be solid ;))
<FromGitter>
<j8r> unless using Lua plugins (HAProxy, NGinx)
<raz>
yup, kong is also lua
<FromGitter>
<j8r> may be more enjoyable to do it in Crystal at the end :P
<raz>
yup, but also much slower
<FromGitter>
<neutrinog> this was my plan `nginx-(reverse proxy)->grip-(proxy to service)->service`
<raz>
(which may not matter, depending on the use case)
<raz>
why not do it directly in nginx if you already it in the path?
<FromGitter>
<Blacksmoke16> how does it know what service to route to? based on data from the db for the current user?
<FromGitter>
<neutrinog> yeah I'll be storing a port for each user in the db.
<raz>
tbh the whole construct sounds a little questionable to me :D
<FromGitter>
<neutrinog> lol. perhaps :) I'm open to suggestions. Basically I have a crazy php app that I don't want to touch so it's running in a docker container and each user will get their own container.
<FromGitter>
<neutrinog> it's not ideal but again... I don't want to touch the code.
<raz>
(like, get ports re-used? will my auth cookie let me into someone elses app?)
<FromGitter>
<neutrinog> I'm thinking a user will be assigned a port when they register.
<FromGitter>
<Blacksmoke16> yea, whats the reasoning for each user getting their own port?
<raz>
well, as long it's not some kind of super critical service, scrappy solutions can work anyway
<FromGitter>
<neutrinog> because the application isn't built to handle multiple users. So it's sandboxed with it's own db and crummy apache server.
<FromGitter>
<Blacksmoke16> gotcha
<raz>
why do they all have to (presumably) live under the same domain tho?
<FromGitter>
<neutrinog> because I don't want to setup a domain for each user?
<FromGitter>
<neutrinog> @raz could you elaborate?
<FromGitter>
<neutrinog> btw this is the actual code I'm running in the containers. http://lwt.sourceforge.net/
<raz>
hum, well i guess you could, in theory: username.mydomain.com -> vhost -> per-user-instances
<FromGitter>
<neutrinog> don't you have to restart nginx if you add a new vhost?
<raz>
depends, you can also do it with lua. but yea, that part would then be easier with something like caddy i suppose
<raz>
(nginx + lua is infinitely powerful, but also a bit cumbersome to get working)
<FromGitter>
<neutrinog> I'll keep it in mind if I run into trouble, but this seems to be working.
<raz>
yup, was just an idea, don't make it more complicated than needed :)
<FromGitter>
<alexherbo2> How to write a game in Crystal?
<FromGitter>
<asterite> I left the contents empty in case we want to define them later. That means we can't put anything there because it will limit our decisions later on
<FromGitter>
<alexherbo2> Works like a charm, thanks!
<FromGitter>
<mattrberry> Is there a good way in crystal to read lines of stdout from an external program *while* it's running?
<FromGitter>
<Blacksmoke16> `STDOUT.each_line do |line|
<FromGitter>
<Blacksmoke16> ?
<oprypin>
wat
<oprypin>
@mattrberry: Process.run with a block
<oprypin>
inside the block you get the process and it has stdout
<FromGitter>
<mattrberry> Got it, thanks
<FromGitter>
<mattrberry> Well, sort of got it.. I'm trying to do something like this ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Where I'm currently printing the byte, I plan on parsing and evaluating the output. However, not all of the bytes seem to be printed right now. Any clue why that might be? [https://gitter.im/crystal-lang/crystal?at=5f10adcd9aa33c55842fc8da]
<oprypin>
mattrberry, not really.. can u get an isolated example not relying on a custom binary
<oprypin>
mattrberry, how bout this for a binary. `ruby -e 'srand 7; 30.times { puts rand; sleep 0.1 }'` i.e. `"ruby", ["-e", "srand 7; 30.times { puts rand; sleep 0.1 }"]`
duane has quit [Ping timeout: 272 seconds]
sorcus has quit [Quit: WeeChat 2.8]
<FromGitter>
<mattrberry> Hmm, turns out the first 3 of the test roms that Dir.glob finds don't have output for some reason lmao. All of the rest of them do. That makes more sense. The above code is working as expected now I guess haha
<FromGitter>
<mattrberry> Thanks for the help
sorcus has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
yxhuvud has joined #crystal-lang
rocx has joined #crystal-lang
duane has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
<FromGitter>
<mattrberry> An issue I'm having now is that reading the output doesn't actually happen until the process is closed. How do I make that happen while the process is executing?
<FromGitter>
<mattrberry> But I can't seem to reproduce it in a super minimal example. Confused lol.
<FromGitter>
<Blacksmoke16> What happens if you manually flush stdout
<FromGitter>
<Blacksmoke16> STDOUT.sync = true, maybe also try that
<FromGitter>
<Blacksmoke16> What about sync directly on stdout?
<FromGitter>
<mattrberry> Same story
<FromGitter>
<Blacksmoke16> Hm
f1refly has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
<oprypin>
@Blacksmoke16: that's not a thing
<FromGitter>
<mattrberry> Hm indeed
<FromGitter>
<Blacksmoke16> whats not a thing?
<oprypin>
@mattrberry: well you just gotta make the writer process not buffer *its* output
<oprypin>
nothing at all that the reader can do
<FromGitter>
<mattrberry> So presumably if I did a STDOUT.flush after each print on the writer process, that'd do it?
<FromGitter>
<mattrberry> That doesn't seem to work
<oprypin>
@mattrberry: you can get more out of your chat support sessions if you drop that kind of lexicon entirely - ""doesn't work""
<oprypin>
always needs to be: what's your approach, your expectation, and the reality
<oprypin>
in this case I'd like to see the code, because i suppose we can infer the approach is what was suggested
<FromGitter>
<mattrberry> Apologies if that came across differently than I intended it. I just said that STDOUT.flush after each print on the writer process doesn't seem to work, meaning that specific approach doesn't seem to work for me right now. Not meant as a "ho hum this doesn't work and it's not my fault" haha
<FromGitter>
<mattrberry> This is currently on the gameboy emulator I'm working on. When the rom writes to a specific memory address, I'd just like the emulator to print the byte written to that address. As of right now, that's just a ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f10cbed54d58c013a492808]
<FromGitter>
<mattrberry> At the moment, I'm trying to write a program to wrap around the emulator, running it from the shell and reading the output to the terminal in real time
<oprypin>
mattrberry, oh sorry yeah im not offended, just advice, or i guess my wishes in order to be helpful more easily
<FromGitter>
<oprypin> @mattrberry one easy thing to try would be `puts value` instead. althoguh maybe it doesnt have an effect when intercepting stdout. not sure
<oprypin>
oops
<oprypin>
and yes it is indeed strange that it doesn't work to flush
<FromGitter>
<mattrberry> I could give `puts` a shot instead of `print`, but in the end it'd be better if I could stick with `print`
<FromGitter>
<mattrberry> But I'll try out puts
<oprypin>
*however* i can make quite a big bet that if i wrote a simple program that just prints and flushes and another program that reads from it, it'd work just fine with my suggestion
<oprypin>
so probably need to exclude other parts of your setup from the equation
<FromGitter>
<mattrberry> Ahh actually no you were right before. I must have had something weird going on. If I `print` then immediately `STDOUT.flush`, it seems to work as intended. Not sure what I was doing differently before...
<FromGitter>
<mattrberry> Thanks for the help!
postmodern has joined #crystal-lang
<FromGitter>
<christopherzimmerman> Self promotion warning: I just finished up what I would call the first stable release of Num.cr, and I'd ⏎ encourage anyone who is doing any number-crunching in Crystal to check it out. If you've used it in the ⏎ past, the biggest difference is much better GPU integration, with OpenCL Tensors now being first class citizens, ⏎ including cached compilation and lots of other good stuff.
<FromGitter>
<mattrberry> In the spirit of self promotion, if anyone is feeling nostalgic for old Game Boy and Game Boy Color games, I've recently added support for many Game Boy Color titles on my emulator. It'd be awesome if people could play some games and let me know if they encounter any issues. I know of a few, but the more info the better!
duane has quit [Ping timeout: 264 seconds]
Human_G33k has joined #crystal-lang
<FromGitter>
<mattrberry> Is there a way to get the exit code of a Process if using the Process.run block syntax?