Skip to content

Instantly share code, notes, and snippets.

@mcoms
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save mcoms/2d5cea626ec50a6e48e0 to your computer and use it in GitHub Desktop.

Select an option

Save mcoms/2d5cea626ec50a6e48e0 to your computer and use it in GitHub Desktop.

Revisions

  1. mcoms revised this gist Dec 22, 2014. 2 changed files with 3 additions and 3 deletions.
    3 changes: 3 additions & 0 deletions helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    def bitstream_to_text(bitstream)
    bitstream.join.gsub('111', '-').gsub('1', '.').gsub('0',' ')
    end
    3 changes: 0 additions & 3 deletions html_helper.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +0,0 @@
    def bitstream_to_html(bitstream)
    bitstream.join.gsub('111', '-').gsub('1', '.').gsub('0',' ').html_safe
    end
  2. mcoms revised this gist Dec 22, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions html_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    def bitstream_to_html(bitstream)
    bitstream.join.gsub('111', '-').gsub('1', '.').gsub('0',' ').html_safe
    end
  3. mcoms revised this gist Dec 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion morse.rb
    Original file line number Diff line number Diff line change
    @@ -46,5 +46,5 @@ def calculate_bitstream(message)
    bits += [0, 0, 0]
    end
    bits.pop 3
    self.bitstream = bits
    bits
    end
  4. mcoms revised this gist Dec 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion morse.rb
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@
    "8"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
    "9"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "0"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "/"=>[1,1,1,0,1,0,1,0,1,1,1,0,1]
    "/"=>[1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1]
    })

    def calculate_bitstream(message)
  5. mcoms revised this gist Dec 22, 2014. 1 changed file with 40 additions and 40 deletions.
    80 changes: 40 additions & 40 deletions morse.rb
    Original file line number Diff line number Diff line change
    @@ -1,43 +1,43 @@
    MORSE_ALPHABET = Hash.new([]).merge!({
    " "=>[0],
    "A"=>[1, 0, 1, 1, 1],
    "B"=>[1, 1, 1, 0, 1, 0, 1, 0, 1],
    "C"=>[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1],
    "D"=>[1, 1, 1, 0, 1, 0, 1],
    "E"=>[1],
    "F"=>[1, 0, 1, 0, 1, 1, 1, 0, 1],
    "G"=>[1, 1, 1, 0, 1, 1, 1, 0, 1],
    "H"=>[1, 0, 1, 0, 1, 0, 1],
    "I"=>[1, 0, 1],
    "J"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "K"=>[1, 1, 1, 0, 1, 0, 1, 1, 1],
    "L"=>[1, 0, 1, 1, 1, 0, 1, 0, 1],
    "M"=>[1, 1, 1, 0, 1, 1, 1],
    "N"=>[1, 1, 1, 0, 1],
    "O"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "P"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "Q"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1],
    "R"=>[1, 0, 1, 1, 1, 0, 1],
    "S"=>[1, 0, 1, 0, 1],
    "T"=>[1, 1, 1],
    "U"=>[1, 0, 1, 0, 1, 1, 1],
    "V"=>[1, 0, 1, 0, 1, 0, 1, 1, 1],
    "W"=>[1, 0, 1, 1, 1, 0, 1, 1, 1],
    "X"=>[1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1],
    "Y"=>[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "Z"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
    "1"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "2"=>[1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "3"=>[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "4"=>[1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
    "5"=>[1, 0, 1, 0, 1, 0, 1, 0, 1],
    "6"=>[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
    "7"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1],
    "8"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
    "9"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "0"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "/"=>[1,1,1,0,1,0,1,0,1,1,1,0,1]
    })
    MORSE_ALPHABET = Hash.new([]).merge!({
    " "=>[0],
    "A"=>[1, 0, 1, 1, 1],
    "B"=>[1, 1, 1, 0, 1, 0, 1, 0, 1],
    "C"=>[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1],
    "D"=>[1, 1, 1, 0, 1, 0, 1],
    "E"=>[1],
    "F"=>[1, 0, 1, 0, 1, 1, 1, 0, 1],
    "G"=>[1, 1, 1, 0, 1, 1, 1, 0, 1],
    "H"=>[1, 0, 1, 0, 1, 0, 1],
    "I"=>[1, 0, 1],
    "J"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "K"=>[1, 1, 1, 0, 1, 0, 1, 1, 1],
    "L"=>[1, 0, 1, 1, 1, 0, 1, 0, 1],
    "M"=>[1, 1, 1, 0, 1, 1, 1],
    "N"=>[1, 1, 1, 0, 1],
    "O"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "P"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "Q"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1],
    "R"=>[1, 0, 1, 1, 1, 0, 1],
    "S"=>[1, 0, 1, 0, 1],
    "T"=>[1, 1, 1],
    "U"=>[1, 0, 1, 0, 1, 1, 1],
    "V"=>[1, 0, 1, 0, 1, 0, 1, 1, 1],
    "W"=>[1, 0, 1, 1, 1, 0, 1, 1, 1],
    "X"=>[1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1],
    "Y"=>[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "Z"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
    "1"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "2"=>[1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "3"=>[1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "4"=>[1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
    "5"=>[1, 0, 1, 0, 1, 0, 1, 0, 1],
    "6"=>[1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1],
    "7"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1],
    "8"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1],
    "9"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "0"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "/"=>[1,1,1,0,1,0,1,0,1,1,1,0,1]
    })

    def calculate_bitstream(message)
    bits = []
  6. mcoms revised this gist Dec 22, 2014. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion morse.rb
    Original file line number Diff line number Diff line change
    @@ -37,4 +37,14 @@
    "9"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "0"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "/"=>[1,1,1,0,1,0,1,0,1,1,1,0,1]
    })
    })

    def calculate_bitstream(message)
    bits = []
    message.upcase.each_char do |letter|
    bits += MORSE_ALPHABET[letter]
    bits += [0, 0, 0]
    end
    bits.pop 3
    self.bitstream = bits
    end
  7. mcoms created this gist Dec 22, 2014.
    40 changes: 40 additions & 0 deletions morse.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    MORSE_ALPHABET = Hash.new([]).merge!({
    " "=>[0],
    "A"=>[1, 0, 1, 1, 1],
    "B"=>[1, 1, 1, 0, 1, 0, 1, 0, 1],
    "C"=>[1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1],
    "D"=>[1, 1, 1, 0, 1, 0, 1],
    "E"=>[1],
    "F"=>[1, 0, 1, 0, 1, 1, 1, 0, 1],
    "G"=>[1, 1, 1, 0, 1, 1, 1, 0, 1],
    "H"=>[1, 0, 1, 0, 1, 0, 1],
    "I"=>[1, 0, 1],
    "J"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "K"=>[1, 1, 1, 0, 1, 0, 1, 1, 1],
    "L"=>[1, 0, 1, 1, 1, 0, 1, 0, 1],
    "M"=>[1, 1, 1, 0, 1, 1, 1],
    "N"=>[1, 1, 1, 0, 1],
    "O"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
    "P"=>[1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1],
    "Q"=>[1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1],
    "R"=>[1, 0, 1, 1, 1, 0, 1],
    "S"=>[1, 0, 1, 0, 1],
    "T"=>[1, 1, 1],
    "U"=>[1, 0, 1, 0, 1, 1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