问:
Bash - Append to Array Issue
I'm pretty new to bash.

I have the following code:

```<code>while read line
do
    foundproduct=`echo $line | awk -F "\"*,\"*" '{print $2}'`
    if [ "$foundproduct" == "$product" ]; then
        productid=`echo $line | awk -F "\"*,\"*" '{print $19}'`
        newid=1
        for i in ${productids[@]}
        do
            if [ "${productids[i]}" == "$productid" ] ; then
                newid=0
                break
            fi
        done
        if (( newid == 1 )) ; then
            declare -p productids
            echo "$productid"
            echo "1. $productids[${#productids[@]}]"
            productids+=("$productid")
            echo "2. $productids[${#productids[@]}]"
            declare -p productids
        fi
        loadid=`echo $line | awk -F "\"*,\"*" '{print $39}'`
    fi
done < hddtable1.csv
</code>```

Which produces the following result:

```<code>declare -a productids='()'
ST900MM0006
1. [0]
2. ST900MM0006 [1]
declare -a productids='([0]="ST900MM0006 ")'
declare -a productids='([0]="ST900MM0006 ")'
ST600MM0006
1. ST900MM0006 [1]
2. ST900MM0006 [2]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [2]
2. ST900MM0006 [3]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [3]
2. ST900MM0006 [4]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [4]
2. ST900MM0006 [5]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [5]
2. ST900MM0006 [6]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [6]
2. ST900MM0006 [7]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [7]
2. ST900MM0006 [8]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 ")'
ST300MM0006
1. ST900MM0006 [8]
2. ST900MM0006 [9]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [9]
2. ST900MM0006 [10]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [10]
2. ST900MM0006 [11]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [11]
2. ST900MM0006 [12]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [12]
2. ST900MM0006 [13]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [13]
2. ST900MM0006 [14]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 " [13]="ST300MM0006 ")'
</code>```

The column from the CSV looks like this: column

I've used this method of appending to arrays in bash in this same script and it worked fine, can someone help me figure out why this isn't working? I tried doing productids+="$productid" and that, for some reason, just appends everything to the end of the first entry in the array.

Iterating through the array:

```<code>for i in ${productids[@]}
do
    echo "${productids[i]}"
done
</code>```

Full output of this:

```<code>ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
</code>```

答:
You can append to a Bash array easily like this:

```<code>productids+=("$productid")
</code>```

You'll find similar examples in the Bash Guide on arrays.

Title: Bash - Append to Array Issue

Body:
I'm pretty new to bash.

I have the following code:

while read line
do
    foundproduct=`echo $line | awk -F "\"*,\"*" '{print $2}'`
    if [ "$foundproduct" == "$product" ]; then
        productid=`echo $line | awk -F "\"*,\"*" '{print $19}'`
        newid=1
        for i in ${productids[@]}
        do
            if [ "${productids[i]}" == "$productid" ] ; then
                newid=0
                break
            fi
        done
        if (( newid == 1 )) ; then
            declare -p productids
            echo "$productid"
            echo "1. $productids[${#productids[@]}]"
            productids+=("$productid")
            echo "2. $productids[${#productids[@]}]"
            declare -p productids
        fi
        loadid=`echo $line | awk -F "\"*,\"*" '{print $39}'`
    fi
done < hddtable1.csv

Which produces the following result:

declare -a productids='()'
ST900MM0006
1. [0]
2. ST900MM0006 [1]
declare -a productids='([0]="ST900MM0006 ")'
declare -a productids='([0]="ST900MM0006 ")'
ST600MM0006
1. ST900MM0006 [1]
2. ST900MM0006 [2]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [2]
2. ST900MM0006 [3]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [3]
2. ST900MM0006 [4]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [4]
2. ST900MM0006 [5]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [5]
2. ST900MM0006 [6]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [6]
2. ST900MM0006 [7]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 ")'
ST600MM0006
1. ST900MM0006 [7]
2. ST900MM0006 [8]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 ")'
ST300MM0006
1. ST900MM0006 [8]
2. ST900MM0006 [9]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [9]
2. ST900MM0006 [10]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [10]
2. ST900MM0006 [11]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [11]
2. ST900MM0006 [12]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [12]
2. ST900MM0006 [13]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 ")'
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 ")'
ST300MM0006
1. ST900MM0006 [13]
2. ST900MM0006 [14]
declare -a productids='([0]="ST900MM0006 " [1]="ST600MM0006 " [2]="ST600MM0006 " [3]="ST600MM0006 " [4]="ST600MM0006 " [5]="ST600MM0006 " [6]="ST600MM0006 " [7]="ST600MM0006 " [8]="ST300MM0006 " [9]="ST300MM0006 " [10]="ST300MM0006 " [11]="ST300MM0006 " [12]="ST300MM0006 " [13]="ST300MM0006 ")'

The column from the CSV looks like this: column

I've used this method of appending to arrays in bash in this same script and it worked fine, can someone help me figure out why this isn't working? I tried doing productids+="$productid" and that, for some reason, just appends everything to the end of the first entry in the array.

Iterating through the array:

for i in ${productids[@]}
do
    echo "${productids[i]}"
done

Full output of this:

ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006
ST900MM0006

Body:
You can append to a Bash array easily like this:

productids+=("$productid")

You'll find similar examples in the Bash Guide on arrays.


来源: stackexchange

问:
Replace special charachter '´' in C
I have a string to parse and it maybe contains the symbol "& acute;" depends on user data. So i want to eliminate this symbole and replace it with '.
Example :

Before --> Won´t Get Fooled Again
After  --> Won't Get Fooled Again

This is my try but it dosen't work in any way ..

```<code>int main()
{

  char* permenant="Won´t Get Fooled Again";
  char* s=permenant;
  for ( ; *s && *s != '&'; s++) ;
  printf("found '&' character \n"); // ---> OK
  printf("s=%s \n",s);              // ---> OK
  if (*(s+1) == 'a' && *(s+2) == 'c' && *(s+3) == 'u' && *(s+4) == 't'  && *(s+5) == 'e'  && *(s+6) == ';') // ---> OK
  {
     *s='\'';   //---> NO also if *s='a'; segmentation fault !!
     while(*(s+7)!='\0')
     {
          *(s+1)=*(s+7);
          s++;
          printf("the next character is -> %c \n", *(s+7));
     }// ---> Segmentation fault also if i remove *s='\''

   }
  printf("permenant=%s \n",permenant);

return 0;

}
</code>```

答:
You are using string literal, which is const char, so you cannot modify it.

You can change it to

```<code>char permenant[]="Won´t Get Fooled Again";
</code>```

It will generate an array of chars initialized with the literal string's characters.

Side note: the s pointer is totally useless. You can perform your checks on permanent directly.

ContentLicense: CC BY-SA 3.0

Title: Replace special charachter '´' in C

Body:
I have a string to parse and it maybe contains the symbol "& acute;" depends on user data. So i want to eliminate this symbole and replace it with '.
Example :

Before --> Won´t Get Fooled Again
After  --> Won't Get Fooled Again

This is my try but it dosen't work in any way ..

int main()
{

  char* permenant="Won´t Get Fooled Again";
  char* s=permenant;
  for ( ; *s && *s != '&'; s++) ;
  printf("found '&' character \n"); // ---> OK
  printf("s=%s \n",s);              // ---> OK
  if (*(s+1) == 'a' && *(s+2) == 'c' && *(s+3) == 'u' && *(s+4) == 't'  && *(s+5) == 'e'  && *(s+6) == ';') // ---> OK
  {
     *s='\'';   //---> NO also if *s='a'; segmentation fault !!
     while(*(s+7)!='\0')
     {
          *(s+1)=*(s+7);
          s++;
          printf("the next character is -> %c \n", *(s+7));
     }// ---> Segmentation fault also if i remove *s='\''

   }
  printf("permenant=%s \n",permenant);

return 0;

}

Body:
You are using string literal, which is const char, so you cannot modify it.

You can change it to

char permenant[]="Won&acute;t Get Fooled Again";

It will generate an array of chars initialized with the literal string's characters.

Side note: the s pointer is totally useless. You can perform your checks on permanent directly.


问:
Is there a way to find all the functions exposed by a dll
I've been searching for a way to get all the strings that map to function names in a dll.

I mean by this all the strings for which you can call GetProcAddress. If you do a hex dump of a dll the symbols (strings) are there but I figure there must me a system call to acquire those names.

答:
It takes a bit of work, but you can do this programmaticly using the DbgHelp library from Microsoft.

Debugging Applications for Microsoft .Net and Microsoft Windows, by John Robbins is an excellent (if a little older) book which contains use details and full source.  And, you can pick it up on Amazon for the cheap!

OwnerDisplayName: minty

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Aaron


问:
Tools used for programming in Linux
I would like to start programming using the Linux operating system and all the free stuff out there.

What is the most common and the best language to use with Linux, C or C++ or C#?

What tools are similar to Turbo C, or Visual Studio in Windows?

答:
This is a very wide question and depends on many elements, such as: what is your programming experience, and more important - what do you want to develop.

The common languages are obviously C\C++, using mainly the GNU compiler. There are many IDEs available, like Eclipse CDT (maybe the most used one), CodeBlocks, and more. If you are coming from the Windows world, I guess you won't want to use text editors for coding, although there are many many Linux developers that use them (VI\ Emacs...)
For GUI development, you can use Qt - this is a wonderful, easy to start with infrastructure (which supports also threading, networking, and much more). Qt is C++ as well.

C# is still not widely used in Linux, as Mono is not ripe enough. This language is the favorite for .Net developers, but it doesn't give you very much Linux experience.

And of course, after all you have Java - where the JVM does the compatibility work behind the scenes for you...

Title: Tools used for programming in Linux


问:
Where does the space from the top-margin came from?
I started to learn CSS, and I got to that example in the internet:
https://www.w3schools.com/css/tryit.asp?filename=trycss_margin_shorthand

But I tried to play with it, and changed some things. Now the code looks like:

 div#my {
        border: 8px solid black;
        margin-left: 0%;
        margin-right: 0%;

        height: 500px;

        background-color: red;
    }

    div {
        border: 5px solid black;
        margin: inherit;
        background-color: lightblue;
    }

    ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="my">
   <div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.</div>
</div></code>```

What I see is a big blue block inside a big red block. The blue block collapse with his left and right sides to the red block's border, but from the top I have margin for some reason.

I think its because I chose inherit in the css element. But that says that I have a default margin to the page. Please, help here to understand.

答:
W3C schools explanation of inherit

The inherit keyword specifies that a property should inherit its value
  from its parent element.

In your code you have inherited the margin property of ALL DIV.

The div with id "my": inherit margin top and bottom from body (8px of margin), left and right are set.

The div without id: inherit the margin top and  bottom from div#id (always 8px) and the left and right from div#id (0% = 0px).

To better understand I added a different margin to body, and set a different margin left/right on div#my.

body {
  margin:50px;
  background-color:yellow;
}

div#my {
        border: 8px solid black;
        margin-left: 5px;
        margin-right: 0%;

        height: 500px;

        background-color: red;
    }

    div {
        border: 5px solid black;
        margin: inherit;
        background-color: lightblue;
    }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="my">
   <div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.</div>
</div></code>```

Body:
I started to learn CSS, and I got to that example in the internet:
https://www.w3schools.com/css/tryit.asp?filename=trycss_margin_shorthand

But I tried to play with it, and changed some things. Now the code looks like:

 div#my {
        border: 8px solid black;
        margin-left: 0%;
        margin-right: 0%;

        height: 500px;

        background-color: red;
    }

    div {
        border: 5px solid black;
        margin: inherit;
        background-color: lightblue;
    }

This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.

What I see is a big blue block inside a big red block. The blue block collapse with his left and right sides to the red block's border, but from the top I have margin for some reason.

I think its because I chose inherit in the css element. But that says that I have a default margin to the page. Please, help here to understand.

Body:
W3C schools explanation of inherit

The inherit keyword specifies that a property should inherit its value
  from its parent element.

In your code you have inherited the margin property of ALL DIV.

The div with id "my": inherit margin top and bottom from body (8px of margin), left and right are set.

The div without id: inherit the margin top and  bottom from div#id (always 8px) and the left and right from div#id (0% = 0px).

To better understand I added a different margin to body, and set a different margin left/right on div#my.

body {
  margin:50px;
  background-color:yellow;
}

div#my {
        border: 8px solid black;
        margin-left: 5px;
        margin-right: 0%;

        height: 500px;

        background-color: red;
    }

    div {
        border: 5px solid black;
        margin: inherit;
        background-color: lightblue;
    }

<div id="my">
   <div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.</div>
</div>


问:
how to pipe functions, when a promise in the promise in the middle checks authorization?
i'm trying to compose some functions together:

```<code>compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
</code>```

checkAuthorization returns a promise that check if a user is authorized.
buildParams receives someRequestData, and pipes the result to searchItem.

```<code>    checkAuthorization()
      .then(() => {
            compose(
                searchItem,
                buildParams
            )(someRequestData)
    }, (e) => {
       handleError(e)
    })
</code>```

I think it's OK, but I wish to have a more elegant look for readability, something like:

```<code>    compose(
      searchItem,
      checkAuthorization
      buildParams
    )(someRequestData)
</code>```

so what will happen is:
1) build params
2) checkAuth
3) search item

Any suggestions?

答:
Here's a composer to handle both sync functions and Promises. Looks like it works correctly maintaining the order:

// Async pipe try. Pass functions left to right
const pipePromises = (...fns) => x => fns.reduce((p, fn) => p.then(fn), Promise.resolve(x));

// functions for the test
const me = x => new Promise(function(resolve, reject) {
  setTimeout(() => resolve(x), 10)
})

const double = x => new Promise(function(resolve, reject) {
  setTimeout(() => resolve(x * 2), 30)
})

const inc = x => new Promise(function(resolve, reject) {
  setTimeout(() => resolve(x + 1), 400)
})

const log = x => { console.log('log: ', x); return x }

const syncTriple = x => x * 3; // sync function

// let's call our chain
pipePromises(
  me, log, // 3
  double, log, // 6
  syncTriple, log, // 18 -- SYNC
  inc, log, // 19
  double, log, // 38
  inc, log, // 39
  syncTriple, log, // 117 -- SYNC
  inc, log // 118
)(3) // 3```

Body:
i'm trying to compose some functions together:

compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));

checkAuthorization returns a promise that check if a user is authorized.
buildParams receives someRequestData, and pipes the result to searchItem.

    checkAuthorization()
      .then(() => {
            compose(
                searchItem,
                buildParams
            )(someRequestData)
    }, (e) => {
       handleError(e)
    })

I think it's OK, but I wish to have a more elegant look for readability, something like:

    compose(
      searchItem,
      checkAuthorization
      buildParams
    )(someRequestData)

so what will happen is:
1) build params
2) checkAuth
3) search item

Any suggestions?


问:
Android 12 hours Time Format getting wrong
I am using

```<code>DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm a");
String dateAsString = dateFormat.format(gmt);
</code>```

And getting String 06-06-2017 08:15 a.m.
Why I am getting a.m. instated of AM or PM?

答:
It depends on the locale. If you use SimpleDateFormat (which you may not want to do, see below), I recommend you give it an explicit locale. The one you construct uses the device’s default, which explains why you get different results on different devices. If you want that, use new SimpleDateFormat("MM-dd-yyyy hh:mm a", Locale.getDefault()) so the reader knows you have thought about it. To make sure you get AM and PM, use for example new SimpleDateFormat("MM-dd-yyyy hh:mm a", Locale.ENGLISH).

Why would you not want to use SimpleDateFormat? I consider it long outdated since the much better replacement for the Java 1.0 and 1.1 classes came out with Java 8 in 2014. They have also been backported to Android Java 7 in the ThreeTenABP. Get this and write for example:

```<code>    LocalDateTime gmt = LocalDateTime.of(2017, Month.JUNE, 6, 8, 15);
    DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("MM-dd-uuuu hh:mm a",
                                                                   Locale.ENGLISH);
    String dateAsString = gmt.format(dateTimeFormat);
</code>```

The result is

```<code>06-06-2017 08:15 AM
</code>```

To make explicit that the time is in GMT, you may use an OffsetDateTime with offset ZoneOffset.UTC.

Link: How to use ThreeTenABP in Android Project.

Body:
I am using

DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm a");
String dateAsString = dateFormat.format(gmt);

And getting String 06-06-2017 08:15 a.m.
Why I am getting a.m. instated of AM or PM?

Body:
It depends on the locale. If you use SimpleDateFormat (which you may not want to do, see below), I recommend you give it an explicit locale. The one you construct uses the device’s default, which explains why you get different results on different devices. If you want that, use new SimpleDateFormat("MM-dd-yyyy hh:mm a", Locale.getDefault()) so the reader knows you have thought about it. To make sure you get AM and PM, use for example new SimpleDateFormat("MM-dd-yyyy hh:mm a", Locale.ENGLISH).

Why would you not want to use SimpleDateFormat? I consider it long outdated since the much better replacement for the Java 1.0 and 1.1 classes came out with Java 8 in 2014. They have also been backported to Android Java 7 in the ThreeTenABP. Get this and write for example:

    LocalDateTime gmt = LocalDateTime.of(2017, Month.JUNE, 6, 8, 15);
    DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("MM-dd-uuuu hh:mm a",
                                                                   Locale.ENGLISH);
    String dateAsString = gmt.format(dateTimeFormat);

The result is

06-06-2017 08:15 AM

To make explicit that the time is in GMT, you may use an OffsetDateTime with offset ZoneOffset.UTC.

Link: How to use ThreeTenABP in Android Project.


问:
XSL if else statement
I want to check if a key has a value and if is empty to assign a default value.

```<code>    <xsl:element name="xtc">
          <xsl:choose name="type">
               <xsl:when test="type!= ''"/>
                 <xsl:value-of select="value"/>
               </xsl:when>
              <xsl:otherwise>
                  NULL
             </xsl:otherwise>
          </xsl:choose>
    </xsl:element>
</code>```

Is not really working for me, can someone kindly suggest what could be failing.

update
After some digging, I am pretty sure my code should be working, but it is not.

```<code>        <xsl:for-each select="webservice/parameters/parameter">
          <xsl:element name="{key}">
            <xsl:choose>
              <xsl:when test="{key} = ''">
              <xsl:text>NULL</xsl:text>
              </xsl:when>
              <xsl:otherwise>
               <xsl:value-of select="value"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:element>
        </xsl:for-each>
</code>```

But my application is throwing an error,

