Posts

python 2.7 - How to stop recursive function before index out of range? -

def isincreasing(ls): if not ls: print "list empty or short" return return (false if ls[0] > ls[1] else isincreasing(ls[1:])) i have made check if list sorted. how can make function stop when there no more check? im getting error "list index out of range". just add: checking if 2 elements in list checking if 1 element or no element in list code: def isincreasing(ls): if len(ls) < 2: print "list empty or short" return if len(ls) == 2: return ls[0] < ls[1] return (false if ls[0] > ls[1] else isincreasing(ls[1:])) print "{}", isincreasing({}) print "[]", isincreasing([]) print [1,2,3], isincreasing([1,2,3]) print [4,6,8], isincreasing([4,6,8]) print [2,1,2,3], isincreasing([2,1,2,3]) print [1,2,3,2], isincreasing([1,2,3,2]) print [3,2,1], isincreasing([3,2,1]) output: {} list empty or short none [] list empty or short none [1, 2, 3] true [4, 6, 8] ...

jquery - Selectbox OnChange copy this text to div -

how can change div text selectbox option selected text... i have selectbox more 100 values scenario: select option selectbox, same option value(text) has replaced relevant div text has ccy class <div class="ccy">blablabla</div> class... eg: have selectbox eur, usd, jpy, inr etc... if select eur selectbox, relevant divs has class ccy <div class='ccy'>currency 1</div><div class='ccy'>currency 2</div> should changed <div class='ccy'>eur</div><div class='ccy'>eur</div> , on... fiddle html <select id="currencty-selectbox"> <option value="1">eur</option> <option value="2">usd</option> <option value="3">jpy</option> <option value="4">cad</option> <option value="5">mxn</option> <option value="6">czk<...

PHP: how to get variables from a JSON(sent from a Swift iOS app) and respond with a JSON -

i developing ios app swift should fetch data mysql database according user's location. don't know php , couldn't find resource explains how receive data app. i have php code: <?php // create connection $con=mysqli_connect("localhost","*******","*******","*******"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } // sql statement selects table 'locations' $sql = "select * *******"; // check if there results if ($result = mysqli_query($con, $sql)) { // if so, create results array , temporary 1 // hold data $resultarray = array(); $temparray = array(); // loop through each row in result set while($row = $result->fetch_object()) { // add each row our results array $temparray = $row; array_push($resultarray, $temparray); } // finally, encode array json , output results ...

node.js - Passport.js / Express.js Creating New Session on Every Network Request -

i have working login function authenticates , saves. however, express never remembers old session, creates new 1 every network request. evidently, passport exceedingly sensitive order express middleware initialized. (example: https://www.airpair.com/express/posts/expressjs-and-passportjs-sessions-deep-dive ). checked config against number of examples , rearranged if help, hasn't moved bug. either isn't issue or haven't found config holy grail yet. here's current config: express config app.engine('html', require('ejs').renderfile); app.set('view engine', 'html'); app.use(express.static(path.join(config.root, '/views'))); app.set('views', config.root + '/views'); var sessionopts = { saveuninitialized: true, resave: false, store: new redisstore({ host: 'localhost', port: 6379 }), secret: 'keyboard', cookie: { httponly: true, maxage: 1000...

ruby on rails - Changing position of options via the admin panel -

i have below method rearranging position of radio , checkbox images app. def change_position if !self.position.blank? existing_model=part.where("ancestry = #{self.ancestry} , position = #{self.position}") if !existing_model[0].blank? if !self.changes['position'].blank? existing_model[0].update_columns(position: self.changes['position'][0]) end end end end but when trying change position of parent option, getting below error in rails admin panel. sqlite3::sqlexception: near "and": syntax error: select "parts".* "parts" (ancestry = , position = 2) order created_at asc why not able save position parent options position here? any here?

javascript - How to stop iteration on error | Node.js and MongoDB -

got little problem here that's taking me long solve. might idiot because feel simple problem cant wrap head around it. here's code: get_online = function (err, result) { if (err) { return next(err); } streamers_size = result.length; result.map( function (entry) { curl.get .to('https://api.twitch.tv/kraken/streams/' + entry.uname) .then(update_streamers); } ); }, update_streamers = function (err, result) { var clean; if (err) { return next(err); } if (result.stream) { db.collection('streamers').update({ _id: result.stream.channel._id }, { $set: { stream_preview: result.stream.preview.large, viewers: result.stream.viewers } }, send_response); } ...

Java: Reading part of a text file -

i'm trying print out sections of text file. right text file consists of jack <id 123.456> doug <id 231.345> this have far in terms of code: bufferedreader reader = new bufferedreader(new filereader("file.txt")); string readbuff = reader.readline(); string tempstring = ""; while (readbuff != null) { if (tempstring.equals("<id ") && !readbuff.equals(">")) { tempstring = readbuff; system.out.println(tempstring); } readbuff = reader.readline(); } reader.close(); i hoping print out id section (i.e. "123.456" , "231.345") of each line right doesn't print anything. appreciated. try code: fileinputstream fis = new fileinputstream(new file("file.txt")); bufferedreader br = new bufferedreader(new inputstreamreader(fis)); string line = null; while ((line = br.readline()) != null) { str...