问:
Pandas apply to dateframe produces '<built-in method values of ...'
I'm trying to build a GeoJSON object. My input is a csv with an address column, a lat column, and a lon column. I then created Shapely points out of the coordinates , buffer them out by a given radius, and get the dictionary of coordinates via the mapping option- so far, so good. Then, after referring to this question, I wrote the following function to get a Series of dictionaries:

    def make_geojson(row):
        return {'geometry':row['geom'], 'properties':{'address':row['address']}}

and I applied it thusly:

```<code>data['new_output'] = data.apply(make_geojson, axis=1)
</code>```

My resulting column is full of these: <built-in method values of dict object at 0x10...

The weirdest part is, when I directly call the function (i.e. make_geojson(data.loc[0]) I do in fact get the dictionary I'm expecting. Perhaps even weirder is that, when I call the functions I'm getting from the apply (e.g. data.output[0](), data.loc[0]['output']()) I get the equivalent of the following list:
    [data.loc[0]['geom'], {'address':data.loc[0]['address']}], i.e. the values (but not the keys) of the dictionary I'm trying to get.

For those of you playing along at home, here's a toy example:

```<code>from shapely.geometry import Point, mapping
import pandas as pd

def make_geojson(row):
    return {'geometry':row['geom'], 'properties':{'address':row['address']}}

data = pd.DataFrame([{'address':'BS', 'lat':34.017, 'lon':-117.959}, {'address':'BS2', 'lat':33.989, 'lon':-118.291}])
data['point'] = map(Point, zip(data['lon'], data['lat']))
data['buffer'] = data['point'].apply(lambda x: x.buffer(.1))
data['geom'] = data.buffer.apply(mapping)
data['output'] = data.apply(make_geojson, axis=1)
</code>```

答:
I got to this post because I ran into a similar issue, but when running a PySpark DataFrame instead of Pandas.

In case someone ends up here, like myself, I'll explain how I fixed it for a PySpark DataFrame.

The reason why I was getting the error (built-in method of Row object, in my case), was because my field name count was colliding with the inherited method count from python tuples (as seen here).

The solution was simply change the name of the field to something like my_count and it worked fine.

Body:
I'm trying to build a GeoJSON object. My input is a csv with an address column, a lat column, and a lon column. I then created Shapely points out of the coordinates , buffer them out by a given radius, and get the dictionary of coordinates via the mapping option- so far, so good. Then, after referring to this question, I wrote the following function to get a Series of dictionaries:

    def make_geojson(row):
        return {'geometry':row['geom'], 'properties':{'address':row['address']}}

and I applied it thusly:

data['new_output'] = data.apply(make_geojson, axis=1)

My resulting column is full of these: <built-in method values of dict object at 0x10...

The weirdest part is, when I directly call the function (i.e. make_geojson(data.loc[0]) I do in fact get the dictionary I'm expecting. Perhaps even weirder is that, when I call the functions I'm getting from the apply (e.g. data.output[0](), data.loc[0]['output']()) I get the equivalent of the following list:
    [data.loc[0]['geom'], {'address':data.loc[0]['address']}], i.e. the values (but not the keys) of the dictionary I'm trying to get.

For those of you playing along at home, here's a toy example:

from shapely.geometry import Point, mapping
import pandas as pd

def make_geojson(row):
    return {'geometry':row['geom'], 'properties':{'address':row['address']}}

data = pd.DataFrame([{'address':'BS', 'lat':34.017, 'lon':-117.959}, {'address':'BS2', 'lat':33.989, 'lon':-118.291}])
data['point'] = map(Point, zip(data['lon'], data['lat']))
data['buffer'] = data['point'].apply(lambda x: x.buffer(.1))
data['geom'] = data.buffer.apply(mapping)
data['output'] = data.apply(make_geojson, axis=1)


来源: stackexchange

问:
SOAP interceptor for .NET?
I'm working with an API and my results (CRUD) are getting mangled somehow in the return and .NET is throwing invalid XML errors.  Is there a setup trick to getting tcpmon to work with a debugger in Visual Studio?  Or is there another lightweight interceptor/analyzer that I can use to capture the XML?

Thanks.

答:
You might be able to use Microsoft's SOAP Toolkit. This little package includes a trace utility that can sit in between your client and web service to help with debugging the SOAP messages.

It's not free, but Altova's XML Spy also has a SOAP debugger.

Hope these help!

ContentLicense: CC BY-SA 2.5

Title: SOAP interceptor for .NET?


问:
XML request and response with fetch?
The Postal Service has an API that allows you to send an xml request with package weight, travel info, etc. It will return back an xml response.

How do I handle the xml response? I either need to parse the xml on the client-side, or more preferably, put the xml in a variable that I can send to my laravel backend for parsing.

Btw, I'm using react and laravel.

```<code>getPostagePrice = () => {
  fetch('http://production.shippingapis.com/ShippingApi.dll?API=RateV4&XML=<RateV4Request USERID="XXXXXXXXXXX"><PackageID="1ST"><Service>PRIORITY</Service><ZipOrigination>44106</ZipOrigination><ZipDestination>20770</ZipDestination><Pounds>1</Pounds><Ounces>8</Ounces><Container>NONRECTANGULAR</Container><Size>LARGE</Size><Width>15</Width><Length>30</Length><Height>15</Height><Girth>55</Girth></Package></RateV4Request>', {
       method: 'get',
   }).then((response) => {
       console.log(response.text());
   }).then(str => (new window.DOMParser()).parseFromString(str, "text/xml")
   ).then(data => console.log(data));
}
</code>```

答:
Response.text() returns a Promise, chain .then() to get the Promise value of .text() call.

If you are expecting a Promise to be returned from getPostagePrice function, return fetch() call from getPostagePrice() call.

```<code>getPostagePrice = () => {
  fetch('/path/to/server')
  .then(response => response.text())
  .then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
  .then(data => console.log(data));
}
</code>```

ContentLicense: CC BY-SA 3.0

Title: XML request and response with fetch?

Body:
The Postal Service has an API that allows you to send an xml request with package weight, travel info, etc. It will return back an xml response.

How do I handle the xml response? I either need to parse the xml on the client-side, or more preferably, put the xml in a variable that I can send to my laravel backend for parsing.

Btw, I'm using react and laravel.

getPostagePrice = () => {
  fetch('http://production.shippingapis.com/ShippingApi.dll?API=RateV4&XML=<RateV4Request USERID="XXXXXXXXXXX"><PackageID="1ST"><Service>PRIORITY</Service><ZipOrigination>44106</ZipOrigination><ZipDestination>20770</ZipDestination><Pounds>1</Pounds><Ounces>8</Ounces><Container>NONRECTANGULAR</Container><Size>LARGE</Size><Width>15</Width><Length>30</Length><Height>15</Height><Girth>55</Girth></Package></RateV4Request>', {
       method: 'get',
   }).then((response) => {
       console.log(response.text());
   }).then(str => (new window.DOMParser()).parseFromString(str, "text/xml")
   ).then(data => console.log(data));
}

Body:
Response.text() returns a Promise, chain .then() to get the Promise value of .text() call.

If you are expecting a Promise to be returned from getPostagePrice function, return fetch() call from getPostagePrice() call.

getPostagePrice = () => {
  fetch('/path/to/server')
  .then(response => response.text())
  .then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
  .then(data => console.log(data));
}


问:
Centering two divs in a wrapper
I am trying to center #left and #center inside #wrapper like this:

I am trying to get #center to be in the actual center of #wrapper both horizontally and vertically, and that #left will be in a slight margin to his left. How do I achieve that?

.c {
  border: 1px solid black;
  margin-left: auto;
  margin-right: auto;
  width: 60vw;
  height: 80vh;
  margin-top: 13vh;
}

#wrapper {
  height: 13vh;
  margin-top: 2vh;
  border: 1px solid blue;
}

#center {
  display: inline-block;
  width: 12vw;
  height: 10vh;
  border: 1px solid red;
}

#left {
  display: inline-block;
  width: 13vh;
  height: 13vh;
  border: 1px solid green;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="c">
  <div>content content content</div>
  <div>content content content</div>

  <div id="wrapper">
    <div id="left">left</div>
    <div id="center">center</div>

  </div>
  <div>content content content</div>
  <div>content content content</div></code>```

Jsfiddle: https://jsfiddle.net/y6r585jk/2/

答:
The only way i can satisfy this answer is with smart margins to center tthe center element..

I feel like there has to be a better way but I'm sure I have tried every combination.. lol

anyhow..

CSS - I added an extra wrapper for the right hand side..

margin-left: 5% on the #left
margin-left: 15% on wrapper_r

You can easily calculate the absolute center by adjusting these margins..

```<code>                          .c {
              border: 1px solid black;
              margin-left: auto;
              margin-right: auto;
              width: 60vw;
              height: 80vh;
              margin-top: 13vh;
            }

          .wrapper1 {
          display: flex;
          justify-content: flex-start;
          border: 1px solid blue;    }

        #left {
              margin-left: 5%;
        width: 13vw;
        height: 13vh;
        border: 1px solid green;
      }

          #wrapper_r {
      display: flex;
      align-items: center;
      margin-left:15%

          }
          #center {
          flex: 1;
        width: 12vw;
        height: 10vh;
        border: 1px solid red;
      }
</code>```

HTML

```<code>          <div class="c">
            <div>content content content</div>
            <div>content content content</div>

          <div class="wrapper1">
              <div id="left">left</div>

            <div id="wrapper_r">
              <div id="center">center</div>

            </div></div>

            <div>content content content</div>
            <div>content content content</div>
