问:
Display file size with find command prior to the paths
I'm trying to find a way to combine the results that are displayed with the find command, e.g:

```<code>$find /home -name "requirements_*"

/home/cobayo/Obligatorio Test 2/requirements_richard
/home/cobayo/Obligatorio Test 2/requirements_paul
/home/cobayo/Obligatorio Test 2/requirements_george
/home/cobayo/Obligatorio Test 1/Subdirectorio/requirements_joe
</code>```

So here I get all of the paths of the files I am looking for, what I would like to do is to get the file size listed prior the paths.
For instance:

```<code>34K "/home/cobayo/Obligatorio Test 2/requirements_richard"
</code>```

I have some commands, even a little script does show me file sizes.

For example, this one:

```<code>find /home -name "requirements_*" -mtime -1 -print0 | du --files0-from=- -hc |
    tail -n1*
</code>```

And it shows the TOTAL size of all files with the name given as a parameter as results.

But then, I also have this little script:

```<code>FILENAME=$1
FILESIZE=$(stat -c%s "$FILENAME")
echo "Size of $FILENAME = $FILESIZE bytes."
</code>```

Which is perfect as I get the file in K of the specific file. I tried to mix them up using a list:

```<code>*for i in `find /home -name "requirements_*"`
do
echo `stat -c%s $i`
done*
</code>```

But I don't get the results Im looking for, in fact it tells me the files don't exist :(

答:
You could use -exec du -hs {} \;:

```<code>$ find -type f -exec du -hs {} \;
4.0K    ./proj-2/README.md
4.0K    ./proj-2/file.c
4.0K    ./proj-2/file.h
</code>```

or alternatively, if your find supports it:

```<code>find -type f -exec du -hs {} +
</code>```

which calls du just once.

Or -printf with the %k formatting parameter for the size in kB:

```<code>$ find -type f -printf '%kK\t%p\n'
4K      ./proj-2/README.md
4K      ./proj-2/file.c
4K      ./proj-2/file.h
</code>```

Manual references:

-exec, single file

-exec, multiple files

-printf

Body:
I'm trying to find a way to combine the results that are displayed with the find command, e.g:

$find /home -name "requirements_*"

/home/cobayo/Obligatorio Test 2/requirements_richard
/home/cobayo/Obligatorio Test 2/requirements_paul
/home/cobayo/Obligatorio Test 2/requirements_george
/home/cobayo/Obligatorio Test 1/Subdirectorio/requirements_joe

So here I get all of the paths of the files I am looking for, what I would like to do is to get the file size listed prior the paths.
For instance:

34K "/home/cobayo/Obligatorio Test 2/requirements_richard"

I have some commands, even a little script does show me file sizes.

For example, this one:

find /home -name "requirements_*" -mtime -1 -print0 | du --files0-from=- -hc |
    tail -n1*

And it shows the TOTAL size of all files with the name given as a parameter as results.

But then, I also have this little script:

FILENAME=$1
FILESIZE=$(stat -c%s "$FILENAME")
echo "Size of $FILENAME = $FILESIZE bytes."

Which is perfect as I get the file in K of the specific file. I tried to mix them up using a list:

*for i in `find /home -name "requirements_*"`
do
echo `stat -c%s $i`
done*

But I don't get the results Im looking for, in fact it tells me the files don't exist :(

Body:
You could use -exec du -hs {} \;:

$ find -type f -exec du -hs {} \;
4.0K    ./proj-2/README.md
4.0K    ./proj-2/file.c
4.0K    ./proj-2/file.h

or alternatively, if your find supports it:

find -type f -exec du -hs {} +

which calls du just once.

Or -printf with the %k formatting parameter for the size in kB:

$ find -type f -printf '%kK\t%p\n'
4K      ./proj-2/README.md
4K      ./proj-2/file.c
4K      ./proj-2/file.h

Manual references:

-exec, single file

-exec, multiple files

-printf


来源: stackexchange

问:
How to succinctly recycle case_when LHS variables for subsetting/indexing using cbind?
Example data:

```<code>tmp_df <-
    data.frame(x_coord = c(3,4), y_coord = c(3, 3))
# x_coord y_coord
# 1       3       3
# 2       4       3
</code>```

Consider the following which works as expected:

```<code>tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   x_coord + y_coord,
                               T ~ 0))
# x_coord y_coord lin_ind
# 1       3       3       6
# 2       4       3       0
</code>```

Now, let me use x_coord and y_coord to index into a 3x3 matrix:

```<code>tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(x_coord,
                                                               y_coord)],
                               T ~ NA_integer_)
    )
# Error in mutate_impl(.data, dots) :
#     Evaluation error: subscript out of bounds.
</code>```

This fails, for some reason the cbind part still takes a column index greater than 3.

This is a work-around that produces the expected result when tmp_df has this special form (i.e. two rows):

```<code>tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord < 4 & y_coord < 4)],
                                                               y_coord[(x_coord < 4 & y_coord < 4)])],
                               T ~ NA_integer_)
    )
# x_coord y_coord lin_ind
# 1       3       3       9
# 2       4       3      NA
</code>```

I cannot help but to think I am missing something with how case_when works.

The work-around also completely fails when tmp_df is more complicated:

```<code>tmp_df <-
    data.frame(x_coord = c(3,4, 3), y_coord = c(3, 3, 3))
</code>```

i.e. when there are just three rows:

```<code>> tmp_df %>%
+     mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
+                                    matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord < 4 & y_coord < 4)],
+                                                                y_coord[(x_coord < 4 & y_coord < 4)])],
+                                T ~ NA_integer_)
+     )
Error in mutate_impl(.data, dots) :
  Evaluation error: `(x_coord < 4 & y_coord < 4) ~ matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord <
    4 & y_coord < 4)], y_coord[(x_coord < 4 & y_coord < 4)])]` must be length 3 or one, not 2.
</code>```

Here is a work-around for the more complicated data frame that produces the expected result:

```<code>tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(pmin(x_coord, 3),
                                                               pmin(y_coord, 3))],
                               T ~ NA_integer_)
    )
# x_coord y_coord lin_ind
# 1       3       3       9
# 2       4       3      NA
# 3       3       3       9
</code>```

答:
If I understand you correctly, I think a good way to solve this is with one of purrr's map functions. Here you can iterative over x_coord and y_coord together and return an integer vector with map2_int. You can write a simple anonymous function (here done with the short ~ syntax) to apply to each set of x_coord and y_coord.

library(dplyr)
library(purrr)

df <- data.frame(x_coord = c(3,4, 3), y_coord = c(3, 3, 3))
mat <- matrix(1:9, nrow = 3)

df %>%
  mutate(
    lin_ind = map2_int(x_coord, y_coord, ~{
      if (.x < 4 && .y < 4) {
        mat[cbind(.x, .y)]
      } else {
        NA_integer_
      }
    })
  )

#>   x_coord y_coord lin_ind
#> 1       3       3       9
#> 2       4       3      NA
#> 3       3       3       9
```

ContentLicense: CC BY-SA 3.0

Body:
Example data:

tmp_df <-
    data.frame(x_coord = c(3,4), y_coord = c(3, 3))
# x_coord y_coord
# 1       3       3
# 2       4       3

Consider the following which works as expected:

tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   x_coord + y_coord,
                               T ~ 0))
# x_coord y_coord lin_ind
# 1       3       3       6
# 2       4       3       0

Now, let me use x_coord and y_coord to index into a 3x3 matrix:

tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(x_coord,
                                                               y_coord)],
                               T ~ NA_integer_)
    )
# Error in mutate_impl(.data, dots) :
#     Evaluation error: subscript out of bounds.

This fails, for some reason the cbind part still takes a column index greater than 3.

This is a work-around that produces the expected result when tmp_df has this special form (i.e. two rows):

tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord < 4 & y_coord < 4)],
                                                               y_coord[(x_coord < 4 & y_coord < 4)])],
                               T ~ NA_integer_)
    )
# x_coord y_coord lin_ind
# 1       3       3       9
# 2       4       3      NA

I cannot help but to think I am missing something with how case_when works.

The work-around also completely fails when tmp_df is more complicated:

tmp_df <-
    data.frame(x_coord = c(3,4, 3), y_coord = c(3, 3, 3))

i.e. when there are just three rows:

> tmp_df %>%
+     mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
+                                    matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord < 4 & y_coord < 4)],
+                                                                y_coord[(x_coord < 4 & y_coord < 4)])],
+                                T ~ NA_integer_)
+     )
Error in mutate_impl(.data, dots) :
  Evaluation error: `(x_coord < 4 & y_coord < 4) ~ matrix(1:9, nrow = 3)[cbind(x_coord[(x_coord <
    4 & y_coord < 4)], y_coord[(x_coord < 4 & y_coord < 4)])]` must be length 3 or one, not 2.

Here is a work-around for the more complicated data frame that produces the expected result:

tmp_df %>%
    mutate(lin_ind = case_when((x_coord < 4 & y_coord < 4) ~
                                   matrix(1:9, nrow = 3)[cbind(pmin(x_coord, 3),
                                                               pmin(y_coord, 3))],
                               T ~ NA_integer_)
    )
# x_coord y_coord lin_ind
# 1       3       3       9
# 2       4       3      NA
# 3       3       3       9


问:
Getting FRF from FFT
I have the FFT of a sensor output data. Is there any way to get frequncy response function FRF from this. I dont have any input data. Plz help.</p>

答:
Taking the IFFT (basically the FFT) of the FFT output data will give get you back into the time domain.

Sorry for the above answer, which doesn't address the question. To be more helpful, IIRC, the FRF is the ratio of the FFT of the response (output) to the FFT of the
excitation (input). Since you only have the FFT of the output, I'd say that there is no way to obtain the FRF from this alone.

ContentLicense: CC BY-SA 2.5

Title: Getting FRF from FFT


问:
node promises.all() doesnt work as expected
I'm trying to run a list of functions synchronously after a loop using promise.all() but my code doesn't work as expected.

Does someone know what I did wrong?

my code is :

```<code>var Promise = require('promise');
var promises = [];

for (var i = 0; i < 3; i++) {
    console.log('push promise ' + i);
    promises.push(foo(i));
}

Promise.all(promises)
        .then(function (data) {
            console.log("done");
        });

function foo(i) {
    return new Promise(function (resolve, reject) {
        console.log('---> foo i ' + i);
        resolve('done foo ' + i);

    });
}
</code>```

but the output is

```<code>push promise 0
---> foo i 0
push promise 1
---> foo i 1
push promise 2
---> foo i 2
done
</code>```

where I expect

```<code>push promise 0
push promise 1
push promise 2
---> foo i 0
---> foo i 1
---> foo i 2
done
</code>```

Thank you in advance.

答:
What's happening here is that when you call the promise constructor, the function being passed to it is being invoked during the construction call.
If you had async call being inside the promise (which is the intended use case), then it would create the behaviour you were expecting.

Here is my example code, using setTimeout as the async call, and note how the resolve call is made inside the async callback.

```<code>var promises = [];

for (var i = 0; i < 3; i++) {
    console.log('push promise ' + i);
    promises.push(foo(i));
}

Promise.all(promises)
        .then(function (data) {
            console.log("done");
        });

function foo(i) {
    return new Promise(function (resolve, reject) {
        // The async call is made inside the Promise
        setTimeout(()=> {
            console.log('---> foo i ' + i);
            // And the resolve call is made inside the callback function
            resolve('done foo ' + i);
        });
    });
}
</code>```

If you run this, you should get the output you desired (tested in chrome):

```<code>push promise 0
push promise 1
push promise 2
---> foo i 0
---> foo i 1
---> foo i 2
done
</code>```

Addendum: This only works (foo i 0, ... 1 ... 2 are in order) because the requests are all done immediately one after the other. If it was an ajax call, the foo statements would be printed in order of completion. So if request 2 finished before 0 or 1, you would see foo i 2 first. But done will only be visible when all the requests were resolved.

Body:
I'm trying to run a list of functions synchronously after a loop using promise.all() but my code doesn't work as expected.

Does someone know what I did wrong?

my code is :

var Promise = require('promise');
var promises = [];

for (var i = 0; i < 3; i++) {
    console.log('push promise ' + i);
    promises.push(foo(i));
}

Promise.all(promises)
        .then(function (data) {
            console.log("done");
        });

function foo(i) {
    return new Promise(function (resolve, reject) {
        console.log('---> foo i ' + i);
        resolve('done foo ' + i);

    });
}

but the output is

push promise 0
---> foo i 0
push promise 1
---> foo i 1
push promise 2
---> foo i 2
done

where I expect

push promise 0
push promise 1
push promise 2
---> foo i 0
---> foo i 1
---> foo i 2
done

Thank you in advance.

Body:
What's happening here is that when you call the promise constructor, the function being passed to it is being invoked during the construction call.
If you had async call being inside the promise (which is the intended use case), then it would create the behaviour you were expecting.

Here is my example code, using setTimeout as the async call, and note how the resolve call is made inside the async callback.

var promises = [];

for (var i = 0; i < 3; i++) {
    console.log('push promise ' + i);
    promises.push(foo(i));
}

Promise.all(promises)
        .then(function (data) {
            console.log("done");
        });

function foo(i) {
    return new Promise(function (resolve, reject) {
        // The async call is made inside the Promise
        setTimeout(()=> {
            console.log('---> foo i ' + i);
            // And the resolve call is made inside the callback function
            resolve('done foo ' + i);
        });
    });
}

If you run this, you should get the output you desired (tested in chrome):

push promise 0
push promise 1
push promise 2
---> foo i 0
---> foo i 1
---> foo i 2
done

Addendum: This only works (foo i 0, ... 1 ... 2 are in order) because the requests are all done immediately one after the other. If it was an ajax call, the foo statements would be printed in order of completion. So if request 2 finished before 0 or 1, you would see foo i 2 first. But done will only be visible when all the requests were resolved.


问:
Real time video streaming to mobile browsers
I have a website where users can live video/audio stream to viewers in their "chat room". Currently I'm relying on RTMP/HLS and am using Wowza media server. I need a low latency option for mobile browsers.

RTMP provides that where flash is enabled, but HLS has an 8-10 second delay (optimized). I could implement WebRTC but playback isn't supported in any IOS browsers.

What are my options as far as protocols/techniques go?

RTMP - dying and only available with plugin

HLS (and other HTTP protocols) - too much latency

答:
HLS (and other HTTP protocols) - too much latency

You mean, HLS and other segmented protocols.

HTTP isn't the problem, the fact that you're writing out ~4 second chunks is.

You can use HTTP Progressive and easily get your latency down to 300ms.

I could implement WebRTC but playback isn't supported in any IOS browsers.

This is no longer the case.  Safari 11 supports WebRTC, and I suspect all other iOS browsers (which are backed by Safari web views) do as well but I haven't personally tested.


问:
Controling Opera by Python and Selenium
I would like to operate Opera by Python + Selenium automatically.

By reference to URL below, I wrote a script below.

Drive Opera with selenium python

```<code>from selenium import webdriver
from selenium.webdriver.chrome import service

webdriver_service = service.Service('/usr/bin/opera')

webdriver_service.start()

capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}

browser = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)

response = browser.get('https://www.facebook.com/')
</code>```

By this script, Opera is launched but facebook page does not open.

How should I fix? Please help me.

Settings are below.

Ubuntu 16.04,
Python 3.5.2,
Selenium 3.6.0,
Opera 49.0

答:
```<code>capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}
</code>```

Since you're setting this, I assume you need this to access the network. But, you didn't set it to the webdriver capabilities

```<code>capabilities = webdriver.DesiredCapabilities.OPERA
capabilities ['operaOptions'] = { 'debuggerAddress': "localhost:1212" }
browser = webdriver.Remote(webdriver_service.service_url, capabilities)
</code>```

Title: Controling Opera by Python and Selenium

Body:
I would like to operate Opera by Python + Selenium automatically.

By reference to URL below, I wrote a script below.

Drive Opera with selenium python

from selenium import webdriver
from selenium.webdriver.chrome import service

webdriver_service = service.Service('/usr/bin/opera')

webdriver_service.start()

capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}

browser = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)

response = browser.get('https://www.facebook.com/')

By this script, Opera is launched but facebook page does not open.

How should I fix? Please help me.

Settings are below.

Ubuntu 16.04,
Python 3.5.2,
Selenium 3.6.0,
Opera 49.0

Body:
capabilities = { 'operaOptions': { 'debuggerAddress': "localhost:1212" }}

Since you're setting this, I assume you need this to access the network. But, you didn't set it to the webdriver capabilities

capabilities = webdriver.DesiredCapabilities.OPERA
capabilities ['operaOptions'] = { 'debuggerAddress': "localhost:1212" }
browser = webdriver.Remote(webdriver_service.service_url, capabilities)


问:
Remove all HTML tags *AND* content from json response
I am aware of this solution - str.replace(/<\/?[^>]+>/gi, '') - which removes the HTML tags from json response.

```<code>{"fdfd":4}<p>fdfdf</p> -> {"fdfd":4} fdfdf
</code>```

However i want to remove all content within the HTML, script tags as well for which i am seeking a solution.
Requirement -

```<code>{"fdfd":4}<p>fdfdf</p> -> {"fdfd":4}
</code>```

答:
Use string match and keep only those characters which are inside {}

var str = '{"fdfd":4}
fdfdf
'
var m = str.match(/{(.*)}/g)[0]
console.log(m)```

Body:
I am aware of this solution - str.replace(/<\/?[^>]+>/gi, '') - which removes the HTML tags from json response.

{"fdfd":4}
fdfdf
 -> {"fdfd":4} fdfdf

However i want to remove all content within the HTML, script tags as well for which i am seeking a solution.
Requirement -

{"fdfd":4}
fdfdf
 -> {"fdfd":4}

Body:
Use string match and keep only those characters which are inside {}

var str = '{"fdfd":4}<p>fdfdf</p>'
var m = str.match(/{(.*)}/g)[0]
console.log(m)


问:
How to write csv file and open in MS.Excel in charset UTF-8
I have detect my value to write is Thai language and I will write to CSV file but when I use fwrite and save .CSV file and open this CSV file in Excel.I see my text about "เธฅเธนเธเธเธฅเธดเนเธ,เธชเธฃเนเธฒเธเธฅเธฒเธข" Below this code

```<code>$xfile =fopen($filename,"w");
foreach( $data as $itm ){
     $outstr="";
     foreach($itm as $key=>$str){
            $val =str_replace("\r\n","",$str);
            val =str_replace("\t\t","",$val);
            $val =str_replace('"',"'",$val);
            $outstr=$outstr.'"'.$val.'"'.$clm;
            //dump(mb_detect_encoding($outstr));die(); --Result UTF-8
     }
$outstr=substr($outstr,0,strlen($outstr)-1);
fwrite($xfile,$outstr."\r\n"); //Newline
fclose($xfile);
</code>```

I feel stupid Or i forgot something. Please help

答:
Try mb_convert_encoding before you write.

```<code>$xfile =fopen($filename,"w");
foreach( $data as $itm ){
     $outstr="";
     foreach($itm as $key=>$str){
            $val =str_replace("\r\n","",$str);
            val =str_replace("\t\t","",$val);
            $val =str_replace('"',"'",$val);
            $outstr=$outstr.'"'.$val.'"'.$clm;
            //dump(mb_detect_encoding($outstr));die(); --Result UTF-8
     }
$outstr=substr($outstr,0,strlen($outstr)-1);
$outstr= mb_convert_encoding($outstr, "UTF-8");
fwrite($xfile,$outstr."\r\n"); //Newline
fclose($xfile);
</code>```

Check detail here PHP_mb_convert_encoding

Body:
I have detect my value to write is Thai language and I will write to CSV file but when I use fwrite and save .CSV file and open this CSV file in Excel.I see my text about "เธฅเธนเธเธเธฅเธดเนเธ,เธชเธฃเนเธฒเธเธฅเธฒเธข" Below this code

$xfile =fopen($filename,"w");
foreach( $data as $itm ){
     $outstr="";
     foreach($itm as $key=>$str){
            $val =str_replace("\r\n","",$str);
            val =str_replace("\t\t","",$val);
            $val =str_replace('"',"'",$val);
            $outstr=$outstr.'"'.$val.'"'.$clm;
            //dump(mb_detect_encoding($outstr));die(); --Result UTF-8
     }
$outstr=substr($outstr,0,strlen($outstr)-1);
fwrite($xfile,$outstr."\r\n"); //Newline
fclose($xfile);

I feel stupid Or i forgot something. Please help

Body:
Try mb_convert_encoding before you write.

$xfile =fopen($filename,"w");
foreach( $data as $itm ){
     $outstr="";
     foreach($itm as $key=>$str){
            $val =str_replace("\r\n","",$str);
            val =str_replace("\t\t","",$val);
            $val =str_replace('"',"'",$val);
            $outstr=$outstr.'"'.$val.'"'.$clm;
            //dump(mb_detect_encoding($outstr));die(); --Result UTF-8
     }
$outstr=substr($outstr,0,strlen($outstr)-1);
$outstr= mb_convert_encoding($outstr, "UTF-8");
fwrite($xfile,$outstr."\r\n"); //Newline
fclose($xfile);

Check detail here PHP_mb_convert_encoding


答:
If you do not put the variable $i between double quotes the spaces will be interpreted as separator and your command will try to asses the following files independently :

```<code>/home/cobayo/Obligatorio
Test
1/Subdirectorio/requirements_joe
/home/cobayo/Obligatorio
Test
2/requirements_richard
/home/cobayo/Obligatorio
Test
2/requirements_paul
/home/cobayo/Obligatorio
Test
2/requirements_george
</code>```

what gives you the error: files don't exist

You can try:

```<code>find . -name "requirements_*" -print0 | xargs -0 -I {} bash -c "echo -n 'Size of {} = '  && stat -c%s '{}' | tr -d '\n' && echo ' bytes.'"
</code>```

Title: Display file size with find command prior to the paths

Body:
If you do not put the variable $i between double quotes the spaces will be interpreted as separator and your command will try to asses the following files independently :

/home/cobayo/Obligatorio
Test
1/Subdirectorio/requirements_joe
/home/cobayo/Obligatorio
Test
2/requirements_richard
/home/cobayo/Obligatorio
Test
2/requirements_paul
/home/cobayo/Obligatorio
Test
2/requirements_george

what gives you the error: files don't exist

You can try:

find . -name "requirements_*" -print0 | xargs -0 -I {} bash -c "echo -n 'Size of {} = '  && stat -c%s '{}' | tr -d '\n' && echo ' bytes.'"


问:
forms authentication and deny access to all files
I have created a "restricted" page with the forms authentication and it's working well.

```<code><authentication mode="Forms">
    <forms loginUrl="login.aspx" defaultUrl="documents.aspx" />
</authentication>

<location path="documents.aspx">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>
</code>```

I would like to deny access to a folder and all the files that it contains depending on this authentication. Basically, documents.apsx has a document list that you can download. If I try to access to www.mywebsite.com/documents I'm automatically redirect to the login.aspx. I added the following Web.config in my Documents folder:

```<code><?xml version="1.0"?>
<configuration>

  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

</configuration>
</code>```

However, if I know the path of a document, for example www.mywebsite.com/documents/test.pdf I can access to this file.

My question is: How can I deny access to all the files in the Document folder if you are not authenticated?

答:
Put all your doucments PDF in a folder and set restriction on that folder like this:

```<code><location path="FolderName">
<system.web>
    <authorization>
        <deny users="?"/>
    </authorization>
</system.web>
</code>```

Body:
I have created a "restricted" page with the forms authentication and it's working well.

<authentication mode="Forms">
    <forms loginUrl="login.aspx" defaultUrl="documents.aspx" />
</authentication>

<location path="documents.aspx">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

I would like to deny access to a folder and all the files that it contains depending on this authentication. Basically, documents.apsx has a document list that you can download. If I try to access to www.mywebsite.com/documents I'm automatically redirect to the login.aspx. I added the following Web.config in my Documents folder:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

</configuration>

However, if I know the path of a document, for example www.mywebsite.com/documents/test.pdf I can access to this file.

My question is: How can I deny access to all the files in the Document folder if you are not authenticated?

Body:
Put all your doucments PDF in a folder and set restriction on that folder like this:

<location path="FolderName">
<system.web>
    <authorization>
        <deny users="?"/>
    </authorization>
</system.web>


问:
Why is my method looping without a loop?
I can't seem to figure out why my addRecord() method is looping. To be specific, it only loops at the "Enter Sales ID>>" at the first else of my if/else in the method. I have tried just invoking the programMenu() method at the end of the code, but then the compiler just keeps trying to run both. This method should only execute when "a" is received at the switch case statement, but it runs when both "a" AND "c" are entered, and then just keeps looping to the same else statement at "Enter Sales ID>>".

My method looks like this:

```<code>public static int addRecord(Salesperson[]salesPeopleArray, int
numOfSalesPpl)
    {
        String name=null;
        String idNum;
        double salesAmt = 0;
        String response;
        numOfSalesPpl = 0;
        final int MAX_LIMIT=20;
        final int ID_NUM_LIMIT = 8;

        if(numOfSalesPpl == MAX_LIMIT)
        {
            System.out.print("Database has reached capacity.");
            System.out.print(" Please delete a record before ");
            System.out.println("adding to the database.");
        }
        else
        System.out.print("Enter Sales ID:>> ");
        idNum = userInput.nextLine();

        if(idNum.length() != ID_NUM_LIMIT)
        {
           System.out.println(">>>>>Sales ID must be 8 digits<<<<<<");
           programMenu();
        }
        else
        {
           System.out.print("Please enter name: >> ");
           name = userInput.nextLine();
           System.out.print("Sales amount : >> ");
           salesAmt = userInput.nextDouble();
           salesPeopleArray[numOfSalesPpl] = new Salesperson(name,
idNum,salesAmt);
           ++numOfSalesPpl;
           userInput.nextLine();
           System.out.print("Do you want to display database> Y/N >>");
           response = userInput.nextLine();
           if(response.equals("y"))

           displayDatabase(salesPeopleArray, numOfSalesPpl);
    }

    return numOfSalesPpl;
    }
</code>```

My switch case looks like this:

```<code>String selection = programMenu();
   boolean loop = true;

     do
       {
          switch(selection)
          {
               case "A":
               case "a":
                  addRecord(salesPeopleArray, numOfSalesPpl);
                  break;

                case "C":
                case "c":
                   changeRecord(numOfSalesPpl, salesPeopleArray);
                   break;

                case "Q":
                case "q":
                System.out.print("You Are Leaving Database");
                System.out.print("   ");
                loop = false;
                break;
           }
       }
     while(loop);

}
</code>```

My programMenu() method looks like this:

```<code>public static String programMenu()
    {
        String selection;
    do

        {
         System.out.println("====================================");
         System.out.println("(A)dd a Record");
         System.out.println("(C)hange a Record");
         System.out.println("(Q)uit Database");
         System.out.print("Enter selection: >> ");
         selection = userInput.nextLine();
            if(!selection.equalsIgnoreCase("a") &&
!selection.equalsIgnoreCase("c") && !selection.equalsIgnoreCase("q"))
            System.out.println(">>>>Invalid Selection<<<<");
         System.out.println("====================================");

        }
       while(!selection.equalsIgnoreCase("a") &&
!selection.equalsIgnoreCase("c") && !selection.equalsIgnoreCase("q"));

        return selection;
}

    }
</code>```

答:
Here your code is only one time getting user input("A/a") then after gone to loop because "selection" in has already value "A" so. when you
Put this line "String selection = programMenu();"  inside the loop, looping time ask User Input and you can change your switch case statement.

```<code>  boolean loop = true;
     do
       {
          String selection = programMenu();
          switch(selection)
          {
               case "A":
               case "a":
                  addRecord(salesPeopleArray, numOfSalesPpl);
                  break;

                case "C":
                case "c":
                   changeRecord(numOfSalesPpl, salesPeopleArray);
                   break;

                case "Q":
                case "q":
                System.out.print("You Are Leaving Database");
                System.out.print("   ");
                loop = false;
                break;
           }
       }
     while(loop);
}
</code>```

Body:
I can't seem to figure out why my addRecord() method is looping. To be specific, it only loops at the "Enter Sales ID>>" at the first else of my if/else in the method. I have tried just invoking the programMenu() method at the end of the code, but then the compiler just keeps trying to run both. This method should only execute when "a" is received at the switch case statement, but it runs when both "a" AND "c" are entered, and then just keeps looping to the same else statement at "Enter Sales ID>>".

My method looks like this:

public static int addRecord(Salesperson[]salesPeopleArray, int
numOfSalesPpl)
    {
        String name=null;
        String idNum;
        double salesAmt = 0;
        String response;
        numOfSalesPpl = 0;
        final int MAX_LIMIT=20;
        final int ID_NUM_LIMIT = 8;

        if(numOfSalesPpl == MAX_LIMIT)
        {
            System.out.print("Database has reached capacity.");
            System.out.print(" Please delete a record before ");
            System.out.println("adding to the database.");
        }
        else
        System.out.print("Enter Sales ID:>> ");
        idNum = userInput.nextLine();

        if(idNum.length() != ID_NUM_LIMIT)
        {
           System.out.println(">>>>>Sales ID must be 8 digits<<<<<<");
           programMenu();
        }
        else
        {
           System.out.print("Please enter name: >> ");
           name = userInput.nextLine();
           System.out.print("Sales amount : >> ");
           salesAmt = userInput.nextDouble();
           salesPeopleArray[numOfSalesPpl] = new Salesperson(name,
idNum,salesAmt);
           ++numOfSalesPpl;
           userInput.nextLine();
           System.out.print("Do you want to display database> Y/N >>");
           response = userInput.nextLine();
           if(response.equals("y"))

           displayDatabase(salesPeopleArray, numOfSalesPpl);
    }

    return numOfSalesPpl;
    }

My switch case looks like this:

String selection = programMenu();
   boolean loop = true;

     do
       {
          switch(selection)
          {
               case "A":
               case "a":
                  addRecord(salesPeopleArray, numOfSalesPpl);
                  break;

                case "C":
                case "c":
                   changeRecord(numOfSalesPpl, salesPeopleArray);
                   break;

                case "Q":
                case "q":
                System.out.print("You Are Leaving Database");
                System.out.print("   ");
                loop = false;
                break;
           }
       }
     while(loop);

}

My programMenu() method looks like this:

public static String programMenu()
    {
        String selection;
    do

        {
         System.out.println("====================================");
         System.out.println("(A)dd a Record");
         System.out.println("(C)hange a Record");
         System.out.println("(Q)uit Database");
         System.out.print("Enter selection: >> ");
         selection = userInput.nextLine();
            if(!selection.equalsIgnoreCase("a") &&
!selection.equalsIgnoreCase("c") && !selection.equalsIgnoreCase("q"))
            System.out.println(">>>>Invalid Selection<<<<");
         System.out.println("====================================");

        }
       while(!selection.equalsIgnoreCase("a") &&
!selection.equalsIgnoreCase("c") && !selection.equalsIgnoreCase("q"));

        return selection;
}

    }

Body:
Here your code is only one time getting user input("A/a") then after gone to loop because "selection" in has already value "A" so. when you
Put this line "String selection = programMenu();"  inside the loop, looping time ask User Input and you can change your switch case statement.

  boolean loop = true;
     do
       {
          String selection = programMenu();
          switch(selection)
          {
               case "A":
               case "a":
                  addRecord(salesPeopleArray, numOfSalesPpl);
                  break;

                case "C":
                case "c":
                   changeRecord(numOfSalesPpl, salesPeopleArray);
                   break;

                case "Q":
                case "q":
                System.out.print("You Are Leaving Database");
                System.out.print("   ");
                loop = false;
                break;
           }
       }
     while(loop);
}


问:
Styling a Button in javascript
I have a button which is generated in this list. I want to style the button to be a bootstrap button. How would I go about doing so? I have posted my javascript below. (This cannot be done in HTML because the button is generated after another JS method executes.) I would also like to make the JS methods re-usable (where I don't need to make 4 methods to do the same thing.) If anyone could help me out it would be awesome!!

// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  myNodelist[i].appendChild(span);
}

// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
  close[i].onclick = function() {
    var div = this.parentElement;
    div.style.display = "none";
  }
}

// Create a new list item when clicking on the "Add" button
function newElement1() {
  var li = document.createElement("div");
  var inputValue = document.getElementById("myInput1").value;
  var inputValueB = document.getElementById("myInput1B").value;

  var t = document.createTextNode(inputValue);
  var space = document.createTextNode("             ");
  var tB = document.createTextNode(inputValueB);

  li.appendChild(tB);
  li.appendChild(space);
  li.appendChild(t);

  if (inputValue === '') {
    alert("You must input an item!");
  } else {
    document.getElementById("myUL1").appendChild(li);
  }
  document.getElementById("myInput1").value = "";
  document.getElementById("myInput1B").value = ""

  // here is the button logic
  var btn = document.createElement("button");

  var txt = document.createTextNode("Bought");
  btn.appendChild(txt);
  li.appendChild(btn);

  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  li.appendChild(span);

  for (i = 0; i < close.length; i++) {
    close[i].onclick = function() {
      var div = this.parentElement;
      div.style.display = "none";
    }
  }
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>/* Create three equal columns that floats next to each other */

.column {
  float: left;
  width: 25%;
  padding: 10px;
  height: 300px;
  /* Should be removed. Only for demonstration */
}

/* Clear floats after the columns */

.row:after {
  content: "";
  display: table;
  clear: both;
}

.logo {
  right: 90%;
}

/* Remove margins and padding from the list */

ul {
  margin: 0;
  padding: 0;
}

/* Style the list items */

ul li {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  background: rgba(0, 143, 149, 0.6);
  font-size: 18px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  transition: 0.2s;
  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

ul>div {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  background: rgba(0, 143, 149, 0.59);
  font-size: 18px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  transition: 0.2s;
  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Style the close button */

.close {
  position: absolute;
  right: 0;
  top: 0;
  padding: 12px 16px 12px 16px;
}

.close:hover {
  background-color: rgba(233, 176, 0, 0.85);
  color: black;
  padding: 12px 16px 12px 16px;
}

/* Style the header */

.header1 {
  background-color: rgba(0, 143, 149, 0.76);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

.header2 {
  background-color: rgba(233, 176, 0, 0.85);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

.header3 {
  background-color: rgba(226, 78, 66, 0.76);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

/* Clear floats after the header */

.header1:after,
.header2:after,
.header3:after {
  content: "";
  display: table;
  clear: both;
}

/* Style the input */

input {
  border: none;
  width: 75%;
  padding: 10px;
  float: left;
  font-size: 16px;
}

/* Style the "Add" button */

.addBtn {
  padding: 10px;
  width: 75%;
  background: rgb(254, 166, 128);
  color: #fff1d9;
  float: left;
  text-align: center;
  font-size: 16px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  cursor: pointer;
  transition: 0.3s;
}

.addBtn:hover {
  background-color: rgb(228, 148, 122);
}

/********* USER PROFILE ********/

#myInput {
  border-box: box-sizing;
  background-position: 14px 12px;
  background-repeat: no-repeat;
  font-size: 16px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  padding: 14px 20px 12px 45px;
  border: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: rgba(254, 166, 128, 0.68);
  min-width: 230px;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown a:hover {
  background-color: rgba(235, 110, 128, 0.65)
}

.show {
  display: block;
}

/* The Modal (background) */

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

Amir's List

      <input type="text" id="myInput1" placeholder="Item...">
      <input type="text" id="myInput1B" placeholder="Brand/Quantity...">
      Add

```

答: When you are creating the button in JS, add the bootstrap classes in the button. That should do the work.</p>

Title: Styling a Button in javascript

Body:
I have a button which is generated in this list. I want to style the button to be a bootstrap button. How would I go about doing so? I have posted my javascript below. (This cannot be done in HTML because the button is generated after another JS method executes.) I would also like to make the JS methods re-usable (where I don't need to make 4 methods to do the same thing.) If anyone could help me out it would be awesome!!

// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  myNodelist[i].appendChild(span);
}

// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
  close[i].onclick = function() {
    var div = this.parentElement;
    div.style.display = "none";
  }
}

// Create a new list item when clicking on the "Add" button
function newElement1() {
  var li = document.createElement("div");
  var inputValue = document.getElementById("myInput1").value;
  var inputValueB = document.getElementById("myInput1B").value;

  var t = document.createTextNode(inputValue);
  var space = document.createTextNode("             ");
  var tB = document.createTextNode(inputValueB);

  li.appendChild(tB);
  li.appendChild(space);
  li.appendChild(t);

  if (inputValue === '') {
    alert("You must input an item!");
  } else {
    document.getElementById("myUL1").appendChild(li);
  }
  document.getElementById("myInput1").value = "";
  document.getElementById("myInput1B").value = ""

  // here is the button logic
  var btn = document.createElement("button");

  var txt = document.createTextNode("Bought");
  btn.appendChild(txt);
  li.appendChild(btn);

  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  li.appendChild(span);

  for (i = 0; i < close.length; i++) {
    close[i].onclick = function() {
      var div = this.parentElement;
      div.style.display = "none";
    }
  }
}

/* Create three equal columns that floats next to each other */

.column {
  float: left;
  width: 25%;
  padding: 10px;
  height: 300px;
  /* Should be removed. Only for demonstration */
}

/* Clear floats after the columns */

.row:after {
  content: "";
  display: table;
  clear: both;
}

.logo {
  right: 90%;
}

/* Remove margins and padding from the list */

ul {
  margin: 0;
  padding: 0;
}

/* Style the list items */

ul li {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  background: rgba(0, 143, 149, 0.6);
  font-size: 18px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  transition: 0.2s;
  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

ul>div {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  background: rgba(0, 143, 149, 0.59);
  font-size: 18px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  transition: 0.2s;
  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Style the close button */

.close {
  position: absolute;
  right: 0;
  top: 0;
  padding: 12px 16px 12px 16px;
}

.close:hover {
  background-color: rgba(233, 176, 0, 0.85);
  color: black;
  padding: 12px 16px 12px 16px;
}

/* Style the header */

.header1 {
  background-color: rgba(0, 143, 149, 0.76);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

.header2 {
  background-color: rgba(233, 176, 0, 0.85);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

.header3 {
  background-color: rgba(226, 78, 66, 0.76);
  padding: 30px 40px;
  color: white;
  text-align: center;
}

/* Clear floats after the header */

.header1:after,
.header2:after,
.header3:after {
  content: "";
  display: table;
  clear: both;
}

/* Style the input */

input {
  border: none;
  width: 75%;
  padding: 10px;
  float: left;
  font-size: 16px;
}

/* Style the "Add" button */

.addBtn {
  padding: 10px;
  width: 75%;
  background: rgb(254, 166, 128);
  color: #fff1d9;
  float: left;
  text-align: center;
  font-size: 16px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  cursor: pointer;
  transition: 0.3s;
}

.addBtn:hover {
  background-color: rgb(228, 148, 122);
}

/********* USER PROFILE ********/

#myInput {
  border-box: box-sizing;
  background-position: 14px 12px;
  background-repeat: no-repeat;
  font-size: 16px;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
  padding: 14px 20px 12px 45px;
  border: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: rgba(254, 166, 128, 0.68);
  min-width: 230px;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  font-family: "Avenir W01", "futura", "Lucida grande", sans-serif;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown a:hover {
  background-color: rgba(235, 110, 128, 0.65)
}

.show {
  display: block;
}

/* The Modal (background) */

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

Amir's List

      <input type="text" id="myInput1" placeholder="Item...">
      <input type="text" id="myInput1B" placeholder="Brand/Quantity...">
      Add


问:
How to enforce float in decimal format when encoding to JSON in Go
I have a big.float which I'm encoding into JSON . However the JSON always end up showing the float in scientific notation rater than decimal notation. I can fix this by changing the JSON to be a string rather than a number and using float.Text('f'), however I would really prefer to keep the type as a number.

I was a taking a look at float.Format but I don't believe this is suitable.

A really condensed gist of what I'm doing is below. I do a lot more modification of the value of supply before encoding it to json.

```<code>type TokenSupply struct {
   TotalSupply  *big.Float  `json:"totalSupply, omitempty"`
}
supply := Float.NewFloat(1000000)
json.NewEncoder(w).Encode(TokenSupply{supply})
</code>```

This returns:

```<code>{"totalSupply":"1e+06"}
</code>```

答:
big.Float is marshaled to string when converted to a JSON type

https://golang.org/pkg/encoding/json/#Marshal

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON. If no MarshalJSON method is present but the value implements encoding.TextMarshaler instead, Marshal calls its MarshalText method and encodes the result as a JSON string. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of UnmarshalJSON.

https://golang.org/pkg/math/big/#Float.MarshalText

```<code>func (x *Float) MarshalText() (text []byte, err error)
</code>```

What can you do about it?

since your float may be more than 64 bits it won't play well with other languages that have to read the JSON value as a number. I'd suggest you keep the number as a string.

Body:
I have a big.float which I'm encoding into JSON . However the JSON always end up showing the float in scientific notation rater than decimal notation. I can fix this by changing the JSON to be a string rather than a number and using float.Text('f'), however I would really prefer to keep the type as a number.

I was a taking a look at float.Format but I don't believe this is suitable.

A really condensed gist of what I'm doing is below. I do a lot more modification of the value of supply before encoding it to json.

type TokenSupply struct {
   TotalSupply  *big.Float  `json:"totalSupply, omitempty"`
}
supply := Float.NewFloat(1000000)
json.NewEncoder(w).Encode(TokenSupply{supply})

This returns:

{"totalSupply":"1e+06"}

Body:
big.Float is marshaled to string when converted to a JSON type

https://golang.org/pkg/encoding/json/#Marshal

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON. If no MarshalJSON method is present but the value implements encoding.TextMarshaler instead, Marshal calls its MarshalText method and encodes the result as a JSON string. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of UnmarshalJSON.

https://golang.org/pkg/math/big/#Float.MarshalText

func (x *Float) MarshalText() (text []byte, err error)

What can you do about it?

since your float may be more than 64 bits it won't play well with other languages that have to read the JSON value as a number. I'd suggest you keep the number as a string.


问:
How to save image along with DPI information into clipboard?
It looks like Bitmap.SetResolution() has no effect on clipboard, see the following trivial code:

Dim bitmap1 As Image = New System.Drawing.Bitmap(100, 100)
Using gr As Graphics = Graphics.FromImage(bitmap1)
    gr.FillRectangle(System.Drawing.Brushes.Black, 0, 0, 99, 99)
    gr.FillRectangle(System.Drawing.Brushes.White, 10, 10, 89, 89)
End Using

bitmap1.SetResolution(150, 150)

Clipboard.SetImage(bitmap1)                              ' DPI not set
bitmap1.Save("D:\bitmap1.png", imaging.ImageFormat.Png)  ' DPI set
```

The file contains correctly set image DPI. In the clipbaord, it is not present.

Proof:  In clipboard dump (image inserted into clipboard by IrfanView), see DIB bitmap header of 60 × 120 DPI (yellow=horizontal DPI, green=vertical DPI):

But after inserting image using .net's Clipboard.SetImage(), both these numbers are 0.

My goal: be able to paste image into Microsoft Word with proper size (taken from DPI and dimensions). Without DPI set in the clipboard, the image is too big after pasting. But it contains barcode already with 1 bar = 1 px resolution, so I cannot sample it down.

How to verify DPI: Either by clipboard viewer OR by opening the image in image editor which shows image properties. If you have only Word, drag&drop the image over the document. Image size of the above example should have been 1.69×1.69 cm – and if taken from file, it actually is. If from .NET-made clipboard, it isn't.

What I am missing in process of setting the image DPI?

(C# or VB, whatever you prefer.)

答:
The work-around I found was to create a temporary file and push that into the Clipboard instead of using SetImage:

```<code>  bitmap1.SetResolution(300, 300)
  Dim strTempFilename As String = TempDirectory & "\mytempfilename.TIF"
  bitmap1.Save(strTempFilename, Imaging.ImageFormat.Tiff)
  Dim DataObject As New DataObject()
  Dim file(0) As String
  file(0) = strTempFilename
  DataObject.SetData(DataFormats.FileDrop, True, file)
  Clipboard.SetDataObject(DataObject)
</code>```

I've omitted all the error checking etc. for brevity. The downside of this approach is that there is a temporary file to delete afterwards.

Body:
It looks like Bitmap.SetResolution() has no effect on clipboard, see the following trivial code:

Dim bitmap1 As Image = New System.Drawing.Bitmap(100, 100)
Using gr As Graphics = Graphics.FromImage(bitmap1)
    gr.FillRectangle(System.Drawing.Brushes.Black, 0, 0, 99, 99)
    gr.FillRectangle(System.Drawing.Brushes.White, 10, 10, 89, 89)
End Using

bitmap1.SetResolution(150, 150)

Clipboard.SetImage(bitmap1)                              ' DPI not set
bitmap1.Save("D:\bitmap1.png", imaging.ImageFormat.Png)  ' DPI set

The file contains correctly set image DPI. In the clipbaord, it is not present.

Proof:  In clipboard dump (image inserted into clipboard by IrfanView), see DIB bitmap header of 60 × 120 DPI (yellow=horizontal DPI, green=vertical DPI):

But after inserting image using .net's Clipboard.SetImage(), both these numbers are 0.

My goal: be able to paste image into Microsoft Word with proper size (taken from DPI and dimensions). Without DPI set in the clipboard, the image is too big after pasting. But it contains barcode already with 1 bar = 1 px resolution, so I cannot sample it down.

How to verify DPI: Either by clipboard viewer OR by opening the image in image editor which shows image properties. If you have only Word, drag&drop the image over the document. Image size of the above example should have been 1.69×1.69 cm – and if taken from file, it actually is. If from .NET-made clipboard, it isn't.

What I am missing in process of setting the image DPI?

(C# or VB, whatever you prefer.)

Body:
The work-around I found was to create a temporary file and push that into the Clipboard instead of using SetImage:

  bitmap1.SetResolution(300, 300)
  Dim strTempFilename As String = TempDirectory & "\mytempfilename.TIF"
  bitmap1.Save(strTempFilename, Imaging.ImageFormat.Tiff)
  Dim DataObject As New DataObject()
  Dim file(0) As String
  file(0) = strTempFilename
  DataObject.SetData(DataFormats.FileDrop, True, file)
  Clipboard.SetDataObject(DataObject)

I've omitted all the error checking etc. for brevity. The downside of this approach is that there is a temporary file to delete afterwards.


问:
How to implement NSLog in Codename One native interface?
I read and followed the instructions from the Codename One manual's Advanced topics section on Native Interfaces. I want to pass Strings to my interface so that I can log events in the iOS version of my app, but am not able to see my logs.

Here is my code:

```<code>InterfaceLogger interfaceLogger = NativeLookup.create(InterfaceLogger.class);
if (interfaceLogger != null && interfaceLogger.isSupported()) {
            interfaceLogger.logThis("hello!");
}
</code>```

Here is my iOS implementation code in the native folder:

.h file:

```<code>#import <Foundation/Foundation.h>

@interface org_myapp_app_cn1_InterfaceLoggerImpl : NSObject {
}

-(void)logThis:(NSString*)param;
-(BOOL)isSupported;
@end
</code>```

**

.m file:

```<code>#import "org_myapp_app_cn1_InterfaceLoggerImpl.h"

@implementation org_myapp_app_cn1_InterfaceLoggerImpl

-(void)logThis:(NSString*)param{
    NSLog(@"%@", param);
}

-(BOOL)isSupported{
    return YES;
}

@end
</code>```

Please help.

Thanks.

答:
I'm not sure why you would need that as Log.p() already invokes NSLog or printf internally. Apple changed the way logging is echoed in recent versions and made a bit of a mess of tracking everything when targeting multiple device generations so NSLog just doesn't work everywhere anymore.

The code you did is just fine though, the reason you can't see the NSLog output is because of Apple. You can see the internal issue we have for this  here: https://github.com/codenameone/CodenameOne/issues/2166

Body:
I read and followed the instructions from the Codename One manual's Advanced topics section on Native Interfaces. I want to pass Strings to my interface so that I can log events in the iOS version of my app, but am not able to see my logs.

Here is my code:

InterfaceLogger interfaceLogger = NativeLookup.create(InterfaceLogger.class);
if (interfaceLogger != null && interfaceLogger.isSupported()) {
            interfaceLogger.logThis("hello!");
}

Here is my iOS implementation code in the native folder:

.h file:

#import <Foundation/Foundation.h>

@interface org_myapp_app_cn1_InterfaceLoggerImpl : NSObject {
}

-(void)logThis:(NSString*)param;
-(BOOL)isSupported;
@end

**

.m file:

#import "org_myapp_app_cn1_InterfaceLoggerImpl.h"

@implementation org_myapp_app_cn1_InterfaceLoggerImpl

-(void)logThis:(NSString*)param{
    NSLog(@"%@", param);
}

-(BOOL)isSupported{
    return YES;
}

@end

Please help.

Thanks.


问:
calculate petrol consumed per second and show on web
I want to calculate the petrol consumed per second and show on the website as a footer.

The calculation will be like, petrol consumption increases by 0.13L per second, so for this, I thought to use setInterval for one second and call a function which will calculate the petrol consumption.

Till now I attempted this:

function random_no() {
  var i;
  i = i + 0.13;

  // jQuery('#random_no_container').html(ran);
}

window.setInterval(function() {
  /// call your function here
  random_no();
}, 1000);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="random_no_container">
  Hello. Here you can see petrol consumption per second
</div></code>```

How can I show the value of I in liters, in the footer?

I am a beginner, please help, thank you.

答:
A couple of things you need to do:

Your variable should be global (outside the function)- so that value isn't replaced each time you call the function.  You also need to initalize i so it has a starting value (0).

You need to add a new element (here I used span) so you know where to put the fuel data.

You needed to change the code for the .html() to use your variable i.

var i = 0;
function random_no() {
  i += 0.13;

  $('#used').html(i);
}

window.setInterval(function() {
  /// call your function here
  random_no();
}, 1000);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="random_no_container">
  Hello. Here you can see petrol consumption per second <span id="used"></span>
</div></code>```

As you can see, this is pretty slow.  I would instead opt for a more complex solution which uses the current time, so you don't have to calculate the exact refresh rate of the function:

var start_time = new Date().getTime();
function update_consumption() {
  var time_since_start = ((new Date().getTime()) - start_time) / 1000;
  $('#used').html(Math.round(time_since_start * 0.13 * 100) / 100);
}

window.setInterval(function() {
  update_consumption();
}, 300);
update_consumption();```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="random_no_container">
  Hello. Here you can see petrol consumption per second <span id="used"></span>
</div></code>```

This second solution works a bit differently:

It stores a global variable start, which represents the time (in miliseconds) since January 1st 1970 when the program starts.

It subtracts the time the function is called, and divides by 1000, to get the number of seconds since the program is started (stored as time_since_start).

Multiply this by the rate (in L/s), and then save this to HTML (rounding using .round()) beforehand.

This second solution is (in my opinion) better than the first  a) because the total fuel consumed is determined independently of the refresh rate- so you can update at 300ms intervals, and still be accurate.  b) because setInterval() is not always accurate.  This way, you use an independent, accurate timer.

Body:
I want to calculate the petrol consumed per second and show on the website as a footer.

The calculation will be like, petrol consumption increases by 0.13L per second, so for this, I thought to use setInterval for one second and call a function which will calculate the petrol consumption.

Till now I attempted this:

function random_no() {
  var i;
  i = i + 0.13;

  // jQuery('#random_no_container').html(ran);
}

window.setInterval(function() {
  /// call your function here
  random_no();
}, 1000);

  Hello. Here you can see petrol consumption per second

How can I show the value of I in liters, in the footer?

I am a beginner, please help, thank you.

Body:
A couple of things you need to do:

Your variable should be global (outside the function)- so that value isn't replaced each time you call the function.  You also need to initalize i so it has a starting value (0).

You need to add a new element (here I used span) so you know where to put the fuel data.

You needed to change the code for the .html() to use your variable i.

var i = 0;
function random_no() {
  i += 0.13;

  $('#used').html(i);
}

window.setInterval(function() {
  /// call your function here
  random_no();
}, 1000);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="random_no_container">
  Hello. Here you can see petrol consumption per second <span id="used"></span>
</div>

As you can see, this is pretty slow.  I would instead opt for a more complex solution which uses the current time, so you don't have to calculate the exact refresh rate of the function:

var start_time = new Date().getTime();
function update_consumption() {
  var time_since_start = ((new Date().getTime()) - start_time) / 1000;
  $('#used').html(Math.round(time_since_start * 0.13 * 100) / 100);
}

window.setInterval(function() {
  update_consumption();
}, 300);
update_consumption();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="random_no_container">
  Hello. Here you can see petrol consumption per second <span id="used"></span>
</div>

This second solution works a bit differently:

It stores a global variable start, which represents the time (in miliseconds) since January 1st 1970 when the program starts.

It subtracts the time the function is called, and divides by 1000, to get the number of seconds since the program is started (stored as time_since_start).

Multiply this by the rate (in L/s), and then save this to HTML (rounding using .round()) beforehand.

This second solution is (in my opinion) better than the first  a) because the total fuel consumed is determined independently of the refresh rate- so you can update at 300ms intervals, and still be accurate.  b) because setInterval() is not always accurate.  This way, you use an independent, accurate timer.


问:
Shell : Check if all output strings are same
I have the following code snippet

```<code>$ mount | grep '^/dev'| awk '{print $1}'
 /dev/disk1s1
 /dev/disk1s4
</code>```

Now I need to check if the output lines have the same value or different.
So in the above case it is different. [ disk1s1 and disk1s4 ]. How can this be achieved in shell.

I may have two or more lines in the result.

答:
Try to modify your command as followed, if you got any duplicated results, the output would append with "same"

```<code>$ mount | awk '/^\/dev/{print $1,a[$1]?"same":"";a[$1]=1}'
/dev/sdb1
/dev/sdb3
/dev/sda1
/dev/sdb1 same
/dev/sdb3 same
</code>```

Brief explanation,

No need to use grep in your command, cause awk can do anything that grepcan.

/^\/dev/: search the lines start with '/dev'

a[$1]?"same":"" if a[$1] is set, print "same" behind $1, otherwise do nothing

a[$1]=1: don't forget to set $1 in the last.

Body:
I have the following code snippet

$ mount | grep '^/dev'| awk '{print $1}'
 /dev/disk1s1
 /dev/disk1s4

Now I need to check if the output lines have the same value or different.
So in the above case it is different. [ disk1s1 and disk1s4 ]. How can this be achieved in shell.

I may have two or more lines in the result.

Body:
Try to modify your command as followed, if you got any duplicated results, the output would append with "same"

$ mount | awk '/^\/dev/{print $1,a[$1]?"same":"";a[$1]=1}'
/dev/sdb1
/dev/sdb3
/dev/sda1
/dev/sdb1 same
/dev/sdb3 same

Brief explanation,

No need to use grep in your command, cause awk can do anything that grepcan.

/^\/dev/: search the lines start with '/dev'

a[$1]?"same":"" if a[$1] is set, print "same" behind $1, otherwise do nothing

a[$1]=1: don't forget to set $1 in the last.


问:
4 Column Footer Not Stacking for Mobile
So basically I've got this 4 column footer and it's perfect, but rather than stacking for mobile, it just gets smashed.
I just want each category to stack once it swaps to mobile view, or just shrink responsively across all sizes.
I've tried setting widths but no luck.  Any help or tips would be appreciated!

footer .clear {
  clear: both;
  float: none;
}

footer {
  background: #222;
  overflow: hidden;
  border-top: solid 1px #000;
  padding: 58px 0 0;
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
}

footer p,
footer ul,
footer a,
footer .btn {
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
  text-transform: none;
}

footer li {
  font-size: .875em;
  line-height: 1.5em;
}

footer .btn {
  background: #4497c4;
  background-image: -webkit-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -moz-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -ms-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -o-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: linear-gradient(to bottom, #4497c4, #2d6a8e);
  -webkit-border-radius: 5;
  -moz-border-radius: 5;
  border-radius: 5px;
  -webkit-box-shadow: 0px 1px 2px #ffffff;
  -moz-box-shadow: 0px 1px 2px #ffffff;
  box-shadow: 0px 1px 2px #ffffff;
  color: #ffffff!important;
  font-size: 15px;
  padding: 5px 15px 6px 15px;
  border: solid #25658a 1px;
  text-decoration: none;
  -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

footer .content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

@media screen and (max-width: 768px) {
  footer .content {
    padding: 0 10px;
  }
}

footer .last {
  margin-right: 0px !important;
}

@media only screen and (max-width: 485px) {
  footer .last {
    clear: both;
  }
}

#emailsignup {
  float: left;
  width: 330px;
}

#emailsignup .footer-logo {
  display: block;
  width: 155px;
  height: 41px;
  background: url("https://www.proxibid.com/images/footer-logo-proxibid.png") top left no-repeat;
  text-indent: -9999px;
  margin-bottom: 30px;
}

#emailsignup a,
#helpfullinks a,
#social a,
#poweredby a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

#emailsignup p {
  font-size: 13px;
  color: #FFF;
  margin: 0px 0px 16px;
}

#helpfullinks {
  float: right;
}

@media only screen and (max-width: 825px) {
  #helpfullinks {
    float: none;
    clear: both;
  }
}

#helpfullinks div {
  float: left;
  margin-right: 45px;
  width: 20%;
}

#helpfullinks div a {
  display: inline;
  margin-top: -6px;
  margin-bottom: 8px;
}

#helpfullinks p.category {
  color: #FFF;
  font-size: 21px;
  margin: 0 0 14px;
}

#helpfullinks p.category a {
  color: #FFF;
}

#helpfullinks ul {
  list-style-type: none;
  padding: 0px;
  margin: 14px 0 0 0;
}

#helpfullinks li {
  padding: 0px;
  margin: 0 0 6px;
  font-size: 15px;
}

#poweredby {
  max-width: 100%;
  margin: 115px auto 0;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #poweredby {
    margin: 26px auto 0;
  }
}

#poweredby p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 10px;
  text-align: center;
}

#poweredby ul {
  display: inline-block;
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#poweredby li {
  margin: 0 40px 0 0;
  float: left;
}

@media only screen and (max-width: 495px) {
  #poweredby li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#poweredby .footer-divvy {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-divvy.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-finest {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-thefinest.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-apn {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-apn.png") top left no-repeat;
  text-indent: -9999px;
}

#social {
  margin: 60px auto;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #social {
    margin: 26px auto;
  }
}

#social ul {
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#social ul.social,
#social ul.contact {
  display: inline-block;
}

#social li {
  margin: 0 17px 0 0;
  float: left;
  color: rgba(255, 255, 255, 0.7);
}

@media only screen and (max-width: 495px) {
  #social li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#social li a {
  color: rgba(255, 255, 255, 0.7);
}

iframe {
  overflow: hidden;
}

#footerSealiFrame {
  border: medium none;
  height: 175px;
  margin: 0 auto;
  width: 100%;
  display: block;
  overflow: hidden;
}

@media only screen and (max-width: 600px) {
  #footerSealiFrame {
    height: 285px;
  }
  #footerSeals>img,
  #footerSeals>embed,
  #footerSeals>object,
  #footerSeals>a {
    display: inline-block !important;
    margin: 0 6px 10px !important;
    vertical-align: middle !important;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><footer>
  <div class="content">
    <div id="helpfullinks">
      <div>
        <p class="category">About</p>
        <ul>
          <li>Our Mission</li>
          <li>AdaptaPASS</li>
          <li>Affiliates</li>
          <li>Campus Representatives</li>
          <li>Privacy Policy</li>
        </ul>
      </div>
      <div>
        <p class="category">Products</p>
        <ul>
          <li>All-Access Course Bundles</li>
          <li>CRAM Courses</li>
          <li>Audio Lectures</li>
          <li>TestBank Software</li>
          <li>Digital Flashcards</li>
          <li>Exam Stress Relief</li>
        </ul>
      </div>
      <div>
        <p class="category">Resources</p>
        <ul>
          <li>Free Assessment</li>
          <li>Start a Free Trial</li>
          <li>Blog</li>
          <li>Requirements by State</li>
        </ul>
      </div>
      <div class="last">
        <p class="category">Support</p>
        <ul>
          <li>(800) 824 2811</li>
          <li>Use the chat feature below to reach one of our support specialists</li>
          <li>Contact Us</li>
          <li>Login to AdaptaPASS</li>
          <li>Login to myYaeger Student Portal</li>
        </ul>
      </div>
      <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <div id="poweredby">
      <ul>
        <li class="last"><img src="include/images/footerlogo.png"></li>
      </ul>
    </div>
    <div class="clear"></div>
    <div id="social">
      <ul class="social">
        <li>Facebook</li>
        <li>Twitter</li>
        <li>YouTube</li>
        <li class="last">LinkedIn</li>
      </ul>
      <div class="clear"></div>
      <ul class="contact">
        <li class="last">©2017 Yaegar CPA Review, All Rights Reserved</li>
      </ul>
    </div>
  </div>
