Feb 162012
 

<canton7> elitheeli, they’re neck and neck, with yours at 3.29 for 10000 cycles, and mine at 3.45. However, filter doesn’t appear to be a method, and yours accepts e.g. history.10n (not sure if that makes any differenc<visof> how can i get the bigger number from [1,2,3,4] ? <visof> using select or anything similar <elitheeli> > [1,2,3].max <elitheeli> 3 <visof> using select? <elitheeli> Use max. <elitheeli> Select is for filtering <visof> elitheeli, can i use it to filter the biggest number <elitheeli> What do you mean? What do you want to do with the biggest number? <visof> elitheeli, just curious <elitheeli> With great difficulty you could <colossus> hey all, quick regex question: need to find both “{nl:” AND “}” in this quote: “{nl:StuffupperAndLowercasew09}”. I have nailed the first part but how do you omit the entire middle and grab the final “}”? <elitheeli> and regexp with (.)$ <elitheeli> or better yet (})z <finsdelosmundos> is there anything I can do with the lines entered into the IRB? Like, can call the same thing I wrote in line 200-212 without ahving to press “up” back a couple thousands times? <elitheeli> finsdelosmundos: if you know ahead of time, assign what you did to a proc <colossus> elitheeli: do I need to create another delete method to get rid of the rest or can I string them together. at the moment I have (A(nl:{)) <finsdelosmundos> elitheeli you know thats not what i was asking <elitheeli> finsdelosmundos: you can also do “eval Readline::HISTORY[104]” <elitheeli> colossus: /A({nl:).*({)z/ <elitheeli> then captures 1 and 2 will have what you want <colossus> elitheeli: hmm now I see, thank you <elitheeli> finsdelosmundos: here’s a transcript: <elitheeli> ruby-1.9.3-p0 :003 > 4 + 5 # => 9 <elitheeli> ruby-1.9.3-p0 :004 > eval Readline::HISTORY[-2] # => 9 <elitheeli> Do *not* do “veal Readline::HISTORY[-1]” — it’ll blow up your Ruby <elitheeli> as it tries to eval itself which evals itself, which … <visof> elitheeli, what i want to do is : ["foo.1", "foo.2", "foo.4"] want to get 4 is the biggest number after . <finsdelosmundos> what about say 3 lines together * canton7 was wondering what was so deadly about the ‘veal’ function for a minute there… <visof> split each string then convert second part to_i then compare, but i guess ruby will do that in more easier way <elitheeli> visof: .max can take a block <canton7> visof, ["foo.1", "foo.2", "foo.4"].max_by{ |f| f[/d+/] } is one quick and dirty way. You can do more complex regex if ther emight be more variation in your filenames <elitheeli> canton7: do #max and #max_by differ? <canton7> elitheeli, max takes two parameters and you have to compare them yourself. max_by just lets you just return an object, and ruby will do the comparison for you <canton7> in fact, in this case ["foo.1", "foo.2", "foo.4"].max will do what you want, visof :P <canton7> elitheeli, for example here, you can use ["foo.1", "foo.2", "foo.4"].max{ |a,b| a[/d+/] b[/d+/] } <elitheeli> canton7: yeah, max_by is definitely better <elitheeli> and you’re right about just max working <Cliff_> Does anyone here use Sahi for Ruby? <finsdelosmundos> elitheeli can i use eval Readline to read a block of lines? liek say, 3-12? <elitheeli> finsdelosmundos: it’s just a glorified array <elitheeli> just call to_a on it first to use a range <elitheeli> try this: Readline::HISTORY.to_a[-4..-2] <elitheeli> then just map eval them <elitheeli> Readline::HISTORY.to_a[-x..-y].map {|x| eval x} <finsdelosmundos> oh nice <visof> what is the best way to create a file ? <visof> File.open(“new_file”, ‘w’) ? <elitheeli> visof: and do what with it? <visof> elitheeli, just create new file <visof> is that enough ? <elitheeli> `touch #{new_file}` <csherin> visof: FileUtils#touch <elitheeli> csherin’s method is probably better <elitheeli> mine is lazier <csherin> elitheeli, visiof: as far as i understand with FileUtils you do not have to worry about platform oddities and you’re not spawning a new sub process per command <elitheeli> Definitely <csherin> internally FileUtils#touch uses File#utime and File#open in append mode <csherin> http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-touch <colossus> ok why in this blockstr.gsub(/([A-Z][a-z]+[A-Z][A-Za-z0-9]+)/) {|page| %Q{#{/[^A({nl:)].*[^(})z]/.match(page)}}} assuming str = {nl:RecordNotFound} gives me a result of “{nl:RecordNotFound}” and /[^A({nl<colossus> yes I understand it is matchdata, but a simple to_s call solves that <KristianDK> Does anyone know what Rubys equivalent of "python setup.py develop" is? I want to install a package into my rvm environment, but i want the package to read directly from the source, in case i change it. <zykes-> how can i find out which part of a rails app is requiring a gem when i get "Could not find rubyzip-0.9.6.1 in any of the sources" during a bundle command ? ChiliProject btw <shevy> KristianDK not sure what that does. ruby projects used to have a setup.rb file <KristianDK> shevy, i just want to install a bundle, in a way where its not copied somwhere else, but used from its actual path, if you know what I mean <KristianDK> e.g. if you have 2 packages, where one depends on the other and you dont want to install new packages for every bugfix in the main package <colossus> stuff <colossus> exit <colossus> another regex question: why do I get different results from this block str.gsub(/([A-Z][a-z]+[A-Z][A-Za-z0-9]+)/) {|page| /[^A({nl:)].*[^(})z]/.match(page)} and this /[^A({nl:)].*[^(})z]/.match(str) if<_obiJuan> zykes-: check out gemfile.lock <zykes-> what’s that file ? <zykes-> _obiJuan: ? <Jarred> How do I have rake tasks within rake tasks (e.g. ‘rake sec:load:disk’) <Jarred> ? <burgestrand> Jarred: it’s just a name <burgestrand> Jarred: task ‘sec:load:disk’ <zykes-> anyone that got a clue on why i fail on rubyzip with gemfile.lock ? <Jarred> oh <burgestrand> Jarred: you can also use a namespace block to scope tasks within that block, namespace(‘sec’) { task ‘load:disk’ } <Jarred> so I can pass a string instead of a symbol? <Jarred> (to task) <burgestrand> Jarred: sure <zykes-> what’s the use of gemfile.lock ? <zykes-> _obiJuan: got a hint or ? <Jarred> I’m getting an unexpected ‘end’ on line 10. I don’t see any reason for it. https://gist.github.com/122a82f82f2366699016. What needs an end that doesn’t have one? <examancer> Jarred: i think interpretter thinks a coupel of your blocks are part of your range definition. you should surround your ranges in parens () <examancer> (1..4).each instead of 1..4.each <Jarred> done <examancer> that fix it? <Jarred> now its complaining about line 12 <examancer> did you do it for both ranges? <Jarred> Yeah <Jarred> (at the second one) <burgestrand> Jarred: forgot do for both tasks <Jarred> ohhh <examancer> yes, missing do <Jarred> and namespace? <burgestrand> Jarred: and your namespace <burgestrand> :p <Jarred> Rails’ rake tasks don’t require the models? <burgestrand> Jarred: you need to require the environment for that <Jarred> What’s the method for that? <burgestrand> Jarred: you can add it as a prereq to your task; task ‘my_task’ => :environment do <examancer> task :some_task_name => :environment do <examancer> that makes :some_task_name dependent on the :environment task <Jarred> hmmm <Jarred> I updated the gist. How do I set it to the environment when the task name is a string? <Jarred> (https://gist.github.com/122a82f82f2366699016) <examancer> funny that you used a private gist but posted it in a public channel :-) <Jarred> Can I just do :load[:disk]? <Jarred> examancer: It’s instinctual <Jarred> nah, that didn’t work <examancer> Jarred: there probably isn’t a :development task… that should literally be :environment <Jarred> ohhhh <burgestrand> Jarred: also, I believe task names are converted to strings, you could rely on ‘environment’ as well as :environment; not entirely sure though <examancer> i don’t know if you can name a task “load:disk”… i know you can make a “load” namespace with a “disk” task in it… maybe it works both ways <Jarred> It’s working <Jarred> Thanks for your help., <examancer> cool :-) <burgestrand> examancer: you can, both task and namespace accept a string, you can also make a symbol a :”namepaced:symbol” :) <examancer> nice <burgestrand> which can make for some very strange symbols <burgestrand> :”" * gen0cide_ loves ruby <superman_ffm> Hi, how can I sum values in a Hash e.g. h = { a: 1, b: 2, c: 3, d: 4} <burgestrand> superman_ffm: { a: 1, b: 2, c: 3, d: 4}.reduce(0) { |m, (k, v)| m + v } <seanstickle> superman_ffm: h.values.reduce(&:+) <burgestrand> Ah yes, reduce allows you to specify the operator without a block too though <burgestrand> { a: 1, b: 2, c: 3, d: 4}.values.reduce(:+) <seanstickle> Nice <superman_ffm> I try that in irb but nothing happend <seanstickle> What happened? <seanstickle> Nothing? Or something, but not what you expected? <superman_ffm> noting <superman_ffm> i have the hash : h = { a: 1, b: 2, c: 3, d: 4} <RubyPanther> if “noting” happened, you didn’t press enter yet <superman_ffm> i pressed enter <superman_ffm> is it for ruby 1.9 <RubyPanther> if you’re in irb, and you type some stuff and press enter, something will happen. <RubyPanther> that much I guar-an-tee <alexh_> hi, it seems that in a class method one can refer to a class instance variable with an @ or without. which is considered better practice? <superman_ffm> i started a new irb and there works <superman_ffm> :- <seanstickle> alek_b_: when you are referring to it without the @, you are actually calling the getter/setter, not the instance variable. <alexh_> ah… thx seanstickle <seanstickle> alexh_: sure <alexh_> btw, what’s the diff between this channel (ruby) and ruby-lang? <seanstickle> alexh_: politics <alexh_> @seanstickle lol <seanstickle> Not joking. <alexh_> im a liberal so which should I go for :) ? <seanstickle> I meant community politics <seanstickle> Also, posting the same question to both at the same time is generally frowned upon. Just so you know. Someone else might call you out on that. <alexh_> so should a newcomer just toss a coin between them? <seanstickle> Yup. <superman_ffm> where can I read more about values and how do I know that is reduce(&:+) <seanstickle> superman_ffm: http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-values <seanstickle> superman_ffm: http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-reduce <seanstickle> superman_ffm: etc <t-mart> Instead of calling myclass.new, I want people to call a class method of myclass to get instances. The problem is, since I’m not privatizing write methods to the instances variables, I can’t make these generate<t-mart> since I am* privatizing <seanstickle> Example <tayy> hi everyone. <tayy> how do i calculate offset in seconds from two strings of %H:%M:%S? <tayy> basically there’s this server whose time is off by actual time by a few minutes <tayy> and i want to calculate in seconds the offset <seanstickle> Time.parse(a) – Time.parse(b) <tayy> THANK YOU! :D <tayy> i couldn’t find the parse method on ruby-doc! <atheken> hi all, I have ruby-1.9.2-p180 installed via RVM. I’ve got a rails app with some generated views, the “new” JSON-ish hash syntax is not being recognized, switching to the hashrocket fixes things, any ideas wh<seanstickle> atheken: example please <superman_ffm> is there other way to write this: h1 = { a: 1, b: 2, c: 3, d: 4} <superman_ffm> h2 = {e: 5} <superman_ffm> h1.merge(h2) <t-mart> h1[e] = 5 <seanstickle> superman_ffm: you just wrote it <t-mart> you’re just trying to add a key/value pair, right superman_ffm? Session Close: Sun Feb 12 19:00:19 2012 * Disconnected * Attempting to rejoin channel #ruby * Rejoined channel #ruby * Topic is ‘Ruby programming language || ruby-lang.org || RUBY SUMMER OF CODE! rubysoc.org/ || Paste >3 lines of text in http://pastie.org || Para a nossa audiencia em portugues http://ruby-br.org/‘ * Set by apeiros_!~apei...@80-218-50-128.dclient.hispeed.ch on Thu Aug 26 17:55:05 <superman_ffm> how do I start then how to find it <examancer> huh? <davidcelis> superman_ffm: Is this a homework question? <seanstickle> Are you one of those LivingSocial students? <superman_ffm> no <davidcelis> Are you sure? <davidcelis> Because this sounds a lot like a homework question Session Close: Sun Feb 12 19:18:43 2012 * Disconnected * Attempting to rejoin channel #ruby * Rejoined channel #ruby * Topic is ‘Ruby programming language || ruby-lang.org || RUBY SUMMER OF CODE! rubysoc.org/ || Paste >3 lines of text in http://pastie.org || Para a nossa audiencia em portugues http://ruby-br.org/‘ * Set by apeiros_!~apei...@80-218-50-128.dclient.hispeed.ch on Thu Aug 26 17:55:05 <mamina> Can anibody help me with this http://alturl.com/n53kn ? <examancer> lol. i for one thank mamina for the link <td123> lame low-res spam <wroathe> So I’m trying to write a method to recursively reverse the digits of an integer in ruby. So far here’s what I’ve got http://pastie.org/3370740 How can this be improved? <wroathe> I’d like to avoid typecasting in that second return <wroathe> and potentially reduce it to 2 lines <wroathe> My math skills aren’t wonderful. <seanstickle> wroathe: only integers? <seanstickle> 123.to_s.split(//).reverse.join.to_i <seanstickle> :) <seanstickle> 123.to_s.reverse.to_i <seanstickle> Even easier <td123> Integer(a.to_s.reverse) <td123> nvm <td123> :P <seanstickle> :) <td123> I like the to_i better <seanstickle> a = “cat”; b = “dog”; a.split(//).zip(b.split(//)).count{|x| x[0] != x[1]} <seanstickle> Hamming distance! <seanstickle> :) <banisterfiend> seanstickle: what’s been up in the recent months when you’ve been absent <seanstickle> banisterfiend: applied for a job as a Ruby programmer. <seanstickle> banisterfiend: and read some books. <seanstickle> How about you? <Dr4g> I’m not a Ruby guy, but organising a “web” event and looking for somewhere to post our web conference that ruby developers can see. <Dr4g> Where should I look? <Dr4g> I see this: http://www.ruby-lang.org/en/community/conferences/ <Dr4g> Our conference isn’t specific to ruby, it’s of the “web” which means php/ruby/python community <wroathe> Sorry, was afk. I don’t want to cast the integer over to a string <wroathe> So the constraints I’ve imposed are that it has to be recursive and it has to operate solely on integers <wroathe> http://pastie.org/3370740 <wroathe> Perhaps there’s a better algorithm <banisterfiend> seanstickle: sorry dc. I’ve been working wth a bunch of guys on expanding the pry ecosystem, built a few plugins: https://github.com/pry/pry/wiki/Available-plugins <td123> if you need to work on ints, then my though would be for you to use log_10 <seanstickle> Nifty! <wroathe> log_10? <td123> yes, assuming you will only be working base 10 integers :P <banisterfiend> seanstickle: you might be interested in this guy: https://github.com/banister/plymouth <td123> wroathe: if it’s not immediately obvious, think about how our numbers work (how do you construct a value from the sequence of numbers we write down) <seanstickle> Ah perfect <wroathe> It will only be base 10 integers and I have no idea :P <wroathe> How would you express that last return statement then? <BSaboia> hey guys… what is the “best way” of implementing tabs? segmented view is a good choice? <BSaboia> sorry, wrong # = <wroathe> td123 what do you think is immediately obvious about it? <wroathe> I’m not following you <td123> wroathe: I’m assuming this is some kind of challenge so I’m trying not to give you too many hints :P <wroathe> No. It’s for project-euler… It’s one part of an overall problem. If I wanted to do things the easy way with ruby I could cast the number to a string and do string.reverse and then cast it back to an integer<wroathe> I’m just having a little fun. <wroathe> That code I just linked is my best attempt so far but I’m not really a math guy. <td123> wroathe: e.g. 4123 = 4*10^3 + 1*10^2 + 2*10^1 + 3*10^0 <wroathe> That’s essentially what I’m doing isn’t it? <wroathe> http://pastie.org/3370740 <wroathe> Unless I’m missing something in your example <banisterfiend> shevy: fowl is in #pry if u wanna join <Jarred> Is open asynchronous? <Jarred> (open-uri) <cespare> Jarred: nope <seanstickle> Dang, wroate left? <seanstickle> I finally figured out the all-mathematics answer <seanstickle> http://pastie.org/3370927 <seanstickle> For thems that care <seanstickle> Not recursive, though <td123> that’s essentially what I was thinking :P <td123> except I had in mind a recursive one :) <seanstickle> I shy away from recursion. <seanstickle> Too many blown stacks. <td123> if your language can’t handle 5 levels of recursion.. :P <seanstickle> td123: I try to assume arbitrarily large inputs <seanstickle> I tried doing a word ladder that way and blew my stack real quick like. <seanstickle> So I converted to iterative <td123> this is where tail recursion would help me <seanstickle> Yes, true. <nobitanobi> Hi. I’m doing this: – Where birthdate is a date type. How can I change the format of that output? <seanstickle> strftime <nobitanobi> ok <hkhalid> ruby for android <hkhalid> needs more attention <examancer> yes <examancer> this looks to be the way to go for now: https://github.com/ruboto/sl4a_jruby_interpreter <swarley> anyone have an answer as to how i make an irc client with GTK, i dont know how to get around the blocking <banisterfiend> swarley: sshhh, i want to listen to the music <swarley> :[ but i have no idea how to do it QQ <td123> swarley: what blocking? are you using threads? <swarley> td123, no, but GLib should block indefinitely right? <td123> nvm, I was thinking about something else <Zolrath> I’m trying to use something that has an Hpricot dependency, but Hpricot is crashing and reporting the wrong version of Ruby for some reasons? <Zolrath> https://gist.github.com/1813664 <RubyPanther> Zolrath: that’s a weird one, something is getting the wrong version… like it is setting the current load path but then running the old ruby <RubyPanther> and Hpricot is just the first native extension that tries to load <Zolrath> Would that be something wrong with my gem command, building native extensions with system ruby then placing them in my rvm ruby directory or something? <Zolrath> I don’t really see how this is happening <RubyPanther> Zolrath: I don’t know how the vim stuff works, but it sounds like you have an app using an embedded Ruby 1.8.7 and then you’re trying to load a gem that you installed into an rvm ruby <Zolrath> RubyPanther That makes way way more sense <Zolrath> RubyPanther: Vim was compiled with ruby support with an old version. Thank you very much! <RubyPanther> Yay!

You must log in to post a comment.