Activity Graph

« Prev | Page 2 of 5 | Next »


[13:10:45] argoneus: (Can I ask about rspec/factorygirl here or is this strictly for rails?)
[13:23:30] argoneus: so, I'm using rails and factorygirl+rspec for testing, but I'm getting this error: DETAIL: Key (char_as_id)=(0) is not present in table "characters".
[13:23:36] argoneus: actually this'll be better to put in a paste, 1 sec
[13:26:54] argoneus:
[13:27:07] argoneus: oh, okay, 1 sec
[13:27:58] argoneus: you can add multiple files to gist, I had no idea, I apologize!
[13:28:01] argoneus: should I re-do it?
[13:28:25] argoneus: doing that atm
[13:29:11] argoneus: I updated it
[13:30:32] argoneus: I'll just split it properly into files, 1 sec
[13:31:16] argoneus: the problem I assumed was happening was that my Characters were somehow getting removed before the Matchup was created


[11:21:03] argoneus: are there any special requirements to overriding []=? for some reason my program doesn't work as intended and I can't figure out why
[11:24:47] argoneus: my signature is def []=(*args), but for some reason when I do Grid[x] = 5 it doesn't get called at all
[11:26:48] argoneus: any idea why this could be?
[11:28:44] argoneus: oh, I'm an idiot
[11:28:53] argoneus: bla[x][y] is different from bla[x, y]
[11:28:59] argoneus: good to know


