Loading...
More JavaScript Posts
function filePath(file){let folders = file.getParents();const parents = [];function makePathString(folderArray){let path = "";folderArray.forEach((folder)=>{path += "/" + folder.getName();});return path;}while (folders.hasNext()) {const folder = folders.next(); //This should hopefully remove that folder from the iteratorparents.unshift(folder);}return makePathString(parents);}function myFunction() {const myEmail = Session.getEffectiveUser().getEmail();Logger.log("My email is " + myEmail);// Log the name of every file in the user's Drive.var fileIterator = DriveApp.getFiles();const files = []; //List of [File, size] entriesconst filesMaxSize = 10;while (fileIterator.hasNext()) {var file = fileIterator.next();const owner = file.getOwner();//Only files I ownif((!(owner)) || (!(owner.getEmail)) || owner.getEmail() != myEmail){continue;}const entry = [file, file.getSize()];function slideUp(arr, index){//Let's keep sliding it up so we don't have to sort it at the end.for(let i = index; i > 0; --i){ //Stops at 1const nextFile = arr[i-1];if(nextFile[1] > entry[1]){break;}else{//Swap with the next file to slide the file upconst temp = arr[i];arr[i] = arr[i - 1];arr[i - 1] = temp;}}}if(files.length < filesMaxSize){files.push(entry);slideUp(files, files.length - 1);}else{if(entry[1] > files[files.length - 1][1]){ //If it's bigger than the smallest file in the list.files[files.length - 1] = entry; //Replace the smallest fileslideUp(files, files.length - 1); //Slide it up}}}for(let i = 0; i < filesMaxSize; ++i){const file = files[i][0];const size = files[i][1];Logger.log(size + "\t" + filePath(file) + "/" + file.getName() + "\t" + file.getOwner().getName());}}
class TreeNode {constructor(key, value = key, parent = null) {this.key = key;this.value = value;this.parent = parent;this.children = [];}get isLeaf() {return this.children.length === 0;}get hasChildren() {return !this.isLeaf;}}class Tree {constructor(key, value = key) {this.root = new TreeNode(key, value);}*preOrderTraversal(node = this.root) {yield node;if (node.children.length) {for (let child of node.children) {yield* this.preOrderTraversal(child);}}}*postOrderTraversal(node = this.root) {if (node.children.length) {for (let child of node.children) {yield* this.postOrderTraversal(child);}}yield node;}insert(parentNodeKey, key, value = key) {for (let node of this.preOrderTraversal()) {if (node.key === parentNodeKey) {node.children.push(new TreeNode(key, value, node));return true;}}return false;}remove(key) {for (let node of this.preOrderTraversal()) {const filtered = node.children.filter(c => c.key !== key);if (filtered.length !== node.children.length) {node.children = filtered;return true;}}return false;}find(key) {for (let node of this.preOrderTraversal()) {if (node.key === key) return node;}return undefined;}}const tree = new Tree(1, 'AB');tree.insert(1, 11, 'AC');tree.insert(1, 12, 'BC');tree.insert(12, 121, 'BG');[...tree.preOrderTraversal()].map(x => x.value);// ['AB', 'AC', 'BC', 'BCG']tree.root.value; // 'AB'tree.root.hasChildren; // truetree.find(12).isLeaf; // falsetree.find(121).isLeaf; // truetree.find(121).parent.value; // 'BC'tree.remove(12);[...tree.postOrderTraversal()].map(x => x.value);// ['AC', 'AB']
//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 MongoClient = require('mongodb').MongoClient;const assert = require('assert');// Connection URLconst url = 'mongodb://localhost:27017';// Database Nameconst dbName = 'myproject';// Use connect method to connect to the serverMongoClient.connect(url, function(err, client) {assert.equal(null, err);console.log("Connected successfully to server");const db = client.db(dbName);client.close();});
function Welcome(props) {return <h1>Hello, {props.name}</h1>;}function App() {return (<div><Welcome name="Sara" /><Welcome name="Cahal" /><Welcome name="Edite" /></div>);}ReactDOM.render(<App />,document.getElementById('root'));
//QM Helper by Leif Messinger//Groups numbers by number of bits and shows their binary representations.//To be used on x.comconst 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 bitslet 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";}}