• Mar 22, 2022 •LeifMessinger
0 likes • 1 view
//QM Helper by Leif Messinger //Groups numbers by number of bits and shows their binary representations. //To be used on x.com const minterms = prompt("Enter your minterms separated by commas").split(",").map(x => parseInt(x.trim())); const maxNumBits = minterms.reduce(function(a, b) { return Math.max(a, Math.log2(b)); }); const bitGroups = []; for(let i = 0; i < maxNumBits; ++i){ bitGroups.push([]); } for(const minterm of minterms){ let outputString = (minterm+" "); //Count the bits let count = 0; for (var i = maxNumBits; i >= 0; --i) { if((minterm >> i) & 1){ ++count; outputString += "1"; }else{ outputString += "0"; } } bitGroups[count].push(outputString); } document.body.textContent = ""; document.body.style.setProperty("white-space", "pre"); for(const group of bitGroups){ for(const outputString of group){ document.body.textContent += outputString + "\r\n"; } }
• Mar 11, 2021 •C S
0 likes • 0 views
require("dotenv").config(); const mongoose = require("mongoose"); const db = process.env.MONGO_URI; const connectDB = async () => { try { await mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true }); console.log("MongoDB Connected"); } catch (err) { console.error(err.message); } }; module.exports = connectDB;
• Jan 25, 2023 •C S
0 likes • 11 views
// Vanilla JS Solution: var app = document.getElementById('app'); var typewriter = new Typewriter(app, { loop: true }); typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); // React Solution: import Typewriter from 'typewriter-effect'; <Typewriter options={{ loop: true }} onInit={typewriter => { typewriter .typeString("I'm John and I'm a super cool web developer") .pauseFor(3000) .deleteChars(13) // "web developer" = 13 characters .typeString("person to talk with!") // Will display "I'm John and I'm a super cool person to talk with!" .start(); }} />
1 like • 21 views
export const Main = () => { const [title, setTitle] = useState(''); return ( <ChildComponent title={title} onChange={e => setTitle(e.target.value)} /> ); }; export const ChildComponent = ({ title, onChange }) => { return ( <Box component="form" onSubmit={() => {}} noValidate mt={5}> <TextField fullWidth id="title" label="Title" name="title" autoComplete="title" autoFocus color="primary" variant="filled" InputLabelProps={{ shrink: true }} value={title} onChange={onChange} /> </Box> ); };
• Nov 19, 2022 •CodeCatch
const nums = [1, 2, 3]; const strs = Array.from('est'); nums.push(6); nums.push(4, 9); strs.unshift('t'); nums.length; // 6 nums[nums.length - 1]; // 9 strs[0]; // 't' strs[2]; // 's' nums.slice(1, 3); // [2, 3] nums.map(n => n * 2); // [2, 4, 6, 12, 8, 18] nums.filter(n => n % 2 === 0); // [2, 6, 4] nums.reduce((a, n) => a + n, 0); // 25 strs.reverse(); // ['t', 's', 'e', 't'] strs.join(''); // 'test' const nums = new Set([1, 2, 3]); nums.add(4); nums.add(1); nums.add(5); nums.add(4); nums.size; // 5 nums.has(4); // true nums.delete(4); nums.has(4); // false [...nums]; // [1, 2, 3, 5] nums.clear(); nums.size; // 0 const items = new Map([ [1, { name: 'John' }], [2, { name: 'Mary' }] ]); items.set(4, { name: 'Alan' }); items.set(2, { name: 'Jeff' }); items.size; // 3 items.has(4); // true items.get(2); // { name: 'Jeff' } items.delete(2); items.size; // 2 [...items.keys()]; // [1, 4] [...items.values()]; // [{ name: 'John' }, { name: 'Alan' }] items.clear(); items.size; // 0
0 likes • 2 views
function formatDate(date) { return date.toLocaleDateString(); } function Comment(props) { return ( <div className="Comment"> <div className="UserInfo"> <img className="Avatar" src={props.author.avatarUrl} alt={props.author.name} /> <div className="UserInfo-name"> {props.author.name} </div> </div> <div className="Comment-text">{props.text}</div> <div className="Comment-date"> {formatDate(props.date)} </div> </div> ); } const comment = { date: new Date(), text: 'I hope you enjoy learning React!', author: { name: 'Hello Kitty', avatarUrl: 'https://placekitten.com/g/64/64', }, }; ReactDOM.render( <Comment date={comment.date} text={comment.text} author={comment.author} />, document.getElementById('root') );