问:
ng-repeat not binding from database
I have a 1 page application which should display a list of objects from a database.  I used ng-repeat to create a template to bind data from array in db. As I am new to Angular any help would be great.  My code is below:

SERVER.JS

var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('eventlist', ['eventlist']);
var bodyParser = require('body-parser');

app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());

app.get('/eventlist', function (req, res) {
  console.log("i received a get request")

  db.eventlist.find(function(err, docs){
    console.log(docs);
    res.json(docs);
  });
});

app.post('/eventlist', function (req, res){
  console.log(req.body);
  db.eventlist.insert(req.body, function (err, doc) {
    res.json(doc);
  });
});

app.delete('/eventlist/:id', function(req, res){
  var id = req.params.id;
  console.log(id);
  db.eventlist.remove({_id: mongojs.ObjectID(id)}, function (err, doc) {
    res.json(doc);
  });
});

app.get('/eventlist/:id', function (req, res) {
  var id = req.params.id;
  console.log(id);
  db.eventlist.findOne({_id: mongojs.ObjectId(id)}, function (err, doc) {
    res.json(doc);
  });
});

app.put('/eventlist/:id', function (req, res) {
  var id = req.params.id;
  console.log(req.body.name);
  db.eventlist.findAndModify({
    query: {_id: mongojs.ObjectId(id)},
    update: {$set: {name: req.body.name, startDate: req.body.startDate, price: req.body.price, location: req.body.location}},
    new: true}, function (err, doc) {
      res.json(doc);
    }
  );
});

app.listen(4000);
console.log("Server running on port 4000");```
<pre class="snippet-code-html lang-html prettyprint-override"><code>INDEX.HTML
<!DOCTYPE html>
<html ng-app="myApp">
  <head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="css/page.css">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">

    <title>Capstone Project</title>
    <meta name="description" content="Carnival and Event Mapping tool">

    <link rel="manifest" href="/manifest.json">

  </head>
  <body>
  <div id="wrapper">
      <div class="overlay"></div>

      <!-- Sidebar -->
      <nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">
          <ul class="nav sidebar-nav">
              <li class="sidebar-brand">

                     Brand

              </li>
              <li>
                  Enter Zip Code
              </li>
              <li>
                  <input type="text"/><button>Submit</button>
              </li>
              <li class="dropdown">
                Events Near Me<span class="caret"></span>
                <ul class="dropdown-menu" role="menu">
                  <li class="dropdown-header">Select Radius</li>
                  <li>5 Miles</li>
                  <li>10 Miles</li>
                  <li>15 Miles</li>
                </ul>
              </li>
              <li>
                  Ascending
              </li>
              <li>
                  Descending
              </li>
              <li>
                  Contact
              </li>
          </ul>
      </nav>
      <!-- /#sidebar-wrapper -->

      <!-- Page Content -->
      <div id="page-content-wrapper">
          <button type="button" class="hamburger is-closed" data-toggle="offcanvas">
              <span class="hamb-top"></span>
        <span class="hamb-middle"></span>
      <span class="hamb-bottom"></span>
          </button>

          <div class="container" ng-controller="AppCtrl">
        <h1>Summer Event List</h1>

        <table class="table">
          <thead>
            <tr>
              <th>Name</th>
              <th>Date</th>
              <th>Price</th>
              <th>Location</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td><input class="form-control" ng-model="event.name"></td>
              <td><input class="form-control" ng-model="event.startDate"></td>  <!--type="date" (put this next to startDate)-->
              <td><input class="form-control" ng-model="event.price"></td> <!--$<input type="number" name="currency" min="0" max="9999" step="0.01" size="4"
    title="CDA Currency Format - no dollar sign and no comma(s) - cents (.##) are optional" />-->
              <td><input class="form-control" ng-model="event.location"></td>
              <td><button class="btn btn-primary" ng-click="addEvent()">Add Event</button></td>
              <td><button class="btn btn-primary" ng-click="deselect()">Clear</button></td>
            </tr>
            <tr ng-repeat="event in eventlist"> <!--also tried ng-repeat="event in eventlist track by $indexs"-->
              <td>{{event.name}}</td>
              <td>{{event.startDate}}</td>
              <td>{{event.price}}</td>
              <td>{{event.location}}</td>
              <!-- <td><button class="btn btn-danger" ng-click="remove(contact._id)">Remove</button></td>
              <td><button class="btn btn-warning" ng-click="edit(contact._id)">Edit</button></td> -->
            </tr>
          </tbody>
        </table>
      </div>

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js" charset="utf-8"></script>
      <script src="controllers/controller.js" charset="utf-8"></script>
    </body>
  </html>

  </div>
   <!-- /#page-content-wrapper -->

   <script>
   $(document).ready(function () {
   var trigger = $('.hamburger'),
       overlay = $('.overlay'),
      isClosed = false;

     trigger.click(function () {
       hamburger_cross();
     });

     function hamburger_cross() {

       if (isClosed == true) {
         overlay.hide();
         trigger.removeClass('is-open');
         trigger.addClass('is-closed');
         isClosed = false;
       } else {
         overlay.show();
         trigger.removeClass('is-closed');
         trigger.addClass('is-open');
         isClosed = true;
       }
   }

   $('[data-toggle="offcanvas"]').click(function () {
         $('#wrapper').toggleClass('toggled');
   });
   });
   </script>

</body>

</html></code>```

CONTROLLER.JS
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
    console.log("Hello World from controller");

var refresh = function(){
  $http.get('/eventlist/').then(function(response) {
    console.log("I got the data I requested");
    $scope.eventlist = response;
    $scope.event = null;
  });
};

refresh();

  $scope.addEvent = function () {
    console.log($scope.event);
    $http.post('/eventlist/', $scope.event).then(function(response){
      console.log(response);
      refresh();
    });
    $scope.update = function() {
      console.log($scope.event._id);
      $http.put('/eventlist/' + $scope.event._id, $scope.event).then(function(response) {
        refresh();
      })
    };
  };

  $scope.remove = function(id) {
    console.log(id);
    $http.delete('/eventlist/' + id).then(function(response) {
      refresh();
    });
  };

  $scope.edit = function(id) {
    console.log(id);
    $http.get('/eventlist/' + id).then(function(response) {
      $scope.event = response;
    });
  };

  $scope.deselect = function() {
    $scope.event = null;
    refresh();
  };

  }]);```

答:
Change it as response.data,

```<code>var refresh = function(){
  $http.get('/eventlist/').then(function(response) {
    $scope.eventlist = response.data;
    $scope.event = null;
  });
};
</code>```

Title: ng-repeat not binding from database

Body:
I have a 1 page application which should display a list of objects from a database.  I used ng-repeat to create a template to bind data from array in db. As I am new to Angular any help would be great.  My code is below:

SERVER.JS

var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('eventlist', ['eventlist']);
var bodyParser = require('body-parser');

app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());

app.get('/eventlist', function (req, res) {
  console.log("i received a get request")

  db.eventlist.find(function(err, docs){
    console.log(docs);
    res.json(docs);
  });
});

app.post('/eventlist', function (req, res){
  console.log(req.body);
  db.eventlist.insert(req.body, function (err, doc) {
    res.json(doc);
  });
});

app.delete('/eventlist/:id', function(req, res){
  var id = req.params.id;
  console.log(id);
  db.eventlist.remove({_id: mongojs.ObjectID(id)}, function (err, doc) {
    res.json(doc);
  });
});

app.get('/eventlist/:id', function (req, res) {
  var id = req.params.id;
  console.log(id);
  db.eventlist.findOne({_id: mongojs.ObjectId(id)}, function (err, doc) {
    res.json(doc);
  });
});

app.put('/eventlist/:id', function (req, res) {
  var id = req.params.id;
  console.log(req.body.name);
  db.eventlist.findAndModify({
    query: {_id: mongojs.ObjectId(id)},
    update: {$set: {name: req.body.name, startDate: req.body.startDate, price: req.body.price, location: req.body.location}},
    new: true}, function (err, doc) {
      res.json(doc);
    }
  );
});

app.listen(4000);
console.log("Server running on port 4000");

INDEX.HTML
<!DOCTYPE html>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <link rel="stylesheet" href="css/page.css">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">

    <title>Capstone Project</title>
    <meta name="description" content="Carnival and Event Mapping tool">

    <link rel="manifest" href="/manifest.json">

                     Brand

                  Enter Zip Code

                  <input type="text"/><button>Submit</button>

                Events Near Me

Select Radius

5 Miles

10 Miles

15 Miles

                  Ascending

                  Descending

                  Contact

          <button type="button" class="hamburger is-closed" data-toggle="offcanvas">

          </button>

Summer Event List

              Name
              Date
              Price
              Location
              Action

              <input class="form-control" ng-model="event.name">
              <input class="form-control" ng-model="event.startDate">
              <input class="form-control" ng-model="event.price">
              <input class="form-control" ng-model="event.location">
              <button class="btn btn-primary" ng-click="addEvent()">Add Event</button>
              <button class="btn btn-primary" ng-click="deselect()">Clear</button>

              {{event.name}}
              {{event.startDate}}
              {{event.price}}
              {{event.location}}

CONTROLLER.JS
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
    console.log("Hello World from controller");

var refresh = function(){
  $http.get('/eventlist/').then(function(response) {
    console.log("I got the data I requested");
    $scope.eventlist = response;
    $scope.event = null;
  });
};

refresh();

  $scope.addEvent = function () {
    console.log($scope.event);
    $http.post('/eventlist/', $scope.event).then(function(response){
      console.log(response);
      refresh();
    });
    $scope.update = function() {
      console.log($scope.event._id);
      $http.put('/eventlist/' + $scope.event._id, $scope.event).then(function(response) {
        refresh();
      })
    };
  };

  $scope.remove = function(id) {
    console.log(id);
    $http.delete('/eventlist/' + id).then(function(response) {
      refresh();
    });
  };

  $scope.edit = function(id) {
    console.log(id);
    $http.get('/eventlist/' + id).then(function(response) {
      $scope.event = response;
    });
  };

  $scope.deselect = function() {
    $scope.event = null;
    refresh();
  };

  }]);

Body:
Change it as response.data,

var refresh = function(){
  $http.get('/eventlist/').then(function(response) {
    $scope.eventlist = response.data;
    $scope.event = null;
  });
};


来源: stackexchange

问:
excel-vba Single column to multidimensional array
I'm trying to put values of a column's range in a 2-dim array (0 To 1, 0 To ´length of my column's range`).

I need something like this:

```<code>arr(0, 0) = value of B4
arr(1, 0) = value of B5
arr(0, 1) = value of B6
arr(1, 1) = value of B7
...
arr(0, n) = value of Bn
arr(1, last row of my column range) = value of last B
</code>```

Can someone tell me what function i must use?

答:
The following code loops through each cell in Column B, starting at B4, and assigns their values to the array aResults, as you've described...</p>

```<code>Dim aResults() As Variant
Dim rRange As Range
Dim nCols As Long
Dim i As Long

Set rRange = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)

nCols = rRange.Cells.Count \ 2
nCols = nCols + (rRange.Cells.Count Mod 2)

ReDim aResults(1, nCols - 1)

For i = 0 To rRange.Cells.Count - 1
    'Debug.Print i Mod 2, i \ 2, rRange(1).Offset(i).Value
    aResults(i Mod 2, i \ 2) = rRange(1).Offset(i).Value
Next i
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to put values of a column's range in a 2-dim array (0 To 1, 0 To ´length of my column's range`).

I need something like this:

arr(0, 0) = value of B4
arr(1, 0) = value of B5
arr(0, 1) = value of B6
arr(1, 1) = value of B7
...
arr(0, n) = value of Bn
arr(1, last row of my column range) = value of last B

Can someone tell me what function i must use?

Body:
The following code loops through each cell in Column B, starting at B4, and assigns their values to the array aResults, as you've described...

Dim aResults() As Variant
Dim rRange As Range
Dim nCols As Long
Dim i As Long

Set rRange = Range("B4:B" & Cells(Rows.Count, "B").End(xlUp).Row)

nCols = rRange.Cells.Count \ 2
nCols = nCols + (rRange.Cells.Count Mod 2)

ReDim aResults(1, nCols - 1)

For i = 0 To rRange.Cells.Count - 1
    'Debug.Print i Mod 2, i \ 2, rRange(1).Offset(i).Value
    aResults(i Mod 2, i \ 2) = rRange(1).Offset(i).Value
Next i


问:
What is the point of nulling private variables in destructor?
I have spot the following pattern in code I'm working with: in some classes in destructor I have found private variable being nulled, in example:

```<code>public function __destruct()
{
    foreach($this->observers as $observer)
    {
        $observer = null;
    }
    $this->db_build = null;
}
</code>```

Is there any point in doing this when PHP has GC? Does it somehow improve performance of script?

答:
It's sometimes just for the cleanliness meme. But in your exmaple both $observer and ->$db_build reference sub-objects. So here the intention is to have them destroyed before the destruction of the current object finishes. (Albeit I'm unsure if Zend core really likes being interrupted when it's on a destroying rampage. It probably has a spool list or something.)

Anyway, it's not necessary from the GC point of view. But it might be sensible if the composite subojects have some inderdependencies; e.g. counters or registry references themselves. So, in most cases not needed I'd say.

I've made a silly example to demonstrate the __destruct order:

```<code>class dest {
        function __construct($name, $sub=NULL) {
                $this->name = $name;
                $this->sub = $sub;
        }
        function __destruct() {
                print "<destroying $this->name>\n";
                $this->sub = NULL;
                print "</destroying $this->name>\n";
        }
}

$d = new dest("first", new dest("second", new dest("third")));
exit;
</code>```

Without the $this->sub = NULL the destruction of the objects would each happen individually, not necessarily in instantiation order. With unsetting composite objects manually however PHP destroys the three objects in a nested fashion:

```<code><destroying first>
    <destroying second>
        <destroying third>
        </destroying third>
    </destroying second>
</destroying first>
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I have spot the following pattern in code I'm working with: in some classes in destructor I have found private variable being nulled, in example:

public function __destruct()
{
    foreach($this->observers as $observer)
    {
        $observer = null;
    }
    $this->db_build = null;
}

Is there any point in doing this when PHP has GC? Does it somehow improve performance of script?

Body:
It's sometimes just for the cleanliness meme. But in your exmaple both $observer and ->$db_build reference sub-objects. So here the intention is to have them destroyed before the destruction of the current object finishes. (Albeit I'm unsure if Zend core really likes being interrupted when it's on a destroying rampage. It probably has a spool list or something.)

Anyway, it's not necessary from the GC point of view. But it might be sensible if the composite subojects have some inderdependencies; e.g. counters or registry references themselves. So, in most cases not needed I'd say.

I've made a silly example to demonstrate the __destruct order:

class dest {
        function __construct($name, $sub=NULL) {
                $this->name = $name;
                $this->sub = $sub;
        }
        function __destruct() {
                print "<destroying $this->name>\n";
                $this->sub = NULL;
                print "</destroying $this->name>\n";
        }
}

$d = new dest("first", new dest("second", new dest("third")));
exit;

Without the $this->sub = NULL the destruction of the objects would each happen individually, not necessarily in instantiation order. With unsetting composite objects manually however PHP destroys the three objects in a nested fashion:

<destroying first>
    <destroying second>
        <destroying third>
        </destroying third>
    </destroying second>
</destroying first>


问:
Delphi Firedac SQL Server: no error raised when update fails because record is locked
I'm currently working on a project to migrate code base from using Advantage Database Server to SQL Server.

I'm using Firedac of XE8 linked to a Microsoft SQL Server 2014 Express.

I have a small test project. There's a TDBGrid showing the content of a table (the query lock mode is Pessimistic, lockpoint immediate).

I have another TQuery with a SQL command like this:

```<code>update myTable
set firstName = 'John'
where id = 1
</code>```

What I do :

I put the first row in Edit mode (by writing something in the cell)

When I press a button, it runs executeSQL on the Update query

Nothing happens -- the update query does not go through

That's fine ... but I was expecting an error message telling me the UPDATE didn't go trough...

How can I get the same behavior but with an error message triggered ?

答:
Essential connection settings to work with row locks :

```<code>TFDConnection.UpdateOptions.Lockmode := lmPessimistic;

TFDConnection.UpdateOptions.LockPoint := lmImmediate;

TFDConnection.UpdateOptions.LockWait := False;
</code>```

Behaviour described is SQL Server waiting for the lock to be removed to finish commiting the UPDATE.  By setting your FireDACconnection to 'no wait' it's going to raise an exception as soon as you attempt to do something on the row you've locked by putting the dataset in Edit. Then you can catch this exception to do what you want.

Body:
I'm currently working on a project to migrate code base from using Advantage Database Server to SQL Server.

I'm using Firedac of XE8 linked to a Microsoft SQL Server 2014 Express.

I have a small test project. There's a TDBGrid showing the content of a table (the query lock mode is Pessimistic, lockpoint immediate).

I have another TQuery with a SQL command like this:

update myTable
set firstName = 'John'
where id = 1

What I do :

I put the first row in Edit mode (by writing something in the cell)

When I press a button, it runs executeSQL on the Update query

Nothing happens -- the update query does not go through

That's fine ... but I was expecting an error message telling me the UPDATE didn't go trough...

How can I get the same behavior but with an error message triggered ?

Body:
Essential connection settings to work with row locks :

TFDConnection.UpdateOptions.Lockmode := lmPessimistic;

TFDConnection.UpdateOptions.LockPoint := lmImmediate;

TFDConnection.UpdateOptions.LockWait := False;

Behaviour described is SQL Server waiting for the lock to be removed to finish commiting the UPDATE.  By setting your FireDACconnection to 'no wait' it's going to raise an exception as soon as you attempt to do something on the row you've locked by putting the dataset in Edit. Then you can catch this exception to do what you want.


问:
Recyclerview within a Scrollview dont coordinate
I have this activity design, which shows a card view inside a scrollView, But under that cardview I need to put a listview or recyclerview. The problem is that I need the scroll of that list to coordinate with the main scroll. Osea that when lower in the content the cardview will disappear and the list of the recyclerview or listview will be crossed.

I need all the content to respond to the main scroll to show up and disappear after titlebar, Which should I change or redesign?

```<code>        <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        app:cardElevation="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/post_coordinator"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/post_bg"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:scaleType="fitXY"
                android:src="@drawable/default_profile" />

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom"
                android:layout_marginLeft="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />

            <com.mikhaellopez.circularimageview.CircularImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:layout_anchor="@id/post_bg"
                app:layout_anchorGravity="center_horizontal|bottom"
                android:src="@drawable/profile"
                app:civ_border_color="#FFF"
                app:civ_border_width="3dp"
                />

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom|end"
                android:layout_marginRight="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_marginTop="205dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="50dp"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Prepare your Anus Cersei Lanister, You Gonna Die"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                    android:textColor="#2d2d2d"
                    android:textAlignment="center"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAlignment="center"
                    android:text="@string/emilia"
                    android:textColor="@color/secondary_text"
                    android:layout_marginTop="10dp"
                    />

            </LinearLayout>

        </android.support.design.widget.CoordinatorLayout>

    </android.support.v7.widget.CardView>

    <ListView
        android:id="@+id/post_comments"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    </ListView>

    </LinearLayout>
</ScrollView>
</code>```

答:
Use android:fillViewport="true" to your ScrollView. ListView that located inside ScrollView works properly.</p>

```<code><ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
</code>```

Body:
I have this activity design, which shows a card view inside a scrollView, But under that cardview I need to put a listview or recyclerview. The problem is that I need the scroll of that list to coordinate with the main scroll. Osea that when lower in the content the cardview will disappear and the list of the recyclerview or listview will be crossed.

I need all the content to respond to the main scroll to show up and disappear after titlebar, Which should I change or redesign?

        <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        app:cardElevation="5dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/post_coordinator"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/post_bg"
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:scaleType="fitXY"
                android:src="@drawable/default_profile" />

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom"
                android:layout_marginLeft="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />

            <com.mikhaellopez.circularimageview.CircularImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:layout_anchor="@id/post_bg"
                app:layout_anchorGravity="center_horizontal|bottom"
                android:src="@drawable/profile"
                app:civ_border_color="#FFF"
                app:civ_border_width="3dp"
                />

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="normal"
                android:src="@drawable/ic_hot_black"
                app:layout_anchorGravity="bottom|end"
                android:layout_marginRight="16dp"
                app:layout_anchor="@id/post_bg"
                android:tint="#FFF"
                />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_marginTop="205dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingBottom="50dp"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Prepare your Anus Cersei Lanister, You Gonna Die"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                    android:textColor="#2d2d2d"
                    android:textAlignment="center"
                    />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAlignment="center"
                    android:text="@string/emilia"
                    android:textColor="@color/secondary_text"
                    android:layout_marginTop="10dp"
                    />

            </LinearLayout>

        </android.support.design.widget.CoordinatorLayout>

    </android.support.v7.widget.CardView>

    <ListView
        android:id="@+id/post_comments"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
    </ListView>

    </LinearLayout>
</ScrollView>

Body:
Use android:fillViewport="true" to your ScrollView. ListView that located inside ScrollView works properly.

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">


问:
problems with Firebase .childChanged in Swift
I use Firebase to hold a users profile info. Because you cannot listen to a Storage Reference, I added a child to the database that changes every time the user changes their profile pic (just a randomly generated uuidString . I verified that it is indeed changing in firebase and the new child is in the same location as the others. whenever a user changes their info, a user that is viewing that profile should see the change so I tested this. Even though the child is changing, there is no change to the profile pic. However, if the user changes another piece of info, I tested it with bio, the profile will update, along with the latest profile pic. A mid-debug version of the code is below:

```<code>    let ref = DatabaseReference.allUsers.reference()
    let query = ref.queryOrdered(byChild: "uid").queryEqual(toValue: (user.uid))

    query.observe(.childChanged, with: { snapshot in
        let user = User(dictionary: snapshot.value as! [String : Any])
        self.user = user
        self.bio.text = user.bio
        self.user?.fullName = user.fullName
        self.user?.instagram = user.instagram
        self.user?.facebook = user.facebook
        self.user?.phone = user.phone
        self.user?.email = user.email

    })

    //let ref2 = DatabaseReference.users(uid: user.uid).reference()
    //let query2 = ref2.child("updatePic")

    query.observe(.childChanged, with: { snapshot in
        let user = User(dictionary: snapshot.value as! [String : Any])

        self.user?.downloadProfilePicture { [weak self] (image, error) in
            self?.profilePicture.image = image
            let profilePictureKey = "\(user.uid)-headerImage"
            self?.cache?.setObject(image, forKey: profilePictureKey)
        }
    })
</code>```

So far I've scratched my head because I have no idea what I could be missing. Basically, it's not recognizing that the child was changed even though I am watching it change before my eyes. Any ideas?

update: Is it possible that the profile photo has not finished being updated at the time the childChanged is triggered and therefore the same photo is being downloaded? this is my current code for changing the photo:

```<code>    extension FIRImage {
func saveProfileImage(_ userUID: String, _ completion: @escaping (Error?) -> Void) {
    let resizedImage = image.resized()
    let imageData = UIImageJPEGRepresentation(resizedImage, 1.0)

    ref = StorageReference.profileImages.reference().child(userUID)
    downloadLink = ref.description

    ref.put(imageData!, metadata: nil) {
        (metaData, error) in
        completion(error)
    }
    updateProfilePic(userUID)
    }
    func updateProfilePic(_ userUID: String) {
    var randomString = UUID().uuidString
    let ref = DatabaseReference.users(uid: userUID).reference()
    ref.child("updatePic").setValue(randomString)
}
</code>```

答:
I'm not entirely sure if this is the cause of your problem, but you should definitely consider storing your users in a structure like this:

```<code>users: {
  uid1: {
    name: "Sudacris"
    profilePic: "https://www.gravatar.com/avatar/60fa08515b157ef927d885a4217c0f76?s=32&d=identicon&r=PG&f=1"
  },
  uid1: {
    name: "Frank van Puffelen"
    profilePic: "https://www.gravatar.com/avatar/12d378e6a9788ab9c94bbafe242b82b4?s=48&d=identicon&r=PG"
  }
}
</code>```

This allows you to look up a specific user without needing a query. You just do a direct lookup:

```<code>let ref = DatabaseReference.allUsers.reference()
let userRef = ref.child(user.uid)

userRef.observe(.value, with: { snapshot in
   let user = User(dictionary: snapshot.value as! [String : Any])
   ...
</code>```

Body:
I use Firebase to hold a users profile info. Because you cannot listen to a Storage Reference, I added a child to the database that changes every time the user changes their profile pic (just a randomly generated uuidString . I verified that it is indeed changing in firebase and the new child is in the same location as the others. whenever a user changes their info, a user that is viewing that profile should see the change so I tested this. Even though the child is changing, there is no change to the profile pic. However, if the user changes another piece of info, I tested it with bio, the profile will update, along with the latest profile pic. A mid-debug version of the code is below:

    let ref = DatabaseReference.allUsers.reference()
    let query = ref.queryOrdered(byChild: "uid").queryEqual(toValue: (user.uid))

    query.observe(.childChanged, with: { snapshot in
        let user = User(dictionary: snapshot.value as! [String : Any])
        self.user = user
        self.bio.text = user.bio
        self.user?.fullName = user.fullName
        self.user?.instagram = user.instagram
        self.user?.facebook = user.facebook
        self.user?.phone = user.phone
        self.user?.email = user.email

    })

    //let ref2 = DatabaseReference.users(uid: user.uid).reference()
    //let query2 = ref2.child("updatePic")

    query.observe(.childChanged, with: { snapshot in
        let user = User(dictionary: snapshot.value as! [String : Any])

        self.user?.downloadProfilePicture { [weak self] (image, error) in
            self?.profilePicture.image = image
            let profilePictureKey = "\(user.uid)-headerImage"
            self?.cache?.setObject(image, forKey: profilePictureKey)
        }
    })

So far I've scratched my head because I have no idea what I could be missing. Basically, it's not recognizing that the child was changed even though I am watching it change before my eyes. Any ideas?

update: Is it possible that the profile photo has not finished being updated at the time the childChanged is triggered and therefore the same photo is being downloaded? this is my current code for changing the photo:

    extension FIRImage {
func saveProfileImage(_ userUID: String, _ completion: @escaping (Error?) -> Void) {
    let resizedImage = image.resized()
    let imageData = UIImageJPEGRepresentation(resizedImage, 1.0)

    ref = StorageReference.profileImages.reference().child(userUID)
    downloadLink = ref.description

    ref.put(imageData!, metadata: nil) {
        (metaData, error) in
        completion(error)
    }
    updateProfilePic(userUID)
    }
    func updateProfilePic(_ userUID: String) {
    var randomString = UUID().uuidString
    let ref = DatabaseReference.users(uid: userUID).reference()
    ref.child("updatePic").setValue(randomString)
}

Body:
I'm not entirely sure if this is the cause of your problem, but you should definitely consider storing your users in a structure like this:

users: {
  uid1: {
    name: "Sudacris"
    profilePic: "https://www.gravatar.com/avatar/60fa08515b157ef927d885a4217c0f76?s=32&d=identicon&r=PG&f=1"
  },
  uid1: {
    name: "Frank van Puffelen"
    profilePic: "https://www.gravatar.com/avatar/12d378e6a9788ab9c94bbafe242b82b4?s=48&d=identicon&r=PG"
  }
}

This allows you to look up a specific user without needing a query. You just do a direct lookup:

let ref = DatabaseReference.allUsers.reference()
let userRef = ref.child(user.uid)

userRef.observe(.value, with: { snapshot in
   let user = User(dictionary: snapshot.value as! [String : Any])
   ...


问:
Create date from date time and time zone Javascript
Given inputs

1) Datetime : day month year hh and mins

2) Timezone

How to create a Javascript date object of a specific time zone or date in UTC ?

Also how to convert this date time to any other timezone.

Is there any package in angular that can do this.

答:
So I do it like this:

```<code>var offset = -5.0; // my servers UTC offset

var clientDate = new Date();
var utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000);

var serverDate = new Date(utc + (3600000 * offset));
var c = $.datepicker.formatDate('mm/dd/yy', serverDate);
</code>```

In the last line, I use the jQuery (commonly called BootStrap) datepicker to format the date for me.

The key here is offset which is the hours offset from UTC time.

In Angular you can use dateFilter

```<code> new Date(dateFilter(minDate, 'yyyy-MM-dd\'T\'00:00:00', timezone));
</code>```

Body:
So I do it like this:

var offset = -5.0; // my servers UTC offset

var clientDate = new Date();
var utc = clientDate.getTime() + (clientDate.getTimezoneOffset() * 60000);

var serverDate = new Date(utc + (3600000 * offset));
var c = $.datepicker.formatDate('mm/dd/yy', serverDate);

In the last line, I use the jQuery (commonly called BootStrap) datepicker to format the date for me.

The key here is offset which is the hours offset from UTC time.

In Angular you can use dateFilter

 new Date(dateFilter(minDate, 'yyyy-MM-dd\'T\'00:00:00', timezone));


问:
casting to (id<protocol>) to guarantee a property is there
if i have a number of classes with something like

```<code>@property (nonatomic, retain) NSString* myString;
</code>```

and want to access that property in a object that is one of these classes (but don't know which so it is type id), i obviously get "request for member 'myString' in something not a structure or union" error.

so if each of these classes conforms to :

```<code>@protocol myProtocol <NSObject>

@required

@property (nonatomic, retain) NSString* myString;

@end
</code>```

then i cast like this to get the property:

```<code>(id<myProtocol>)anObject.myString
</code>```

why doesn't this work? i still get the same error.

答:
ignore this.. turns out just to need more brackets:</p>

```<code>((id<myProtocol>)anObject).myString
</code>```

Body:
if i have a number of classes with something like

@property (nonatomic, retain) NSString* myString;

and want to access that property in a object that is one of these classes (but don't know which so it is type id), i obviously get "request for member 'myString' in something not a structure or union" error.

so if each of these classes conforms to :

@protocol myProtocol <NSObject>

@required

@property (nonatomic, retain) NSString* myString;

@end

then i cast like this to get the property:

(id<myProtocol>)anObject.myString

why doesn't this work? i still get the same error.

Body:
ignore this.. turns out just to need more brackets:

((id<myProtocol>)anObject).myString


问:
SQL: Efficiently Calculate Time Spent
Given a list of event timestamps, how do you calculate the "time spent"? The "time spent" is the sum of the time intervals between each timestamp, ignoring intervals above a certain threshold, e.g. 1 minute, during which the user was probably inactive.

I tried something like this:

```<code>select sum(finish - start)
from (select start.time as start,
             finish.time as finish
      from events start, events finish
      where start.time < finish.time and
            finish.time - start.time < interval '1 minute'
      group by start.time) as intervals;
</code>```

But this proved vastly inefficient and never terminated.

答:
```<code>select sum(time-lag(time) over (order by time)) from events
</code>```

I'm not sure why you're joining events to itself in that fashion but that's most likely why the query is running forever, not because of the trivial aggregate calculation.

Title: SQL: Efficiently Calculate Time Spent

Body:
Given a list of event timestamps, how do you calculate the "time spent"? The "time spent" is the sum of the time intervals between each timestamp, ignoring intervals above a certain threshold, e.g. 1 minute, during which the user was probably inactive.

I tried something like this:

select sum(finish - start)
from (select start.time as start,
             finish.time as finish
      from events start, events finish
      where start.time < finish.time and
            finish.time - start.time < interval '1 minute'
      group by start.time) as intervals;

But this proved vastly inefficient and never terminated.

Body:
select sum(time-lag(time) over (order by time)) from events

I'm not sure why you're joining events to itself in that fashion but that's most likely why the query is running forever, not because of the trivial aggregate calculation.


问:
How to convert a NSString to long double?
I am dealing with a long double value that can have huge values.

At one time I have this number represented as NSString and I need to convert it to long double. I see that the only API I have is

```<code>[myString doubleValue];
</code>```

I don't see a longDoubleValue.

Trying to convert this number using doubleValue...

```<code>long double x = (long double)[@"3765765765E933" doubleValue];
</code>```

gives me inf and the number in question is a legit long double value, as these numbers can go up to 1.18973149535723176502E+4932.

How do I do that?

答:
You could probably do:

```<code>long double s = strtold(myString.UTF8String, NULL);
</code>```

but if sizeof(long double) is the same as sizeof(double) as mag_zbc says, you might still get Inf.

If you want to go the pow() route, there is powl() which takes and returns long doubles.

Body:
I am dealing with a long double value that can have huge values.

At one time I have this number represented as NSString and I need to convert it to long double. I see that the only API I have is

[myString doubleValue];

I don't see a longDoubleValue.

Trying to convert this number using doubleValue...

long double x = (long double)[@"3765765765E933" doubleValue];

gives me inf and the number in question is a legit long double value, as these numbers can go up to 1.18973149535723176502E+4932.

How do I do that?

Body:
You could probably do:

long double s = strtold(myString.UTF8String, NULL);

but if sizeof(long double) is the same as sizeof(double) as mag_zbc says, you might still get Inf.

If you want to go the pow() route, there is powl() which takes and returns long doubles.


问:
Formatting SQL Server Query Output
I like to get the SQL Server query output in the following way. Currently my output is:

```<code>Class | Student ID | Student Name
------+------------+---------------
121        S1          Test 1
121        S2          Test 2
500        S22         Test a
500        S23         Test b
</code>```

But I want the data output in the following way -

```<code>Class: 121
--------------------------------

Student ID | Student Name
-----------+---------------
S1            Test 1
S2            Test 2

Class: 500
--------------------------------

Student ID | Student Name
-----------+---------------
S22            Test a
S23            Test b
</code>```

Could someone help me how can I achieve these?

Thanks

答:
While I would agree SQL isn't the place to do your formatting.... sometimes you get stuck....

This Code

```<code>select '121' as Class,       'S1  ' as [Student ID],        'Test 1' as [Student Name] into #test
union select '121', 'S2  ', 'Test 2'
union select '500', 'S22 ', 'Test a'
union select '500', 'S23 ', 'Test b'

;
WITH class
AS (
    SELECT DISTINCT class
    FROM #test
    )
    ,student
AS (
    SELECT class
        ,(
            SELECT STUFF((
                        SELECT CHAR(13) + t.[Student ID] + space(len('Student ID | ') - len(t.[Student ID])) + [Student Name]
                        FROM #Test t
                        WHERE t.[class] = class.[class]
                        FOR XML PATH('')
                            ,type
                        ).value('.[1]', 'nvarchar(max)'), 1, 1, '')
            ) AS info
    FROM class
    )
    ,theoutput
AS (
    SELECT 'Class: ' + class + CHAR(13) + '------------------------' + CHAR(13) + 'Student ID | Student Name' + CHAR(13) + info + CHAR(13) + CHAR(13) AS txt
    FROM student c
    )
SELECT STUFF((
            SELECT CHAR(13) + txt
            FROM theoutput
            FOR XML PATH('')
                ,type
            ).value('.[1]', 'nvarchar(max)'), 1, 1, '')
</code>```

Will Produce

```<code>Class: 121
------------------------
Student ID | Student Name
S1            Test 1
S2            Test 2

Class: 500
------------------------
Student ID | Student Name
S22          Test a
S23          Test b
</code>```

Title: Formatting SQL Server Query Output

Body:
I like to get the SQL Server query output in the following way. Currently my output is:

Class | Student ID | Student Name
------+------------+---------------
121        S1          Test 1
121        S2          Test 2
500        S22         Test a
500        S23         Test b

But I want the data output in the following way -

Class: 121
--------------------------------

Student ID | Student Name
-----------+---------------
S1            Test 1
S2            Test 2

Class: 500
--------------------------------

Student ID | Student Name
-----------+---------------
S22            Test a
S23            Test b

Could someone help me how can I achieve these?

Thanks

Body:
While I would agree SQL isn't the place to do your formatting.... sometimes you get stuck....

This Code

select '121' as Class,       'S1  ' as [Student ID],        'Test 1' as [Student Name] into #test
union select '121', 'S2  ', 'Test 2'
union select '500', 'S22 ', 'Test a'
union select '500', 'S23 ', 'Test b'

;
WITH class
AS (
    SELECT DISTINCT class
    FROM #test
    )
    ,student
AS (
    SELECT class
        ,(
            SELECT STUFF((
                        SELECT CHAR(13) + t.[Student ID] + space(len('Student ID | ') - len(t.[Student ID])) + [Student Name]
                        FROM #Test t
                        WHERE t.[class] = class.[class]
                        FOR XML PATH('')
                            ,type
                        ).value('.[1]', 'nvarchar(max)'), 1, 1, '')
            ) AS info
    FROM class
    )
    ,theoutput
AS (
    SELECT 'Class: ' + class + CHAR(13) + '------------------------' + CHAR(13) + 'Student ID | Student Name' + CHAR(13) + info + CHAR(13) + CHAR(13) AS txt
    FROM student c
    )
SELECT STUFF((
            SELECT CHAR(13) + txt
            FROM theoutput
            FOR XML PATH('')
                ,type
            ).value('.[1]', 'nvarchar(max)'), 1, 1, '')

Will Produce

Class: 121
------------------------
Student ID | Student Name
S1            Test 1
S2            Test 2

Class: 500
------------------------
Student ID | Student Name
S22          Test a
S23          Test b


问:
Clicking through Positioned Fontawesome Icon with CSS
I want that the font awesome icon should only appear on the hover of the image and that too over the image: top right of the image, but I am unable to accomplish this. I have created a sample code snippet replicating the issue.

// Get the modal
var modal = document.getElementById('lazy-mymodal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('lazyimg-popup');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the  element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on  (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#lazyimg-popup {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#lazyimg-popup:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 30px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 100%;
    max-width: 1100px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    max-width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)}
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)}
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

.lazyimg i {
    top: 50%;
    position: absolute;
    left: 0;
    right: 0;
    transform: translateY(-50%);
}</code>```

                          ×

```
</div>
</div>
</p>

```
```

the above neeeds to be on hover, but not on the click. Just like the
  image is clickable and enlarges into modal boxes the fontawesome icon
  on click should also enlarge the same image in the modal box.

答:
Add pointer-events: none to the close button and it'll allow you to click and hover through the icon.

More info

// Get the modal
var modal = document.getElementById('lazy-mymodal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('lazyimg-popup');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the  element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on  (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.lazyimg {
    position: relative;
    width: 500px;
    height: 300px;
}

#lazyimg-popup {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
    width: 100%;
    height: 100%;
}

.full {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    transform: translateY(-50%);
}

.lazyimg:hover .full {
    display: block;
}

#lazyimg-popup:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 30px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 100%;
    max-width: 1100px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    max-width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)}
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)}
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}</code>```

        ×

```

Body:
I want that the font awesome icon should only appear on the hover of the image and that too over the image: top right of the image, but I am unable to accomplish this. I have created a sample code snippet replicating the issue.

// Get the modal
var modal = document.getElementById('lazy-mymodal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('lazyimg-popup');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the  element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on  (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

#lazyimg-popup {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#lazyimg-popup:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 30px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 100%;
    max-width: 1100px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    max-width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)}
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)}
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

.lazyimg i {
    top: 50%;
    position: absolute;
    left: 0;
    right: 0;
    transform: translateY(-50%);
}

                          ×

the above neeeds to be on hover, but not on the click. Just like the
  image is clickable and enlarges into modal boxes the fontawesome icon
  on click should also enlarge the same image in the modal box.

Body:
Add pointer-events: none to the close button and it'll allow you to click and hover through the icon.

More info

// Get the modal
var modal = document.getElementById('lazy-mymodal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('lazyimg-popup');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

.lazyimg {
    position: relative;
    width: 500px;
    height: 300px;
}

#lazyimg-popup {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
    width: 100%;
    height: 100%;
}

.full {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    transform: translateY(-50%);
}

.lazyimg:hover .full {
    display: block;
}

#lazyimg-popup:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 30px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 100%;
    max-width: 1100px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    max-width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {
    -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)}
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)}
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #000000;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

    <div class="lazyimg">
        <img id="lazyimg-popup" src="http://moimir.org/wp-content/uploads/2015/08/1.jpg" alt="Trolltunga, Norway" width="700px" height="auto">
        <i class="fa fa-expand full" aria-hidden="true" style="pointer-events: none;"></i>
    </div>

    <!-- The Modal -->
    <div id="lazy-mymodal" class="modal">
        <img class="modal-content" id="img01">
        <span class="img-close">&times;</span>
        <div id="caption"></div>
    </div>


问:
rails EXECJS runtime error
Hello I am getting a ExecJS::RuntimeError in Demo#index

Below is the line 6 that was highlighted and below that is my full trace.  Can someone either A: point me in the right direction to debug this as well as a good reference for debugging rails.  I am new to rails.  My guess is i'm missing a gem (i checked to make sure turbolinks was there) or something in turbolinks is wrong.  I'm using Rails 4 using rails installer (after updating gems and rails and bundle install etc.).

Below is also my gemfile

Line 6 is highlighted:

```<code><%= javascript_include_tag "application", "data-turbolinks-track" => true %>
</code>```

Below is my full trace:

```<code>execjs (1.4.0) lib/execjs/external_runtime.rb:142:in `exec_runtime'
execjs (1.4.0) lib/execjs/external_runtime.rb:28:in `block in exec'
execjs (1.4.0) lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
execjs (1.4.0) lib/execjs/external_runtime.rb:27:in `exec'
execjs (1.4.0) lib/execjs/external_runtime.rb:19:in `eval'
execjs (1.4.0) lib/execjs/external_runtime.rb:33:in `call'
coffee-script (2.2.0) lib/coffee_script.rb:57:in `compile'
tilt (1.4.1) lib/tilt/coffee.rb:46:in `evaluate'
tilt (1.4.1) lib/tilt/template.rb:103:in `render'
sprockets (2.10.0) lib/sprockets/context.rb:197:in `block in evaluate'
sprockets (2.10.0) lib/sprockets/context.rb:194:in `each'
sprockets (2.10.0) lib/sprockets/context.rb:194:in `evaluate'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:12:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:395:in `circular_call_protection'
sprockets (2.10.0) lib/sprockets/base.rb:373:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:105:in `each'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:97:in `build_required_assets'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:16:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:395:in `circular_call_protection'
sprockets (2.10.0) lib/sprockets/base.rb:373:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/bundled_asset.rb:16:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:377:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:377:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/environment.rb:75:in `find_asset'
sprockets (2.10.0) lib/sprockets/base.rb:295:in `[]'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:141:in `lookup_asset_for_path'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:90:in `block in javascript_include_tag'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:89:in `map'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:89:in `javascript_include_tag'
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__93722521_39251544'
actionpack (4.0.0.rc1) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.0.rc1) lib/action_view/template.rb:141:in `render'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.0.rc1) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.0.rc1) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.0.rc1) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.0.rc1) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (4.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.0.rc1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.0.rc1) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:422:in `_run__842584183__process_action__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0.rc1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:654:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0.rc1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0.rc1) lib/active_record/migration.rb:366:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:392:in `_run__736096468__call__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0.rc1) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.rc1) lib/rails/engine.rb:511:in `call'
railties (4.0.0.rc1) lib/rails/application.rb:96:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
</code>```

GEMFILE Below for this project

```<code>source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc1'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]
</code>```

答:
This worked for me. This problem occurs mainly in Windows OS. Force your Coffee Script Source version to 1.8.0. Higher versions are not supported properly.

Change or add this to your gem file:

```<code>gem 'coffee-script-source', '1.8.0'
</code>```

then update the coffee-script-source bundle

```<code>bundle update coffee-script-source
</code>```

This should fix the issue.

Title: rails EXECJS runtime error

Body:
Hello I am getting a ExecJS::RuntimeError in Demo#index

Below is the line 6 that was highlighted and below that is my full trace.  Can someone either A: point me in the right direction to debug this as well as a good reference for debugging rails.  I am new to rails.  My guess is i'm missing a gem (i checked to make sure turbolinks was there) or something in turbolinks is wrong.  I'm using Rails 4 using rails installer (after updating gems and rails and bundle install etc.).

Below is also my gemfile

Line 6 is highlighted:

<%= javascript_include_tag "application", "data-turbolinks-track" => true %>

Below is my full trace:

execjs (1.4.0) lib/execjs/external_runtime.rb:142:in `exec_runtime'
execjs (1.4.0) lib/execjs/external_runtime.rb:28:in `block in exec'
execjs (1.4.0) lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
execjs (1.4.0) lib/execjs/external_runtime.rb:27:in `exec'
execjs (1.4.0) lib/execjs/external_runtime.rb:19:in `eval'
execjs (1.4.0) lib/execjs/external_runtime.rb:33:in `call'
coffee-script (2.2.0) lib/coffee_script.rb:57:in `compile'
tilt (1.4.1) lib/tilt/coffee.rb:46:in `evaluate'
tilt (1.4.1) lib/tilt/template.rb:103:in `render'
sprockets (2.10.0) lib/sprockets/context.rb:197:in `block in evaluate'
sprockets (2.10.0) lib/sprockets/context.rb:194:in `each'
sprockets (2.10.0) lib/sprockets/context.rb:194:in `evaluate'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:12:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:395:in `circular_call_protection'
sprockets (2.10.0) lib/sprockets/base.rb:373:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:105:in `each'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:97:in `build_required_assets'
sprockets (2.10.0) lib/sprockets/processed_asset.rb:16:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:374:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:395:in `circular_call_protection'
sprockets (2.10.0) lib/sprockets/base.rb:373:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/bundled_asset.rb:16:in `initialize'
sprockets (2.10.0) lib/sprockets/base.rb:377:in `new'
sprockets (2.10.0) lib/sprockets/base.rb:377:in `build_asset'
sprockets (2.10.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets (2.10.0) lib/sprockets/caching.rb:58:in `cache_asset'
sprockets (2.10.0) lib/sprockets/index.rb:93:in `build_asset'
sprockets (2.10.0) lib/sprockets/base.rb:287:in `find_asset'
sprockets (2.10.0) lib/sprockets/index.rb:61:in `find_asset'
sprockets (2.10.0) lib/sprockets/environment.rb:75:in `find_asset'
sprockets (2.10.0) lib/sprockets/base.rb:295:in `[]'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:141:in `lookup_asset_for_path'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:90:in `block in javascript_include_tag'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:89:in `map'
sprockets-rails (2.0.0) lib/sprockets/rails/helper.rb:89:in `javascript_include_tag'
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__93722521_39251544'
actionpack (4.0.0.rc1) lib/action_view/template.rb:143:in `block in render'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:161:in `instrument'
actionpack (4.0.0.rc1) lib/action_view/template.rb:141:in `render'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (4.0.0.rc1) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionpack (4.0.0.rc1) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionpack (4.0.0.rc1) lib/action_view/renderer/renderer.rb:23:in `render'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:127:in `_render_template'
actionpack (4.0.0.rc1) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:120:in `render_to_body'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.0.rc1) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (4.0.0.rc1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.0.rc1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.0.rc1) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.0.rc1) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:422:in `_run__842584183__process_action__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0.rc1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:654:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0.rc1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0.rc1) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0.rc1) lib/active_record/migration.rb:366:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:392:in `_run__736096468__call__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0.rc1) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.rc1) lib/rails/engine.rb:511:in `call'
railties (4.0.0.rc1) lib/rails/application.rb:96:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

