Skip to content

Commit

Permalink
snippeting, URL link button
Browse files Browse the repository at this point in the history
  • Loading branch information
colevandersWands committed Jun 30, 2023
1 parent 4b2adff commit e908636
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 16 deletions.
18 changes: 15 additions & 3 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ const runCode = (snippet = {}, debug = false) => {
snippet.root.appendChild(evaller);
};

const copyCode = (code) => {
const copyCode = (code, message = 'copied!') => {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(code);
return;
}
navigator.clipboard.writeText(code).then(
function () {
// console.log('Async: Copying to clipboard was successful!');
alert('copied!');
alert(message);
},
function (err) {
// console.error('Async: Could not copy text: ', err);
Expand Down Expand Up @@ -159,6 +159,7 @@ const renderSnippet = (snippet) => {
<button class='editoringer'>edit</button>
|
<button class='copier'>copy</button>
<button class='linker'>link</button>
<button class='githubber'>source</button>
</div>
</div>`;
Expand Down Expand Up @@ -268,7 +269,18 @@ for (const snippet of state.snippets) {

snippet.root
.getElementsByClassName('copier')[0]
.addEventListener('click', () => copyCode(snippet.code));
.addEventListener('click', () =>
copyCode(snippet.code, `${snippet.name} - the snippet is copied`),
);

snippet.root
.getElementsByClassName('linker')[0]
.addEventListener('click', () =>
copyCode(
`${window.location.origin}/${window.location.pathname}?query=${snippet.name}`,
`${snippet.name} - the URL is copied`,
),
);

snippet.root
.getElementsByClassName('githubber')[0]
Expand Down
11 changes: 8 additions & 3 deletions public/snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
{
"name": "dna.js",
"code": "const WIDTH = 30;\nconst STEP = 0.08;\n\nconst coordinate = (num, phase = 0) =>\n Math.round(Math.sin(num + phase) * WIDTH) + WIDTH;\n\nlet a = 0;\nlet b = WIDTH;\n\nconst strand = setInterval(() => {\n const aIndex = coordinate((a += STEP));\n const bIndex = coordinate((b += STEP), WIDTH / 2);\n console.log(\n `${''.padStart(aIndex < bIndex ? aIndex : bIndex)}{|${''.padStart(\n Math.abs(bIndex - aIndex),\n '=',\n )}|}`,\n );\n if (a / b > 0.3) {\n clearInterval(strand);\n }\n}, 30);\n\n// tags: sketch\n",
"code": "const WIDTH = 30;\nconst STEP = 0.08;\n\nconst coordinate = (num, phase = 0) =>\n Math.round(Math.sin(num + phase) * WIDTH) + WIDTH;\n\nlet a = 0;\nlet b = WIDTH;\n\nconst strand = setInterval(() => {\n const cA = coordinate((a += STEP));\n const cB = coordinate((b += STEP), WIDTH / 2);\n console.log(\n `${Array((cA < cB ? cA : cB) + 1).join(' ')}{|${Array(\n Math.abs(cB - cA),\n ).join('=')}|}`,\n );\n if (a / b > 0.3) {\n clearInterval(strand);\n }\n}, 30);\n\n// tags: sketch\n",
"tags": [
"sketch"
]
Expand Down Expand Up @@ -86,12 +86,17 @@
"tags": []
},
{
"name": "recurseval.js",
"code": "eval((callEval = 'eval(callEval)'));\n\n// tags: useless\n",
"name": "recurseval-1.js",
"code": "eval((recurseval = 'eval(recurseval)'));\n\n// tags: useless\n",
"tags": [
"useless"
]
},
{
"name": "recurseval-2.js",
"code": "(function recurseval() {\n eval(`(${recurseval.toString()})()`);\n})();\n",
"tags": []
},
{
"name": "reflection.js",
"code": "var w = 0;\n\nwhile (w < 3) {\n w++;\n}\n\nalert(w);\n\n/*~~~~~~~~~~~~*/\n\nalert(m);\n\ndo {\n m++;\n} while (m < 3);\n\nvar m = 0;\n",
Expand Down
11 changes: 5 additions & 6 deletions snippets/dna.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ let a = 0;
let b = WIDTH;

const strand = setInterval(() => {
const aIndex = coordinate((a += STEP));
const bIndex = coordinate((b += STEP), WIDTH / 2);
const cA = coordinate((a += STEP));
const cB = coordinate((b += STEP), WIDTH / 2);
console.log(
`${''.padStart(aIndex < bIndex ? aIndex : bIndex)}{|${''.padStart(
Math.abs(bIndex - aIndex),
'=',
)}|}`,
`${Array((cA < cB ? cA : cB) + 1).join(' ')}{|${Array(
Math.abs(cB - cA),
).join('=')}|}`,
);
if (a / b > 0.3) {
clearInterval(strand);
Expand Down
62 changes: 62 additions & 0 deletions snippets/mu.draft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// variable name is 'mu'
// the only value stored is 'mu'
// the two keys are 'whol' & 'rede'
// but somehow defined by each other
// !! reflect
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect

// ----------

class Mu {
get Reductionism() {
// debugger;
return this instanceof Reductionism ? new Wholism() : new Reductionism();
}
get Wholism() {
// debugger;
return this instanceof Wholism ? new Reductionism() : new Wholism();
}
}
class Wholism extends Mu {}
class Reductionism extends Mu {}

const r = new Reductionism();
const w = new Wholism();

console.log(r.Wholism, w.Reductionism);

// --------

// class Reductionism extends Mu {}
// class Mu extends Wholism {}
// class Wholism extends Reductionism {}

// -------

// const mu = new String('mu');
// // Object.setPrototypeOf(mu, mu);
// mu.__proto__.__proto__ = mu;
// console.log(mu.__proto__.__proto__);

// ----------

// but where's the mu in this?2
// reflect?
// const wholism = () => reductionism;
// const reductionism = () => wholism;

// ----------

// not so much, maybe clases?
// mu = {
// get wholism() {
// return this;
// },
// get reductionism() {
// return this;
// },
// };

// console.log(mu.wholism);

// https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.IEpeeWykfDy_wVjvK7vkbwHaFM%26pid%3DApi&f=1&ipt=56cc492262d99d03355a67f077fe81f82294d9fe9d833d737b488de925b889f0&ipo=images
1 change: 1 addition & 0 deletions snippets/plaid.draft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tags: sketch
Empty file added snippets/recurseval-0.draft.js
Empty file.
3 changes: 3 additions & 0 deletions snippets/recurseval-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eval((recurseval = 'eval(recurseval)'));

// tags: useless
3 changes: 3 additions & 0 deletions snippets/recurseval-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function recurseval() {
eval(`(${recurseval.toString()})()`);
})();
3 changes: 0 additions & 3 deletions snippets/recurseval.js

This file was deleted.

1 change: 0 additions & 1 deletion snippets/recursimport.draft.mjs

This file was deleted.

21 changes: 21 additions & 0 deletions snippets/steamroll.draft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// how to find the line number in an error?
// otherwise set a global listener

window.addEventListener('error', (e) => {
console.log(e);
});

steamroll('asdf');

function steamroll(code, refactors) {
code = code || '';
refactors = refactors || [];

try {
eval(code);
} catch (err) {
console.error(err);
}
}

// inspiration: https://github.com/mattdiamond/fuckitjs

0 comments on commit e908636

Please sign in to comment.