</footer></code>```

答:
You have used pixels instead of percentage for margin-right. So if we convert the remaining space into percentage we will get approximately 6.66% per each div. So we can achieve the required layout.

.clear {
  clear: both;
  float: none;
}

footer {
  background: #222;
  overflow: hidden;
  border-top: solid 1px #000;
  padding: 58px 0 0;
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
}

footer p,
footer ul,
footer a,
footer .btn {
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
  text-transform: none;
}

footer li {
  font-size: .875em;
  line-height: 1.5em;
}

footer .btn {
  background: #4497c4;
  background-image: -webkit-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -moz-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -ms-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -o-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: linear-gradient(to bottom, #4497c4, #2d6a8e);
  -webkit-border-radius: 5;
  -moz-border-radius: 5;
  border-radius: 5px;
  -webkit-box-shadow: 0px 1px 2px #ffffff;
  -moz-box-shadow: 0px 1px 2px #ffffff;
  box-shadow: 0px 1px 2px #ffffff;
  color: #ffffff!important;
  font-size: 15px;
  padding: 5px 15px 6px 15px;
  border: solid #25658a 1px;
  text-decoration: none;
  -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

footer .content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

@media screen and (max-width: 768px) {
  footer .content {
    padding: 0 10px;
  }
}

footer .last {
  margin-right: 0px !important;
}

@media only screen and (max-width: 485px) {
  footer .last {}
}

#emailsignup {
  float: left;
  width: 330px;
}

#emailsignup .footer-logo {
  display: block;
  width: 155px;
  height: 41px;
  background: url("https://www.proxibid.com/images/footer-logo-proxibid.png") top left no-repeat;
  text-indent: -9999px;
  margin-bottom: 30px;
}

#emailsignup a,
#helpfullinks a,
#social a,
#poweredby a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

#emailsignup p {
  font-size: 13px;
  color: #FFF;
  margin: 0px 0px 16px;
}

#helpfullinks {
  float: right;
}

@media only screen and (max-width: 825px) {
  #helpfullinks {
    float: none;
    clear: both;
  }
}

#helpfullinks div {
  float: left;
  margin-right: 6.66%;
  width: 20%;
}

#helpfullinks div a {
  display: inline;
  margin-top: -6px;
  margin-bottom: 8px;
}

#helpfullinks p.category {
  color: #FFF;
  font-size: 21px;
  margin: 0 0 14px;
}

#helpfullinks p.category a {
  color: #FFF;
}

#helpfullinks ul {
  list-style-type: none;
  padding: 0px;
  margin: 14px 0 0 0;
}

#helpfullinks li {
  padding: 0px;
  margin: 0 0 6px;
  font-size: 15px;
}

#poweredby {
  max-width: 100%;
  margin: 115px auto 0;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #poweredby {
    margin: 26px auto 0;
  }
}

#poweredby p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 10px;
  text-align: center;
}

#poweredby ul {
  display: inline-block;
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#poweredby li {
  margin: 0 40px 0 0;
  float: left;
}

@media only screen and (max-width: 495px) {
  #poweredby li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#poweredby .footer-divvy {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-divvy.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-finest {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-thefinest.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-apn {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-apn.png") top left no-repeat;
  text-indent: -9999px;
}

#social {
  margin: 60px auto;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #social {
    margin: 26px auto;
  }
}

#social ul {
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#social ul.social,
#social ul.contact {
  display: inline-block;
}

#social li {
  margin: 0 17px 0 0;
  float: left;
  color: rgba(255, 255, 255, 0.7);
}

@media only screen and (max-width: 495px) {
  #social li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#social li a {
  color: rgba(255, 255, 255, 0.7);
}

iframe {
  overflow: hidden;
}

#footerSealiFrame {
  border: medium none;
  height: 175px;
  margin: 0 auto;
  width: 100%;
  display: block;
  overflow: hidden;
}

@media only screen and (max-width: 600px) {
  #footerSealiFrame {
    height: 285px;
  }
  #footerSeals>img,
  #footerSeals>embed,
  #footerSeals>object,
  #footerSeals>a {
    display: inline-block !important;
    margin: 0 6px 10px !important;
    vertical-align: middle !important;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><footer>
  <div class="content">
    <div id="helpfullinks">
      <div>
        <p class="category">About</p>
        <ul>
          <li>Our Mission</li>
          <li>AdaptaPASS</li>
          <li>Affiliates</li>
          <li>Campus Representatives</li>
          <li>Privacy Policy</li>
        </ul>
      </div>
      <div>
        <p class="category">Products</p>
        <ul>
          <li>All-Access Course Bundles</li>
          <li>CRAM Courses</li>
          <li>Audio Lectures</li>
          <li>TestBank Software</li>
          <li>Digital Flashcards</li>
          <li>Exam Stress Relief</li>
        </ul>
      </div>
      <div>
        <p class="category">Resources</p>
        <ul>
          <li>Free Assessment</li>
          <li>Start a Free Trial</li>
          <li>Blog</li>
          <li>Requirements by State</li>
        </ul>
      </div>
      <div class="last">
        <p class="category">Support</p>
        <ul>
          <li>(800) 824 2811</li>
          <li>Use the chat feature below to reach one of our support specialists</li>
          <li>Contact Us</li>
          <li>Login to AdaptaPASS</li>
          <li>Login to myYaeger Student Portal</li>
        </ul>
      </div>
      <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <div id="poweredby">
      <ul>
        <li class="last"><img src="include/images/footerlogo.png"></li>
      </ul>
    </div>
    <div class="clear"></div>
    <div id="social">
      <ul class="social">
        <li>Facebook</li>
        <li>Twitter</li>
        <li>YouTube</li>
        <li class="last">LinkedIn</li>
      </ul>
      <div class="clear"></div>
      <ul class="contact">
        <li class="last">©2017 Yaegar CPA Review, All Rights Reserved</li>
      </ul>
    </div>
  </div>
</footer></code>```

Title: 4 Column Footer Not Stacking for Mobile

Body:
So basically I've got this 4 column footer and it's perfect, but rather than stacking for mobile, it just gets smashed.
I just want each category to stack once it swaps to mobile view, or just shrink responsively across all sizes.
I've tried setting widths but no luck.  Any help or tips would be appreciated!

footer .clear {
  clear: both;
  float: none;
}

footer {
  background: #222;
  overflow: hidden;
  border-top: solid 1px #000;
  padding: 58px 0 0;
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
}

footer p,
footer ul,
footer a,
footer .btn {
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
  text-transform: none;
}

footer li {
  font-size: .875em;
  line-height: 1.5em;
}

footer .btn {
  background: #4497c4;
  background-image: -webkit-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -moz-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -ms-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -o-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: linear-gradient(to bottom, #4497c4, #2d6a8e);
  -webkit-border-radius: 5;
  -moz-border-radius: 5;
  border-radius: 5px;
  -webkit-box-shadow: 0px 1px 2px #ffffff;
  -moz-box-shadow: 0px 1px 2px #ffffff;
  box-shadow: 0px 1px 2px #ffffff;
  color: #ffffff!important;
  font-size: 15px;
  padding: 5px 15px 6px 15px;
  border: solid #25658a 1px;
  text-decoration: none;
  -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

footer .content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

@media screen and (max-width: 768px) {
  footer .content {
    padding: 0 10px;
  }
}

footer .last {
  margin-right: 0px !important;
}

@media only screen and (max-width: 485px) {
  footer .last {
    clear: both;
  }
}

#emailsignup {
  float: left;
  width: 330px;
}

#emailsignup .footer-logo {
  display: block;
  width: 155px;
  height: 41px;
  background: url("https://www.proxibid.com/images/footer-logo-proxibid.png") top left no-repeat;
  text-indent: -9999px;
  margin-bottom: 30px;
}

#emailsignup a,
#helpfullinks a,
#social a,
#poweredby a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

#emailsignup p {
  font-size: 13px;
  color: #FFF;
  margin: 0px 0px 16px;
}

#helpfullinks {
  float: right;
}

@media only screen and (max-width: 825px) {
  #helpfullinks {
    float: none;
    clear: both;
  }
}

#helpfullinks div {
  float: left;
  margin-right: 45px;
  width: 20%;
}

#helpfullinks div a {
  display: inline;
  margin-top: -6px;
  margin-bottom: 8px;
}

#helpfullinks p.category {
  color: #FFF;
  font-size: 21px;
  margin: 0 0 14px;
}

#helpfullinks p.category a {
  color: #FFF;
}

#helpfullinks ul {
  list-style-type: none;
  padding: 0px;
  margin: 14px 0 0 0;
}

#helpfullinks li {
  padding: 0px;
  margin: 0 0 6px;
  font-size: 15px;
}

#poweredby {
  max-width: 100%;
  margin: 115px auto 0;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #poweredby {
    margin: 26px auto 0;
  }
}

#poweredby p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 10px;
  text-align: center;
}

#poweredby ul {
  display: inline-block;
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#poweredby li {
  margin: 0 40px 0 0;
  float: left;
}

@media only screen and (max-width: 495px) {
  #poweredby li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#poweredby .footer-divvy {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-divvy.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-finest {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-thefinest.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-apn {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-apn.png") top left no-repeat;
  text-indent: -9999px;
}

#social {
  margin: 60px auto;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #social {
    margin: 26px auto;
  }
}

#social ul {
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#social ul.social,
#social ul.contact {
  display: inline-block;
}

#social li {
  margin: 0 17px 0 0;
  float: left;
  color: rgba(255, 255, 255, 0.7);
}

@media only screen and (max-width: 495px) {
  #social li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#social li a {
  color: rgba(255, 255, 255, 0.7);
}

iframe {
  overflow: hidden;
}

#footerSealiFrame {
  border: medium none;
  height: 175px;
  margin: 0 auto;
  width: 100%;
  display: block;
  overflow: hidden;
}

@media only screen and (max-width: 600px) {
  #footerSealiFrame {
    height: 285px;
  }
  #footerSeals>img,
  #footerSeals>embed,
  #footerSeals>object,
  #footerSeals>a {
    display: inline-block !important;
    margin: 0 6px 10px !important;
    vertical-align: middle !important;
  }
}

About

Our Mission

AdaptaPASS

Affiliates

Campus Representatives

Privacy Policy

Products

All-Access Course Bundles

CRAM Courses

Audio Lectures

TestBank Software

Digital Flashcards

Exam Stress Relief

Resources

Free Assessment

Start a Free Trial

Blog

Requirements by State

Support

(800) 824 2811

Use the chat feature below to reach one of our support specialists

Contact Us

Login to AdaptaPASS

Login to myYaeger Student Portal

Facebook

Twitter

YouTube

LinkedIn

©2017 Yaegar CPA Review, All Rights Reserved

Body:
You have used pixels instead of percentage for margin-right. So if we convert the remaining space into percentage we will get approximately 6.66% per each div. So we can achieve the required layout.

.clear {
  clear: both;
  float: none;
}

footer {
  background: #222;
  overflow: hidden;
  border-top: solid 1px #000;
  padding: 58px 0 0;
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
}

footer p,
footer ul,
footer a,
footer .btn {
  font-family: arial, helvetica, sans-serif;
  line-height: 1.5em;
  text-transform: none;
}

footer li {
  font-size: .875em;
  line-height: 1.5em;
}

footer .btn {
  background: #4497c4;
  background-image: -webkit-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -moz-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -ms-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: -o-linear-gradient(top, #4497c4, #2d6a8e);
  background-image: linear-gradient(to bottom, #4497c4, #2d6a8e);
  -webkit-border-radius: 5;
  -moz-border-radius: 5;
  border-radius: 5px;
  -webkit-box-shadow: 0px 1px 2px #ffffff;
  -moz-box-shadow: 0px 1px 2px #ffffff;
  box-shadow: 0px 1px 2px #ffffff;
  color: #ffffff!important;
  font-size: 15px;
  padding: 5px 15px 6px 15px;
  border: solid #25658a 1px;
  text-decoration: none;
  -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

footer .content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

@media screen and (max-width: 768px) {
  footer .content {
    padding: 0 10px;
  }
}

footer .last {
  margin-right: 0px !important;
}

@media only screen and (max-width: 485px) {
  footer .last {}
}

#emailsignup {
  float: left;
  width: 330px;
}

#emailsignup .footer-logo {
  display: block;
  width: 155px;
  height: 41px;
  background: url("https://www.proxibid.com/images/footer-logo-proxibid.png") top left no-repeat;
  text-indent: -9999px;
  margin-bottom: 30px;
}

#emailsignup a,
#helpfullinks a,
#social a,
#poweredby a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

#emailsignup p {
  font-size: 13px;
  color: #FFF;
  margin: 0px 0px 16px;
}

#helpfullinks {
  float: right;
}

@media only screen and (max-width: 825px) {
  #helpfullinks {
    float: none;
    clear: both;
  }
}

#helpfullinks div {
  float: left;
  margin-right: 6.66%;
  width: 20%;
}

#helpfullinks div a {
  display: inline;
  margin-top: -6px;
  margin-bottom: 8px;
}

#helpfullinks p.category {
  color: #FFF;
  font-size: 21px;
  margin: 0 0 14px;
}

#helpfullinks p.category a {
  color: #FFF;
}

#helpfullinks ul {
  list-style-type: none;
  padding: 0px;
  margin: 14px 0 0 0;
}

#helpfullinks li {
  padding: 0px;
  margin: 0 0 6px;
  font-size: 15px;
}

#poweredby {
  max-width: 100%;
  margin: 115px auto 0;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #poweredby {
    margin: 26px auto 0;
  }
}

#poweredby p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 10px;
  text-align: center;
}

#poweredby ul {
  display: inline-block;
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#poweredby li {
  margin: 0 40px 0 0;
  float: left;
}

@media only screen and (max-width: 495px) {
  #poweredby li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#poweredby .footer-divvy {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-divvy.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-finest {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-thefinest.png") top left no-repeat;
  text-indent: -9999px;
}

#poweredby .footer-apn {
  display: block;
  width: 77px;
  height: 24px;
  background: url("https://www.proxibid.com/images/footer-logo-apn.png") top left no-repeat;
  text-indent: -9999px;
}

#social {
  margin: 60px auto;
  overflow: hidden;
  text-align: center;
}

@media screen and (max-width: 768px) {
  #social {
    margin: 26px auto;
  }
}

#social ul {
  margin: 0px auto;
  list-style-type: none;
  padding: 0px;
}

#social ul.social,
#social ul.contact {
  display: inline-block;
}

#social li {
  margin: 0 17px 0 0;
  float: left;
  color: rgba(255, 255, 255, 0.7);
}

@media only screen and (max-width: 495px) {
  #social li {
    margin: 0 0 10px 0;
    float: none;
    clear: both;
  }
}

#social li a {
  color: rgba(255, 255, 255, 0.7);
}

iframe {
  overflow: hidden;
}

#footerSealiFrame {
  border: medium none;
  height: 175px;
  margin: 0 auto;
  width: 100%;
  display: block;
  overflow: hidden;
}

@media only screen and (max-width: 600px) {
  #footerSealiFrame {
    height: 285px;
  }
  #footerSeals>img,
  #footerSeals>embed,
  #footerSeals>object,
  #footerSeals>a {
    display: inline-block !important;
    margin: 0 6px 10px !important;
    vertical-align: middle !important;
  }
}

<footer>
  <div class="content">
    <div id="helpfullinks">
      <div>
        <p class="category">About</p>
        <ul>
          <li><a href="#">Our Mission</a></li>
          <li><a href="#">AdaptaPASS</a></li>
          <li><a href="#">Affiliates</a></li>
          <li><a href="#">Campus Representatives</a></li>
          <li><a href="#">Privacy Policy</a></li>
        </ul>
      </div>
      <div>
        <p class="category">Products</p>
        <ul>
          <li><a href="#">All-Access Course Bundles</a></li>
          <li><a href="#">CRAM Courses</a></li>
          <li><a href="#">Audio Lectures</a></li>
          <li><a href="#">TestBank Software</a></li>
          <li><a href="#">Digital Flashcards</a></li>
          <li><a href="#">Exam Stress Relief</a></li>
        </ul>
      </div>
      <div>
        <p class="category">Resources</p>
        <ul>
          <li><a href="#">Free Assessment</a></li>
          <li><a href="#">Start a Free Trial</a></li>
          <li><a href="#">Blog</a></li>
          <li><a href="#">Requirements by State</a></li>
        </ul>
      </div>
      <div class="last">
        <p class="category">Support</p>
        <ul>
          <li><a href="#">(800) 824 2811</a></li>
          <li><a href="#">Use the chat feature below to reach one of our support specialists</a></li>
          <li><a href="#">Contact Us</a></li>
          <li><a href="#">Login to AdaptaPASS</a></li>
          <li><a href="#">Login to myYaeger Student Portal</a></li>
        </ul>
      </div>
      <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <div id="poweredby">
      <ul>
        <li class="last"><img src="include/images/footerlogo.png"></li>
      </ul>
    </div>
    <div class="clear"></div>
    <div id="social">
      <ul class="social">
        <li><a target="_blank" href="#">Facebook</a></li>
        <li><a target="_blank" href="#">Twitter</a></li>
        <li><a target="_blank" href="#">YouTube</a></li>
        <li class="last"><a target="_blank" href="#">LinkedIn</a></li>
      </ul>
      <div class="clear"></div>
      <ul class="contact">
        <li class="last">&copy;2017 Yaegar CPA Review, All Rights Reserved</li>
      </ul>
    </div>
  </div>
</footer>


问:
NLP - How to Identify whether 2 texts refer to similar object
I am looking for some general guidance here.

The high-level use case is such that I receive some product documents
  from which I need to extract some information and process it. Before
  doing that, I need to verify that the document is actually referring
  to the correct product. For that I need to validate the product
  heading/description from document against what I know to be correct.

So I have 2 texts

Text 1 - this refers to the product information extracted from some document

Text 2 - this is the actual product heading/description available with me, which can be considered as correct.

I need to validate that both texts refer to same product or object.

Example:

```<code>Text 1 (to be validated) - Optimus Prime Costume, Blue, with good packaging and warranty
Text 2 (correct info) - Optimus Prime Blue Costume, Medium Size`
</code>```

You see, I need to validate that both text refer to Optimus Prime Costume.

I tried following methods -

Cosine Similarity

TF-IDF similarity

Overlapping words between strings

But the problem with them is that they depends on the entire text rather than the primary object being referred in the text.

I was thinking of processing as follows:-

Remove colors, size info etc. from the text 2. The text 2, is very concise and does not contain random data. It contains product name and size, colour info.

Validate that the remaining elements from Text 2 are present in Text 1, or atleast a majority of them are.

I am not quite sure what different NLP techniques might be there, which would be better than this approach, so any suggestions would be appreciated.

答:
Depending on your target this can be medium-hard or very hard.

There are a couple of things you can use:

NER would definitely be helpful:

Wikifier could be useful too: http://cogcomp.org/page/demo_view/Wikifier

And also Semantic-Role-Labeling. See more annotations here: http://nlp.cogcomp.org/

It's hard to judge from one single example what is the exact algorithm, but if you have more examples might be easier to come up with a better formalization.

An extension of this can be found in what has been used
in this work.

Body:
I am looking for some general guidance here.

The high-level use case is such that I receive some product documents
  from which I need to extract some information and process it. Before
  doing that, I need to verify that the document is actually referring
  to the correct product. For that I need to validate the product
  heading/description from document against what I know to be correct.

So I have 2 texts

Text 1 - this refers to the product information extracted from some document

Text 2 - this is the actual product heading/description available with me, which can be considered as correct.

I need to validate that both texts refer to same product or object.

Example:

Text 1 (to be validated) - Optimus Prime Costume, Blue, with good packaging and warranty
Text 2 (correct info) - Optimus Prime Blue Costume, Medium Size`

You see, I need to validate that both text refer to Optimus Prime Costume.

I tried following methods -

Cosine Similarity

TF-IDF similarity

Overlapping words between strings

But the problem with them is that they depends on the entire text rather than the primary object being referred in the text.

I was thinking of processing as follows:-

Remove colors, size info etc. from the text 2. The text 2, is very concise and does not contain random data. It contains product name and size, colour info.

Validate that the remaining elements from Text 2 are present in Text 1, or atleast a majority of them are.

I am not quite sure what different NLP techniques might be there, which would be better than this approach, so any suggestions would be appreciated.