GEMFILE Below for this project

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc1'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

Body:
This worked for me. This problem occurs mainly in Windows OS. Force your Coffee Script Source version to 1.8.0. Higher versions are not supported properly.

Change or add this to your gem file:

gem 'coffee-script-source', '1.8.0'

then update the coffee-script-source bundle

bundle update coffee-script-source

This should fix the issue.


问:
Different between WAMP and web hosting?
I have planned to learn WordPress. I just want to know what will be core difference between functionality and features if I install it on WAMP that is local host and a web server?

My preference was WAMP but I am not yet sure.

答:
When doing web development on your local machine using a localhost, there are a few things you need to be aware of.

You need to ensure that it is same as the versions of the products on your actual web server or close to it (MySql, Apache, Php, etc.)

You need to be aware of the urls you use compared to the urls when deployed to the server (in Wordpress, you need to edit the main web urls in your mysql dump file before uploading to your webhosting)

WAMP actually is easy to configure, other alternative is XAMPP for local development

Wordpress updates a lot and usually so is there requirements, so in order for wordpress functions to work properly, your local server must be updated to their requirements or at least close to it

Title: Different between WAMP and web hosting?


问:
cant fetch data from mysql
`

```<code>                $sql = "SELECT * FROM tbl_feedback where status='Pending'";
                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                        $i=1;

                // output data of each row
                while($row = $result->fetch_assoc()) {
                $loc=$row['location'];
                $inci=$row['incident'];
                $sol=$row['solution'];

                echo "<tr>
                    <td>
                    <a href=editrecipient.php?feed_id=" . $row['feed_id'] . "><button type=button class='btn btn-info btn-xs' data-toggle='tooltip' data-placement='left' title='Edit'><i class='fa fa-pencil'></i></button></a>
                    <a href=recprofile.php?feed_id=" . $row['feed_id'] . "><button type=button class='btn btn-danger btn-xs' data-toggle='tooltip' data-placement='right' title='Delete'><i class='fa fa-trash'></i></button></a>
                    </td>
                    <td>$i</td>
                    <td>$loc</td>
                    <td>$inci</td>
                    <td>$sol</td>
                    <td><button type='button' class='btn btn-default btn-xs'>Post Feedback</button></td>

              </tr>";
              $i++;
                }
                    } else {
                    echo "0 results";
                    }
                $conn->close();

              ?>
