Posts

how to autobuild an associated polymorphic activerecord object in rails 3 -

how to autobuild an associated polymorphic activerecord object in rails 3 - class itemsource < activerecord::base belongs_to :product, :polymorphic => true end class randomproduct < activerecord::base has_one :item_source, :as => :product, :autosave => true, :dependent => :destroy end what i'd is call: a = randomproduct.find(1) a.item_source and if item_source doesn't exist (= nil), build automatically (build_item_source). previously, did alias_chain_method, that's not supported in rails 3. oh, , tried no avail: class randomproduct < activerecord::base has_one :item_source, :as => :product, :autosave => true, :dependent => :destroy module autobuilditemsource def item_source super || build_item_source end end include autobuilditemsource end in rails 3, alias_method_chain (and alias_method , , alias ) work fine: class user < activerecord::base has_one :profile, :inverse_of => :...

Javascript animation of CSS classes? -

Javascript animation of CSS classes? - is possible animate replacement of class in javascript? let's consider have this: .class1 {background-color:blue;} .class2 {background-color:red;} is there javascript library can ease alter between 2 classes? wouldn't create user's computer explode? if not, way of achieving that? server-generated javascript file? yes, jquery can when have jqueryui loaded well. see demo here: http://jqueryui.com/demos/addclass/ here's illustration specific css. http://jsfiddle.net/hhept/ div { width: 100px; height: 100px; } .class1 {background-color:blue;} .class2 {background-color:red;}​ <div class='class1'></div> $('div').addclass('class2', 1000); javascript css

java - What's the problem with this code? -

java - What's the problem with this code? - hi when run next code getting numberformatexception can help me out in debugging code. import java.io.*; public class case1 { public static void main(string args[]) { char ch='y';int i=0; bufferedreader bf=new bufferedreader(new inputstreamreader(system.in)); system.out.println("ch before while:::"+ch); while(ch=='y'||ch=='y'){ try{ system.out.println("enter option"); i=integer.parseint(bf.readline()); system.out.println("after"+i); switch { case 1 ystem.out.println("1"); break; case 2 ystem.out.println("1"); break; } system.out.println("do u want continue(y/y"); ch=(char)bf.read(); system.out.println("ch after execution:::"+ch); } catch(numberformatexception e){e.printstacktrace();} catch(ioe...

iphone - cellForRowAtIndexPath always return nil -

iphone - cellForRowAtIndexPath always return nil - i have created sample application insert 12 rows in tableview.and inserted fine.when after inserted rows dont want changes in text during scrolling of tableview.so checked indexpath row has value of uitableviewcell , if has values means homecoming cell otherwise created new uitableviewcell. my sample code below - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } // customize number of rows in table view. - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { nslog(@"globalcount = %d",globalcount); homecoming globalcount; } - (uitableviewcell *)tableview:(uitableview *)tv cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *obj = (uitableviewcell*)[tableview cellforrowatindexpath:indexpath]; if(obj!=nil) { nslog(@"cell indexpath row = %d",indexpath.row); nslog(@"cell text = %d",obj.textlabel.t...

python - Pandas Difference in DataFrames -

python - Pandas Difference in DataFrames - i trying figure out how display differences between 2 pandas dataframes. there can't seem figure out how display additional info rows contain difference. here have far: compare dataframe dataframe b: dataframe a: date id_1 id_2 value 1-jan 1 1 5 2-jan 1 2 6 3-jan 1 3 4 4-jan 1 4 2 5-jan 1 5 8 dataframe b: date id_1 id_2 value 1-jan 1 1 5 2-jan 1 2 6 3-jan 1 3 4 4-jan 1 4 2 5-jan 1 5 55 current output: date column 5-jan value 8 55 desired output: date id_1 id_2 5-jan 1 5 8 55 current code: #stack column(s) dataframes not equal ne_stacked = (df1 != df2).stack() #create new dataframe ne_stacked changed = ne_stacked[ne_stacked] #change column names changed.index.names = ['date', 'column'] #create array dataframes not equal diff_loc = np.where(df1 != df2) #create 'from' column changed_from...

java - Application/JSON is Unsupported Media Type in restful webservice -

java - Application/JSON is Unsupported Media Type in restful webservice - i trying create restful-jersey webservice. have pass json object webservice. @post @path("/savevehicletrackingdata") @consumes(mediatype.application_json) @produces(mediatype.text_plain) public string savevehicletrackingdata(vehicletracking vehicletracking) { homecoming vehicletracking.tostring(); } when seek try create request service, says http status 415 - unsupported media type. please help. also, should type of single argument of method savevehicletrackingdata. ps: using postman create http request. http://goo.gl/vwxnxq update : pointed out peeskillet, missing thing here json provider. next challenge have is, how integrate json provider in project. after researching little, found fasterxml jackson 1 of json provider. this image reference. had post. basically when utilize raw, default text/plain . json in drop down, select syntax high...

c++ - Can a std::ifstream/FILE* change size? -

c++ - Can a std::ifstream/FILE* change size? - say have next code (which opens file, gets size, , reads in 1 go): std::ifstream file(path, std::ios_base::binary | std::ios_base::ate); std::istream::streampos file_size = file.tellg(); file.seekg(0); char* buffer = new char[file_size]; file.read(buffer, file_size); is possible file alter size in between file.tellg() , file.read() calls (i.e. programme modifies file)? is, if file.read() succeeds, guaranteed file.gcount() == file_size ? and extending c* (i.e. doing fopen("rb") , fseek() , ftell() , rewind() , fread() ), if fread() succeeds, homecoming file size (as reported ftell() )? i'm leaning towards beingness implementation defined, i'm curious if c++ standard (or c standard, c++ standard refers file -related functions) makes guarantees here or not. *i'm working in c++, , there 2 ways me work files: std::fstream , file* . c++ standard defers c standard regarding file* functions, why br...