[#35036] Intentional Programming — "John" <nojgoalbyspam@...>

Hi all

17 messages 2002/03/01

[#35112] RDoc question — Michael Davis <mdavis@...>

I have a question about RDoc. I would like to reference an external

17 messages 2002/03/02

[#35162] string to array and back — Ron Jeffries <ronjeffries@...>

I am needing to convert strings to arrays of bytes and back. I see pack and

19 messages 2002/03/03

[#35364] file reading impossibly slow? — Ron Jeffries <ronjeffries@...>

So I'm doing this benchmark to work with my set program. Part of the problem is

18 messages 2002/03/07

[#35429] Interesting link on static/dynamic typing... — Robert Feldt <feldt@...>

...relevant to Ruby compared to other languages discussion:

25 messages 2002/03/08
[#35441] Re: Interesting link on static/dynamic typing... — Paul Brannan <paul@...> 2002/03/08

On Fri, Mar 08, 2002 at 05:34:43PM +0900, Robert Feldt wrote:

[#35460] Spam, ruby-talk, and me — Dave Thomas <Dave@...>

14 messages 2002/03/08

[#35537] Confusion — David Corbin <dcorbin@...>

The following is from my debugging through xmlc.rb

16 messages 2002/03/10

[#35579] RE: WIN32OLE and LDAP — "Morris, Chris" <chris.morris@...>

> The new version 0.4.2 of Win32OLE has WIN32OLE.bind method.

16 messages 2002/03/11

[#35652] Method type 'abstract' — Peter Hickman <peter@...>

The one thing I miss in Ruby is the abstract class method to go along

15 messages 2002/03/12

[#35653] Some potential RCRs — "Bob Alexander" <bobalex@...>

Here are a few thing I am considering submitting as RCRs. I'm looking =

50 messages 2002/03/12
[#35672] Re: Some potential RCRs — matz@... (Yukihiro Matsumoto) 2002/03/12

Hi,

[#35683] Re: Some potential RCRs — Massimiliano Mirra <list@...> 2002/03/12

On Wed, Mar 13, 2002 at 03:58:01AM +0900, Yukihiro Matsumoto wrote:

[#35697] Re: Some potential RCRs — David Alan Black <dblack@...> 2002/03/13

Hello --

[#35694] rpkg 0.3 — Massimiliano Mirra <list@...>

14 messages 2002/03/13
[#35699] RE: [ANN] rpkg 0.3 — <james@...> 2002/03/13

>

[#35787] testunit - setup -> set_up ? — "Morris, Chris" <chris.morris@...>

I'm just starting to use testunit instead of rubyunit ... I noticed with an

21 messages 2002/03/13
[#35793] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

Morris, Chris [mailto:chris.morris@snelling.com] wrote:

[#35796] Re: testunit - setup -> set_up ? — Dave Thomas <Dave@...> 2002/03/13

"Nathaniel Talbott" <nathaniel@talbott.ws> writes:

[#35797] RE: testunit - setup -> set_up ? — "Nathaniel Talbott" <nathaniel@...> 2002/03/13

dave@thomases.com [mailto:dave@thomases.com] wrote:

[#35898] camelCase and underscore_style — "Morris, Chris" <chris.morris@...>

First, a question. If underscore_style is the Ruby norm for methods and the

20 messages 2002/03/15
[#35924] Re: camelCase and underscore_style — "Guy N. Hurst" <gnhurst@...> 2002/03/15

Phil Tomson wrote:

[#35930] RE: camelCase and underscore_style — "Nathaniel Talbott" <nathaniel@...> 2002/03/16

Guy N. Hurst [mailto:gnhurst@hurstlinks.com] wrote:

[#35989] ANN: Locana GUI and GUI Builder version 0.81 — Michael Davis <mdavis@...>

I am pleased to announce release 0.81 of Locana. Locana is a GUI

16 messages 2002/03/16

[#35992] XPath — Michael Schuerig <schuerig@...>

27 messages 2002/03/16

[#36034] Mini Rant: Indenting — Thomas Hurst <tom.hurst@...>

Why is it that I see *so* much code like:

14 messages 2002/03/17

[#36049] web templating for static sites? — Massimiliano Mirra <list@...>

I'm using the Template Toolkit for generating static web sites and I

42 messages 2002/03/17
[#36426] web standars (was: web templating for static sites?) — Tobias Reif <tobiasreif@...> 2002/03/20

Albert Wagner wrote:

[#36052] Xml Serialization for Ruby — "Chris Morris" <chrismo@...>

=Xml Serialization for Ruby

20 messages 2002/03/17
[#36059] Re: [ANN] Xml Serialization for Ruby — Massimiliano Mirra <list@...> 2002/03/17

On Mon, Mar 18, 2002 at 05:20:56AM +0900, Chris Morris wrote:

[#36067] eval/Module question — David Corbin <dcorbin@...>

If I have a String src that is similar to the following:

13 messages 2002/03/18

[#36157] Development of Windows version of Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

Now that we've dumped the cygwin requirement for the Windows version of

63 messages 2002/03/18
[#36330] Re: Development of Windows version of Ruby — Ron Jeffries <ronjeffries@...> 2002/03/19

On Tue, 19 Mar 2002 14:05:27 GMT, "Albert L. Wagner" <alwagner@uark.edu> wrote:

[#36431] Re: Development of Windows version of Ruby — Dennis Newbold <dennisn@...> 2002/03/20

[#36458] Windows version of Ruby (proposals) — ptkwt@... (Phil Tomson) 2002/03/21

Dennis Newbold <dennisn@pe.net> wrote in message news:<Pine.GSO.3.96.1020320113603.22242B-100000@shell2>...

[#36482] RE: Windows version of Ruby (proposals) — "Christian Boos" <cboos@...> 2002/03/21

Some thoughts on the 2 first Windows issues, plus a 4th one...

[#36496] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

"Christian Boos" <cboos@bct-technology.com> writes:

[#36510] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36514] Re: Windows version of Ruby (proposals) — Dave Thomas <Dave@...> 2002/03/21

nobu.nokada@softhome.net writes:

[#36518] Re: Windows version of Ruby (proposals) — nobu.nokada@... 2002/03/21

Hi,

[#36211] dots in Dir.entries — matz@... (Yukihiro Matsumoto)

Hi,

22 messages 2002/03/19

[#36231] style choice — Ron Jeffries <ronjeffries@...>

A style question for the community ... which of the following do you prefer, and

18 messages 2002/03/19

[#36345] ANN: REXML 2.0 — Sean Russell <ser@...>

I have a feeling there will only be three major revisions of REXML. Version

19 messages 2002/03/20

[#36610] Re: Windows version of Ruby (proposals) — Ron Jeffries <ronjeffries@...>

On Thu, 21 Mar 2002 14:11:55 GMT, Dave Thomas <Dave@PragmaticProgrammer.com> wrote:

16 messages 2002/03/22

[#36645] Ruby for Mac OS 10.1 — Jim Freeze <jim@...>

Hi:

28 messages 2002/03/23

[#36768] Re: Difference between 'do' and 'begin' — Clemens Hintze <c.hintze@...>

In <slrna9ulvi.f2h.mwg@fluffy.isd.dp.ua> Wladimir Mutel <mwg@fluffy.isd.dp.ua> writes:

23 messages 2002/03/26
[#36783] RE: Difference between 'do' and 'begin' — <james@...> 2002/03/26

[#36792] Re: Difference between 'do' and 'begin' — Kent Dahl <kentda@...> 2002/03/26

james@rubyxml.com wrote:

[#36808] Error calling Tk in a loop — <james@...>

I'm trying to write some code that pops up a Tk window when for certain

15 messages 2002/03/26

[#36841] RE: Windows version of Ruby (proposals) — "Andres Hidalgo" <sol123@...>

I believe that Ruby has a place in windows (Office), I happened to have

14 messages 2002/03/27

[#36863] Hash.new(Hash.new) doesn't use Hash.new as default value — "Jonas Delfs" <jonas@...>

Hi -

18 messages 2002/03/27

[#37080] Why isn't Math object-oriented? — Bil Kleb <W.L.Kleb@...>

So I'm reading along in the Pixaxe book (yet again), and I am told

15 messages 2002/03/30

[#37121] String#begins?(s) — timsuth@... (Tim Sutherland)

class String

24 messages 2002/03/31

RE: Newbie -- Please help!!

From: "Firestone, Mark - Technical Support" <mark.firestone@...>
Date: 2002-03-14 14:46:06 UTC
List: ruby-talk #35839
Well.  That puts me back in the same boat I was before.  I have started to
put the peice of code into the main telnet app (which I am rapidly turning
into a total mess anyway...) the problem is, it still is making the user
data into a LOCAL object... so, it isn't accessable from any other place.
If I make it a global object... then I violate the multi-threading rules.

The problem is, none of the resources I have found (except you kind people)
tell you how to actually correctly structure things.  see the following code
(which is bad, I know...)  Right now...my the object is only accessable from
whatever one def at a time.  Am I missing something?

Mark

#!/usr/bin/ruby

# This version has mixin classes: TelnetIO and ConsoleIO,
# which are used to create local and network versions of the
# Session class.

#CONST

  BS = 8
  CR = 13
  LF  = 10
  NOECHOCHAR = 36
  PRINTABLE = 32..126

def pick_one(sequence)
  sequence[rand(sequence.length)]
end

module ConsoleIO
  
  def hangup
    print "NO CARRIER\n"
  end
  
  # Write line without CR
  def write(x)
    print x
    STDOUT.flush
  end
    
  # Write line with CR
  def putstr(*lines)
    if lines.length == 0
      print "\n"
    else
      lines.each { |line|
        print line
        print "\n"
      }
    end
  end
  
  def getstr
    gets
  end
end

module TelnetIO
  
  # hangup
  def hangup
    @socket.flush
    @socket.close
  end    
  
  # Write line without CR
  def write(line)
    @socket.write line
  end
  
  # Write line with CR
  def putstr(*lines)
    crlf = "\r\n"
    if lines.length == 0
      @socket.write crlf
    else
      lines.each { |line|
        @socket.write line
        @socket.write crlf
      }
    end
  end



def getstr(echo)  # Input  a line a character at a time.

 whole = ""
 fred    = ""

    @socket.each_byte do  | fred| 
       
        case fred
          when 255
           puts "Command Mode Request"
          when  PRINTABLE
           whole = whole + fred.chr
           if echo 
            @socket.write fred.chr 
           else
            @socket.write NOECHOCHAR.chr
           end
         when CR
          @socket.write CR.chr+LF.chr
          break
        when BS
          whole.chop!                       #the user pressed backspace, so
get rid
          @socket.write fred.chr
        end
     end
@socket.flush
 getstr = whole
end
end
  
class User

   def initialize(name,phone,citystate,address,password)
     @deleted = FALSE
     @locked  = TRUE
     @name   = name
     @alais    = ''
     @alaisOn = FALSE
     @phone   = phone
     @citystate = citystate
     @address  = address
     @password = password
     @width = 80
    end


   attr_reader :name, :password # short and neat
 
 def show
  print "User: #@name #@phone #@citystate #@address #@password\n"
 end
 
end

class User_list

  include Enumerable 
  
  def initialize
    @users = Array.new
  end
  
  def append(aUser)
   @users.push(aUser)
   self
  end
  
  
  def [](key)
   if key.kind_of?(Integer)
      result = @users[key]
    else
     result = @users.find { |user| key == user.name }
    end
    return result 
 end
 
## end   #of Class User_list
 
  ## class method of User_list, so we don't need instance.
  def self.loadusers
    list = nil
    File.open("users.dat") do |f|  
      list = Marshal.load(f)  ##
      print "- Loading User Object...\n"
    end
    return list ##
  end
  
  # save list
  def saveusers
    File.open("users.dat", "w+") do |f|
      Marshal.dump( self, f) ##
    end
    print "- Saving User Object...\n"
  end

  def checkpassword (username,password)
    result = FALSE
    if self[username] != nil ##
      if self[username].password == password  ##
	result = TRUE
      end
    else
      print "\n-Bad username passed to def:checkpassword.  Please tell
sysop!\n"
    end
    return result
  end

  ## new end...
end   #of Class User_list 


class Session

  require 'thread'

  @@busy = Mutex.new

  # Perhaps we'll find another way to pass the socket.
  # For now, a default value of "nil" will make it OK
  # for ConsoleIO.
  def initialize(socket = nil)
    @socket = socket 
  end
  
  def login  
  if File.exists?("users.dat")  ##this shouldn't be here.  this is a stupid
place for it.  blarg!  
  list = User_list.loadusers
else
  
  list = User_list.new
  list.append(User.new('SYSOP','000-000-0000','Tempe, AZ','600 E. Solana
Drive','STUPID'))
  list.append(User.new('TEST','000-000-0000','Mesa, AZ','123 Sample
Street','HAPPY'))
  print "- User File not Found.  Creating new User File\n"
end
    write 255.chr     #this seems to stop telnet clients that want to echo
    write 254.chr     #from echoing.  move this to it's own def later
    write 1.chr
    putstr
   
    putstr "TOPquark 1.2r (c) 1993 by TOPsoftware"
    putstr
    IO.foreach("welcome1.txt") { |line| putstr line }
    
  
    write "Enter your name: "
    userName = getstr(true).strip.upcase
    
     if list[userName] != nil
      write "Password: "
      password = getstr(false).strip.upcase
       if list.checkpassword(userName,password) == TRUE
	done = TRUE
       end
     else 
      putstr "User not found"
     end
    putstr
    putstr "Congratulations.  You have been granted the privilege"
    putstr "of entry into the system by Microsoft's* certified,"
    putstr "better-than-yours-because-we-said-so security."
    putstr 
    putstr "* Microsoft(r) is a registered trademark of a company"
    putstr "with way more lawyers than me."
    putstr
  end

  def readmsgs
    users = ["BIG BEN", "SHO KOSUGI", "GLENN", "CAPTAIN CRUNCH", 
             "PEE-WEE HERMAN", "SUE WIDEMARK", "TINA"]
    subjects = ["Ev Mecham", "Atari Roolz!", "Call my board!", 
                "Please don't delete me!", "Where's the file board?"]
    putstr "From: " + pick_one(users)
    putstr "To:   ALL"
    putstr "Subj: " + pick_one(subjects)
    putstr
    putstr "Hello, world!"
    putstr
    putstr "END OF MESSAGES"
  end

  def commandLoop
    putstr "Q=Quit E=Error R=Read Messages"
    while true
      write "Command? "
      case getstr(true).strip
      when "q"
        break
      when "e"
        raise "The sky is falling!"
      when "r"
        readmsgs
      else
        putstr "Nope, can't do that"
      end
    end
  end

  def doSession
    if @@busy.try_lock
      begin
        login
        commandLoop
        putstr "Bye"
      ensure 
        @@busy.unlock
      end
    else
      putstr "BUSY"
      sleep 0.1
    end
  end

  def run
    begin
      doSession
    rescue Exception
      oops = "Oops: #{$!}"
      puts oops, $@
      putstr oops
    ensure
      hangup
    end
  end

end

# Create net session class that adds TelnetIO's methods to Session.
class TelnetSession<Session
  include TelnetIO
end
class ConsoleSession<Session
  include ConsoleIO
end


class Server

  require 'socket'

  def run
    Thread.new {
      server = TCPServer.new (23)
      while (socket = server.accept)
        Thread.new {TelnetSession.new(socket).run}
      end
    }
    # command loop
    while TRUE
      puts "Type QUIT to stop the server."
      case gets.downcase.strip
      when "local"
        ConsoleSession.new.run
      when "quit"
        break
      end
    end
  end
end

## 


Server.new.run
list.saveusers


-----Original Message-----
From: Olonichev Sergei [mailto:olonichev@scnsoft.com]
Sent: 14 March 2002 14:18
To: ruby-talk@ruby-lang.org
Subject: Re: Newbie -- Please help!!


> 1) This thing will eventually be multiuser -- so more than one thread will
> have to be able to access those objects.  How can I plan for this now --
so
> I don't have to "pay" later?

1. If you're going to write multi-thread application you MUST, yes MUST!
forget about global objects.
This is a good practice in general and it is obligatory in multi-threding.

2. All methods that do not need to change object, must not do that, let's
call them const methods.

3. If you have common resource used from multiple threads, those threads
must call only const methods.

BR,
Sergei


NOTICE:  This e-mail and any attachment(s) may contain confidential and
proprietary information of Goss International Corporation and/or its
subsidiaries and may be legally privileged. This e-mail is intended solely
for the addressee. If you are not the addressee, dissemination, copying or
other use of this e-mail or any of its content is strictly prohibited and
may be unlawful. If you are not the intended recipient please inform the
sender immediately and destroy the e-mail and any copies. All liability for
viruses is excluded to the fullest extent permitted by law. Any views
expressed in this message are those of the individual sender. No contract
may be construed by this e-mail.

In This Thread

Prev Next