问:
npm install - error This version of node/NAN/v8 requires a C++11 compiler libxmljs@0.18.0 node-gyp rebuild
I'm running CentOS 6.8(Final) using Vagrant/VirtualBox.
GCC compiler version is (v4.4.7)
Node version (latest LTS): v4.4.6

My package.json file has:

```<code>{
  "name": "njse",
  "main": "server.js",
  "description": "MyCompany services",
  "repository": "",
  "license": "",
  "dependencies": {
    "bunyan": "^1.8.1",
    "dns": "^0.2.2",
    "express": "~4.0.0",
    "express-delay": "~0.1.0",
    "libxmljs": "^0.18.0",
    "mssql": "^3.3.0",
    "ping": "^0.1.10",
    "powershell": "^2.0.2",
    "q": "^1.4.1",
    "q-io": "^1.13.2",
    "validatorjs": "^2.0.11",
    "xml2js": "^0.4.16"
  }
}
</code>```

While running "npm install" or "sudo ~vagrant/bin/npm install" I'm getting the following errors.

Any ideas what should I do to fix this issue and run "npm install" successfully? Thanks.

Log:(with some truncation of log files to fit the word limit for this post)

```[vagrant@localhost my-directory]$ npm install
npm WARN package.json njse@ No repository field.
npm WARN package.json njse@ No README data
npm WARN package.json njse@ No license field.
npm WARN engine dns@0.2.2: wanted: {"node":">= 0.10.0 < 0.11.0"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine tomahawk@0.1.6: wanted: {"node":">= 0.8.0 < 0.11.0"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine hawk@0.10.2: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine boom@0.3.8: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine hoek@0.7.6: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})

> dtrace-provider@0.6.0 install /home/vagrant/ws/06272016/my-directory/node_modules/bunyan/node_modules/dtrace-provider
> node scripts/install.js

> libxmljs@0.18.0 install /home/vagrant/ws/06272016/my-directory/node_modules/libxmljs
> node-gyp rebuild

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/libxmljs/build'
  CC(target) Release/obj.target/libxml/vendor/libxml/buf.o
  CC(target) Release/obj.target/libxml/vendor/libxml/catalog.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlschemas.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlschemastypes.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlstring.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlunicode.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlwriter.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xpath.o
In file included from ../vendor/libxml/xpath.c:462:
../vendor/libxml/timsort.h: In function ‘libxml_domnode_tim_sort_collapse’:
../vendor/libxml/timsort.h:405: warning: comparison between signed and unsigned integer expressions
../vendor/libxml/xpath.c: At top level:
../vendor/libxml/trionan.c:218: warning: ‘trio_is_negative’ defined but not used
../vendor/libxml/xpath.c: In function ‘xmlXPathCastNumberToString’:
../vendor/libxml/xpath.c:3197: warning: array subscript is above array bounds
  CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
  AR(target) Release/obj.target/vendor/libxml/xml.a
  COPY Release/xml.a
  CXX(target) Release/obj.target/xmljs/src/libxmljs.o
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h:43:3: error: #error This version of node/NAN/v8 requires a C++11 compiler
In file included from ../src/libxmljs.cc:3:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:336: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::MaybeLocal<T>::MaybeLocal()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:353: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::IsEmpty() const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:360: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::ToLocal(v8::Local<S>*) const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:364: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::WeakCallbackInfo<T>::IsFirstPass() const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:430: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: At global scope:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:469: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::Global<T>::Global()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:790: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::Global<T>::Global(v8::Global<T>&&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:815: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::Global<T>& v8::Global<T>::operator=(v8::Global<S>&&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:827: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: At global scope:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:852: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:1089: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:1095: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3205: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::Local<T> v8::MaybeLocal<T>::ToLocalChecked()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:7164: error: ‘nullptr’ was not declared in this scope
In file included from ../node_modules/nan/nan.h:196,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_maybe_43_inl.h: At global scope:
../node_modules/nan/nan_maybe_43_inl.h:13: error: expected unqualified-id before ‘using’
../node_modules/nan/nan_maybe_43_inl.h:16: error: expected unqualified-id before ‘using’
../node_modules/nan/nan_maybe_43_inl.h:19: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:24: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:83: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:91: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:98: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:108: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:114: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:118: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:125: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:130: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:135: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:139: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:145: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:150: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:156: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:162: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:168: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:174: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:180: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:186: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:194: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:201: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:205: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:209: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:213: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:217: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:223: error: expected initializer before ‘<’ token
In file included from ../node_modules/nan/nan.h:201,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_converters.h:14: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type
../node_modules/nan/nan_converters.h:14: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_converters.h:16: error: ISO C++ forbids declaration of ‘Maybe’ with no type
../node_modules/nan/nan_converters.h:16: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_converters.h:26: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:27: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:28: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:29: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:30: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:31: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:32: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:42: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:43: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:44: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:45: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:46: error: ‘return_t’ does not name a type
In file included from ../node_modules/nan/nan_converters.h:59,
                 from ../node_modules/nan/nan.h:201,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_converters_43_inl.h:18: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Boolean>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:19: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Number>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:20: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::String>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:21: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Object>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:22: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Integer>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:23: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Uint32>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:24: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Int32>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:34: error: ‘return_t’ in class ‘Nan::imp::ToFactory<bool>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:35: error: ‘return_t’ in class ‘Nan::imp::ToFactory<double>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:36: error: ‘return_t’ in class ‘Nan::imp::ToFactory<long int>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:37: error: ‘return_t’ in class ‘Nan::imp::ToFactory<unsigned int>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:38: error: ‘return_t’ in class ‘Nan::imp::ToFactory<int>’ does not name a type
In file included from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Integer]’:
../node_modules/nan/nan_new.h:21: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Int32]’:
../node_modules/nan/nan_new.h:28: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Uint32]’:
../node_modules/nan/nan_new.h:35: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: At global scope:
../node_modules/nan/nan_new.h:43: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type
../node_modules/nan/nan_new.h:43: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_new.h:75: error: ‘return_t’ does not name a type
../node_modules/nan/nan_new.h:182: error: ‘return_t’ does not name a type
../node_modules/nan/nan_new.h:183: error: ‘return_t’ does not name a type
In file included from ../node_modules/nan/nan_new.h:189,
                 from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_implementation_12_inl.h:56: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::Date>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::Function> Nan::imp::Factory<v8::Function>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan_implementation_12_inl.h:90: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::FunctionTemplate> Nan::imp::Factory<v8::FunctionTemplate>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>, v8::Local<v8::Signature>)’:
../node_modules/nan/nan_implementation_12_inl.h:118: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan_implementation_12_inl.h: At global scope:
../node_modules/nan/nan_implementation_12_inl.h:197: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:216: error: ‘return_t’ in
../node_modules/nan/nan_implementation_12_inl.h:275: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:281: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:286: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:347: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:354: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type
In file included from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_new.h:293: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_new.h:299: error: ‘return_t’ in
../node_modules/nan/nan_new.h:335: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::Error(const char*)’:
../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowError(const char*)’:
../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::RangeError(const char*)’:
../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowRangeError(const char*)’:
../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::ReferenceError(const char*)’:
../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowReferenceError(const char*)’:
../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::SyntaxError(const char*)’:
../node_modules/nan/nan.h:664: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowSyntaxError(const char*)’:
../node_modules/nan/nan.h:664: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::TypeError(const char*)’:
../node_modules/nan/nan.h:665: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowTypeError(const char*)’:
../node_modules/nan/nan.h:665: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: At global scope:
../node_modules/nan/nan.h:673: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:695: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:762: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:768: error: expected initializer before ‘<’ token
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘void Nan::Callback::SetFunction(const v8::Local<v8::Function>&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’
../node_modules/nan/nan.h:1404: error:   in call to ‘Set’
../node_modules/nan/nan.h: In member function ‘void Nan::AsyncWorker::SaveToPersistent(const char*, const v8::Local<v8::Value>&)’:
../node_modules/nan/nan.h:1524: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In member function ‘v8::Local<v8::Value> Nan::AsyncWorker::GetFromPersistent(const char*) const’:
../node_modules/nan/nan.h:1542: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In member function ‘virtual void Nan::AsyncWorker::HandleErrorCallback()’:
../node_modules/nan/nan.h:1576: error: no matching function for call to ‘New(const char*)’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::Object>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1896: error: ‘GetFunction’ was not declared in this scope
../node_modules/nan/nan.h:1897: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::FunctionTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1908: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::ObjectTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1919: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1933: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)’:
../node_modules/nan/nan.h:1958: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘bool Nan::SetAccessor(v8::Local<v8::Object>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute)’:
../node_modules/nan/nan.h:2001: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2049: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2119: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2174: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2196: error: ‘NewInstance’ was not declared in this scope
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h: In function ‘void Nan::Export(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:2223: error: no matching function for call to ‘New(const char*&)’
../node_modules/nan/nan.h:2224: error: ‘GetFunction’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’
../node_modules/nan/nan.h:2224: error:   in call to ‘Set’
../node_modules/nan/nan.h: In constructor ‘Nan::Tap::Tap(v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2231: error: no matching function for call to ‘To(v8::Local<v8::Value>&)’
../src/libxmljs.cc:263: error: ‘Set’ is not a member of ‘Nan’
../src/libxmljs.cc:263: error: no matching function for call to ‘New(const char [7])’
make: *** [Release/obj.target/xmljs/src/libxmljs.o] Error 1
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/libxmljs/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/vagrant/tools/node-v4.4.6-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 2.6.32-573.7.1.el6.x86_64
gyp ERR! command "/home/vagrant/tools/node-v4.4.6-linux-x64/bin/node" "/home/vagrant/tools/node-v4.4.6-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/vagrant/ws/06272016/my-directory/node_modules/libxmljs
gyp ERR! node -v v4.4.6
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

> ws@0.4.31 install /home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'

> ws@0.4.31 install /home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
npm ERR! Linux 2.6.32-573.7.1.el6.x86_64
npm ERR! argv "/home/vagrant/tools/node-v4.4.6-linux-x64/bin/node" "/home/vagrant/bin/npm" "install"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE

npm ERR! libxmljs@0.18.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the libxmljs@0.18.0 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs libxmljs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls libxmljs
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/ws/06272016/my-directory/npm-debug.log
[vagrant@localhost my-directory]$ sudo yum install libxmljs
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: chicago.gaminghost.co
 * epel: mirror.oss.ou.edu
 * extras: mirrors.adams.net
 * updates: centos.pymesolutionsweb.com
No package libxmljs available.
Error: Nothing to do
[vagrant@localhost my-directory]$ which gcc
/usr/bin/gcc
[vagrant@localhost my-directory]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
```

<p>Tried upgrading/install of <strong>gcc</strong> using (yum), it says:</p>

```Package gcc-4.4.7-17.el6.x86_64 already installed and latest version
```

One of the post says, I may need to install gcc 4.8 or newer to build binary addons for node 4.x and above? Is that really required, if so, how can I efficiently install gcc 4.8 without breaking anything else? I also see there's devtoolset-3-rebuild version available on CentOS site. devtoolset-2 has KNOWN issues as per the post: https://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos

答: We did a mistake and passed .c extension file changing extension of those files to .cpp fixed this issue for us.

Body:
I'm running CentOS 6.8(Final) using Vagrant/VirtualBox.
GCC compiler version is (v4.4.7)
Node version (latest LTS): v4.4.6

My package.json file has:

{
  "name": "njse",
  "main": "server.js",
  "description": "MyCompany services",
  "repository": "",
  "license": "",
  "dependencies": {
    "bunyan": "^1.8.1",
    "dns": "^0.2.2",
    "express": "~4.0.0",
    "express-delay": "~0.1.0",
    "libxmljs": "^0.18.0",
    "mssql": "^3.3.0",
    "ping": "^0.1.10",
    "powershell": "^2.0.2",
    "q": "^1.4.1",
    "q-io": "^1.13.2",
    "validatorjs": "^2.0.11",
    "xml2js": "^0.4.16"
  }
}

While running "npm install" or "sudo ~vagrant/bin/npm install" I'm getting the following errors.

Any ideas what should I do to fix this issue and run "npm install" successfully? Thanks.

Log:(with some truncation of log files to fit the word limit for this post)

[vagrant@localhost my-directory]$ npm install
npm WARN package.json njse@ No repository field.
npm WARN package.json njse@ No README data
npm WARN package.json njse@ No license field.
npm WARN engine dns@0.2.2: wanted: {"node":">= 0.10.0 < 0.11.0"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine tomahawk@0.1.6: wanted: {"node":">= 0.8.0 < 0.11.0"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine hawk@0.10.2: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine boom@0.3.8: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})
npm WARN engine hoek@0.7.6: wanted: {"node":"0.8.x"} (current: {"node":"4.4.6","npm":"2.15.5"})

> dtrace-provider@0.6.0 install /home/vagrant/ws/06272016/my-directory/node_modules/bunyan/node_modules/dtrace-provider
> node scripts/install.js

> libxmljs@0.18.0 install /home/vagrant/ws/06272016/my-directory/node_modules/libxmljs
> node-gyp rebuild

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/libxmljs/build'
  CC(target) Release/obj.target/libxml/vendor/libxml/buf.o
  CC(target) Release/obj.target/libxml/vendor/libxml/catalog.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlschemas.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlschemastypes.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlstring.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlunicode.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xmlwriter.o
  CC(target) Release/obj.target/libxml/vendor/libxml/xpath.o
In file included from ../vendor/libxml/xpath.c:462:
../vendor/libxml/timsort.h: In function ‘libxml_domnode_tim_sort_collapse’:
../vendor/libxml/timsort.h:405: warning: comparison between signed and unsigned integer expressions
../vendor/libxml/xpath.c: At top level:
../vendor/libxml/trionan.c:218: warning: ‘trio_is_negative’ defined but not used
../vendor/libxml/xpath.c: In function ‘xmlXPathCastNumberToString’:
../vendor/libxml/xpath.c:3197: warning: array subscript is above array bounds
  CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
  AR(target) Release/obj.target/vendor/libxml/xml.a
  COPY Release/xml.a
  CXX(target) Release/obj.target/xmljs/src/libxmljs.o
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h:43:3: error: #error This version of node/NAN/v8 requires a C++11 compiler
In file included from ../src/libxmljs.cc:3:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:336: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::MaybeLocal<T>::MaybeLocal()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:353: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::IsEmpty() const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:360: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::ToLocal(v8::Local<S>*) const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:364: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘bool v8::WeakCallbackInfo<T>::IsFirstPass() const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:430: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: At global scope:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:469: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::Global<T>::Global()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:790: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In constructor ‘v8::Global<T>::Global(v8::Global<T>&&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:815: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::Global<T>& v8::Global<T>::operator=(v8::Global<S>&&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:827: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: At global scope:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:852: error: expected unqualified-id before ‘using’
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:1089: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:1095: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3205: error: ‘nullptr’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘v8::Local<T> v8::MaybeLocal<T>::ToLocalChecked()’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:7164: error: ‘nullptr’ was not declared in this scope
In file included from ../node_modules/nan/nan.h:196,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_maybe_43_inl.h: At global scope:
../node_modules/nan/nan_maybe_43_inl.h:13: error: expected unqualified-id before ‘using’
../node_modules/nan/nan_maybe_43_inl.h:16: error: expected unqualified-id before ‘using’
../node_modules/nan/nan_maybe_43_inl.h:19: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:24: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:83: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:91: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:98: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:108: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:114: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:118: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:125: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:130: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:135: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:139: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:145: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:150: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:156: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:162: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:168: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:174: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:180: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:186: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:194: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:201: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:205: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:209: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:213: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:217: error: expected initializer before ‘<’ token
../node_modules/nan/nan_maybe_43_inl.h:223: error: expected initializer before ‘<’ token
In file included from ../node_modules/nan/nan.h:201,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_converters.h:14: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type
../node_modules/nan/nan_converters.h:14: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_converters.h:16: error: ISO C++ forbids declaration of ‘Maybe’ with no type
../node_modules/nan/nan_converters.h:16: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_converters.h:26: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:27: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:28: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:29: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:30: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:31: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:32: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:42: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:43: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:44: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:45: error: ‘return_t’ does not name a type
../node_modules/nan/nan_converters.h:46: error: ‘return_t’ does not name a type
In file included from ../node_modules/nan/nan_converters.h:59,
                 from ../node_modules/nan/nan.h:201,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_converters_43_inl.h:18: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Boolean>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:19: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Number>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:20: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::String>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:21: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Object>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:22: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Integer>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:23: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Uint32>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:24: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Int32>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:34: error: ‘return_t’ in class ‘Nan::imp::ToFactory<bool>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:35: error: ‘return_t’ in class ‘Nan::imp::ToFactory<double>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:36: error: ‘return_t’ in class ‘Nan::imp::ToFactory<long int>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:37: error: ‘return_t’ in class ‘Nan::imp::ToFactory<unsigned int>’ does not name a type
../node_modules/nan/nan_converters_43_inl.h:38: error: ‘return_t’ in class ‘Nan::imp::ToFactory<int>’ does not name a type
In file included from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Integer]’:
../node_modules/nan/nan_new.h:21: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Int32]’:
../node_modules/nan/nan_new.h:28: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Uint32]’:
../node_modules/nan/nan_new.h:35: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’
../node_modules/nan/nan_new.h: At global scope:
../node_modules/nan/nan_new.h:43: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type
../node_modules/nan/nan_new.h:43: error: expected ‘;’ before ‘<’ token
../node_modules/nan/nan_new.h:75: error: ‘return_t’ does not name a type
../node_modules/nan/nan_new.h:182: error: ‘return_t’ does not name a type
../node_modules/nan/nan_new.h:183: error: ‘return_t’ does not name a type
In file included from ../node_modules/nan/nan_new.h:189,
                 from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_implementation_12_inl.h:56: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::Date>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::Function> Nan::imp::Factory<v8::Function>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan_implementation_12_inl.h:90: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::FunctionTemplate> Nan::imp::Factory<v8::FunctionTemplate>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>, v8::Local<v8::Signature>)’:
../node_modules/nan/nan_implementation_12_inl.h:118: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan_implementation_12_inl.h: At global scope:
../node_modules/nan/nan_implementation_12_inl.h:197: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:216: error: ‘return_t’ in
../node_modules/nan/nan_implementation_12_inl.h:275: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:281: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:286: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:347: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type
../node_modules/nan/nan_implementation_12_inl.h:354: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type
In file included from ../node_modules/nan/nan.h:202,
                 from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan_new.h:293: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type
../node_modules/nan/nan_new.h:299: error: ‘return_t’ in
../node_modules/nan/nan_new.h:335: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::Error(const char*)’:
../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowError(const char*)’:
../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::RangeError(const char*)’:
../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowRangeError(const char*)’:
../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::ReferenceError(const char*)’:
../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowReferenceError(const char*)’:
../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::SyntaxError(const char*)’:
../node_modules/nan/nan.h:664: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowSyntaxError(const char*)’:
../node_modules/nan/nan.h:664: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::TypeError(const char*)’:
../node_modules/nan/nan.h:665: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::ThrowTypeError(const char*)’:
../node_modules/nan/nan.h:665: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: At global scope:
../node_modules/nan/nan.h:673: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:695: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:762: error: expected initializer before ‘<’ token
../node_modules/nan/nan.h:768: error: expected initializer before ‘<’ token
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h: In member function ‘void Nan::Callback::SetFunction(const v8::Local<v8::Function>&)’:
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’
../node_modules/nan/nan.h:1404: error:   in call to ‘Set’
../node_modules/nan/nan.h: In member function ‘void Nan::AsyncWorker::SaveToPersistent(const char*, const v8::Local<v8::Value>&)’:
../node_modules/nan/nan.h:1524: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In member function ‘v8::Local<v8::Value> Nan::AsyncWorker::GetFromPersistent(const char*) const’:
../node_modules/nan/nan.h:1542: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In member function ‘virtual void Nan::AsyncWorker::HandleErrorCallback()’:
../node_modules/nan/nan.h:1576: error: no matching function for call to ‘New(const char*)’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::Object>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1896: error: ‘GetFunction’ was not declared in this scope
../node_modules/nan/nan.h:1897: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::FunctionTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1908: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(v8::Local<v8::ObjectTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1919: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:1933: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’
../node_modules/nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)’:
../node_modules/nan/nan.h:1958: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘bool Nan::SetAccessor(v8::Local<v8::Object>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute)’:
../node_modules/nan/nan.h:2001: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2049: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2119: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2174: error: ‘NewInstance’ was not declared in this scope
../node_modules/nan/nan.h: In function ‘void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2196: error: ‘NewInstance’ was not declared in this scope
In file included from ../src/libxmljs.h:7,
                 from ../src/libxmljs.cc:7:
../node_modules/nan/nan.h: In function ‘void Nan::Export(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’:
../node_modules/nan/nan.h:2223: error: no matching function for call to ‘New(const char*&)’
../node_modules/nan/nan.h:2224: error: ‘GetFunction’ was not declared in this scope
/home/vagrant/.node-gyp/4.4.6/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’
../node_modules/nan/nan.h:2224: error:   in call to ‘Set’
../node_modules/nan/nan.h: In constructor ‘Nan::Tap::Tap(v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:2231: error: no matching function for call to ‘To(v8::Local<v8::Value>&)’
../src/libxmljs.cc:263: error: ‘Set’ is not a member of ‘Nan’
../src/libxmljs.cc:263: error: no matching function for call to ‘New(const char [7])’
make: *** [Release/obj.target/xmljs/src/libxmljs.o] Error 1
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/libxmljs/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/vagrant/tools/node-v4.4.6-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 2.6.32-573.7.1.el6.x86_64
gyp ERR! command "/home/vagrant/tools/node-v4.4.6-linux-x64/bin/node" "/home/vagrant/tools/node-v4.4.6-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/vagrant/ws/06272016/my-directory/node_modules/libxmljs
gyp ERR! node -v v4.4.6
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

> ws@0.4.31 install /home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/engine.io/node_modules/ws/build'

> ws@0.4.31 install /home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
make: Leaving directory `/home/vagrant/ws/06272016/my-directory/node_modules/dns/node_modules/tomahawk/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/build'
npm ERR! Linux 2.6.32-573.7.1.el6.x86_64
npm ERR! argv "/home/vagrant/tools/node-v4.4.6-linux-x64/bin/node" "/home/vagrant/bin/npm" "install"
npm ERR! node v4.4.6
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE

npm ERR! libxmljs@0.18.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the libxmljs@0.18.0 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs libxmljs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls libxmljs
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/ws/06272016/my-directory/npm-debug.log
[vagrant@localhost my-directory]$ sudo yum install libxmljs
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: chicago.gaminghost.co
 * epel: mirror.oss.ou.edu
 * extras: mirrors.adams.net
 * updates: centos.pymesolutionsweb.com
No package libxmljs available.
Error: Nothing to do
[vagrant@localhost my-directory]$ which gcc
/usr/bin/gcc
[vagrant@localhost my-directory]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)

Tried upgrading/install of gcc using (yum), it says:

Package gcc-4.4.7-17.el6.x86_64 already installed and latest version

One of the post says, I may need to install gcc 4.8 or newer to build binary addons for node 4.x and above? Is that really required, if so, how can I efficiently install gcc 4.8 without breaking anything else? I also see there's devtoolset-3-rebuild version available on CentOS site. devtoolset-2 has KNOWN issues as per the post: https://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos


来源: stackexchange

问:
How to find scala java.util.Date difference in minutes?
```<code>scala> val dates = filtering1.map(x => (format.parse(x._1),format.parse(x._2)))
dates: org.apache.spark.rdd.RDD[(java.util.Date, java.util.Date)] = MapPartitionsRDD[7] at map at <console>:34
</code>```

stores below values

```<code>scala> dates.collect
res0: Array[(java.util.Date, java.util.Date)] = Array((Sat Jun 30 23:42:00 IST 2018,Thu Jul 04 15:10:00 IST 2019), (Sat Jun 30 23:37:00 IST 2018,Sun Jul 01 14:44:00 IST 2018), (Sat Jun 30 23:13:00 IST 2018,Sun Feb 28 23:34:00 IST 219), (Sat Jun 30 22:58:00 IST 2018,Mon Jul 01 18:22:00 IST 2019), (Sat Jun 30 22:36:00 IST 2018,Mon Jul 01 16:01:00 IST 2019), (Sat Jun 30 21:53:00 IST 2018,Tue Jul 02 10:36:00 IST 2019), (Sat Jun 30 21:42:00 IST 2018,Sun Jun 30 23:25:00 IST 2019), (Sat Jun 30 21:36:00 IST 2018,Mon Jul 01 16:47:00 IST 2019), (Sat Jun 30 21:16:00 IST 2018,Mon Jul 01 18:18:00 IST 2019), (Sat Jun 30 21:10:00 IST 2018,Thu Jul 04 12:25:00 IST 2019), (Sat Jun 30 21:02:00 IST 2018,Sat Dec 01 17:29:00 IST 2018), (Sat Jun 30 20:54:00 IST 2018,Mon Jul 01 15:51:00 IST 2019), (Sat Jun 30 ...
</code>```

But how to perform operation so the difference in dates, is grouped together, gives value in minutes.

I have command , it does not give me desired output, what changes should be made?

val time_diff = dates.map(x => (x._2.getTime()-x._1.getTime())/(60*1000)%60)

what is (60*1000)%60) values represent?

答:
First problem when you subtract two times, time might go negative.
Second, getTime returns value in miliseconds. </p>

```<code>1000ms = 1 second
</code>```

<p>So, first there is need to divide it by 1000 to get time in seconds. To get in minutes,divide it again by 60.
Since you require result in minutes. </p>

```<code>val time_diff = dates.map(x => (x._2.getTime()-x._1.getTime())/(60*1000))
</code>```

ContentLicense: CC BY-SA 3.0

Body:
scala> val dates = filtering1.map(x => (format.parse(x._1),format.parse(x._2)))
dates: org.apache.spark.rdd.RDD[(java.util.Date, java.util.Date)] = MapPartitionsRDD[7] at map at <console>:34

stores below values

scala> dates.collect
res0: Array[(java.util.Date, java.util.Date)] = Array((Sat Jun 30 23:42:00 IST 2018,Thu Jul 04 15:10:00 IST 2019), (Sat Jun 30 23:37:00 IST 2018,Sun Jul 01 14:44:00 IST 2018), (Sat Jun 30 23:13:00 IST 2018,Sun Feb 28 23:34:00 IST 219), (Sat Jun 30 22:58:00 IST 2018,Mon Jul 01 18:22:00 IST 2019), (Sat Jun 30 22:36:00 IST 2018,Mon Jul 01 16:01:00 IST 2019), (Sat Jun 30 21:53:00 IST 2018,Tue Jul 02 10:36:00 IST 2019), (Sat Jun 30 21:42:00 IST 2018,Sun Jun 30 23:25:00 IST 2019), (Sat Jun 30 21:36:00 IST 2018,Mon Jul 01 16:47:00 IST 2019), (Sat Jun 30 21:16:00 IST 2018,Mon Jul 01 18:18:00 IST 2019), (Sat Jun 30 21:10:00 IST 2018,Thu Jul 04 12:25:00 IST 2019), (Sat Jun 30 21:02:00 IST 2018,Sat Dec 01 17:29:00 IST 2018), (Sat Jun 30 20:54:00 IST 2018,Mon Jul 01 15:51:00 IST 2019), (Sat Jun 30 ...

But how to perform operation so the difference in dates, is grouped together, gives value in minutes.

I have command , it does not give me desired output, what changes should be made?

val time_diff = dates.map(x => (x._2.getTime()-x._1.getTime())/(60*1000)%60)

what is (60*1000)%60) values represent?

Body:
First problem when you subtract two times, time might go negative.
Second, getTime returns value in miliseconds.

1000ms = 1 second

So, first there is need to divide it by 1000 to get time in seconds. To get in minutes,divide it again by 60.
Since you require result in minutes.

val time_diff = dates.map(x => (x._2.getTime()-x._1.getTime())/(60*1000))


问:
Should I avoid Alternative Control Syntax?
As a mostly self-taught programmer, I have never really had anyone explain why certain things should or should not be used. One example (which I picked up years ago and use quite often) is the alternative control structure syntax:

```<code>x = (y == true) ? "foo" : "bar";
</code>```

I personally find this syntax easy to follow, especially for short, concise code, but I don't see it get a lot of use "in the wild" so I'd like to know if it's bad practice to use this over a more traditional if ... else structure?

Thanks in advance.

答:
The syntax you're referring to is often called the ternary conditional operator and it's semantically equal to an if/else clause and it performs just the same.

The main objection towards overusing theese constructs is that it can create somewhat messy source code that may not be as readable as using the if/else way. This is especially true for people who don't know about that particular syntax. It's far more likely 100% safe to assume that people understand if/else.

OwnerDisplayName: Chris

ContentLicense: CC BY-SA 2.5

Body:
As a mostly self-taught programmer, I have never really had anyone explain why certain things should or should not be used. One example (which I picked up years ago and use quite often) is the alternative control structure syntax:

x = (y == true) ? "foo" : "bar";

I personally find this syntax easy to follow, especially for short, concise code, but I don't see it get a lot of use "in the wild" so I'd like to know if it's bad practice to use this over a more traditional if ... else structure?

Thanks in advance.

OwnerDisplayName: Markus Olsson

LastEditorDisplayName: Markus Olsson


问:
Database column data having linebreaks are ignored when retrieved from Hibernate?
A CLOB database column data has linebreaks :

When I retrieve it and display the data inside a html table cell then the linebreaks are ignored :

```<code>    @Override
    @Transactional
    public String getPrevisionRessourceAutreForProduit(Objectif produit) {

        String hql = "select to_char(r.ress_comment_1) " +
                     "from ressource r join type_ressource t on r.type_ress_code = t.type_ress_code " +
                     "left join objectif o on r.obj_code = o.obj_code " +
                     "where o.obj_code = " + produit.getCode().toString() + " and upper(t.type_ress_code) = 'AUT'";

        Session sessionDynamic = Utils.createDynamicSession(env);

        Query query = sessionDynamic.createSQLQuery(hql);

        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) query.list();

        sessionDynamic.close();

        if (list.isEmpty())
            return "";
        else
            return list.get(0) == null ? "" : list.get(0);

    }
</code>```

So how to fix it ?

答: I found the solution by enclosing the data inside the tags <code>```...```</code></p>

Body:
A CLOB database column data has linebreaks :

When I retrieve it and display the data inside a html table cell then the linebreaks are ignored :

    @Override
    @Transactional
    public String getPrevisionRessourceAutreForProduit(Objectif produit) {

        String hql = "select to_char(r.ress_comment_1) " +
                     "from ressource r join type_ressource t on r.type_ress_code = t.type_ress_code " +
                     "left join objectif o on r.obj_code = o.obj_code " +
                     "where o.obj_code = " + produit.getCode().toString() + " and upper(t.type_ress_code) = 'AUT'";

        Session sessionDynamic = Utils.createDynamicSession(env);

        Query query = sessionDynamic.createSQLQuery(hql);

        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) query.list();

        sessionDynamic.close();

        if (list.isEmpty())
            return "";
        else
            return list.get(0) == null ? "" : list.get(0);

    }

So how to fix it ?

Body: I found the solution by enclosing the data inside the tags <pre>...</pre>


问:
Hypothesis (Python): Omit argument
I have a function like so (it's actually a class, but that's not relevant given Python's duck typing):

```<code>def myfunc(a=None, b=None):
    <snip>
</code>```

Now I want to write a Hypothesis test which always supplies a, but only sometimes b.

I tried

```<code>from hypothesis import given, strategies as strat

@given(a=strat.booleans())
@given(b=strat.integers(min_value=1) | strat.nothing())
def test_model_properties(self, **kwargs):
    myval = myfunc(**kwargs)
    <snip>
</code>```

But it seems that when it gets strat.nothing() just skips that test run (I get hypothesis.errors.FailedHealthCheck: It looks like your strategy is filtering out a lot of data. when using that as the sole strategy for b).

How can I only sometimes supply an argument with a Hypothesis test? Do I need to write two tests, one with b and one without?

答:
jacq's answer put me on the right track - the selection of keywords needs to be its own strategy.

With the standard dictionary

```<code>std = {'a': strat.booleans()}
</code>```

and the optional dictionary

```<code>opt = {
    'b': strat.integers(),
    'c': strat.integers(),
}
</code>```

I can then use chained list comprehension for all the possible "optional argument combinations":

```<code># chain.from_iterable may or may not be faster; it doesn't matter for me.
optional = [combo
            for n in range(len(opt.items()))
            for combo in itertools.combinations(opt.items(), n+1)]
</code>```

That generates the key-value tuples for b, c, and (b, c).

In order to draw a set of values, we need to get one of those options, which can be done with sampled_from(optional). With the obtained tuples, we must draw from the strategies within, in addition to those in the std dictionary.

```<code>strat.sampled_from(optional).flatmap(
    lambda x: strat.fixed_dictionaries(
        {**std, **dict(x)}
    )
)
</code>```

This can all be wrapped in a function, let's call it valid_values(). You can't use @given(valid_values()) if you specify *args or **kwargs in the signature of the wrapped function.

As a result, test_model_properties(self, **kwargs) becomes test_model_properties(self, kwargs) (and you can use @given(kwargs=valid_values())) - by calling the dictionary kwargs, the rest of the function remains unchanged.

Note: This will not include an empty tuple if you want the possibility of no optional parameters, but that can be appended to the optional list easily. Alternatively, have range(n+1) instead of combinations(..., n+1), hence including a length of 0.

Title: Hypothesis (Python): Omit argument

Body:
I have a function like so (it's actually a class, but that's not relevant given Python's duck typing):

def myfunc(a=None, b=None):
    <snip>

Now I want to write a Hypothesis test which always supplies a, but only sometimes b.

I tried

from hypothesis import given, strategies as strat

@given(a=strat.booleans())
@given(b=strat.integers(min_value=1) | strat.nothing())
def test_model_properties(self, **kwargs):
    myval = myfunc(**kwargs)
    <snip>

But it seems that when it gets strat.nothing() just skips that test run (I get hypothesis.errors.FailedHealthCheck: It looks like your strategy is filtering out a lot of data. when using that as the sole strategy for b).

How can I only sometimes supply an argument with a Hypothesis test? Do I need to write two tests, one with b and one without?

Body:
jacq's answer put me on the right track - the selection of keywords needs to be its own strategy.

With the standard dictionary

std = {'a': strat.booleans()}

and the optional dictionary

opt = {
    'b': strat.integers(),
    'c': strat.integers(),
}

I can then use chained list comprehension for all the possible "optional argument combinations":

# chain.from_iterable may or may not be faster; it doesn't matter for me.
optional = [combo
            for n in range(len(opt.items()))
            for combo in itertools.combinations(opt.items(), n+1)]

That generates the key-value tuples for b, c, and (b, c).

In order to draw a set of values, we need to get one of those options, which can be done with sampled_from(optional). With the obtained tuples, we must draw from the strategies within, in addition to those in the std dictionary.

strat.sampled_from(optional).flatmap(
    lambda x: strat.fixed_dictionaries(
        {**std, **dict(x)}
    )
)

This can all be wrapped in a function, let's call it valid_values(). You can't use @given(valid_values()) if you specify *args or **kwargs in the signature of the wrapped function.

As a result, test_model_properties(self, **kwargs) becomes test_model_properties(self, kwargs) (and you can use @given(kwargs=valid_values())) - by calling the dictionary kwargs, the rest of the function remains unchanged.

Note: This will not include an empty tuple if you want the possibility of no optional parameters, but that can be appended to the optional list easily. Alternatively, have range(n+1) instead of combinations(..., n+1), hence including a length of 0.


问:
Putting of common method of derived classes in base, where the base doesn't use it
Is it correct from terms of OOP to put common method of derived classes in base class, where base doesn't (!) use it. As in the example:</p>

```<code>class Base {
    virtual void CalculateTotal()
    {
        //calculate without taxes (no need in base)
    }

    void CalculateTaxes()
    {
        //do something
    }
}

class A : Base {
   override void CalculateTotal() {
       //...
       CalculateTaxes();
       //...
   }
}

class B : Base {
   override void CalculateTotal() {
       //...
       CalculateTaxes();
       //...
   }
}
</code>```

答:
I think not.
I'd rather put the CalculateTaxes in a utility class used from both A and B.
Es taxes.Calculate()

or something like this.

Body:
Is it correct from terms of OOP to put common method of derived classes in base class, where base doesn't (!) use it. As in the example:

class Base {
    virtual void CalculateTotal()
    {
        //calculate without taxes (no need in base)
    }

    void CalculateTaxes()
    {
        //do something
    }
}

class A : Base {
   override void CalculateTotal() {
       //...
       CalculateTaxes();
       //...
   }
}

class B : Base {
   override void CalculateTotal() {
       //...
       CalculateTaxes();
       //...
   }
}


问:
Improving first time load of a Production Admin on Rest/React App
I'm using Admin-on-rest and deploy the production app to AWS S3.

I created Admin-on-rest app with create-react-app in Admin-on-rest's instructions.

To build app: I run this script: npm run build

Size of file main.js is too big (5 MB). And for the first time load, it takes more than 5 mins. (My internet's speed test is 3MB/s)

Is there any way to reduce the size of main.js file?

I'm reading about JS chucking but it's not easy to apply to Admin-on-rest

答:
First things first. AOR itself has not THAT much of an impact on application size and optimising an app is a very different task.

Following are the steps I took when optimising my in production app from 2.8 MB ish to 400 KB served file size.

1) First step is to know what part of the code is causing bloats. You can do this quite easily with Source Map Explorer.

https://www.npmjs.com/package/source-map-explorer

2) After identifying the packages/modules you should explore ways of reducing their size on your code. e.g
Don't do

```<code>import _ from 'lodash'
</code>```

DO

```<code>import find from 'lodash/find'
</code>```

Reducing unnecessary imports is low hanging easy fruit

3) Check if there are smaller versions of the libraries available that you can plug  in.

For instance moment.js now has moment-mini which tracks the main package and does not have all the internationalisation data in it. That shaved off about 400 KB of the bundle size for me.

4) GZIP GZIP GZIP. The biggest impact on my file size yet.

I was using Nginx to serve my static files and I could simply add a config to it to gzip the package while in transit. Worked super smoothly.

If you are using something like Apache then you can also probably figure out a way to do this.

Another option is to eject from Create React App and then configure webpack to generate gzipped files at build time. This theoretically should lead to even smaller bundles as you can use Tree Shaking during compression. This was my experience just 2 months ago, Create React App might have made some way to inform webpack to gzip the bundle. Do explore that avenue as well.

This reduced my bundle size down from 1.6 mb to a ~400 kb served file.

5) Finally, there you can exit React itself and use Preact which is the hot in the market way to reduce bundle size. I haven't used this. But you can try and document your findings, for the benefit of us all.

6) If you need in production app to be even smaller then you will have to look at more advanced strategies such as loading a dashboard/landing page with server side rendering and the rest of the app bundle async when the dashboard gets loaded.

Best of luck.

Edit on - 26/02/2018
Just discovered this --> https://github.com/jamiebuilds/react-loadable

More details here. This does not use the react-loadable and instead teaches you how to use code splitting, which is supported by Create-React-App bootstrapped pages out of the block.

https://scotch.io/tutorials/lazy-loading-routes-in-react

Body:
First things first. AOR itself has not THAT much of an impact on application size and optimising an app is a very different task.

Following are the steps I took when optimising my in production app from 2.8 MB ish to 400 KB served file size.

1) First step is to know what part of the code is causing bloats. You can do this quite easily with Source Map Explorer.

https://www.npmjs.com/package/source-map-explorer

2) After identifying the packages/modules you should explore ways of reducing their size on your code. e.g
Don't do

import _ from 'lodash'

DO

import find from 'lodash/find'

Reducing unnecessary imports is low hanging easy fruit

3) Check if there are smaller versions of the libraries available that you can plug  in.

For instance moment.js now has moment-mini which tracks the main package and does not have all the internationalisation data in it. That shaved off about 400 KB of the bundle size for me.

4) GZIP GZIP GZIP. The biggest impact on my file size yet.

I was using Nginx to serve my static files and I could simply add a config to it to gzip the package while in transit. Worked super smoothly.

If you are using something like Apache then you can also probably figure out a way to do this.

Another option is to eject from Create React App and then configure webpack to generate gzipped files at build time. This theoretically should lead to even smaller bundles as you can use Tree Shaking during compression. This was my experience just 2 months ago, Create React App might have made some way to inform webpack to gzip the bundle. Do explore that avenue as well.

This reduced my bundle size down from 1.6 mb to a ~400 kb served file.

5) Finally, there you can exit React itself and use Preact which is the hot in the market way to reduce bundle size. I haven't used this. But you can try and document your findings, for the benefit of us all.

6) If you need in production app to be even smaller then you will have to look at more advanced strategies such as loading a dashboard/landing page with server side rendering and the rest of the app bundle async when the dashboard gets loaded.

Best of luck.

Edit on - 26/02/2018
Just discovered this --> https://github.com/jamiebuilds/react-loadable

More details here. This does not use the react-loadable and instead teaches you how to use code splitting, which is supported by Create-React-App bootstrapped pages out of the block.

https://scotch.io/tutorials/lazy-loading-routes-in-react


问:
receive var declaration string, save value only
I am trying to use a variable value that I get with an HTTP request, and what I get back is this:

```<code>var nums=["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]
</code>```

Which is a string with the declaration of the variable. What I want is to collect ONLY the value, not the whole line. So, in this case, I'd save ["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]

Is there any JQuery or JS library that can do this kind of operations with strings?? I'd want to implement an universal solution as I don't always know what will I receive in the HTTP request.

Thank you so much.

答:
you can use a regexp :

```<code>var myString = 'var nums=["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]';
var myRegexp = /var\s*nums\s*=(.*)/g;
var match = myRegexp.exec(myString);
console.log(match[1]);
</code>```

The first match group (match[1]) will contain your array (as a string)

If you want the array itself (and not a string containing the array), you can just deserialize as a JSON :

```<code> var myArray = JSON.parse(match[1]);
 console.log(myArray);
</code>```

As a remark, as stated in several comments, an API should not return this kind of data (with the var nums = part); if you don't have a specific reason for that, you should review your API.

Body:
I am trying to use a variable value that I get with an HTTP request, and what I get back is this:

var nums=["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]

Which is a string with the declaration of the variable. What I want is to collect ONLY the value, not the whole line. So, in this case, I'd save ["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]

Is there any JQuery or JS library that can do this kind of operations with strings?? I'd want to implement an universal solution as I don't always know what will I receive in the HTTP request.

Thank you so much.

Body:
you can use a regexp :

var myString = 'var nums=["155","175","195","205","215","225","235","245","255","265","275","285","295","315","325"]';
var myRegexp = /var\s*nums\s*=(.*)/g;
var match = myRegexp.exec(myString);
console.log(match[1]);

The first match group (match[1]) will contain your array (as a string)

If you want the array itself (and not a string containing the array), you can just deserialize as a JSON :

 var myArray = JSON.parse(match[1]);
 console.log(myArray);

As a remark, as stated in several comments, an API should not return this kind of data (with the var nums = part); if you don't have a specific reason for that, you should review your API.


问:
Mark-up Validation
I am attempting to clean up some HTML after it being chopped and altered many times.

When I go to Validate the page I keep getting a kick back saying this

"end tag for "table" which is not finished"

bit confused as i believe I closed it? here is a sample.

I also tried

```<code><table align="center" border="0" cellpadding="0" cellspacing="0" class="widthtable" width="650"< </table>
</code>```

thanks in advance.

答:
Look at the error message more closely.

It says that it has found the end tag (so you have closed it) but that it is not finished.

Now look at the DTD:

```<code><!ELEMENT TABLE - -
     (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>
</code>```

Its children are:

An optional caption element

Any number of col and colgroup elements

An optional thead element

An optional tfoot element

At least one tbody element

You haven't added any children at all, so the mandatory first tbody element is missing. This means the table isn't finished when you write the end tag for it.

A table without any children doesn't many any sense anyway.

If you have no data, then you can't express that data in the form of a table.

NB: With the exception of the class attribute, every attribute you have used was superseded by CSS a decade ago.

Title: Mark-up Validation

Body:
I am attempting to clean up some HTML after it being chopped and altered many times.

When I go to Validate the page I keep getting a kick back saying this

"end tag for "table" which is not finished"

bit confused as i believe I closed it? here is a sample.

I also tried

<table align="center" border="0" cellpadding="0" cellspacing="0" class="widthtable" width="650"<

thanks in advance.

Body:
Look at the error message more closely.

It says that it has found the end tag (so you have closed it) but that it is not finished.

Now look at the DTD:

<!ELEMENT TABLE - -
     (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>

Its children are:

An optional caption element

Any number of col and colgroup elements

An optional thead element

An optional tfoot element

At least one tbody element

You haven't added any children at all, so the mandatory first tbody element is missing. This means the table isn't finished when you write the end tag for it.

A table without any children doesn't many any sense anyway.

If you have no data, then you can't express that data in the form of a table.

NB: With the exception of the class attribute, every attribute you have used was superseded by CSS a decade ago.


问:
Replace everything not in the String
I know when I use .replace I can replace a specified String for another string. For example:

```<code>String string = “hi fjrkfinnek”;

string.replace(“fjrkfinnek”, “”);
</code>```

I know using this will replace that specified part of the string with a blank space in this example. However, is it possible to remove everything that’s not “hi” instead of referencing what I want to replace?

The output I would desire is to remove everything but Hi by saying Remove everything that’s not Hi if that can be done!

答:
I think using regex we can do this..</p>

```<code>string.replaceAll("[^hi]", "?")
</code>```

Title: Replace everything not in the String

Body:
I know when I use .replace I can replace a specified String for another string. For example:

String string = “hi fjrkfinnek”;

string.replace(“fjrkfinnek”, “”);

I know using this will replace that specified part of the string with a blank space in this example. However, is it possible to remove everything that’s not “hi” instead of referencing what I want to replace?

The output I would desire is to remove everything but Hi by saying Remove everything that’s not Hi if that can be done!

Body:
I think using regex we can do this..

string.replaceAll("[^hi]", "?")


问:
python string changed when using enumerate over path names
I do face following odd behavior:

```<code>paths =['./01_data\\2017-04-12 yy\\data.xlsx', './01_data\\2017-05-01 dd\\data.xlsx', './01_data\\2016-11-18 xx\\data.xlsx', './01_data\\2017-10-11 dd\\data.xlsx']
</code>```

the paths to my data file are generated by:

```<code>paths = [item for item in glob.glob('./01_data/**/**') if '.xlsx' in item]
</code>```

I do loop over the file paths and want to extract the date from it:

```<code># date measured
re_date = re.compile(r'\d{4}-\d{2}-\d{2}')
</code>```

What does work:

```<code>dates = []
for i in len(paths):
    match = re_date.search(paths[i])
    if match:
        dates.append(match.group())
</code>```

If I use enumerate, the paths are changed and \\ is converted to :

```<code>for item, file in enumerate(paths):
    print(file)

./01_data\2017-04-12 yy\data.xlsx
./01_data\2017-05-01 dd\data.xlsx
./01_data\2016-11-18 xx\data.xlsx
./01_data\2017-10-11 dd\data.xlsx
</code>```

Same behavior with:

```<code>for file in paths:
    print(file)

./01_data\2017-04-12 yy\data.xlsx
./01_data\2017-05-01 dd\data.xlsx
./01_data\2016-11-18 xx\data.xlsx
./01_data\2017-10-11 dd\data.xlsx
</code>```

Regex does not work with these strings because the missing '\\'. Any ideas why iteration over the list changes '\\' to '\' ? It is not a big deal to change my code but it took me quite a while to find the source of the error.

答:
Your strings aren't changing.  If you loop over paths without enumerate, and print the strings, you will see the same thing.  This is the difference between printing the str() of the string (single backslash, no enclosing quotes), and the repr() of the string (double backslash, with enclosing quotes).</p>

```<code>>>> s = './01_data\\2017-04-12 yy\\data.xlsx'
>>> print(repr(s))
'./01_data\\2017-04-12 yy\\data.xlsx'
>>> print(str(s))
./01_data\2017-04-12 yy\data.xlsx
</code>```

Body:
I do face following odd behavior:

paths =['./01_data\\2017-04-12 yy\\data.xlsx', './01_data\\2017-05-01 dd\\data.xlsx', './01_data\\2016-11-18 xx\\data.xlsx', './01_data\\2017-10-11 dd\\data.xlsx']

the paths to my data file are generated by:

paths = [item for item in glob.glob('./01_data/**/**') if '.xlsx' in item]

I do loop over the file paths and want to extract the date from it:

# date measured
re_date = re.compile(r'\d{4}-\d{2}-\d{2}')

What does work:

dates = []
for i in len(paths):
    match = re_date.search(paths[i])
    if match:
        dates.append(match.group())

If I use enumerate, the paths are changed and \\ is converted to :

for item, file in enumerate(paths):
    print(file)

./01_data\2017-04-12 yy\data.xlsx
./01_data\2017-05-01 dd\data.xlsx
./01_data\2016-11-18 xx\data.xlsx
./01_data\2017-10-11 dd\data.xlsx

Same behavior with:

for file in paths:
    print(file)

./01_data\2017-04-12 yy\data.xlsx
./01_data\2017-05-01 dd\data.xlsx
./01_data\2016-11-18 xx\data.xlsx
./01_data\2017-10-11 dd\data.xlsx

Regex does not work with these strings because the missing '\\'. Any ideas why iteration over the list changes '\\' to '\' ? It is not a big deal to change my code but it took me quite a while to find the source of the error.

Body:
Your strings aren't changing.  If you loop over paths without enumerate, and print the strings, you will see the same thing.  This is the difference between printing the str() of the string (single backslash, no enclosing quotes), and the repr() of the string (double backslash, with enclosing quotes).

>>> s = './01_data\\2017-04-12 yy\\data.xlsx'
>>> print(repr(s))
'./01_data\\2017-04-12 yy\\data.xlsx'
>>> print(str(s))
./01_data\2017-04-12 yy\data.xlsx


答:
This has nothing to do with the enumerate() function. You're printing a string with double backslash. Double backslash when printing is understood like escaping a backslash, and that's why you get this result.
Try without the enumerate, it will give you the same result.

```<code>for file in paths:
    print(file)
</code>```

Title: python string changed when using enumerate over path names

Body:
This has nothing to do with the enumerate() function. You're printing a string with double backslash. Double backslash when printing is understood like escaping a backslash, and that's why you get this result.
Try without the enumerate, it will give you the same result.

for file in paths:
    print(file)


问:
How to embed a Mongoid tree in another document?
I'm using mongoid-tree but this question probably applies to other acts_as_tree ports for Mongoid.

I want a tree of nodes and I want the whole tree to be embedded in another document. My problem is that this really only requires that the root node be embedded but all nodes have the same embedded_in. In my case:

```<code>class Container
  include Mongoid::Document

  embeds_one :root, :class_name => "Node"
end

class Node
  include Mongoid::Document
  include Mongoid::Tree

  embedded_in :container, :inverse_of => :root
end
</code>```

How can I set this up so that only one record per tree is embedded_in the Container? Is there another approach that would be better?

答:
The author of mongoid-tree, benedikt, answered on GitHub.

Currently Mongoid::Tree doesn't work with embedded Nodes. He suggests:

```<code>class Container
  include Mongoid::Document

  referenced_in :node, :inverse_of => :container
end

class Node
  include Mongoid::Document
  include Mongoid::Tree

  references_one :container
end
</code>```

This way you any node can be assigned to a container. You could also overwrite the Node.container method to call root.container for child nodes so you'd get the container for subnodes as well.

Body:
I'm using mongoid-tree but this question probably applies to other acts_as_tree ports for Mongoid.

I want a tree of nodes and I want the whole tree to be embedded in another document. My problem is that this really only requires that the root node be embedded but all nodes have the same embedded_in. In my case:

class Container
  include Mongoid::Document

  embeds_one :root, :class_name => "Node"
end

class Node
  include Mongoid::Document
  include Mongoid::Tree

  embedded_in :container, :inverse_of => :root
end

How can I set this up so that only one record per tree is embedded_in the Container? Is there another approach that would be better?

Body:
The author of mongoid-tree, benedikt, answered on GitHub.

Currently Mongoid::Tree doesn't work with embedded Nodes. He suggests:

class Container
  include Mongoid::Document

  referenced_in :node, :inverse_of => :container
end

class Node
  include Mongoid::Document
  include Mongoid::Tree

  references_one :container
end

This way you any node can be assigned to a container. You could also overwrite the Node.container method to call root.container for child nodes so you'd get the container for subnodes as well.


问:
$uibModal - dismiss failing to invoke
I know there are numerous threads on this issue, but I have tried to follow solutions provided but am having no success.

The one I followed which resolved the error Unknown provider: $uibModalInstanceProvider, was the answer from @GeorgeKach in Unknown provider: $uibModalInstanceProvider - Bootstrap UI modal. The error has been removed and the modal opens, but my dismissal/close methods aren't invoking.

```<code>    vm.open = function() {

        console.log('open') //invokes

        var modalInstance = $uibModal.open({
            templateUrl: 'p3sweb/app/components/app/views/modalTemplate.html',
            appendTo: undefined,
            controller: function($uibModalInstance ,$scope){

                vm.ok = function () {
                    console.log('ok') //fails
                    $uibModalInstance.close();
                };

                vm.cancel = function () {
                    console.log('close') //fails
                    $uibModalInstance.dismiss('cancel');
                };

            }
        })

        modalInstance.result.then(function() {
          //resolved
        }, function() {
          //rejected
        })
    }
</code>```

Question

Why are my ok and cancel methods not invoking? Rather than providing a work around, can someone explain why they aren't invoking?

Template

```<code><div class="modal-header d-flex flex-column align-items-center justify-content-center">
    <i class="fa fa-warning fa-3x"></i>
    <p class="h4 txt-phase-red">Remove Patent</p>
</div>
<div class="modal-body d-flex flex-column align-items-center justify-content-center">
    <p class="font-body">Are you sure you want to remove patent application xxxxxxxxxx?</p>
</div>
<div class="modal-footer">
    <button class="btn btn--lg font-body font-body--component bg-phase-red txt-white" ng-click="$ctrl.cancel()">No</button>
    <button class="btn btn--lg font-body font-body--component bg-phase-green txt-white" ng-click="$ctrl.ok()">Yes</button>
</div>
</code>```

答:
You should you controllerAs, and set it to vm

controllerAs (Type: string, Example: ctrl) - An alternative to the controller-as syntax. Requires the controller option to be provided as well.

```<code>var modalInstance = $uibModal.open({
        templateUrl: 'p3sweb/app/components/app/views/modalTemplate.html',
        appendTo: undefined,
        controllerAs: 'vm',
        controller: function($uibModalInstance){

            var vm = this;

            vm.ok = function () {
                console.log('ok') //fails
                $uibModalInstance.close();
            };

            vm.cancel = function () {
                console.log('close') //fails
                $uibModalInstance.dismiss('cancel');
            };

        }
    })
</code>```

Of course you can avoid using these kind of simple controllers by utilizing $close(result) and $dismiss(result) inside the template

```<code><button class="btn btn-lg font-body font-body--component bg-phase-red txt-white" ng-click="$dismiss('cancel')">No</button>
<button class="btn btn-lg font-body font-body--component bg-phase-green txt-white" ng-click="$close('ok')">Yes</button>
</code>```

Title: $uibModal - dismiss failing to invoke

Body:
I know there are numerous threads on this issue, but I have tried to follow solutions provided but am having no success.

The one I followed which resolved the error Unknown provider: $uibModalInstanceProvider, was the answer from @GeorgeKach in Unknown provider: $uibModalInstanceProvider - Bootstrap UI modal. The error has been removed and the modal opens, but my dismissal/close methods aren't invoking.

    vm.open = function() {

        console.log('open') //invokes

        var modalInstance = $uibModal.open({
            templateUrl: 'p3sweb/app/components/app/views/modalTemplate.html',
            appendTo: undefined,
            controller: function($uibModalInstance ,$scope){

                vm.ok = function () {
                    console.log('ok') //fails
                    $uibModalInstance.close();
                };

                vm.cancel = function () {
                    console.log('close') //fails
                    $uibModalInstance.dismiss('cancel');
                };

            }
        })

        modalInstance.result.then(function() {
          //resolved
        }, function() {
          //rejected
        })
    }

Question

Why are my ok and cancel methods not invoking? Rather than providing a work around, can someone explain why they aren't invoking?

Template

Remove Patent

Are you sure you want to remove patent application xxxxxxxxxx?

    <button class="btn btn--lg font-body font-body--component bg-phase-red txt-white" ng-click="$ctrl.cancel()">No</button>
    <button class="btn btn--lg font-body font-body--component bg-phase-green txt-white" ng-click="$ctrl.ok()">Yes</button>

Body:
You should you controllerAs, and set it to vm

controllerAs (Type: string, Example: ctrl) - An alternative to the controller-as syntax. Requires the controller option to be provided as well.

var modalInstance = $uibModal.open({
        templateUrl: 'p3sweb/app/components/app/views/modalTemplate.html',
        appendTo: undefined,
        controllerAs: 'vm',
        controller: function($uibModalInstance){

            var vm = this;

            vm.ok = function () {
                console.log('ok') //fails
                $uibModalInstance.close();
            };

            vm.cancel = function () {
                console.log('close') //fails
                $uibModalInstance.dismiss('cancel');
            };

        }
    })

Of course you can avoid using these kind of simple controllers by utilizing $close(result) and $dismiss(result) inside the template

<button class="btn btn-lg font-body font-body--component bg-phase-red txt-white" ng-click="$dismiss('cancel')">No</button>
<button class="btn btn-lg font-body font-body--component bg-phase-green txt-white" ng-click="$close('ok')">Yes</button>


答:
It works as expected...

```<code>dates = []
for item, file in enumerate(paths):
    match = re_date.search(file)
    if match:
        dates.append(match.group())
print(dates)
</code>```

Prints:

```<code>['2017-04-12', '2017-05-01', '2016-11-18', '2017-10-11']
</code>```

Read more about escaping characters and raw strings:

```<code>>>> print("\\")
\
>>> print(r"\\")
\\
</code>```

Body:
It works as expected...

dates = []
for item, file in enumerate(paths):
    match = re_date.search(file)
    if match:
        dates.append(match.group())
print(dates)

Prints:

['2017-04-12', '2017-05-01', '2016-11-18', '2017-10-11']

Read more about escaping characters and raw strings:

>>> print("\\")
\
>>> print(r"\\")
\\