This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright (c) 1993-1999 Microsoft Corp. | |
| # | |
| # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. | |
| # | |
| # This file contains the mappings of IP addresses to host names. Each | |
| # entry should be kept on an individual line. The IP address should | |
| # be placed in the first column followed by the corresponding host name. | |
| # The IP address and the host name should be separated by at least one | |
| # space. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generates a random string, defaults to 30 characters in length. | |
| def String.random_alphanumeric(size=30) | |
| (1..size).collect { (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61))).chr }.join | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def image_resizer max, height, width | |
| # capture any nil or 0/less-than-0 objects and set them to the max value, since they need a value. | |
| # Assume max size is desired unless we're told otherwise. | |
| height = height.nil? || height <= 0 ? max : height | |
| width = width.nil? || width <= 0 ? max : width | |
| # Find out if any of the dimensions are bigger than the max size | |
| if height > max || width > max | |
| # isolate the largest dimension -> it doesn't really matter which one we look at, as long as it's the largest | |
| largest_dimension = height > max ? height : width |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'yaml' | |
| #=> true | |
| urlhash = { "1.1.1.1" => {:url => "http://www.example.com", :time => Time.now}} | |
| #=> {"1.1.1.1"=>{:time=>Wed May 06 15:03:58 -0700 2009, :url=>"http://www.example.com"}} | |
| open("ip_cache.yml", "w") { |f| YAML.dump(urlhash, f)} | |
| #=> #<File:ip_cache.yml (closed)> | |
| # Generates the following in the YAML file: | |
| # | |
| # --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /^((\d{1,3}\.){3}\d{1,3})\s/ | |
| ### | |
| # will find the following IP addresses: | |
| # | |
| # 127.0.0.1 | |
| # 192.168.1.105 | |
| # 192.168.1.58 | |
| # 192.168.1.127 | |
| # 10.37.129.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def list_directories path, response | |
| dir_list = Dir.new(path).entries.reject{ |f| f =~ /^\./ } | |
| response.body = "<html><head></head><body><ul style=\"list-style-type:none;margin:0;padding:0;\">" | |
| dir_list.each do |d| | |
| response.body += "<li>" | |
| response.body += File.directory?(d) ? "<strong>#{d}/</strong>" : "#{d}" | |
| response.body += "</li>" | |
| end | |
| response.body += "</ul></body></html>" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_lists_files_and_directories | |
| io = StringIO.new("GET /test/ HTTP/1.0\r\n\r\n") | |
| body = "<html><head></head><body><ul style=\"list-style-type:none;margin:0;padding:0;\"><li>helper.rb</li><li>test.html</li><li>test.html.erb</li><li>test_pan_server.rb</li><li>test_pan_server_g.rb</li><li>test_pan_server_t_c_p.rb</li><li>test_request.rb</li><li>test_response.rb</li><li>test_router.rb</li></ul></body></html>" | |
| @router.accept(io) | |
| response = io.string.split("\r\n") | |
| assert response.include?('HTTP/0.9 200 OK'), 'should have 200 status code' | |
| assert response.include?('Content-Type: text/html'), "should have content type header" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tierney@panmac:~ ➝ irb | |
| >> require 'tmpdir' | |
| => true | |
| >> Dir::tmpdir | |
| => "/var/folders/22/22A2X2I6HcmsssIW7SdM7++++TI/-Tmp-" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ([\.|^\#|^|\s]([\.a-zA-Z0-9_-]+)\s?){1,}[\,|\{] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body class="support screencast"> | |
| # ... | |
| <h1 class="hidden"> | |
| <%= @screencast_name.titleize %> | |
| </h1> | |
| # ... | |
| <div class="movie"> |