</code>```

`
this are the error messages
Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 222

Notice: Trying to get property of non-object in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 224
0 results
Warning: mysqli::close(): Couldn't fetch mysqli in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 252

答:
I believe there is some rule about adding the close statement right after the query, but i can't seem to find it. </p>

<p>Try adding the $result->close(); right after the sql executes. </p>

Title: cant fetch data from mysql

Body:
`

                $sql = "SELECT * FROM tbl_feedback where status='Pending'";
                $result = $conn->query($sql);

                if ($result->num_rows > 0) {
                        $i=1;

                // output data of each row
                while($row = $result->fetch_assoc()) {
                $loc=$row['location'];
                $inci=$row['incident'];
                $sol=$row['solution'];

                echo "

                    <button type=button class='btn btn-info btn-xs' data-toggle='tooltip' data-placement='left' title='Edit'></button>
                    <button type=button class='btn btn-danger btn-xs' data-toggle='tooltip' data-placement='right' title='Delete'></button>

                    $i
                    $loc
                    $inci
                    $sol
                    <button type='button' class='btn btn-default btn-xs'>Post Feedback</button>

";
              $i++;
                }
                    } else {
                    echo "0 results";
                    }
                $conn->close();

              ?>

`
this are the error messages
Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 222

Notice: Trying to get property of non-object in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 224
0 results
Warning: mysqli::close(): Couldn't fetch mysqli in C:\xampp2\htdocs\Sahana\residentfeedback.php on line 252

