Tim Hunter | 1 Oct 01:06 2009
Picon

Re: Can you make a clock?

Scott Andrechek wrote:
> 'Ello. I was just wandering how you update the time in a ruby program
> (like a clock). For instance:
> COMP:WED Sep 30 18:51:30
> COMP:WED Sep 30 18:51:31  #Replacing the above line
> 
> I don't need the entire code for a clock (unless you happen to have it)
> I just need to know the idea of how to make it. Thanks.
> 
> -Scott

Look at the Time class, particularly Time.now

--

-- 
MagickWand for Ruby - http://magickwand.rubyforge.org/

Ken Bloom | 1 Oct 01:08 2009
Picon

Re: SystemStackError: stack level too deep > how make it deeper?

On Thu, 01 Oct 2009 04:47:28 +0900, Joshua Muheim wrote:

> Hi all
> 
> I have a recursive algorith that must run until it finds the result:
> 
> def p(n)
>   n * (3 * n - 1) / 2
> end
> 
> def h(n)
>   n * (2 * n - 1)
> end
> 
> def find_next_match(p, h)
>   result_p = p(p + 1)
>   result_h = h(h + 1)
>   if result_p == result_h # Resultat gefunden!
>     return result_p
>   else
>     result_p < result_h ? p += 1 : h += 1
> 
>     puts "find next match for p=#{p} (#{result_p}) and h=#{h}
> (#{result_h})"
>     find_next_match(p, h)
>   end
> end

The code you have posted is tail recursive, which means that the original 
function call does nothing after it makes the recursive call, and returns 
(Continue reading)

Thomas Haggett | 1 Oct 01:15 2009

Re: Can you make a clock?

Hi. Am I missing something or do you just need:

	Time.now.strftime("%h %d %H:%M:%S")

To write to a terminal by replacing existing lines you need to send a  
carriage-return without a line-feed (i.e. \r rather than \n on the end  
of lines). If I'm being hacky, I generally just write them directly:

	$stderr.write "\rstuff here"

Just be aware that anything longer than the new line will still be  
visible (i.e.

	$stderr.write "\rlong string"
	$stderr.write "\rshort"

will result in

	"shortstring"

being visible.

If you want to do this properly, you should probably look at the  
ncurses library (http://ncurses-ruby.berlios.de/).

Thomas

On 30 Sep 2009, at 23:54, Scott Andrechek wrote:

> 'Ello. I was just wandering how you update the time in a ruby program
(Continue reading)

Russell Fulton | 1 Oct 01:22 2009
Picon
Picon

Monitors on data structures

Hi

I am trying to use monitors for the first time in ruby.  I am familiar
with the concept but am having some problems making things work.

Background:  I have a program that uses nmap-parser to parse large nmap
scans and uses the call back to deliver results for each host.  The call
back is threaded.

I want to build lists of IP addresses for further investigation from the
callback routine.  I have made a class AddressList:

class AddressList < Array
  include MonitorMixin

  def initialise  # redundant ?
  super
  end

  def <<(addr)
    synchronise do  # make sure we don't clobber another thread
      super( addr )
    end
  end

end

we need to protect the push code so that to threads don't collide so I
put a synchronise block around it.

(Continue reading)

Bertram Scharpf | 1 Oct 01:38 2009
Picon

Re: Can you make a clock?

Hi,

Am Donnerstag, 01. Okt 2009, 07:54:14 +0900 schrieb Scott Andrechek:
> 'Ello. I was just wandering how you update the time in a ruby program
> (like a clock). For instance:
> COMP:WED Sep 30 18:51:30
> COMP:WED Sep 30 18:51:31  #Replacing the above line

You need a signal triggered every second so that you can refresh
the display. Just three weeks ago I posted this:

  http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/3750044

Good luck!

Bertram

--

-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

David Masover | 1 Oct 01:44 2009

Re: Exceptional Rails Developer

On Wednesday 30 September 2009 01:45:27 pm Zundra Daniel wrote:
> At least he didn't say "Rockstar" or "Ninja"

Well, what's he going to say, "Average"?

We are looking to hire a Mediocre Rails developer to join our could-run-out-
of-funding-at-any-moment startup...

It just doesn't have the same ring to it, I guess.

(Actually, I'd probably apply if I wasn't currently in school. I was just 
feeling snarky today.)

Greg Donald | 1 Oct 01:54 2009
Picon

Re: Exceptional Rails Developer

On Wed, Sep 30, 2009 at 6:44 PM, David Masover <ninja <at> slaphack.com> wrote:
> On Wednesday 30 September 2009 01:45:27 pm Zundra Daniel wrote:
>> At least he didn't say "Rockstar" or "Ninja"
>
> Well, what's he going to say, "Average"?

Why not?  It's unrealistic to think every company wants and can afford
the best.  Many will have to settle for who they can find.

At a minimum they should include something like "and willing to pay
exceptional wages too!" when asking for an "exceptional" coder.  I saw
no such mention.

And finally, to the OP, did you learn something?  No?  Well here's the
take-away: We programmers all already think we are exceptional.  You
won't make less of us apply for a job by trying to single out people
using silly buzzwords.  So stop it.

--

-- 
Greg Donald
http://destiney.com/

Scott Andrechek | 1 Oct 02:03 2009
Picon

Re: Can you make a clock?

I have tried all 3 tips and although i see how it would work maybe if i 
be more specific it'll help you help me : ) . I am making a program 
notify me how many days are left till an event happens (in the case of 
my program when a game comes out). This is what I use:

puts 'Hey Scott : D'
time=Time.new
time_cod=Time.mktime(2009,11,13)
time_operationflash=Time.mktime(2009,10,6)
time_assassinscreed2=Time.mktime(2009,11,17)
time_godofwar3=Time.mktime(2010,3)
if (time_cod.to_i<0 or time_cod.to_i==0)
  puts 'It\'s already out!'
  else
    puts 'There are ' + (((((time_cod-time)/60)/60)/24).to_i).to_s + ' 
days left until Call of Duty 4: Modern Warfare 2 is released'
  end
  if (time_operationflash.to_i<0 or time_operationflash.to_i==0)
    puts 'It\'s already out!'
    else
      puts 'There are ' + 
(((((time_operationflash-time)/60)/60)/24).to_i).to_s + ' days left 
until Operation Flashpoint: Dragon Rising is released'
    end
    if (time_assassinscreed2.to_i<0 or time_assassinscreed2==0)
      puts 'It\'s already out!'
else
puts 'There are ' + 
(((((time_assassinscreed2-time)/60)/60)/24).to_i).to_s + ' days left 
until Assassin\'s Creed 2 is released'
(Continue reading)

David Masover | 1 Oct 02:07 2009

Re: SystemStackError: stack level too deep > how make it deeper?

On Wednesday 30 September 2009 04:17:31 pm Rob Biedenharn wrote:

> your algorithm is "tail recursive" and that's partly why you run out
> of stack space in a language like Ruby, but in a language optimized
> for tail recursion it might have worked.

Probably would have.

The other thing is to note that the question the subject is asking should 
never be asked. If you're in a language that optimizes tail-recursing, it's 
probably about as efficient as a loop.

If you're in a language that doesn't optimize tail-recursing, the last thing 
you want to do is increase the size of the stack. That would just give you the 
same problem again later, and waste tons of RAM.

Reid Thompson | 1 Oct 02:27 2009

Re: Can you make a clock?

Scott Andrechek wrote:
> I have tried all 3 tips and although i see how it would work maybe if i 
> be more specific it'll help you help me : ) . I am making a program 
> notify me how many days are left till an event happens (in the case of 
> my program when a game comes out). This is what I use:
> 
> puts 'Hey Scott : D'
> time=Time.new
> time_cod=Time.mktime(2009,11,13)
> time_operationflash=Time.mktime(2009,10,6)
> time_assassinscreed2=Time.mktime(2009,11,17)
> time_godofwar3=Time.mktime(2010,3)
> if (time_cod.to_i<0 or time_cod.to_i==0)
>   puts 'It\'s already out!'
>   else
>     puts 'There are ' + (((((time_cod-time)/60)/60)/24).to_i).to_s + ' 
> days left until Call of Duty 4: Modern Warfare 2 is released'
>   end
>   if (time_operationflash.to_i<0 or time_operationflash.to_i==0)
>     puts 'It\'s already out!'
>     else
>       puts 'There are ' + 
> (((((time_operationflash-time)/60)/60)/24).to_i).to_s + ' days left 
> until Operation Flashpoint: Dragon Rising is released'
>     end
>     if (time_assassinscreed2.to_i<0 or time_assassinscreed2==0)
>       puts 'It\'s already out!'
> else
> puts 'There are ' + 
> (((((time_assassinscreed2-time)/60)/60)/24).to_i).to_s + ' days left 
(Continue reading)


Gmane