Activity Graph

Page 1 of 33 | Next »


[03:18:55] Scriptonaut: has left #ruby: ()


[00:07:52] Scriptonaut: has left #ruby: ()
[20:32:02] Scriptonaut: has joined #ruby
[20:33:17] Scriptonaut: hey I was just wondering if any of you know an array method similar to .find, but rather than returning the first element that satisfies the condition, it returns a property/value of that element. So like if I had an array of object, I would want to return object.some_value of the first object that satisfies the condition, rather than returning the object itself
[20:33:49] Scriptonaut: I could easily do this in two lines, but I'm wondering if there's a shorthand oneliner way
[20:34:42] Scriptonaut: actually I might just change it to an each loop and then return the element explicitly, I just usually liek to avoid explicit return statements when it's at the tail-end of a method
[20:36:29] Scriptonaut: I only want the first element that satisfies the condition
[20:36:33] Scriptonaut: map would give me an array
[20:37:19] Scriptonaut: I could do `next if blah?` and then chain a `compact` to the end of the block but that would be janky
[20:38:49] Scriptonaut: that returns the element
[20:39:08] Scriptonaut: I need a method like find, but rather than returning the element, it returns a result I calculate in the block
[20:39:51] Scriptonaut:
[20:39:54] Scriptonaut: that's the method
[20:40:01] Scriptonaut: I need to return snomed_record.first
[20:50:33] Scriptonaut: woodruffw: find won't work
[20:50:48] Scriptonaut: find returns the element in the array, not a different value calculated from the element
[20:51:02] Scriptonaut: ya reduce was something I was thinking of
[20:51:51] Scriptonaut: I need the calculation in order to determine if it satisfies the condition, which is an expensive database lookup, I don't want to have to do that calculation twice. I think I'm just going to do an each loop and do an explicit return
[20:51:57] Scriptonaut: was just looking for a more 'ruby way' of doing it
[20:52:12] Scriptonaut: I'll checkout reduce
[20:52:20] Scriptonaut: haven't used that in a while
[20:53:34] Scriptonaut: selecting then mapping would incur a penalty because then the alg would become 2n rather than n (O)
[20:54:31] Scriptonaut: Eiam: because I'm looping over an array of object, then doing a db lookup for each one, then determining if the lookup yielded a sufficient result. If it did, then I need to return that result
[20:54:45] Scriptonaut: so I would have to calculate the result a second time once I returned teh element
[20:55:37] Scriptonaut: the lookup api can't take more than one param at a time
[20:55:49] Scriptonaut: so I can't do like Datasets::ICD10.snomedct_map([list, of, codes])
[20:55:59] Scriptonaut: I have to do it one by one
[20:56:19] Scriptonaut: lol, it's postgres, but the module was written that way
[21:15:17] Scriptonaut: ya, true, that's a decent solution, though I'd have to tack a .first on the end of it
[21:24:39] Scriptonaut: that wouldn't be a find_map would it?
[21:24:41] Scriptonaut: since each returns the whole list
[21:26:18] Scriptonaut: havenwood: that would return nil
[21:26:20] Scriptonaut: the thing you wrote
[21:26:31] Scriptonaut: oh n evermind
[21:26:36] Scriptonaut: I had no idea each worked that way
[21:26:47] Scriptonaut: I thought each always returned the original array
[21:26:52] Scriptonaut: unless the block specifies otherwise
[21:27:08] Scriptonaut: I didn't know you could pass an argument to break, that's awesome
[21:27:49] Scriptonaut: I use break all the time, but I didn't know if you passed it a value it would break from the block and return that value
[21:27:57] Scriptonaut: Does next also take a value?
[21:29:13] Scriptonaut: that's literally exactly how I solved my problem lol
[21:29:15] Scriptonaut: what your code is now
[21:29:52] Scriptonaut:
[21:30:18] Scriptonaut: havenwood: do you contribute to ruby?
[21:30:26] Scriptonaut: you were saying "we" when talking about removing features like that
[21:36:51] Scriptonaut: havenwood: nice. You mixed up the dx_code.code and dx_code.code_type in the else statement, but I like that idea better than mine (having an assignment operation inside a conditional)
[21:36:55] Scriptonaut: and ya, I shoulda used .any?


[20:25:01] Scriptonaut: has joined #ruby
[20:44:58] Scriptonaut: hey guys, I'm working on a really old project that uses activerecord 2, I'm having an issue with connections to the database persisting after I've ran the query, and returned from the method. Here is a basic rundown of what is happening:
[20:45:42] Scriptonaut: this ends up meaning that when I iterate a few hundred time, it ends up maxing out my max connection pool within a few seconds
[20:46:35] Scriptonaut: each time I call the method that runs this query, I return an array of the results (not an activerecord relation), yet the connection stays open
[20:49:00] Scriptonaut: oh, ya it is, but isn't Sequel an activerecord wrapper?
[20:49:24] Scriptonaut: ah, ok. I guess this is a sequel problem
[20:49:34] Scriptonaut: or is it behaving as intended?
[20:52:34] Scriptonaut: havenwood: thanks


[02:53:25] Scriptonaut: has left #ruby: ()


[00:01:14] Scriptonaut: hey all, I need help from some of you old ruby devs. I am working on an ancient ruby app, in 1.8.7. There is some kind of change that happened to strings in 1.9.3. I am using a library that was built for 2.4 or something relatively new, but when I run the code with the 1.8.7 interpreter, I get an encoding exception, specifically this: 'Exception encountered: undefined method `encoding' for "INFO VER RUBY
[00:01:20] Scriptonaut: 1.0.104b":String'
[00:01:37] Scriptonaut: could someone help me understand the encoding exceptions that happen from running this code through a 1.8.7 interpreter?
[00:01:58] Scriptonaut: this is the line that causes the exception: send_command "INFO VER RUBY #{@@VERSION}.#{@@BUILD}"
[00:02:48] Scriptonaut: here is the send_command method:
[00:06:59] Scriptonaut: oh, it's because I'm calling if !command.encoding.ascii_compatible?
[00:07:20] Scriptonaut: I wonder if I can get rid of that check
[00:16:15] Scriptonaut: ya, I'm confused by this code, I'm not sure why encoding should matter at all. It seems to be using a string with class variables interpolated in it. Class variables that don't change, so it's essentially a string literal. Why would they need to check the encoding? Oh well, thanks for pointing me in the right direction
[00:22:05] Scriptonaut: sweet it's working now, thanks
[00:23:34] Scriptonaut: I can't even put into words how messed up this app is
[00:23:41] Scriptonaut: you would all die inside if you saw it
[00:24:50] Scriptonaut: it's like the original dev gutted ruby on rails 2.0 (or possibly even older), and pulled those libraries into a few directories in the project. Then the backend server is handled by asp (not .NET, legacy asp), by sending the requests to a VM running windows 95
[00:25:07] Scriptonaut: also there is Java and PHP on the backend
[00:25:27] Scriptonaut: no idea how it works, it has two databases, a really nice postgresql db, and a microsoft SQL db (running on that windows 95 VM)
[00:25:42] Scriptonaut: ya, getting paid pretty well, otherwise I would have *not* agreed to this
[00:28:55] Scriptonaut: why are you calling gsub twice on it mroutis_
[00:29:52] Scriptonaut: oh, that's more complicated, I'm not sure
[00:30:26] Scriptonaut: I mean I'm sure it can be way worse, apparently there is *a lot* of COBOL code out there
[00:30:33] Scriptonaut: it used to be the number one business language
[00:30:55] Scriptonaut: COBOL programmers are needed to maintain the gigantic legacy codebases, and a lot of them start at 1/4 million $ a year apparently
[00:37:14] Scriptonaut: instead of using the first gsub I would probably just use a regexp
[00:37:21] Scriptonaut: and then based on the match data do something
[00:37:23] Scriptonaut: to make it a bit more clear
[00:37:29] Scriptonaut: the first gsub isn't really doing much
[00:38:18] Scriptonaut: the first gsub is more about detecting the patter
[00:38:27] Scriptonaut: then it passes it so the second gsub
[00:38:33] Scriptonaut: and the actual replacement happens there
[00:38:45] Scriptonaut: but he hardcoded those 'A' in there
[00:38:53] Scriptonaut: if he needs to do that for any character, it will get more tricky
[00:39:00] Scriptonaut: because that gsub block only takes the outermost match
[00:41:55] Scriptonaut: I figured out a way to do it
[00:41:57] Scriptonaut: not sure if better
[00:42:00] Scriptonaut: but it will work on any letter
[00:42:39] Scriptonaut: &>> 'A..A..'.gsub(/(\w)(\.+)(\w)/) { Regexp.last_match[0].gsub('.', Regexp.last_match[1]) }
[00:42:45] Scriptonaut: &>> 'B..B..'.gsub(/(\w)(\.+)(\w)/) { Regexp.last_match[0].gsub('.', Regexp.last_match[1]) }
[00:42:52] Scriptonaut: oh wait my solution isn't complete
[00:42:57] Scriptonaut: &>> 'A..B..'.gsub(/(\w)(\.+)(\w)/) { Regexp.last_match[0].gsub('.', Regexp.last_match[1]) }
[00:44:40] Scriptonaut: ok I figured it out
[00:45:05] Scriptonaut: &>> 'A..A..'.gsub(/(\w)(\.+)(\w)/) { Regexp.last_match[1] == Regexp.last_match[3] ? Regexp.last_match[0].gsub('.', Regexp.last_match[1]) : Regexp.last_match[0] }
[00:45:22] Scriptonaut: I knew there was an easier way haha
[00:49:31] Scriptonaut: too bad there's no shorthand for Regexp.last_match[0]
[00:51:45] Scriptonaut: &>> 'A..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:51:49] Scriptonaut: &>> 'Z..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:52:00] Scriptonaut: &>> 'Z..Z..A..A..'.gsub(/(\w)(\.+)(\w)/) { $~[1] == $~[3] ? $~[0].gsub('.', $~[1]) : $~[0] }
[00:52:07] Scriptonaut: thanks al2o3-cr
[00:52:32] Scriptonaut: the regexp stuff?
[00:52:44] Scriptonaut: no I just typed it in my console, but it is running in 1.8.7
[00:52:53] Scriptonaut: it was pretty gross to begin with
[00:52:58] Scriptonaut: I would probably just write a method for this
[00:53:24] Scriptonaut: yours isn't the actual solution
[00:53:26] Scriptonaut: it only works with A
[00:53:37] Scriptonaut: it has to work with any character


[23:59:31] Scriptonaut: has joined #ruby


[20:31:24] Scriptonaut: has left #RubyOnRails: ()


[23:00:50] Scriptonaut: has joined #RubyOnRails


[22:44:13] Scriptonaut: has joined #RubyOnRails
[22:45:20] Scriptonaut: hey all, I haven't written view tests in a long time (rspec). I just tried writing a few, and it causes an error because the instance vars are ending up nil. Those vars are set from an api request (from the server to a 3rd party). Does rails 5 or rspec disable remote requests like that?
[22:45:39] Scriptonaut: the page renders fine in the browser, complete with the data I fetch from that api call
[22:45:58] Scriptonaut: I don't have webmock or anything like that so I'm kind of puzzled why it's doing that
[22:59:14] Scriptonaut: oh I'm an idiot, I forgot that view specs don't touch the controller
[22:59:24] Scriptonaut: nevermind about that question


[06:18:53] Scriptonaut: has left #ruby: ()


[00:17:57] Scriptonaut: has joined #ruby
[00:18:16] Scriptonaut: hey all, I was curious, are there any good terminal interface libraries other than ncurses?
[00:18:43] Scriptonaut: I have always found ncurses to be pretty unintuitive, and figured by now there must be some other good quailty gems for writing terminal applications


[20:23:49] Scriptonaut: has joined #ruby
[20:24:44] Scriptonaut: hey, I'm wondering which is more conventional, passing a file object or a filename to a method (initializer)
[20:25:02] Scriptonaut: should I open the file then pass the file object as an argument? Or just pass the absolute path? (that's what I'm doing right now)
[20:25:17] Scriptonaut: it will only be opened once during the whole run of the program
[22:44:07] Scriptonaut: I actually hated the "class" thing they added to es6
[22:44:17] Scriptonaut: it's just hiding how javascript actually works, it's not a classical OOP language
[22:44:33] Scriptonaut: I like the prototypal inheritance model
[22:44:43] Scriptonaut: a lot of people just can't seem to wrap their head around it so I get why they did it
[22:45:50] Scriptonaut: also I'm surprised you think ruby is cryptic, it reads more like english to me than any other language
[22:46:02] Scriptonaut: and it was designed with that in mind
[22:46:25] Scriptonaut: symbols? Like :some_symbol or you mean like random operators?
[22:51:34] Scriptonaut: when I was first using rails I was annoyed how it so heavily relies on convention, but you start to appreciate it over time
[22:51:43] Scriptonaut: like in rails, there *is* a right way to do things
[22:51:45] Scriptonaut: and wrong ways
[22:51:57] Scriptonaut: whereas with other frameworks/languages it's like "does it work? Cool"
[22:53:07] Scriptonaut: I haven't worked in django since like 2011, is it still widely used?
[22:53:40] Scriptonaut: kinda like PHP
[22:54:16] Scriptonaut: I haven't worked in PHP since like 2009 and I have no desire to
[22:54:24] Scriptonaut: I always hated PHP
[22:54:30] Scriptonaut: I'm actually mostly sick with webdev
[22:54:36] Scriptonaut: though there is some really cool stuff nowadays
[22:55:45] Scriptonaut: in terms of getting a job, rails is still very common
[22:58:04] Scriptonaut: when I need to host shit really damn fast I use a ruby oneliner hehe
[22:58:33] Scriptonaut: ruby -run -e httpd . -p 9090
[23:44:25] Scriptonaut: has left #ruby: ()


[04:01:30] Scriptonaut: has joined #ruby
[04:02:54] Scriptonaut: hey, any of y'all do some amateur gamedev in ruby? I was thinking I wanted to make a little game/physics engine in ruby. I got one in es6 I was gonna port to ruby, but not sure what to use. I've heard of gosu, but it seems like gosu does a lot for you, and I want to implement pretty much everything myself (collision detection/resolution, asset loading, game state, sprites, etc)
[04:03:17] Scriptonaut: anyone know of a good library to use that will let me make a window, draw polygons
[04:13:08] Scriptonaut: RickHull: ya I just found a guide on getting started with gosu, and it actually doesn't have very much stuff (which is what I want)
[04:13:16] Scriptonaut: however, it has a huge userbase, and very few bugs from what I gather
[04:13:20] Scriptonaut: so it's basically the perfect platform
[04:13:47] Scriptonaut: all it has is a window with a main loop and callbacks (awesome), 2d graphics and text, sound samples/music, and keyboard and mouse input
[04:13:55] Scriptonaut: ya, I'm pretty stoked that it didn't take me very long to find something so promising
[05:12:29] Scriptonaut: has left #ruby: ()


[18:03:30] Scriptonaut: has joined #RubyOnRails
[18:03:58] Scriptonaut: hey y'all. I have a validation on my model with a custom error message. For some reason, it's forcing the message to be lowercase, except the very first character.
[18:04:01] Scriptonaut: I have :message => "Max. 20 characters Please use your Tracking ID (Starting With UA-)"
[18:04:10] Scriptonaut: but then the message that shows up is: Max. 20 characters please use your tracking id (starting with ua-)
[18:04:44] Scriptonaut: see how the P in Please, the T in Tracking, the ID, and the UA are all lowercase in the message when it shows up on the screen? Despite being uppercase when I set it on the model?
[18:04:50] Scriptonaut: anyone ever seen that before?
[18:05:53] Scriptonaut: cerulean: not that I'm aware of
[18:05:58] Scriptonaut: it's literally just a run of the mill validation
[18:06:13] Scriptonaut: here's the entire line
[18:06:14] Scriptonaut: validates :google_analytics_tracking_code, :length => { :maximum => 20, :message => "Max. 20 characters Please use your Tracking ID (Starting With UA-)" }
[18:06:40] Scriptonaut: and when I put more than 20 chars in the field, the error message is all in lowercase except the first char
[18:07:31] Scriptonaut: this is on Rails 5.0.2 if that matters
[18:07:55] Scriptonaut: cerulean: that's what I thought, but I checked the source, and checked the message, it's downcased on the backend
[18:09:33] Scriptonaut: oh weird, when I do: @design.errors.full_messages, I get ["Google analytics tracking code Max. 20 characters Please use your Tracking ID (Starting With UA-)"]
[18:11:08] Scriptonaut: ok, so 5.1.1 is where I should be at?
[18:11:11] Scriptonaut: I'll put that on the list of todos
[18:11:26] Scriptonaut: I figured it out
[18:11:28] Scriptonaut: it's the capitalize method
[18:11:38] Scriptonaut: "Google analytics tracking code Max. 20 characters Please use your Tracking ID (Starting With UA-)".capitalize downcases everything except the first char
[18:11:45] Scriptonaut: that doesn't seem like the intended behavior does it?
[18:16:08] Scriptonaut: cerulean: ya it was my own code, false alarm
[18:16:20] Scriptonaut: but I am surprised that String#capitalize downcases all the other chars ?
[18:16:34] Scriptonaut: "blah BLAH BLAH".capitalize goes to "Blah blah blah"
[23:07:20] Scriptonaut: has left #RubyOnRails: ()


