Posts

algorithm - Find Shortest Path -

Image
there’s m*n grid, filled black , white color. given start point , end point. white points passed, how find shortest path between start , end? any thoughts appreciated. there multiple algorithm matter, of important algorithms : dijkstra bellman ford floyd warshall even bfs algorithms choice.

asp.net mvc - Design | maintainable | conditionals view | MVC -

have view need show address details in view name street state , city, washington now sequence of address needs differ each country china want below format name state , city, washington street so have done written if else statement in view , have format , earlier have no issues 1 or 2 countries but seeing same kind of different request each countries, make view heavy , not maintainable can provide pattern have more maintainable 1 have different partial view each country , load partial view etc ok best option have different views different countries , return them controller based on identifier.this keep code maintainable.for sure dont use if - else. can create multiple partial views each country if not fields dynamically sequenced.keep static ones on main view , dynamic in partial view. now if have far many countries , don't want maintain individual views option create htmlhelper extension , use create view dynamically in code , return mvchtmlstring can use...

Custom json response for internal exception in spring -

while implementing global exception handler in spring, noticed in case of not recognized accept header, spring throw it's own internal error. need return custom json error structure instead. works fine application specific exceptions , totally fails spring httpmediatypenotacceptableexception. this code tells me "failed invoke @exceptionhandler method: public java.util.map restexceptionhandler.springmalformedacceptheaderexception()" when try request page incorrect accept header. other way return custom json spring internal exceptions? @controlleradvice public class restexceptionhandler { @exceptionhandler(value = httpmediatypenotacceptableexception.class) @responsebody public map<string, string> springmalformedacceptheaderexception() { map<string, string> test = new hashmap<string, string>(); test.put("test", "test"); return test; } } eventually figured way json mapping ma...

objective c - Set NSButton enabled based on NSArrayController selection -

Image
ok, i've set nstableview bound nsarraycontroller . now, have nsbutton want make "enabled" when there is selection, , disabled when there nothing selected. so, i'm bind nsbutton 's enabled array controller's selection value transformer of nsisnotnil . however, doesn't seem working. am missing anything? regardless of whether or not selected, selection property of nsarraycontroller returns object ( _nscontrollerproxyobject ). why binding isn't working way expect, because selection never nil . instead, bind selectionindexes , rather selection , , have value transformer called selectionindexescountiszero implemented so: @interface selectionindexescountiszero : nsvaluetransformer @end @implementation selectionindexescountiszero + (class)transformedvalueclass { return [nsnumber class]; } + (bool)allowsreversetransformation { return no; } - (id)transformedvalue:(nsindexset *)value { return [nsnumber numberwithbool:[value co...

javascript - how to use svgz file in html5 and jboss server -

i using html5,jquery , jboss server developing spring j2ee project. using svg file in website.this files big size did compress svg svgz type. have problem loading svgz file in browser. my html code is: <embed width="100%" height="100%" style="opacity: 0.6;" src="${context}/resources/svg/valentines_day_heart_card_vector.svgz" type="image/svg+xml" /> the error is: this page contains following errors: error on line 1 @ column 1: document empty below rendering of page first error. how can solve it? check svg resource url available (that it's not 404) check it's sent correct mediatype, image/svg+xml check it's served content-encoding: gzip http header you might want consider using transfer-encoding: gzip instead, that's you. see e.g https://stackapps.com/questions/916/why-content-encoding-gzip-rather-than-transfer-encoding-gzip .

ruby on rails - Set activerecord model defaults before mass assignment initialize -

i need defaults (from remote service) in modela set before object passed view modelacontroller#new . have used after_initialize this. however, in #create have problem. if use model_b.create_model_a(some_attributes) , attributes passed in during initialization , overwritten after_initialize call: class modela < activerecord::base after_initialize :set_defaults, if: :new_record? def set_defaults self.c = "default" #actually remote call, not can set database default end end class modelb < activerecord::base belongs_to :model_a end class modelacontroller < applicationcontroller #modela nested under modelb in routes.rb #get /model_bs/:model_b_id/model_as/new def new model_b = modelb.find(params[:model_b_id]) #no problem respond_with model_b.build_model_a end #post /model_bs/:model_b_id/model_as def create model_b = modelb.find(params[:id]) #problem: respond_with model_b.create_model_a({c: "not default...

c# - edit in detailsview with dropdownlist -

i new @ asp.net c#. edit detailsview dropdown list. have followed instructions on link -- this link -- , orrigionally thought of. flawed however, because although can see items on dropdown list, not update database. @ loss. have been trying find answer couple of days , unsure of need do. there need in backend? attach code @ end well. have nothing going on in backend. <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:it_supportconnectionstring %>" deletecommand="delete [issues] [issue_id] = @issue_id" insertcommand="insert [issues] ([requestor], [email], [urgency], [issue_type], [details], [priority], [issue_manager], [status], [date_reported]) values (@requestor, @email, @urgency, @issue_type, @details, @priority, @issue_manager, @status, @date_reported)" selectcommand="select issues.issue_id, issues.requestor, issues.email, issues.phone, issues.urgency, i...