Posts

javascript - setTimeout is not working correctly inside "for loop" -

now of course, code make do. but i'm confused why in following code: var = { 0: "hi", 1: "bye" } (var b in a) { settimeout(function () { console.log(b); }, 1000); } instead of consoling "0" , "1" i "1" twice. i'm not sure why happens. need setup script making same issue. it because usage of closure wrong. in case using closure variable b inside settimeout callback, value of variable b not looked until callback executed, value of updated last value in object. one of solution in such case create local closure given below for (var b in a) { (function(c){ settimeout(function () { console.log(c); }, 1000); })(b) } demo: fiddle

c++ - How can I make an object immutable in the Google V8 Javascript engine? -

is possible make object immutable in v8 javascript engine? v8 embedded in c++ application. in case i've created , populated array (code simplified) auto arr = v8::array::new(isolate, 10); (auto = 0; < 10; ++i) { arr->set(context, i, v8::integer::new(isolate, i)); } i'd make resulting object "read-only" (as might calling object.freeze ) before passing script. 1 of script authors got in confusing situation trying re-use object convoluted way, , i'd make harder happen making object immutable. i understand can in javascript ( object.freeze ), able in c++ if possible. this approach works, although it's little inelegant. essentially, i'm calling "object.freeze" directly in javascript, couldn't find way invoke functionality c++. i'm less fluent in v8, code may unnecessarily verbose. /** * make object immutable calling "object.freeze". * https://developer.mozilla.org/en-us/docs/web/javascript/reference...

java - ArrayList size() method crashing program -

i developing game using lwjgl 3.0.0b , strange occurrence has come up. background: i have custom entity class , entity manager store entities in. when entity updated method gets called named " ticktrail " adds in trail entity make graphics visually better , entertaining. already have simplified down entities.size() function, yes try solve myself :p a solution have replacing methods similar this: for (int = 0; < entities.size(); i++) { //calls method drawing, updating, or input } to replace every single entities.size() size . size being variable changed upon when entity added, removed, list cleared, or enemies removed. this method work 100%, window dragging not crash program using method. question so sum up, final question why occur? haven't determined why dragging window , using arraylist's size() method crashes program, yet storing variable in place fine. any or explanation strange phenomenon highly appreciated :) edit last edit pro...

Excel VBA: Error in file format when saved using VBA -

Image
i trying format contents of excel file, , automatically save in specified location specified name via dialog box. have codes below, experiencing issues file format after save file. issue excel prompts me: this code allows me format excel file format require, , automatically shows location , file name want save in. codes allows me save me excel file successfully. however, when try open it, tells me file corrupted, or extension wrong. does know why experiencing error? thanks! code: option explicit sub externalratingchangefile() 'declare data type of variables dim wks worksheet dim lastcol integer dim lastrow long dim icol integer dim irow long dim sfilename string dim fdlg filedialog dim xlsxfileformat xlfileformat 'set wks current active worksheet set wks = activeworkbook.activesheet set fdlg = application.filedialog(msofiledialogfilepicker) 'set location save file variable sfilename = "h:\testing file\rating change - " + format(date, "yyyymm...

javascript - Dropdown Menu not working on Index.html after adding java script -

i creating personal website can not drop down work on desktop when on mobile devise hide nav , click(using js) show nav. not working on index.html <div class="content"> <div class="header"> <div class="logo"><a href="assets/img/logo.png" alt="gm">gm</a> </div> <span class="menu-trigger">menu</span> <nav class="nav clearfix"> <ul class="clearfix"> <li><a class="active" href="index.html">home</a> </li> <li><a href="about.html">about</a> </li> <li><a href="#">portfolio <i class="fa fa-angle-down fa-1"></i></a> <ul class="sub-nav"> ...

apache spark - How to declare Iterator and DenseMatrix type variable in operation mapPartition of RDD? -

i have double array in mappartition of rdd,and when declare iterator or densematrix double array.i found iterator , matrix empty.my test codes below: val randxts = data.map{ line => val fields = patterns.findallin(line).toarray.map(_.todouble) fields(fields.length-1) }.repartition(2) val res = randxts.mappartitions(x=>{ val matrix = new densematrix(x.length,1,x.toarray) val arr = matrix.toarray println(k.length) (matrix::list[densematrix[double]]()).iterator }) as shown above,the line declare matrix cause error.the error message below: java.lang.indexoutofboundsexception: storage array has size 0 indices can grow large 124 how can fix problem? your code calls x.length , passes x again densematrix constructor. since x iterator, calling length "consumes" iterator, hence passing again result in empty collection. to fix - scan iterator once (by converting array): val res: rdd[densematrix] = randxts.mappartitions(x => { val arr = x.to...

PHP mail reply to sender instead of server email -

can point out getting form wrong? instead of being able reply " email " sender server email. here php code: <?php $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; $from = 'from: business.com'; $to = 'anyone@gmail.com'; $subject = 'a new message website business.com'; $human = $_post['human']; $headers = 'from: info@business.com' . "\r\n" . 'reply-to: ' . $email . "\r\n" . 'x-mailer: php/' . phpversion(); $body = "from: $name\n e-mail: $email\n message:\n $message"; if ($_post['submit']) { if ($name != '' && $email != '') { if ($human == '4') { if (mail ($to, $subject, $body, $from)) { echo '<p>your message has been sent!</p>'; } else { echo ...