‏إظهار الرسائل ذات التسميات Check. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات Check. إظهار كافة الرسائل

الأحد، 5 يناير 2014

Check the Errorlevel value and process the if command

The "problem" with your code is that when the parser reach that line, the %errorlevel% variable is replaced with its value, and then the line is executed. So, any change to the value of the variable is not seen. The "usual" way of handling this cases is enabling delayed expansion and change the %errorlevel% sintax with !errorlevel! to indicate the parser that the value will change and need to be retrieved at execution time.

But, in this case, as you have the requirement of a "one liner", change the if test to

if errorlevel 1 (echo "SQL Not Installed") else (echo "SQL Installed")

A standard construct to check for errorlevel without reading the variable value.

You have also the posibility to code it as

reg query .... && echo Installed || echo Not Installed

This executes the reg command (with all your parameters, of course). On success, the command after && is executed. On failure the command after || is executed.


View the original article here

Cassandra row update check in a table

Is there any way to check whether a row in a table has been modified or not in Cassandra. I don't want to compare the date before and after updating row in table. After Update operation I need to verify the query executed properly or not using python scripts. I am using Cassandra Driver for python.


View the original article here

how to check input boxes according to values

You can iterate through the array of values, then check each input based on the product ID.

list.forEach(function(item) { $('#product_'+ item).prop('checked', true);});

.forEach() documentation

.prop() documentation


View the original article here

الجمعة، 20 ديسمبر 2013

Check multiple exceptions in Scala retry control structure

I'm trying to develop a control structure that retries on some declared exceptions but throw others. The control structure works nicely but I have problem checking if the exception caught belongs to the types of declared exceptions. In more generic words, how do I check if a parameter is one of the declared list of type parameters?

Define a retry control structure:

def retry[T, R](times:Int=3, delay:Int=1000)(ex:Class[_<:Exception]*)(t:T)(block:T=>R):R = {try { block(t)}catch { case e:Exception if (isOneOf(e, ex:_*) && times>0) => { println(s"Exception $e happened, sleep $delay milliseconds") Thread.sleep(delay) println(s"$times times remain for retry before give up") retry(times-1, delay)(ex:_*)(t)(block) } case e:Throwable => { println(s"Exception $e is not handled") throw e }}

}

define a function that throws multiple exceptions

def d(str:String) = { val r = Math.random() println(r) if (r>0.6) throw new IllegalArgumentException else if (r>0.4) throw new java.io.IOException else if (r>0.2) throw new UnsupportedOperationException else println(str)}

and I can call the function with retry as:

retry(3, 1000)(classOf[IllegalArgumentException], classOf[java.io.IOException])("abc"){ x=> d(x)}

I'm want to retry on IllegalArgumentException and IOException, but will throw UnsupportedOperationException.

For the retry structure, the list of declared exceptions is passed in dynamically at runtime. So multiple exception case statement does not work for me. When an exception is caught, I match it with generic exception, check the exception type with the isOneOf function. Ideally the function will take a sequence of types, instead of a sequence of classes. How do I pass in a sequence of exception types, rather than a sequence of classes and check the caught exception against the sequence of types?


View the original article here