Loading...
More JavaScript Posts
//Upvotes comments according to a regex pattern. I tried it out on https://www.reddit.com/r/VALORANT/comments/ne74n4/please_admire_this_clip_precise_gunplay_btw///Known bugs://If a comment was already upvoted, it gets downvoted//For some reason, it has around a 50-70% success rate. The case insensitive bit works, but I think some of the query selector stuff gets changed. Still, 50% is goodlet comments = document.getElementsByClassName("_3tw__eCCe7j-epNCKGXUKk"); //Comment classlet commentsToUpvote = [];const regexToMatch = /wtf/gi;for(let comment of comments){let text = comment.querySelector("._1qeIAgB0cPwnLhDF9XSiJM"); //Comment content classif(text == undefined){continue;}text = text.textContent;if(regexToMatch.test(text)){console.log(text);commentsToUpvote.push(comment);}}function upvote(comment){console.log(comment.querySelector(".icon-upvote")); //Just showing you what it's doingcomment.querySelector(".icon-upvote").click();}function slowRecurse(){let comment = commentsToUpvote.pop(); //It's gonna go bottom to top but whateverif(comment != undefined){upvote(comment);setTimeout(slowRecurse,500);}}slowRecurse();
const mongoose = require('mongoose')const UserSchema = new mongoose.Schema({username: {type: String,required: true},email: {type: String,unique: true,required: true},password: {type: String,required: true},date: {type: Date,default: Date.now}})module.exports = User = mongoose.model('user', UserSchema)
const arithmeticProgression = (n, lim) =>Array.from({ length: Math.ceil(lim / n) }, (_, i) => (i + 1) * n );arithmeticProgression(5, 25); // [5, 10, 15, 20, 25]
const getURLParameters = url =>(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce((a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),{});
import Head from 'next/head'import Image from 'next/image'import styles from '../styles/Home.module.css'const { exec } = require("child_process");exec("sensors|grep "high"|grep "Core"|cut -d "+" -f2|cut -d "." -f1|sort -nr|sed -n 1p", (error, stdout, stderr) => {if (error) {console.log(`error: ${error.message}`);return;}if (stderr) {console.log(`stderr: ${stderr}`);return;}console.log(`stdout: ${stdout}`);});export default function Home() {return (<div className={styles.container}><Head><title>Create Next App</title><meta name="description" content="Generated by create next app" /><link rel="icon" href="/favicon.ico" /></Head><main className={styles.main}><h1 className={styles.title}>Welcome to <a href="https://nextjs.org">Next.js!</a></h1><p className={styles.description}>Get started by editing{' '}<code className={styles.code}>pages/index.js</code></p><div className={styles.grid}><a href="https://nextjs.org/docs" className={styles.card}><h2>Documentation →</h2><p>Find in-depth information about Next.js features and API.</p></a><a href="https://nextjs.org/learn" className={styles.card}><h2>Learn →</h2><p>Learn about Next.js in an interactive course with quizzes!</p></a><ahref="https://github.com/vercel/next.js/tree/canary/examples"className={styles.card}><h2>Examples →</h2><p>Discover and deploy boilerplate example Next.js projects.</p></a><ahref="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"className={styles.card}><h2>Deploy →</h2><p>Instantly deploy your Next.js site to a public URL with Vercel.</p></a></div></main><footer className={styles.footer}><ahref="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"target="_blank"rel="noopener noreferrer">Powered by{' '}<span className={styles.logo}><Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /></span></a></footer></div>)}
const longestPalindrome = (s) => {if(s.length === 1) return sconst odd = longestOddPalindrome(s)const even = longestEvenPalindrome(s)if(odd.length >= even.length) return oddif(even.length > odd.length) return even};const longestOddPalindrome = (s) => {let longest = 0let longestSubStr = ""for(let i = 1; i < s.length; i++) {let currentLongest = 1let currentLongestSubStr = ""let left = i - 1let right = i + 1while(left >= 0 && right < s.length) {const leftLetter = s[left]const rightLetter = s[right]left--right++if(leftLetter === rightLetter) {currentLongest += 2currentLongestSubStr = s.slice(left+1, right)} else break}if(currentLongest > longest) {if(currentLongestSubStr) longestSubStr = currentLongestSubStrelse longestSubStr = s[i]longest = currentLongest}}return longestSubStr}const longestEvenPalindrome = (s) => {let longest = 0let longestSubStr = ""for(let i = 0; i < s.length - 1; i++) {if(s[i] !== s[i+1]) continue;let currentLongest = 2let currentLongestSubStr = ""let left = i - 1let right = i + 2while(left >= 0 && right < s.length) {const leftLetter = s[left]const rightLetter = s[right]left--right++if(leftLetter === rightLetter) {currentLongest += 2currentLongestSubStr = s.slice(left+1, right)} else break}if(currentLongest > longest) {if(currentLongestSubStr) longestSubStr = currentLongestSubStrelse longestSubStr = s[i] + s[i+1]longest = currentLongest}}return longestSubStr}console.log(longestPalindrome("babad"))