[18:32:50] Scriptonaut: has joined #RubyOnRails
[18:33:01] Scriptonaut: does anyone know how I can generate a migration that is the opposite of an existing migration?
[18:33:24] Scriptonaut: I have a migration that changes a column type from string to text. It was run in production like a month ago, but now I want to undo it.
[18:33:28] Scriptonaut: so I need to make a new migration
[18:33:43] Scriptonaut: is there a handy command that will just make a new migration, that just swaps the "up" and the "down" of my existing migration?
[18:35:19] Scriptonaut: oh, this is a good idea:
[19:05:38] Scriptonaut: fryguy: activeyaml?
[19:05:44] Scriptonaut: not sure if that's what you mean
[19:07:11] Scriptonaut: oh, active_yaml is part of active_hash
[19:16:06] Scriptonaut: has left #RubyOnRails: ()


[01:59:40] Scriptonaut: has left #RubyOnRails: ()


[23:28:31] Scriptonaut: has joined #RubyOnRails
[23:29:36] Scriptonaut: hey y'all. I have a rails 5 project, and for some reason, seemingly out of nowhere, I can no longer load my fixture data. When I do: rake db:fixtures:load, it seems to work, but then when I fire up a console, it's completely empty. None of the records are in there. Anyone have an idea of why this would be?
[23:29:41] Scriptonaut: the project used to be rails 4 by the way
[23:29:53] Scriptonaut: I also tried `rails db:fixtures:load`, no luck


[17:28:30] Scriptonaut: has joined #RubyOnRails
[17:29:28] Scriptonaut: Hey, I'm having a really weird problem with rspec controller specs. Basically, in a single test (not file, a single 'it' block), I have doing a post request twice, to the same controller, but with different params.
[17:29:40] Scriptonaut: for some reason, when I do the second post, it is using the params of the first post
[17:29:50] Scriptonaut: it doesn't do this if I send it to a different controller
[17:30:12] Scriptonaut: it's like it's caching my params if I send a post request twice, to the same controller, despite having explicitly different params
[17:50:11] Scriptonaut: dminuoso: ok I created a super simple example to outline the problem, I confirmed that it is an issue
[17:50:17] Scriptonaut: one sec I will gist
[17:50:39] Scriptonaut: dminuoso:
[17:52:22] Scriptonaut: ok dminuoso (and anyone else), I updated the gist by adding the output of rspec failure
[17:52:58] Scriptonaut: dminuoso: that completely defeats the purpose of my tset then
[17:53:11] Scriptonaut: the database is rolledback between each test
[17:54:26] Scriptonaut: we're testing an external API, we don't ever actually hit that API in the UI
[17:54:37] Scriptonaut: integration test is impossible atm
[17:55:03] Scriptonaut: that is a basic example I made
[17:55:36] Scriptonaut: ok, anyways, doing multiple http requests within a single test is totally normal
[17:55:43] Scriptonaut: it's in the documentation even
[17:55:55] Scriptonaut: this is what I'm asking
[17:55:59] Scriptonaut: where are those values memoized?
[17:56:04] Scriptonaut: I cleared cache, didn't fix
[17:58:44] Scriptonaut: ok, you know what I mean. I'm saying, in rspec controller tests doing multiple "requests", or whatever they actually are under the hood, is standard
[17:59:14] Scriptonaut: it's usually not a problem because people don't do the same type of request to the same controller and the same action all within the same test
[17:59:20] Scriptonaut: don't tend to **
[17:59:42] Scriptonaut: this is the first time in over 50,000 lines of rspec that this has ever come up
[18:10:59] Scriptonaut:
[18:12:35] Scriptonaut: I just meant doing multiple requests in a single test. Why is that not normal specifically for controller tests?
[18:12:52] Scriptonaut: what do people do instead of controller tests?
[18:16:05] Scriptonaut: Ah, in that case, I will make an integration test that uses an explicit request like that
[18:23:29] Scriptonaut: has left #RubyOnRails: ()


[00:12:47] Scriptonaut: has left #RubyOnRails: ()
[19:56:02] Scriptonaut: has joined #RubyOnRails
[21:01:54] Scriptonaut: has left #RubyOnRails: ()


[22:50:41] Scriptonaut: can anyone tell me why that's happening?
[22:51:05] Scriptonaut: ultimately, what I want, is to find all the people who have email details with a value that is the same as another email detail belonging to a person on teh same account
[22:51:22] Scriptonaut: I'm trying to find all the people with duplicate emails (within an account)
[23:38:04] Scriptonaut: desnudopenguino: I figured it out, to fix it, I just had to order by "details.value", because I guess ActiveRecord inserts an auto order_by ""