)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Acronym Definition Generator

  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8" />
  5.     <title>Acro</title>
  6.  
  7.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  8.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9.     <style>
  10.  
  11.       body {
  12.         font-family: sans-serif;
  13.         margin: 3em;
  14.       }
  15.  
  16.       button {
  17.         cursor: pointer;
  18.         font-size: 1em;
  19.         padding: .6em;
  20.         margin-bottom: 2em;
  21.       }
  22.  
  23.       h1 {
  24.         font-size: 3em;
  25.         text-decoration: underline;
  26.       }
  27.  
  28.       hr {
  29.         border: none;
  30.         border-bottom: 1px dashed gray;  
  31.       }
  32.  
  33.       i {
  34.         text-transform: lowercase;
  35.       }
  36.  
  37.       #acro {
  38.         position: relative;
  39.         width: 100%;
  40.         min-width: 350px;
  41.         max-width: 700px;
  42.         margin: 0 auto;
  43.  
  44.       }
  45.  
  46.       input[type=text] {
  47.         padding: .5em;  
  48.         margin-right: 1em;
  49.         text-transform: uppercase;
  50.       }
  51.  
  52.       #go {
  53.         margin-right: .5em;  
  54.       }
  55.  
  56.       #btn {
  57.         float: right;  
  58.       }
  59.  
  60.       .row {
  61.         width: 100%;
  62.         clear: both;
  63.       }
  64.       .uiBreak { display: none; }
  65.  
  66.       @media only screen and (max-width: 600px) {
  67.         body {
  68.           font-size: .8em;
  69.           margin: 1em;
  70.         }
  71.  
  72.       }
  73.  
  74.       @media only screen and (max-width: 400px) {
  75.         .uiBreak { display: block; }
  76.         #btn {
  77.           float: left;
  78.           display: block;
  79.           clear: both;
  80.         }
  81.       }
  82.  
  83.     </style>
  84.   </head>
  85.   <body>
  86.     <div id=acro>
  87.       <h1>Acro</h1>
  88.       <div>
  89.         <input id=input type=text placeholder="enter acronym">
  90.         <button id=go>go...</button>
  91.         <br class=uiBreak>
  92.         <button id=btn>generate random...</button>
  93.       </div>
  94.  
  95.       <div id=acros></div>
  96.     </div>
  97.     <script>
  98. (() => {
  99.  
  100.   const min = 3
  101.   const max = 5
  102.   const diff = max - min
  103.  
  104.   const { random } = Math
  105.  
  106.   const wordsByLetter = {}
  107.   const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split``
  108.   let words;
  109.  
  110.   alphabet.forEach(let => wordsByLetter[let] = [])
  111.  
  112.   console.log('loading...')
  113.  
  114.   fetch('words.txt')
  115.     .then(data => data.text())
  116.     .then(text => {
  117.       console.log('prepping...')
  118.  
  119.       words = text.split(/\s+/m).sort()
  120.  
  121.       const chunk = 500
  122.       const ticks = ~~(words.length / chunk)
  123.  
  124.       let idx = 0
  125.       let count = 0
  126.  
  127.       let interval = setInterval(() => {
  128.         if (count === ticks) {
  129.           start()
  130.           clearInterval(interval)
  131.           return
  132.         }
  133.  
  134.         for (let i = 0; i < chunk; i++) {
  135.           const word = words[idx]
  136.           if (word[0]) {
  137.             const firstLetter = word[0].toUpperCase()
  138.             wordsByLetter[firstLetter]?.push(word)
  139.           }
  140.           idx++
  141.         }
  142.         count++
  143.       }, 1)
  144.     })
  145.  
  146.   function start() {
  147.     console.log('starting...')
  148.  
  149.     const rando = _ => {
  150.       const leng =  ~~(min + diff * random())
  151.       let word = ''
  152.       for (let i = 0; i < leng; i++) {
  153.         word += alphabet[~~(random() * alphabet.length)]
  154.       }
  155.       return word
  156.     }
  157.  
  158.     const gen = custom => {
  159.       if (!custom) return
  160.       custom = custom.toUpperCase()
  161.       const leng = custom.length
  162.       const def = []
  163.  
  164.       for (let i = 0; i < leng; i++) {
  165.         const sourceWords = wordsByLetter[custom[i]]
  166.         def[i] = sourceWords[~~(random() * sourceWords.length)]
  167.       }
  168.       const div = document.createElement`div`
  169.       div.className = 'row'
  170.       div.innerHTML = `
  171.         <h2>${custom}</h2>
  172.         <i>${def.join` `}</i>
  173.         <hr>
  174.       `
  175.       acros.prepend(div)
  176.     }
  177.  
  178.     btn.onclick = () => {
  179.       gen(rando())
  180.     }
  181.  
  182.     go.onclick = () => gen(input.value);
  183.     document.onkeydown = e => {
  184.       if (e.key === 'Enter') gen(input.value);
  185.     }
  186.  
  187.   }
  188. })()
  189.     </script>
  190.   </body>
  191. </html>


A friend of mine had this idea the other night so I coded it up…

Update: I forgot to mention, this uses this list of words from google…

JavaScript Exotic Undefined

  1. // from Martin Kleppe
  2. Array: [][[]]
  3. String: ""[""]
  4. Function: ($=>$)()
  5. Object: ({}).$
  6. Number: 0.0.$
  7. RegExp: /$/.$
  8. Boolean: false.true

Fun tweet from Martin Kleppe today

osx Command Files

  1. #!/bin/bash
  2. cd "$(dirname "$0")"
  3. . ~/.nvm/nvm.sh
  4.  
  5. nvm use stable && npm run dev

Then name that file “whatever.command”. When you double-click it, it’ll launch a terminal and run the command. I pop these in my dock for projects I’m always opening…

Label Thoughts

  1. main:{
  2.   header:{
  3.     {'Tasker'}
  4.     newCol:{'New Column'}
  5.   }
  6.  
  7.   columns:{
  8.     scroll:{
  9.       NoteCols:{}
  10.     }
  11.   }
  12. }
  13.  
  14. NoteCol:{
  15.   title:{['editable', 'focus']
  16.     close:{
  17.       {'&times;'}
  18.     }
  19.   }
  20.   newNote:{['editable', 'placeholder="New Note..."']}
  21.   hr:{}
  22.   noteContainer:{
  23.     Notes:{}
  24.   }
  25. }
  26.  
  27. Note:{['focus']
  28.   close:{
  29.     {'&times;'}
  30.   }
  31.   checkbox:{}
  32.   content:{['edtiable']}
  33. }
  34.  
  35. console.log('no errors :D');

The above is actually valid javascript, just a bunch of labels, blocks and a few arrays

// javascript // tricks // ui

Soundex

  1. // Minimum length of Soundex keys.
  2. var minLength = 4
  3.  
  4. // Soundex values belonging to characters.
  5. // This map also includes vowels (with a value of 0) to easily distinguish
  6. // between an unknown value or a vowel.
  7. var map = {}
  8.  
  9. map.a = map.e = map.i = map.o = map.u = map.y = 0
  10. map.b = map.f = map.p = map.v = 1
  11. map.c = map.g = map.j = map.k = map.q = map.s = map.x = map.z = 2
  12. map.d = map.t = 3
  13. map.l = 4
  14. map.m = map.n = 5
  15. map.r = 6
  16.  
  17. /**
  18.  * Get the soundex key from a given value.
  19.  *
  20.  * @param {string} value
  21.  * @param {number} [maxLength=4]
  22.  * @returns {string}
  23.  */
  24. function soundex(value, maxLength) {
  25.   var lowercase = String(value).toLowerCase()
  26.   /** @type {Array.<string|number>} */
  27.   var results = []
  28.   var index = -1
  29.   /** @type {string} */
  30.   var character
  31.   /** @type {number} */
  32.   var previous
  33.   /** @type {number} */
  34.   var phonetics
  35.  
  36.   while (++index < lowercase.length) {
  37.     character = lowercase.charAt(index)
  38.     phonetics = map[character]
  39.  
  40.     if (index === 0) {
  41.       // Initial letter
  42.       results.push(character.toUpperCase())
  43.     } else if (phonetics && phonetics !== previous) {
  44.       // Phonetics value
  45.       results.push(phonetics)
  46.     } else if (phonetics === 0) {
  47.       // Vowel
  48.       phonetics = null
  49.     } else {
  50.       // Unknown character (including H and W)
  51.       phonetics = previous
  52.     }
  53.  
  54.     previous = phonetics
  55.   }
  56.  
  57.   return pad(results.join('')).slice(0, maxLength || minLength)
  58. }
  59.  
  60. /**
  61.  * Pad a given value with zero characters. The function only pads four characters.
  62.  *
  63.  * @param {string} value
  64.  * @returns {string}
  65.  */
  66. function pad(value) {
  67.   var length = minLength - value.length
  68.   var index = -1
  69.  
  70.   while (++index < length) {
  71.     value += '0'
  72.   }
  73.  
  74.   return value
  75. }
  76.  
  77. console.log(
  78.   soundex('Joe'),
  79.   soundex('Smith'),
  80.   soundex('Ed'), 
  81.   soundex('Vilowat')
  82. )

Was talking with someone about Soundex… I grabbed this implementation from the soundex-code npm package from Titus Wormer

Soundex has always been super interesting to me for some reason.

snippet.zone ~ 2021-24 /// {s/z}