Mattx

Activity Graph

Page 1 of 8 | Next »

2017-08-01

[19:14:01] Mattx: has joined #ruby
[19:14:21] Mattx: Hey people! I have this string: "\141", and I want to convert it to "a". How is it done?
[19:14:52] Mattx: (actually the string may be in hex, oct or whatever. I don't know beforehand)
[19:15:23] Mattx: sorry. yes, I have \\141
[19:16:05] Mattx: or "\\x6" in other cases. or things like that
[19:16:27] Mattx: Papierkorb, that's right. I want to get the string in plain ascii
[19:17:33] Mattx: no problem about that
[19:19:06] Mattx: that's exactly what I was doing, but isn't there a better way than checking if the match starts with \x, \o, \ or whatever?
[19:19:30] Mattx: sure, one sec
[19:20:13] Mattx: it's pretty simple at the moment: content.gsub! /(\\.\d+)/ do ...$1... end
[19:20:51] Mattx: that $1 contains the character, I thought there may be something like .to_s(base) or something, but the other way around
[19:21:58] Mattx: alright, I was trying to avoid that but if there's no other way...
[19:22:46] Mattx: nothing or \o for base 8, \x for base 16, \b for base 2
[19:22:51] Mattx: is there anything else out there?
[19:23:49] Mattx: no? I think I used \b in the past, maybe on another language (?)
[19:24:01] Mattx: thanks Papierkorb
[19:28:01] Mattx: "foobar".gsub! /\\(x?)([0-9a-f]+)/i do $1 == "x" ? $2.to_i(16).chr : $2.to_i(8).chr end
[19:28:04] Mattx: that would do it
[19:33:35] Mattx: didn't know about \h, nice
[21:22:37] Mattx: Quit: Leaving

2016-07-31

[00:56:06] Mattx: has joined #ruby
[03:39:22] Mattx: do you use the gem config (from rails I believe)?
[03:39:30] Mattx: I'm getting a strange "uninitialized constant Settings"
[03:39:45] Mattx: Shouldn't config define Settings?
[03:41:10] Mattx: has joined #RubyOnRails
[03:41:24] Mattx: Anyone using the config gem (part of rails) standalone?
[03:41:37] Mattx: I'm getting `<top (required)>': uninitialized constant Settings (NameError)
[03:42:22] Mattx: ah, never mind, I have to load a settings file with Config before using Settings
[03:42:28] Mattx: never mind
[05:03:47] Mattx: Ping timeout: 260 seconds
[08:44:22] Mattx: has joined #ruby
[08:44:22] Mattx: has joined #RubyOnRails
[08:56:35] Mattx: Quit: Leaving

2016-07-30

[01:13:12] Mattx: has joined #ruby
[01:14:18] Mattx: How do I run jruby once it's installed through rvm if I don't want to make it the default ruby interpreter? I just want to execute a file every now and then
[01:14:58] Mattx: I can do "rvm jruby" and then "ruby file.rb". but then I have to always run "rvm use ruby"
[01:15:34] Mattx: and actually, I need to use both at the same time sometimes
[03:46:51] Mattx: Quit: Leaving

2016-07-29

[14:52:04] Mattx: has joined #ruby
[14:52:41] Mattx: Hey, I have a function defined in the global (Object?) scope. and I want to know if it's callable from the inside of a method in a class. The name of the function is in a variable myfunc
[14:53:05] Mattx: So for instance I tried methods.include?(myfunc) and respond_to?(myfunc), but both return false
[14:53:54] Mattx: ok, main, I just didn't know how it was called
[14:55:00] Mattx: I don't think so, if I try to run the function it works
[14:55:23] Mattx: I'm trying to do this: send myfunc, "foo", "bar" if respond_to? myfunc
[14:55:40] Mattx: my point is, "send myfunct foo bar" works, it's callable
[14:55:46] Mattx: sure, one sec
[14:58:41] Mattx: dminuoso, what's the default class/module when you don't specify one? is it Kernel?
[14:59:24] Mattx: I believe my function is defined there, and I want to check before I run it from a variable (myfunc = :function_name)
[14:59:36] Mattx: (I'm writing an example anyway, just a moment)
[15:00:25] Mattx: https://gist.github.com/2cf88b033902b59f5c2514e0f0a68070
[15:00:45] Mattx: it works as I expected, I should be doing something wrong in the real code. I'll double check
[15:01:49] Mattx: dminuoso, yeah, I know what you mean. I wanted to make it clear the "function" doesn't beloing to a class I have defined. it was "global" (belonging to main or whatever it's called)
[15:02:06] Mattx: ljarvis, I expected it to print 6, which is what it does
[15:02:14] Mattx: so the bug is somewhere else. I'm checking
[15:02:35] Mattx: it does, believe me :P
[15:03:19] Mattx: it does in pry
[15:03:29] Mattx: does it make any differenece?
[15:04:07] Mattx: alright, that's the problem them. in pry it works as I thought it would, but the real code is obviously run in ruby (not pry)
[15:04:26] Mattx: so what's the explanation?
[15:06:09] Mattx: got it, it's Object
[15:07:28] Mattx: in the real code when I run method(:descriptive) I get #<Method: Repository(Object)#descriptive>
[15:07:36] Mattx: then I run method(:descriptive).owner and I get Object
[15:07:44] Mattx: and respond_to? :descriptive returns false
[16:26:46] Mattx: Quit: Leaving

2016-07-23

[14:18:31] Mattx: has joined #ruby
[14:19:15] Mattx: Hey. I'm installing the gem weka, but I get "Could not find a valid gem 'weka' (>= 0) in any repository"
[14:19:29] Mattx: however, I have weka (0.3.0 java) on my repo
[14:19:43] Mattx: that's what it says if I run gem search weka
[14:21:24] Mattx: toretore, is that gem only available for jruby?
[14:22:30] Mattx: is there a way to use it in ruby?
[14:25:12] Mattx: Hmn. Look, I need to use a program (weka) from ruby. there's an official lib
[14:25:25] Mattx: I guess the best I can do is use it through command line in ruby and parse its output?
[14:26:05] Mattx: I don't think it's a good idea to run my whole code in jruby just because of that dependency
[14:26:27] Mattx: that's not a problem
[14:26:41] Mattx: but I'm running my code in ruby not jruby
[14:48:15] Mattx: Read error: Connection reset by peer
[14:48:36] Mattx: has joined #ruby
[17:54:32] Mattx: Read error: Connection reset by peer
[18:55:18] Mattx: Read error: Connection reset by peer
[18:55:57] Mattx: has joined #ruby
[19:09:08] Mattx: Ping timeout: 265 seconds

2016-07-10

[00:05:34] Mattx: apeiros, it's actually a quick socket server I'm writing
[00:05:50] Mattx: you can connect to it and run different services
[00:06:27] Mattx: and those services are related but the logic is quite different, they do different things using the same data
[00:08:09] Mattx: apeiros, how would you divide that?
[00:26:10] Mattx: Quit: Leaving

2016-07-09

[23:21:46] Mattx: has joined #ruby
[23:22:48] Mattx: Hey people! Any idea about this? I have a class, and it's divided into multiple files because some methods have nothing to do with some others. so the thing is that I need of a certain instance @variable, but I'm not sure how to initialize it from outside the method /initialize/
[23:23:59] Mattx: if I put @myvar = [] in file2.rb (file1.rb is where I have the method initialize), then I get @myvar is not initialized because that initialization wasn't run inside an instance
[23:24:07] Mattx: Is it clear or should I write an example?
[23:26:58] Mattx: https://gist.github.com/anonymous/3679e2abf0b4724225cc38126be5a7d2
[23:27:03] Mattx: here is an example
[23:27:53] Mattx: I forgot the extension so the code is colored, check this instead: https://gist.github.com/anonymous/81c6dd7b662bc9666262848fd3206ed7
[23:35:11] Mattx: maybe I should be using modules and multiple initialize? I don't know...

2016-07-07

[01:46:14] Mattx: has joined #ruby
[04:45:05] Mattx: Read error: Connection reset by peer

2016-07-06

[19:48:39] Mattx: has joined #ruby
[22:21:14] Mattx: Ping timeout: 250 seconds

2016-07-03

[05:19:23] Mattx: has joined #ruby
[05:19:25] Mattx: Hey people!
[05:19:53] Mattx: I want to combine a hash like this {:a=>[5, 10, 15], :b=>["open", "close"]}
[05:20:04] Mattx: and get something like this [{:a=>5, :b=>"open"}, {:a=>5, :b=>"close"}, {:a=>10, :b=>"open"}, {:a=>10, :b=>"close"}, {:a=>15, :b=>"open"}, {:a=>15, :b=>"close"}]
[05:20:55] Mattx: Is there any built in function for that? I'm looking for an elegant and quick solution, since you know the output could be huge depending on the input
[05:22:09] Mattx: just in case, I don't know the length of the input, there could be more keys or the arrays could be larger
[05:22:41] Mattx: yep, everything is of variable length
[05:25:24] Mattx: I'm thinking about doing it recursively
[05:31:46] Mattx: [4] pry(main)> [1,2,3].product [4,5,6]
[05:31:47] Mattx: => [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]]
[05:31:48] Mattx: that's cool!
[07:17:20] Mattx: Ping timeout: 258 seconds
[12:50:52] Mattx: has joined #ruby
[14:21:43] Mattx: Quit: Leaving

2016-06-21

[04:09:30] Mattx: Quit: Leaving

2016-06-20

[15:17:32] Mattx: has joined #ruby
[15:18:09] Mattx: Hey guys, any of you using MongoDB? I want to give it a try but I've found the documentation of the gem "mongo" is awful and in many cases outdated. Any idea?
[15:18:58] Mattx: for instance there's a method called #hint(hash) to query documents, but all the doc says is "Provides the query with an index hint to use."
[15:19:40] Mattx: Papierkorb, that's what I'm reading. check the example above. how are you supposed to use .hint?
[15:20:09] Mattx: or even #batch_size(integer), something way more useful
[15:20:15] Mattx: what's the default value? no idea...
[15:21:28] Mattx: well, my point is that it's not documented
[15:21:43] Mattx: using find() surely selects a default batch_size
[15:22:10] Mattx: or probably not, who knows :P
[20:14:15] Mattx: Disconnected by services

2016-06-11

[16:33:12] Mattx: has joined #ruby
[16:34:10] Mattx: Hey guys! I'm looking for a database that I can store in a file, so it's easy to setup. I'm particularly interested in schemaless databases
[16:34:15] Mattx: Is there anything like this?
[16:35:55] Mattx: jhass, interesting. Do you happen to know how fast it is?
[16:36:10] Mattx: I want to save and query around 1 million objects
[16:46:21] Mattx: it would be great to use sqlite as a schemaless database, for small/command line projects
[16:51:03] Mattx: something like UnQLite!
[23:27:05] Mattx: has left #ruby: ("Leaving")

