code
stringlengths
1
1.73M
language
stringclasses
1 value
# # tclx/tclx.rb # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' # call setup script require 'tkextlib/tclx/setup.rb' # TkPackage.require('Tclx', '8.0') TkPackage.require('Tclx') module Tk ...
Ruby
# # TkTrans support (win32 only) # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' # call setup script for general 'tkextlib' libraries require 'tkextlib/setup.rb' # call setup script require 'tkextlib/tktrans/setup.rb' # load library require 'tkextlib/tktrans/tktrans'
Ruby
# # tcheckbutton widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TCheckButton < Tk::CheckButton end TCheckbutton = TCheckButton CheckButton = TCheckButton Checkbutton = TCheckButton end e...
Ruby
# # tseparator widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TSeparator < TkWindow end Separator = TSeparator end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Separator, :TkSeparator) class...
Ruby
# # style commands # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile module Style end end end module Tk::Tile::Style extend TkCore end class << Tk::Tile::Style if Tk::Tile::TILE_SPEC_VERSION_ID < 8 TkComman...
Ruby
# # ttk::sizegrip widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class SizeGrip < TkWindow end Sizegrip = SizeGrip end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Sizegrip, :TkSizegrip, :TkSizeGrip...
Ruby
# # tcombobox widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TCombobox < Tk::Tile::TEntry end Combobox = TCombobox end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Combobox, :TkCombobox) cla...
Ruby
# # setup.rb -- setup script before calling TkPackage.require() # # If you need some setup operations (for example, add a library path # to the library search path) before using Tcl/Tk library packages # wrapped by Ruby scripts in this directory, please write the setup # operations in this file. #
Ruby
# # ttk::dialog (tile-0.7+) # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class Dialog < TkWindow end end end class Tk::Tile::Dialog TkCommandNames = ['::ttk::dialog'.freeze].freeze def self.show(*args) ...
Ruby
# # tpaned widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TPaned < TkWindow end PanedWindow = Panedwindow = Paned = TPaned end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Panedwindow, ...
Ruby
# # tframe widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TFrame < Tk::Frame end Frame = TFrame end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Frame, :TkFrame) class Tk::Tile::TFrame < Tk:...
Ruby
# # tscrollbar widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TScrollbar < Tk::Scrollbar end Scrollbar = TScrollbar end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Scrollbar, :TkScrollbar) ...
Ruby
# # tsquare widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TSquare < TkWindow end Square = TSquare end end class Tk::Tile::TSquare < TkWindow include Tk::Tile::TileWidget if Tk::Tile::USE_TT...
Ruby
# # tentry widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TEntry < Tk::Entry end Entry = TEntry end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Entry, :TkEntry) class Tk::Tile::TEntry < Tk:...
Ruby
# # tprogressbar widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TProgressbar < TkWindow end Progressbar = TProgressbar end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Progressbar, :TkProgress...
Ruby
# # tlabel widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TLabel < Tk::Label end Label = TLabel end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Label, :TkLabel) class Tk::Tile::TLabel < Tk:...
Ruby
# # tbutton widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TButton < Tk::Button end Button = TButton end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Button, :TkButton) class Tk::Tile::TButt...
Ruby
# # treeview widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class Treeview < TkWindow end end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Treeview, :TkTreeview) module Tk::Tile::TreeviewConfig incl...
Ruby
# # tradiobutton widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TRadioButton < Tk::RadioButton end TRadiobutton = TRadioButton RadioButton = TRadioButton Radiobutton = TRadioButton end e...
Ruby
# # tlabelframe widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TLabelframe < Tk::Tile::TFrame end TLabelFrame = TLabelframe Labelframe = TLabelframe LabelFrame = TLabelframe end end Tk....
Ruby
# # tmenubutton widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TMenubutton < Tk::Menubutton end TMenuButton = TMenubutton Menubutton = TMenubutton MenuButton = TMenubutton end end Tk.__...
Ruby
# # tnotebook widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TNotebook < TkWindow end Notebook = TNotebook end end Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Notebook, :TkNotebook) class Tk::T...
Ruby
# # tscale & tprogress widget # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) # require 'tk' require 'tkextlib/tile.rb' module Tk module Tile class TScale < Tk::Scale end Scale = TScale class TProgress < TScale end Progress = TProgress end end Tk.__set_topleve...
Ruby
# # tkfont.rb - load tk/font.rb # require 'tk/font'
Ruby
# # tkentry.rb - load tk/entry.rb # require 'tk/entry'
Ruby
# # tkmngfocus.rb - load tk/mngfocus.rb # require 'tk/mngfocus'
Ruby
############################################################## # extconf.rb for tcltklib # release date: 2010-07-30 ############################################################## require 'mkmf' TkLib_Config = {} TkLib_Config['search_versions'] = # %w[8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6 4.2] # %w[8.7 8.6 8....
Ruby
# $Id: extconf.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'mkmf' create_makefile 'racc/cparse'
Ruby
require 'mkmf' have_header( "st.h" ) create_makefile( "syck" )
Ruby
# $RoughId: extconf.rb,v 1.3 2001/11/24 17:49:26 knu Exp $ # $Id: extconf.rb 11708 2007-02-12 23:01:19Z shyouhei $ require 'mkmf' have_header("syslog.h") && have_func("openlog") && have_func("setlogmask") && create_makefile("syslog")
Ruby
#!/usr/bin/env ruby # $RoughId: test.rb,v 1.9 2002/02/25 08:20:14 knu Exp $ # $Id: test.rb 11708 2007-02-12 23:01:19Z shyouhei $ # Please only run this test on machines reasonable for testing. # If in doubt, ask your admin. require 'test/unit' # Prepend current directory to load path for testing. $:.unshift('.') re...
Ruby
require 'mkmf' create_makefile('fcntl')
Ruby
require 'Win32API' getch = Win32API.new("crtdll", "_getch", [], 'L') puts getch.Call.chr
Ruby
require 'Win32API' getCursorPos = Win32API.new("user32", "GetCursorPos", ['P'], 'V') lpPoint = " " * 8 # store two LONGs getCursorPos.Call(lpPoint) x, y = lpPoint.unpack("LL") # get the actual values print "x: ", x, "\n" print "y: ", y, "\n" ods = Win32API.new("kernel32", "OutputDebugString", ['P'], 'V') ods.Call("...
Ruby
=begin = Win32 Registry I/F win32/registry is registry accessor library for Win32 platform. It uses Win32API to call Win32 Registry APIs. == example Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\foo') do |reg| value = reg['foo'] # read a value value = reg['foo', Win32::Regis...
Ruby
=begin = Win32 DNS and DHCP I/F =end require 'win32/registry' module Win32 module Resolv API = Registry::API def self.get_hosts_path path = get_hosts_dir path = File.expand_path('hosts', path) File.exist?(path) ? path : nil end def self.get_resolv_info search, name...
Ruby
require 'mkmf' dir_config("win32") if have_header("windows.h") and have_library("kernel32") create_makefile("Win32API") end
Ruby
#! /usr/bin/ruby # :stopdoc: require 'rbconfig' require 'optparse' # http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset # Fri, 30 May 2003 00:09:00 GMT' OS = Config::CONFIG["target_os"] SHELL = Config::CONFIG['SHELL'] class Hash::Ordered < Hash def [](key) val = super and val.last end...
Ruby
require 'mkmf' dir_config("iconv") conf = File.exist?(File.join($srcdir, "config.charset")) conf = with_config("config-charset", enable_config("config-charset", conf)) if have_func("iconv", "iconv.h") or have_library("iconv", "iconv", "iconv.h") if checking_for("const of iconv() 2nd argument") do create_...
Ruby
require 'mkmf' create_makefile("sdbm")
Ruby
require 'mkmf' dir_config("gdbm") if have_library("gdbm", "gdbm_open") and have_header("gdbm.h") create_makefile("gdbm") end
Ruby
module Gtk autoload :Widget, 'gtk2/Widget.rb' autoload :Stock, 'gtk2/Stock.rb' autoload :Button, 'gtk2/Button.rb' autoload :Window, 'gtk2/Window.rb' autoload :VBox, 'gtk2/VBox.rb' autoload :HBox, 'gtk2/HBox.rb' autoload :Entry, ...
Ruby
class Gtk::TextBuffer attr_accessor :muiObject attr_accessor :_view def initialize() # z = Zuby.new # tObject = z.buildMUIFrame(label) # @muiObject = tObject @text = "" self end def text=(text) @text = text z = Zuby.new z.setMUITextAreaText( @_view.muiObject, @te...
Ruby
class Gtk::Widget def reparent(new_parent) puts "reparent" puts new_parent puts self z = Zuby.new puts new_parent.muiObject puts @muiObject z.moveMUIObject(new_parent.muiObject, @muiObject) end def show() end end
Ruby
class Gtk::TextView<Gtk::Widget attr_accessor :muiObject attr_accessor :buffer attr_accessor :set_editable def initialize(buffer = nil) if( buffer == nil) @buffer = Gtk::TextBuffer.new else @buffer = buffer end #HACK - only associate one textview with a buffer - to allow ...
Ruby
class Gtk::Entry<Gtk::Widget attr_accessor :muiObject attr_accessor :text def initialize(text=nil, use_underline=nil) if (text == nil) text = "" end z = Zuby.new tObject = z.buildMUIStringEntry(text) @muiObject = tObject self end end
Ruby
class Gtk::VBox<Gtk::Widget attr_accessor :muiObject attr_accessor :border_width def initialize(homogeneous = false, spacing = nil) z = Zuby.new tObject = z.buildMUIVGroup() @muiObject = tObject self end #FIXME - move to a generic super Box (and container) class def add(widget, c...
Ruby
#TODO - add a proper mapping to the Tango icon library class Gtk::Image attr_accessor :muiObject attr_accessor :file #def initialize(value = nil) # # @file = value # # self #end def initialize(stock_id, size=nil) #if( stock_id == nil) # @file = "Development:tango-icon-theme-0.8.90/3...
Ruby
class Gtk::MenuShell def append(child=nil) z = Zuby.new tWidget = child.muiObject z.addMUIObject(@muiObject, tWidget) puts "appending #{@muiObject}" self end end
Ruby
module Gtk::Stock QUIT = "Quit" end
Ruby
class Gtk::TreeViewColumn attr_accessor :mode def initialize(title = nil, cell_renderer = nil, attributes = nil) # assume 'CellRendererText' end end
Ruby
#Should be a reference to a model row class Gtk::TreeIter #HACK attr_accessor :sourceModel #HACK attr_accessor :row def initialize() #@row = Array.new # NO - Reference this to the source model row! end def [](column) return get_value(column) end def get_value(column) return @r...
Ruby
class Gtk::HBox<Gtk::Widget attr_accessor :muiObject attr_accessor :border_width def initialize(homogeneous = false, spacing = nil) z = Zuby.new tObject = z.buildMUIHGroup() @muiObject = tObject self end #FIXME - move to a generic super Box (and container) class def add(widget, c...
Ruby
class Gtk::TreeView<Gtk::Widget attr_accessor :muiObject attr_accessor :selection #Gets the Gtk::TreeSelection associated with the TreeView. #attr_accessor :model #FIXME add an = method and do the sync def initialize(model = nil) if( model != nil ) @model = model #HACK - ADD TREEVIEW ...
Ruby
class Gtk::CellRendererText def initialize() end end
Ruby
class Gtk::Frame attr_accessor :muiObject attr_accessor :border_width def initialize(label = nil) z = Zuby.new tObject = z.buildMUIFrame(label) @muiObject = tObject self end def add(pWidget=nil) z = Zuby.new tWidget = pWidget.muiObject z.addMUIObject(@muiObject, tWi...
Ruby
#IGNORE - # We don't need this extra menu widget in MUI, so just pass through the parent #IGNORE - # just change append to attach to parent. DANGER - what if there is no parent defined yet! class Gtk::Menu<Gtk::MenuShell attr_accessor :muiObject def initialize() self end end
Ruby
class Gtk::Label<Gtk::Widget attr_accessor :muiObject attr_accessor :selectable def initialize(str = nil, mnemonic = false) if (str == nil) str = "UNDEFINED" end z = Zuby.new tObject = z.buildMUILabel(str) @muiObject = tObject self end def set_markup(str, mnemonic =...
Ruby
require "rexml/document" include REXML #FIXME - need to return a ["window1"] #FIXME - add all the created objects to a map class Gtk::Builder def initialize(pCallee)#HACK #HACK @callee = pCallee @widgetMap = Hash.new end def add_from_file(filename=nil) gladeRootNode = (Document.new File....
Ruby
class Gtk::HSeparator<Gtk::Widget attr_accessor :muiObject def initialize(text=nil, use_underline=nil) z = Zuby.new tObject = z.buildMUIBalance() @muiObject = tObject self end end
Ruby
class Gtk::MenuItem attr_accessor :muiObject def initialize(label = nil, use_underline = true) z = Zuby.new tObject = z.buildMUIMenuItem(label) @muiObject = tObject self end def set_submenu(submenu) @submenu = submenu # is a 'Gtk::Menu' submenu.muiObject = @muiObject # J...
Ruby
class Gtk::SeparatorMenuItem attr_accessor :muiObject def initialize() z = Zuby.new tObject = z.buildMUIMenuSeparatorItem() @muiObject = tObject self end end
Ruby
# Limitation - there can only be one Menubar in MUI (I think!) - check this class Gtk::MenuBar<Gtk::MenuShell attr_accessor :muiObject def initialize(label = nil) #TODO - grab/recover the MUI menu z = Zuby.new tObject = z.buildMUIMenuBar() @muiObject = tObject self end end
Ruby
class Gtk::Toolbar attr_accessor :muiObject attr_accessor :orientation def initialize(homogeneous = false, spacing = nil) z = Zuby.new tObject = z.buildMUIHGroup() @muiObject = tObject self end #FIXME - move to a generic super Box (and container) class def append(text, tooltip_te...
Ruby
#FIXME - should data only be stored in the iter? or it iter just referencing this? #TODO - figure out when the list should sync with the MUI list? class Gtk::ListStore #attr_accessor :iter - should iter be a TreeIter? attr_accessor :treeView#HACK def initialize(type1, *rest)#, ...)#FIXME #build a li...
Ruby
class Gtk::TreeSelection attr_accessor :mode def initialize(model = nil) end def set_mode(type) @mode = type end end
Ruby
class Gtk::TextMark #attr_accessor :offset def initialize() self end end
Ruby
class Gtk::Button<Gtk::Widget attr_accessor :muiObject def initialize(text=nil, use_underline=nil) z = Zuby.new tObject = z.buildMUIButton(text) #tObject = z.buildMUIImageButton(text, "Development:tango-icon-theme-0.8.90/16x16/actions/bookmark-new.png") @muiObject = tObject self en...
Ruby
#buffer class Gtk::TextIter attr_accessor :offset def initialize() end end
Ruby
class Gtk::Window attr_accessor :muiObject attr_accessor :border_width def initialize(name=nil) z = Zuby.new #Reclaim the MUI Root @muiObject = z.getMUIRoot() if( name != nil ) z.setMUIWindowTitle(name) end self end def add(pWidget=nil) z = Zuby.new tWidget = pWidg...
Ruby
# Loads mkmf which is used to make makefiles for Ruby extensions require 'mkmf' # Give it a name extension_name = 'zuby' # The destination dir_config(extension_name) have_library("mui") # Do the work create_makefile(extension_name)
Ruby
require 'mkmf' dir_config("dbm") if dblib = with_config("dbm-type", nil) dblib = dblib.split(/[ ,]+/) else dblib = %w(db db2 db1 dbm gdbm gdbm_compat qdbm) end headers = { "db" => ["db.h"], "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"], "db2" => ["db2/db.h", "db2.h", "db.h"], "dbm" => ["ndbm.h"], "gdbm" =...
Ruby
require "fcntl" class IO def nonblock? (fcntl(Fcntl::F_GETFL) & File::NONBLOCK) != 0 end def nonblock=(nb) f = fcntl(Fcntl::F_GETFL) if nb f |= File::NONBLOCK else f &= ~File::NONBLOCK end fcntl(Fcntl::F_SETFL, f) end def nonblock(nb = true) nb, self.nonblock = nonblo...
Ruby
require 'mkmf' target = "io/wait" unless macro_defined?("DOSISH", "#include <ruby.h>") fionread = %w[sys/ioctl.h sys/filio.h].find do |h| have_macro("FIONREAD", h) end if fionread $defs << "-DFIONREAD_HEADER=\"<#{fionread}>\"" create_makefile(target) end else if have_func("rb_w32_ioctlsocket", "r...
Ruby
#!/usr/bin/env ruby if ARGV[0] == "-c" out_stdout = 1 ARGV.shift end $sawbegin = 0 $sawend = 0 while line = gets() if /^begin\s*(\d*)\s*(\S*)/ =~ line $mode, $file = $1, $2 $sawbegin+=1 if out_stdout out = STDOUT else out = open($file, "w") if $file != "" end out.binmode ...
Ruby
#! ./ruby # split into multi part # usage: mpart.rb [-nnn] file.. lines = 1000 if (ARGV[0] =~ /^-(\d+)$/ ) lines = $1.to_i; ARGV.shift; end basename = ARGV[0] extname = "part" part = 1 line = 0 fline = 0 for i in ifp = open(basename) fline = fline + 1 end ifp.close parts = fline / lines + 1 for i in ifp = ...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. class Subtracter def initialize(number) @number = number end def subtract(number) return @number - number end end
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'tc_adder' require 'tc_subtracter'
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'adder' class TC_Adder < Test::Unit::TestCase def setup @adder = Adder.new(5) end def test_add assert_equal(7, @adder.add(2), "Should have add...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. require 'test/unit' require 'subtracter' class TC_Subtracter < Test::Unit::TestCase def setup @subtracter = Subtracter.new(5) end def test_subtract assert_equal(3, @subtr...
Ruby
# Author:: Nathaniel Talbott. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. class Adder def initialize(number) @number = number end def add(number) return @number + number end end
Ruby
# Linked list example -- short version # using inspect class Point def initialize(x, y) @x = x; @y = y self end def to_s sprintf("%d@%d", @x, @y) end end list1 = [10, 20, Point.new(2, 3), Point.new(4, 5)] list2 = [20, Point.new(4, 5), list1] print("list1: ", list1.inspect, "\n") print("list2:...
Ruby
# ioctl example works on Sun CBREAK = 0x00000002 ECHO = 0x00000008 TIOCGETP = 0x40067408 TIOCSETP = 0x80067409 def cbreak () set_cbreak(true) end def cooked () set_cbreak(false) end def set_cbreak (on) tty = "\0" * 256 STDIN.ioctl(TIOCGETP, tty) ttys = tty.unpack("C4 S") if on ttys[4] |= CBREAK ...
Ruby
# simple httpd # The code demonstrates how a multi-protocol daemon should be written. require "socket" require "thread" port = 8888 res = Socket.getaddrinfo(nil, port, nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE) sockpool = [] names = [] threads = [] res.each do |i| s = TCPserver.new(i[3], i[1]) n = Socke...
Ruby
#!/usr/local/bin/ruby # # biorhythm.rb - # $Release Version: $ # $Revision: 11708 $ # $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $ # by Yasuo OHBA(STAFS Development Room) # # -- # # # # probably based...
Ruby
# calculate Fibonacci(20) # for benchmark def fib(n) if n<2 n else fib(n-2)+fib(n-1) end end print(fib(20), "\n");
Ruby
# socket example - client side # usage: ruby clnt.rb [host] port require "socket" if ARGV.length >= 2 host = ARGV.shift else host = "localhost" end print("Trying ", host, " ...") STDOUT.flush s = TCPSocket.open(host, ARGV.shift) print(" done\n") print("addr: ", s.addr.join(":"), "\n") print("peer: ", s.peeraddr.j...
Ruby
require "pp" module DemoApplication def initialize(config, enctype) super @enctype = enctype end def do_GET(req, res) if req.path_info != "/" res.set_redirect(WEBrick::HTTPStatus::Found, req.script_name + "/") end res.body =<<-_end_of_html_ <HTML> <FORM method="POST" encty...
Ruby
#!/usr/bin/env ruby require "webrick/cgi" require "webrick/https" # should load if it runs on HTTPS server require "./demo-app" class DemoCGI < WEBrick::CGI include DemoApplication end config = { :NPH => false } cgi = DemoCGI.new(config, "multipart/form-data") cgi.start
Ruby
require "webrick" class HelloServlet < WEBrick::HTTPServlet::AbstractServlet def do_GET(req, res) res["content-type"] = "text/plain" res.body = "Hello, world.\n" end end
Ruby
require "webrick" httpd = WEBrick::HTTPServer.new( :DocumentRoot => File::dirname(__FILE__), :Port => 10080, :Logger => WEBrick::Log.new($stderr, WEBrick::Log::DEBUG), :AccessLog => [ [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ], [ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT...
Ruby
#!/usr/bin/env ruby require "webrick/cgi" require "webrick/https" # should load if it runs on HTTPS server require "./demo-app" class DemoCGI < WEBrick::CGI include DemoApplication end config = { :NPH => false } cgi = DemoCGI.new(config, "application/x-www-form-urlencoded") cgi.start
Ruby
require "webrick" require "webrick/https" hostname = WEBrick::Utils::getservername subject = [["O", "ruby-lang.org"], ["OU", "sample"], ["CN", hostname]] comment = "Comment for self-signed certificate" httpd = WEBrick::HTTPServer.new( :DocumentRoot => File::dirname(__FILE__), :Port => 10443, :SSLEna...
Ruby
require "webrick" require "./demo-app" class DemoServlet < WEBrick::HTTPServlet::AbstractServlet include DemoApplication end
Ruby
require "webrick" require "webrick/httpproxy" # :ProxyContentHandler will be invoked before sending # response to User-Agenge. You can inspect the pair of # request and response messages (or can edit the response # message if necessary). pch = Proc.new{|req, res| p [ req.request_line, res.status_line ] } def upstr...
Ruby
#!/usr/bin/env ruby require "webrick/cgi" class HelloCGI < WEBrick::CGI def do_GET(req, res) res["content-type"] = "text/plain" res.body = "Hello, world.\n" end end HelloCGI.new.start
Ruby
# sieve of Eratosthenes max = Integer(ARGV.shift || 100) sieve = [] for i in 2 .. max sieve[i] = i end for i in 2 .. Math.sqrt(max) next unless sieve[i] (i*i).step(max, i) do |j| sieve[j] = nil end end puts sieve.compact.join(", ")
Ruby
#! /usr/local/bin/ruby require "parsedate" require "kconv" require "mailread" include ParseDate include Kconv class String def kconv(code = Kconv::EUC) Kconv.kconv(self, code, Kconv::AUTO) end def kjust(len) len += 1 me = self[0, len].ljust(len) if me =~ /.$/ and $&.size == 2 me[-2..-1]...
Ruby
#!/usr/bin/env ruby require 'logger' log = Logger.new(STDERR) def do_log(log) log.debug('do_log1') { "debug" } log.info('do_log2') { "info" } log.warn('do_log3') { "warn" } log.error('do_log4') { "error" } log.fatal('do_log6') { "fatal" } log.unknown('do_log7') { "unknown" } end log.level = Logger::DEBU...
Ruby
#!/usr/bin/env ruby require 'logger' class MyApp < Logger::Application def initialize(a, b, c) super('MyApp') # Set logDevice here. logfile = 'app.log' self.log = logfile self.level = INFO # Initialize your application... @a = a @b = b @c = c end def run @log.info { '...
Ruby