</code>```

I hope this works for you and I hope if there is a better solution with Flexbox It is posted here..

Your layout might be more suited or grid or a smarter mind :)

Title: Centering two divs in a wrapper

Body:
I am trying to center #left and #center inside #wrapper like this:

I am trying to get #center to be in the actual center of #wrapper both horizontally and vertically, and that #left will be in a slight margin to his left. How do I achieve that?

.c {
  border: 1px solid black;
  margin-left: auto;
  margin-right: auto;
  width: 60vw;
  height: 80vh;
  margin-top: 13vh;
}

#wrapper {
  height: 13vh;
  margin-top: 2vh;
  border: 1px solid blue;
}

#center {
  display: inline-block;
  width: 12vw;
  height: 10vh;
  border: 1px solid red;
}

#left {
  display: inline-block;
  width: 13vh;
  height: 13vh;
  border: 1px solid green;
}

content content content

content content content

left

center

content content content

content content content

Jsfiddle: https://jsfiddle.net/y6r585jk/2/

Body:
The only way i can satisfy this answer is with smart margins to center tthe center element..

I feel like there has to be a better way but I'm sure I have tried every combination.. lol

anyhow..

CSS - I added an extra wrapper for the right hand side..

margin-left: 5% on the #left
margin-left: 15% on wrapper_r

You can easily calculate the absolute center by adjusting these margins..

                          .c {
              border: 1px solid black;
              margin-left: auto;
              margin-right: auto;
              width: 60vw;
              height: 80vh;
              margin-top: 13vh;
            }

          .wrapper1 {
          display: flex;
          justify-content: flex-start;
          border: 1px solid blue;    }

        #left {
              margin-left: 5%;
        width: 13vw;
        height: 13vh;
        border: 1px solid green;
      }

          #wrapper_r {
      display: flex;
      align-items: center;
      margin-left:15%

          }
          #center {
          flex: 1;
        width: 12vw;
        height: 10vh;
        border: 1px solid red;
      }

HTML

          <div class="c">
            <div>content content content</div>
            <div>content content content</div>

          <div class="wrapper1">
              <div id="left">left</div>

            <div id="wrapper_r">
              <div id="center">center</div>

            </div></div>

            <div>content content content</div>
            <div>content content content</div>

I hope this works for you and I hope if there is a better solution with Flexbox It is posted here..

Your layout might be more suited or grid or a smarter mind :)


问:
how cam I make video.js work In the Nuxt
I am using video.js in the Nuxt frame, the video is work fine, but something are out of expectation,this is my nuxt.config.js:

```<code>head: {
    title: 'starter',
    meta: [
       { charset: 'utf-8' },
       { name: 'viewport', content: 'width=device-width, initial-scale=1' },
       { hid: 'description', name: 'description', content: 'Nuxt.js project'          }
    ],
    link: [
        { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
        { rel: 'stylesheet', href: 'http://vjs.zencdn.net/5.19/video-js.css' }
    ],
    script: [
        {src: 'http://vjs.zencdn.net/ie8/1.1/videojs-ie8.min.js'},
        {src: 'http://vjs.zencdn.net/5.19/video.js'}
    ]
}
</code>```

This is my vue:

```<code><video id="example_video_1" class="video-js vjs-default-skin" controls     preload="none" width="100%" height="300" data-setup="{}">
    <source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
</video>
</code>```

[Vue warn]:

```<code>The client-side rendered virtual DOM tree is not matching server-rendered     content. This is likely caused by incorrect HTML markup, for example nesting    block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.
</code>```

And video button bar is not work.
I would be happy for any kind of support.

答: If you replace data-setup="{}" by setup="{}" in the <video> element, this warning will disappear.

Body:
I am using video.js in the Nuxt frame, the video is work fine, but something are out of expectation,this is my nuxt.config.js:

head: {
    title: 'starter',
    meta: [
       { charset: 'utf-8' },
       { name: 'viewport', content: 'width=device-width, initial-scale=1' },
       { hid: 'description', name: 'description', content: 'Nuxt.js project'          }
    ],
    link: [
        { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
        { rel: 'stylesheet', href: 'http://vjs.zencdn.net/5.19/video-js.css' }
    ],
    script: [
        {src: 'http://vjs.zencdn.net/ie8/1.1/videojs-ie8.min.js'},
        {src: 'http://vjs.zencdn.net/5.19/video.js'}
    ]
}

This is my vue:

<video id="example_video_1" class="video-js vjs-default-skin" controls     preload="none" width="100%" height="300" data-setup="{}">
    <source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
</video>

[Vue warn]:

The client-side rendered virtual DOM tree is not matching server-rendered     content. This is likely caused by incorrect HTML markup, for example nesting    block-level elements inside
, or missing
. Bailing hydration and performing full client-side render.

And video button bar is not work.
I would be happy for any kind of support.


问:
WebClient not downloading file completely if above 50MB size
I'm using WebClient for downloading files.
But something fishy is going on when it tries to download larger files exactly above 50mb size, download gets completed right after 39kb and does not downloads it till the end.
Anyone knows what could be the issue?

```<code>using (webClient = new WebClient())
{
    webClient.Proxy = null;
    webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)");
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

    // The variable that will be holding the url address (making sure it starts with http://)
    Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);

    // Start the stopwatch which we will be using to calculate the download speed
    sw.Start();

    try
    {
        // Start downloading the file
        webClient.DownloadFileAsync(URL, _mainWindow.outputDirComboBox.SelectedItem.ToString() + "\\" + _compressedClientFileDownloadRelativePath, new List<object>
        {
            _compressedClientFileDownloadRelativePath,
            _decompressedClientFileDownloadRelativePath,
            _lastDownloadedFilePath,
            _compressedSize,
            _lastCompressedFilePartRelativePath,
            _filePartsRelativePath,
            urlAddress,
            _clientFilePack,
            _clientFile
        });
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
</code>```

DownloadFileCompleted checks only for errors and when its completed but there isnt any error report going on. Only that it finishes downloading as if the download size was only 39kb

Edit1:
While digging i end up here: Downloading Large Google Drive files with WebClient in C#

Looks like Google Drive gives some sort of confirm link but im not yet able to know how to putting all together working.

Edit2:
I just confirmed, the 39kb are the html page confirmation

答:
you must wait webClient.DownloadFileAsync process

else your execution fall down to the dispose command when the file is still downloading

example:

```<code>public class DownloadManager
{
    public void DownloadFile(string sourceUrl, string targetFolder)
    {
        WebClient downloader = new WebClient();
            // fake as if you are a browser making the request.
        downloader.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
        downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(Downloader_DownloadFileCompleted);

        downloader.DownloadFileAsync(new Uri(sourceUrl), targetFolder);

    }

    private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
            // display completion status.
        if (e.Error != null)
            Console.WriteLine(e.Error.Message);
        else
            Console.WriteLine("Download Completed!!!");
    }
}
</code>```

Body:
I'm using WebClient for downloading files.
But something fishy is going on when it tries to download larger files exactly above 50mb size, download gets completed right after 39kb and does not downloads it till the end.
Anyone knows what could be the issue?

using (webClient = new WebClient())
{
    webClient.Proxy = null;
    webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)");
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

    // The variable that will be holding the url address (making sure it starts with http://)
    Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);

    // Start the stopwatch which we will be using to calculate the download speed
    sw.Start();

    try
    {
        // Start downloading the file
        webClient.DownloadFileAsync(URL, _mainWindow.outputDirComboBox.SelectedItem.ToString() + "\\" + _compressedClientFileDownloadRelativePath, new List<object>
        {
            _compressedClientFileDownloadRelativePath,
            _decompressedClientFileDownloadRelativePath,
            _lastDownloadedFilePath,
            _compressedSize,
            _lastCompressedFilePartRelativePath,
            _filePartsRelativePath,
            urlAddress,
            _clientFilePack,
            _clientFile
        });
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

DownloadFileCompleted checks only for errors and when its completed but there isnt any error report going on. Only that it finishes downloading as if the download size was only 39kb

Edit1:
While digging i end up here: Downloading Large Google Drive files with WebClient in C#

Looks like Google Drive gives some sort of confirm link but im not yet able to know how to putting all together working.

Edit2:
I just confirmed, the 39kb are the html page confirmation

Body:
you must wait webClient.DownloadFileAsync process

else your execution fall down to the dispose command when the file is still downloading

example:

public class DownloadManager
{
    public void DownloadFile(string sourceUrl, string targetFolder)
    {
        WebClient downloader = new WebClient();
            // fake as if you are a browser making the request.
        downloader.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
        downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(Downloader_DownloadFileCompleted);

        downloader.DownloadFileAsync(new Uri(sourceUrl), targetFolder);

    }

    private void Downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
            // display completion status.
        if (e.Error != null)
            Console.WriteLine(e.Error.Message);
        else
            Console.WriteLine("Download Completed!!!");
    }
}


问:
Process Accessability
I am trying to write some information into the file, which is located in
ftp, and this file can be updated by number of people, but if at all i
download a file from the ftp to my local machine, update it and then
upload it back to ftp, and at the same time if some one else downloads
the same file for the modification, then the data will be overwritten.

so is there a way in Python script where i can lock the file, so that
no one updates it until i release the lock

答: Look at fuser

Title: Process Accessability

Body: Look at fuser


问:
Declaring Arrays of known custom class types in obj C/ios
Is there anyway to declare an array of custom class type in ios. eg if I have a custom class called GenericProduct, is there a way to declare an array of objects of this type only in ios instead of NSArray or NSMutableArray.

Thanks in advance

答:
Now with Generics you specific what type the NSArray is containing.

For example:

```<code>NSMutableArray<GenericProduct *> *array = [NSMutableArray array];
</code>```

The same thing can be done in Swift

```<code>var array = [GenericProduct]()
</code>```

or more explicitly

```<code>var array = Array<GenericProduct>()
</code>```

Now Swift will strictly enforce this type checking. While in ObjC, it is simply a guideline for us human developers and will not throw an error at compile time.

Obviously, there is still the C array option that @futureelite7 mentioned.

A real world example using Apple's ObjC Runtime Library

```<code>int numberOfClasses = objc_getClassList(NULL, 0);
Class *classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numberOfClasses);
numberOfClasses = objc_getClassList(classes, numberOfClasses);
for (int i = 0; i < numberOfClasses; i++) {
   Class class = classes[i];
   //do something with it
}
</code>```

Body:
Now with Generics you specific what type the NSArray is containing.

For example:

NSMutableArray<GenericProduct *> *array = [NSMutableArray array];

The same thing can be done in Swift

var array = [GenericProduct]()

or more explicitly

var array = Array<GenericProduct>()

Now Swift will strictly enforce this type checking. While in ObjC, it is simply a guideline for us human developers and will not throw an error at compile time.

Obviously, there is still the C array option that @futureelite7 mentioned.

A real world example using Apple's ObjC Runtime Library

int numberOfClasses = objc_getClassList(NULL, 0);
Class *classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numberOfClasses);
numberOfClasses = objc_getClassList(classes, numberOfClasses);
for (int i = 0; i < numberOfClasses; i++) {
   Class class = classes[i];
   //do something with it
}


问:
How to use Loop to execute store procedure in Cosmos-DB/Document-DB?
I have JSON like

```<code>{
  "id": "58d99ca3231f13b9ecbbbca4",
  "50records": [
    {
      "aomsLineNbr": 1,
      "licenses": [
        {
          "productKey": "84fc2cde-9735-4cea-b97a-3cd627d3d0a5",
          "aid": "someAid"
        }
      ]
    }
  ]
}
</code>```

I want to fetch record on the basis of aid.

50record can have multiple objects and licenses can also have multiple objects.

I am constucting the query as
"SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='someAid'"

how can I loop those 50records and licenses to search aid in all available objects?

Below is my store procedure:

```<code>function getOrdersByAidCollection(aid){
var context = getContext();
var collection = context.getCollection();
var link = collection.getSelfLink();
var response = context.getResponse();

var query = "SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='"+aid+"'";

var isAccepted = collection.queryDocuments(collection.getSelfLink(),query,
function (err, feed, options) {
    if (err) {
        return errorResponse(400, err.message);
    }
    if (!feed || !feed.length){
        return errorResponse(400, "no orders doc found");
    }else {
       getContext().getResponse().setBody(JSON.stringify(feed));
    }
});

    if (!isAccepted){
        return errorResponse(400, "The query was not accepted by the server.");
    }

}
</code>```

Where and how I need to put a loop ??

Any help will be appreciable!

Thanks

答:
why do you need a loop? This looks like a query question. Can you try a query like this:

```<code>SELECT VALUE r
FROM orders c
JOIN r in c["50records"]
JOIN li in r.licenses
WHERE li.aid = "someAid"
</code>```

Thanks!

Body:
I have JSON like

{
  "id": "58d99ca3231f13b9ecbbbca4",
  "50records": [
    {
      "aomsLineNbr": 1,
      "licenses": [
        {
          "productKey": "84fc2cde-9735-4cea-b97a-3cd627d3d0a5",
          "aid": "someAid"
        }
      ]
    }
  ]
}

I want to fetch record on the basis of aid.

50record can have multiple objects and licenses can also have multiple objects.

I am constucting the query as
"SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='someAid'"

how can I loop those 50records and licenses to search aid in all available objects?

Below is my store procedure:

function getOrdersByAidCollection(aid){
var context = getContext();
var collection = context.getCollection();
var link = collection.getSelfLink();
var response = context.getResponse();

var query = "SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='"+aid+"'";

var isAccepted = collection.queryDocuments(collection.getSelfLink(),query,
function (err, feed, options) {
    if (err) {
        return errorResponse(400, err.message);
    }
    if (!feed || !feed.length){
        return errorResponse(400, "no orders doc found");
    }else {
       getContext().getResponse().setBody(JSON.stringify(feed));
    }
});

    if (!isAccepted){
        return errorResponse(400, "The query was not accepted by the server.");
    }

}

Where and how I need to put a loop ??

Any help will be appreciable!

Thanks

Body:
why do you need a loop? This looks like a query question. Can you try a query like this:

SELECT VALUE r
FROM orders c
JOIN r in c["50records"]
JOIN li in r.licenses
WHERE li.aid = "someAid"

Thanks!


问:
How to check that an uploaded file is a valid Image in Django
I have an ImageField in one of my models so that users can upload an image. When a user submits an upload form, I want to verify that the file in question is a fully valid and displayable image.

I tried using PIL to verify that the image was in fact authentic, but using

```<code>from PIL import Image
Image.open(model.file)
Image.verify()
</code>```

No matter what file I give it though, it always throws an exception.

Anyone know of an easy way to verify the file?

答:
Also, you should use verify() as follows:</p>

```<code>from PIL import Image
im = Image.open(model.file)
im.verify()
</code>```

Body:
I have an ImageField in one of my models so that users can upload an image. When a user submits an upload form, I want to verify that the file in question is a fully valid and displayable image.

I tried using PIL to verify that the image was in fact authentic, but using

from PIL import Image
Image.open(model.file)
Image.verify()

No matter what file I give it though, it always throws an exception.

Anyone know of an easy way to verify the file?

Body:
Also, you should use verify() as follows:

from PIL import Image
im = Image.open(model.file)
im.verify()


问:
Can't push rails app to heroku because of sqlite3?
I am trying to push my app to heroku, but I could not prevent it from installing sqlite3 - I believe this is what is causing the problem pushing it.

I have read and applied the following SO posts:

Deploying RoR app to Heroku with Sqlite3 fails

HEROKU - cannot run git push heroku master

Unable to Deploy Rails App to Heroku, Gem Errors (SQLite3 and Gem Native Extension)

I have also made sure to commit my work:

```<code>git add .
git commit -m "sqlite3 problem"
git push heroku master
</code>```

I tried deleting the Gemfile.lock and running both bundle and bundle install and add, commit, and pushed it to heroku, but still no luck.

This is inside my Gemfile:

```<code>group :production do
  gem 'pg'
