AngularJS, ui.router, load template and controller based on user role

Loading template and controller based on user role While technically ui-router templateUrl function does not support injecting services you can use templateProvider to inject service that holds role variable or loads it asynchronously and then use $templateFactory to return HTML content. Consider following example: var app = angular.module(‘app’, [‘ui.router’]); app.service(‘session’, function($timeout, $q){ this.role = null; … Read more

Deduction of the function

No, you (currently) cannot. The standard way of doing this is by creating “make_like” function (such as make_pair, make_optional …): template<typename F, typename… Args> A<std::decay_t<F>> make_A (F &&f, Args&&… args) { return {std::forward<F>(f), std::forward<Args>(args)…}; } C++17 will introduce template argument deduction for class which will allow you to do exactly what you want (see also … Read more

Difference between * and node() in XSLT

<xsl:template match=”node()”> is an abbreviation for: <xsl:template match=”child::node()”> This matches any node type that can be selected via the child:: axis: element text-node processing-instruction (PI) node comment node. On the other side: <xsl:template match=”*”> is an abbreviation for: <xsl:template match=”child::*”> This matches any element. The XPath expression: someAxis::* matches any node of the primary node-type … Read more

Identifying primitive types in templates

UPDATE: Since C++11, use the is_fundamental template from the standard library: #include <type_traits> template<class T> void test() { if (std::is_fundamental<T>::value) { // … } else { // … } } // Generic: Not primitive template<class T> bool isPrimitiveType() { return false; } // Now, you have to create specializations for **all** primitive types template<> bool … Read more

Switch passed type from template

Yes, it is…but it probably won’t work the way you expect. template < typename T > void foo() { if (is_same<T, SomeClass>::value) …; else if (is_same<T, SomeClass2>::value) …; } You can get is_same from std:: or boost:: depending on your desire/compiler. The former is only in C++0x. The problem comes with what is in …. … Read more

How can C# allow virtual generic methods where C++ can’t allow virtual template methods?

Running this code and analyzing the IL and generated ASM allows us to see what is going on: internal class Program { [MethodImpl(MethodImplOptions.NoInlining)] private static void Test() { var b = GetA(); b.GenericVirtual<string>(); b.GenericVirtual<int>(); b.GenericVirtual<StringBuilder>(); b.GenericVirtual<int>(); b.GenericVirtual<StringBuilder>(); b.GenericVirtual<string>(); b.NormalVirtual(); } [MethodImpl(MethodImplOptions.NoInlining)] private static A GetA() { return new B(); } private class A { public … Read more

How to display current year in Flask template?

Use a template context processor to pass the current date to every template, then render its year attribute. from datetime import datetime @app.context_processor def inject_now(): return {‘now’: datetime.utcnow()} {{ now.year }} Or pass the object with render if you don’t need it in most templates. return render_template(‘show.html’, now=datetime.utcnow())

SFINAE to check for inherited member functions

Take a look at this thread: http://lists.boost.org/boost-users/2009/01/44538.php Derived from the code linked to in that discussion: #include <iostream> template <typename Type> class has_foo { class yes { char m;}; class no { yes m[2];}; struct BaseMixin { void foo(){} }; struct Base : public Type, public BaseMixin {}; template <typename T, T t> class Helper{}; … Read more

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