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 'sinatra' | |
| Switch = Struct.new(:vendor, :model, :ports) | |
| Ports = Struct.new(:first, :second) | |
| get '/' do | |
| erb :select_switch | |
| end | |
| post '/' do |
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 'sinatra' | |
| # routes | |
| get '/' do | |
| erb :body_vendor | |
| end | |
| post '/' do | |
| @switch = params[:vendor] | |
| case @switch |
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 'readline' | |
| # Empty and dup are BAD. | |
| # 1. Read line and append to history | |
| # 2. Quick Break on nil | |
| # 3. Remove from history if empty or dup | |
| def readline_lineread | |
| line = Readline.readline('> ', true) | |
| return nil if line.nil? |
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
| var arr = [9, 9, 111, 2, 3, 4, 4, 5, 7]; | |
| var sorted_arr = arr.sort(); | |
| var results = []; | |
| for (var i = 0; i < arr.length - 1; i += 1) { | |
| if (sorted_arr[i + 1] == sorted_arr[i]) { | |
| results.push(sorted_arr[i]); | |
| } | |
| } | |
| alert(results); |
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
| #define a recursive function that will traverse the directory tree | |
| def printAndDescend(pattern) | |
| #we keep track of the directories, to be used in the second, recursive part of this function | |
| directories=[] | |
| Dir['*'].sort.each do |name| | |
| if File.file?(name) and name[pattern] | |
| puts(File.expand_path(name)) | |
| elsif File.directory?(name) | |
| directories << name | |
| 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
| #define a recursive function that will traverse the directory tree | |
| def printAndDescend(pattern) | |
| #we keep track of the directories, to be used in the second, recursive part of this function | |
| directories=[] | |
| Dir['*'].sort.each do |name| | |
| if File.file?(name) and name[pattern] | |
| puts(File.expand_path(name)) | |
| elsif File.directory?(name) | |
| directories << name | |
| 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
| open("|gem list").read.each_line { |gem| system "gem uninstall -aI #{gem[/^\w+/]}" } | |
| # or something related like `gem list`.split("\n").each { |gem| system "gem uninstall -aI #{gem.split(" ").first}" } |
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
| class Integer | |
| def check | |
| case | |
| when self % 15 == 0 | |
| puts "Fizzbang" | |
| when self % 3 == 0 | |
| puts "Fizz" | |
| when self % 5 == 0 | |
| puts "Bang" | |
| else |
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 split_up string | |
| @array = string.downcase.split '' | |
| end | |
| def find_palindromes | |
| @palindromes = [] | |
| 1.upto @array.size do |spot| | |
| look = 1 | |
| while @array[spot - look] == @array[spot + look] | |
| @palindromes << @array[spot - look, look * 2 + 1].join |
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
| 1.upto 100 do |n| | |
| r = "" | |
| r << "fizz" if n % 3 == 0 | |
| r << "buzz" if n % 5 == 0 | |
| r << n.to_s if r.empty? | |
| puts r | |
| end |
OlderNewer