The token '{key}' was unexpected.
  expression = '{key} = ''' Remaining tokens are:  ('{key}' '=' '''') A
  failure occurred while parsing the style sheet.

答:
You need to replace this...

```<code><xsl:when test="{key} = ''">
</code>```

With this...

```<code><xsl:when test="key = ''">
</code>```

Attribute Value Templates do not apply here, as test already expects an expression.

Title: XSL if else statement

Body:
I want to check if a key has a value and if is empty to assign a default value.

    <xsl:element name="xtc">
          <xsl:choose name="type">
               <xsl:when test="type!= ''"/>
                 <xsl:value-of select="value"/>
               </xsl:when>
              <xsl:otherwise>
                  NULL
             </xsl:otherwise>
          </xsl:choose>
    </xsl:element>

Is not really working for me, can someone kindly suggest what could be failing.

update
After some digging, I am pretty sure my code should be working, but it is not.

        <xsl:for-each select="webservice/parameters/parameter">
          <xsl:element name="{key}">
            <xsl:choose>
              <xsl:when test="{key} = ''">
              <xsl:text>NULL</xsl:text>
              </xsl:when>
              <xsl:otherwise>
               <xsl:value-of select="value"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:element>
        </xsl:for-each>

But my application is throwing an error,

The token '{key}' was unexpected.
  expression = '{key} = ''' Remaining tokens are:  ('{key}' '=' '''') A
  failure occurred while parsing the style sheet.

Body:
You need to replace this...

<xsl:when test="{key} = ''">

With this...

<xsl:when test="key = ''">

Attribute Value Templates do not apply here, as test already expects an expression.


问:
Telegram API - Password to Dots
I am trying to create a ChatBot where using Python I interact with Telegram API to get update of previous message and reply suitably. My user's message could be a password which cannot be displayed and need to converted into dots(*****). Is there such feature to convert PW to dots ? Any help would be appreciated.

答: Telegram doesn't support this at this time, but you can try to use inline keyboard contain 0-9 number instead of it.</p>

Title: Telegram API - Password to Dots


问:
Twilio Programable Chat Rest API Accepting JSON
When creating a Channel the REST API seems to ignore any data in requests with a JSON body. Example:

```<code>curl -X POST https://chat.twilio.com/v2/Services/{instance sid}/Channels -H 'authorization: Basic blah blah blah' -H 'content-type: application/json' -d '{ "friendly_name": "Test Chat One", "type": "private" }'
</code>```

Does the API not support JSON requests? The docs show requests with post with form data https://www.twilio.com/docs/api/chat/rest/channels?code-sample=code-create-a-channel&code-language=curl&code-sdk-version=default but not JSON??

Have I missed something?

Ta

答:
Twilio developer evangelist here.

The Twilio API does not support JSON requests (though it will respond with JSON if you ask it to).

Check the documentation on the API here. It says:

In the PUT or POST, you represent the properties of the object you wish to update as form urlencoded key/value pairs. Don't worry, this is already the way browsers encode POSTs by default. But be sure to set the HTTP Content-Type header to "application/x-www-form-urlencoded" for your requests if you are writing your own client.

Body:
When creating a Channel the REST API seems to ignore any data in requests with a JSON body. Example:

curl -X POST https://chat.twilio.com/v2/Services/{instance sid}/Channels -H 'authorization: Basic blah blah blah' -H 'content-type: application/json' -d '{ "friendly_name": "Test Chat One", "type": "private" }'

Does the API not support JSON requests? The docs show requests with post with form data https://www.twilio.com/docs/api/chat/rest/channels?code-sample=code-create-a-channel&code-language=curl&code-sdk-version=default but not JSON??

Have I missed something?

Ta


问: When and how do browsers render

Title: When and how do browsers render <style> tag in <body>?

Body: I noticed that if I place

Body:
TL;DR:

In short, the answer to your question is: once a <style> tag is met inside <body> everything stops and the CSSOM is being rebuilt and re-applied to all existing rendered (painted) content.

Placing <style> tags inside <body> is considered bad practice because it can create FOUC. But if your <style> tag only contains rules for elements placed after it in DOM, placing it in body is perfectly fine, as no FOUC can happen.

The render process of a page is quite complex. But, overly-simplified, here's what happens

<head> is read and CSSOM is built. All CSS is render blocking, unless explicitly specified otherwise by use of @media queries. The non-blocking CSS is still loaded, it's not entirely skipped.

DOM building and CSSOM building are ran in paralel, but all <script> execution is deferred until CSSOM has been built (on </head> tag met), at which point all loaded <script>s are ran, blocking DOM building. JS can make changes to CSSOM at this point.  *

Placing <style> tags inside <body> interrupts everything (JS execution and DOM building), CSSOM is being updated and applied to the already rendered content, if any. Everything is resumed after.

* On further testing it appears <head> parsing is single threaded. CSSOM building does block javascript execution but it's done is stages, as each <link /> and <style> tags are met (a <script> placed after a <link> will only execute after the <link /> was resolved and applied to CSSOM). <script> tags placed in between CSS resources are not deferred until all CSS resources in <head> are parsed, as I initially thought.

And, of course js can make changes to CSSOM at run time. See this question I asked for more on how js execution is blocked by CSSOM building.

All the above apply to the normal loading, without considering async, which adds a whole new layer of complexity to it.

If you're interested in more details, I recommend going through the Performance chapter of Web Fundamentals, provided by Google.


问:
How to get a specific part of a URL using PHP
I've had a look around and can't find an answer specific to my needs...

This is the URL being sent back to my redirect page from an identity server: http://localhost/?code=92092c2f65560d835a73cda852393316&state=random_state&session_state=CEwifhoy_x1RJWH-DoV_9Q1yJVNUXV4z5YRGGuXsUvs.39c667f469b8f6585a9f699d0b7d76f3

I need to get the code between "code=" and "&state".

Then put it in the <> part of "grant_type=authorization_code&code=<>&redirect_uri=<>" so I can request a token. This part I can do, I just can't figure out how to get the code out of the URL.

Thanks.

答:
For this you can use the $_GET variable. It will become more clear for you if you do:

```<code><?php
print_r($_GET);
?>
</code>```

Then you can see there is a key "code" in this array. You can get the value of this key like this:

```<code><?php
$code = $_GET['code'];
?>
</code>```

Body:
For this you can use the $_GET variable. It will become more clear for you if you do:

<?php
print_r($_GET);
?>

Then you can see there is a key "code" in this array. You can get the value of this key like this:

<?php
$code = $_GET['code'];
?>


问:
Firebase and Ionic 1.x - unable to add several objects at once to DB
The usual usage of my app (ionic 1.x and firebase) is pushing one object at a time, but there might be a case where several objects must be added to the DB one after another. The official docs say nothing about such case. This is the code for pushing one object each time:

```<code>this.addExpenseToDB = function (expense, uid) {
  var newExpenseKey = firebase.database().ref().child('expenses').push().key;
  var updates = {};
  var keyByDate = "someKey";

  updates['/user-data/' + uid + '/' + keyByDate + '/'+ newExpenseKey] = expense;

  return firebase.database().ref().update(updates);
};
</code>```

Two questions, A: How can I push several objects at once? B How can I get a confirmation (promise? callback?) that the data saved successfully to the DB? The docs, again, are lacking this information :\

答:
You can fan an object, similar to what you are doing now. First you need to pass an array of objects to add to the database, then fan them out like you current do in a loop:

```<code>this.addExpenseToDB = function (arr) {
    // arr: [{expense: ..., uid: ...}];

    var updates = {};
    for(var i=0; i<arr.length; i++) {
        var newExpenseKey = firebase.database().ref().child('expenses').push().key;
        var keyByDate = "someKey";
        updates['/user-data/' + arr[i].uid + '/' + keyByDate + '/'+ newExpenseKey] = arr[i].expense;
    }

    return firebase.database().ref().update(updates);
};
</code>```

push(...) returns a promise so listen for the response:

```<code>this.addExpenseToDB([expense: ..., uid: ...])
    .then(response => {

    })
    .catch(error => {

    });
</code>```

With callbacks

```<code>this.addExpenseToDB = function (arr, callback) {
    ...
    return firebase.database().ref().update(updates, function(error) {
        callback(error);
    });
}
this.updated = function(error) {
    if(error)
        // error
    else
       // success
}
this.addExpenseToDB([expense: ..., uid: ...], this.updated);
</code>```

Body:
The usual usage of my app (ionic 1.x and firebase) is pushing one object at a time, but there might be a case where several objects must be added to the DB one after another. The official docs say nothing about such case. This is the code for pushing one object each time:

this.addExpenseToDB = function (expense, uid) {
  var newExpenseKey = firebase.database().ref().child('expenses').push().key;
  var updates = {};
  var keyByDate = "someKey";

  updates['/user-data/' + uid + '/' + keyByDate + '/'+ newExpenseKey] = expense;

  return firebase.database().ref().update(updates);
};

Two questions, A: How can I push several objects at once? B How can I get a confirmation (promise? callback?) that the data saved successfully to the DB? The docs, again, are lacking this information :\

Body:
You can fan an object, similar to what you are doing now. First you need to pass an array of objects to add to the database, then fan them out like you current do in a loop:

this.addExpenseToDB = function (arr) {
    // arr: [{expense: ..., uid: ...}];

    var updates = {};
    for(var i=0; i<arr.length; i++) {
        var newExpenseKey = firebase.database().ref().child('expenses').push().key;
        var keyByDate = "someKey";
        updates['/user-data/' + arr[i].uid + '/' + keyByDate + '/'+ newExpenseKey] = arr[i].expense;
    }

    return firebase.database().ref().update(updates);
};

push(...) returns a promise so listen for the response:

this.addExpenseToDB([expense: ..., uid: ...])
    .then(response => {

    })
    .catch(error => {

    });

With callbacks

this.addExpenseToDB = function (arr, callback) {
    ...
    return firebase.database().ref().update(updates, function(error) {
        callback(error);
    });
}
this.updated = function(error) {
    if(error)
        // error
    else
       // success
}
this.addExpenseToDB([expense: ..., uid: ...], this.updated);


问:
Reduce Bootstrap list width
I am creating a list and styling it with Bootstrap. The HTML looks something like this:

```<code><div class="list-group">
    <a href="/link" class="list-group-item list-group-item-success">Name</a>
    <a href="/link" class="list-group-item list-group-item-danger">Name</a>
</div>
</code>```

When this displays, the list elements take up the whole page.

If not for the coloring, this would not be a big deal. How can I make the list elements stretch only as far as the text? Thanks!

答:
You can use display:inline or display:inline-block property to get it

```<code>.somethingClass > .list-group {
   display:inline-block; /* You can use inline also */
}
</code>```

HTML PART

```<code>    <div class="somethingClass">
    <div class="list-group">
        <a href="/link" class="list-group-item list-group-item-success">Name</a>
        <a href="/link" class="list-group-item list-group-item-danger">Name</a>
    </div>
</div>
</code>```

When you are using somethingClass > list-group it will effect only list-group when it will come inside the somethingCalss so bootstrap list-group class is save with own propery which gives by bootstrap.

Title: Reduce Bootstrap list width

Body:
I am creating a list and styling it with Bootstrap. The HTML looks something like this:

    Name
    Name

When this displays, the list elements take up the whole page.

If not for the coloring, this would not be a big deal. How can I make the list elements stretch only as far as the text? Thanks!

Body:
You can use display:inline or display:inline-block property to get it

.somethingClass > .list-group {
   display:inline-block; /* You can use inline also */
}

HTML PART

    <div class="somethingClass">
    <div class="list-group">
        <a href="/link" class="list-group-item list-group-item-success">Name</a>
        <a href="/link" class="list-group-item list-group-item-danger">Name</a>
    </div>
</div>

When you are using somethingClass > list-group it will effect only list-group when it will come inside the somethingCalss so bootstrap list-group class is save with own propery which gives by bootstrap.


问:
How do I reorder UITableView cells in Realm Swift?
I'm using Realm for my Note-taking-app.
I used core data before and I am now migrating core data to realm, but i got trouble! reordering objects like this causes error.

```<code>do {
let realm = try Realm()
let source = myNote[sour!.row]
try realm.write() {
 myNote.remove(objectAtIndex: sourceIndexPath!.row)
 myNote.insert(source, at: destensionIndexPath!.row)
 }
 }
 catch {
 print("handle error")
 }
</code>```

So I added
orderPosition property to my object

```<code>dynamic var orderPosition: Int = 0
</code>```

and changed tableView moveRowAtIndexPath to this
 ReorderingRealmResultsInTableView.swift

but it didn't helped a lot.
so How can I reorder objects in realm?

答: A List is certainly efficient and clean, though I wasn't sure how I would sync it through a server. So in my case I'm using orderPosition: Double, and the value is calculated as the middle of the two existing orderPositions that the object is inserted between. Also keep in mind that you can perform the write without updating the tableView from the notification: try! list.realm?.commitWrite(withoutNotifying: [notificationToken!]).

Body:
I'm using Realm for my Note-taking-app.
I used core data before and I am now migrating core data to realm, but i got trouble! reordering objects like this causes error.

do {
let realm = try Realm()
let source = myNote[sour!.row]
try realm.write() {
 myNote.remove(objectAtIndex: sourceIndexPath!.row)
 myNote.insert(source, at: destensionIndexPath!.row)
 }
 }
 catch {
 print("handle error")
 }

So I added
orderPosition property to my object

dynamic var orderPosition: Int = 0

and changed tableView moveRowAtIndexPath to this
 ReorderingRealmResultsInTableView.swift

but it didn't helped a lot.
so How can I reorder objects in realm?


问:
How to stream live video from DJI Professional 3 camera?
I have to get the live stream video from DJI Phantom 3 camera in my C++ application, in order to do a Computer Vision processing in OpenCV.

First I tried sending the H264 raw data through an UDP socket, inside this callback:

```<code>        mReceivedVideoDataCallBack = new CameraReceivedVideoDataCallback() {

        @Override
        public void onResult(byte[] videoBuffer, int size) {
            //Here, I call a method from a class I created, that sends the buffer through UDP
            if (gravar_trigger) controleVideo.enviarFrame(videoBuffer, size);

            if (mCodecManager != null)  mCodecManager.sendDataToDecoder(videoBuffer, size);

        }

    };
</code>```

That communication above works well. However, I haven't been able to decode that UDP H264 data in my C++ desktop application. I have tested with FFmpeg lib, but couldn't get to alocate an AVPacketwith my UDP data, in order to decode using avcodec_send_packet and avcodec_receive_frame. I also had problems with AVCodecContext, since my UDP communication wasn't a stream like RTSP, where it could get information about its source. Therefore, I had to change how I was trying to solve the problem.

Then, I found libstreaming, in which can be associate to stream the android video camera to a Wowza Server, creating something like a RTSP stream connection, where the data could be obtained in my final C++ application easily using OpenCV videoCapture. However, libstreaming uses its own surfaceView. In other words, I would have to link the libstreaming surfaceView with the DJI Drone's videoSurface. I'm really new to Android, so don't have any clue of how to do that.

To sum up, is that the correct approach? Someone has a better idea? Thanks in advance

答:
After a long time, I finally developed a system that can stream the DJI drone camera correctly

https://github.com/raullalves/DJI-Drone-Camera-Streaming

Body:
I have to get the live stream video from DJI Phantom 3 camera in my C++ application, in order to do a Computer Vision processing in OpenCV.

First I tried sending the H264 raw data through an UDP socket, inside this callback:

        mReceivedVideoDataCallBack = new CameraReceivedVideoDataCallback() {

        @Override
        public void onResult(byte[] videoBuffer, int size) {
            //Here, I call a method from a class I created, that sends the buffer through UDP
            if (gravar_trigger) controleVideo.enviarFrame(videoBuffer, size);

            if (mCodecManager != null)  mCodecManager.sendDataToDecoder(videoBuffer, size);

        }

    };

That communication above works well. However, I haven't been able to decode that UDP H264 data in my C++ desktop application. I have tested with FFmpeg lib, but couldn't get to alocate an AVPacketwith my UDP data, in order to decode using avcodec_send_packet and avcodec_receive_frame. I also had problems with AVCodecContext, since my UDP communication wasn't a stream like RTSP, where it could get information about its source. Therefore, I had to change how I was trying to solve the problem.

Then, I found libstreaming, in which can be associate to stream the android video camera to a Wowza Server, creating something like a RTSP stream connection, where the data could be obtained in my final C++ application easily using OpenCV videoCapture. However, libstreaming uses its own surfaceView. In other words, I would have to link the libstreaming surfaceView with the DJI Drone's videoSurface. I'm really new to Android, so don't have any clue of how to do that.

To sum up, is that the correct approach? Someone has a better idea? Thanks in advance


问:
Background color seeping into body when expanded on height
I've got an angular application I'm working on right now that implements angular-pdf.

The controller and view work absolutely fine and the pdf is displayed just fine, with one problem. As the PDF is higher than the min-height of the module it expands the height of it.

This seems to make the background color into the color of the modules background.
Usually the background is grey-ish, but as the height expands the module's background color seems to seep into the body (the page is a placeholder. I have no affiliation with them!):

As you can see the background is different about 80% down the webpage.

I'd like to have the same background-color all the way down.

As it stands now I set the background-color in a stylesheet and refer to body:

```<code>body {
    background-color: #D2D5D3;
    -webkit-font-smoothing: antialiased;
}
</code>```

Other than that I do nothing with the body's background. The only other background I have is taken from md-content:

```<code><div ng-controller="pdfpageController as vm">
    <md-content id="pdfpage" layout-padding>
        <md-toolbar>
            <div class="md-toolbar-tools">
                <md-button class="md-primary md-raised" ng-click="goback()">
                    <md-icon md-svg-icon="../resources/img/arrow_left.svg"></md-icon>
                    <span class="orange"><b>Back</b></span>
                </md-button>
                <h2 flex md-truncate class="text-center">Shifts</h2>
            </div>
        </md-toolbar>
        <md-toolbar class="md-wan md-hue-2" style="border-top: 0.5px solid black">
            <h1>{{pdfName}}</h1>
        </md-toolbar>

            <ng-pdf template-url="app/views/partials/viewer.html" scale="page-fit"></ng-pdf>
            <canvas id="pdf-canvas"></canvas>d="test-canvas"></canvas>-->

        <hr />
        <div layout="row" layout-align="start center">
            <div class="container">
                <span><b>Signature:</b></span>
                <signature-pad accept="accept" clear="clear" height="220" width="568" dataurl="dataurl"></signature-pad>
                <div layout="row">
                    <md-button ng-model="signature" class="md-raised md-primary" ng-click="signature = accept()">Use signature</md-button>
                    <md-button ng-model="clearSig" class="md-warn md-raised md-hue-2" ng-click="clearSig = clear()">Clear signature</md-button>
                </div>
            </div>
        </div>

        <!--<iframe style="width: 400px; height: 400px;"></iframe>-->
    </md-content>
</div>
</code>```

Does anyone have a suggestion on how I stop the md-colors background from seeping into the body's background?

答: Try adding min-height: 100% to body, and also make sure the content of body is not position:absolute or fixed, try position:relative for body content so that the body adapts its size to the contents size

Body:
I've got an angular application I'm working on right now that implements angular-pdf.

The controller and view work absolutely fine and the pdf is displayed just fine, with one problem. As the PDF is higher than the min-height of the module it expands the height of it.

This seems to make the background color into the color of the modules background.
Usually the background is grey-ish, but as the height expands the module's background color seems to seep into the body (the page is a placeholder. I have no affiliation with them!):

As you can see the background is different about 80% down the webpage.

I'd like to have the same background-color all the way down.

As it stands now I set the background-color in a stylesheet and refer to body:

body {
    background-color: #D2D5D3;
    -webkit-font-smoothing: antialiased;
}

Other than that I do nothing with the body's background. The only other background I have is taken from md-content:

    <md-content id="pdfpage" layout-padding>
        <md-toolbar>

                <md-button class="md-primary md-raised" ng-click="goback()">
                    <md-icon md-svg-icon="../resources/img/arrow_left.svg"></md-icon>
                    Back
                </md-button>

Shifts

        </md-toolbar>
        <md-toolbar class="md-wan md-hue-2" style="border-top: 0.5px solid black">

{{pdfName}}

        </md-toolbar>

            <ng-pdf template-url="app/views/partials/viewer.html" scale="page-fit"></ng-pdf>
            <canvas id="pdf-canvas"></canvas>d="test-canvas"></canvas>-->

                Signature:
                <signature-pad accept="accept" clear="clear" height="220" width="568" dataurl="dataurl"></signature-pad>

                    <md-button ng-model="signature" class="md-raised md-primary" ng-click="signature = accept()">Use signature</md-button>
                    <md-button ng-model="clearSig" class="md-warn md-raised md-hue-2" ng-click="clearSig = clear()">Clear signature</md-button>

    </md-content>

Does anyone have a suggestion on how I stop the md-colors background from seeping into the body's background?


问:
Questions on directory on shell
Say I make a directory using mkdir like this:
temp/king/learning 1

And I want to delete the folder learning 1 by using rmdir

But it gives me an error message, possibly because of the space between learning and 1. How do I delete this folder without getting an error message?

Thank you so much.

答:
Place the directory name in quotes.

```<code>C:\> rd "temp\king\learning 1"
</code>```

The quotes are not a part of the path name, but tell the command-line parser that the string between the quotes is a single string. Without the quotes, you are giving the rd (same as rmdir) command two separate parameters.

Title: Questions on directory on shell

Body:
Place the directory name in quotes.

C:\> rd "temp\king\learning 1"

The quotes are not a part of the path name, but tell the command-line parser that the string between the quotes is a single string. Without the quotes, you are giving the rd (same as rmdir) command two separate parameters.


问:
Nunit Ordering Issue with 2 classes in a project
I am trying to run Unit TestCases through Nunit where i have two Unit TestCase classes,
1 class which deals with Product Console
2nd class which deals with other Windows processes and services, and both are under same project and they are set a sequence through Nunit Ordering which is very important aspect as all the testcases have to run sequentially.

When I am trying to run the testcases through command line, only the testcases specific to one class is running irrespective or ordering.

So, for example :

```<code>NoConsoleclass.cs

[Test , Order(1)]
public void Test1()
{}

[Test, Order(3)]
public void Test3()
{}

ConsoleTestCases.cs
[Test, Order(2)]
public void Test2()
{}

nunit3-console projectname.dll is running 1 and 3 first and then test 2.
</code>```

Is there any way I could attain it the way I want as test 1, test 2 and then test 3??

I know, sequencing or pre-requisites is not adviceable, but it is required for this specific suite.

Kindly let me know
Thanks

答:
Not currently, no.

There's an open feature request to allow the ordering of different TestFixtures - see the link below.
https://github.com/nunit/nunit/issues/345

This still wouldn't cover your case however, of wanting to interleave tests from different classes in a specific order. (Although would, if you were able to break this up into three classes.)

There's also an open feature request for a TestDependencyAttribute - which would allow you to specify one test as being dependent on the completion of others. This perhaps seems close to what you want to represent, than actual explicit ordering. Find that one at the link below.
https://github.com/nunit/nunit/issues/51

Body:
I am trying to run Unit TestCases through Nunit where i have two Unit TestCase classes,
1 class which deals with Product Console
2nd class which deals with other Windows processes and services, and both are under same project and they are set a sequence through Nunit Ordering which is very important aspect as all the testcases have to run sequentially.

When I am trying to run the testcases through command line, only the testcases specific to one class is running irrespective or ordering.

So, for example :

NoConsoleclass.cs

[Test , Order(1)]
public void Test1()
{}

[Test, Order(3)]
public void Test3()
{}

ConsoleTestCases.cs
[Test, Order(2)]
public void Test2()
{}

nunit3-console projectname.dll is running 1 and 3 first and then test 2.

Is there any way I could attain it the way I want as test 1, test 2 and then test 3??

I know, sequencing or pre-requisites is not adviceable, but it is required for this specific suite.

Kindly let me know
Thanks


问:
How to Compare two Arrays are Equal using Javascript?
I want position of the array is to be also same and value also same.

```<code>var array1 = [4,8,9,10];
var array2 = [4,8,9,10];
</code>```

I tried like this

```<code>var array3 = array1 === array2   // returns false
</code>```

答:
Use lodash.
In ES6 syntax:

```<code>import isEqual from 'lodash/isEqual';
let equal = isEqual([1,2], [1,2]);  // true
</code>```

Or previous js versions:

```<code>var isEqual = require('lodash/isEqual');
var equal = isEqual([1,2], [1,2]);  // true
</code>```

Body:
I want position of the array is to be also same and value also same.

var array1 = [4,8,9,10];
var array2 = [4,8,9,10];

I tried like this

var array3 = array1 === array2   // returns false

Body:
Use lodash.
In ES6 syntax:

import isEqual from 'lodash/isEqual';
let equal = isEqual([1,2], [1,2]);  // true

Or previous js versions:

var isEqual = require('lodash/isEqual');
var equal = isEqual([1,2], [1,2]);  // true