Nested if else in Twig

elseif needs to be single word tag/keyword and expression shouldn’t have parenthesis same as if expression. http://twig.sensiolabs.org/doc/tags/if.html <body {% if page|default(‘login’) == ‘login’ %} class=”login” {% elseif page == ‘other’ %} class=”login” {% else %} class=”noclass” {% endif %}> </body>

Extract numbers from a field in PostgreSQL

Simply: SELECT NULLIF(regexp_replace(po_number, ‘\D’,”,’g’), ”)::numeric AS result FROM tbl; \D being the class shorthand for “not a digit”. And you need the 4th parameter ‘g’ (for “globally”) to replace all occurrences. Details in the manual. For a known, limited set of characters to replace, plain string manipulation functions like replace() or translate() are substantially cheaper. … Read more

How to instantiate only part of a function template if a condition is true

Type traits: #include <iostream> #include <type_traits> // C++0x //#include <tr1/type_traits> // C++03, use std::tr1 template<typename T> void printType(T param) { if(std::is_same<T,char*>::value) std::cout << “char*” << endl; else if(std::is_same<T,int>::value) std::cout << “int” << endl; else std::cout << “???” << endl; } Or even better yet, just overload the function: template<class T> void printType(T partam){ std::cout << … Read more

Wait x seconds or until a condition becomes true

Assuming you want what you asked for, as opposed to suggestions for redesigning your code, you should look at Awaitility. For example, if you want to see if a file will be created within the next 10 seconds, you do something like: await().atMost(10, SECONDS).until(() -> myFile.exists()); It’s mainly aimed at testing, but does the specific … Read more

Rxjs conditional switchMap based on a condition

Another possibility is to use the operator iif in a SwitchMap. https://www.learnrxjs.io/learn-rxjs/operators/conditional/iif https://rxjs-dev.firebaseapp.com/api/index/function/iif but it can restrain the possibility to control specfic conditions on your Observable : myObservable1 .pipe( switchMap(result1 => iif(() => condition , myObservable2 , myObservable1 ) ) .subscribe(result => console.log(result)); Where you can replace ‘condition’ by a function returning a boolean. With … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)