Posts

Is there a C# String.Format() equivalent in JavaScript? -

this question has answer here: equivalent of string.format in jquery 19 answers c# has powerful string.format() replacing elements {0} with parameters. javascript have equivalent? try sprintf() javascript . or // first, checks if isn't implemented yet. if (!string.prototype.format) { string.prototype.format = function() { var args = arguments; return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match ; }); }; } "{0} dead, {1} alive! {0} {2}".format("asp", "asp.net") both answers pulled javascript equivalent printf/string.format

java - Running caliper from eclipse in maven's test scope -

i have java project in eclipse, junit tests in src/test directory. i've added class tests caliper microbenchmarks, , i'd able run these tests within eclipse. as caliper code test code, i've added caliper dependency in maven in test scope. makes show in classpath when run junit tests, can't see way run arbitrary class test dependencies in classpath. tried doing adding new run configuration java application, thinking launch calipermain right class parameter, caliper jar not on classpath , can't see how add it. i don't want move benchmark code , dependency main scope, it's test code! seems overkill move separate project. you should able maven exec plugin . project, opted make benchmark profile can run maven command mvn compile -p benchmarks . to configure this, can add along lines of following pom.xml , specifying scope of classpath test using <classpathscope> tag: <profiles> <profile> <id>benc...

if statement - Common If Structure -

more , more find myself writing structure of if statements looks this: if(something) { if(somethingelse) { // if both evaluate true. dosomething(); } else { // if first if true second not. dosomethingelse(); } } else { // if first evaluates false. dosomethingdifferent(); } now, me, looks horrific. have cleaner way of representing logic? the question as-is has 3 cases: something & somethingelse , something & !somethingelse , , !something . alternative break out if-else 3 branches: if(something & somethingelse) { // if both evaluate true. dosomething(); } elif(something) { // explicit test of somethingelse falsity not required // if first if true second not. dosomethingelse(); } else { // if first evaluates false. dosomethingdifferent(); } for such simple case, prefer flatten structure above. more complex cases, can end being simpler nest, or better reduce tests kind of structure (a l...

json - Preserve column names when converting the results of a query to hstore -

i have table users columns user_id , user_name , user_phone example. if do: select hstore(u) users u the result is: "user_id" => "1", "user_name" => "mcenroe", "user_phone" => "xxx" if do: select hstore(u) (select user_id, user_name, user_phone users) u the result is: "f1" => "1", "f2" => "mcenroe", "f3" => "xxx" i lose name of columns. how can use 2nd example , having correct column name? this shortcoming fixed postgres 9.2 . quote release notes 9.2 here : e.5.3.3. queries (...) retain column names @ run time row expressions (andrew dunstan, tom lane) this change allows better results when row value converted hstore or json type: fields of resulting value have expected names. also, don't use user table name, if it's demo. reserved word in every sql standard , in postgres...

Struts2 json model -

i following problems when enter action: struts problem report struts has detected unhandled exception: messages: java.lang.reflect.invocationtargetexception org.apache.struts2.json.jsonexception: java.lang.reflect.invocationtargetexception org.apache.struts2.json.jsonexception: org.apache.struts2.json.jsonexception: java.lang.reflect.invocationtargetexception file: model/empresa.java line number: 34 //action private static final long serialversionuid = 1l; private sincronizaservice service = new sincronizaserviceimp(); //your result list private list<sincroniza> gridmodel; //get how many rows want have grid - rownum attribute in grid private integer rows = 0; //get requested page. default grid sets 1. private integer page = 0; // sorting order - asc or desc private string sord; // index row - i.e. user click sort. private string sidx; // search f...

java - Dynamically build table from bean -

i'm building application lot of tables (or forms) representing details of given data row. quite big , not nice have add fields (with handler, logic, etc.) 1 one. what have factory able build form (or table) given bean. created pretty nice factory using java reflection discover gwt not support it... is there suit needs? because gwt's compilation monolithic (there can no class that'd unknown @ compile-time used @ runtime), means code generated. because can generated, means can during gwt compilation using so-called deferred binding . gwt generator can use reflection on classes known @ compile-time, it'll distinct api java.reflect (just java annotation processors use distinct api). you common-denominator identify classes need taken account in generation (e.g. implement same marker interface, or extend same base class) , generate 1 table/form each, , either: an interface type parameter object edit/render, directly represent generated table/form; yo...

Flash/ActionScript - Use .mp3 file in library in a movieclip -

Image
i've imported mp3 file library , made actionscript class, can't access in movieclip. edit: i'm using adobe air, because want compile android application set as linkage sound (in library panel) then paste code in movieclip (first keyframe) var snd:snd=new snd(); snd.play(); hope helps