Start a mongodb shell in docker container

You can run the interactive mongo shell by running the following command:

docker run -it -p 28000:27017 --name mongoContainer mongo:latest mongo

Otherwise, if your container is already running, you can use the exec command:

docker exec -it mongoContainer mongo


docker pull mongo
docker run --name CONTAINERNAME --restart=always -d -p 8080:8080 mongo mongod --auth
sudo docker exec -i -t CONTAINERNAME bash
use admin
db.createUser({user:"user", pwd:"password", roles:[{role:"root", db:"admin"}]})
exit && exit

Now you have created a running Docker container with everything you need. Now if you want to connect from any client with an admin user, just run this

mongo -u "user" -p "password" HOSTIP --authenticationDatabase "admin"

Command ‘ls’ output numerical chmod permissions

it almost can …

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) *2^(8-i));if(k)printf("%0o ",k);print}'


stat -c "%a %n" *

Also, you can use any filename or directory name instead of * to get a specific result.

On Mac, you can use

stat -f '%A %N' *


Disable & remove virtual host website entry in Apache

You can list the currently enabled websites if you want to check the name:

$ ls /etc/apache2/sites-enabled
000-default.conf my-website.conf

Disable virtual host entry
Let’s assume we’d like to disable my-website.conf. To disable this virtual hosts entry, we issue the following command to Apache (note the exclusion of the .conf extension from the virtual host name):

$ sudo a2dissite my-website

You can confirm this has disabled the website by checking that the site is no longer listed in the enabled sites directory:

$ ls /etc/apache2/sites-enabled

You’ll then need to reload Apache for the changes to take effect:

$ sudo service apache2 reload

Remove virtual host entry

Wanna go the whole nine yards?

If you no longer need the virtual host configuration file, remove that too. First double check what it’s called by listing out the available websites:

$ ls /etc/apache2/sites-available
000-default.conf my-website.conf

Note that this is a different location to /etc/apache2/sites-enabled, from earlier.

Remove the config file you no longer need:

$ rm /etc/apache2/sites-available/my-website.conf

You may also want to backup then remove any website files residing in the /var/www directory, for example:

$ cd /var/www
$ tar czf my-website.tar.gz my-website
$ rm -r my-website

Finish up by copying the backup to somewhere safe and then go ahead and delete it from the server to free up some space.

List all IP addresses connected to linux server

ด้านล่างนี้เป็นคำสั่ง Unix เพื่อแสดงรายการที่อยู่ IP ทั้งหมดที่เชื่อมต่อกับเซิร์ฟเวอร์ของคุณบนพอร์ต 80

netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

เอาท์พุท – การเชื่อมต่อโดยใช้ IP จากสูงสุดไปต่ำสุด


คำสั่งนี้จะเป็นประโยชน์ในการตรวจสอบว่าเซิร์ฟเวอร์ของคุณอยู่ภายใต้การโจมตีหรือไม่ให้เส้นทางเหล่านั้นเป็นโมฆะ อ่านนี่


Mac: Stop the Adobe Creative Cloud app from auto-launching on login

It is loaded by default by /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist.

If you run

launchctl unload -w /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist

that will disable it for your user.

To turn it back on

launchctl load -w /Library/LaunchAgents/com.adobe.AdobeCreativeCloud.plist


Calculate distance between two points in google maps V3

The default radius is Earth’s radius of 6378137 meters. But Mike in the Haversine above uses 6371km instead.


If you want to calculate it yourself, then you can use the Haversine formula:

