mongoDB setup using Docker

Pull mongodb image and run container 

$ docker container run –name mongodb –mount type=bind,source=/Users/noy/Documents/Docker/mongodb/data,target=/data/db -d mongo –auth

 

Execute mongo to create root user

$ docker container exec -it mongodb mongo admin

> db.createUser({

      user: “admin”,

      pwd: “secure”,

      roles: [ { role: “root”, db: “admin” } ]

})

> exit

 

Execute mongo and use as root user

$ docker container exec -it mongodb mongo admin

> db.auth(‘admin’,’secure’)

> show dbs

The X-Frame-Options response header

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object> . Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

Using X-Frame-Options

There are three possible values for X-Frame-Options:

DENY
The page cannot be displayed in a frame, regardless of the site attempting to do so.
SAMEORIGIN
The page can only be displayed in a frame on the same origin as the page itself.
ALLOW-FROM uri
The page can only be displayed in a frame on the specified origin.

In other words, if you specify DENY, not only will attempts to load the page in a frame fail when loaded from other sites, attempts to do so will fail when loaded from the same site. On the other hand, if you specify SAMEORIGIN, you can still use the page in a frame as long as the site including it in a frame is the same as the one serving the page.

Configuring Apache

To configure Apache to send the X-Frame-Options header for all pages, add this to your site’s configuration:

Header always append X-Frame-Options SAMEORIGIN

Configuring nginx

To configure nginx to send the X-Frame-Options header, add this either to your http, server or location configuration:

add_header X-Frame-Options SAMEORIGIN;

Configuring IIS

To configure IIS to send the X-Frame-Options header, add this your site’s Web.config file:

<system.webServer>
  ...

  <httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="SAMEORIGIN" />
    </customHeaders>
  </httpProtocol>

  ...
</system.webServer>

Configuring HAProxy

To configure HAProxy to send the X-Frame-Options header, add this to your frontend, listen, or backend configuration:

rspadd X-Frame-Options:\ SAMEORIGIN

Results

When an attempt is made to load content into a frame, and permission is denied by the X-Frame-Options header, Firefox currently renders about:blank into the frame. At some point, an error message of some kind will be displayed in the frame instead.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.1.249.1042 3.6.9 (1.9.2.9) 8.0 10.5 4.0
ALLOW-FROM support Not supported 18.0 (18.0) bug 690168 8.0? ? Not supported WebKit bug 94836

ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options

Feed Instagram Image to Website

  1. Login instagram at http://instagram.com/developer/
  2. Click Register Your Application and input your information
  3. Click Manage Clients and create client, you will receive Client ID

manage-client

4. Go to http://instagram.com/developer/authentication/ and read the instruction for get Token
5. Create and Go to Link https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token for get Token from callback URL parameter
6. Download javascript script from http://lab.adrianquevedo.com/jquery-spectragram/ (or other jQuery)
7. You can debug your request and response from Instagram API by https://apigee.com/console/instagram

api-console

Make sure that your photos display in the highest possible quality when upload to Facebook

Facebook automatically resizing and formatting your upload photos. If you’d like to use more advanced techniques to make your photos look better, try these tips:

  • Resize your photo before you upload it. These are the sizes we support:

    Regular photos 720 px, 960 px, 2048 px
    Cover photos 851 px by 315 px

    If you use a 2048 px photo, make sure to select the High Quality option when you upload it.

    To avoid compression when you upload your cover photo, make sure the file size is under 100 KB.

  • Save your image as a JPEG with an sRGB color profile.

Credit: https://www.facebook.com/help/266520536764594

Setup Password Protection in IIS7

First create a new Windows user which will have access to the directory. If this user already exists, skip to step #5.

1. Open Server Manager by clicking Start -> Administrative Tools -> Server Manager

2. Expand Configuration -> Local Users and Groups

3. Right click Users and select New User.

4. Enter the desired user name and password. Make sure to uncheck “User must change password at next logon” and check both options for “User cannot change password” and “Password never expires”.

5. Open IIS Manager by clicking Start -> Administrative Tools -> Internet Information Services (IIS) Manager

6. Expand the server name in IIS then Sites. Expand the site in question and select the directory you are looking to secure.

7. Double click “Authenticaton” under the IIS heading on the right. If you do not see this, make sure you “Features view” is selected at the bottom of IIS.

8. Right click “Anonymous Authentication” and choose Disable.

9. Right click on “Windows Authentication” and choose Enable.

By default the new user we created will be a member of the “Users” group and this group has access to the directory we are securing. However if you want to limit this access to a select user(s) instead of all users on your server, follow the extra steps below.

1. Right click the directory again on the left side of IIS and choose Edit Permissions.

2. Click the Security tab and then click Advanced.

3. Click Change Permissions

4. Select the Users group and choose Remove

5. Click Add -> Advanced -> Find Now to browse for the new user

6. Click OK until all dialogue boxes are closed

 

Credit: http://toastergremlin.com/?p=175

How to Delete an OEM Partition?

Step-by-step tutorial to follow

Step1: Hit “Windows Key” + “R” to open the run dialogue box and type “diskpart” and hit “OK” to open a black command prompt window.

Step2: Type “list disk” to display all the disks of your computer.

Step3: Type “select disk n”. Here n stands for the disk you want to work well.

Step4: Type “list partition” to display all the volumes on the hard drive.

Step5: Type “select partition n”. Here n stands for the volume you want to delete.

Step6: Type “delete partition override” to get rid of the volume.

Step7: Type “exit” to close the window.

Once you do that you have removed the OEM partition on the drive!

 

Credit: http://www.disk-partition.com/blog/how-to-delete-an-oem-partition/

Configure IIS to accept URL with Special Characters

Ref: http://adorr.net/2010/01/configure-iis-to-accept-url-with-special-characters.html

By default, IIS will block URL requests containing special characters (%, &, :, *) for security concerns, throwing error “400 Bad Request” (or simply “Bad Request” for some cases).

The workaround is rather simple, just following the following steps. Be extra careful as it involves changes in your registry

  1. Set “AllowRestrictedChars” to 1 (http://support.microsoft.com/kb/820129)
  2. Set “VerificationCompatibility” to 1 (http://support.microsoft.com/default.aspx?scid=kb;EN-US;826437) – yes, it applies to ASP.NET frameworks other than 1.1
  3. If you are running on Windows 64-bit version, you may also want to set “VerificationCompatibility” to 1 (Path: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NET)
  4. And if all the above does not help, you may want to try to set “<Page ValidateRequest=false>” on your website’s web.config

Do note that for step 1 and 2, you’ll need to restart IIS and/or HTTP related services, so you may want to follow the steps closely.

Configuring FTP User Isolation in IIS 7

http://www.iis.net/learn/publish/using-the-ftp-service/configuring-ftp-user-isolation-in-iis-7

Configuring User Isolation Settings for All Directories

When isolating users for all directories, all FTP user sessions are restricted to the physical or virtual directory with the same name of the FTP user account. In addition, all global virtual directories that are created will be ignored. In this step you will configure user isolation for all directories, and add a virtual directory for the administrator user.

  1. In IIS Manager, click the node for the FTP site that you created; this will display the icons for all of the FTP features.
  2. Double-click the FTP User Isolation icon to open the FTP user isolation feature.
  3. When the FTP User Isolation feature page is displayed, select the User name directory (disable global virtual directories) option, then click Apply in the Actions pane.
  4. Expand the tree node for your FTP site, then right-click the LocalUser folder and click Add Virtual Directory. (Note: In this example the “LocalUser” folder is a physical directory, but a virtual directory could also have been used.)
  5. When the Add Virtual Directory dialog box appears:
    • Enter “administrator” for the Alias.
    • Enter “%SystemDrive%\inetpub\adminfiles” for the Physical path.
    • When you have completed these items, click OK.

LOGGING IN TO YOUR FTP SITE

You can now log in to your FTP site using user isolation, but the following information applies:

  1. As with Step 3, if you log in to your FTP site anonymously, your session will be restricted to the “LocalUser\Public” folder that you created in the Prerequisites section.
  2. If you log in to your FTP site using the administrator account, your session will be restricted to the “/LocalUser/administrator” virtual directory that you just created.

Google Maps Geolocation and Directions to a Specific Destination

<!DOCTYPE html>
<html>
<head>
  <title>How to get to our headquarters</title>
  <style type="text/css">
    html {
      height: 100%;
    }
    
    body {
      font: 12px Helvetica, Arial ,sans-serif;
      height: 100%;
      margin: 0;
      padding: 0;
    }
    
    #map, #route {
      width: 100%;
      height: 50%;
    }
    #route {
      overflow-y:auto;
    }
    #method {
      position: absolute;
      left: 75px;
      top:15px;
      padding:10px;
      opacity: .9;
      -moz-opacity: .9;
      z-index: 10;
      background-color:#fff;
      border-radius:3px;
      -moz-border-radius:3px;
      -webkit-border-radius:3px;
      
    }
  </style>
  <script src="http://www.google.com/jsapi"></script>
  <script>
    var map;          //the google map     
    var directionsService;    //service that provides directions to get to our destination
    var directionsDisplay;    //rendeder that draws directions on map
    var destinationName   =   "Ventorro del Cano, Madrid";  //our destination. Set yours!
    function initiate_geolocation(skipHTML5){
     
      if (!skipHTML5 &amp;&amp; navigator.geolocation) {
        // HTML5 GeoLocation
        function getLocation(position) {
        document.getElementById("method").innerHTML = "Location obtained using HTML5";
        showMapAndRoute({
          "lat": position.coords.latitude,
          "lng": position.coords.longitude
        });
        }
        navigator.geolocation.getCurrentPosition(getLocation, error);
      } else {
        // Google AJAX API fallback GeoLocation
        if (typeof google == 'object') {
        var geocoder = new google.maps.Geocoder();
        if (google.loader.ClientLocation) {
          document.getElementById("method").innerHTML = "Location obtained using Google Geocoder"; 
          showMapAndRoute({
            "lat": google.loader.ClientLocation.latitude,
            "lng": google.loader.ClientLocation.longitude
          });
        } else
        {
          alert("Google Geocoder was unable to get the client position");
        }
        }
      }
    }
    function showMapAndRoute(l)
    {
       var latlng = new google.maps.LatLng(l.lat,l.lng);
     
       var myOptions = {
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      
      map = new google.maps.Map(document.getElementById("map"), myOptions);
      directionsDisplay = new google.maps.DirectionsRenderer();
      directionsDisplay.setMap(map);
      directionsDisplay.setPanel(document.getElementById("route"));
       var request = {
        origin: l.lat + ',' + l.lng ,
        destination: destinationName,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService = new google.maps.DirectionsService();
        directionsService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(result);
        }
        });   
    }
    function error(e)
    {
      switch(e.code)
      {
        case e.TIMEOUT:
          alert ('Timeout');
          break;
        case e.POSITION_UNAVAILABLE:
          alert ('Position unavailable');
          break;
        case e.PERMISSION_DENIED:
          alert ('Permission denied');
          break;
        case e.UNKNOWN_ERROR:
          alert ('Unknown error');
          break;
      }
      
      //try to get location using Google Geocoder
      initiate_geolocation(true);     
    }
  </script>
</head>
  <body onload="initiate_geolocation()">
  <div id="method"></div>
  <div id="map"></div>
  <div id="route"></div>
  </body>
</html>