Body:
I believe there is some rule about adding the close statement right after the query, but i can't seem to find it.

Try adding the $result->close(); right after the sql executes.


问:
Unzip or inflate php://input stream?
I'm trying to unzip a zip file directly from the php://input stream.  I'm running Laravel Homestead, PHP 7.1.3-3+deb.sury.org~xenial+1, with an endpoint at myproject.app/upload, here is the curl command:

```<code>curl --request POST \
  --url 'http://myproject.app/upload' \
  --data-binary "@myfile.zip" \
</code>```

Here is a list of all the methods I've tried, which all fail:

```<code>dd(file_get_contents('compress.zlib://php://input'));
</code>```

file_get_contents(): cannot represent a stream of type Input as a File Descriptor

```<code>$fh = fopen('php://input', 'rb');

stream_filter_append($fh, 'zlib.inflate', STREAM_FILTER_READ, array('window'=>15));

$data = '';

while (!feof($fh)) {
    $data .= fread($fh, 8192);
}

dd($data);
</code>```

""

```<code>$zip = new ZipArchive;

$zip->open('php://input');
$zip->extractTo(storage_path() . '/' . 'myfile');
$zip->close();
</code>```

ZipArchive::extractTo(): Invalid or uninitialized Zip object

Here are all the links I've found on the subject:

http://php.net/manual/en/wrappers.php#83220

http://php.net/manual/en/wrappers.php#109657

http://php.net/manual/en/wrappers.compression.php#118461

https://secure.phabricator.com/rP42566379dc3c4fd01a73067215da4a7ca18f9c17

https://arjunphp.com/how-to-unpack-a-zip-file-using-php/

I'm beginning to think that it's not possible to operate on streams with PHP's built-in zip functionality.  The overhead and complexity of writing temporary files would be pretty disappointing.  Does anyone know how to do this, or is it a bug?

答:
After more research, I discovered the answer, but it's not satisfactory.  Due to one of the great blunders of the modern world, gzip and zip are not the same format.  gzip encodes a single file (that's why we often see tar.gz), while zip encodes files and folders.  I was trying to upload a zip file and decode it with gzip, which doesn't work.  More info:

https://stackoverflow.com/a/20765054/539149

https://stackoverflow.com/a/1579506/539149

The other part of this issue is that PHP neglected to provide a stream filter for gzip:

https://stackoverflow.com/a/11926679/539149

So even though gzopen('php://temp', 'rb') works, gzopen('php://input', 'rb') does not because the input stream is not rewindable.  This makes it impossible to operate on an in-memory stream, because there is no way to write data to a stream and then read unzipped data on a separate gzip connection to that stream.  Which means the following code does not work:

```<code>$input = fopen("php://input", "rb");
$temp = fopen("php://temp", "rb+");
stream_copy_to_stream($input, $temp);
rewind($temp);
dd(stream_get_contents(gzopen('php://temp', 'rb')));
</code>```

People have attempted various workarounds, but they all do bit fiddling:

http://php.net/manual/en/function.gzopen.php#105676

http://php.net/manual/en/function.gzdecode.php#112200

I did manage to get a pure in-memory solution to work, but since it's not possible to use streams, a needless copy occurs:

```<code>// works (stream + string)
dd(gzdecode(file_get_contents('php://input')));
</code>```

```<code>// works (stream + file)
dd(stream_get_contents(gzopen(storage_path() . '/' . 'myfile.gz', 'rb')));

// works (stream + file)
dd(file_get_contents('compress.zlib://' . storage_path() . '/' . 'myfile.gz'));
</code>```

```<code>// doesn't work (stream)
dd(stream_get_contents(gzopen('php://input', 'rb')));

// doesn't work (stream + filter)
dd(file_get_contents('compress.zlib://php://input'));
</code>```

Without a working example, I have to assume that PHP's zip implementation is incomplete because it can't operate on streams.  If anyone has more information, I'm happy to revisit this.  Please post any examples or repositories that implement zipped uploads/downloads via streams, thanks!

Title: Unzip or inflate php://input stream?

Body:
I'm trying to unzip a zip file directly from the php://input stream.  I'm running Laravel Homestead, PHP 7.1.3-3+deb.sury.org~xenial+1, with an endpoint at myproject.app/upload, here is the curl command:

curl --request POST \
  --url 'http://myproject.app/upload' \
  --data-binary "@myfile.zip" \

Here is a list of all the methods I've tried, which all fail:

dd(file_get_contents('compress.zlib://php://input'));

file_get_contents(): cannot represent a stream of type Input as a File Descriptor

$fh = fopen('php://input', 'rb');

stream_filter_append($fh, 'zlib.inflate', STREAM_FILTER_READ, array('window'=>15));

$data = '';

while (!feof($fh)) {
    $data .= fread($fh, 8192);
}

dd($data);

""

$zip = new ZipArchive;

$zip->open('php://input');
$zip->extractTo(storage_path() . '/' . 'myfile');
$zip->close();

ZipArchive::extractTo(): Invalid or uninitialized Zip object

Here are all the links I've found on the subject:

http://php.net/manual/en/wrappers.php#83220

http://php.net/manual/en/wrappers.php#109657

http://php.net/manual/en/wrappers.compression.php#118461

https://secure.phabricator.com/rP42566379dc3c4fd01a73067215da4a7ca18f9c17

https://arjunphp.com/how-to-unpack-a-zip-file-using-php/

I'm beginning to think that it's not possible to operate on streams with PHP's built-in zip functionality.  The overhead and complexity of writing temporary files would be pretty disappointing.  Does anyone know how to do this, or is it a bug?

Body:
After more research, I discovered the answer, but it's not satisfactory.  Due to one of the great blunders of the modern world, gzip and zip are not the same format.  gzip encodes a single file (that's why we often see tar.gz), while zip encodes files and folders.  I was trying to upload a zip file and decode it with gzip, which doesn't work.  More info:

https://stackoverflow.com/a/20765054/539149

https://stackoverflow.com/a/1579506/539149

The other part of this issue is that PHP neglected to provide a stream filter for gzip:

https://stackoverflow.com/a/11926679/539149

So even though gzopen('php://temp', 'rb') works, gzopen('php://input', 'rb') does not because the input stream is not rewindable.  This makes it impossible to operate on an in-memory stream, because there is no way to write data to a stream and then read unzipped data on a separate gzip connection to that stream.  Which means the following code does not work:

$input = fopen("php://input", "rb");
$temp = fopen("php://temp", "rb+");
stream_copy_to_stream($input, $temp);
rewind($temp);
dd(stream_get_contents(gzopen('php://temp', 'rb')));

People have attempted various workarounds, but they all do bit fiddling:

http://php.net/manual/en/function.gzopen.php#105676

http://php.net/manual/en/function.gzdecode.php#112200

I did manage to get a pure in-memory solution to work, but since it's not possible to use streams, a needless copy occurs:

// works (stream + string)
dd(gzdecode(file_get_contents('php://input')));

// works (stream + file)
dd(stream_get_contents(gzopen(storage_path() . '/' . 'myfile.gz', 'rb')));

// works (stream + file)
dd(file_get_contents('compress.zlib://' . storage_path() . '/' . 'myfile.gz'));

// doesn't work (stream)
dd(stream_get_contents(gzopen('php://input', 'rb')));

// doesn't work (stream + filter)
dd(file_get_contents('compress.zlib://php://input'));

Without a working example, I have to assume that PHP's zip implementation is incomplete because it can't operate on streams.  If anyone has more information, I'm happy to revisit this.  Please post any examples or repositories that implement zipped uploads/downloads via streams, thanks!