What's the best way to trim std::string?

What's the best way to trim std::string?

I'm currently using the following code to right-trim all the std::strings in my programs:std::string s;s.erase(s.find_last_not_of(" \n\r\t")+1);It works fine, but I wonder if there are some end-cases where it might fail?Of course, answers w

How do I watch a file for changes?

How do I watch a file for changes?

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I'd like to read the new data in to do some processing on it.What's the best way to do this? I was hoping there'd be some sort o

Is there a function to extract a 'column' from an array in PHP?

Is there a function to extract a 'column' from an array in PHP?

I have an array of arrays, with the following structure :array(array('page' => 'page1', 'name' => 'pagename1') array('page' => 'page2', 'name' => 'pagename2') array('page' => 'page3', 'name' => 'pagename3'))Is there a bui

Generate a matrix containing all combinations of elements taken from n vectors

Generate a matrix containing all combinations of elements taken from n vectors

This question pops up quite often in one form or another (see for example here or here). So I thought I'd present it in a general form, and provide an answer which might serve for future reference. Given an arbitrary number n of vectors of

When to use self over $this?

When to use self over $this?

In PHP 5, what is the difference between using self and $this?When is each appropriate? 1:Short Answer Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static

When is .then(success, fail) considered an antipattern for promises?

When is .then(success, fail) considered an antipattern for promises?

I had a look at the bluebird promise FAQ, in which it mentions that .then(success, fail) is an antipattern. I don't quite understand its explanation as for the try and catch. What's wrong with this the following?some_promise_call().then(fun

How to initialize javascript date to a particular timezone

How to initialize javascript date to a particular timezone

I have date time in a particular timezone as a string and I want to convert this to the local time. But, I don't know how to set the timezone in the Date object.For example, I have Feb 28 2013 7:00 PM ET, then I can var mydate = new Date();

Fastest way to list all primes below N

Fastest way to list all primes below N

This is the best algorithm I could come up.def get_primes(n): numbers = set(range(n, 1, -1)) primes = [] while numbers: p = numbers.pop() primes.append(p) numbers.difference_update(set(range(p*2, n+1, p))) r

How to check visibility of software keyboard in Android?

How to check visibility of software keyboard in Android?

I need to do a very simple thing - find out if the software keyboard is shown. Is this possible in Android? 1:NEW ANSWER added Jan 25th 2012Since writing the below answer, someone clued me in to the existence of ViewTreeObserver and frie

How do I format a Microsoft JSON date?

How do I format a Microsoft JSON date?

I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this:/Date(1224043200

How do I add a library project to Android Studio?

How do I add a library project to Android Studio?

How do I add a library project (such as Sherlock ABS) to Android Studio? (Not to the old ADT Eclipse-based bundle, but to the new Android Studio.) 1:Update for Android Studio 1.0Since Android Studio 1.0 was released (and a lot of version

Why is Java Vector class considered obsolete or deprecated?

Why is Java Vector class considered obsolete or deprecated?

Why is Java Vector considered a legacy class, obsolete or deprecated?Isn't its use valid when working with concurrency?And if I don't want to manually synchronize objects and just want to use a thread-safe collection without needing to make

Why is my Spring @Autowired field null?

Why is my Spring @Autowired field null?

Note: This is intended to be a canonical answer for a common problem.I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try to use it. The logs show that both the M

How do you use JSHint and Browserify together?

How do you use JSHint and Browserify together?

I'm attempting to build a project using Angular and Browserify. My controllers.js file looks like this...'use strict';module.exports.testController = function($scope){ $scope.message = 'Controller 1'; console.log( 'hello' );};As you m

PHP Convert String into Float/Double

PHP Convert String into Float/Double

I have list of string (size in bytes), I read those from file. Let say one of the string is 2968789218, but when I convert it to float it become 2.00.This is my code so far :$string = "2968789218";$float = (float)$string;//$float = floatval

New Google Sheets custom functions sometimes display “Loading…” indefinitely

New Google Sheets custom functions sometimes display “Loading…” indefinitely

SPECIFIC FOR: "NEW" google sheets only.This is a known issue as highlighted by google in the new sheets.Issues: If you write complex* custom functions in google-apps-script for google sheets, you will occasionally run into cells which displ

pros and cons of db and ndb in google app engine

pros and cons of db and ndb in google app engine

I have seen a little of this in stack overflow but I am wondering if there is any reason to use the DB entity model and what the specific pros and cons of using on or the other are.I have read the ndb is a little faster and that it helps wi

Missing makecert.exe

Missing makecert.exe

For some reason I am missing makecert.exe on my system. I searched the whole hard drive and it's not there. In particular, it's not in C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin where I believe it's supposed to be. I haven't found an

How to generate VS proj with both 32-bit and 64-bit configurations using CMake

How to generate VS proj with both 32-bit and 64-bit configurations using CMake

Does any one know how to generate a VS proj/soln file with both 32-bit and 64-bit configurations using CMake. 1:You can't. With CMake you can generate separate solution files for 32-bit and 64-bit depending on the Visual Studio generator

debug_backtrace() from registered shutdown function in PHP

debug_backtrace() from registered shutdown function in PHP

While tinkering for an answer to this question, I found that debug_backtrace() doesn't trace beyond the function registered to register_shutdown_function(), when called from within it.This was mentioned in this comment for register_shutdown

response.writeHead and response.end in NodeJs

response.writeHead and response.end in NodeJs

var https = require('https');var fs = require('fs');var options = { key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')};https.createServer(options, function (req, res) {

MongoDB's ISODate() vs. UNIX Timestamp

MongoDB's ISODate() vs. UNIX Timestamp

Is there any sort of advantage (performance, indexes, size, etc) to storing dates in MongoDB as an ISODate() vs. storing as a regular UNIX timestamp? 1:The amount of overhead of a ISODate compared to a time_t is trivial compared to the a

How about Haskell's GC performance for soft realtime application like games?

How about Haskell's GC performance for soft realtime application like games?

Because I realized game rule logic should handle huge complexity, I'm considering using of non-typical language in game field as in-game logic script language. The reason of in-game script is representing complex logic with less code. So ex

What is jQuery (edge) in jsfiddle.net?

What is jQuery (edge) in jsfiddle.net?

In jsfiddle.net if one choose framework as jQuery or Mootools they will get an option for choosing jQuery ( edge ) and Mootools( edge ).I googled it quite a bit but did not get any good answers. My questions areWhat are those versions?How a

Declarations in extensions cannot override yet error in Swift 4

Declarations in extensions cannot override yet error in Swift 4

I have an extension:public extension UIWindow { override public func topMostController()->UIViewController? { ... }}but for my topMostController I get the next error:Declarations in extensions cannot override yet errorIt works well for S