ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.23.1 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
<vivus> @marksiemers you are amazing man! I figured it out and it works! (almost). it still displays the action buttons, but now I can see all the content XD
<FromGitter> <marksiemers> The individual parts of the page you'll have to take care of in the views
<FromGitter> <marksiemers> but you should be able to check against `current_user` in any of them (I think)
<vivus> @marksiemers so I added the "/" route to the else and it shows the front page, but I think I need to add a `get /posts/` route to to display posts
<vivus> (or the content rather)
<FromGitter> <marksiemers> Do you have content? It wouldn't have been seeded, unless you added to the seeds file
<vivus> yeah I do. I created 3 test posts
<vivus> I need "read" to work, and edit/delete can remain as is
<FromGitter> <marksiemers> add `"/posts"` to the else statement in the pipe
<FromGitter> <marksiemers> And in the edit/update/delete actions in the controller, put in a before_action, or some code at the top of each action
<FromGitter> <marksiemers> That redirects if the post doesn't belong to the user
eliasjpr has joined #crystal-lang
<vivus> @marksiemers I added that route to the , however, it just shows the /posts URL. for any URLs like: posts/1 or posts/2 , those are still restricted
<FromGitter> <marksiemers> Try a wildcard maybe `"/posts/*"`
<vivus> tried that :P no luck
<FromGitter> <marksiemers> I can mess with it, but won't have any more time today
<FromGitter> <marksiemers> If you're comfortable with regex, you could use that as a conditonal
<vivus> @marksiemers, no worries. this is mostly a learning experience. the end-result is a rudimentary reddit for others to use
eliasjpr has quit [Ping timeout: 240 seconds]
<FromGitter> <marksiemers>
<FromGitter> <marksiemers> It isn't a final solution, but you can use a regex check for now in the pipe
Renich_ has joined #crystal-lang
<vivus> @marksiemers does it also leak the following: ?
<vivus> yes it does XD
<vivus> how do I put this regex into: if ["/signin","/session","/signup","/registration", ... ] ?
Renich_ has quit [Client Quit]
Renich_ has joined #crystal-lang
eliasjpr has joined #crystal-lang
Renich_ has quit [Client Quit]
Renich_ has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
Renich has quit [Disconnected by services]
Renich has joined #crystal-lang
<FromGitter> <marksiemers> It won't go in there. do a separate line with an if statement
_whitelogger has joined #crystal-lang
Renich_ has quit [Quit: leaving]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eliasjpr has joined #crystal-lang
<vivus> @marksiemers I have been trying to do so, but it isn't quite clear how 2 if statements can exist under this 1 return
eliasjpr has quit [Ping timeout: 260 seconds]
qard has joined #crystal-lang
vivus has quit [Quit: Leaving]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
mbarbar has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
mbarbar has quit [Ping timeout: 260 seconds]
eliasjpr has joined #crystal-lang
alex`` has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
faustinoaq has quit [Quit: Konversation terminated!]
snsei has joined #crystal-lang
eliasjpr has joined #crystal-lang
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
eliasjpr has quit [Ping timeout: 248 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
_whitelogger has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
alex`` has quit [Ping timeout: 252 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 260 seconds]
shankar has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
shankar has quit [Quit: Leaving]
shankar has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 260 seconds]
claudiuinberlin has joined #crystal-lang
shankar_ has joined #crystal-lang
shankar_ has quit [Client Quit]
shankar_ has joined #crystal-lang
shankar has quit [Ping timeout: 260 seconds]
eliasjpr has joined #crystal-lang
shankar_ has quit [Remote host closed the connection]
eliasjpr has quit [Ping timeout: 240 seconds]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <unreadable> Morning all
<FromGitter> <unreadable> It's a bit early I know ;)
rohitpaulk has joined #crystal-lang
eliasjpr has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
eliasjpr has quit [Ping timeout: 248 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
rohitpaulk has joined #crystal-lang
<crystal-gh> [crystal] lachlan opened pull request #5242: Change Time class to extract additional constants for numbers which are used in multiple calculations (master...time_constants)
_whitelogger has joined #crystal-lang
mbarbar has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
bazaar has quit [Quit: leaving]
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
<FromGitter> <marksiemers> Either restructure it to be an if statement with an `||` or use two return statements with post conditions: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <marksiemers> That is pseudocode, but you could create private methods with those names too.
<FromGitter> <marksiemers> vivus ^^
alex`` has joined #crystal-lang
<FromGitter> <Qwerp-Derp> I need help with my project -
<FromGitter> <Qwerp-Derp> In `src/mirrors/display/`, in line 56 to 63, I'm trying to get the game board to update once every half a second
<FromGitter> <Qwerp-Derp> But that doesn't happen, and it ends up with the main window waiting for a few seconds before even running at all
<FromGitter> <Qwerp-Derp> How do I run two things simultaneously with `Fiber`s?
eliasjpr has joined #crystal-lang
<FromGitter> <Qwerp-Derp> Say I have these two functions: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Qwerp-Derp> How do I execute both of these functions simultaneously, so the output is a mishmash of `1`s and `2`s?
eliasjpr has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> You can read about fibers & concurrency in the docs:
<FromGitter> <Qwerp-Derp> Well yeah I read that, but how would I apply it to what I want to do?
<FromGitter> <Qwerp-Derp> I'm still kinda confused at the fiber documentation
snsei has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> You need to create a fiber in each method with the loop inside it, and pause the main fiber to allow the others to run.
<FromGitter> <bew> Note that it probably won't work the way you want because writing something to the use is instantaneous, and probably won't block the fiber doing it, so only one fiber will print its stuff.
<FromGitter> <bew> To allow other fibers to run after a puts, add a `Fiber.yield` after it
<FromGitter> <Qwerp-Derp> Hmmm... so Crystal doesn't support what I want to do yet?
<FromGitter> <bew> What you're describing is parallelism, which is currently not supported, but being worked on by Manas
<FromGitter> <Qwerp-Derp> Ah, cool :D
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
<handicraftsman> FromIRC
snsei has quit [Remote host closed the connection]
eliasjpr has joined #crystal-lang
<FromGitter> <watzon> Here's a question for you guys. Is it possible to get the remainder of an array when deconstructing into variables? For instance, I'd like to be able to do this: ⏎ ⏎ ```foo, ..barbaz = "foo:bar:baz".split(":")``` ⏎ ⏎ Or something similar. `foo` should be `"foo"` and `barbaz` should be `["bar", "baz"]` []
<FromGitter> <bew> Currently not
<FromGitter> <watzon> I thought not haha. Tried several ways
<FromGitter> <bew> But iirc there is an issue open about that
<FromGitter> <watzon> I was just going to ask about that
<FromGitter> <watzon> Have any idea what I could search to find that issue and subscribe to it?
eliasjpr has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> Bingo #132
<DeBot_> (Array/Tuple decomposition)
<FromGitter> <watzon> Oh wow, that's way back there
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
<FromGitter> <codem4ster> Hi all, how can I format time in a specified timezone?
<FromGitter> <codem4ster> I inspect Time::Format but cannot find a way for that
<FromGitter> <codem4ster>"%FT%X%z", ???).format(
<FromGitter> <codem4ster> I think crystal only support local and utc time
<FromGitter> <smarr> Hi, seems to be unavailable, what would be an easy workaround? are the ubuntu packages available somewhere else?
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
rohitpaulk has quit [Ping timeout: 240 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> @codem4ster iirc it's something like that:"the format string")
<FromGitter> <codem4ster> I know that @bew but I'm looking for formatting for a specific timezone, my local time is GMT+3 but I want to format it for GMT+5
<FromGitter> <codem4ster> but Time::Format::Kind only supports for local and utc
<FromGitter> <codem4ster> I need smt like this ; `"%FT%X%z", "+5").format(` with an output like this `2017-11-04T17:35:43+0500`
rohitpaulk has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
<FromGitter> <Rinkana> lolwat `no overload matches 'Array(Array(Int32))#<<' with type Array(Array(Int32))`
faustinoaq has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
Kug3lis_off is now known as Kug3lis
faustinoaq has quit [Quit: Konversation terminated!]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
sevensidedmarble has joined #crystal-lang
<sevensidedmarble> can you not have default arguments to a proc in crystal?
<sevensidedmarble> because lambda { |x = 0| print x } doesnt work for me
<Papierkorb> sevensidedmarble: Not possible
<sevensidedmarble> not possible now or not possible ever?
Groogy2 has joined #crystal-lang
<sevensidedmarble> because it'd be really cool if that could be in the language
<Papierkorb> likely not possible ever
<sevensidedmarble> what prevents it?
<Papierkorb> how default arguments work
Groogy has quit [Disconnected by services]
Groogy2 is now known as Groogy
Groogy_ has joined #crystal-lang
sz0 has joined #crystal-lang
<sevensidedmarble> also is there any way to write one line if statements at this time?
<Papierkorb> ... Yes?
<Papierkorb> Just .. write one?
<sevensidedmarble> well I saw that there was no then
<sevensidedmarble> the keyword
<Papierkorb> huh
<Papierkorb> `puts "foo" if bar` has worked since forever
<Groogy> var = 25 if something_true
<Groogy> yeah
<sevensidedmarble> I hadn't tried it lol
<sevensidedmarble> I assumed you needed a then since thats how ruby works I thought
<sevensidedmarble> maybe its optional in ruby too
<Groogy> you need then in Ruby now days?
<Groogy> I don't remember that when I sued it
<sevensidedmarble> maybe you don't
<sevensidedmarble> I don't know, its in lua and thats what I first learned so I always did it
<Groogy> Yeah I thought you were coming from Lua there :P
<sevensidedmarble> yeah it seems like one of those things everyone hates about lua lol
<Groogy> well I don't hate it, just reminded me of Lua
<sevensidedmarble> I was doing a lot of luajit recently and when I discovered this lang I was amazed
<Groogy> cool
<sevensidedmarble> I love luajit but after writing ruby its hard to go back to not even having classes
<Groogy> Yeah biggest OO difference with Lua is that Crystal is class based OO while Lua is prototype based
<Groogy> if you hadn't realized already, but it is kind of fundamental difference
<sevensidedmarble> I was curious what the state of any ORM frameworks in crystal is though, are there any that have caught on in a big way?
<sevensidedmarble> I've read the github awesome page and there were a few but I wasnt sure which ones were really popular
<FromGitter> <fridgerator> Jennifer and crecto seem to be the .o st popular
<Groogy> I have no idea whcich one is more popular, probably look at which one is most maintained?
<sevensidedmarble> do you know if they support generating migrations ala django/flask?
<sevensidedmarble> coming from django first I've always hated the rails workflow of having to write the migration by hand
<FromGitter> <fridgerator> No, they don't
<sevensidedmarble> I realize theres the rails generator but you still have to supply it what you want
<Papierkorb> What do you mean?
<Papierkorb> How is a migration thing supposed to figure out what you wanted to do?
<sevensidedmarble> in django you define your models right in python code, and then run a command called makemigrations
<FromGitter> <fridgerator> In not a fan of Django migrations
<Papierkorb> And then later on?
<sevensidedmarble> and it parses the models and the current schema and determines how to change it
<Papierkorb> How does it figure out that I wanted to rename a column?
<FromGitter> <fridgerator> Magic
<Papierkorb> Or that I wanted to change the type? Using which conversion?
<sevensidedmarble> its all declared in the model
faustinoaq has quit [Quit: Konversation terminated!]
<sevensidedmarble> the orm has a syntax for declaring all that and the makemigrations tool parses it
<Papierkorb> How do you go back?
faustinoaq has joined #crystal-lang
<Papierkorb> Do I have to mess with the model then?
<FromGitter> <fridgerator> you end up with 1000 migration files
<sevensidedmarble> that works a little differently, you can just rollback the migration but then you have to add the code back in to the model yeah
<sevensidedmarble> I get the complaints about it, but it works perfectly fine for small projects in my experience
<sevensidedmarble> maybe it doesnt scale as well as what rails does but its so easy to maintain at first
<sevensidedmarble> the idea is fundamentally different though
<FromGitter> <fridgerator> I just dont like Django, especially the orm, lol
<sevensidedmarble> your intended to have the model be the one true source of information
<sevensidedmarble> so if you're changing things, you have that file under version control
<sevensidedmarble> thats another way to roll things back
eliasjpr has joined #crystal-lang
<Papierkorb> I mean I get the point, and for *small* project it works, but that's not good enough for a general purpose ORM which has to work with more than that
<sevensidedmarble> I think flask does it too
<FromGitter> <fridgerator> flask doesn't come with an ORM, I dont think
<sevensidedmarble> they heavily reccomend sqlalchemy though
eliasjpr has quit [Ping timeout: 240 seconds]
sevensidedmarble has quit [Quit: Leaving]
rohitpaulk has joined #crystal-lang
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> @oprypin hey I'd like to use or make some dbus bindings, I saw your lib (, do you plan to improve it one day (e.g: add signal reception)?
faustinoaq has quit [Quit: Konversation terminated!]
rohitpaulk has quit [Ping timeout: 255 seconds]
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 255 seconds]
shankar has joined #crystal-lang
shankar has quit [Remote host closed the connection]
mbarbar has quit [Ping timeout: 248 seconds]
Ryan_ has joined #crystal-lang
<Ryan_> Hi all, just discovered Crystal (from Ruby). I'm having difficulty getting a JSON::Any type into an Array. I want to preassign the array size and then loop through from 0..100 and assign it at that point. Any ideas how to do this?
eliasjpr has joined #crystal-lang
<Papierkorb> Ryan_: 1) please always post the complete error message when you're getting one. You'll be getting one on this one.
<Papierkorb> Ryan_: 2) `foo = Array(JSON::Any).new(100){|i| JSON.parse(".."))}`
<Papierkorb> Ryan_: But in reality, you want to use `JSON.mapping` instead of `JSON.parse`.
<Ryan_> The key in the mapping is dynamic, is that possible? I couldn't find anything in the docs
<Ryan_> { "bob" => "20", "john" => "50" }
<Papierkorb> no, you can't map something you don't know the structure of
<FromGitter> <bew> Ryan_ are there nested maps in your jsons?
eliasjpr has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> or only Hash(String, String) ?
<Ryan_> It's Hash(String, String)
<FromGitter> <bew> You could use sth like `foo = { |i| Hash(String, String).from_json("#{i}.txt")) }` maybe?
<FromGitter> <bew> and you end up with a `Aray(Hash(String, String))`
<FromGitter> <bew> Array*
<Ryan_> Nice! That's got it working, thank you.
<Ryan_> I'm impressed with the execution speed. Going from Ruby to C and now Crystal is a nice middle ground
<Ryan_> Is it possible to sprintf onto a File write? `f.write(sprintf("%d,%d,%0.4f\n", i, j, c))`
<RX14> printf is a method on IO
<RX14> of which file is a subclass
<RX14> so just { |f| f.printf(...) }
<RX14> if you wanted to send a string to an IO you can't use write either
<RX14> you'd use print or typically just io << string
<Ryan_> It's going to be running about 40 million writes per file, so I wanted to keep the file open rather than open and close
<RX14> so feep the file object around???
<RX14> keep*
<RX14> File.write is literally opening and closing the file
<RX14> i dont understand
<Groogy> ah it's fun being back working on Boleite ^^ been hectic at work
faustinoaq has joined #crystal-lang
<Ryan_> f ="out.txt", "w"); f.write(sprintf("%d,%d,%0.4f\n", i, j, c)); f.close
<Ryan_> There's other stuff around `f.write`, just chopped it for brevity
<Groogy> you can still do f.printf there....?
<RX14> exactly
<Groogy> is shorthand for exactly what you did there manually
<RX14> lol
faustinoaq has quit [Client Quit]
<Groogy> eh the block variant that is
<Ryan_> I see, I thought took a lot longer, than keeping the file open and just pushing the string to it
<RX14> no
<RX14> File.write is literally a method written in crystal which calls
<Ryan_> Class method or instance method?
<RX14> perhaps in ruby where the literal calling of and constructiong the File object takes some time but never consider ruby performance tips in crystal
<Ryan_> Gotcha
<RX14> its this
<RX14> always remember you can just look at how the stdlib works
<Ryan_> Thanks
<RX14> performance is going to be limited by the syscall speed (slow)
<RX14> and perhaps the malloc might take some time but not much
<Ryan_> Last thing, I need to create a fixed length array that's going to be populated with Float64, I thought something like`Array(n).new { Float64 }`
<RX14> it's ns
<RX14> maybe 100
<Ryan_> Cool
<RX14> actually not sure what the kernel does on an open, might require a fair bit of bookkeeping
<RX14> Ryan_, yeah array constructor with a block is good
<RX14> if it's the same float you can just use .new(size, float)
<RX14> because it's a Value so it's copied
eliasjpr has joined #crystal-lang
<Ryan_> Nice, thanks RX14! Appreciate the tips
rohitpaulk has joined #crystal-lang
eliasjpr has quit [Ping timeout: 248 seconds]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Quit: Konversation terminated!]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
faustinoaq has joined #crystal-lang
moon_ has joined #crystal-lang
<moon_> Hello, I am fairly new to Crystal ... I am not able to figure out why I am getting the following error:
<moon_> Error in src/ undefined constant Services result[s] = Services[s]?
<moon_> Would really appriciate some help here
eliasjpr has joined #crystal-lang
<Papierkorb> constants are ALL_UPPER_CASE
<FromGitter> <unreadable> No upper case
<moon_> @Papierkorb: I renamed Services to SERVICES .. same error: Error in src/ undefined constant SERVICES
snsei has joined #crystal-lang
<Groogy> then you doing it in a scope where SERVICES is not defined
<Groogy> ie. you probably have to do WebServer::SERVICES
<moon_> @Groogy trying it
<Papierkorb> Probably has to do with you not having the initializations in the #initialize
faustinoaq has quit [Ping timeout: 240 seconds]
<Papierkorb> Which, seeing as yours come with actual logic, is the place they should be in
<Groogy> oh yeah I see now, yeah you are referencing the constant too early
<Groogy> It's something annoying I've found around constants from time to time, primarily when I am doing inheritance
<moon_> So I have to move SERVICES = {} in the initialize method? And it would be available in a Class scope?
<Groogy> no no the @get_services
<Papierkorb> No, you have to move the @ivars into the #initialize
eliasjpr has quit [Ping timeout: 248 seconds]
<Papierkorb> Which is where they belong
<Groogy> when it is trying to parse the block there it tries to resolve the constant
<Groogy> which it can't
<moon_> Okay, so instead I replaced SERVICES to @Services .. but now I am getting: Invalid memory access (signal 11) at address 0x0 when I do `crystal run`
<Papierkorb> 1) Please file a bug 2) That's not what we advised you to do.
<moon_> @Papierkorb yes, that's not you advised me to do .. but eventually `Services` will be coming form DB anyways so it does not make sense for it to be Constant
snsei has quit [Remote host closed the connection]
<moon_> That is why I made it an instance variable
<moon_> Here is the updated gist which contains both updated code and error I am getting:
<Papierkorb> Again, move those @ivar assignements into the #initialize
<moon_> OK. I moved `@Services = { }` inside `def initialize` block
<Papierkorb> All of them.
snsei has joined #crystal-lang
<Papierkorb> Or rather, those which have logic in them. In your case, those with blocks.
<moon_> Ahh .. ok moving makes it work .. makes sense .. Thank you .. but this doesn't let me keep my init function clean
snsei_ has joined #crystal-lang
<moon_> Is there any better pattern / work around for this?
faustinoaq has joined #crystal-lang
<Papierkorb> It was never clean to begin with
<Papierkorb> Split it up
Ryan_ has quit [Ping timeout: 260 seconds]
snsei has quit [Ping timeout: 258 seconds]
<moon_> Currently I have `@get_services = do |context, params|` ... would it be possible for me to pass in additional params to this function?
<moon_> from `init` method?
<Papierkorb> blocks are closures
<moon_> ok thanks
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 260 seconds]
moon_ has quit [Quit: Page closed]
snsei_ has quit [Remote host closed the connection]
<oprypin> bew, unfortunately at this point i forgot all about how dbus works, so i probably will not return to this
eliasjpr has joined #crystal-lang
hightower3 has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
hightower4 has quit [Ping timeout: 260 seconds]
eliasjpr has joined #crystal-lang
qard has joined #crystal-lang
eliasjpr has quit [Ping timeout: 260 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
qard_ has joined #crystal-lang
qard has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 248 seconds]
eliasjpr has joined #crystal-lang
RX14 has quit [Excess Flood]
RX14 has joined #crystal-lang
eliasjpr has quit [Ping timeout: 264 seconds]
<FromGitter> <bew> Ok, also the code seems quite old^^ I'll probably make my own and will look at how you did yours, thanks anyway!
vivus has joined #crystal-lang
<FromGitter> <eliasjpr> What’s the best way to deallocate, destroy a class?
<FromGitter> <eliasjpr> I swear I read about deallocate in the docs
<FromGitter> <straight-shoota> you can't destroy a class, only instances
<FromGitter> <straight-shoota> for that, you just remove all references, memory will be cleaned up by the garbage collector
eliasjpr has joined #crystal-lang
eliasjpr has quit [Ping timeout: 240 seconds]
<FromGitter> <HCLarsen> I've got a question about JSON::Any. What if I'm not sure if the JSON object has a certain key/value pair? I can't use has_key like I would with a has, but if I try to access a key when it doesn't exist, I crash the program.
<FromGitter> <bew> why can't you use has_key?
<FromGitter> <HCLarsen> Because it's a JSON::Any object. That class doesn't have has_key? as a method.
<FromGitter> <eliasjpr> @straight-shoota yes I meant to say instances of a class
<FromGitter> <bew> @HCLarsen hmm sure ><
<FromGitter> <bew> but if you know it's a Hash you can?
<FromGitter> <HCLarsen> Tried it. Compiler rejected it.
<FromGitter> <HCLarsen> ```code paste, see link``` []
<FromGitter> <HCLarsen> Do I apply #as_h between the value and the #has_key?
<FromGitter> <bew> there should be `value["rain"]?`
<FromGitter> <unreadable> Wouldn't be better to replace the `syscalls` in crystal with assembly instead of using libc
<FromGitter> <unreadable> On linux, assembly doesn't look that bad
<Groogy> the JSON::Any is a type union
<FromGitter> <HCLarsen> No, there may, or may not be value["rain"]. Sometimes it will be there, sometimes it won't, that's why I need to check if it's there.
<Groogy> he has to narrow it down to types that only respond to has_key?
<Groogy> and bew was referring to #[]? which will return nil if it didn't find it
<Groogy> oh wait no it isn't a union
<Groogy> huh it is in YAML
<FromGitter> <HCLarsen> @FromIRC #[] returns a runtime error if it doesn't find that key.
<FromGitter> <HCLarsen> Groogy, #[] returns a runtime error if "rain" isn't present.
<Groogy> yes but not []?
<Groogy> #[]? is a method
<FromGitter> <HCLarsen> Yes it is.
<Groogy> it returns nil if it isn't present
<FromGitter> <HCLarsen> Nope. it returns this error: ⏎ ⏎ `````` []
<FromGitter> <HCLarsen> Missing hash key: "rain" (KeyError)
<FromGitter> <HCLarsen> Dude, you declared that as a hash. I'm working with a JSON::Any object.
<FromGitter> <HCLarsen> Got it though.
<FromGitter> <HCLarsen> ```value.as_h.has_key? "rain"```
<Groogy> ... no don't do that
<Groogy> also the JSON::Any works like a hash
<vivus> does anybody know how to put a regex in `return call_next` here:
<Groogy> the same applies to it
<Groogy> it just took longer to write so I was lazy and did it as a hash
<FromGitter> <HCLarsen> Groogy, JSON::Any doesn't work as a hash. The error message I showed you earlier proves that quite sufficiently.
<Groogy> Look at what I pasted
<Groogy> it works exactly like a hash
<FromGitter> <HCLarsen> Groogy, look at what I already pasted.
<Groogy> I mean if you wanna do unnessecary casting go ahead
<FromGitter> <HCLarsen> I got the "missing hash key" error.
<Groogy> then you did it wrong
<FromGitter> <HCLarsen> ```code paste, see link``` []
<FromGitter> <HCLarsen> There's my code. Show me what I did wrong.
<Groogy> you are missing the ?
<Groogy> #[]? is not the same method as #[]
<FromGitter> <HCLarsen> Where?
<Groogy> in the if
<FromGitter> <HCLarsen> Specifying that earlier would have helped.
<FromGitter> <bew> @HCLarsen the ? is part of the method: `value["rain"]?`
<Groogy> I did
<Groogy> several times
<FromGitter> <picatz> Miscommunication, it happens. :)
<Groogy> also I would rewrite it as this:
<Groogy> so you don't have to fetch the value twice
<vivus> does anybody know how to put a regex in `return call_next` here:
<Groogy> the if statement will disqualifiy the Nil type anyway on the value variable
<FromGitter> <HCLarsen> I don't want it as a string through, I want it as an integer.
<FromGitter> <HCLarsen> though.
<Groogy> yeah you can call to_i on it if you want
<Groogy> I was pointing more on how you fetch it
<FromGitter> <HCLarsen> I'd like to use the ternary operator, but the ? is throwing the compiler off.
<Groogy> i.e you don't have to fetch twice
<FromGitter> <HCLarsen> Yeah, I'm with you there, not fetching twice would be ideal.
<FromGitter> <picatz> Optimization 👍
<FromGitter> <HCLarsen> Exactly Kent.
<FromGitter> <bew> @HCLarsen you can do: `@rain = value["rain"]? || 0`
<FromGitter> <bew> better than a ternary
<Groogy> yeah there are bunch of tricks like this to make the code look better
<FromGitter> <HCLarsen> I like that @bew , but that threw another error
<FromGitter> <HCLarsen> ```code paste, see link```
<Groogy> ugh gitter bot didn't give me a link to the code on IRC D:
<Groogy> ah well yeah the thing you get out of a JSON::Any is another JSON::Any you have to convert it
<FromGitter> <bew> vivius: don't try to put everything on one line, you can create a method with the conditions, the you'd use `return call_next if your_new_method(context.request.path)` for example
<FromGitter> <bew> oh right @HCLarsen ...
<FromGitter> <HCLarsen> Is there any way to convert it in that same line?
<Groogy> @rain = value["rain"]?.to_i || 0 should work
<Groogy> I think?
<FromGitter> <bew> with .try
<Groogy> ah right forgot about #try
<FromGitter> <picatz> *Unrelated to what's currently being discussed:* Could someone help me understand the usage of a C binding to LibPcap? The `pcap_ pcap_findalldevs` function -- how would I end up using this in Crystal? : Source:
<FromGitter> <bew> `value["rain"]?.try(&.to_i) || 0` should work
<FromGitter> <HCLarsen> Oh wow. I did not know about that method.
<FromGitter> <bew> well there it is ;)
<FromGitter> <picatz> I'ma have to *try* it out sometime. 😂
<FromGitter> <bew> :D
rohitpaulk has joined #crystal-lang
<Groogy> I always forget about it
<Groogy> need to get better at using it
<FromGitter> <HCLarsen> Still threw a compile time error.
<vivus> how big is the crystal channel on gitter?
<FromGitter> <bew> TBH me too
<FromGitter> <picatz> *Or at least *try* to.* I should stop.
<FromGitter> <HCLarsen> Works now. Used as_i instead of to_i.
<FromGitter> <bew> @picatz don't use the lib directly, usually the binding has a wrapper around the lib to have crystal-ish code to manipulate the lib, but you shouldn't have to do it yourself
<FromGitter> <bew> @HCLarsen cool!
<FromGitter> <HCLarsen> ```@rain = value["rain"]?.try(&.as_i) || 0```
<FromGitter> <HCLarsen> Now I gotta figure out another one, where sometimes the API returns an int, and other times it returns a float.
<FromGitter> <HCLarsen> I got it working, but I'm basically fetching it twice again.
<FromGitter> <picatz> @bew Right, but in this case I can't find any wrapper to that function. For practice, I'm trying to write my own bindings to libpcap just to learn how it works. I'm able to get the `pcap_lookupdev` function to work, but the `pcap_findalldevs` function has some arguments I suppose I don't entirely understand / looking for clarification or, better, an example.
<FromGitter> <bew> @picatz see this it is a wrapper around pcap lib, you should use the wrapper
<Groogy> I need to figure out how I want my UI components to communicate button press, state changes etc. :/
<FromGitter> <bew> yeah maybe he didn't finished
<vivus> Groogy: sounds like a non-problem to have
<FromGitter> <bew> the readme says "work in progress"
<FromGitter> <picatz> From what I can tell, he didn't / I'm not entirely sure how correct it is. Though, I'm no expert either.
<Groogy> eh well it is, there's tons of ways to do it and I am porting my old code from C++ and I am wondering what would be the more "crystal" approach to it
<FromGitter> <picatz> I love his work, and am using it to get a start, but I'm finding some of the C stuff confusing. Specifically how the `pcap_findalldevs` function is used. 😟
<FromGitter> <bew> do you know a bit of C?
<FromGitter> <picatz> A little bit. Enough of it to use libpcap in C based on examples I've found.
<FromGitter> <bew> did you find examples about the function you're trying to use?
<FromGitter> <picatz> I can't find crystal examples, but I can find some C references and a reference to it in pcaprub
<FromGitter> <picatz> is used under the hood of `lookupdev` if on windows.
<FromGitter> <bew> don't worry about what's underthehood
<FromGitter> <picatz> Well, it acts as an example of how it is used as a binding, at least in Ruby land.
<FromGitter> <bew> do you know pointers in C?
<FromGitter> <picatz> I'm familiar-ish with them, but I guess I don't know how it works in Crystal land when the function is asking for one.
<FromGitter> <picatz> I guess I don't know how they're used in crystal lang to make a pointe to the particular struct/type I need.
<FromGitter> <bew> here is a very basic example in C:
<FromGitter> <picatz> Yup, found that too! I understand that I need to `pcap_if_t *interfaces` in crystal.
illyohs has joined #crystal-lang
<FromGitter> <picatz> And use that as an argument. That seems to be implemented with `type PcapIfT = PcapIf`
<FromGitter> <picatz> Which is equiv of `typedef struct pcap_if pcap_if_t;` in the libpcap library I'd imagine.
<FromGitter> <picatz> `fun pcap_findalldevs(x0 : PcapIfT**, x1 : LibC::Char*) : LibC::Int ` so, I don't really know how to use this. I can give the `x1` param the `PCAP_ERRBUF_SIZE` -- but I don't know about `x0`
<FromGitter> <picatz> ~I don't really know, of course. I'm just trying to figure it out~
qard_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <bew> x0 and x1 are not very explicit about what it is ><
qard has joined #crystal-lang
<FromGitter> <picatz> Yeah. I know `x0` should be a `pcap_if_t *alldevs;`
<vivus> does anybody know how to put a regex in `return call_next` here:
<FromGitter> <picatz> That's how it's used in pcaprub.
<FromGitter> <bew> vivus I replied to you already
<FromGitter> <bew> @picatz from the man page, the args are `pcap_if_t **alldevsp, char *errbuf` (in C)
<vivus> @bew you incorrectly tagged my username so I missed your reply, sorry
<FromGitter> <bew> oh sorry, well now you know you have a reply :p
<vivus> @bew : can you show me how to do this: you can create a method with the conditions, the you'd use `return call_next if your_new_method(context.request.path)` ?
<FromGitter> <picatz> @bew Right, so, I know how to get the `char *errbuf` arg. I just don't know how to create what I need for the `pcap_if_t **alldevsp` arg.
<Groogy> I used to have a hook type called "OnDestruction" though for Crystal that wouldn't make sense because of GC etc. What would be a good name for like, being "taken out of usage"?
<FromGitter> <bew> seems that `errbuf` should be a pointer to a char, and if the call fails that variable will be filled with the error (in crystal it's a UInt8)
<FromGitter> <picatz> Yup, I got the `errbuf` sorted out, more or less. Just know the pointer/typedef/struct thing for the first arg.
<FromGitter> <bew> do you know the concept of iterators and how they work?
<FromGitter> <bew> (basically)
<FromGitter> <picatz> I think so.
<FromGitter> <picatz> I suppose I don't entirely understand how it's used in this context / don't have example code to get a better understand in Crystal.
<FromGitter> <bew> the first arg is a pointer of pointer that will be filled with the pointer of the first element (a possible interface) of the chain, then you'll use `` to get the next element, until there is none
<FromGitter> <bew> I'll give you an example
<FromGitter> <picatz> Plz <3
<FromGitter> <picatz> I appreciate the heck'out of you for an example of how it's used.
<vivus> @bew the code I showed you is from the handler in amber framework
<FromGitter> <bew> vivus: ah ok, then maybe you need to hook yourself somewhere else, don't know Amber enough to tell you, you should ask on their gitter room, you'll get more help I think
<vivus> @bew how do I get that regex to appear in the line though?
<FromGitter> <picatz> I'm super interested to see what this `pointer of pointer` stuff looks like / trying to hack together something with that before you give me the example. 😂
<FromGitter> <picatz> @bew I think I'm getting somewhere? `argument 'x0' of 'LibPcap#pcap_findalldevs' must be Pointer(Pointer(LibPcap::PcapIfT)), not Pointer(LibPcap::PcapIf)`
<FromGitter> <bew> it's a start!
<FromGitter> <bew> almost finished ;)
<FromGitter> <picatz> :D
<FromGitter> <bew> ```code paste, see link``` []
<FromGitter> <bew> not tested but it should work (it compiles at least)
<FromGitter> <bew> you'll need to change the require, sth like `pcap/libpcap` I think
<FromGitter> <picatz> Looking into it now 👍 Will let you know if I have questions!
<FromGitter> <bew> better: change to while to `until iface_iterator.null?`
<FromGitter> <bew> ah I misunderstood the errbuf arg
<FromGitter> <picatz> Sorry, I'm a bit confused how `result = LibPcap.pcap_findalldevs(out iface_iterator, out error)` works.
<FromGitter> <picatz> I guess I don't know how `out iface_iterator` was initialized.
<Groogy> put together a minimal example, is there a way to do this kind of prettier?
<Groogy> imagine collection var being a @ivar
<FromGitter> <picatz> @bew I appreciate that documentation link!
<vivus> does anybody else use Crystal for web apps?
<FromGitter> <picatz> Sorry if this is obvious and I'm missing something: How is the `iface_iterator` object first created / does it need to be?
<Papierkorb> Groogy: What are you trying to do? Can you give a real, not a hypothetical, example?
<FromGitter> <HCLarsen> Vivus, check out the amber framework and gitter channel. It's a Crystal web framework.
<vivus> @HCLarsen that is the 1 I am using
<Papierkorb> Groogy: Also *cough*
<Groogy> eh hooks for GUI widgets
<Papierkorb> A symbol based API is not safe to use (typos etc.). It also has the disvantage that you can't have "hooks" with different arguments
<Groogy> I am not using symbols
<Groogy> using enums
<FromGitter> <bew> Groogy for your specific example I'd say: `hooks = c[:bla] ||= [] of Int32` (replace with your variables)
<Papierkorb> Groogy: The second part holds true for enums too
<Groogy> thx bew
<Groogy> hmmm
<Papierkorb> Hence cute doing a few things to make it possible (Not based on enums or symbols)
<Groogy> problem with cute is it would be variables so for instance if Widget defines behaviour for on state change, having a sub class then define it as well would shadow that wouldn't it?
<FromGitter> <picatz> @bew I think I'm starting to understand the code you shared! Thank you!
<FromGitter> <bew> @picatz `out` allows you to create a new local variable from a lib fun, based on the type defined for that lib fun' arg
<Groogy> could potentially do it with macros though
<Papierkorb> Groogy: One sender, many receivers
<Papierkorb> Optionally, many concurrent receivers
<FromGitter> <picatz> Right! That's what I was missing / silly me. 😂
<Groogy> no that's not waht I mean
<FromGitter> <bew> minus 1 level of pointer, so with a type `Int32*`, `out var` will make a var of type `Int32`
<Papierkorb> Groogy: ?
<Groogy> Widget holds on state change logic for what applies to every kind of widget while Window only holds for instance moving around a window
<FromGitter> <bew> and the address of that var will be passed to the lib fun call, so that the lib cal fill it
<Groogy> how I've done it in C++ it would just be an array it appends onto
<Papierkorb> signals are inherited, correct. If what triggers them is inherited (how) is up to you
<FromGitter> <picatz> @bew Thanks!
<Papierkorb> Basically I mirror the behaviour of Qt
<Groogy> I'll give it a try
<Groogy> It looks sort of similar to what I did for input
<Groogy> can you access self somehow in a signal?
<Papierkorb> which self?
<Groogy> i.e the widget
<Papierkorb> The connected blocks are not messed with
<Groogy> yeah no I was thinking of the widget you are adding the signal to
<Papierkorb> No
<Papierkorb> But as you must know the widget outside the block
<Papierkorb> you know it inside
<Papierkorb> Which is why I didn't add that
<Groogy> hm true
<Groogy> huh that's weird
<Papierkorb> did you break it?
<Groogy> oh no I forgot to install cute on the project
<Groogy> I only did it in Boleite
<Groogy> ah since it isn't committed to Github it won't intall it that's why
<FromGitter> <bew> Papierkorb what is IntervalSink for? (in cute)
<Papierkorb> you dump signal emissions into sinks
<Papierkorb> and then they do something with them
<Papierkorb> interval sink does .. erm
<Papierkorb> doesn't the docs say that?
<FromGitter> <bew> what is a "sink"
<FromGitter> <bew> in that case
<FromGitter> <bew> yes but I don't get ^
<Papierkorb> There's a USAGE section on it, but not a complete description in words apparently
<FromGitter> <bew> nvm I've found the doc of Sink
<FromGitter> <bew> yes thx!
<Papierkorb> sinks are basically there to easily add a more refined control flow to your logic
<FromGitter> <bew> I'm interested into how IntervalSink works because I need sth that have this behavior (but without cute)
<Papierkorb> Say you build a network instant-messaging service, and have many clients. You could use a sink to e.g. add flood control, meaning that you'd notice that a client is sending too much stuff. Because of the pipeline-ish design, you can add this later on in the app as you totally forgot to add it in the first place
<FromGitter> <picatz> @bew Whilst I think I understand what's being done in the code you shared: I keep running across this bug when using stuff from it: `BUG: LibPcap::PcapIfT doesn't implement instance_vars`
<FromGitter> <bew> Papierkorb In my case I have a fiber that renders something to a process, it is notified by a channel that it need to re-render the content and I'd like to "de-bounce" and re-render every 100ms even if I get a lot of render notification
<Papierkorb> bew, just remember the last Time you rendered, then on next call, check if the last time was earlier than 100.milliseconds
<Papierkorb> ago
<FromGitter> <bew> @picatz during build? or runtime?
<FromGitter> <picatz> I'd imagine build because of this `Error: you've found a bug in the Crystal compiler.`
<Groogy> Papierkorb something like that I guess?
<FromGitter> <bew> Papierkorb yes could work, I know I shouldn't worry about that but I don't want to make too much syscalls to get the current time on each render notification
<Papierkorb> * `state_changed`, but yeah kinda like that. Not sure if #on accepts a Proc by itself though (line 25), or if you have to pass a block
<FromGitter> <bew> Groogy don't think you need the empty ()
<Groogy> ah it is just place holder right now
<FromGitter> <bew> 👍
<Groogy> it did work with giving it a Proc
<Papierkorb> bew, If you have that many requests to the render function, then each time you render check if @rendered is true (and if so, return), else set it to true. Then in a fiber, you sleep 100ms and simply set @rendered to false
<Groogy> but for instance I guess like Button would add a "activated" kind of variant which is whenever it is clicked
<Groogy> and then Window would have a "dragged" variant etc.
<Papierkorb> Groogy: Also you can send arguments along the emission
<Papierkorb> Yup
<Groogy> I know
<FromGitter> <bew> thanks, I don't have that many requests but I (too much probably) like to have "clean" stuff, with minimal nb of syscalls, I like your idea I'll try that!
<FromGitter> <picatz> @bew It seems to be linked to the `.next` method when it called on the iface iterator. That's when I get the error. I see you're busy with other stuff too, sorry lol
<Groogy> though I don't like putting it in initialize
<Groogy> thinking about adding a setup_hooks method for sub classes to override or something
<FromGitter> <bew> @picatz don't worry ;)
<Papierkorb> bew, note that a fiber is also expensive in its own right: If your program is super busy, it take much much longer than 100ms for reset fiber to be woken up again. In that case, a may not be that bad after all
<Papierkorb> Groogy: For something like event bouncing, I'd think about using a method you re-implement in sub-classes, and then call `super`. `state_changed` may be a good candidate for this
<Groogy> hm?
<FromGitter> <bew> Papierkorb: that's true too, do you think that a smaller stack for the fiber would speed it up? (if one day we can configure that)
<Papierkorb> Signals are really good at stuff like user interactions (mouse pressed)
<Papierkorb> bew, stack size has nothing to do with it
<FromGitter> <bew> what could be the slowness?
<Papierkorb> well, if the combination of all other fibers take more time to process (until yielding) than 100ms, your sleep of 100ms would get bigger, missing the reset, thus making your #render not re-render as it thinks it's not time yet
<Papierkorb> doesn't have that issue
<FromGitter> <bew> ok I see, thanks!
<Papierkorb> Though if your #render is so hammered that becomes a bottleneck, you should rethink your design
<Groogy> ugh gah the WeakRef is making the code ugglier :/
<Papierkorb> bew If it's getting hammered anyway, then why call it at all? Just re-render every 100ms
<Groogy> So I can't assign Nil to the WeakRef because it isn't the type I want
<Groogy> so I made it WeakRef?
<Groogy> but then whenever I try to access the value it becomes really weird if statements
<Papierkorb> bew, if you don't want to re-render if nothing happened anyway (rendering is actually expensive in your case?), then your public #update method could simply set the @dirty flag, and a 100ms sleeping fiber loop could #render if @dirty is set
<Papierkorb> Setting a Bool to true is pretty cheap :P
<Papierkorb> Groogy: `@parent.try(&.value)`
<Papierkorb> if var = ^
<vivus> who runs/owns the FromGitter bot here?
<Papierkorb> um .. oprypin ?
<FromGitter> <bew> Papierkorb I already have that dirty flag system here, didn't thought I could use it this way for the renderer too, thanks!
<vivus> ping oprypin
<Groogy> though I could make the weakptr have the type Widget | Nil right?
<Groogy> that should be fine?
<Papierkorb> Groogy: Why not add a `def parent? : Widget?` and then do the #try in there?
<Groogy> no it is literally in there I am writing the code :P
<Groogy> I noticed I had written it wrong in there and I am trying to fix it
<FromGitter> <bew> Papierkorb and no, it's not expensive, will never be under load or anything, I'm just having fun experimenting with crystal ;)
<FromGitter> <bew> and how things can be done in different ways, etc...
faustinoaq has quit [Quit: Konversation terminated!]
faustinoaq has joined #crystal-lang
<FromGitter> <bew> @picatz I think you can open an issue about that bug
<Papierkorb> Why don't we btw use the ALRM signal to make the scheduler preemptive?
<FromGitter> <picatz> @bew ok, will do
<FromGitter> <bew> @picatz does it crash with master too?
<FromGitter> <picatz> As in the latest crystal version?
<FromGitter> <bew> yes
<FromGitter> <picatz> Good question! I just realized I am on `23`
<FromGitter> <picatz> I'll check it out.
<oprypin> vivus, what is going on
<Groogy> huh Papierkorb
<Groogy> Cute is gonna mesh really freaking nice with my input system I realized
<Groogy> not actual code
<Groogy> but something like that
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
<Groogy> that system takes care of translating generic events from GLFW to arguments and it should be feasable to just have that directly translate into an emit
<Groogy> this should sort of work right Papierkorb? @input.register WidgetMouseMoved, ->mouse_enter.emit(Float64, Float64)
<Papierkorb> depending on what your #register does, yeah
<Groogy> yeah were more on if the -> would accept that
<Groogy> cool
<Papierkorb> ya um .. not sure. please report back if it works....
<Groogy> ah no it doesn't
<Groogy> I also tried self.mouse_enter.emit
<Groogy> it complains on the second .
<Groogy> would be nice with a self.mouse_enter.emit_proc or something
<FromGitter> <bew> whats the error?
<Groogy> Syntax error in lib/boleite/src/boleite/gui/ unexpected token: .
<FromGitter> <bew> without self. too?
<Groogy> I mean I can fix it by just wrapping it in a proc call like the -> does for me
<Groogy> without self it complains that it thinks mouse_enter is a variable
<Groogy> Syntax error in lib/boleite/src/boleite/gui/ undefined variable 'mouse_enter'
<FromGitter> <bew> ah yes, mouse_enter is a call in your case
<FromGitter> <bew> and -> proc syntax only works with obj.method not method.method
<Groogy> yeah I get why it doesn't work
<FromGitter> <bew> ah I just understood your comment about emit_proc x)
<Groogy> though hmm after moving things around it now doesn't like my state_change.on ->on_state_change
<vivus> oprypin: may I PM you?
<Groogy> I don't get it :S
<Groogy> the block should be fine with Proc(Nil) right?
<vivus> oprypin: sorry for the ping. I wanted to query about your Critter bot
<FromGitter> <bew> Groogy, with `&->on_state_changed` ?
<FromGitter> <bew> you need to pass it a a block arg
<FromGitter> <bew> I think
<Groogy> seamed to solve itself if I just did ->self.on_state_change?
<oprypin> vivus, just do it
<Groogy> ooooooh
<Groogy> it's caused by my another error
<Groogy> block is getting a reference to self before a variable is initialized
<vivus> oprypin: can your bot run in multiple gitters and IRC channels?
<oprypin> yes
<vivus> oprypin: can you add the bot to connect the following 2 channels: #amber and please?
<oprypin> vivus, ok, but how about a proof of ownership, so to say?
<FromGitter> <picatz> @bew I think I figured out the issue!
<vivus> oprypin: proof of ownership w.r.t ?
<oprypin> the channels
<FromGitter> <bew> @picatz what was it?
<vivus> oprypin: you can join #amber and speak to faustinoaq , who is a core member of the amber framework
<FromGitter> <picatz> Well, I was having all sorts of issues with that `PcapIfT` type. And so, I figured, what if I sort of ignored it? So, I implemented the functions like so: `fun pcap_findalldevs(x0 : PcapIf**, x1 : LibC::Char*) : LibC::Int`
<FromGitter> <picatz> Then, my `result = LibPcap.pcap_findalldevs(out iface_iterator, out error)` works along with all my `` when I iterate over interfaces later.
<FromGitter> <picatz> OR at least I'm getting stuff to work.
<FromGitter> <bew> oh good!
<FromGitter> <picatz> Right?! This is why I wanted to implement LibPcap bindings. I figured I'd learn things.
<FromGitter> <picatz> I appreciate your help! 👏 I don't think I would've figure this out without you.
<FromGitter> <bew> you're welcome ;)
<FromGitter> <picatz> I'ma work on this some more and write up a blog post about what I've learned.
<FromGitter> <picatz> Maybe it'll help someone.
<FromGitter> <picatz> I also want to make a contribution to pcaprub to implement the `pcap_findalldevs` method so it's available there too.
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<FromGitter> <him9> on windows. when?
claudiuinberlin has quit [Quit: Textual IRC Client:]
lacour has joined #crystal-lang
<FromGitter> <exts> is there a way to rename a lib from the compiler or do you have to recreate the project
<FromGitter> <bew> what part of the lib, the @Link or the Crystal' lib name?
<FromGitter> <bew> and what do you mean "from the compiler"?
<FromGitter> <exts> the lib itself, the namespace
<FromGitter> <exts> after running init lib name
<FromGitter> <bew> ah yes of course, when you run `crystal init lib name` it only generates some files, you can do whatever you want with them!
<FromGitter> <exts> yeah, my question is can you rename an already created lib eg.: `crystal rename lib src dst`
<FromGitter> <bew> ah no, no such tool exists
<FromGitter> <exts> maybe in the future then
<FromGitter> <bew> don't think so
<FromGitter> <bew> `grep old_name` to see where you need to change it, and if you know a bit of `sed` you can replace the name in all your files at once (don't forget to make a backup before)
<FromGitter> <exts> maybe when I get good enough with crystal I'll do it myself :)
<FromGitter> <bew> Basically you want to rename a module?
eliasjpr has joined #crystal-lang
<FromGitter> <exts> not sure how to explain it better than what I've previously typed
<Groogy> Papierkorb this is working out perfectly
<Groogy> just want a function to convert emit easily to a proc
<FromGitter> <bew> hint: open an issue :p
<Groogy> ah true
<Groogy> ^^
<FromGitter> <bew> looks really nice!
<FromGitter> <Qwerp-Derp> What's Cute?
<FromGitter> <exts> me obviously ;)
<Groogy> PApierkorb's publisher/subscriber model stuff
<FromGitter> <bew> @Qwerp-Derp
<FromGitter> <bew> @exts please x)
<Groogy> I bet I am cuter
eliasjpr has quit [Ping timeout: 260 seconds]
<FromGitter> <Qwerp-Derp> :( None of Papierkorb's QT stuff works on Mac OS X...
<FromGitter> <exts> haha
<Papierkorb> Qwerp-Derp, because no Mac OS X user stepped up.
<Papierkorb> From my end this won't change. I want it to be supported, but I don't own apple stuff, so I can't.
<Groogy> also Papierkorb be prepared to get your first ticket ;D
<Papierkorb> What, for a emit_proc func?
<Groogy> or something
<Groogy> i.e a nice way to get a callback back to the signals emit
<Papierkorb> No idea yet if I even want that, as writing that block/proc it isn't hard
<FromGitter> <Qwerp-Derp> Papierkorb Yeah I know that no mac users have stepped up, I would step up but I have zero Qt experience
eliasjpr has joined #crystal-lang
<Papierkorb> Groogy: How does your #register_instance work?
<Groogy> IT takes a transformation object (without _instance it takes a type) that will transform an Event to a tuple that get splatted to a Proc
<Groogy> i.e the proc I am trying to provide to it
<Groogy> is there a uniform type of signals I could just have it refer to?
<Papierkorb> then you don't need the restrictions
<Papierkorb> There's `Cute::Signal` as base type. If you want to restrict on that, you can
<Groogy> well the glue code calls *args
<Groogy> will Signal respond to that or do I have to call #emit?
<Groogy> If I use a type restriction for Cute::Signal I could do a method that wraps it for me in a Proc
<Papierkorb> #emit
alex`` has quit [Ping timeout: 240 seconds]
<Papierkorb> Groogy: You could also have a #register_instance that calls #emit instead of #call on the passed thing
eliasjpr has quit [Ping timeout: 240 seconds]
<Groogy> ah no its not register_instance that does it
<Papierkorb> If you're the application, and not the lib, you could of course monkey-patch an alias from #call to #emit
<Groogy> it is GlueImp that does it
<Groogy> wait
<FromGitter> <pnloyd> When you do `alias Foo = Bar | Baz` are you basically giving a union name?
<Groogy> yeah kinda
<Groogy> I could do a GlueImp specifically for signals
<FromGitter> <bew> CuteGlue :p
<Papierkorb> A SignalGlue could just inherit from GlueOmp, the only thing that has to change is your #execute
<Groogy> yeah that's what I sorta meant
<Papierkorb> Though having a -> would be nice
<Papierkorb> Isn't that actually possible already? You should be able to do `->, B, C)`
<Groogy> yeah this solves it for me
<Groogy> no it doesn't like it
<Groogy> it thinks foo is a variable
<Papierkorb> not even with the explicit types?
<Groogy> nope
<Papierkorb> ... ->
<Groogy> makes it worse
<Groogy> it then says second dot is unexpected
<FromGitter> <bew> what about `->` ?
<Groogy> that might work, haven't tested that
<Groogy> second
<FromGitter> <bew> (probably won't work)
<FromGitter> <bew> (maybe there isn't even an ivar for each cute's signals)
<Groogy> unexpected token
<Groogy> ->@ is probably not valid
<Papierkorb> There's an ivar, but it's nilable
<Papierkorb> signals are lazy
<FromGitter> <bew> Groogy hmm thought so
<Papierkorb> You could also throw them into a temporary var
<Groogy> yeah but this is fine
<Groogy> though think I found a weird issue in Crystal
<Groogy> gonna see if I can do miniaml repro
<FromGitter> <bew> would be nice to have `->(foo).bar` that'll call foo and use that as the receiver
<FromGitter> <bew> but probably too cryptic
<Papierkorb> it should just call the getter method
<Groogy> hah yeah I did
<Groogy> if you switch the generic argument S to P
<Groogy> it works
<Papierkorb> rubocop would complain that line 18 is ambiguous
<Papierkorb> (@callback.emit * args) or @callback.emit(*args) ?
<Groogy> no the issue I am refering to is specifically on is the args
<Groogy> S and P are not the same
<Groogy> even if they are the same type
<Groogy> since I don't define my own initialize
<Groogy> that seems like a bug right?
<Papierkorb> I wouldn't call it intentional
<Groogy> there is as minimal I can get it
<Groogy> I'm gonna see if there is an issue on it already otherwise report it
eliasjpr has joined #crystal-lang
<07IABQ5Q9> [crystal] RX14 closed pull request #5200: Disallow invalid values to be set in XML::Node (master...bugfix/xml-special-entities)
<7GHAA2T2B> [crystal] RX14 pushed 1 new commit to master:
<7GHAA2T2B> crystal/master 39b8e88 Chris Hobbs: Disallow invalid values to be set in XML::Node (#5200)...
<DeBot_> (Disallow invalid values to be set in XML::Node)
<DeBot_> (Disallow invalid values to be set in XML::Node)
<RX14> oops
<RX14> probably should have rebased instead of squashed
<RX14> oh well
<Groogy> there we go, my good deed of the day
<Groogy> time to sleep