Created
April 10, 2019 18:30
-
-
Save simonsnow/c592cd214032bd240e0c2599ecb5533d to your computer and use it in GitHub Desktop.
[js-snips] JS Snippets
This file contains 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
// Care of https://dev.to/healeycodes/javascript-one-liners-that-make-me-excited-56aj?utm_source=Newsletter+Subscribers&utm_campaign=4964317d7c-EMAIL_CAMPAIGN_2019_04_01_11_04&utm_medium=email&utm_term=0_d8f11d5d1e-4964317d7c-154942693 | |
// Create an array of the past seven days, inclusive | |
[...Array(7).keys()].map(days => new Date(Date.now() - 86400000 * days)); | |
// Generate a random alphanumerical string of length 11 | |
Math.random().toString(36).substring(2); | |
// $=_=>`$=${$};$()`;$() | |
$=_=>`$=${$};$()`;$() | |
// eval(I="'eval(I='+JSON.stringify(I)+')'") | |
eval(I="'eval(I='+JSON.stringify(I)+')'") | |
// For those who like their quines via alert | |
// (function a(){alert("("+a+")()")})() | |
(function a(){alert("("+a+")()")})() | |
// Generate a random alphanumerical string of length 11 | |
Math.random().toString(36).substring(2); | |
// $=_=>`$=${$};$()`;$() | |
$=_=>`$=${$};$()`;$() | |
// eval(I="'eval(I='+JSON.stringify(I)+')'") | |
eval(I="'eval(I='+JSON.stringify(I)+')'") | |
// For those who like their quines via alert | |
// (function a(){alert("("+a+")()")})() | |
(function a(){alert("("+a+")()")})() | |
// Set the current page's query parameters to `q` | |
q={};location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);q; | |
// Quick Clock | |
<body onload="setInterval(()=>document.body.innerHTML=new Date().toGMTString().slice(17,25))"></body> | |
// Return a shuffled copy of an Array-like | |
(arr) => arr.slice().sort(() => Math.random() - 0.5) | |
// Generate a random hex code such as `#c618b2` | |
'#' + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0'); | |
// https://blog.codinghorror.com/why-cant-programmers-program/ oneliner solution | |
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz' | |
// Remove duplicates from the iterable `arr` | |
[...new Set(arr)] | |
// Return a ***3D*** ASCII keyboard as string (in the least amount of code possible) | |
(_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"].map(x=>(o+=`/${b='_'.repeat(w=x<y?2:' 667699'[x=["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',p])}\\|`,m+=y+(x+' ').slice(0,w)+y+y,n+=y+b+y+y,l+=' __'+b)[73]&&(k.push(l,m,n,o),l='',m=n=o=y),m=n=o=y='|',p=l=k=[])&&k.join` | |
`)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment