<FromGitter>
<aisrael> @valamorgon I don’t think Crystal supports true run-time dynamic evaluation. It doesn’t even have reflection AFAIK. ⏎ ⏎ Most you can maybe do is a hash of `String` to block/prod to call.
<FromGitter>
<aisrael> (I hate the Gitter app)
sz0 has quit [Quit: Connection closed for inactivity]
wontruefree has quit [Ping timeout: 264 seconds]
DTZUZO has quit [Ping timeout: 268 seconds]
<FromGitter>
<sam0x17> is there a rubocop/eslint-style linter for crystal?
<FromGitter>
<sam0x17> (i'm expecting a no)
<FromGitter>
<sam0x17> @valamorgon the closest you can get to that is using `method_missing` at compile time
<FromGitter>
<aisrael> I just go `crystal tool format`. But that’s just styling. Not semantic as far as I can tell
<FromGitter>
<sam0x17> if you need to do dynamic class/method referencing at runtime you could always manage your own data structure e.g. a hash of String to classes/procs/etc like aisrael said
<FromGitter>
<sam0x17> @aisrael gotcha
<FromGitter>
<bew> @aisrael what do you mean "not semantic"? what do you want?
<FromGitter>
<aisrael> Am specifically looking at more advanced PMD/Findbugs (Java) or flog/flay in Ruby. Stuff like complexity metrics, Demeter violations, etc.
<FromGitter>
<aisrael> So, by “semantic” I meant beyond just analyzing the styling or syntax, but actual code semantics for potential code smells or violations.
zachk has quit [Quit: Leaving]
<FromGitter>
<aisrael> I realize the compiler already performs a bunch of checks (like `nil` checking). Not sure if the compiler flags unused variables (unnecessary object creation). Pretty sure it doesn’t flag unused `require`s (like Go)
<FromGitter>
<bew> it's not as complete as you describe, but it does some things
<crystal-gh>
[crystal] asterite opened pull request #6320: Fix: disallow cast from module class to virtual metaclass (master...bug/6113-cast-from-module-class-to-virtual-metaclass) https://git.io/fSGnx
<FromGitter>
<aisrael> Thanks, will do!
<FromGitter>
<aisrael> Hey, `ameba` fits the bill! Will try to see if I can contribute any additional checks.
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter>
<bararchy> @aisrael ameba is great, we use it also in the SDLC process. Also, checkout Scry
<FromGitter>
<bararchy> wow I just can't seem to be able to use the JSON::Sereliazble module, invalid mem access all over the place lol
<FromGitter>
<tbrand> Hi forks! Let me ask a question. Is there any way to hook object finalization? I would like to call a method just before the finalization.
<FromGitter>
<tbrand> I mean just before the GC destroys the object.
<FromGitter>
<bararchy> `def finalize`
<FromGitter>
<tbrand> I tries this
<FromGitter>
<tbrand> Oh just inherit it? cool. will try. thanks.
<FromGitter>
<bew> Huh? @tbrand just add a `finalize` method in your class, and do what you have to do there
<FromGitter>
<reiswindy> Don't forget to `require "http"`
rohitpaulk has joined #crystal-lang
<FromGitter>
<Grabli66> Great :)
<FromGitter>
<mtn> New to crystal and trying things out. I'm reading in a character from stdin with: `ch = STDIN.raw &.read_char`
<FromGitter>
<mtn> How can I interpret it as an integer?
<FromGitter>
<Grabli66> to_i
<FromGitter>
<mtn> I end up with an error because of the possibility of `nil` though. Is there some sort of pattern matching of `if-else` I should be doing?
<FromGitter>
<bararchy> it's a really cool project :)
<FromGitter>
<rishavs> Has anyone used crystal with xunit/mstest/vstest? I am trying to use the ci/cd on vsts for my crystal project
<FromGitter>
<j8r> How can I wait for an event from the keyboard an return it? Basically a `gets` without to have to press enter
<FromGitter>
<bendietze_twitter> @j8r i think this should depend on the context in which you want to get this, because the OS manages this. It's a difference, if you are in bash, in a browser textfield and so on, so, i think generally it's a more specific question to the environment - the place where the keyboard would be listened / actually bounded to by OS - correct me if i am wrong :)
tilpner has joined #crystal-lang
<crystal-gh>
[crystal] RX14 closed pull request #6317: Flatten project structure created by crystal init (master...jm/feature/crystal-init-remove-version.cr) https://git.io/fSs7A
<RX14>
i'm glad everyone agreed on that PR
<FromGitter>
<j8r> This is in terminal. `STDIN.gets` works, but I'm searching a way to only get one char and return it, and loop again
<FromGitter>
<bendietze_twitter> Its simply a question of how would you build an editor - a terminal is simply a kind of an editor/window over a scripting language like a bash or whatever - what API would you implement for comfort and low-level if you write such an keyboard-lasty environment? So, you can have raw, key, line,.. and choose between the possible (comfort) functions of this interface - so you would end up with the enter
<FromGitter>
... key as the last thing that could be done ;) Everything before is the way the terminal pipes it to fd 0, 1 and 2 and Crystal is reading from (or writing to)
<crystal-gh>
[crystal] asterite opened pull request #6322: JSON/YAML: error if a maximum nesting is reached (prevents stack overflow) (master...feature/json-yaml-max-nesting) https://git.io/fHVe3
<FromGitter>
<bendietze_twitter> @rishavs sorry, can't follow the context, but be aware of saving raw passwords in your DB :) maybe, it's just for showing your error, so don't understand me wrong to implement this before it goes public in an blog or website ;)
snsei has quit [Ping timeout: 245 seconds]
snsei has joined #crystal-lang
<FromGitter>
<bendietze_twitter> If it's just for your tutorial IMO it might be ok if you simply use a fake method like xyz.encrypt_pw() and let the readers implement their own or you tutorial it later :)
<FromGitter>
<j8r> How can I create an UTF-8 Char from a Slice?
<FromGitter>
<bendietze_twitter> Not #to_a? Or #to_s?
<FromGitter>
<rishavs> @bendietze_twitter Yep its for my tutorial and I am indeed using bcrypt for the hashing. :D ⏎ I really want to use working functions as I myself am building the app as I am writing the tutorial
<z64>
@rishavs typically i have my own `class App::Database` that has `@db : DB::Database`, with instance methods that abstract the queries my application makes
duane has quit [Ping timeout: 264 seconds]
<FromGitter>
<bendietze_twitter> @rishavs yes, i can remember you are very fast in doing this and would avoid you forget it and publish without :) 👍
<FromGitter>
<rishavs> @z64 can you share some example code.
<FromGitter>
<bendietze_twitter> Cool - i must check this, heredoc is such a powerful thing, crazy 😄 👍 thx
wontruefree has joined #crystal-lang
<wontruefree>
has anyone here tried deploying crystal with a unikernel?
<FromGitter>
<giuseongit> hi, is possible to call crystal function(s) from c code?
sz0 has joined #crystal-lang
<wontruefree>
after looking through the doc i dont see a way but I have not built a c binding in crystal yet
<wontruefree>
crystal does generate object files so I dont know if you can link into those
wontruefree has quit [Quit: bye]
<FromGitter>
<giuseongit> I'd like to write a kernel module in crystal, but the only way to do it is write a thin wrapper in c that acts as an entry point for my crystal code
akaiiro has quit [Ping timeout: 248 seconds]
<FromGitter>
<bendietze_twitter> BTW as a newbie i am scrolling every day a hundred times through the API looking for a method - search isn't helpful because i often have no more idea of naming something in english/Crystal-way and sometimes it feels my brain is formatted, so, the method overview is a good thing, but its so many scrolling too, IMO for newbies and many others it could be helpful to reduce it to a table overview -
<FromGitter>
... mostly a one-screener - of simply all #methods(params), for me this were nice if we implement this some days 😄 If there were some thoughts about i would give my 👍
<FromGitter>
<j8r> @bendietze_twitter you can also use devdocs.io
<FromGitter>
<fridgerator> I was going to mention that, it looks like it hasn't been updated to version 0.25 yet
wontruefree has joined #crystal-lang
<FromGitter>
<bendietze_twitter> @j8r yes, thanks, i have used some times, might be worth to test it again :)
<FromGitter>
<bendietze_twitter> @giuseongit i would be interested to know if a kernel module should be written in Crystal because nearly everything is written in C, so there would be wrappers around nearly everything? :) Makes it sense? @others?
<FromGitter>
<giuseongit> @bendietze_twitter I found this (https://github.com/souvik1997/kernel-roulette) on github , but it's written in rust, i was just wondering if something similar could be done in crystal
<FromGitter>
<bendietze_twitter> @giuseongit play Russian Roulette with the Linux kernel 😆 now you now why they choose Rust 😄
<FromGitter>
<bendietze_twitter> Just a joke :) i will have a look, thx 👍
wontruefree has quit [Quit: bye]
<FromGitter>
<bendietze_twitter> I think, the difference between Rust and Crystal is, that Rust is going every day to become the new (really dirty) low-level lang and Crystal is more the way to write quickly (but beautiful) native code, fast and clean - there would every day be new things in Rust which are not our way - but its just my opinion and a kernel module may already be possible :) Stay here while WIP :)
<FromGitter>
<giuseongit> @bendietze_twitter but I still need some c code or it is possible to fully write it in crystal?
<FromGitter>
<bendietze_twitter> All ..nixes are written mostly in C, so, bisides assembler this is their native language and i think you need many c-bindings and wrappers but i am not deep enough with capabilities of llvm - there are many people here in the chat which can help you lot more than i can :)
<FromGitter>
<j8r> The only C files are on the `/tests` folder
<FromGitter>
<giuseongit> @j8r but it's a kernel, not a kernel module. I've also found a kernel (https://github.com/TheKernelCorp/Fluorite) written (almost) entirely in crystal
wontruefree has joined #crystal-lang
akaiiro has joined #crystal-lang
<FromGitter>
<Willamin> I know about `crystal tool expand`, but is there any interest in a feature that does the macro pass over an entire project, outputting crystal code with all macros expanded?
greengriminal has joined #crystal-lang
<FromGitter>
<rishavs> What does db.exec returns in case of any error? nil or an exception?
<FromGitter>
<rishavs> Actually I got it. This weird chimera version works; `unq_count = (Cove::DB.scalar "select count(*) from #{dbtable} where username = $1", itemval).as(Int)`
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
akaiiro has quit [Ping timeout: 256 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
akaiiro has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter>
<shreeve> I'd like to pipe ansi-colorized output to a process that: 1) strips the colors and logs content to a file; and 2) passes the original stream from stdin to stdout
<FromGitter>
<shreeve> Thinking of just using a pipe, but wondering how I handle output that is buffered so that escape sequences might be split across buffer reads
wontruefree has quit [Quit: bye]
<FromGitter>
<shreeve> something like the 'tee' command line, but instead of writing the entire stream to a file, it would only write the de-colorized stream to the file and pass the colorized stream along
<FromGitter>
<bew> it'd be better done by 2 program: one to remove ansi escape code and one to write to file, you already have the 2nd one (`tee`), you ust have to find the 1st one (or make it yourself)
<FromGitter>
<shreeve> problem is that if I have program 1 strip the colors, then by the time the data gets to program 2, there are no colors
<FromGitter>
<shreeve> so, i sort of need 1 program to do both things... strip the colors for what it's going to log, but pass the original colors along to stdout
<FromGitter>
<bew> yes that's the idea, no?
<FromGitter>
<bew> ah
<FromGitter>
<shreeve> i wanted the colors to show on stdout (so they look 'purdy), but have just the content written to the file (so I can review it and read it in an editor)
<FromGitter>
<bew> instead of doing the 2 in one operation, I think it's simpler to separate the task in the program: print to a file, and print to stdout. the subtle difference is that it doesn't only do stdout from your program, but do both operation separately in the program. It means that instead of removing ansi sequences, you can simply not send them to the file, and send them to stdout
<oprypin>
bew, it's really not simpler
<oprypin>
shreeve, `some_command | tee >(sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' >some_file)` anyway
<FromGitter>
<shreeve> thank you both, i'll experiment with the above
<FromGitter>
<shreeve> :-)
<FromGitter>
<shreeve> worked great!
<FromGitter>
<shreeve> `bam | tee >(sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' >bam.log)`
<FromGitter>
<shreeve> (program was 'bam' and 'bam.log' was the logfile)
wontruefree has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> Does Shards support Git Remote Helpers?
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter>
<Daniel-Worrall> I don't think it does, but I would like a confirmation
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
Groogy has quit [Ping timeout: 256 seconds]
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> Oh. Maybe it does now
<FromGitter>
<Daniel-Worrall> It didn't work in 0.25.0, but does in 0.25.1
<FromGitter>
<Daniel-Worrall> Not sure which Crystal version I was on
<FromGitter>
<Daniel-Worrall> *Shards
<FromGitter>
<valamorgon> is there any simple way to make reverse for loop?
<FromGitter>
<shreeve> @bew @oprypin - fwiw, one more small (but important!) tweak to that pipeline was to make `sed` use output line buffering (otherwise, you can't see the output until the buffer fills up)... here's the final line:
<FromGitter>
<shreeve> `bam | tee >(sed -l $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' >bam.log)`
<FromGitter>
<shreeve> that little "-l" param to `sed` is key... with this, now I can just look at `bam.log` in sublime happily (without all the ANSI characters), but still see all the 'purdy colors on my console... thanks again for both of your help!!!
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
zachk has joined #crystal-lang
zachk has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
<crystal-gh>
[crystal] straight-shoota opened pull request #6323: Refactor and improve URI implementation (master...jm/fix/uri-refactor) https://git.io/f5bF1
<wontruefree>
I have a reasonably fresh install of macosx and crystal is failing to build
<wontruefree>
the xcode-select part might be out of date
<wontruefree>
but yes
<FromGitter>
<straight-shoota> so what's the error?
<wontruefree>
`ld: symbol(s) not found for architecture x86_64`
<Yxhuvud>
straight-shoota: omg @ that PR. seems you reacted to me pasting the RFC by actually reading it (and some followers?) :)
<FromGitter>
<straight-shoota> yeah, I was already working on it before that^^
knight- has joined #crystal-lang
<knight->
hey hey
<FromGitter>
<jwoertink> Is the `crystal tool expand` command is for showing all of the macros in the file expanded?
<Yxhuvud>
uri:s are such a mess of a format.
moei has quit [Quit: Leaving...]
<FromGitter>
<jwoertink> In any case, how do you run it? I've tried `crystal tool expand test.cr`, `crystal tool expand ./test.cr`, `crystal tool expand --stdin-filename=test.cr`, and I just keep getting the help menu
* Yxhuvud
wrote some of the wrappers of tool expand in the crystal elisp mode so that people wouldn't have to fight with that
<Yxhuvud>
not that it works very well as the editor must know what file it is that requires everything, but anyhow.
<Yxhuvud>
and by "know" I mean "guess".
<FromGitter>
<jwoertink> hmm. ok, so `crystal tool expand -c test.cr:1:1 test.cr` runs (sort of). Just says "no expansion found". If my macro is on line 1 column 1, then this should do something, right?
<FromGitter>
<jwoertink> or maybe I'm just not writing enough for it to do something
<FromGitter>
<jwoertink> ah, ok, that's what it was. It's the line of where the macro is called, and not the macro itself
duane has joined #crystal-lang
<FromGitter>
<j8r> Are Enum only about Int32 or can i change this to UInt8?
<FromGitter>
<jwoertink> Haven't tried, but could you do `Red = 1_u8` inside the enum?
<FromGitter>
<j8r> Nicely tried but doesn't work - It said it must be int32
<FromGitter>
<jwoertink> ah damn. Maybe it's a bug?
pbodev1 has quit [Quit: ChatZilla 0.9.93 [Firefox 56.0/20170903140023]]
moei has joined #crystal-lang
<FromGitter>
<talbergs> Hello community
<FromGitter>
<talbergs> Im coming from php world, so im new to crystal
<FromGitter>
<bendietze_twitter> Why should it be a bug? Is there a usecase for smaller Ints? I did not know if the internal representation is tweakable in other languages.. Enum internal knows only Int32 as far as i can see first look :)
<FromGitter>
<talbergs> Could anyone please give a hand?
<FromGitter>
<bendietze_twitter> Hey @talbergs sorry, my time is over, its middle of the night here - good start 😄 hope to see you next days 👍
<FromGitter>
<bendietze_twitter> Means good start for you with Crystal
<FromGitter>
<talbergs> So, I managed this shell thingy. ^^
<FromGitter>
<jwoertink> I've never worked with websockets before, so I'm definitely not the right person to solve this one. I'm curious about the implementation though.
<FromGitter>
<jwoertink> So you have a kemal app running, and a ws endpoint. Then you want a shell script to print to the ws channel each time?
<FromGitter>
<talbergs> Basically yes. The GET to route will start a shell script and put update user on the output. ⏎ ⏎ Currently I need to dig out from api page, how to hook into a process again. Because if user calls GET again, and process is still running - I want to hook into it and continue updating user. ⏎ ⏎ In short my story is like so - I was smart enough to copy HTTP example from docs, and look up websocket API,
<FromGitter>
<jwoertink> Looks like your script you have now does most of what you want. I'm assuming you'd replace the `puts o` with `socket.send o`. Then I guess it's just a matter of doing `break if rec.eof?`. There's no `eof?` method on IO::FileDescriptor, but you'd probably need something that tells when to break out of that while loop
<FromGitter>
<talbergs> yes, exactly. I expected the `rec.gets` to give `nil` then, but my script now just hangs, I look at `.terminated?` inside that while loop, and it stays false =/. Yes there is no `eof?` method there. Just tested
<crystal-gh>
crystal/master 735be7f Paul Kassianik: Implemented #2770 (#6306)...
<FromGitter>
<drosehn> Hmm. I haven't tried Process.run in quite awhile, but I ran into a similar problem with something I was writing. (I don't remember what...). I ended up solving it by putting a `rescue` around the work I was doing inside the Process.run. In your case, that'd be a `begin ... rescue ... end` around the `while true ... end` loop.
<FromGitter>
<talbergs> Rescue was for exception catching, thou still I'll try out your suggestion and report. I just realized I skipped the "concurrency" section when reading thru them docs this morning. I guess the fibers stuff may help me `spawn do rec.gets end ; process.wait`
<FromGitter>
<drosehn> I didn't work on that program for long though. And while I was working on it, I always had the feeling that there must have been a better way to do what I was trying to do.