Tag:ruby

  • Give an example to explain the regular expressions in ruby

    Time:2022-5-9

     regular expression Is a special character sequence that can help match or find other strings or strings. The pattern used maintains a special syntax. Regular expression text is a slash between patterns or any separator%r as follows:Syntax:   Copy codeThe code is as follows: /pattern/ /pattern/im    # option can be specified %r!/usr/local! # general delimited […]

  • Introduction to CGI programming with ruby

    Time:2022-5-7

    Write CGI script: The most basicRubyThe CGI script looks like this: ? 1 2 3 4 5 #!/usr/bin/ruby   puts “HTTP/1.0 200 OK” puts “Content-type: text/html\n\n” puts “<html><body>This is a test</body></html>” If you call this script, test If CGI is uploaded to a UNIX / Linux based web hosting service provider and has appropriate permissions, […]

  • Tutorial on sending e-mail using net:: SMTP class in Ruby

    Time:2022-5-6

    Simple Mail Transfer Protocol(SMTP)SendE-mailAnd routing protocol processing between e-mail servers. RubyIt provides the connection of simple mail transfer protocol (SMTP) client of net:: SMTP class, and provides two new methods: new and start New takes two parameters: Server name defaults to localhost Port number defaults to 25 The start method takes these parameters: Server – […]

  • A preliminary introduction to Ruby multithreaded programming

    Time:2022-5-4

    Traditional programs have a separate thread to execute, and the statements or instructions containing the program are executed sequentially until the program terminates. A multithreaded program has the execution of multiple threads. Each thread is executed sequentially, but on a multi-core CPU machine, threads may execute in parallel. For example, generally, in a single CPU […]

  • Common file operation methods in Ruby

    Time:2022-5-3

    1、 New file Copy codeThe code is as follows:     f=File.new(File.join(“C:”,”Test.txt”), “w+”)     f.puts(“I am Jack”)     f.puts(“Hello World”) File mode “r” :Read-only. Starts at beginning of file (default mode). “r+” :Read-write. Starts at beginning of file. “w” :Write-only. Truncates existing file to zero length or creates a new file for writing. “w+” :Read-write. Truncates […]

  • Using soap4r of ruby to write a tutorial of soap server

    Time:2022-5-2

    What isSOAP ? Simple object access protocol (soap) is a cross platform, language independent, XML based RPC Protocol, usually (but not necessarily) http. It uses XML to encode information, enabling remote procedure calls, HTTP over the network from clients toThe serverTo transmit information, and vice versa. Soap has several advantages over other technologies, such as […]

  • Collected multiple Ruby traversal folder code instances

    Time:2022-5-1

    1、 Traverse all files under the folder and output the file name   Copy codeThe code is as follows: def traverse_dir(file_path)     if File.directory? file_path         Dir.foreach(file_path) do |file|             if file !=”.” and file !=”..”                 traverse_dir(file_path+”/”+file)             end         end     else         puts “File:#{File.basename(file_path)}, Size:#{File.size(file_path)}”     end end traverse_dir(‘D:/apache-tomcat’)   2、 Ruby […]

  • Ruby traverses the folder and calculates the md5sum of the file

    Time:2022-4-30

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #!/usr/bin/ruby -w # require ‘digest/md5’   if ARGV.empty?     puts “usgae: #$0 path”     exit 0 end dir_name=ARGV.shift   […]

  • Ruby common file operation code examples

    Time:2022-4-29

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 […]

  • Quick sorting in one line of ruby code

    Time:2022-4-28

    Copy codeThe code is as follows: def quick_sort(a)       return a if a.size < 2     (x = a.pop) ?  quick_sort(a.select{|i| i <=x }) + [x] + quick_sort(a.select{|i| i > x}) : [] end array = [72,6,57,88,60,42,83,73,42,48,85] p quick_sort(array)    #=> [6, 42, 42, 48, 57, 60, 72, 73, 83, 85, 88]

  • Three quick sorting algorithms implemented by ruby

    Time:2022-4-27

    When I first learned ruby, it happened that the algorithm teacher encouraged me to write algorithms in unfamiliar languages. I’ll use ruby~~Ruby is really powerful. Many intuitive methods can be used….. Worship infinity…. During this period, I encountered the error of invalid multibyte char (us-ascii). The solution is to add a #encoding: UTF-8 at the […]

  • Optimal binary search tree algorithm implemented by ruby

    Time:2022-4-26

    The pseudo code on the introduction of the algorithm is rewritten, plus the constructor of the solution of the first problem in the after-school practice of the introduction. Copy codeThe code is as follows: #encoding: utf-8 =begin author: xu jin date: Nov 11, 2012 Optimal Binary Search Tree to find by using EditDistance algorithm refer […]