var rad = function(x) {
  return x * Math.PI / 180;

var getDistance = function(p1, p2) {
  var R = 6378137; // Earth’s mean radius in meter
  var dLat = rad( -;
  var dLong = rad(p2.lng() - p1.lng());
  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
    Math.cos(rad( * Math.cos(rad( *
    Math.sin(dLong / 2) * Math.sin(dLong / 2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  var d = R * c;
  return d; // returns the distance in meter


There actually seems to be a method in GMap3. It’s a static method of the google.maps.geometry.spherical namespace.

It takes as arguments two LatLng objects and will utilize a default Earth radius of 6378137 meters, although the default radius can be overridden with a custom value if necessary.

Make sure you include:

<script type="text/javascript" src=""></script>

in your head section.

The call will be:

google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);


Just add this to the beginning of your JavaScript code:

google.maps.LatLng.prototype.distanceFrom = function(latlng) {
  var lat = [,]
  var lng = [this.lng(), latlng.lng()]
  var R = 6378137;
  var dLat = (lat[1]-lat[0]) * Math.PI / 180;
  var dLng = (lng[1]-lng[0]) * Math.PI / 180;
  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
  Math.cos(lat[0] * Math.PI / 180 ) * Math.cos(lat[1] * Math.PI / 180 ) *
  Math.sin(dLng/2) * Math.sin(dLng/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;
  return Math.round(d);

and then use the function like this:

var loc1 = new GLatLng(52.5773139, 1.3712427);
var loc2 = new GLatLng(52.4788314, 1.7577444);
var dist = loc2.distanceFrom(loc1);


AngularJS: Symbols ‘@’, ‘&’, ‘=’ and ‘>’ in custom directive’s scope binding

In an AngularJS directive the scope allows you to access the data in the attributes of the element to which the directive is applied.

This is illustrated best with an example:

<div my-customer name="Customer XYZ"></div>

and the directive definition:

angular.module('myModule', [])
.directive('myCustomer', function() {
  return {
    restrict: 'E',
    scope: {
      customerName: '@name'
    controllerAs: 'vm',
    bindToController: true,
    controller: ['$http', function($http) {
      var vm = this;

      vm.doStuff = function(pane) {
    link: function(scope, element, attrs) {

When the scope property is used the directive is in the so called “isolated scope” mode, meaning it can not directly access the scope of the parent controller.

In very simple terms, the meaning of the binding symbols is:

someObject: '=' (two-way data binding)

someString: '@' (passed directly or through interpolation with double curly braces notation {{}})

someExpression: '&' (e.g. hideDialog())

This information is present in the AngularJS directive documentation page, although somewhat spread throughout the page.

The symbol > is not part of the syntax.

However, < does exist as part of the AngularJS component bindings and means one way binding.

> is not in the documentation.

< is for one-way binding.

@ binding is for passing strings. These strings support {{}} expressions for interpolated values.

= binding is for two-way model binding. The model in parent scope is linked to the model in the directive’s isolated scope.

& binding is for passing a method into your directive’s scope so that it can be called within your directive.

When we are setting scope: true in directive, Angular js will create a new scope for that directive. That means any changes made to the directive scope will not reflect back in parent controller.


There are a lot of great answers here, but I would like to offer my perspective on the differences between @=, and & binding that proved useful for me.

All three bindings are ways of passing data from your parent scope to your directive’s isolated scope through the element’s attributes:

  1. @ binding is for passing strings. These strings support {{}} expressions for interpolated values. For example: . The interpolated expression is evaluated against directive’s parent scope.
  2. = binding is for two-way model binding. The model in parent scope is linked to the model in the directive’s isolated scope. Changes to one model affects the other, and vice versa.
  3. & binding is for passing a method into your directive’s scope so that it can be called within your directive. The method is pre-bound to the directive’s parent scope, and supports arguments. For example if the method is hello(name) in parent scope, then in order to execute the method from inside your directive, you must call $scope.hello({name:’world’})

I find that it’s easier to remember these differences by referring to the scope bindings by a shorter description:

  • @ Attribute string binding
  • = Two-way model binding
  • & Callback method binding

The symbols also make it clearer as to what the scope variable represents inside of your directive’s implementation:

  • @ string
  • = model
  • & method

In order of usefulness (for me anyways):

  1. =
  2. @
  3. &