Remove values from an existing array in MongoDB

Before

{
   _id: 1,
   fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ],
   vegetables: [ "carrots", "celery", "squash", "carrots" ]
}
{
   _id: 2,
   fruits: [ "plums", "kiwis", "oranges", "bananas", "apples" ],
   vegetables: [ "broccoli", "zucchini", "carrots", "onions" ]
}
db.stores.update(
    { },
    { $pull: { fruits: { $in: [ "apples", "oranges" ] }, vegetables: "carrots" } },
    { multi: true }
)

After

{
  "_id" : 1,
  "fruits" : [ "pears", "grapes", "bananas" ],
  "vegetables" : [ "celery", "squash" ]
}
{
  "_id" : 2,
  "fruits" : [ "plums", "kiwis", "bananas" ],
  "vegetables" : [ "broccoli", "zucchini", "onions" ]
}

References
https://docs.mongodb.com/manual/reference/operator/update/pull/#pull
http://stackoverflow.com/questions/16959099/how-to-remove-array-element-in-mongodb

Setting up a Node.js Cluster

 

var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

   Object.keys(cluster.workers).forEach(function(id) {
    console.log("I am running with ID : "+cluster.workers[id].process.pid);
  });

  cluster.on('exit', function(worker, code, signal) {
    console.log('worker ' + worker.process.pid + ' died');
  });
} else {

      //Do further processing.
}

Express :

app.js

var express=require("express");
var app=express();

app.get('/',function(req,res){

          res.end("Hello world !");

});

app.listen(3000,function(){

          console.log("Running at PORT 3000");

});

cluster.js

var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {

  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', function(worker, code, signal) {
    console.log('worker ' + worker.process.pid + ' died');
  });
} else {

    //change this line to Your Node.js app entry point.
    require("./app.js");
}

References
https://codequs.com/p/BkCZ1VMY/setting-up-a-node-js-cluster/
https://www.sitepoint.com/how-to-create-a-node-js-cluster-for-speeding-up-your-apps/
https://nodejs.org/api/cluster.html

MongoDB Update Operators

Name Description
$inc Increments the value of the field by the specified amount.
$mul Multiplies the value of the field by the specified amount.
$rename Renames a field.
$setOnInsert Sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents.
$set Sets the value of a field in a document.
$unset Removes the specified field from a document.
$min Only updates the field if the specified value is less than the existing field value.
$max Only updates the field if the specified value is greater than the existing field value.
$currentDate Sets the value of a field to current date, either as a Date or a Timestamp.

References
https://docs.mongodb.com/manual/reference/operator/update/#update-operators

How to Setup SoftEther in Ubuntu

download then install

tar xzvf softether-vpnserver-v2.00-9387-rtm-2013.09.16-linux-x86-32bit.tar.gz
cd vpnserver
make

command line

./vpnserver start
./vpncmd
ServerPasswordSet
HubCreate VPN
Hub VPN
SecureNatEnable

use port 992 to connect with Server Manager from windows

Client

/etc/sysctl.conf : net.ipv4.ip_forward=1

ip addr show vpn_vpn
sudo dhclient vpn_vpn
ip addr show vpn_vpn
ip neigh
sudo ip route add 51.254.87.79/32 via 192.168.43.1 dev wlp3s0
sudo ip route del default
sudo ip route add default via 192.168.30.1 dev vpn_vpn

References
https://www.digitalocean.com/community/tutorials/how-to-setup-a-multi-protocol-vpn-server-using-softether
http://lukeluo.blogspot.fr/2013/11/how-to-set-up-softehter-vpn-client.html
https://blog.harshillodhi.co.in/softether-vpn-ubuntu-linux-client-configuration-behind-http-proxy/

How to overlay one div over another div in HTML

use position: relative on the parent and child element with position: absolute.

<div id="container">
  <div id="navi">a</div>
  <div id="infoi">
    <img src="https://appharbor.com/assets/images/stackoverflow-logo.png" height="20" width="32" />b
  </div>
</div
#container {
  width: 100px;
  height: 100px;
  position: relative;
}
#navi,
#infoi {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
#infoi {
  z-index: 10;
}

References
http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div

Configure proxy authentication to work with Ubuntu Software Center

Go to /etc/apt. Create the file apt.conf if you don’t have it there. Write the following lines there.

Acquire::http::proxy "http://username:password@proxyserver:port/";
Acquire::https::proxy "https://username:password@proxyserver:port/";
Acquire::socks::proxy "socks://username:password@proxyserver:port/";
Acquire::ftp::proxy "ftp://username:password@proxyserver:port/";

Save it. You are done.

Keywords
apt , ubuntu , proxy

References
http://askubuntu.com/questions/77449/how-to-configure-proxy-authentication-to-work-with-ubuntu-software-center