This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeFunction() { | |
| let myVar = 123 | |
| return function (s) { | |
| console.log(eval(s)) | |
| } | |
| } | |
| const func = makeFunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <body> | |
| <script type="hash-module" id="sum"> | |
| export const sum = (a, b) => a + b; | |
| </script> | |
| <!-- All hash modules need to go before this script. --> | |
| <!-- This cant be a type="module", it must be executed immediately. --> | |
| <script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const to = Symbol('number to') | |
| // Number.prototype[to] = function to(end) { | |
| // let [start, tend, rev] = (this>end) ? [end, this, true] : [this, end, false], arr = [] | |
| // for (let i=start; i<=tend; i++) arr.push(i) | |
| // return rev ? arr.sort(_=>1) : arr | |
| // } | |
| Number.prototype[to] = function to(end, {step}={step:this<=end?1:-1}) { | |
| let arr = [], i, d = end>this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add(target, f, outerSyntax=false){ | |
| return f.length ? | |
| outerSyntax ? | |
| addProperty(target, f) | |
| : | |
| addWithParams(target, f) | |
| : | |
| addSimple(target, f) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var n = 53.73; | |
| var rounded = n|0; //53 | |
| x|0 //Round x down | |
| func`arg` //Call function with one string argument | |
| getContext`2d`; // ^ | |
| `rgb(${r}, ${g}, ${b})` //Template literals | |
| C //together with <canvas id=C> instead of document.getElementById("C"); | |
| 1e3 //Shorter than 1000 | |
| 1e-3 //Shorter than 0.001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function allocateInt(amount, ratios) { | |
| if (ratios.length == 1) { | |
| return [amount] | |
| } else { | |
| const rs = [...ratios] | |
| const divisor = rs.reduce((a,i)=>a+i) | |
| const thisAmount = Math.round(amount*rs.shift()/divisor) | |
| return [ | |
| thisAmount, | |
| ...allocateInt(amount-thisAmount, rs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* https://edent.gitlab.io/paper-prototype-css/ */ | |
| @font-face { | |
| font-family: 'Reenie Beanie'; | |
| font-style: normal; | |
| font-weight: 400; | |
| font-display: swap; | |
| src: url(https://fonts.gstatic.com/s/reeniebeanie/v16/z7NSdR76eDkaJKZJFkkjuvWxXPq1qw.woff2) format('woff2'); | |
| unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const mostFrequent = s=>s.match(/(.)\1+/g)?.sort((a,b)=>b.length-a.length)[0][0]||s[0] | |
| const mostFrequentLetter = s=>([...s].sort().join('').match(/(\w)\1+/g)?.sort((a,b)=>b.length-a.length)[0]||s.match(/\w/))[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <g-carousel> | |
| <g-images> | |
| <a href="#b"><img id="a" src="https://source.unsplash.com/random/800x400?sig=1"></a> | |
| <a href="#c"><img id="b" src="https://source.unsplash.com/random/800x400?sig=2"></a> | |
| <a href="#a"><img id="c" src="https://source.unsplash.com/random/800x400?sig=3"></a> | |
| </g-images> | |
| </g-carousel> | |
| <style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function shuffle(array) { | |
| let a = [...array], m = a.length, i | |
| while (m) { | |
| // Pick a remaining element | |
| i = ~~(Math.random() * m--); | |
| // Swap it with the current element | |
| [a[m], a[i]] = [a[i], a[m]] | |
| } | |
| return a | |
| } |
NewerOlder