Skip to content

Instantly share code, notes, and snippets.

@twome
Last active August 4, 2019 14:32
Show Gist options
  • Save twome/57875263bfd30713060eea9394f9afe3 to your computer and use it in GitHub Desktop.
Save twome/57875263bfd30713060eea9394f9afe3 to your computer and use it in GitHub Desktop.
Nah, yeah, yeah, nah, nah, nah, yeah, nah, nah, yeah, yeah, nah, yeah, nah, nah, yeah, nah, yeah, yeah, nah, yeah, yeah, yeah, nah, nah, yeah, yeah, nah, nah, yeah, yeah, yeah, nah, yeah, yeah, nah, nah, nah, yeah, nah, nah, yeah, yeah, nah, yeah, yeah, yeah, yeah, nah, yeah, yeah, nah, yeah, yeah, yeah, nah, nah, yeah, yeah, nah, nah, yeah, yea…
#!/usr/bin/env node
const uintToBitString = int => {
if (!(int >= 0 && int <= 127)) throw Error('ASCII only, hun.')
let bitString = ''
function f(num){
if (num == 0) return
let rem = num % 2
let div = Math.floor(num / 2)
f(div)
bitString += rem.toString() // Because this happens after the stack has fully extended, the string will be appended to in reverse order.
}
f(int)
return bitString
}
const leftPad8 = bitString => '0'.repeat(8 - bitString.length) + bitString
let input = process.argv[2]
if (!input) throw Error('Huh?')
let ascii = ''
for (let i = 0; i < input.length; i += 1){
let charCodeInt = input.codePointAt(i)
let bitString = leftPad8(uintToBitString(charCodeInt))
ascii += bitString
}
let translated = ascii.replace(/1/g,'yeah, ').replace(/0/g, 'nah, ')
// Grammar
translated = translated.replace(/^y/, 'Y').replace(/^n/, 'N').substring(0, translated.length - 2) + '.'
process.stdout.write(translated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment