Posts

dictionary - C++ STL associative containers: Get iterator from element? -

this has been asked vectors . possible sets & co too? c.equal_range(elem); for set-like, or c.equal_range(elem.first); for map-type containers return pair of iterators equivalent (under container's rules) element. takes between o(k) , o(lg n) time, n number of elements in container, , k number of elements pseudo-equivalent elem / elem.first (pseudo, hash collisions modulo bucket count count). average constant (for unordered)/lg n (for ordered).

c# - Dependency injection for a static method -

this question has answer here: dependency injection static logger, static helper class 4 answers i have class in api, have static method, intended validate , log details. guidance how inject ilogger interface please. public class validatedatainapi { public static bool isvalid(string data) { //do if(error) { _logger.error("log error implemented caller"); } } } if understand correctly, want inject instance of ilogger static method. figured out cannot make use of dependency injection "normal way" when dependent method static. what might looking here service locator pattern . using structuremap ioc container (but can use container), configuration wiring might this: for<ilogger>().use<someloggerimplementation>(); when implemented, calling code might this: public c...

Why 'segmentation fault' occurs in the following C code -

$hoho b abcd $hoho | lala segmentation fault lala.c --> #include<stdio.h> int main(int argc, char* argv){ printf("%s\n", argv[1]); ... } then, how can use std_input a, b , abcd your main() has wrong signature. it's not int main(int argc, char* argv) it's int main(int argc, char **argv) or equivalently int main(int argc, char *argv[]) you trying print char "%s" specifier, printf() function tries read string , interprets char value address because it's expecting char pointer, leads undefined behavior 1 , hence problem. 1 please read link posted @ souravghosh answer advice.

Throwing custom error messages in java struts -

are there useful patterns or best practices throwing/showing user friendly error messages in struts 1? if(something nasty...) { throw new userexception("very bad thing happened"); } else if(something other nasty...) { throw new userexception("other thing happened"); } .... other 100 cases because using above sample in validate() method on , on again seems bit redundant , unprofessional. create actionmessage(s) , display these. there better information here can give you: http://www.mkyong.com/struts/struts-logic-messages-present-logic-messages-notpresent-example/

angularjs - AngualrJS ElasticUI dependency injection -

i have question regarding dependency injection in angular. i'm using elasticui: https://github.com/yousefed/elasticui the index-name needs set inside tag. <body ng-app="tutorial" eui-index="'index_name'"> is possible set index_name "outside" ? angular.module('tutorial', ['elasticui']). ??? i don't know angular. i'm sorry if stupid question... thanks help! it's passing value directive. in controller: .controller('mycontroller', function($scope) { $scope.indexname = "asdsd"; }) in html: <body ng-app="tutorial" ng-controller="mycontroller" eui-index="indexname">

java - How to load log4j2 configuration file from JNDI -

i migrating web applications log4j 1.12 log4j2. due company policies our log4j.xml file locations configured urls in application server , applications have them jndi. implemented servletcontextlistener allowed initialize log4j infraestructure way: public void contextinitialized(servletcontextevent servletcontextevent) { ... urllogconfig = (url) context.lookup("java:comp/env/"+loglocation); ... //urllogconfig -> file:///somepath/log4j.xml domconfigurator.configureandwatch(urllogconfig.getpath()); } public void contextdestroyed(servletcontextevent servletcontextevent) { servletcontext servletcontext = servletcontextevent.getservletcontext(); servletcontext.log("log4jconfigurationlistener - shutting down log4j"); logmanager.shutdown(); } however, log4j2 api changes can no longer used. log4j2 provides lo4j2-web.jar module uses log4jservletcontainerinitializer initialize library. ends calling log4jwebinitializerimpl.getconfigu...

Show the euro simbol in a shiny R application -

i'm trying create shiny r application. have troubles show euro symbol (and return it) in radio button. i've tried different version of code: library(shiny) runapp(list( ui= navbarpage(title = 'shoe euro', radiobuttons('var', 'var', c("income_mgl", "income_mgl€", "income_mgl&euro;", "income_mgl&#8364;", "income_mgl\u20ac") )), server=function(input, output, session) { })) but "€" doesn't appear in web page. if select second option page returns error: "error in fromjson(content, handler, default.size, depth, allowcomments, : invalid json input" the problem lies in class shiny-options-group in div function. way class works appears convert & &amp; , preventing browser converting &#8364; € because first changes &amp;#8364; . try following ui.r see happen. library(shiny) options = as.list(c("a...