[21:23:10] argoneus: I have a function that returns an Enumerator and/or yields to a block, the result is a bunch of numbers
[21:23:28] argoneus: I want to write a function "no_zeroes" so that I can do something like my_numbers.no_zeroes.to_a
[21:23:45] argoneus: what kind of signature should that function have? I tried looking at with_index, which seems to work similarly, but only found C source
[21:24:19] argoneus: (the goal of the function is to return an enumerator/yield to a block all the numbers that aren't == 0
[21:24:48] argoneus: I could use select, but I wanted to try and make a more... specialized function as an exercise
[21:25:04] argoneus: since I was wondering how these functions worked
[21:28:23] argoneus: ohhh, I'm an idiot
[21:28:40] argoneus: I'd need to have no_zeroes inside of Enumerable for this to work like that
[21:28:54] argoneus: reading that medium link made me realize


[20:10:40] argoneus: I have a table called "match results", which basically has team1_id, team2_id, and I'm wondering
[20:10:55] argoneus: id1=5, id2=8 for example should return the same matches as id1=8, id2=5
[20:11:10] argoneus: is this something that's doable in the database directly or do I just make another select if the first yields no results?
[20:11:21] argoneus: or make two selects and merge the results or idk


[12:43:04] argoneus: has joined #RubyOnRails
[14:16:18] argoneus: hello, I have a bit of a technical question. I get how respond_to works, but I don't understand how it works internally, e.g. respond_to do |format| format.xml { code } end
[14:16:32] argoneus: what exactly is format.xml? I found that 'format' is some Collector but I'm not sure how that works
[14:16:36] argoneus: and I couldn't find any documentation on this
[14:18:48] argoneus: I'm not sure what the .xml part exactly is
[14:19:03] argoneus: I'd understand if it was assigning some lambda
[14:19:12] argoneus: but it's just a block
[14:19:14] argoneus: smalltalk interface?
[14:22:20] argoneus: sending a block that is passed into the .xml message... this is still a bit confusing to me :( so the 'format' object is sent a message :xml which is a block?
[14:22:45] argoneus: ohhhh, so the block is like an argument?
[14:23:05] argoneus: damn, this is some magic (for now)
[14:23:53] argoneus: so the entire idea is that I tell it "if people send a request for xml, then do this and return xml"
[14:24:10] argoneus: except it's not limited to just xml, json, etc. but I can feed it format.my_custom_format
[14:24:19] argoneus: and a block as argument?
[14:27:08] argoneus: I see, or rather, this is a bit too complicated to understand for me right now
[14:27:17] argoneus: but it's making a lot more sense than before, thanks a lot for your answer!
[14:30:20] argoneus: I wasn't sure what you meant before, but now I see
[14:30:45] argoneus: basically format.xml doesn't exist as a method, so it will invoke method_missing with the block as an argument, which is then saved as the respective mime type handler and called if needed


[13:00:53] argoneus: why is it not possible to do ary << yield val?
[13:01:07] argoneus: is it because yield val is a function
[13:03:21] argoneus: I have code that looks like
[13:03:58] argoneus: ah, okay, that works


[10:13:03] argoneus: as part of a homework I wrote some code that works, but I have no clue why
[10:13:59] argoneus: I have a module, inside it a function called "sum", and its only statement is 'reduce(:+)', this module is than included in a class that also includes enumerable, and for some reason calling 'sum' on this gives the desired result
[10:14:17] argoneus: what exactly does it mean if I just have 'reduce(:+)'? I can't find any doc on this
[10:14:51] argoneus: all I see is that reduce is a method of Enumerable, but inside this other module I'm writing, I don't include Enumerable
[10:16:17] argoneus: and what does that even return
[11:57:51] argoneus: so whether reduce() exists or not is determined in the class that incldues the module
[11:57:54] argoneus: not in the module itself
[20:38:08] argoneus: hello, I'm wondering, is Ruby suited for a websocket server project? trying to learn the language on something I might actually use
[20:38:21] argoneus: I thought it'd be similar to python but blocks are killing me inside
[20:40:26] argoneus: I'm not planning to use rails, I plan to use something else altogether to make the client
[20:40:34] argoneus: and I don't need high performance, I just want to actually learn the language
[20:41:00] argoneus: and by killing me, I mean that I understand in my head how blocks work, but then I see some examples of code that uses blocks and I'm back to square one and don't understand how it works
[20:43:41] argoneus: like, when looking at the example code for faye-websockets
[20:44:03] argoneus: ( from here)
[20:44:29] argoneus: which part of the example block keeps track of which client it's responding to? or do I need to do that
[20:44:47] argoneus: I just can't picture the flow in my head
[20:45:23] argoneus: nope, that'd probably be a good place to start
[20:45:34] argoneus: I've only done raw TCP servers before which was considerably easier
[20:46:00] argoneus: using asyncio
[20:47:26] argoneus: the syntax is way different
[20:48:05] argoneus: also it's more
[20:48:17] argoneus: I can understand from the examples how to use the code, but I'd like to understand what it actually does under the hood
[20:48:25] argoneus: and the more I try to do this in ruby the more I regret it every time
[20:49:55] argoneus: well, the websocket part is just a tiny part of the server, right
[20:50:05] argoneus: I still need to actually have the server do things, so I can take the websocket lib as magic for now
[20:50:52] argoneus: yes, and/or use electron or similar
[20:50:59] argoneus: it's a server for a simple text game
[20:51:10] argoneus: not too concerned about the client atm
[20:52:58] argoneus: implementing websockets by myself is probably out of the question
[20:53:12] argoneus: ruby doesn't seem too ideal for low level bitwise work
[20:53:16] argoneus: or am I wrong
[20:53:52] argoneus: yes but I mean stuff like
[20:54:05] argoneus: "extract the first 15 bytes from the tcp stream and convert them to a value"
[20:54:42] argoneus: then how about writing my own simple websocket implementation on top of TCPServer
[20:54:53] argoneus: I can always just plug the faye-websockets lib in later, right
[20:56:07] argoneus: writing my own WS implementation seems like good practice, since it's a lot of io work
[20:56:24] argoneus: thanks a lot, just one last thing, or two
[20:56:34] argoneus: 1) is TCPServer the go-to for just a tcp server or are there issues with that too?
[20:57:19] argoneus: I'm used to raw sockets so that's nice
[20:57:43] argoneus: and 2) is it difficult in ruby to write unit tests for network stuff? or in general things out of my control
[20:58:44] argoneus: well, like I said, it's a text game server
[20:58:49] argoneus: I need to implement the whole text game logic
[20:59:36] argoneus: hmm, well, here's what I'll do
[20:59:51] argoneus: I've never actually tried implementing WS before, so I'll try that first, if it proves to be too painful, I'll use a lib and just make the game instead
[21:00:03] argoneus: does that work
[21:00:30] argoneus: I'm a control freak in the sense that I want to know exactly what my program does >_>
[21:00:38] argoneus: instead of relying on magic function calls
[21:01:31] argoneus: I'm still learning, it's not my job yet
[21:02:06] argoneus: then again... I guess there's a learning curve to using the big boy libraries too?
[21:02:18] argoneus: like, I can't just "learn" ruby and then download rails and suddenly be familiar with it, right
[21:04:49] argoneus: I think I see what you mean
[21:05:06] argoneus: the average javascript developer is probably way more productive than me
[21:05:13] argoneus: but they probably don't know what a higher order function is
[21:05:17] argoneus: well, they do intuitively
[21:05:21] argoneus: something like that?
[21:05:51] argoneus: fair enough
[21:06:01] argoneus: I'll just try implementing my own WS until I start hating it
[21:06:04] argoneus: then I'll look into libs
[21:06:16] argoneus: thanks for the help anyhow
[21:06:33] argoneus: rubyists seem like a nice bunch :=)
[21:08:45] argoneus: I just realized how the pattern actually works
[21:08:59] argoneus: the websocket server example isn't the full program, I still need some "rack" to run it in
[21:09:10] argoneus: it makes sense now
[21:10:36] argoneus: so basically whenever this "rack" receives a request, it calls the lambda stored in App, and creates a new websocket out of the client
[21:10:42] argoneus: and then it's just callbacks on events
[21:10:46] argoneus: well that's simple
[21:13:32] argoneus: I've done a bit of common lisp if you want strictly FP, but python supports higher order functions
[21:13:46] argoneus: but no, not really
[21:13:55] argoneus: I just know what it is
[21:14:54] argoneus: I'm familiar with each and map and reduce and such
[21:15:31] argoneus: I'm actually not 100% on block semantics yet
[21:16:10] argoneus: the way I see it, when I call "yield x", it passes 'x' into an outside block currently calling the function, then the function does <stuff> and whatever is returned from the block is returned back into the yield statement, so I can assign it or put it back into the structure or such
[21:16:16] argoneus: probably wrong
[21:18:37] argoneus: what I don't understand yet and didn't find proper doc on
[21:18:41] argoneus: is how to_enum works
[21:18:57] argoneus: like, if I'm writing some custom each, there's often something like
[21:19:06] argoneus: return to_enum(:customeach) unless block_given
[21:19:38] argoneus: it returns an "enumerator", so I can iterate over it at a later time, but I don't get *how* it works
[21:20:27] argoneus: is an enumerator like a reference to the current function
[21:20:32] argoneus: so if I call .each on the enumerator it calls the same func
[21:22:05] argoneus: yeah, unless you give it a block, then it just yields the values
[21:22:14] argoneus: and saves them back
[21:27:13] argoneus: I had to stare at that sigma function for 10 minutes before I got it
[21:27:21] argoneus: &block means it might be nil, right
[21:30:40] argoneus: my head hurts, but I somewhat get it
[21:33:17] argoneus: so enumerator#next just... goes until the next yield, and then pauses again?
[21:33:27] argoneus: that's clever
[21:35:41] argoneus: I really really like the idea of blocks in Ruby, gotta say
[21:36:01] argoneus: instead of focusing how I'm going to be iterating over what, I focus on what I actually do with the things
[21:37:52] argoneus: and it's not just for iterating, I suppose? I can even use blocks as callbacks, like I could have something like { |buf| buf << "text" }, and this will open a file, "yield" a buffer which is filled and then returned, and the file writes it into the file and closes it
[21:38:01] argoneus: (is that a valid use of blocks? tho I'm sure this is in the std lib already)
[21:39:00] argoneus: that makes a ton of sense though!
[21:40:27] argoneus: so in this case, ws is some socket object, and on_message is... some block inside the ws object, and this block is yielded to from the internal implementation whenever there's a message?
[21:40:44] argoneus: like @message_block
[21:40:45] argoneus: or something
[21:41:15] argoneus: I get it, then :D
[21:41:20] argoneus: this is awesome
[21:41:44] argoneus: seems like all blocks are are just anonymous functions that take some arguments (or don't)
[21:42:18] argoneus: it's a special feeling when I reach the conclusion myself, ok
[21:42:38] argoneus: so it's like
[21:42:53] argoneus: def on_message(block)
[21:43:02] argoneus: @onmessage_block = block if block
[21:43:09] argoneus: or something
[21:45:19] argoneus: how does another method yield to this @onmessage_block or w/e it's called?
[21:46:52] argoneus: you can call a block just like that?
[21:46:56] argoneus: that's pretty rad
[21:48:11] argoneus: thanks a lot for this discussion
[21:48:19] argoneus: I actually have somewhat of an idea how the faye-websocket thing works now
[21:48:24] argoneus: like, why its interface is how it is
[21:48:48] argoneus: I was confused how they did stuff like
[21:48:55] argoneus: ws.on :message do |event| ... end
[21:49:13] argoneus: but, all this is is just a method on the websocket, def on(type, &block)
[21:49:30] argoneus: which is then converted to a proc object and stored internally and called whenever like
[21:49:33] argoneus: is that about right
[21:50:42] argoneus: this is a really really really clean and nice syntax for callbacks
[21:53:52] argoneus: anyway, thanks a lot for the discussion! I learned a lot today
[21:54:00] argoneus: I feel a lot more confident in actually writing something now
[21:54:08] argoneus: have a good evening


[12:42:59] argoneus: has joined #ruby
[12:43:38] argoneus: I have a 'case' operator with about 15 "whens" doing a regex check on a string, basically I'm looking for substrings in the given string, and if there's a match, I want it to give a prepared response
[12:43:49] argoneus: thing is, rubocop complains about too high cyclomatic complexity
[12:43:55] argoneus: what's the ruby way to do this?
[12:44:34] argoneus: ex.: case string\when /keyword/i then 'response'
[12:44:51] argoneus: it's part of a homework so I don't think I can just turn it off
[12:44:58] argoneus: but at the same time I can't think of a better solution
[12:46:06] argoneus: yeah, rubocop shouldn't be touched afaik
[12:47:27] argoneus: the keywords are wildly different
[12:47:32] argoneus: I need to do a separate lookup for each
[12:47:45] argoneus: I'll try the array approach
[12:49:09] argoneus: I'll send an email then, because I can't think of a cleaner solution than this


[13:09:01] argoneus: has left #RubyOnRails: ()
[13:09:03] argoneus: has left #ruby: ()


[09:50:03] argoneus: *.net *.split


[01:56:12] argoneus: I suppose this isn't a channel to ask about db schemas, right
[02:01:30] argoneus: basically, I have an event, that can have n users
[02:01:44] argoneus: and the event can also have sub-events, which can have a subset of these users
[02:01:53] argoneus: and I'm not sure how I'm supposed to put this in a schema
[02:02:19] argoneus: I want to do queries like "find all users on this event who haven't been to any sub-events"
[02:02:29] argoneus: and the reverse "find all users on this event who've been to at least 1 sub-event"


[16:28:45] argoneus: has joined #ruby
[16:38:55] argoneus: Ping timeout: 245 seconds
[16:51:37] argoneus: has joined #RubyOnRails
[16:51:38] argoneus: has joined #ruby
[17:14:17] argoneus: has joined #RubyOnRails
[17:14:17] argoneus: has joined #ruby
[17:14:17] argoneus: Changing host
[17:14:58] argoneus: there's so many methods, find, find_by, find_by_something, where.... which one is preferable when I just want to do something like: return the first user whose id=x and name=y or return nil
[17:15:16] argoneus: I even read that find_by is deprecated and I should use where
[17:16:36] argoneus: find_by seems to be the one I want for this, though
[17:18:28] argoneus: got it, thanks :)
[17:32:07] argoneus: renegadeandy: there doesn't seem to be an easy option to do multiole conditions
[17:32:23] argoneus: find_by(id: something, email: somethingelse) doesn't work :(
[18:07:06] argoneus: yayyyy it works
[18:34:34] argoneus: tbh if you crash a bike at high speed you are probably dead anyway
[18:35:03] argoneus: and if you aren't dead you will wish you were
[18:42:12] argoneus: what the fuck
[18:42:28] argoneus: is freenode being ddos'd again?