Posts

javascript - multiple .on events AND detecting keypress -

i run function this: $(document).on('change, focusout', '.something', function(){ ... } i handler execute when keypress == 13. what's best approach? do if statement $(document).on('change focusout keypress', '.something', function(e){ if(e.keycode == 13 ) { //code here } });

php - Obtaining categories and subcategories joined from Mysql tables -

i have 3 tables. 1 table called places , table holds different places (such businesses, restaurants, etc...) each "place" linked table called categories , categories have subcategories in hierarchical structure (i.e. thai food subcategory of restaurants). system lets admin create places , matches them corresponding category or subcategory. what know best way obtain these relations? using joins , group_concat still not getting result set. these tables: places: +----+----------------+ | id | name | +----+----------------+ | 1 | mings place | +----+----------------+ | 2 | halsey library | +----+----------------+ | 3 | stellas uso | +----+----------------+ places_categories_rel : +----------+-------------+ | place_id | category_id | +----------+-------------+ | 1 | 2 | +----------+-------------+ | 2 | 4 | +----------+-------------+ | 3 | 3 | +----------+-------------+ | 3 | 4 | ...

algorithm - Given an array of ranges find the total distance covered? -

here interview question heard about. have range of arrays elements length 2 arrays starting point , end point on number line. there can overlaps. need return total distance covered. how solve this? example: input: [[3,5], [1,3], [2,4]] output: 4 my thoughts: you'd need keep track of ranges covered , if value in particular range. not sure how though? here implementation. since every range has min value , max value (|min|------|max|) if have sorted list , can find distance wasn't covered subtracting current min last max. if value negative, know no difference found between 2 ranges. don't have include range, store new maximum. import java.util.arraylist; import java.util.hashmap; public class main { public static void main(string[] args) { //given sorted array index @ 0 // (equal array[0] sorted array[1]. //if array isn't sorted sort here arraylist<int[]> ranges = new arraylist<>(); ranges.a...

c++ - String pointer manipulation -

i have assignment @ school. string pointer passed function , returns 2 const strings different functions. 2 new strings divide original string 2 parts based on space. example: input str = 05/12 hello desired output key = 05/12 satdata = hello this code wrote giving me errors. please help void rbapp::processinsert(string &str) { string *key = new string(); string *satdata = new string(); int = 0, j =0; while(str[i]!=" ") { key[j] = str[i]; i++; j++; } j = 0; while(str[i]!='\0') { satdata[j] = str[i]; i++; j++; } myrbt.rbinsert(key, satdata); } using stringstream void rbapp::processinsert(const std::string &str) { std::stringstream ss(str); std::string key; std::string satdata; ss >> key; ss >> satdata; myrbt.rbinsert(key, satdata); }

javascript - Error in Rails with JS code -

Image
rails not let me run js code, have these errors 1) 2) whenever add js code, errors appear. idea why happening? just because you're getting error highlights in ide, doesn't mean code wrong. try running server, navigate site browser, , check developer console. still see javascript errors?

c# - ToArray doesn't seem to be working Moq's Verify method -

i'm trying verify method call using moq following code. var _payload= new list<keyvaluepair<string, object>> { new keyvaluepair<string, object>("test", testnum), new keyvaluepair<string, object>("firstruntime", datetime.parse("19-apr-2001 09:30:00")) }; the above list definition common both following pieces of code. i'd tried this:: mockmessageprocessor.verify(service => service.queuemessage( datetime.parse("19-apr-2016 10:05:00"), "testjobkey", _payload.toarray()), times.once); this fails saying there no invocation of above method parameters. putting same thing in variable works. var payloadarray = _payload.toarray(); mockmessageprocessor.verify(service => service.queuemessage( datetime.parse("19-apr-2016 10:05:00"), "testjobkey", payloadarray), times.once); the above verify works. wanted know why happening. quoting aro...

ios - No method declared with Objective c selector 'scale' -

i'm following stanford lecture on ios development. want create pinch gesture can enlarge or reduce size of smiley face. here original code: faceview.addgesturerecognizer(uipinchgesturerecognizer(target: faceview, action: "scale:")) however, xcode complained " no method declared objective c selector 'scale' ". i followed suggestion replace "scale:" selector("scale:") still display same error message. i did bit of research online , found out swift 2.2, syntax selector has changed #selector(myclass.methodname) , changed line of code faceview.addgesturerecognizer(uipinchgesturerecognizer(target: faceview, action: #selector(faceview.scale))) this time, no error message displayed, when run project , tried enlarge or reduce smiley face in simulator, not change size @ all. seems changed since last release. you have been suggested use #selector(myclass.methodname) documentation correct syntax in case of stanford...