How can I disable an in a based on its value in JavaScript?

JavaScript, in 2022 You can use querySelectorAll, and forEach off of the resulting NodeList to do this same thing more easily in 2022. document.querySelectorAll(“#foo option”).forEach(opt => { if (opt.value == “StackOverflow”) { opt.disabled = true; } }); Do be mindful of string-comparisons, however. ‘StackOverflow’ and ‘stackoverflow’ are not the same string. As such, you can … Read more

Python Binomial Coefficient

This question is old but as it comes up high on search results I will point out that scipy has two functions for computing the binomial coefficients: scipy.special.binom() scipy.special.comb() import scipy.special # the two give the same results scipy.special.binom(10, 5) # 252.0 scipy.special.comb(10, 5) # 252.0 scipy.special.binom(300, 150) # 9.375970277281882e+88 scipy.special.comb(300, 150) # 9.375970277281882e+88 # … Read more

How does Rust provide move semantics?

I think it’s a very common issue when coming from C++. In C++ you are doing everything explicitly when it comes to copying and moving. The language was designed around copying and references. With C++11 the ability to “move” stuff was glued onto that system. Rust on the other hand took a fresh start. Rust … Read more

“Safe” TO_NUMBER()

From Oracle Database 12c Release 2 you could use TO_NUMBER with DEFAULT … ON CONVERSION ERROR: SELECT TO_NUMBER(‘*’ DEFAULT 0 ON CONVERSION ERROR) AS “Value” FROM DUAL; Or CAST: SELECT CAST(‘*’ AS NUMBER DEFAULT 0 ON CONVERSION ERROR) AS “Value” FROM DUAL; db<>fiddle demo

How to display list items as columns?

This can be done using CSS3 columns quite easily. Here’s an example, HTML: #limheight { height: 300px; /*your fixed height*/ -webkit-column-count: 3; -moz-column-count: 3; column-count: 3; /*3 in those rules is just placeholder — can be anything*/ } #limheight li { display: inline-block; /*necessary*/ } <ul id = “limheight”> <li><a href=””>Glee is awesome 1</a></li> <li><a … Read more

Which is more efficient: Return a value vs. Pass by reference?

First of all, take in account that returning an object will always be more readable (and very similar in performance) than having it passed by reference, so could be more interesting for your project to return the object and increase readability without having important performance differences. If you want to know how to have the … Read more