Posts

Featured post

node.js - How to mock a third-party api calls in the backend -

i'm testing application mocha , supertest, test like var request = require('supertest'), app = require('./bootstrap.js'); describe('...', function() { it('...', function() { request(app) .get('/some/url') // ... }); }); the bootstrap.js real application before listen ports all works perfect have add calls third-party api , testing slow so when do, test example takes 5 seconds request(app) .get('/my/endpoint/that/makes/call/others') // ... how can make fake calls during test real when running application? you can use nock purpose.

java - player naming with loops -

this question has answer here: scanner skipping nextline() after using next(), nextint() or other nextfoo()? 14 answers im having problem loop im doing. when ever run program displays please enter name of player 1? please enter name of player 2? when enter first name automatically prints please enter name of player three. 3 players have been created can name 2 appears advice public static void startgame() { system.out.println("how many players like?"); int noplayers = input.nextint(); (int = 0; < noplayers; i++) { system.out.println("what 1st name of player " + (i + 1) + "?" ); string name = input.nextline(); player player = new player (name, 80); players.add(player); } note 80 money. you should add input.nextline() after int noplayers = input.nextint()

windows - Access denied if Call used along with MOVE in batch script -

here batch script call jekyll build move _site e:\ md temp set src_folder=e:\_site set tar_folder=.\temp /f %%a in ('dir "%src_folder%" /b') move %src_folder%\%%a %tar_folder% pause in script if jekyll build command not used,all move , make directory commands working if call added,the output shown configuration file: e:/workspace/github/rrevanth.github.io/_config.yml source: e:/workspace/github/rrevanth.github.io destination: e:/workspace/github/rrevanth.github.io/_site generating... c:/ruby22-x64/lib/ruby/gems/2.2.0/gems/posix-spawn-0.3.10/lib/posix/spawn.rb:164: warning: cannot close fd before spawn 'which' not recognized internal or external command, operable program or batch file. done. auto-regeneration: disabled. use --watch enable. access denied. subdirectory or file temp exists. here,it showing access denied.is there workaround or doing wrong here. thanks in advance! apparently atte

javascript - How to pass value from a form control via ajax to node.js -

i new jquery/node.js world. so, trying basic stuff getting stuck. checked questions not able hold of right approach. so, here posting code understand wrong here: i using express framework view template engine build using ejs. this script have written in index.ejs <script> $(document).ready(function() { $("button1").click(function() { var obj = $('#text1').val(); $.post("/localhost:3000/",{val: obj}, function(restxt, status, xhr) { if (status=="success") { alert("external content loaded successfully"); //code } if (status=="error") { alert(xhr.status + xhr.statustext); //code } }) }) }); </script> and on index.js render html ejs, have written foll

python - Sending a StringIO to a Twisted FileSender -

i trying send image data filesender in twisted. works fine if use temporary file save image; #works img = image(format='png', blob=base64.decodestring(dt)) img.save(filename='/tmp/tmp.png') file = open('/tmp/tmp.png','rb') filesender = filesender().beginfiletransfer(file, request) def filefinished(ignored): request.finish() filesender.addcallback(filefinished) however do in memory rather file. have tried use stringio this, filesender seems send few bytes before giving up. doing wrong? img = image(format='png', blob=base64.decodestring(dt)) buffer = stringio() img.save(buffer) filesender = filesender().beginfiletransfer(buffer, request) def filefinished(ignored): request.finish() filesender.addcallback(filefinished) your stringio positioned @ eof when try send it. it's surprising sends few bytes (i suspect doesn't , you're seeing http framing). try seeking beginning before call beginfiletransfer . also, do

enums - Possibility of assumption in C# -

can make assumptions on casted int value of system enums in c#? for example: //dayofweek (int)dayofweek.monday == 1, (int)dayofweek.tuesday == 2, (int)dayofweek.wednesday == 3, (int)dayofweek.thursday == 4, (int)dayofweek.friday == 5, (int)dayofweek.saturday == 6, (int)dayofweek.sunday == 0 the logic of code depends on it. however, don't feel writing own mapping, because it... wrong solution. edit here comes culture thing well. iso standard - monday 1st day. in usa - sunday 1st day. yes, can rely on it, insofar documented that: the dayofweek enumeration represents day of week in calendars have 7 days per week. value of constants in enumeration ranges dayofweek.sunday dayofweek.saturday. if cast integer, value ranges 0 (which indicates dayofweek.sunday) 6 (which indicates dayofweek.saturday). of course, while unlikely so, microsoft free change in future releases.

sorting - C++ Most efficient way iterate specific contents in vector -

i have 2 vectors, vec , p, such p vector of pointers different locations in vec. so like: p[0] = &vec[12] p[1] = &vec[20] p[3] = &vec[1] etc. p's size less or equal vec, , contain no duplicate references same location in vec. what i'd have data structure can iterate through dereferenced values of p in order of index pointing in a. above example, result need iterate through in order vec[1], vec[12], vec[20]. i know can position in vec p pointing doing p[i] - &vec[0] , , implement using std::sort , custom comparing function, feel there more efficient way o(nlogn) of sort function. wrong that. thanks help! after discarding few mental ideas, thought of simple one: std::vector<char> is_pointed_to(vec.size(), 0);//initialize "bools" "false" //set is_pointed_to values for(t* pointer : p) { size_t orig_index = pointer - &vec[0]; is_pointed_to[orig_index] = 1; //set index "true" } //now iteration