end
group :development, :test do
  gem 'byebug', platform: :mri
  gem 'faker', '~> 1.7', '>= 1.7.3'
  gem 'rspec-rails', '~> 3.5'
  gem 'factory_girl_rails', '~> 4.8'
  gem 'sqlite3'
end
</code>```

Error log:

```<code>remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.13.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/...........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.1
remote:        Installing rake 12.0.0
remote:        Installing concurrent-ruby 1.0.5
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.6
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing nio4r 2.0.0 with native extensions
remote:        Installing rack 2.0.1
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing connection_pool 2.2.1
remote:        Installing thor 0.19.4
remote:        Installing jwt 1.5.6
remote:        Installing method_source 0.8.2
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.8.2 with native extensions
remote:        Installing redis 3.3.3
remote:        Installing sqlite3 1.3.13 with native extensions
remote:        Installing tzinfo 1.2.3
remote:        Installing nokogiri 1.7.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing rack-protection 2.0.0
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing foreman 0.84.0
remote:        Installing twilio-ruby 4.11.1
remote:        Installing activesupport 5.0.2
remote:        Installing sidekiq 5.0.0
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:        current directory:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/ruby -r
remote:        ./siteconf20170606-219-133actd.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-config
remote:        --without-sqlite3-config
remote:        --with-pkg-config
remote:        --without-pkg-config
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:        To see why this extension failed to compile, please check the mkmf.log which can
remote:        be found here:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log
remote:        extconf failed, exit code 1
remote:        Gem files will remain installed in
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out
remote:        An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.
remote:        Bundler Output: Fetching gem metadata from https://rubygems.org/...........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.1
remote:        Installing rake 12.0.0
remote:        Installing concurrent-ruby 1.0.5
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.6
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing nio4r 2.0.0 with native extensions
remote:        Installing rack 2.0.1
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing connection_pool 2.2.1
remote:        Installing thor 0.19.4
remote:        Installing jwt 1.5.6
remote:        Installing method_source 0.8.2
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.8.2 with native extensions
remote:        Installing redis 3.3.3
remote:        Installing sqlite3 1.3.13 with native extensions
remote:        Installing tzinfo 1.2.3
remote:        Installing nokogiri 1.7.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing rack-protection 2.0.0
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing foreman 0.84.0
remote:        Installing twilio-ruby 4.11.1
remote:        Installing activesupport 5.0.2
remote:        Installing sidekiq 5.0.0
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:
remote:        current directory:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/ruby -r
remote:        ./siteconf20170606-219-133actd.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-config
remote:        --without-sqlite3-config
remote:        --with-pkg-config
remote:        --without-pkg-config
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:
remote:        To see why this extension failed to compile, please check the mkmf.log which can
remote:        be found here:
remote:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log
remote:
remote:        extconf failed, exit code 1
remote:
remote:        Gem files will remain installed in
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out
remote:
remote:        An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
</code>```

Every single time, I keep seeing this line Installing sqlite3 1.3.13 with native extensions and I believe that is what caused the error, even though I don't have sqlite3 in production. I have also tried removing sqlite3 altogether from Gemfile and have only gem pg, but it still somehow installs sqlite3 when I push it to heroku.

How can I push the app to heroku successfully?

EDIT:

The problem is solved (well, technically not - I am still having trouble pushing, but the sqlite3 error disappeared, and that's the gist of this question). Here is what I did wrong: I was working on other local branch when I see the error message, let's say iggy-branch-2. I did my git add ., git commit -m "some message", and git push heroku master on this branch. When I switched back to master branch and git merge iggy-branch-2, and after I git push heroku master, it stopped trying to install sqlite3. It appears that when I push to heroku, it looks for gemfile.lock inside master branch (someone correct me if I'm wrong).

The comments and answer here gave me the insight that the only way to update gemfile.lock is really just to bundle it up. I figured I did all the right thing, so I decided to try switching branches.

Take-home: make sure my master branch is up-to-date. Seems like Heroku looks there for gemfile info.

Thanks, everyone!

答:
This is because herouku uses your gemfile.lock to know the gems and versions to use instead of the gemfile, you must:

run a bundle install locally to update your gemfile.lock

commit and push that change to git(hub)

push to heroku.

Good luck!

Edit: Also, make sure to include your gemfile.lock to git, although that's kind of obvious

Body:
I am trying to push my app to heroku, but I could not prevent it from installing sqlite3 - I believe this is what is causing the problem pushing it.

I have read and applied the following SO posts:

Deploying RoR app to Heroku with Sqlite3 fails

HEROKU - cannot run git push heroku master

Unable to Deploy Rails App to Heroku, Gem Errors (SQLite3 and Gem Native Extension)

I have also made sure to commit my work:

git add .
git commit -m "sqlite3 problem"
git push heroku master

I tried deleting the Gemfile.lock and running both bundle and bundle install and add, commit, and pushed it to heroku, but still no luck.

This is inside my Gemfile:

group :production do
  gem 'pg'
end
group :development, :test do
  gem 'byebug', platform: :mri
  gem 'faker', '~> 1.7', '>= 1.7.3'
  gem 'rspec-rails', '~> 3.5'
  gem 'factory_girl_rails', '~> 4.8'
  gem 'sqlite3'
end

Error log:

remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.13.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/...........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.1
remote:        Installing rake 12.0.0
remote:        Installing concurrent-ruby 1.0.5
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.6
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing nio4r 2.0.0 with native extensions
remote:        Installing rack 2.0.1
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing connection_pool 2.2.1
remote:        Installing thor 0.19.4
remote:        Installing jwt 1.5.6
remote:        Installing method_source 0.8.2
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.8.2 with native extensions
remote:        Installing redis 3.3.3
remote:        Installing sqlite3 1.3.13 with native extensions
remote:        Installing tzinfo 1.2.3
remote:        Installing nokogiri 1.7.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing rack-protection 2.0.0
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing foreman 0.84.0
remote:        Installing twilio-ruby 4.11.1
remote:        Installing activesupport 5.0.2
remote:        Installing sidekiq 5.0.0
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:        current directory:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/ruby -r
remote:        ./siteconf20170606-219-133actd.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-config
remote:        --without-sqlite3-config
remote:        --with-pkg-config
remote:        --without-pkg-config
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:        To see why this extension failed to compile, please check the mkmf.log which can
remote:        be found here:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log
remote:        extconf failed, exit code 1
remote:        Gem files will remain installed in
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out
remote:        An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.
remote:        Bundler Output: Fetching gem metadata from https://rubygems.org/...........
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Installing i18n 0.8.1
remote:        Installing rake 12.0.0
remote:        Installing concurrent-ruby 1.0.5
remote:        Installing minitest 5.10.1
remote:        Installing thread_safe 0.3.6
remote:        Installing builder 3.2.3
remote:        Installing erubis 2.7.0
remote:        Installing mini_portile2 2.1.0
remote:        Installing nio4r 2.0.0 with native extensions
remote:        Installing rack 2.0.1
remote:        Installing websocket-extensions 0.1.2
remote:        Installing mime-types-data 3.2016.0521
remote:        Installing arel 7.1.4
remote:        Installing connection_pool 2.2.1
remote:        Installing thor 0.19.4
remote:        Installing jwt 1.5.6
remote:        Installing method_source 0.8.2
remote:        Installing multi_json 1.12.1
remote:        Using bundler 1.13.7
remote:        Installing puma 3.8.2 with native extensions
remote:        Installing redis 3.3.3
remote:        Installing sqlite3 1.3.13 with native extensions
remote:        Installing tzinfo 1.2.3
remote:        Installing nokogiri 1.7.1 with native extensions
remote:        Installing rack-test 0.6.3
remote:        Installing rack-protection 2.0.0
remote:        Installing sprockets 3.7.1
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Installing mime-types 3.1
remote:        Installing foreman 0.84.0
remote:        Installing twilio-ruby 4.11.1
remote:        Installing activesupport 5.0.2
remote:        Installing sidekiq 5.0.0
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
remote:
remote:        current directory:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/ruby -r
remote:        ./siteconf20170606-219-133actd.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probably lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file for more details.  You may
remote:        need configuration options.
remote:
remote:        Provided configuration options:
remote:        --with-opt-dir
remote:        --without-opt-dir
remote:        --with-opt-include
remote:        --without-opt-include=${opt-dir}/include
remote:        --with-opt-lib
remote:        --without-opt-lib=${opt-dir}/lib
remote:        --with-make-prog
remote:        --without-make-prog
remote:        --srcdir=.
remote:        --curdir
remote:        --ruby=/tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/ruby-2.3.4/bin/$(RUBY_BASE_NAME)
remote:        --with-sqlite3-config
remote:        --without-sqlite3-config
remote:        --with-pkg-config
remote:        --without-pkg-config
remote:        --with-sqlite3-dir
remote:        --without-sqlite3-dir
remote:        --with-sqlite3-include
remote:        --without-sqlite3-include=${sqlite3-dir}/include
remote:        --with-sqlite3-lib
remote:        --without-sqlite3-lib=${sqlite3-dir}/lib
remote:
remote:        To see why this extension failed to compile, please check the mkmf.log which can
remote:        be found here:
remote:
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log
remote:
remote:        extconf failed, exit code 1
remote:
remote:        Gem files will remain installed in
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cb97a281aec933a41e755d6b82c2e524/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out
remote:
remote:        An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succeeds before bundling.
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:

Every single time, I keep seeing this line Installing sqlite3 1.3.13 with native extensions and I believe that is what caused the error, even though I don't have sqlite3 in production. I have also tried removing sqlite3 altogether from Gemfile and have only gem pg, but it still somehow installs sqlite3 when I push it to heroku.

How can I push the app to heroku successfully?

EDIT:

The problem is solved (well, technically not - I am still having trouble pushing, but the sqlite3 error disappeared, and that's the gist of this question). Here is what I did wrong: I was working on other local branch when I see the error message, let's say iggy-branch-2. I did my git add ., git commit -m "some message", and git push heroku master on this branch. When I switched back to master branch and git merge iggy-branch-2, and after I git push heroku master, it stopped trying to install sqlite3. It appears that when I push to heroku, it looks for gemfile.lock inside master branch (someone correct me if I'm wrong).

The comments and answer here gave me the insight that the only way to update gemfile.lock is really just to bundle it up. I figured I did all the right thing, so I decided to try switching branches.

Take-home: make sure my master branch is up-to-date. Seems like Heroku looks there for gemfile info.

Thanks, everyone!


问:
I have an image that is pushing the body away from the html element if the windows height shrinks
I'm building a website and the picture that is 256X480 on the home page breaks out of the body and pushes the body away from the html element, I'm a bit confused on how to handle this the image and its container dont seem to respond at all to the max-height property. Can someone explain why this is or point me to some resources that explain this and how to fix it, thanks.

https://jsfiddle.net/9oy5n0he/

```<code>html{
    height: 100%;
}
body{
    margin: 0px;
    background-image: linear-gradient( 0, rgba(0,0,0,.8) 30%, rgba(0,150,255,.8) 100%), url("images/mainCover.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    height: 100%;
}
img{
    max-width: 100%;
}
/*nav and header*/
header{
    background-color: rgba(255,165,0,.8);
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    border-bottom: 8px solid black;
}
nav ul {
        list-style: none;
        padding: 0;
}
header h1{
    text-align: center;
    margin: 0;
    padding: 15px;
    text-shadow: 5px 5px 5px rgba(0,0,0,.3);
}
header h1, nav a{
    font-weight: 700;
    font-family: arial;
}
header nav{
    display: none;
}

.main-nav{
    margin: 4px;
}
nav ul li{
    text-align: center;
    margin: 0 4px;
    border: 1px solid white;
    border-radius: 15px;
    font-size: 1.2rem;
}
a{
    text-decoration: none;
}

 nav a:visited, nav a,h1{
   color: white;
}

.current-page{
    background-color: rgba(0,0,0,.5);
}

footer nav{
    position: fixed;
    width: 100%;
    bottom: 0px;
}

footer nav ul{
    margin: 0;
}
footer nav li{
    background-color: rgba(255,165,0,.8);
}
/*home page*/
.bookWrapper{
    width: 25%;
    margin: auto;
}
 .bookLink {
    display: block;
    margin: auto;
}

.bookImage{
    margin: auto;
    display: block;
}

.amazonBookLabel{
    background-color: rgba(0,0,0,.5);
    color: white;
    padding: 10px;
    font-size: 1.5em;
    font-weight: 600;
    width: 50%;
    border-radius: 20px;
    margin: 30px auto;
    text-align: center;
    position: relative;
}
.amazonBookLabel:after{
    content: "";
    width: 30px;
    height: 5px;
    background-color: rgba(0,0,0,.5);
    position: absolute;
    bottom: -5px;
    left: calc(50% - 17px);
}
.amazonBookLabel:before{
    content: "";
    width: 0;
    height: 0;
    border-left:  40px solid rgba(0,0,0,.5);
    border-top: 40px solid transparent;
    position: absolute;
    bottom: -45px;
    transform: rotate(-45deg);
    transform-origin: top left;
    left: calc(50% - 30px);
}

/***responsive***/
@media screen and (min-width: 400px){
        header{
            height: 130px;
            display: flex;
            justify-content: center;
        }
      header h1{
                font-size: 2em;
                align-self: flex-start;
                white-space: nowrap;
                border: 8px solid black;
            }
     header nav{
                display: block;
                align-self: flex-end;
            }
      .main-nav{
                display: flex;
                justify-content: flex-end;
            }
     .main-nav li{
                border-radius: 8px;
                padding: 5px;
                font-size: 1.3rem;
            }
    .characters:hover {
            position: relative;
            border-radius: 8px 8px 0 0;
            }

     .drop-menu{
            position: absolute;
            visibility: hidden;
            display: block;
            top: 33px;
            white-space: nowrap;
            left: -2px;
            background-color: rgba(255,165,0,.8);
            border: 1px solid rgba(0,0,0,.02);
            box-shadow: 5px 5px 5px 2px rgba(0,0,0,.3);
            opacity: 0;
            transition: opacity 300ms ease-in-out 0s;
            z-index: 1;
            }
    .characters:hover .drop-menu{
             visibility: visible;
             opacity:1;
        }

    .drop-menu li{
        margin: 0;
        border-radius: 0;
    }

    footer nav{
                display: none;
            }
}
@media screen and (min-width:860px){
    header{
        height: 120px;
        justify-content: space-between;
    }
    header h1{
        margin: 0 0 0 20px;
    }
    .main-nav li{
        font-size: 1.5rem;
    }
    header nav{
        margin: 0 40px 0 0;
    }
}

@media screen and (min-width: 1109px){
    header h1{
        font-size: 3em;
        margin: 0 0 0 80px;
    }
    .main-nav > li{
        margin: 0 8px;
    }
    header nav{
        margin: 0 80px 0 0;
    }
}
</code>```

答:
It's because height: 100% on html is limiting the height and technically the image is overflowing html/body, so you won't see the background in that overflow.

A better technique is to remove the height on html (not necessary) and use min-height: 100vh on body

body {
  margin: 0px;
  background-image: linear-gradient( 0, rgba(0, 0, 0, .8) 30%, rgba(0, 150, 255, .8) 100%), url("images/mainCover.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  min-height: 100vh;
}

img {
  max-width: 100%;
}

/*nav and header*/

header {
  background-color: rgba(255, 165, 0, .8);
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  border-bottom: 8px solid black;
}

nav ul {
  list-style: none;
  padding: 0;
}

header h1 {
  text-align: center;
  margin: 0;
  padding: 15px;
  text-shadow: 5px 5px 5px rgba(0, 0, 0, .3);
}

header h1,
nav a {
  font-weight: 700;
  font-family: arial;
}

header nav {
  display: none;
}

.main-nav {
  margin: 4px;
}

nav ul li {
  text-align: center;
  margin: 0 4px;
  border: 1px solid white;
  border-radius: 15px;
  font-size: 1.2rem;
}

a {
  text-decoration: none;
}

nav a:visited,
nav a,
h1 {
  color: white;
}

.current-page {
  background-color: rgba(0, 0, 0, .5);
}

footer nav {
  position: fixed;
  width: 100%;
  bottom: 0px;
}

footer nav ul {
  margin: 0;
}

footer nav li {
  background-color: rgba(255, 165, 0, .8);
}

/*home page*/

.bookWrapper {
  width: 25%;
  margin: auto;
}

.bookLink {
  display: block;
  margin: auto;
}

.bookImage {
  margin: auto;
  display: block;
}

.amazonBookLabel {
  background-color: rgba(0, 0, 0, .5);
  color: white;
  padding: 10px;
  font-size: 1.5em;
  font-weight: 600;
  width: 50%;
  border-radius: 20px;
  margin: 30px auto;
  text-align: center;
  position: relative;
}

.amazonBookLabel:after {
  content: "";
  width: 30px;
  height: 5px;
  background-color: rgba(0, 0, 0, .5);
  position: absolute;
  bottom: -5px;
  left: calc(50% - 17px);
}

.amazonBookLabel:before {
  content: "";
  width: 0;
  height: 0;
  border-left: 40px solid rgba(0, 0, 0, .5);
  border-top: 40px solid transparent;
  position: absolute;
  bottom: -45px;
  transform: rotate(-45deg);
  transform-origin: top left;
  left: calc(50% - 30px);
}

/***responsive***/

@media screen and (min-width: 400px) {
  header {
    height: 130px;
    display: flex;
    justify-content: center;
  }
  header h1 {
    font-size: 2em;
    align-self: flex-start;
    white-space: nowrap;
    border: 8px solid black;
  }
  header nav {
    display: block;
    align-self: flex-end;
  }
  .main-nav {
    display: flex;
    justify-content: flex-end;
  }
  .main-nav li {
    border-radius: 8px;
    padding: 5px;
    font-size: 1.3rem;
  }
  .characters:hover {
    position: relative;
    border-radius: 8px 8px 0 0;
  }
  .drop-menu {
    position: absolute;
    visibility: hidden;
    display: block;
    top: 33px;
    white-space: nowrap;
    left: -2px;
    background-color: rgba(255, 165, 0, .8);
    border: 1px solid rgba(0, 0, 0, .02);
    box-shadow: 5px 5px 5px 2px rgba(0, 0, 0, .3);
    opacity: 0;
    transition: opacity 300ms ease-in-out 0s;
    z-index: 1;
  }
  .characters:hover .drop-menu {
    visibility: visible;
    opacity: 1;
  }
  .drop-menu li {
    margin: 0;
    border-radius: 0;
  }
  footer nav {
    display: none;
  }
}

@media screen and (min-width:860px) {
  header {
    height: 120px;
    justify-content: space-between;
  }
  header h1 {
    margin: 0 0 0 20px;
  }
  .main-nav li {
    font-size: 1.5rem;
  }
  header nav {
    margin: 0 40px 0 0;
  }
}

@media screen and (min-width: 1109px) {
  header h1 {
    font-size: 3em;
    margin: 0 0 0 80px;
  }
  .main-nav > li {
    margin: 0 8px;
  }
  header nav {
    margin: 0 80px 0 0;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><main>
  <header>
    <h1>Seraph Chronicles</h1>
    <nav>
      <ul class="main-nav">
        <li class="main-nav-item current-page">Home</li>
        <li class="main-nav-item">About</li>
        <li class="main-nav-item characters">
          Characters
          <ul class="drop-menu">
            <li>Ethan Clarke</li>
            <li>Serena Kiriaga</li>
            <li>Marcus Flynn</li>
            <li>Emily Ashdown</li>
            <li>Director Miles West</li>
          </ul>
        </li>
        <li class="main-nav-item">Author</li>
      </ul>
    </nav>
  </header>
  <section>
    <p class="amazonBookLabel">Get the first and newest addition of the trilogy here!</p>
    <div class="bookWrapper">

        <img class="bookImage" src="images/bookCover.jpg" alt="image of seraph chronicles: evangelion for purchase">

    </div>
  </section>
  <footer>
  </footer>
  <section>
  </section>
  <footer>
    <nav>
      <ul>
        <li>Home</li>
        <li>About</li>
        <li>Characters</li>
        <li>Author</li>
      </ul>
    </nav>
  </footer>
</main></code>```

Body:
I'm building a website and the picture that is 256X480 on the home page breaks out of the body and pushes the body away from the html element, I'm a bit confused on how to handle this the image and its container dont seem to respond at all to the max-height property. Can someone explain why this is or point me to some resources that explain this and how to fix it, thanks.

https://jsfiddle.net/9oy5n0he/

html{
    height: 100%;
}
body{
    margin: 0px;
    background-image: linear-gradient( 0, rgba(0,0,0,.8) 30%, rgba(0,150,255,.8) 100%), url("images/mainCover.jpg");
    background-repeat: no-repeat;
    background-size: cover;
    height: 100%;
}
img{
    max-width: 100%;
}
/*nav and header*/
header{
    background-color: rgba(255,165,0,.8);
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    border-bottom: 8px solid black;
}
nav ul {
        list-style: none;
        padding: 0;
}
header h1{
    text-align: center;
    margin: 0;
    padding: 15px;
    text-shadow: 5px 5px 5px rgba(0,0,0,.3);
}
header h1, nav a{
    font-weight: 700;
    font-family: arial;
}
header nav{
    display: none;
}

.main-nav{
    margin: 4px;
}
nav ul li{
    text-align: center;
    margin: 0 4px;
    border: 1px solid white;
    border-radius: 15px;
    font-size: 1.2rem;
}
a{
    text-decoration: none;
}

 nav a:visited, nav a,h1{
   color: white;
}

.current-page{
    background-color: rgba(0,0,0,.5);
}

footer nav{
    position: fixed;
    width: 100%;
    bottom: 0px;
}

footer nav ul{
    margin: 0;
}
footer nav li{
    background-color: rgba(255,165,0,.8);
}
/*home page*/
.bookWrapper{
    width: 25%;
    margin: auto;
}
 .bookLink {
    display: block;
    margin: auto;
}

.bookImage{
    margin: auto;
    display: block;
}

.amazonBookLabel{
    background-color: rgba(0,0,0,.5);
    color: white;
    padding: 10px;
    font-size: 1.5em;
    font-weight: 600;
    width: 50%;
    border-radius: 20px;
    margin: 30px auto;
    text-align: center;
    position: relative;
}
.amazonBookLabel:after{
    content: "";
    width: 30px;
    height: 5px;
    background-color: rgba(0,0,0,.5);
    position: absolute;
    bottom: -5px;
    left: calc(50% - 17px);
}
.amazonBookLabel:before{
    content: "";
    width: 0;
    height: 0;
    border-left:  40px solid rgba(0,0,0,.5);
    border-top: 40px solid transparent;
    position: absolute;
    bottom: -45px;
    transform: rotate(-45deg);
    transform-origin: top left;
    left: calc(50% - 30px);
}

/***responsive***/
@media screen and (min-width: 400px){
        header{
            height: 130px;
            display: flex;
            justify-content: center;
        }
      header h1{
                font-size: 2em;
                align-self: flex-start;
                white-space: nowrap;
                border: 8px solid black;
            }
     header nav{
                display: block;
                align-self: flex-end;
            }
      .main-nav{
                display: flex;
                justify-content: flex-end;
            }
     .main-nav li{
                border-radius: 8px;
                padding: 5px;
                font-size: 1.3rem;
            }
    .characters:hover {
            position: relative;
            border-radius: 8px 8px 0 0;
            }

     .drop-menu{
            position: absolute;
            visibility: hidden;
            display: block;
            top: 33px;
            white-space: nowrap;
            left: -2px;
            background-color: rgba(255,165,0,.8);
            border: 1px solid rgba(0,0,0,.02);
            box-shadow: 5px 5px 5px 2px rgba(0,0,0,.3);
            opacity: 0;
            transition: opacity 300ms ease-in-out 0s;
            z-index: 1;
            }
    .characters:hover .drop-menu{
             visibility: visible;
             opacity:1;
        }

    .drop-menu li{
        margin: 0;
        border-radius: 0;
    }

    footer nav{
                display: none;
            }
}
@media screen and (min-width:860px){
    header{
        height: 120px;
        justify-content: space-between;
    }
    header h1{
        margin: 0 0 0 20px;
    }
    .main-nav li{
        font-size: 1.5rem;
    }
    header nav{
        margin: 0 40px 0 0;
    }
}

@media screen and (min-width: 1109px){
    header h1{
        font-size: 3em;
        margin: 0 0 0 80px;
    }
    .main-nav > li{
        margin: 0 8px;
    }
    header nav{
        margin: 0 80px 0 0;
    }
}

Body:
It's because height: 100% on html is limiting the height and technically the image is overflowing html/body, so you won't see the background in that overflow.

A better technique is to remove the height on html (not necessary) and use min-height: 100vh on body

body {
  margin: 0px;
  background-image: linear-gradient( 0, rgba(0, 0, 0, .8) 30%, rgba(0, 150, 255, .8) 100%), url("images/mainCover.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  min-height: 100vh;
}

img {
  max-width: 100%;
}

/*nav and header*/

header {
  background-color: rgba(255, 165, 0, .8);
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  border-bottom: 8px solid black;
}

nav ul {
  list-style: none;
  padding: 0;
}

header h1 {
  text-align: center;
  margin: 0;
  padding: 15px;
  text-shadow: 5px 5px 5px rgba(0, 0, 0, .3);
}

header h1,
nav a {
  font-weight: 700;
  font-family: arial;
}

header nav {
  display: none;
}

.main-nav {
  margin: 4px;
}

nav ul li {
  text-align: center;
  margin: 0 4px;
  border: 1px solid white;
  border-radius: 15px;
  font-size: 1.2rem;
}

a {
  text-decoration: none;
}

nav a:visited,
nav a,
h1 {
  color: white;
}

.current-page {
  background-color: rgba(0, 0, 0, .5);
}

footer nav {
  position: fixed;
  width: 100%;
  bottom: 0px;
}

footer nav ul {
  margin: 0;
}

footer nav li {
  background-color: rgba(255, 165, 0, .8);
}

/*home page*/

.bookWrapper {
  width: 25%;
  margin: auto;
}

.bookLink {
  display: block;
  margin: auto;
}

.bookImage {
  margin: auto;
  display: block;
}

.amazonBookLabel {
  background-color: rgba(0, 0, 0, .5);
  color: white;
  padding: 10px;
  font-size: 1.5em;
  font-weight: 600;
  width: 50%;
  border-radius: 20px;
  margin: 30px auto;
  text-align: center;
  position: relative;
}

.amazonBookLabel:after {
  content: "";
  width: 30px;
  height: 5px;
  background-color: rgba(0, 0, 0, .5);
  position: absolute;
  bottom: -5px;
  left: calc(50% - 17px);
}

.amazonBookLabel:before {
  content: "";
  width: 0;
  height: 0;
  border-left: 40px solid rgba(0, 0, 0, .5);
  border-top: 40px solid transparent;
  position: absolute;
  bottom: -45px;
  transform: rotate(-45deg);
  transform-origin: top left;
  left: calc(50% - 30px);
}

/***responsive***/

@media screen and (min-width: 400px) {
  header {
    height: 130px;
    display: flex;
    justify-content: center;
  }
  header h1 {
    font-size: 2em;
    align-self: flex-start;
    white-space: nowrap;
    border: 8px solid black;
  }
  header nav {
    display: block;
    align-self: flex-end;
  }
  .main-nav {
    display: flex;
    justify-content: flex-end;
  }
  .main-nav li {
    border-radius: 8px;
    padding: 5px;
    font-size: 1.3rem;
  }
  .characters:hover {
    position: relative;
    border-radius: 8px 8px 0 0;
  }
  .drop-menu {
    position: absolute;
    visibility: hidden;
    display: block;
    top: 33px;
    white-space: nowrap;
    left: -2px;
    background-color: rgba(255, 165, 0, .8);
    border: 1px solid rgba(0, 0, 0, .02);
    box-shadow: 5px 5px 5px 2px rgba(0, 0, 0, .3);
    opacity: 0;
    transition: opacity 300ms ease-in-out 0s;
    z-index: 1;
  }
  .characters:hover .drop-menu {
    visibility: visible;
    opacity: 1;
  }
  .drop-menu li {
    margin: 0;
    border-radius: 0;
  }
  footer nav {
    display: none;
  }
}

@media screen and (min-width:860px) {
  header {
    height: 120px;
    justify-content: space-between;
  }
  header h1 {
    margin: 0 0 0 20px;
  }
  .main-nav li {
    font-size: 1.5rem;
  }
  header nav {
    margin: 0 40px 0 0;
  }
}

@media screen and (min-width: 1109px) {
  header h1 {
    font-size: 3em;
    margin: 0 0 0 80px;
  }
  .main-nav > li {
    margin: 0 8px;
  }
  header nav {
    margin: 0 80px 0 0;
  }
}

<main>
  <header>
    <h1>Seraph Chronicles</h1>
    <nav>
      <ul class="main-nav">
        <li class="main-nav-item current-page"><a href="index.html">Home</a></li>
        <li class="main-nav-item"><a href="about.html">About</a></li>
        <li class="main-nav-item characters">
          <a href="characters.html">Characters</a>
          <ul class="drop-menu">
            <li><a href="ethanClarke.html">Ethan Clarke</a></li>
            <li><a href="serenaKiriaga.html">Serena Kiriaga</a></li>
            <li><a href="MarcusFlynn.html">Marcus Flynn</a></li>
            <li><a href="EmilyAshdown.html">Emily Ashdown</a></li>
            <li><a href="MilesWest.html">Director Miles West</a></li>
          </ul>
        </li>
        <li class="main-nav-item"><a href="auther.html">Author</a></li>
      </ul>
    </nav>
  </header>
  <section>
    <p class="amazonBookLabel">Get the first and newest addition of the trilogy here!</p>
    <div class="bookWrapper">
      <a href="https://www.amazon.com/Seraph-Chronicles-Kyle-James-Feller/dp/1520404999/ref=sr_1_3?ie=UTF8&qid=1496613120&sr=8-3&keywords=seraph+chronicles" class="bookLink">
        <img class="bookImage" src="images/bookCover.jpg" alt="image of seraph chronicles: evangelion for purchase">
      </a>
    </div>
  </section>
  <footer>
  </footer>
  <section>
  </section>
  <footer>
    <nav>
      <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="characters.html">Characters</a></li>
        <li><a href="auther.html">Author</a></li>
      </ul>
    </nav>
  </footer>
</main>


问:
File upload controller not working after upload - global.asax not firing after upload
I have a problem with fileuploadController. On my local computer it works perfectly. Uploading without problem. But when I publish site and upload to web its not uploading and getting error not found.

Here is the my local computer result

And here is the web version

and my Globax.Asax file is like that

GlobalConfiguration.Configure(config =>
            {
                config.MapHttpAttributeRoutes();
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{action}/{id}",
                    defaults: new { id = System.Web.Http.RouteParameter.Optional }
                    );

            });```

I tried everything but no success. What can I do to fix this problem.

答:
I know this is really old, but look if you have a Precompiledapp.config file in the project.

I've found that deleting this file solved it as the routing in global.asax wasn't being done with that file in the project.

Body:
I have a problem with fileuploadController. On my local computer it works perfectly. Uploading without problem. But when I publish site and upload to web its not uploading and getting error not found.

Here is the my local computer result

And here is the web version

and my Globax.Asax file is like that

GlobalConfiguration.Configure(config =>
            {
                config.MapHttpAttributeRoutes();
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{action}/{id}",
                    defaults: new { id = System.Web.Http.RouteParameter.Optional }
                    );

            });

I tried everything but no success. What can I do to fix this problem.


问:
How to install Semantic UI into Dreamweaver?
Sorry if this sounds dumb, but I'm brand new to Javascript libraries/repos. All I basically need to do is be able to use the Dropdown functionality in Semantic UI: https://semantic-ui.com/modules/dropdown.html

I have the zip file installed and it comes with different CSS/JS files, but how exactly do I incorporate this into my code? Do I just copy the javascript content into my code?

Any help/guidance would be appreciated, thanks.

答:
From https://semantic-ui.com/introduction/advanced-usage.html

Looks like you can include the CDN scripts into your html file.

```<code><link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">

<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.js"></script>
</code>```

Body:
From https://semantic-ui.com/introduction/advanced-usage.html

Looks like you can include the CDN scripts into your html file.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">

<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.js"></script>


问:
How do I limit one pop up per user, using JavaScript
Well I found this code for my blog:

```<code><script type="text/javascript">
document.body.onclick= function(){ window.open('My site', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50'); }
</script>
</code>```

But since I know nothing about JS, I can't really edit it much.

答:
Using cookies https://jsfiddle.net/arvinddhakad/bq8f241a/</p>

```<code>document.body.onclick = function() {
    isPopup = document.cookie.replace(/(?:(?:^|.*;\s*)popup\s*\=\s*([^;]*).*$)|^.*$/, "$1") || false;
    if (!isPopup) {
        window.open('My site', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
    document.cookie = "popup=true";
    }
}
</code>```

Body:
Well I found this code for my blog:

But since I know nothing about JS, I can't really edit it much.

Body:
Using cookies https://jsfiddle.net/arvinddhakad/bq8f241a/

document.body.onclick = function() {
    isPopup = document.cookie.replace(/(?:(?:^|.*;\s*)popup\s*\=\s*([^;]*).*$)|^.*$/, "$1") || false;
    if (!isPopup) {
        window.open('My site', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
    document.cookie = "popup=true";
    }
}


问:
EnumProcesses - weird behaviour
I have some weird behaviour while using WIndows API function EnumProcesses()

I have a function to determine wether a process with a certain name is already running which delivery different results wether I open the .executable manually (doubleclick) or open it via shell.

When I open it via shell it detects its running only 1 time (itself) and all is fine. When I open it using doubleclick on the .exe file however the function is returning true (already running) because the loop lists me the same process twice.

For the following code-snipped it is to mention that:

```<code>this->thisExecutableFile
</code>```

contains argv[0] (initialised from running the program) to get the own process-name as you can see here:

```<code>int main(int argc, char* argv[])
{
    ClientUpdate* update = ClientUpdate::getInstance();
    update->setThisExecutableFile(argv[0]);
    if (update->clientUpdateProcessIsRunning() == false) {
    ...
</code>```

My goal is to find out if another instance of this process is already running and in this case exit it.

Here is my code:

```<code>bool ClientUpdate::clientUpdateProcessIsRunning()
{
    bool retVal = false;

    uint16_t processCount = 0;
    unsigned long aProcesses[1024], cbNeeded, cProcesses;
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
        return false;

    cProcesses = cbNeeded / sizeof(unsigned long);

    for(unsigned int i = 0; i < cProcesses; i++) {
        if (aProcesses[i] == 0) {
            continue;
        }

        HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
        wchar_t buffer[50];
        GetModuleBaseNameW(hProcess, 0, buffer, 50);
        CloseHandle(hProcess);

        std::wstring tempBuffer(buffer);
        std::string tempStringBuffer(tempBuffer.begin(), tempBuffer.end());
        boost::filesystem::path p(this->thisExecutableFile);
        if(_strcmpi(p.filename().string().c_str(), tempStringBuffer.c_str()) == 0) {
            processCount++;
            if(processCount > 1) {
                retVal = true;
                break;
            }
        }
    }

    return retVal;
}
</code>```

I know that the base-path is different when using doubleclick on the file or calling it via shell. (shell produces only filename while doubleclick passes entire path + filename into argv[0]) but I fixed that issue using

```<code>boost::filesystem::path p(this->thisExecutableFile);
p.fileName()
</code>```

Which returns the correct filename (without path) in both cases I checked using print.

I am pretty puzzled why EnumProcesses() returns me the same file twice when calling the file via doubleclick instead of shell. Its not spawning two processed and in taskmanager I dont see anything like this either.

Is this a bug or I need to know something about the method I couldnt find in docs?

答:
Thanks to the hint by Richard Critten I was able to fix it. My method is much smaller now and easier. (Also probably also alot more performant then scanning entire process-stack.) :D

Here is the solution

```<code>bool ClientUpdate::clientUpdateProcessIsRunning()
{

    HANDLE hMutex = CreateMutexA(NULL, TRUE, "client-updater-mtx");
    DWORD dwErr = GetLastError();
    return dwErr == ERROR_ALREADY_EXISTS;
}
</code>```

Thanks!

Title: EnumProcesses - weird behaviour

Body:
I have some weird behaviour while using WIndows API function EnumProcesses()

I have a function to determine wether a process with a certain name is already running which delivery different results wether I open the .executable manually (doubleclick) or open it via shell.

When I open it via shell it detects its running only 1 time (itself) and all is fine. When I open it using doubleclick on the .exe file however the function is returning true (already running) because the loop lists me the same process twice.

For the following code-snipped it is to mention that:

this->thisExecutableFile

contains argv[0] (initialised from running the program) to get the own process-name as you can see here:

int main(int argc, char* argv[])
{
    ClientUpdate* update = ClientUpdate::getInstance();
    update->setThisExecutableFile(argv[0]);
    if (update->clientUpdateProcessIsRunning() == false) {
    ...

My goal is to find out if another instance of this process is already running and in this case exit it.

Here is my code:

bool ClientUpdate::clientUpdateProcessIsRunning()
{
    bool retVal = false;

    uint16_t processCount = 0;
    unsigned long aProcesses[1024], cbNeeded, cProcesses;
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
        return false;

    cProcesses = cbNeeded / sizeof(unsigned long);

    for(unsigned int i = 0; i < cProcesses; i++) {
        if (aProcesses[i] == 0) {
            continue;
        }

        HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
        wchar_t buffer[50];
        GetModuleBaseNameW(hProcess, 0, buffer, 50);
        CloseHandle(hProcess);

        std::wstring tempBuffer(buffer);
        std::string tempStringBuffer(tempBuffer.begin(), tempBuffer.end());
        boost::filesystem::path p(this->thisExecutableFile);
        if(_strcmpi(p.filename().string().c_str(), tempStringBuffer.c_str()) == 0) {
            processCount++;
            if(processCount > 1) {
                retVal = true;
                break;
            }
        }
    }

    return retVal;
}

I know that the base-path is different when using doubleclick on the file or calling it via shell. (shell produces only filename while doubleclick passes entire path + filename into argv[0]) but I fixed that issue using

boost::filesystem::path p(this->thisExecutableFile);
p.fileName()

Which returns the correct filename (without path) in both cases I checked using print.

I am pretty puzzled why EnumProcesses() returns me the same file twice when calling the file via doubleclick instead of shell. Its not spawning two processed and in taskmanager I dont see anything like this either.

Is this a bug or I need to know something about the method I couldnt find in docs?

Body:
Thanks to the hint by Richard Critten I was able to fix it. My method is much smaller now and easier. (Also probably also alot more performant then scanning entire process-stack.) :D

Here is the solution

bool ClientUpdate::clientUpdateProcessIsRunning()
{

    HANDLE hMutex = CreateMutexA(NULL, TRUE, "client-updater-mtx");
    DWORD dwErr = GetLastError();
    return dwErr == ERROR_ALREADY_EXISTS;
}

Thanks!


问:
how to add grand child element in xml child elements section C# XML
I want to add a 3rd level grand child section into my XML.

Before:

```<code><level1>
    <level2>
          <coolstuff name="name"/>
    </level2>
</level1>
</code>```

After:

```<code><level1>
    <level2>
          <stupidtags>
               <stupidtag name ="stupidname"/>
          <stupidtags>
          <coolstuff name="coolname"/>
    </level2>
</level1>
</code>```

How should I add the stupidtags into the level2 tag in C#?
I implement a little bit, how should i pass two level and let newNode append it that and it should above coolstuff tag?

```<code>XDocument doc = XDocument.Load(fileOfReportInXML);
XElement newNode= new XElement("stupidtags");
</code>```

答:
The below sample code should demonstrate how to add a node to an existing XML in a given location

```<code>var xml = new XmlDocument();
xml.Load("file.xml");               // fetch the existing XML

// create the grand child node to be inserted
var node = xml.CreateElement("level3");
node.SetAttribute("attrname", "attrvalue");
var level2Node = xml.SelectSingleNode("level1/level2"); // Use XPath to find the location of insertion

level2Node.PrependChild(node);      // Insert the Node in the grand child position

xml.Save("out.xml");                // store the new xml in a new file for demo
</code>```

Below is the content of file.xml and out.xml

D:\tmp>type file.xml
<level1>
    <level2>
          <coolstuff name="name"/>
    </level2>
</level1>

D:\tmp>type out.xml
<level1>
  <level2>
    <level3 attrname="attrvalue" />
    <coolstuff name="name" />
  </level2>
</level1>
```

As you notice, the XPath expression identifies the location for the insertion. XPath is a rich language so you can fine tune it further if you need.

Body:
I want to add a 3rd level grand child section into my XML.

Before:

<level1>
    <level2>
          <coolstuff name="name"/>
    </level2>
</level1>

After:

<level1>
    <level2>
          <stupidtags>
               <stupidtag name ="stupidname"/>
          <stupidtags>
          <coolstuff name="coolname"/>
    </level2>
</level1>

How should I add the stupidtags into the level2 tag in C#?
I implement a little bit, how should i pass two level and let newNode append it that and it should above coolstuff tag?

XDocument doc = XDocument.Load(fileOfReportInXML);
XElement newNode= new XElement("stupidtags");

Body:
The below sample code should demonstrate how to add a node to an existing XML in a given location

var xml = new XmlDocument();
xml.Load("file.xml");               // fetch the existing XML

// create the grand child node to be inserted
var node = xml.CreateElement("level3");
node.SetAttribute("attrname", "attrvalue");
var level2Node = xml.SelectSingleNode("level1/level2"); // Use XPath to find the location of insertion

level2Node.PrependChild(node);      // Insert the Node in the grand child position

xml.Save("out.xml");                // store the new xml in a new file for demo

Below is the content of file.xml and out.xml

D:\tmp>type file.xml
<level1>
    <level2>
          <coolstuff name="name"/>
    </level2>
</level1>

D:\tmp>type out.xml
<level1>
  <level2>
    <level3 attrname="attrvalue" />
    <coolstuff name="name" />
  </level2>
</level1>

As you notice, the XPath expression identifies the location for the insertion. XPath is a rich language so you can fine tune it further if you need.


问:
Angular table filter on inner array of an object

I am new the angular, what I am trying to do is applying filter on inner array of an object from table row, filter is working but works only for that td, not for the entire row, why is this happening, is there anything missing here? Any help is much appreciated.

plunker here:  http://plnkr.co/edit/lXxTS1A3zRCk6mdtw2JP?p=preview

答:
Use a filter function to pipe a second filter to your Project list:
http://plnkr.co/edit/ydKDEUUWZcI0Qt9fQxhB?p=preview

```<code>$scope.applyToTitle = function (title)
  {
    if($scope.support.code.length !== 0)
    {
      for(var i=0; i<$scope.tableObject.length; i++)
      {
        for(var j=0; j<$scope.tableObject[i].details.length; j++)
        {
          if(title.details[j].code == $scope.support.code)
          {
            return title;
          }
        }
      }
    }
    else
    {
      return title;
    }
  }
</code>```

And apply this filter by piping it after filter:search:

```<code><tr ng-repeat="item in tableObject | filter:search | filter: applyToTitle">
        <td>{{item.title}}</td>
...
</code>```

Body:
Use a filter function to pipe a second filter to your Project list:
http://plnkr.co/edit/ydKDEUUWZcI0Qt9fQxhB?p=preview

$scope.applyToTitle = function (title)
  {
    if($scope.support.code.length !== 0)
    {
      for(var i=0; i<$scope.tableObject.length; i++)
      {
        for(var j=0; j<$scope.tableObject[i].details.length; j++)
        {
          if(title.details[j].code == $scope.support.code)
          {
            return title;
          }
        }
      }
    }
    else
    {
      return title;
    }
  }

And apply this filter by piping it after filter:search:

<tr ng-repeat="item in tableObject | filter:search | filter: applyToTitle">
        <td>{{item.title}}</td>
...


问:
How to Make Header Menu Vertically Aligned & Icon aligned to the left
I'm trying to make a header for a webpage that has a horizontal menu tab (composed of links to other html files), but I find it hard to align the icon on the same horizontal row as the menu tab while keeping the icon and tabs aligned differently (icon to the left, tabs to the right). When I move the icon out of the same group as the links and use css to make them aligned differently, the result is the two (icon and tabs) being in separate rows. I even tried using the align attribute directly to the image tag but it made everything align to the left as well.

So here is my code so far, using a random logo image.

```<code><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
    <title>[Website-Name] | Home</title>
</head>
<style type="text/css">
    img {
        text-align: left;
    }
    ul {
        text-align: right;
        padding: 0px;
        margin: 0px
    }
    a{
        color: white;
        text-decoration: none; /* remove link underline*/
        font-size: 20px;
    }
    div/*MENU CSS*/ {
        background: black;
    }

    a:hover /* Change color mouse hover */,
    a:active {
        color: orange;
    }

    li { /*Space between tabs */
        display: inline;
        padding: 0px 25px 0px 25px; /* distance between menu tabs*/
            vertical-align: middle;
    }

</style>
<body>
    <nav>
    <div>
    <img src="icon.jpg">
        <ul>
            <li><a href="index.html">Home</a></li>
            <li><a href="drawing.html">Drawing</a></li>
            <li><a href="music.html">Music</a></li>
            <li><a href="handcrafted.html">Handcrafted</a></li>
            <li><a href="literature.html">Literature</a></li>
            <li><a href="search.html">Search</a></li>
        </ul>
    </div>
    </nav>
</body>
</html>
</code>```

So here is an image comparing what I would like the code to do and what the code (above) is actually doing:
https://i.stack.imgur.com/hTGob.jpg

And here is the icon.jpg used in the code above:
https://i.stack.imgur.com/qW4UU.jpg

Thanks in advance, and please ask if there is something you would like me to clarify on!

答:
```<code>li { /*Space between tabs */
    display: inline-block;
    padding: 0px 25px 0px 25px; /* distance between menu tabs*/
    vertical-align: central;
    line-height:100%;
    height:100%;
}
a{
    display: inline-block;
    line-height:100px;
    height:100%;
}
div/*MENU CSS*/ {
    background: black;
    height:100px;
}
img {
    text-align: left;
    height:100px;
}
ul {
    text-align: right;
    padding: 0px;
    margin: 0px;
    float:right;
    height:100%;
}
</code>```

Replace the following css elements, this assumes the image height is 100px so change all occurrences of that to the actual height of your image

Body:
I'm trying to make a header for a webpage that has a horizontal menu tab (composed of links to other html files), but I find it hard to align the icon on the same horizontal row as the menu tab while keeping the icon and tabs aligned differently (icon to the left, tabs to the right). When I move the icon out of the same group as the links and use css to make them aligned differently, the result is the two (icon and tabs) being in separate rows. I even tried using the align attribute directly to the image tag but it made everything align to the left as well.

So here is my code so far, using a random logo image.

<!DOCTYPE html>

<meta charset="UTF-8"/>
    <title>[Website-Name] | Home</title>

Home

Drawing

Music

Handcrafted

Literature

Search

So here is an image comparing what I would like the code to do and what the code (above) is actually doing:
https://i.stack.imgur.com/hTGob.jpg

And here is the icon.jpg used in the code above:
https://i.stack.imgur.com/qW4UU.jpg

Thanks in advance, and please ask if there is something you would like me to clarify on!

Body:
li { /*Space between tabs */
    display: inline-block;
    padding: 0px 25px 0px 25px; /* distance between menu tabs*/
    vertical-align: central;
    line-height:100%;
    height:100%;
}
a{
    display: inline-block;
    line-height:100px;
    height:100%;
}
div/*MENU CSS*/ {
    background: black;
    height:100px;
}
img {
    text-align: left;
    height:100px;
}
ul {
    text-align: right;
    padding: 0px;
    margin: 0px;
    float:right;
    height:100%;
}

Replace the following css elements, this assumes the image height is 100px so change all occurrences of that to the actual height of your image


问:
Regarding union and multiple integer values
I'm getting into C and I experimented with union. My code is the following:

```<code>#include <stdio.h>

union date {
 int year  ;
 char month;
 char day  ;
 };

int main() {
 union date birth;
 birth.year = 1984;
 birth.month = 7;
 birth.day = 28;
 printf("%d, %d, %d\n",birth.year, birth.month, birth.day);
 // return 1820,28,28
 return 0;
}
</code>```

1984 is written in binary as 0111 1100 0000

7 is written in binary as 0110

28 is written in binary as 0001 1100

I understand that because of union, birth.year has the value of 0111 0001 1100 which is 1820. But I do not understand why does birth.month return as value 28.

答:
A union stores all its members in the same space and the data present in that space corresponds to whichever member was written last. A union is exactly as large as its largest member. You don't mention your specific platform, but assuming a fairly recent GCC on a modern x86 Windows, MacOS, or desktop Linux, char is probably 8 bits and int is probably 32 bits, making your date union look something like this:

```<code>0000 0000 0000 0000 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/
</code>```

Let's walk through your use of union date birth, shall we? Starting with birth.year = 1984;, we have (keep in mind that x86 is little endian)

```<code>1100 0000 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/
</code>```

Then birth.month = 7;:

```<code>0000 0111 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/
</code>```

And finally, birth.day = 28;:

```<code>0001 1100 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/
</code>```

It should be clear that writing to any member of a union will overwrite at least part of all other members.

Contrast that with a struct, which has unique storage space for all its members, making it at least as large as all its members added together (it may be larger do to padding). If you replace all instances of union in your sample code with struct, you'd get something that looks like this in memory at the end:

```<code>1100 0000 0000 0111 0000 0000 0000 0000 0000 0111 0001 1100
\_______________ year ________________/ \ month / \_ day _/
</code>```

The data for each member is fully intact and can be correctly retrieved with birth.year, birth.month, or birth.day.

Body:
I'm getting into C and I experimented with union. My code is the following:

#include <stdio.h>

union date {
 int year  ;
 char month;
 char day  ;
 };

int main() {
 union date birth;
 birth.year = 1984;
 birth.month = 7;
 birth.day = 28;
 printf("%d, %d, %d\n",birth.year, birth.month, birth.day);
 // return 1820,28,28
 return 0;
}

1984 is written in binary as 0111 1100 0000

7 is written in binary as 0110

28 is written in binary as 0001 1100

I understand that because of union, birth.year has the value of 0111 0001 1100 which is 1820. But I do not understand why does birth.month return as value 28.

Body:
A union stores all its members in the same space and the data present in that space corresponds to whichever member was written last. A union is exactly as large as its largest member. You don't mention your specific platform, but assuming a fairly recent GCC on a modern x86 Windows, MacOS, or desktop Linux, char is probably 8 bits and int is probably 32 bits, making your date union look something like this:

0000 0000 0000 0000 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/

Let's walk through your use of union date birth, shall we? Starting with birth.year = 1984;, we have (keep in mind that x86 is little endian)

1100 0000 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/

Then birth.month = 7;:

0000 0111 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/

And finally, birth.day = 28;:

0001 1100 0000 0111 0000 0000 0000 0000
\_______________ year ________________/
\ month /
\_ day _/

It should be clear that writing to any member of a union will overwrite at least part of all other members.

Contrast that with a struct, which has unique storage space for all its members, making it at least as large as all its members added together (it may be larger do to padding). If you replace all instances of union in your sample code with struct, you'd get something that looks like this in memory at the end:

1100 0000 0000 0111 0000 0000 0000 0000 0000 0111 0001 1100
\_______________ year ________________/ \ month / \_ day _/

The data for each member is fully intact and can be correctly retrieved with birth.year, birth.month, or birth.day.


问:
Creating an interactive map in a web page
I would like to create an interactive map on my website where you can hover over a location and it will animate showing some links that are clickable and will take the client to another page displaying graphs about that location. What should I learn in order to achieve this? Thanks</p>

答:
I'm assuming you don't know much about web development yet, so start with some HTML tutorials (such as this, or this, or this) and Javascript tutorials (such as this, or this, or this). There's a number of ways of creating graphics on web pages (Chart.js is a great library that takes all the hard work out of it).

Then you might want to look into learning how the Google Maps API works. It's a pretty dang flexible API.