knjrbfw 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/knj/.gitignore +1 -0
- data/lib/knj/arrayext.rb +157 -0
- data/lib/knj/autoload/activesupport.rb +2 -0
- data/lib/knj/autoload/backups/facets_dictionary.rb +430 -0
- data/lib/knj/autoload/backups/parsedate.rb +53 -0
- data/lib/knj/autoload/backups/ping.rb +64 -0
- data/lib/knj/autoload/cinch.rb +2 -0
- data/lib/knj/autoload/erubis.rb +6 -0
- data/lib/knj/autoload/facebooker.rb +3 -0
- data/lib/knj/autoload/facets_dictionary.rb +7 -0
- data/lib/knj/autoload/gd2.rb +2 -0
- data/lib/knj/autoload/gettext.rb +9 -0
- data/lib/knj/autoload/gtk2.rb +5 -0
- data/lib/knj/autoload/json_autoload.rb +7 -0
- data/lib/knj/autoload/magick.rb +6 -0
- data/lib/knj/autoload/mysql.rb +6 -0
- data/lib/knj/autoload/parsedate.rb +1 -0
- data/lib/knj/autoload/ping.rb +64 -0
- data/lib/knj/autoload/rexml.rb +12 -0
- data/lib/knj/autoload/soap.rb +3 -0
- data/lib/knj/autoload/sqlite3.rb +6 -0
- data/lib/knj/autoload/tmail.rb +6 -0
- data/lib/knj/autoload/twitter.rb +2 -0
- data/lib/knj/autoload/xmlsimple.rb +6 -0
- data/lib/knj/autoload/zip.rb +6 -0
- data/lib/knj/autoload.rb +136 -0
- data/lib/knj/compiler.rb +53 -0
- data/lib/knj/cpufreq.rb +40 -0
- data/lib/knj/datarow.rb +256 -0
- data/lib/knj/datestamp.rb +91 -0
- data/lib/knj/datet.rb +448 -0
- data/lib/knj/degulesider.rb +46 -0
- data/lib/knj/erb/apache_knjerb.conf +8 -0
- data/lib/knj/erb/cache/README +1 -0
- data/lib/knj/erb/erb.rb +21 -0
- data/lib/knj/erb/erb_1.9.rb +13 -0
- data/lib/knj/erb/erb_cache_clean.rb +20 -0
- data/lib/knj/erb/erb_fcgi.rb +44 -0
- data/lib/knj/erb/erb_fcgi_1.9.rb +44 -0
- data/lib/knj/erb/erb_fcgi_jruby.rb +7 -0
- data/lib/knj/erb/erb_jruby.rb +22 -0
- data/lib/knj/erb/include.rb +248 -0
- data/lib/knj/errors.rb +19 -0
- data/lib/knj/eruby.rb +224 -0
- data/lib/knj/event_filemod.rb +53 -0
- data/lib/knj/event_handler.rb +69 -0
- data/lib/knj/exchangerates.rb +39 -0
- data/lib/knj/ext/webrick.rb +31 -0
- data/lib/knj/filesystem.rb +8 -0
- data/lib/knj/fs/drivers/filesystem.rb +14 -0
- data/lib/knj/fs/drivers/ftp.rb +33 -0
- data/lib/knj/fs/drivers/ssh.rb +28 -0
- data/lib/knj/fs/fs.rb +36 -0
- data/lib/knj/gettext_fallback.rb +17 -0
- data/lib/knj/gettext_threadded.rb +77 -0
- data/lib/knj/google_sitemap.rb +59 -0
- data/lib/knj/gtk2.rb +277 -0
- data/lib/knj/gtk2_cb.rb +85 -0
- data/lib/knj/gtk2_menu.rb +57 -0
- data/lib/knj/gtk2_statuswindow.rb +64 -0
- data/lib/knj/gtk2_tv.rb +63 -0
- data/lib/knj/hash_methods.rb +37 -0
- data/lib/knj/http.rb +190 -0
- data/lib/knj/includes/appserver_cli.rb +39 -0
- data/lib/knj/ip2location.rb +22 -0
- data/lib/knj/ironruby-gtk2/button.rb +19 -0
- data/lib/knj/ironruby-gtk2/dialog.rb +44 -0
- data/lib/knj/ironruby-gtk2/entry.rb +9 -0
- data/lib/knj/ironruby-gtk2/gdk_event.rb +3 -0
- data/lib/knj/ironruby-gtk2/gdk_eventbutton.rb +13 -0
- data/lib/knj/ironruby-gtk2/gdk_pixbuf.rb +11 -0
- data/lib/knj/ironruby-gtk2/gladexml.rb +104 -0
- data/lib/knj/ironruby-gtk2/glib.rb +15 -0
- data/lib/knj/ironruby-gtk2/gtk2.rb +148 -0
- data/lib/knj/ironruby-gtk2/gtk_builder.rb +31 -0
- data/lib/knj/ironruby-gtk2/gtk_cellrenderertext.rb +5 -0
- data/lib/knj/ironruby-gtk2/gtk_combobox.rb +19 -0
- data/lib/knj/ironruby-gtk2/gtk_filechooserbutton.rb +5 -0
- data/lib/knj/ironruby-gtk2/gtk_liststore.rb +18 -0
- data/lib/knj/ironruby-gtk2/gtk_menu.rb +5 -0
- data/lib/knj/ironruby-gtk2/gtk_menuitem.rb +7 -0
- data/lib/knj/ironruby-gtk2/gtk_statusicon.rb +8 -0
- data/lib/knj/ironruby-gtk2/gtk_treeiter.rb +24 -0
- data/lib/knj/ironruby-gtk2/gtk_treeselection.rb +16 -0
- data/lib/knj/ironruby-gtk2/gtk_treeview.rb +19 -0
- data/lib/knj/ironruby-gtk2/gtk_treeviewcolumn.rb +32 -0
- data/lib/knj/ironruby-gtk2/iconsize.rb +3 -0
- data/lib/knj/ironruby-gtk2/image.rb +15 -0
- data/lib/knj/ironruby-gtk2/label.rb +19 -0
- data/lib/knj/ironruby-gtk2/stock.rb +4 -0
- data/lib/knj/ironruby-gtk2/tests/test.glade +15 -0
- data/lib/knj/ironruby-gtk2/tests/test_2.rb +22 -0
- data/lib/knj/ironruby-gtk2/tests/test_ironruby_window.rb +47 -0
- data/lib/knj/ironruby-gtk2/vbox.rb +5 -0
- data/lib/knj/ironruby-gtk2/window.rb +23 -0
- data/lib/knj/jruby-gtk2/builder/test_builder.glade +43 -0
- data/lib/knj/jruby-gtk2/builder/test_builder.rb +19 -0
- data/lib/knj/jruby-gtk2/builder/test_builder.ui +43 -0
- data/lib/knj/jruby-gtk2/builder.rb +27 -0
- data/lib/knj/jruby-gtk2/cellrenderertext.rb +12 -0
- data/lib/knj/jruby-gtk2/checkbutton.rb +3 -0
- data/lib/knj/jruby-gtk2/combobox.rb +29 -0
- data/lib/knj/jruby-gtk2/dialog.rb +44 -0
- data/lib/knj/jruby-gtk2/eventbutton.rb +21 -0
- data/lib/knj/jruby-gtk2/gladexml.rb +99 -0
- data/lib/knj/jruby-gtk2/gtk-4.0.jar +0 -0
- data/lib/knj/jruby-gtk2/gtk2.rb +246 -0
- data/lib/knj/jruby-gtk2/hbox.rb +10 -0
- data/lib/knj/jruby-gtk2/iconsize.rb +5 -0
- data/lib/knj/jruby-gtk2/image.rb +10 -0
- data/lib/knj/jruby-gtk2/liststore.rb +56 -0
- data/lib/knj/jruby-gtk2/menu.rb +40 -0
- data/lib/knj/jruby-gtk2/progressbar.rb +12 -0
- data/lib/knj/jruby-gtk2/statusicon.rb +8 -0
- data/lib/knj/jruby-gtk2/stock.rb +8 -0
- data/lib/knj/jruby-gtk2/tests/test_glade_window.glade +163 -0
- data/lib/knj/jruby-gtk2/tests/test_glade_window.rb +47 -0
- data/lib/knj/jruby-gtk2/tests/test_normal_window.rb +17 -0
- data/lib/knj/jruby-gtk2/tests/test_trayicon.png +0 -0
- data/lib/knj/jruby-gtk2/tests/test_trayicon.rb +18 -0
- data/lib/knj/jruby-gtk2/treeview.rb +105 -0
- data/lib/knj/jruby-gtk2/vbox.rb +12 -0
- data/lib/knj/jruby-gtk2/window.rb +11 -0
- data/lib/knj/jruby_compiler.rb +14 -0
- data/lib/knj/knj.rb +19 -0
- data/lib/knj/knj_controller.rb +13 -0
- data/lib/knj/knjdb/dbtime.rb +30 -0
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +327 -0
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb +130 -0
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb +30 -0
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +255 -0
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +93 -0
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +151 -0
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb +29 -0
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +300 -0
- data/lib/knj/knjdb/libknjdb.rb +438 -0
- data/lib/knj/knjdb/libknjdb_java_sqlite3.rb +83 -0
- data/lib/knj/knjdb/libknjdb_row.rb +149 -0
- data/lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb +69 -0
- data/lib/knj/knjdb/mysql-connector-java-5.1.13-bin.jar +0 -0
- data/lib/knj/knjdb/sqlitejdbc-v056.jar +0 -0
- data/lib/knj/libqt.rb +75 -0
- data/lib/knj/libqt_window.rb +10 -0
- data/lib/knj/locale_strings.rb +3 -0
- data/lib/knj/locales.rb +54 -0
- data/lib/knj/maemo/fremantle-calendar/fremantle-calendar.rb +56 -0
- data/lib/knj/mail.rb +75 -0
- data/lib/knj/mailobj.rb +82 -0
- data/lib/knj/mount.rb +115 -0
- data/lib/knj/notify.rb +13 -0
- data/lib/knj/nvidia_settings.rb +45 -0
- data/lib/knj/objects.rb +731 -0
- data/lib/knj/opts.rb +38 -0
- data/lib/knj/os.rb +158 -0
- data/lib/knj/php.rb +717 -0
- data/lib/knj/php_parser/arguments.rb +5 -0
- data/lib/knj/php_parser/functions.rb +97 -0
- data/lib/knj/php_parser/php_parser.rb +99 -0
- data/lib/knj/php_parser/tests/test.rb +12 -0
- data/lib/knj/php_parser/tests/test_function.php +8 -0
- data/lib/knj/php_parser/tests/test_function_run.rb +19 -0
- data/lib/knj/power_manager.rb +31 -0
- data/lib/knj/rand.rb +10 -0
- data/lib/knj/retry.rb +71 -0
- data/lib/knj/rhodes/mutex.rb +11 -0
- data/lib/knj/rhodes/rhodes.js +3 -0
- data/lib/knj/rhodes/rhodes.rb +11 -0
- data/lib/knj/rsvgbin.rb +20 -0
- data/lib/knj/scripts/degulesider.rb +12 -0
- data/lib/knj/scripts/filesearch.rb +51 -0
- data/lib/knj/scripts/ip2location.rb +12 -0
- data/lib/knj/scripts/keepalive.rb +6 -0
- data/lib/knj/scripts/svn_merge.rb +29 -0
- data/lib/knj/scripts/upgrade_knjrbfw_checker.rb +41 -0
- data/lib/knj/sms.rb +54 -0
- data/lib/knj/sshrobot/sshrobot.rb +93 -0
- data/lib/knj/strings.rb +65 -0
- data/lib/knj/sysuser.rb +27 -0
- data/lib/knj/tests/compiler/compiler_test.rb +13 -0
- data/lib/knj/tests/compiler/compiler_test_file.rb +62 -0
- data/lib/knj/tests/test_degulesider.rb +11 -0
- data/lib/knj/tests/test_mount.rb +30 -0
- data/lib/knj/tests/test_retry.rb +30 -0
- data/lib/knj/thread.rb +32 -0
- data/lib/knj/thread2.rb +47 -0
- data/lib/knj/threadhandler.rb +130 -0
- data/lib/knj/threadpool.rb +177 -0
- data/lib/knj/translations.rb +139 -0
- data/lib/knj/unix_proc.rb +82 -0
- data/lib/knj/web.rb +932 -0
- data/lib/knj/webscripts/image.rhtml +82 -0
- data/lib/knj/win.rb +4 -0
- data/lib/knj/win_registry.rb +60 -0
- data/lib/knj/win_tightvnc.rb +127 -0
- data/lib/knj/x11vnc.rb +48 -0
- data/lib/knj/youtube.rb +38 -0
- data/lib/knjrbfw.rb +4 -0
- data/spec/knjrbfw_spec.rb +269 -0
- data/spec/spec_helper.rb +12 -0
- metadata +336 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
# = Dictionary.rb
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2005, 2009 Jan Molic, Thomas Sawyer
|
|
4
|
+
#
|
|
5
|
+
# Ruby License
|
|
6
|
+
#
|
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
|
8
|
+
# software under the same terms as Ruby.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
|
13
|
+
#
|
|
14
|
+
# == Acknowledgments
|
|
15
|
+
#
|
|
16
|
+
# * Andrew Johnson (merge, to_a, inspect, shift and Hash[])
|
|
17
|
+
# * Jeff Sharpe (reverse and reverse!)
|
|
18
|
+
# * Thomas Leitner (has_key? and key?)
|
|
19
|
+
#
|
|
20
|
+
# Ported from OrderHash 2.0, Copyright (c) 2005 Jan Molic
|
|
21
|
+
|
|
22
|
+
# = Dictionary
|
|
23
|
+
#
|
|
24
|
+
# The Dictionary class is a Hash that preserves order.
|
|
25
|
+
# So it has some array-like extensions also. By defualt
|
|
26
|
+
# a Dictionary object preserves insertion order, but any
|
|
27
|
+
# order can be specified including alphabetical key order.
|
|
28
|
+
#
|
|
29
|
+
# == Usage
|
|
30
|
+
#
|
|
31
|
+
# Just require this file and use Dictionary instead of Hash.
|
|
32
|
+
#
|
|
33
|
+
# # You can do simply
|
|
34
|
+
# hsh = Dictionary.new
|
|
35
|
+
# hsh['z'] = 1
|
|
36
|
+
# hsh['a'] = 2
|
|
37
|
+
# hsh['c'] = 3
|
|
38
|
+
# p hsh.keys #=> ['z','a','c']
|
|
39
|
+
#
|
|
40
|
+
# # or using Dictionary[] method
|
|
41
|
+
# hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
|
|
42
|
+
# p hsh.keys #=> ['z','a','c']
|
|
43
|
+
#
|
|
44
|
+
# # but this don't preserve order
|
|
45
|
+
# hsh = Dictionary['z'=>1, 'a'=>2, 'c'=>3]
|
|
46
|
+
# p hsh.keys #=> ['a','c','z']
|
|
47
|
+
#
|
|
48
|
+
# # Dictionary has useful extensions: push, pop and unshift
|
|
49
|
+
# p hsh.push('to_end', 15) #=> true, key added
|
|
50
|
+
# p hsh.push('to_end', 30) #=> false, already - nothing happen
|
|
51
|
+
# p hsh.unshift('to_begin', 50) #=> true, key added
|
|
52
|
+
# p hsh.unshift('to_begin', 60) #=> false, already - nothing happen
|
|
53
|
+
# p hsh.keys #=> ["to_begin", "a", "c", "z", "to_end"]
|
|
54
|
+
# p hsh.pop #=> ["to_end", 15], if nothing remains, return nil
|
|
55
|
+
# p hsh.keys #=> ["to_begin", "a", "c", "z"]
|
|
56
|
+
# p hsh.shift #=> ["to_begin", 30], if nothing remains, return nil
|
|
57
|
+
#
|
|
58
|
+
# == Usage Notes
|
|
59
|
+
#
|
|
60
|
+
# * You can use #order_by to set internal sort order.
|
|
61
|
+
# * #<< takes a two element [k,v] array and inserts.
|
|
62
|
+
# * Use ::auto which creates Dictionay sub-entries as needed.
|
|
63
|
+
# * And ::alpha which creates a new Dictionary sorted by key.
|
|
64
|
+
#
|
|
65
|
+
class Dictionary
|
|
66
|
+
|
|
67
|
+
include Enumerable
|
|
68
|
+
|
|
69
|
+
class << self
|
|
70
|
+
#--
|
|
71
|
+
# TODO is this needed? Doesn't the super class do this?
|
|
72
|
+
#++
|
|
73
|
+
|
|
74
|
+
def [](*args)
|
|
75
|
+
hsh = new
|
|
76
|
+
if Hash === args[0]
|
|
77
|
+
hsh.replace(args[0])
|
|
78
|
+
elsif (args.size % 2) != 0
|
|
79
|
+
raise ArgumentError, "odd number of elements for Hash"
|
|
80
|
+
else
|
|
81
|
+
while !args.empty?
|
|
82
|
+
hsh[args.shift] = args.shift
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
hsh
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Like #new but the block sets the order.
|
|
89
|
+
#
|
|
90
|
+
def new_by(*args, &blk)
|
|
91
|
+
new(*args).order_by(&blk)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Alternate to #new which creates a dictionary sorted by key.
|
|
95
|
+
#
|
|
96
|
+
# d = Dictionary.alpha
|
|
97
|
+
# d["z"] = 1
|
|
98
|
+
# d["y"] = 2
|
|
99
|
+
# d["x"] = 3
|
|
100
|
+
# d #=> {"x"=>3,"y"=>2,"z"=>2}
|
|
101
|
+
#
|
|
102
|
+
# This is equivalent to:
|
|
103
|
+
#
|
|
104
|
+
# Dictionary.new.order_by { |key,value| key }
|
|
105
|
+
|
|
106
|
+
def alpha(*args, &block)
|
|
107
|
+
new(*args, &block).order_by_key
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Alternate to #new which auto-creates sub-dictionaries as needed.
|
|
111
|
+
#
|
|
112
|
+
# d = Dictionary.auto
|
|
113
|
+
# d["a"]["b"]["c"] = "abc" #=> { "a"=>{"b"=>{"c"=>"abc"}}}
|
|
114
|
+
#
|
|
115
|
+
def auto(*args)
|
|
116
|
+
#AutoDictionary.new(*args)
|
|
117
|
+
leet = lambda { |hsh, key| hsh[key] = new(&leet) }
|
|
118
|
+
new(*args, &leet)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# New Dictiionary.
|
|
123
|
+
|
|
124
|
+
def initialize(*args, &blk)
|
|
125
|
+
@order = []
|
|
126
|
+
@order_by = nil
|
|
127
|
+
if blk
|
|
128
|
+
dict = self # This ensure autmatic key entry effect the
|
|
129
|
+
oblk = lambda{ |hsh, key| blk[dict,key] } # dictionary rather then just the interal hash.
|
|
130
|
+
@hash = Hash.new(*args, &oblk)
|
|
131
|
+
else
|
|
132
|
+
@hash = Hash.new(*args)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def order
|
|
137
|
+
reorder if @order_by
|
|
138
|
+
@order
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Keep dictionary sorted by a specific sort order.
|
|
142
|
+
|
|
143
|
+
def order_by( &block )
|
|
144
|
+
@order_by = block
|
|
145
|
+
order
|
|
146
|
+
self
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Keep dictionary sorted by key.
|
|
150
|
+
#
|
|
151
|
+
# d = Dictionary.new.order_by_key
|
|
152
|
+
# d["z"] = 1
|
|
153
|
+
# d["y"] = 2
|
|
154
|
+
# d["x"] = 3
|
|
155
|
+
# d #=> {"x"=>3,"y"=>2,"z"=>2}
|
|
156
|
+
#
|
|
157
|
+
# This is equivalent to:
|
|
158
|
+
#
|
|
159
|
+
# Dictionary.new.order_by { |key,value| key }
|
|
160
|
+
#
|
|
161
|
+
# The initializer Dictionary#alpha also provides this.
|
|
162
|
+
|
|
163
|
+
def order_by_key
|
|
164
|
+
@order_by = lambda { |k,v| k }
|
|
165
|
+
order
|
|
166
|
+
self
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Keep dictionary sorted by value.
|
|
170
|
+
#
|
|
171
|
+
# d = Dictionary.new.order_by_value
|
|
172
|
+
# d["z"] = 1
|
|
173
|
+
# d["y"] = 2
|
|
174
|
+
# d["x"] = 3
|
|
175
|
+
# d #=> {"x"=>3,"y"=>2,"z"=>2}
|
|
176
|
+
#
|
|
177
|
+
# This is equivalent to:
|
|
178
|
+
#
|
|
179
|
+
# Dictionary.new.order_by { |key,value| value }
|
|
180
|
+
|
|
181
|
+
def order_by_value
|
|
182
|
+
@order_by = lambda { |k,v| v }
|
|
183
|
+
order
|
|
184
|
+
self
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
def reorder
|
|
189
|
+
if @order_by
|
|
190
|
+
assoc = @order.collect{ |k| [k,@hash[k]] }.sort_by(&@order_by)
|
|
191
|
+
@order = assoc.collect{ |k,v| k }
|
|
192
|
+
end
|
|
193
|
+
@order
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
#def ==( hsh2 )
|
|
197
|
+
# return false if @order != hsh2.order
|
|
198
|
+
# super hsh2
|
|
199
|
+
#end
|
|
200
|
+
|
|
201
|
+
def ==(hsh2)
|
|
202
|
+
if hsh2.is_a?( Dictionary )
|
|
203
|
+
@order == hsh2.order &&
|
|
204
|
+
@hash == hsh2.instance_variable_get("@hash")
|
|
205
|
+
else
|
|
206
|
+
false
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def [] k
|
|
211
|
+
@hash[ k ]
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def fetch(k, *a, &b)
|
|
215
|
+
@hash.fetch(k, *a, &b)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Store operator.
|
|
219
|
+
#
|
|
220
|
+
# h[key] = value
|
|
221
|
+
#
|
|
222
|
+
# Or with additional index.
|
|
223
|
+
#
|
|
224
|
+
# h[key,index] = value
|
|
225
|
+
|
|
226
|
+
def []=(k, i=nil, v=nil)
|
|
227
|
+
if v
|
|
228
|
+
insert(i,k,v)
|
|
229
|
+
else
|
|
230
|
+
store(k,i)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def insert( i,k,v )
|
|
235
|
+
@order.insert( i,k )
|
|
236
|
+
@hash.store( k,v )
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def store( a,b )
|
|
240
|
+
@order.push( a ) unless @hash.has_key?( a )
|
|
241
|
+
@hash.store( a,b )
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def clear
|
|
245
|
+
@order = []
|
|
246
|
+
@hash.clear
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def delete( key )
|
|
250
|
+
@order.delete( key )
|
|
251
|
+
@hash.delete( key )
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def each_key
|
|
255
|
+
order.each { |k| yield( k ) }
|
|
256
|
+
self
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def each_value
|
|
260
|
+
order.each { |k| yield( @hash[k] ) }
|
|
261
|
+
self
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def each
|
|
265
|
+
order.each { |k| yield( k,@hash[k] ) }
|
|
266
|
+
self
|
|
267
|
+
end
|
|
268
|
+
alias each_pair each
|
|
269
|
+
|
|
270
|
+
def delete_if
|
|
271
|
+
order.clone.each { |k| delete k if yield(k,@hash[k]) }
|
|
272
|
+
self
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def values
|
|
276
|
+
ary = []
|
|
277
|
+
order.each { |k| ary.push @hash[k] }
|
|
278
|
+
ary
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def keys
|
|
282
|
+
order
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def invert
|
|
286
|
+
hsh2 = self.class.new
|
|
287
|
+
order.each { |k| hsh2[@hash[k]] = k }
|
|
288
|
+
hsh2
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def reject(&block)
|
|
292
|
+
self.dup.delete_if(&block)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def reject!( &block )
|
|
296
|
+
hsh2 = reject(&block)
|
|
297
|
+
self == hsh2 ? nil : hsh2
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def replace(hsh2)
|
|
301
|
+
case hsh2
|
|
302
|
+
when Hash
|
|
303
|
+
@order = hsh2.keys
|
|
304
|
+
@hash = hsh2
|
|
305
|
+
else
|
|
306
|
+
@order = hsh2.order
|
|
307
|
+
@hash = hsh2.hash
|
|
308
|
+
end
|
|
309
|
+
reorder
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def shift
|
|
313
|
+
key = order.first
|
|
314
|
+
key ? [key,delete(key)] : super
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def unshift( k,v )
|
|
318
|
+
unless @hash.include?( k )
|
|
319
|
+
@order.unshift( k )
|
|
320
|
+
@hash.store( k,v )
|
|
321
|
+
true
|
|
322
|
+
else
|
|
323
|
+
false
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def <<(kv)
|
|
328
|
+
push(*kv)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def push( k,v )
|
|
332
|
+
unless @hash.include?( k )
|
|
333
|
+
@order.push( k )
|
|
334
|
+
@hash.store( k,v )
|
|
335
|
+
true
|
|
336
|
+
else
|
|
337
|
+
false
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def pop
|
|
342
|
+
key = order.last
|
|
343
|
+
key ? [key,delete(key)] : nil
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def inspect
|
|
347
|
+
ary = []
|
|
348
|
+
each {|k,v| ary << k.inspect + "=>" + v.inspect}
|
|
349
|
+
'{' + ary.join(", ") + '}'
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
def dup
|
|
353
|
+
a = []
|
|
354
|
+
each{ |k,v| a << k; a << v }
|
|
355
|
+
self.class[*a]
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def update( hsh2 )
|
|
359
|
+
hsh2.each { |k,v| self[k] = v }
|
|
360
|
+
reorder
|
|
361
|
+
self
|
|
362
|
+
end
|
|
363
|
+
alias :merge! update
|
|
364
|
+
|
|
365
|
+
def merge( hsh2 )
|
|
366
|
+
self.dup.update(hsh2)
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def select
|
|
370
|
+
ary = []
|
|
371
|
+
each { |k,v| ary << [k,v] if yield k,v }
|
|
372
|
+
ary
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def reverse!
|
|
376
|
+
@order.reverse!
|
|
377
|
+
self
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
def reverse
|
|
381
|
+
dup.reverse!
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
#
|
|
385
|
+
def first(x=nil)
|
|
386
|
+
return @hash[order.first] unless x
|
|
387
|
+
order.first(x).collect { |k| @hash[k] }
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
#
|
|
391
|
+
def last(x=nil)
|
|
392
|
+
return @hash[order.last] unless x
|
|
393
|
+
order.last(x).collect { |k| @hash[k] }
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def length
|
|
397
|
+
@order.length
|
|
398
|
+
end
|
|
399
|
+
alias :size :length
|
|
400
|
+
|
|
401
|
+
def empty?
|
|
402
|
+
@hash.empty?
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
def has_key?(key)
|
|
406
|
+
@hash.has_key?(key)
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
def key?(key)
|
|
410
|
+
@hash.key?(key)
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
def to_a
|
|
414
|
+
ary = []
|
|
415
|
+
each { |k,v| ary << [k,v] }
|
|
416
|
+
ary
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def to_s
|
|
420
|
+
self.to_a.to_s
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
def to_hash
|
|
424
|
+
@hash.dup
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def to_h
|
|
428
|
+
@hash.dup
|
|
429
|
+
end
|
|
430
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#
|
|
2
|
+
# = parsedate.rb: Parses dates
|
|
3
|
+
#
|
|
4
|
+
# Author:: Tadayoshi Funaba
|
|
5
|
+
# Documentation:: Konrad Meyer
|
|
6
|
+
#
|
|
7
|
+
# ParseDate munches on a date and turns it into an array of values.
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# ParseDate converts a date into an array of values.
|
|
12
|
+
# For example:
|
|
13
|
+
#
|
|
14
|
+
# require 'parsedate'
|
|
15
|
+
#
|
|
16
|
+
# ParseDate.parsedate "Tuesday, July 6th, 2007, 18:35:20 UTC"
|
|
17
|
+
# # => [2007, 7, 6, 18, 35, 20, "UTC", 2]
|
|
18
|
+
#
|
|
19
|
+
# The order is of the form [year, month, day of month, hour, minute, second,
|
|
20
|
+
# timezone, day of the week].
|
|
21
|
+
|
|
22
|
+
require 'date/format'
|
|
23
|
+
|
|
24
|
+
module ParseDate
|
|
25
|
+
#
|
|
26
|
+
# Parse a string representation of a date into values.
|
|
27
|
+
# For example:
|
|
28
|
+
#
|
|
29
|
+
# require 'parsedate'
|
|
30
|
+
#
|
|
31
|
+
# ParseDate.parsedate "Tuesday, July 5th, 2007, 18:35:20 UTC"
|
|
32
|
+
# # => [2007, 7, 5, 18, 35, 20, "UTC", 2]
|
|
33
|
+
#
|
|
34
|
+
# The order is of the form [year, month, day of month, hour, minute,
|
|
35
|
+
# second, timezone, day of week].
|
|
36
|
+
#
|
|
37
|
+
# ParseDate.parsedate can also take a second argument, +comp+, which
|
|
38
|
+
# is a boolean telling the method to compensate for dates with years
|
|
39
|
+
# expressed as two digits. Example:
|
|
40
|
+
#
|
|
41
|
+
# require 'parsedate'
|
|
42
|
+
#
|
|
43
|
+
# ParseDate.parsedate "Mon Dec 25 00 06:53:24 UTC", true
|
|
44
|
+
# # => [2000, 12, 25, 6, 53, 24, "UTC", 1]
|
|
45
|
+
#
|
|
46
|
+
def parsedate(str, comp=false)
|
|
47
|
+
Date._parse(str, comp).
|
|
48
|
+
values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
module_function :parsedate
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# = ping.rb: Check a host for upness
|
|
3
|
+
#
|
|
4
|
+
# Author:: Yukihiro Matsumoto
|
|
5
|
+
# Documentation:: Konrad Meyer
|
|
6
|
+
#
|
|
7
|
+
# Performs the function of the basic network testing tool, ping.
|
|
8
|
+
# See: Ping.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require 'timeout'
|
|
12
|
+
require "socket"
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Ping contains routines to test for the reachability of remote hosts.
|
|
16
|
+
# Currently the only routine implemented is pingecho().
|
|
17
|
+
#
|
|
18
|
+
# Ping.pingecho uses a TCP echo (not an ICMP echo) to determine if the
|
|
19
|
+
# remote host is reachable. This is usually adequate to tell that a remote
|
|
20
|
+
# host is available to telnet, ftp, or ssh to.
|
|
21
|
+
#
|
|
22
|
+
# Warning: Ping.pingecho may block for a long time if DNS resolution is
|
|
23
|
+
# slow. Requiring 'resolv-replace' allows non-blocking name resolution.
|
|
24
|
+
#
|
|
25
|
+
# Usage:
|
|
26
|
+
#
|
|
27
|
+
# require 'ping'
|
|
28
|
+
#
|
|
29
|
+
# puts "'jimmy' is alive and kicking" if Ping.pingecho('jimmy', 10)
|
|
30
|
+
#
|
|
31
|
+
module Ping
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# Return true if we can open a connection to the hostname or IP address
|
|
35
|
+
# +host+ on port +service+ (which defaults to the "echo" port) waiting up
|
|
36
|
+
# to +timeout+ seconds.
|
|
37
|
+
#
|
|
38
|
+
# Example:
|
|
39
|
+
#
|
|
40
|
+
# require 'ping'
|
|
41
|
+
#
|
|
42
|
+
# Ping.pingecho "google.com", 10, 80
|
|
43
|
+
#
|
|
44
|
+
def pingecho(host, timeout=5, service="echo")
|
|
45
|
+
begin
|
|
46
|
+
timeout(timeout) do
|
|
47
|
+
s = TCPSocket.new(host, service)
|
|
48
|
+
s.close
|
|
49
|
+
end
|
|
50
|
+
rescue Errno::ECONNREFUSED
|
|
51
|
+
return true
|
|
52
|
+
rescue Timeout::Error, StandardError
|
|
53
|
+
return false
|
|
54
|
+
end
|
|
55
|
+
return true
|
|
56
|
+
end
|
|
57
|
+
module_function :pingecho
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if $0 == __FILE__
|
|
61
|
+
host = ARGV[0]
|
|
62
|
+
host ||= "localhost"
|
|
63
|
+
printf("%s alive? - %s\n", host, Ping::pingecho(host, 5))
|
|
64
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "/backups/parsedate.rb"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#
|
|
2
|
+
# = ping.rb: Check a host for upness
|
|
3
|
+
#
|
|
4
|
+
# Author:: Yukihiro Matsumoto
|
|
5
|
+
# Documentation:: Konrad Meyer
|
|
6
|
+
#
|
|
7
|
+
# Performs the function of the basic network testing tool, ping.
|
|
8
|
+
# See: Ping.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require 'timeout'
|
|
12
|
+
require "socket"
|
|
13
|
+
|
|
14
|
+
#
|
|
15
|
+
# Ping contains routines to test for the reachability of remote hosts.
|
|
16
|
+
# Currently the only routine implemented is pingecho().
|
|
17
|
+
#
|
|
18
|
+
# Ping.pingecho uses a TCP echo (not an ICMP echo) to determine if the
|
|
19
|
+
# remote host is reachable. This is usually adequate to tell that a remote
|
|
20
|
+
# host is available to telnet, ftp, or ssh to.
|
|
21
|
+
#
|
|
22
|
+
# Warning: Ping.pingecho may block for a long time if DNS resolution is
|
|
23
|
+
# slow. Requiring 'resolv-replace' allows non-blocking name resolution.
|
|
24
|
+
#
|
|
25
|
+
# Usage:
|
|
26
|
+
#
|
|
27
|
+
# require 'ping'
|
|
28
|
+
#
|
|
29
|
+
# puts "'jimmy' is alive and kicking" if Ping.pingecho('jimmy', 10)
|
|
30
|
+
#
|
|
31
|
+
module Ping
|
|
32
|
+
|
|
33
|
+
#
|
|
34
|
+
# Return true if we can open a connection to the hostname or IP address
|
|
35
|
+
# +host+ on port +service+ (which defaults to the "echo" port) waiting up
|
|
36
|
+
# to +timeout+ seconds.
|
|
37
|
+
#
|
|
38
|
+
# Example:
|
|
39
|
+
#
|
|
40
|
+
# require 'ping'
|
|
41
|
+
#
|
|
42
|
+
# Ping.pingecho "google.com", 10, 80
|
|
43
|
+
#
|
|
44
|
+
def pingecho(host, timeout=5, service="echo")
|
|
45
|
+
begin
|
|
46
|
+
timeout(timeout) do
|
|
47
|
+
s = TCPSocket.new(host, service)
|
|
48
|
+
s.close
|
|
49
|
+
end
|
|
50
|
+
rescue Errno::ECONNREFUSED
|
|
51
|
+
return true
|
|
52
|
+
rescue Timeout::Error, StandardError
|
|
53
|
+
return false
|
|
54
|
+
end
|
|
55
|
+
return true
|
|
56
|
+
end
|
|
57
|
+
module_function :pingecho
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if $0 == __FILE__
|
|
61
|
+
host = ARGV[0]
|
|
62
|
+
host ||= "localhost"
|
|
63
|
+
printf("%s alive? - %s\n", host, Ping::pingecho(host, 5))
|
|
64
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "rexml/rexml"
|
|
2
|
+
|
|
3
|
+
module REXML
|
|
4
|
+
autoload :Document, "rexml/document"
|
|
5
|
+
autoload :ParseException, "rexml/parseexception"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module REXML::Formatters
|
|
9
|
+
autoload :Default, "rexml/formatters/default"
|
|
10
|
+
autoload :Pretty, "rexml/formatters/pretty"
|
|
11
|
+
autoload :Transitive, "rexml/formatters/transitive"
|
|
12
|
+
end
|