Posts

Showing posts from April, 2011

php - Android App not syncing with database -

the andriod app i'm developing using http gets/posts using php files on website perform transactions on mysql database. on php side, wrap data json parse on java end of app when receiving response. modified 1 of tables , eliminated unnecessary values table. when poll using php scripts website, polls correctly. when use app, uses same php script polling, returns additional values removed database. i've restarted eclipse, cleaned project, , restarted android vdm refresh it; however, continues find values removed. ideas going on? here php script i'm connecting app: <?php mysql_connect("localhost", "******", "******"); mysql_select_db("bouncet2_pogoapp"); $query = "select * event_table order event asc"; $sql = mysql_query($query); while($row=mysql_fetch_assoc($sql)) $output[]=$row; print(json_encode($output)); mysql_close(); ?> as code in app using script: try { string response = customhttpclient.executehttpget(...

Jpa and spring 3 mvc validation -

i working spring 3 mvc , need validation it. actually validator not working , can't understand reason. i next configuration: in pom.xml add next dependency: <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>4.3.0.final</version> </dependency> i productsform.jsp , add tag: <%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%> i add tags: <form:form> , <form:input> . i write follow in controller: //here show form @requestmapping(value = "products", method = requestmethod.get) public string managmenthome(map model2,model model,httpservletrequest request){ product validationform=new product(); model2.put("validationform",validationform); return "productsform"; } // here process form public string addproduct(@requestparam string product, bindingresult result, map model2,model model, httpservle...

android - Convert String month to integer java -

how convert month string integer? on click method want display date selected if date has event should display more event. method check holiday event requires integer values. here's code: updated: @override public void onclick(view view) { int m = 0; int d, y; string date_month_year = (string) view.gettag(); selecteddaymonthyearbutton.settext("selected: " + date_month_year); string [] datear = date_month_year.split("-"); log.d(tag, "date split: " + datear[0] + " " + datear[1] + " " + datear[2]); y = integer.parseint(datear[2]); try { calendar c1 = calendar.getinstance(); c1.settime(new simpledateformat("mmm").parse(datear[1])); m = c1.get((calendar.month) + 1); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } //int m = integer.parseint(datear[1]); d = integer.parseint(datear[0]); log.d(tag, "date forward: " + d + " " + m + " " + y); if (isholiday(d, m,...

Scipy optimization algorithms? (for minimizing neural network cost function) - python -

i wrote neural network object in python has cost function , determines gradients via back-propogation. see bunch of optimization functions here , have no idea how implement them. i'm having hard time finding example code learn from. clearly need somehow tell parameters i'm trying change, cost function i'm trying minimize, , gradient calculated backprop. how tell, say, fmin_cg what's what? bonus question: can learn differences in uses of various algorithms? ===== ok, update ===== this have atm: def train(self, x, y_vals, iters = 400): t0 = concatenate((self.hid_t.reshape(-1), self.out_t.reshape(-1)), 1) self.forward_prop(x, t0) c = lambda v: self.cost(x, y_vals, v) g = lambda v: self.back_prop(y_vals, v) t_best = fmin_cg(c, t0, g, disp=true, maxiter=iters) self.hid_t = reshape(t_best[:,:(hid_n * (in_n+1))], (hid_n, in_n+1)) self.out_t = reshape(t_best[:,(hid_n * (in_n+1)):], (out_n, hid_n+1)) and, error it's throwing: traceback (most recent call last): file ...

asp.net mvc - It is possible to combine ValidationSummary(true) and ModelState.AddError("field", "error")? -

i use validationsummary(true) print model validation errors in 1 place , property validation errors near each field. in controller add property error : modelstate.adderror("property","error") i see message validation error property got validation-summary-errors div although have no model error. doing wrong , why div generated if have no model errors? <div class="validation-summary-errors"> <ul> <li style="display:none"></li> </ul> </div> you have add twice so: string errormessage = "the error message"; //will show in summary modelstate.addmodelerror(string.empty, errormessage); //will show prop modelstate.addmodelerror("prop", errormessage); or can change call so: @html.validationsummary(false) changing argument false include property errors. param name in validationsummary excludepropertyerrors , passing true excluding them.

c++ - error: invalid initialization of reference of type 'int&' from expression of type 'const int' -

this unrelated question code in this question , regarding following template function. template <class t> class object : public container { public: t& object; object(const t& obj) : object(obj) {} }; this code calls constructor: template <class t> void array::add_element(const t& element) { vec.push_back(new object<t>(element)); } this code compiles fine, add line in main calls it: array array; int = 3; array.add_element(i); i compiler warning: error: invalid initialization of reference of type 'int&' expression of type 'const int' . what about? passed int in. shouldn't automatically turned const int& me? why compiler complaining? obj const reference. object non-const reference. you can't initialize non-const reference const reference, because doing defeat purpose of having const reference in first place. if want instance of object able modify int that's passed constructor, constructor should take no...

matlab - find out the orientation, length and radius of capped rectangular object -

Image
i have image shown fig.1. trying fit binary image capped rectangular (fig.2) figure out: the orientation (the angle between long axis , horizontal axis) the length (l) , radius (r) of object. best way it? help. my naive idea using least square fit find out these information found out there no equation capped rectangle. in matlab there function called rectangle can create capped rectangle seems plot purpose. i solved 2 different ways , have notes on each approach below. each method varies in complexity need decide best trade application. first approach: least-squares-optimization: here used unconstrained optimization through matlab's fminunc() function. take @ matlab's see options can set prior optimization. made simple choices approach working you. in summary, setup model of capped rectangle function of parameters, l, w, , theta. can include r if wish don't think need that; examining continuity half-semi-circles @ each edge, think may sufficient let r = w, in...

sql - How to translate PostgreSQL "merge_db" (aka upsert) function into MySQL -

straight manual, here's canonical example of merge_db in postgresql : create table db (a int primary key, b text); create function merge_db(key int, data text) returns void $$ begin loop -- first try update key update db set b = data = key; if found return; end if; -- not there, try insert key -- if else inserts same key concurrently, -- unique-key failure begin insert db(a,b) values (key, data); return; exception when unique_violation -- nothing, , loop try update again. end; end loop; end; $$ language plpgsql; select merge_db(1, 'david'); select merge_db(1, 'dennis'); can expressed user-defined function in mysql, , if so, how? there advantage on mysql's standard insert...on duplicate key update ? note: i'm looking user-defined function, not insert...on duplicate key update . tested on mysql 5.5.14. create table db (a int primary key, b text); delimiter // create procedure merge_db(k int, data text) begin declare done boolean; repeat begin -- if th...

Rails: Multiple layouts with Devise -

how can have different layout depending on wether user logged in or not? follow instructions at https://github.com/plataformatec/devise/wiki/how-to%3a-create-custom-layouts , make check if user logged in, devise means checking user_signed_in? , devise helper. specifically: class applicationcontroller < actioncontroller::base layout :layout_by_resource protected def layout_by_resource if user_signed_in? "special_layout_name_for_logged_in" else "application" end end end and put special_layout_for_logged_in.html.erb view file in layouts directory.

asp.net mvc 4 - Is it possible to unit test BundleConfig in MVC4? -

as far can tell, answer no. issue i'm seeing comes include(params string[]) method in system.web.optimization.bundle class. internally invokes system.web.optimization.includedirectory(string, string, bool) , in turn uses code: directoryinfo directoryinfo = new directoryinfo( httpcontext.current.server.mappath(directoryvirtualpath)); while possible set httpcontext.current during unit test, can't figure out how make .server.mappath(string directoryvirtualpath) return non-null string. since directoryinfo(string) constructor throws exception when passed null argument, such test fail. what .net team's recommendation this? have unit test bundling configurations part of integration tests or user acceptance tests? i have news you, rtm added new static property on bundletable enable more unit tests: public static func<string, string> mappathmethod; edit updated test virtual path provider: so can this: public class testvirtualpathprovider : virtualpathprovide...

JavaScript libraries that connects two Raphael objects in flowchart connectors style? -

i searching js lib works on raphael object. means conects multiple raphael objects in flowchart connectors style. works jsplumb dosent work raphael object. plz me know if know such js lib. in advance dracula quite good, though not active anymore. raphaël offers own extension, called graffle , made purpose. can play around the demo . see this answer on similar post, author of dracula , listing many alternatives.

android - I tried this below code to set increment and decrement values in edittext field .But its not working why? -

package com.inc.increment; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.view.onclicklistener; import android.view.view; import android.widget.button; import android.widget.edittext; public class increment extends activity implements onclicklistener { int a,b; button b1,b2; edittext edittext; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_increment); b1 = (button) findviewbyid(r.id.button1); b1.setonclicklistener(this); b2 = (button) findviewbyid(r.id.button2); b2.setonclicklistener(this); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.activity_increment, menu); return true; } public void onclick(view v) { // perform increment/decrement if (r.id.button1 == v.getid()) { edittext = (edittext) findviewbyid(r.id.timepicker_input); a=integer.parseint(edittext.gettext().tostring()); b=a+1; string s1 = string.va...

c++ - std::bind to std::function? -

i compile error using this: std::vector<std::function<int(int)>> functions; std::function<int(int, int)> foo = [](int a, int b){ return + b; }; std::function<int(int)> bar = std::bind(foo, 2); functions.push_back(bar); the error is: /usr/include/c++/4.6/functional:1764:40: error: no match call '(std::_bind<std::function<int(int, int)>(int)>) (int)' can tell me how convert std::bind std::function ? std::function<int(int)> bar = std::bind(foo, 2, std::placeholders::_1);

actionscript 3 - Connecting to a local socket server from SWF on remote page -

i have kiosk connects local socket server can access hardware. if kiosk code stored locally, can access socket perfectly. however, , know reason, if kiosk code hosted on remote server, can not access local socket server because of sandbox violation. the problem of these kiosks hosted on appengine, when done making changes, takes hours render out single html file, , change css/js location links. is there anyway possible allow swf file access local socket server when hostel remotely? also, socket server java app dont have source to. run locally through terminal i've had same problem. the thing flash player 10 security sockets has become stricter. placing crossdomain.xml on server won't - have send crossdomain policy file client connects. the simplest solution provided adobe - they've provided couple of scripts, 1 perl , 1 python, set policy file server. can find them here: setting socket policy server

How to select multiple deep DOM using JQUERY -

i have multiple level dom elements, still finding how select dom element. html here. <div class="data"> <div class="item"> <form class="comment" method="post" action=""> <div class="d1"> <a href="">tree</a> <p> </p> </div> <div class="d2"> <p class="quote"> </div> <div class="col p3"> <input type="hidden" name="token" value=""/><input type="hidden" name="u" value=""/><input type="button" class="button" name="submit"/><br> <abbr class="selected_dom" title="2012-07-05t11:29:22z">july 1, 2012</abbr> </div> </form> </div> </div> can please me how select <abbr class="selected_dom" title="2012-07-05t11:29:22z">july 1, 201...

json - API Twitter + PHP + JSON_decode -

Image
trying api of twitter, got problem... use url: https://api.twitter.com/1/statuses/oembed.json?id= &align=center i file_get_contents json , insert bd, before insert, see json have slashes , can json_decode, but, once string inserted, slashes disappear! cant json_decode when query sql, can do?? thank you! json returned api twitter: string(878) "{"type":"rich","provider_name":"twitter","height":null,"html":"\u003cblockquote class=\"twitter-tweet tw-align-center\" lang=\"es\"\u003e\u003cp\u003e\u00bfc\u00f3mo se llama esa cancion que suena \"aaronu ri lorunarenuronuaanale nararinunaloaalaiiaaranu reaa runaiiriiirorinaleaanatinurorela\"?\u003c\/p\u003e— comosuenaesa (@comosuenaesa) \u003ca href=\"https:\/\/twitter.com\/comosuenaesa\/status\/221453498653478914\" data-datetime=\"2012-07-07t04:00:03+00:00\"\u003ejulio 7, 2012\u003c\/a\u003e\u003c\/blockquote\u003e...