logic
Ruby if .. elsIf .. else on a single line?
a = (foo && “a” or bar && “b” or “c”) or a = (“a” if foo) || (“b” if bar) || “c”
How can I simplify this set of if statements? (Or, what’s making it feel so awkward?)
One reason it looks like a lot of code is that it is very repetitive. Use variables to store the parts that are repeated, and that will help with the readability: private List<Foo> parseResponse(Response<ByteString> response) { Status status = response.status(); int code = status.code(); boolean payloadAbsent = !response.payload().isPresent(); if (code != Status.OK.code() || payloadAbsent) { … Read more
Universal and Existential Quantifiers of First-Order Logic
That sentence is full of jargon. You can find a description of universal and existential logical quantifiers here. A Universal Quantifier is a logical statement that applies to all elements of a set. An Existential Quantifier is a logical statement that applies to at least one element of a set. You can also look here … Read more
What are the best uses of Logic Programming?
Prototyping. Prolog is dynamic and has been for 50 years. The compiler is liberal, the syntax minimalist, and “doing stuff” is easy, fun and efficient. SWI-Prolog has a built-in tracer (debugger!), and even a graphical tracer. You can change the code on the fly, using make/0, you can dynamically load modules, add a few lines … Read more
oracle sql date not later than today
For last 24 hours: Where publish_date >= sysdate -1 or anytime today (midnight forward) where publish_date >= trunc(sysdate) If this is a big table, I assume you have an index on publish_date. If you use trunc(publish_date), it may not be able to use the index (untested, but run an explain plan to be sure).
How do I determine if *exactly* one boolean is true, without type conversion?
You can actually accomplish this using only boolean logic, although there’s perhaps no practical value of that in your example. The boolean version is much more involved than simply counting the number of true values. Anyway, for the sake of satisfying intellectual curiosity, here goes. First, the idea of using a series of XORs is … Read more
Is it common for 0 to mean ‘true’ and 1 to mean ‘false’ in a C API?
It is common for comparison functions to return 0 on “equals”, so that they can also return a negative number for “less than” and a positive number for “greater than”. strcmp() and memcmp() work like this. It is, however, idiomatic for zero to be false and nonzero to be true, because this is how the … Read more
Reason for “all” and “any” result on empty lists
How about some analogies… You have a sock drawer, but it is currently empty. Does it contain any black sock? No – you don’t have any socks at all so you certainly don’t have a black one. Clearly any([]) must return false – if it returned true this would be counter-intuitive. The case for all([]) … Read more
jQuery password strength checker
The best way is to take an existing plugin as TJB suggested. As to your question about the code itself, a nicer way is to write it like that: var pass = “f00Bar!”; var strength = 1; var arr = [/.{5,}/, /[a-z]+/, /[0-9]+/, /[A-Z]+/]; jQuery.map(arr, function(regexp) { if(pass.match(regexp)) strength++; }); (Modified to correct syntax errors.)