• Nov 19, 2022 •CodeCatch
0 likes • 0 views
// promisify(f, true) to get array of results function promisify(f, manyArgs = false) { return function (...args) { return new Promise((resolve, reject) => { function callback(err, ...results) { // our custom callback for f if (err) { reject(err); } else { // resolve with all callback results if manyArgs is specified resolve(manyArgs ? results : results[0]); } } args.push(callback); f.call(this, ...args); }); }; } // usage: f = promisify(f, true); f(...).then(arrayOfResults => ..., err => ...);
• Jan 25, 2023 •C S
0 likes • 22 views
const ResponsiveCardImg = styled(Card.Img)` // For screens wider than 768px @media(min-width: 768px) { // Your responsive styles here. } // For screens smaller than 768px @media(max-width: 768px) { // Your responsive styles here. } ` export default function App() { return ( <MainContainer> <Container> <Card text='white' bg='dark' style={styles.mainCard}> <ResponsiveCardImg style={styles.cardImage} onClick={handleClick} src={apeImage} alt='Degenerate Ape Academy' /> <Card.Body> <Card.Title className='text-center' as='h2'> {apeId} </Card.Title> </Card.Body> </Card> </Container> </MainContainer> ); }
• Nov 8, 2023 •LeifMessinger
0 likes • 6 views
function copyString(text){ async function navigatorClipboardCopy(text){ if(document.location.protocol != "https:"){ return false; } return new Promise((resolve, reject)=>{ navigator.clipboard.writeText(text).then(()=>{resolve(true);}, ()=>{resolve(false);}); }); } function domCopy(text){ if(!(document.execCommand)){ console.warn("They finally deprecated document.execCommand!"); } const input = document.createElement('textarea'); input.value = text; document.body.appendChild(input); input.select(); const success = document.execCommand('copy'); document.body.removeChild(input); return success; } function promptCopy(){ prompt("Copy failed. Might have ... somewhere. Check console.", text); console.log(text); } function done(){ alert("Copied to clipboard"); } navigatorClipboardCopy(text).catch(()=>{return false;}).then((success)=>{ if(success){ done(); }else{ if(domCopy(text)){ done(); }else{ promptCopy(); } } }); }
• Oct 29, 2020 •LeifMessinger
0 likes • 2 views
questions = Array.from(document.querySelectorAll(".multiple-choice-question")); async function hackRadio(question){ if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return; let answerChoices = question.querySelectorAll(".zb-radio-button"); async function guess(answerChoice){ answerChoice.querySelector("label").click(); } let pause = 0; for(let answerChoice of answerChoices){ setTimeout(()=>{guess(answerChoice)},pause); //No need to check given that it will record the correct answer anyways. pause += 1000; } } for(let question of questions){ hackRadio(question); } questions = Array.from(document.querySelectorAll(".short-answer-question")); async function hackShortAnswer(question){ if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return; question.querySelector("textarea").value = question.querySelector(".forfeit-answer").textContent; //question.querySelector(".check-button").click(); They are smart bastards } for(let question of questions){ const showAnswerButton = question.querySelector(".show-answer-button"); showAnswerButton.click(); showAnswerButton.click(); hackShortAnswer(question); }
0 likes • 1 view
const getURLParameters = url => (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce( (a, v) => ( (a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a ), {} );
• Oct 15, 2022 •CodeCatch
1 like • 274 views
const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })