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

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…

Odd Gradient Notation

  1. // "Being clever is not clever"
  2. // -- Bjarne Stroustrup
  3. D = document
  4. ang = {
  5.   '|': 180,
  6.   '-': 90,
  7.   '\\': 135,
  8.   '/': 225
  9. }
  10.  
  11. box = def => {
  12.   def = def.split(/\s+/)
  13.   form = def.length
  14.   I = i => parseInt(def[i], 16)
  15.  
  16.   ;[,,, _=>{x = y = I(0); w = h = I(1); c = def[2]},
  17.     _=>{x = I(0), y = I(1); w = h = I(2);c = def[3]},
  18.     _=>{x = I(0); y = I(1); w = I(2); h = I(3); c = def[4]}
  19.   ][form]()
  20.  
  21.   c = c.split``
  22.  
  23.   ca = c[0]
  24.   ca = ca+ca+ca
  25.   cD = ang[c[1]]
  26.   cb = c[2]
  27.   cb = cb+cb+cb 
  28.  
  29.   D.body.appendChild(
  30.     D.createElement`div`
  31.   ).style = `
  32.     position: absolute; left: ${x}px; top: ${y}px;
  33.     width: ${w}px; height: ${h}px;
  34.     background: linear-gradient(${cD}deg, #${ca}, #${cb})
  35.   `
  36. }
  37.  
  38. const parse = prog => prog.trim()
  39.   .split(/\n+/m)
  40.   .map(line => box(line.trim()))
  41.  
  42. parse(`
  43.   0 64 0/f
  44.   64 64 0\\f
  45.   a0 f0 30 54 f\\0
  46.   0 6f 20 60 0-c
  47.   f 7f 20 60 0|c
  48.   1f 8f 30 30 c/0
  49. `)

Just playing around… odd micro-gradient notation:

  1. '0 64 0/f'
  2. // x=0 y=0 width=0x64 height=0x64
  3. // 0/f = gradient black to white top right to bottom left
  4.  
  5. '64 64 0\\f'
  6. // x=0 y=0 width=0x64 height=0x64
  7. // 0\\f = black to to white gradient top left to bottom right
  8.  
  9. '0 6f 20 60 0-c'
  10. // x=0 y=0x6f width=0x20 height=0x60
  11. // 0-c = gradient black to grey (#ccc) left to right
  12.  
  13. // etc... ( | ) is top to bottom grad
// css // dom // golfed // graphics // hacks // humor // regex // speed-coded

Isometric Vases

  1.  
  2. const canvas = document.createElement`canvas`
  3. const c = canvas.getContext`2d`
  4.  
  5. document.body.appendChild(canvas)
  6. document.body.style.margin = 0
  7.  
  8. canvas.style.width = '100%'
  9. canvas.style.height = '100%'
  10.  
  11. const COLS = 10
  12. const ROWS = 10
  13. let space;
  14. let size;
  15. let time = 0
  16. const num = COLS * ROWS
  17. const mon = []
  18. for (let y = 0; y < COLS; y++) {
  19.   for (let x = 0; x < ROWS; x++) {
  20.     mon.push(monument())
  21.   }
  22. }
  23.  
  24. function reset(){
  25.   time = 0
  26.   c.fillStyle = '#ccc'
  27.   c.fillRect(0, 0, canvas.width, canvas.height)
  28. }
  29.  
  30. function resize() {
  31.   canvas.width = innerWidth * 2
  32.   canvas.height = innerHeight * 2
  33.  
  34.   reset()
  35. }
  36. resize()
  37. window.addEventListener('resize', resize)
  38.  
  39. function monument(x, y) {
  40.  
  41.   const s = Math.random()
  42.   let cl = 0;
  43.   let damp = Math.random() / 10;
  44.  
  45.   let rad = 10 + Math.random() * 
  46.   Math.random() * (innerWidth / 30)
  47.  
  48.   let skip = Math.random() < .5;
  49.   let o = Math.random() * 7
  50.   let shade = .01;
  51.   let radamp = 200 + Math.random() * 90
  52.   let life = 100 + Math.random() *  Math.random() *  Math.random() * 1200;
  53.   return (x, y) => { 
  54.       if (time === 0) { 
  55.       c.save()
  56.       c.strokeStyle = 'rgba(0, 0, 0, 0.2)'
  57.       c.translate(x - space / 2, y - space / 2)
  58.       c.strokeRect(0, 0, space, space)
  59.       c.restore()
  60.       }
  61.     if (skip) {
  62.  
  63.  
  64.     } else { 
  65.  
  66.       //rad += (0 - rad) / radamp
  67.       let teta = time * s * damp
  68.       let C = Math.sin(teta)
  69.       let C2 = Math.sin(time * s * damp + o);
  70.  
  71.       cl = C2 * 200 + 55;
  72.  
  73.       shade -= .0001;
  74.  
  75.       let col = `rgba(${cl}, ${cl}, ${cl}, 1)`
  76.       if (time > life) {
  77.         col = `rgba(155, 155, 155, .4)`
  78.         skip = true
  79.       }
  80.  
  81.     c.save()
  82.  
  83.       c.translate(x - time * s, y)
  84.       c.fillStyle = `rgba(0, 0, 0, ${shade})`
  85.       c.beginPath()
  86.       c.arc(0, 0, rad + rad * C, 0, 7)
  87.       c.fill()
  88.       c.restore();
  89.  
  90.       c.save()
  91.  
  92.       c.translate(x - time * s, y - time * s)
  93.       c.fillStyle = col
  94.       c.beginPath()
  95.       c.arc(0, 0, rad + rad * C, 0, 7)
  96.       c.fill()
  97.       c.restore();
  98.     }
  99.   }
  100. }
  101.  
  102. function draw() {
  103.   space = (innerWidth * 2) / COLS * .6;
  104.  
  105.   size = COLS * space
  106.  
  107.   c.save()
  108.   c.scale(1, .6)
  109.   c.translate(innerWidth, innerHeight * 2)
  110.   c.rotate(45 * Math.PI / 180)
  111.   c.translate(-size / 2, -size / 2)
  112.  
  113.   let inc = 0;
  114.   for (let y = 0; y < COLS; y++) {
  115.     for (let x = 0; x < ROWS; x++) {
  116.       mon[inc++](y * space, x * space)
  117.     }
  118.   }
  119.   c.restore()
  120.   time++
  121.   requestAnimationFrame(draw)
  122. }
  123.  
  124. draw();

Something I speed coded for genuary

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…

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