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

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

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.)