Last active
July 3, 2024 22:43
-
-
Save nick3499/7202dfe86ba7ee0d7e214392fdbdab59 to your computer and use it in GitHub Desktop.
Translate to NATO Phonetic Alphabet: JavaScript, Python, Ruby
This file contains 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
#! /bin/python3 | |
'''Convert letters to NATO phonetic alphabet.''' | |
_INPUT = input('Enter letters: ') | |
def convert_nato(): | |
d = { | |
'A': 'Alpha', 'B': 'Bravo', 'C': 'Charlie', | |
'D': 'Delta', 'E': 'Echo', 'F': 'Foxtrot', | |
'G': 'Golf', 'H': 'Hotel', 'I': 'India', | |
'J': 'Juliett','K': 'Kilo', 'L': 'Lima', | |
'M': 'Mike', 'N': 'November','O': 'Oscar', | |
'P': 'Papa', 'Q': 'Quebec', 'R': 'Romeo', | |
'S': 'Sierra', 'T': 'Tango', 'U': 'Uniform', | |
'V': 'Victor', 'W': 'Whiskey', 'X': 'X-ray', | |
'Y': 'Yankee', 'Z': 'Zulu'} | |
print(' '.join([d[x] for x in [*_INPUT.upper()]])) | |
if __name__ == '__main__': | |
convert_nato() |
This file contains 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
const nato = s => { | |
let h = { | |
"A": "Alpha", "B": "Bravo", "C": "Charlie", | |
"D": "Delta", "E": "Echo", "F": "Foxtrot", | |
"G": "Golf", "H": "Hotel", "I": "India", | |
"J": "Juliett","K": "Kilo", "L": "Lima", | |
"M": "Mike", "N": "November","O": "Oscar", | |
"P": "Papa", "Q": "Quebec", "R": "Romeo", | |
"S": "Sierra", "T": "Tango", "U": "Uniform", | |
"V": "Victor", "W": "Whiskey", "X": "X-ray", | |
"Y": "Yankee", "Z": "Zulu" | |
} | |
return [...s.toUpperCase()].map(x => h[x]).join(' ') | |
} |
This file contains 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 nato s | |
h = { | |
"A"=>"Alpha", "B"=>"Bravo", "C"=>"Charlie", | |
"D"=>"Delta", "E"=>"Echo", "F"=>"Foxtrot", | |
"G"=>"Golf", "H"=>"Hotel", "I"=>"India", | |
"J"=>"Juliett","K"=>"Kilo", "L"=>"Lima", | |
"M"=>"Mike", "N"=>"November","O"=>"Oscar", | |
"P"=>"Papa", "Q"=>"Quebec", "R"=>"Romeo", | |
"S"=>"Sierra", "T"=>"Tango", "U"=>"Uniform", | |
"V"=>"Victor", "W"=>"Whiskey", "X"=>"X-ray", | |
"Y"=>"Yankee", "Z"=>"Zulu" | |
} | |
return s.upcase.split('').collect { |x| h[x] }.join(' ') | |
end |
This file contains 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
#! /bin/python3 | |
'''Execute raw Gist code (Python code) locally.''' | |
import pycurl | |
from io import BytesIO | |
bytes_oi = BytesIO() # init bytesio obj | |
_curl = pycurl.Curl() # init curl obj | |
# set raw gist URL | |
_curl.setopt(_curl.URL, 'https://gist.githubusercontent.com/nick3499/7202dfe86ba7ee0d7e214392fdbdab59/raw/4aa37582274f98ffffd776a69aa08ab6c738beac/convert2nato.py') | |
_curl.setopt(_curl.WRITEDATA, bytes_oi) # write utf-8 encoded bytes | |
_curl.perform() # perform file transfer to bytes_oi | |
_curl.close() # end session | |
get_body = bytes_oi.getvalue() # get bytes code from bytes_oi | |
exec(get_body.decode('utf8')) # decode bytes code to utf-8 and exec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment