Posts

io - Writing to a text file issue Java -

i coding function check if file cq.txt exists , if so, read it. have been having issue have declared printwriter outside of while loop. later in application, supposed write question 1: correct or question 2: correct file. but, not. creates text file when check it, shows empty. here code, thank in advance: package receiverhost; import java.io.*; import java.net.*; public class receiverhost { public static void main(string[] args) throws exception { //set socket on port 5000 serversocket server = new serversocket(5000); //set "cookie"/ text file written to/ read writer db = new bufferedwriter(new outputstreamwriter(new fileoutputstream("cq.txt"), "utf-8")); system.out.println("tcpserver waiting client on port 5000"); while(true){ //declare string fromclient string fromclient; socket connected = server.accept(); system.out.println(" client" + " " + connec...

r - How to combine columns with identical names in a large sparse Matrix -

i have sparse dgtmatrix matrix package, has picked duplicate colnames . want combine these summing columns same names, forming reduced matrix. i found this post , adapted sparse matrix operations. but: it's still slow on large objects. wondering if has better solution operates directly on indexed elements of sparse matrix faster. instance, a@j indexes (from zero) labels in a@dimnames[[2]] , compacted , used reindex a@j . (note: why used triplet sparse matrix form rather matrix default of column-sparse matrixes since figuring out p value makes head hurt every time.) require(matrix) # set (triplet) sparsematrix <- sparsematrix(i = c(1, 2, 1, 2, 1, 2), j = 1:6, x = rep(1:3, 2), givecsparse = false, dimnames = list(paste0("r", 1:2), rep(letters[1:3], 2))) ## 2 x 6 sparse matrix of class "dgtmatrix" ## b c b c ## r1 1 . 3 . 2 . ## r2 . 2 . 1 . 3 str(a) ## formal class 'dgtmatrix' [package "mat...

angularjs - [JavaScript][Angular]: TypeError: Cannot read property 'getCityData' of undefined -

this question has been asked many times before , i've tried answers not seem solve problem i'm facing. i'm new angular , trying pass value controller factory can retrieve json information through api. while i'm able value html controller, next step giving me typeerror: cannot read property 'getcitydata' of undefined. controller code follows: app.controller('maincontroller', ['$scope', function($scope, httpgetter) { var successfunction = function(data) { $scope.data = data; } var errorfunction = function(data) { console.log("something went wrong: " + data); } $scope.cityname = ''; $scope.getcityname = function(city) { $scope.cityname = city; httpgetter.getcitydata($scope.cityname, successfunction, errorfunction); }; }]); the factory code follows: app.factory('httpgetter', ['$http', function($http){ return { getcitydata: function(query, ...

javascript - { [Error: listen EADDRINUSE :::5000] -

what's wrong following server.js file? trying connect deployd heroku , keep getting following error. we're using nitrous, , have configure mongodb port 5000. appreciated. ton! server.js // require deployd var deployd = require('deployd'); // configure database etc. var server = deployd({ port: process.env.port || 5000, env: 'production', db: { host: '0.0.0.0', port: 5000, name: 'database_name', credentials: { username: 'username', password: 'password' } } }); // heroku requires these settings sockets work server.sockets.server.set('transports', ["xhr-polling"]); // start server server.listen(); // debug server.on('listening', function() { console.log("server listening on port: " + process.env.port); }); // deployd requires server.on('error', function(err) { console.error(err); process.nexttick(function() { // give server chance return error process.exit...

vba - How do I insert text at my cursor location in Word? -

i'm trying have excel macro insert text @ cursor location in already-opened word document. this have written. i'm aware activedocument.range has start , end arguments, cannot seem able assign them "current selection" value. help? thanks? sub inserttext() dim rngtemp word.range set rngtemp = activedocument.range rngtemp .insertafter "this sample text" .font.name = "tahoma" .font.size = 11 .insertparagraphafter end end sub the current selection selection . if, indicate, need use in excel macro that's automating word, need use word.application object you've declared , instantiated qualify it. this: dim wdapp word.application set wdapp = getobject(, "word.application") wdapp.selection.text = "text @ current selection" 'get range current selection dim rng word.range set rng = wdapp.selection.range rng.text = "this text replace text in current selection" rng.collapse wdco...

java - Akka actors processes one message at a time -

akka actor can process 1 message @ time , hence dont need worry concurrency. consider have system pizza shop. design this 1)webservice 2)akka ecosystem actors pizaacreater, deliveryhandler 3)web service accepts ther order , passes pizzacreater,pizzacreater creates pizza , passes deliveryhanlder. now there 1 instance of pizzacreater , deliveryhandler.this slow down entire system. 1)should create multiple pizzacreaters , deliveryhandler? 2)how customerservice pass order pizzacreater minimum load or how pizzacreater pass pizza delivieryhandler minimum load then? 3)is creating multiple instance of pizzacreaters / deliveryhandler ok? if "pizza creation" blocking operation (uses network/db) create router pizzacreatorworkers (the number of workers/threads depends on scenario). if "pizza creation" non-blocking - create 1 actor per request. same thing delivery: create router fixed number of deliveryhandles if delivery blocking otherwise create actor...

java - Regular expression not matching on first and last word of string -

i trying write java program specific words in string. have working part doesnt seem match if word match first or last word in string. here example: "trying find first word".matches(".*[^a-z]find[^a-z].*") //returns true "trying find first word".matches(".*[^a-z]trying[^a-z].*") //returns false "trying find first word".matches(".*[^a-z]word[^a-z].*") //returns false any idea how make match on word in string? thanks in advance, craig the problem character class before , after words [^a-z] - think want word boundary character \b (as per colind's comment) opposed not character in a-z range. pointed out in comments (thanks) you'll needs handle start , end of string cases. so try, eg: "(?:^|.*\b)trying(?:\b.*|$)"