My string check doesnt work and I dont know what is the most eficient method to do it

So I have a code to check if a string matches a certain pattern, this pattern: 555-555-5555 (555)555-5555 (555) 555-5555 555 555 5555 5555555555 1 555 555 5555 for exemple this should return true: 1 456 789 4444 but it doesnt here’s my code: function telephoneCheck(str) { str = str.split(”); for (let c in str)… Read More My string check doesnt work and I dont know what is the most eficient method to do it

Why do I get the "can't read properties of null" error, when using "querySelectorAll.forEach"?

Here is the code I have right now. It’s purpose is to place an event listener on every button with the same class using querySelectorAll and some loop (currently using forEach), and make it a togglable "fav", toggling which will add or subtract 1 from the text in the span inside the button: const likeButtonArray… Read More Why do I get the "can't read properties of null" error, when using "querySelectorAll.forEach"?

How to generalize a comparison in Java code

Say I have a Filter interface public interface Filter { public boolean satisfies(Earthquake earthquake) } Which can have different implementations (one such below) public final class MagnitudeFilter implements Filter { private final double minimumMagnitude; private final double maximumMagnitude; private final ComparisonStrategy strategy; public MagnitudeFilter(double minimumMagnitude, double maximumMagnitude, ComparisonStrategy strategy) { this.minimumMagnitude = minimumMagnitude; this.maximumMagnitude =… Read More How to generalize a comparison in Java code

Interpret interpolated html tag as html, not string literal?

I’m trying have the HTML tag <br> interpreted as a line break, but instead it displays as a string literal in the view when I attempt this: <%= property.address_line_2 + "<br>" if property.address_line_2.present? %> I tried raw() and .html_safe but they the same effect. <%= property.address_line_2 + raw("<br>") if property.address_line_2.present? %> <%= property.address_line_2 + "<br>".html_safe… Read More Interpret interpolated html tag as html, not string literal?

If an app has multiple models with the same field, whats the best practice for keeping things DRY?

For example, if I have 3 models that look like this: class CallLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields class EmailLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields class TextLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields Do I add lead_id to each model individually or is there a way to only type it… Read More If an app has multiple models with the same field, whats the best practice for keeping things DRY?

async/await vs callback resolution order, given shared asynchronicity

If async/await & callbacks are both asynchronous, why are async/await resolved before callbacks? For example (hypothetical, in practice its obviously not so cut-and-dry) // classic callback doSomething("./some-path", (err, data) => {…}) // This resolves with higher priority await someAsyncFunction() >Solution : In short, callbacks go to the end of the line in the regular job… Read More async/await vs callback resolution order, given shared asynchronicity

Define multiple buttons for Windows commands

I’m writing a script that will run Windows commands for work ( I will convert it to an executable ). Eventually the script will have 10-15 buttons. How can I make it DRYer? from tkinter import * import os, ctypes, sys os.system(‘cmd /c "color a"’) root=Tk() root.title(‘Common Fixes’) root.geometry("1000×100") def is_admin(): try: return ctypes.windll.shell32.IsUserAnAdmin() except:… Read More Define multiple buttons for Windows commands