2016-06-06

[16:13:24] Mattx: has joined #RubyOnRails
[16:13:35] Mattx: Hello! I'm getting this error: Cannot load `Rails.application.database_configuration`: undefined method `adapter' for nil:NilClass
[16:14:02] Mattx: Rails is configured to used Postgresql, and this code was working just fine a few days ago
[16:14:17] Mattx: what could it be? I'm not finding anything relevant on the internet
[16:20:01] Mattx: norc, https://gist.github.com/anonymous/73ed7ee0332b0c67551a0a59b5dbbd62
[16:23:50] Mattx: any idea?
[16:26:06] Mattx: lupine, it is of course, I've used this file for months. it's just now that it's throwing an error for whatever reason
[16:26:11] Mattx: but the syntax is ok
[16:28:36] Mattx: ok, one sec
[16:34:09] Mattx: Nope, that's not the problem. I was running bundle install just in case
[16:35:39] Mattx: Yes, I'm using git. I never used that command, let me check
[16:36:06] Mattx: I think nothing changed, I can't remember any relevant change
[16:42:23] Mattx: well, never mind. I'll create a new rails app and compare all files or use bisect for that. thanks guys
[16:48:37] Mattx: norc, I've never used git bisect, I'll give it a try. thanks
[17:41:38] Mattx: Quit: Leaving

2016-06-02

[17:07:59] Mattx: has joined #ruby
[17:08:09] Mattx: hey people!
[17:09:03] Mattx: I'm getting some weird resuls with this. I'm running whois from Ruby, and I'm trying to read the exitcode so that I know when it failed (sometimes the connection is reseted, the domain is malformed or whatever)
[17:09:32] Mattx: for instance, how do you get the exitcode of `whois foo.com` ?
[17:11:19] Mattx: I've tried with $?.exitstatus, which seems to work, but I think errors with that code while using system(), I'm double checking now
[17:11:42] Mattx: err, think I've seen *
[17:13:09] Mattx: ah, I know what happens
[17:13:21] Mattx: whois returns exit code 1 when the domain is invalid, or when the domain is not registered
[17:13:35] Mattx: for instance `whois oasnfosanf.com`; $?.exitstatus == 1
[17:16:30] Mattx: elomatreb, I'm trying to know when whois returns an error because there was a problem with the connection (I sometimes get "connection reset" or fgets problems), or because the domain is not registered
[20:06:25] Mattx: Quit: Leaving

2016-04-21

[03:39:38] Mattx: has joined #RubyOnRails
[03:40:00] Mattx: Hey guys. I want to respond with :json even if the format param is html. How do you do that?
[03:40:21] Mattx: I have tried this: format.html { render json: {...} }
[03:40:39] Mattx: but a header for html is sent instead, not json
[03:41:29] Mattx: Hey guys and gals!
[03:44:54] Mattx: because I have other formats, not only those two
[03:45:32] Mattx: I don't want to render html
[03:45:40] Mattx: it's for an API, it should default to json
[03:46:08] Mattx: that doesn't work either, if I don't set format.html and I don't specify the format in the url, it crashes
[03:46:12] Mattx: it says format unknown
[03:46:24] Mattx: how do I default to json?
[08:00:28] Mattx: Ping timeout: 252 seconds
[14:23:57] Mattx: has joined #RubyOnRails
[15:14:58] Mattx: Ping timeout: 252 seconds

2016-04-19

[16:26:22] Mattx: has joined #RubyOnRails
[16:26:25] Mattx: Hey guys!
[16:26:35] Mattx: I have this column in a model: t.text :keywords, null: false, array: true, default: []
[16:26:49] Mattx: so I expect it to be an empty array in case I don't specify otherwise
[16:27:03] Mattx: also, I don't have any validation over that column
[16:27:20] Mattx: but when I try to save an object with .keywords = nil
[16:27:37] Mattx: I get this error: ERROR: null value in column "keywords" violates not-null constraint
[16:27:52] Mattx: Why is that? How do I set a default value if not like this?
[16:32:55] Mattx: beingjohnm, nope, it says null: false, default: []
[16:33:06] Mattx: if I save it with nil, it should assume the default value
[16:33:11] Mattx: that's how it *should* work
[16:33:34] Mattx: I just noticed the problem is that empty arrays in postgres are '{}', that should be the default value I use, not []
[16:33:39] Mattx: I think that will solve the isse
[17:11:03] Mattx: Quit: Leaving

2016-04-17

[00:29:46] Mattx: Quit: Leaving

2016-04-16

[16:39:52] Mattx: has joined #ruby
[16:39:59] Mattx: Hey guys! Check this code: https://gist.github.com/0178dc758501bdfe238a36ab69b9d69b
[16:40:13] Mattx: Why is it unpredictable?
[16:40:36] Mattx: I want the second behavior, always
[16:44:34] Mattx: any idea?
[16:46:24] Mattx: has joined #RubyOnRails
[16:47:31] Mattx: it's always executing the code in the same order, why would the output change?
[16:48:35] Mattx: Guys, it's a little bit offtopic, but no one is reading in #ruby
[16:48:38] Mattx: Check this code: https://gist.github.com/0178dc758501bdfe238a36ab69b9d69b
[16:48:46] Mattx: it's always executing the code in the same order, why would the output change?
[16:54:35] Mattx: has left #ruby: ("Leaving")
[16:54:39] Mattx: has joined #ruby
[17:18:00] Mattx: Depili, it is. Why do you think it's not?
[17:18:18] Mattx: The sleeps are causing the code to run in the same order
[17:18:30] Mattx: or so it should
[17:22:31] Mattx: Hey, I repeat my problem just in case
[17:22:40] Mattx: Check this code: https://gist.github.com/0178dc758501bdfe238a36ab69b9d69b
[17:22:59] Mattx: It's always executing the code in the same order (due to the sleeps), why would the output change then?
[17:47:01] Mattx: No one is reading :(

2016-04-02

[15:21:33] Mattx: has joined #RubyOnRails
[15:22:21] Mattx: How do you set "with timezone" for all datetime columns in a migration?
[15:23:01] Mattx: (including but not limited to created_at and updated_on)
[16:31:57] Mattx: Quit: Leaving

2016-04-01

[18:52:00] Mattx: has joined #RubyOnRails
[19:10:06] Mattx: Quit: Leaving

2016-03-31

[00:11:37] Mattx: Radar, would you mind checking this? https://github.com/rails/rails/issues/23550
[00:11:43] Mattx: I just sent a comment
[00:13:50] Mattx: it's not that hard. I'm just trying to match namespaced controllers without listing them all on the route files.
[00:14:14] Mattx: in the example, I'm trying to match "domains/analyze#handle"
[00:14:26] Mattx: I mean, that's the code I want to execute
[00:14:38] Mattx: the url is /domains/analyze
[00:15:32] Mattx: yep, the file is app/controllers/domains/analyze_controller.rb
[00:15:45] Mattx: class Domains::AnalyzeController < ApiController
[00:16:25] Mattx: only one action at the moment, which is "handle"
[00:18:02] Mattx: Radar, I know I can do that, but I don't want to list all controllers
[00:19:30] Mattx: the problem is that multiple people is in charge of the different APIs provided, so I'm developing an endpoint to put them all together, and I don't want our developers having to edit the route file to setup one
[00:19:40] Mattx: Radar, Arcaire: why ^
[00:20:43] Mattx: What do you think about the doc? maybe it's not implemented, but it's weird that on the debug input works...
[00:21:27] Mattx: would you list all apis?
[00:24:13] Mattx: btw, I'm doing all this because I haven't found a way to integrate all APIs while keeping them independent from one another
[00:24:40] Mattx: maybe rails engines is the closest, but still a lot of overhead
[00:25:11] Mattx: yep, keeping everything into independent folders for instance (namespacing)
[00:25:26] Mattx: controllers, models, migrations, etc
[00:25:36] Mattx: it's painful, I haven't found anything better though :(
[00:26:07] Mattx: Arcaire, no, because I'm using the same models to keep track of apis keys, quota limits, etc
[00:26:19] Mattx: the same tables I meant
[00:26:55] Mattx: Arcaire, I seriously haven't found any good way. what's your suggestion?
[00:28:36] Mattx: I have something like 10 apis right now: /domains/analyze /apps/add /foo/bar etc
[00:29:02] Mattx: I'm creating a single endpoint for all of them, so we keep track of users keys, quotas, etc in one place
[00:29:32] Mattx: again: I seriously haven't found any good way. what's your suggestion?
[00:31:21] Mattx: so I repeat the tracking method, tables to keep users, and everything else in all 10 rails apps (one for each api)?
[00:31:58] Mattx: Arcaire, I don't think that's a good idea either, honestly
[03:28:40] Mattx: Ping timeout: 252 seconds
[11:35:56] Mattx: has joined #RubyOnRails
[20:25:54] Mattx: Remote host closed the connection

2016-03-30

[23:36:45] Mattx: because I assume the code is the same