Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active August 29, 2015 13:57
Show Gist options
  • Save joshuakfarrar/9711672 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/9711672 to your computer and use it in GitHub Desktop.
/*
royalflush:science sent1nel$ node index.js http://www.facebook.com
1395511696652 Device(s) /dev/cu.usbmodem1411
1395511701611 Connected /dev/cu.usbmodem1411
1395511701611 Repl Initialized
>> Getting http://www.facebook.com...got it!
Attempting to encode 'Update Your Browser | Facebook'
Encoded title:
..- .--. -.. .- - . ....... -.-- --- ..- .-. ....... -... .-. --- .-- ... . .-. ....... ? ....... ..-. .- -.-. . -... --- --- -.-
..- .--. -.. .- - . ....... -.-- --- ..- .-. ....... -... .-. --- .-- ... . .-. ....... ....... ..-. .- -.-. . -... --- --- -.-
*/
var sendString = function(string) {
// for each character in the string..
var characters = string.split(' ');
for (var k = 0; k < characters.length; k++) {
queueCharacter(characters[k], characters[k + 1], !k);
}
}
var queueCharacter = function(character, nextCharacter, first) {
// unknown character. i've had errors with -s and |s in titles. eat them, ungracefully.
if (character === '?') return process.stdout.write(' ');
// queue up a space; it's simply a 7-unit off
if (character === '.......') return queueSpace();
// for each element in the character, queue up the appropriate action
for (var k = 0; k < character.length; k++) {
switch (character[k]) {
case '.':
queueDit();
break;
case '-':
queueDah();
break;
}
// if not the last element, queue up an inter-element gap
if (k != character.length - 1) {
queueElementGap();
}
}
// queue a character gap if the next character isn't a space and isn't undefined
if (nextCharacter !== '.......' && typeof nextCharacter !== 'undefined') {
queueCharacterGap();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment