Warning: Undefined array key "rss_show_deleted" in /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php on line 86

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 54

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 55

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 56

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/inc/httputils.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/inc/httputils.php on line 33
wi12.unix7.org - ruby https://w12.unix7.org/ Wed, 05 Aug 2026 03:47:12 +0000 FeedCreator 1.8 https://w12.unix7.org/_media/wiki/dokuwiki.svg wi12.unix7.org https://w12.unix7.org/ Address book converter, xml to csv https://w12.unix7.org/ruby/abconv ruby Address book converter, xml to csv Target: convert company address book (more 900 records) for format of new VoIP PBX. #!/usr/bin/env ruby # # $Id$ # require 'nokogiri' require 'json' require 'pp' dir = "orig0" def stripNumber(str) str.sub!(/^[09],,/,'') str.sub!(/^0/,'') str.sub!(/^8/, '7') str.gsub!(/[+-. ()]/, '') str.gsub!(/^([0-9]{6})$/, '74012\1') #9520587264 #1234567890 str.gsub!(/^9([0-9]{9})$/, '79\1') # mark strange number #795205872… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 PBX address book convertor https://w12.unix7.org/ruby/addrconv ruby PBX address book convertor #!/usr/bin/env ruby require 'nokogiri' require 'json' hash = Hash.new begin Dir.open(".").each do | name | next unless name.match('.xml$') next if File.size(name) == 0 doc = Nokogiri::XML(File.open(name)) begin doc.xpath('///c:Name').each do |the| hash['FamilyName'] = the.xpath('c:FamilyName').text hash['GivenName'] = the.xpath('c:GivenName').text end rescue # puts "error #{$!.inspect}" end… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 https://w12.unix7.org/ruby/crtsel ruby # # Author, Copyright: Oleg Borodin <onborodin@gmail.com> # require 'openssl' require 'pg' pghost = "xxxxxxxxx" pguser = "xxxxx" pgpass = "xxxxxx" dbname = "xxxxxxx" conn = PG.connect(host: pghost, dbname: dbname, user: pguser, password: pgpass) puts "%26s %s" % [ "cert name", "not before / not after" ] Dir["/data/xxxxxxxxxxxx/*.crt"].sort.each do |crt_name| raw = File.read crt_name cert = OpenSSL::X509::Certificate.new raw cn = crt_name.gsub "_", " " cn = File.ba… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 JSON RPC daemod on pure Ruby https://w12.unix7.org/ruby/jrpcd ruby JSON RPC daemod on pure Ruby The code work like Perl realize Perl JSON RPC daemon Full source code package placed on <https://github.com/kindsoldier/ruby-jrpcd> #!@ruby@ require 'socket' require 'openssl' require 'time' require 'base64' require 'json' require 'pp' require 'etc' class HTTPServer < TCPServer def initialize(*args) @route = Hash.new @config = Hash.new @config['pidfile'] = "/dev/null" @config['logfile'] = "/dev/null" @config['p… anonymous@undisclosed.example.com (Anonymous) Sat, 05 Feb 2022 08:21:42 +0000 Out https://w12.unix7.org/ruby/object ruby # # Author, Copyright: Oleg Borodin <onborodin@gmail.com> # class Index def initialize @items = Hash.new @sum = 0 end def add(name, cost) if !@items[name] @items[name] = cost @sum += cost end end def delete(name) cost = @items[name] if cost @sum -= cost @items.delete(name) end end def print @items.each do |key, value| puts "item: #{k… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 https://w12.unix7.org/ruby/pg-sample ruby #!/usr/bin/env ruby # # Author, Copyright: Oleg Borodin <onborodin@gmail.com> # require 'pg' class Log def initialize(filename) @log = File.open(filename, 'a') end def puts(string) timestamp = Time.now.getlocal @log.puts "#{timestamp} #{string}" end end hosts = [ 'pgdbxx', 'pgdbxx', 'pgdbxx', 'pgdbxx' ] log = Log.new('dump.log') log.puts("begin") hosts.each do |host| begin conn = PG.connect(host: host, dbname: 'postgres', user: 'xx… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Very simple ruby template for PG https://w12.unix7.org/ruby/pg-tmpl ruby Very simple ruby template for PG * <http://www.rubydoc.info/gems/pg/PG/Connection> #!/usr/bin/env ruby require 'pg' conn = PG.connect(:dbname => "mail") res = conn.exec('select * from alias order by id') res.each do |row| if row['address'].match('unix7') puts row['id'] + "\t" + row['address'].gsub('.pro','.org') end end #EOF anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 https://w12.unix7.org/ruby/r ruby #!/usr/bin/env ruby require 'digest' res = File.open('checker.log', 'a+') res.fsync (1..2).each do (1..1600).each do |num| size = 1024*1024*1024 # 1G mem -> 1G * 100 = 100G disk memory u = File.open('/dev/urandom') i = u.read(size) u.close d1 = Digest::MD5.hexdigest i w = File.open("test#{num}", 'w') w.fsync w.write i w.close r = File.open("test#{num}", 'r') n = r.read(size) d2 = Dige… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Minimal sinatra ruby daemon https://w12.unix7.org/ruby/rubydaemon ruby Minimal sinatra ruby daemon * #!/usr/bin/env ruby require 'json' require 'sinatra/base' require 'logger' require 'pg' class App < Sinatra::Base configure do logfile = File.new("access.log", 'a+') logfile.sync = true use Rack::CommonLogger, logfile end set :public_folder, 'public' set :views, 'tmpl' set :logging, false enable :sessions set :server, "thin" get '/' do erb :index end not_found do erb :n… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Sinatra+Thin ruby daemon, sample https://w12.unix7.org/ruby/rubydaemon2 ruby Sinatra+Thin ruby daemon, sample Target: base for writing “one-two-three-day development” micro web-application. After some days of per-1min-monitoring work good and stable. Short benchmark in bottom the page. Released: * Session authentication with htpassword file anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Very simple mem & fs checker https://w12.unix7.org/ruby/simple-checker ruby Very simple mem & fs checker #!/usr/bin/env ruby require 'digest' res = File.open('checker.log', 'w') res.fsync (1..10000000).each do (1..100).each do |num| size = 1024*1024*1024 # 1G mem -> 1G * 100 = 100G disk memory u = File.open('/dev/urandom') i = u.read(size) u.close d1 = Digest::MD5.hexdigest i w = File.open("test#{num}", 'w') w.fsync w.write i w.close r = File.open("test#{num}", 'r') … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Watch log https://w12.unix7.org/ruby/tail ruby Watch log #!/usr/bin/env ruby require 'sinatra/base' require 'thin' class Tail def initialize(file) @file = file end def first f = File.open(@file,"r") f.seek(-500, :END) f.readline res = String.new f.each do |line| line.chomp! line += '<br/>' line += "\n" res += line end @pos = f.tell f.close res end def last f = File.open(@fi… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Watch tail of file on ruby https://w12.unix7.org/ruby/watchtail ruby Watch tail of file on ruby Two part form for web #!/usr/bin/env ruby file = "/var/log/debug.log" f = File.open(file,"r") # first download of page f.seek(-100, :END) f.readline f.each do |line| print line end current = f.tell f.close # jquery append while true do f = File.open(file, "r") f.seek(current) f.each do | line | print line end current = f.tell f.close sleep 1 end #EOF anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Result https://w12.unix7.org/ruby/xls-to-activerecords ruby # # Author, Copyright: Oleg Borodin <onborodin@gmail.com> # require 'roo' require 'csv' require 'active_record' require 'sqlite3' source_file = 'schedule.xlsx' sheet = Roo::Spreadsheet.open(source_file, extension: :xlsx) sheet.default_sheet = "Кухни" sheet.parse(headers: true, :clean => true) csv_file = "schedule.csv" csv = sheet.to_csv file = File.open(csv_file, "w") file.write csv file.close ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "schedule.sqlite3") … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000