问:
php form with database embed in wordpress
I am creating custom form in php and using database. I want to integrate that form in wordpress; for this i create one template(customform.php) and adding in page. My php code is smoothly running on xampp but not in wordpress.

Please help me to integrate code in wordpress.

```<code>/*CustomForm php*/
<?php /* Template Name: CustomForm */ ?>
<?php  require_once("conn.php");?>

<?php get_header(); ?>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<div id="content" class="full-width">
    <?php while ( have_posts() ) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<body>
    <form name="course_information" id="course_information" method="post" action="course_information_action.php" >
    <div>
    <h1 class="heading">Product Details</h1>
    <h3>Product Type</h3>
    <?php
        $sql = "select id,course from course_master";
        $result = mysqli_query($con,$sql);
        $selectbox = '';

        $selectbox .= '<select id="course_master" name="course_master" class="select_style"><option value="0"> -- select --</option>';
        while($data = mysqli_fetch_assoc($result))
        {
            $selectbox .= "<option value=".$data['id'].">".$data['course']."</option>";
        }
        $selectbox .= '</select>';
        echo $selectbox;
    ?>

    <h3>Product</h3>

    <div><select class="select_style" id="course_details" name="course_details" >
        <option value="0"> -- select --</option>
    </select></div>

    <p></p>
    <div id="ex_data">
    <input type="checkbox" name="check" id="check" value="" /> I need a product demonstration, installation assistance and for other queries at no additional cost</div>

    <p></p>
    <div id="after_check">
    <div><textarea rows="5" cols="50" name="requirements" id="requirements" placeholder="Please provide your requirement here"></textarea></div>

    <h3>Address</h3>
    <div><textarea rows="5" cols="50" name="address" id="address" placeholder="Please provide your address for visit purpose"></textarea></div>
    </div>
    <span id="key_val">
    <h3>Please enter existing serial for extend subscription: </h3>
    <div><input type="text" name="key" id="key" value="" /></div>
    </span>

    <h3>No. of licenses<span class="star_require">*</span> : </h3>
    <div><input type="text" name="licenses" id="licenses" value="" required /></div>

    <h3>Sub Total : </h3>
    <span id="sub_total"></span>
    <div><input type="hidden" name="price" id="hidden_subtotal" value="" /></div>

    <div><input class="form_btn" type="submit" id="continue_first" value="continue" /></div>
     </div>

    <div id="contact_details">
    h1 class="heading">Contact Details</h1>
    <h3>Email Address<span class="star_require">*</span>:</h3>
    <div><input type="text" id="email" name="email" value="" required /></div>

    <h3>Mobile <span class="star_require">*</span>: </h3>
    <div><input type="text" id="mobile" name="mobile" value="" maxlength="10" required /></div>

    <div><input class="form_btn" type="submit" id="continue" value="continue" /></div>
    </div>

    <div id="billing_details">
    h1 class="heading">Billing Details</h1>
    <h3>Your Name/Organisation Name<span class="star_require">*</span>:</h3>
    <div><input type="text" id="name" name="name" value="" required /></div>

    <h3>Your Area PIN code <span class="star_require">*</span>: </h3>
    <div><input type="text" id="pincode" name="pincode" value="" maxlength="10" required /></div>

    <div><input class="form_btn" type="submit" id="submit" value="submit" /></div>

    </div>
 </form>

        </div>
    <?php endwhile; ?>
</div>
<?php get_footer();

/*contact form.js*/

// JavaScript Document
$(document).ready(function(){
        $("#key_val").hide();
        $("div#ex_data").hide();
        $("div#after_check").hide();
        $no = $("#licenses").val();

        $("#licenses").keypress(function (e) {
             //if the letter is not digit then display error and don't type anything
             if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                       return false;
            }
           });

        $("#course_master").change(function(){
            var cid = $(this).val();
            if(cid == 2)
            {
                $("#key_val").show();
                $('#licenses').attr('disabled', 'disabled');
                $("div#ex_data").css("display","none");
            }
            else{
                $("#key_val").hide();
                $("div#ex_data").show(1000);
                $("#licenses").removeAttr("disabled");
            }
            $.ajax({
                type:"POST",
                url:"get_course_details.php",
                data:"cid="+cid,
                success:function(msg)
                {
                    $("#course_details").html(msg);
                }
            });

        });

        $("#course_details").change(function(){
            var id = $(this).val();
            $.ajax({
                type:"POST",
                url:"get_course_info.php",
                data:"id="+id,
                success:function(msg)
                {
                    $("#hidden_subtotal").val(msg);
                    if($no == '')
                    {
                        var total = msg * 1;
                        $("#sub_total").text(total);
                    }
                    else
                    {
                        var total = msg * $no;
                        $("#sub_total").text(total);
                    }
                }
            });
        });

        $("#check").click(function(){
            if($(this).is(":checked")){
                $("div#after_check").show(1000);
                $("div#after_check #address").attr("required","true");
                $("div#after_check h3").append("<span class='star_require'>*</span>");
            }
            else
            {
                $("div#after_check").hide(1000);
                $("div#after_check #address").attr("required","false");
            }
        });

        $("#key").blur(function(){
            var key = $("#key").val();
            $.ajax({
                type:"POST",
                url:"validate_key.php",
                data:"key="+key,
                success:function(msg)
                {
                    if(msg ==1)
                    {
                        $("#licenses").removeAttr("disabled");
                    }
                    else
                    {
                        $('#licenses').attr('disabled', 'disabled');
                    }
                }
            });

        });

        $("#licenses").blur(function(){
            var subtotal = $("#hidden_subtotal").val();
            if(!isNaN(subtotal) && subtotal != '' && subtotal != 0)
            {
                subtotal = subtotal * $("#licenses").val();
                $("#sub_total").text(subtotal);
            }

        });

        $("#continue_first").click(function(){
            $("div#contact_details").css("display","block");

        });
        $("#continue").click(function(){
            $("div#billing_details").css("display","block");

        });

        $("#submit").click(function(){
            var email = $("#email").val();
            var mobile = $("#mobile").val();
            var pincode = $("#pincode").val();
            if( !isValidEmailAddress( email ) ) {
                alert("invalid email address!"); return false;
            }
            else if(isNaN(mobile) || (mobile.length < 10) )
            {
                alert("invalid mobile no!"); return false;
            }
            else if(isNaN(pincode))
            {
                alert("Invalid Pincode!");return false;
            }
            else{
                alert("success");
                $( "#course_information" ).submit();
                return true;
            }

        });

    });

    //if( !isValidEmailAddress( emailaddress ) ) { /* do stuff here */ }

    function isValidEmailAddress(emailAddress) {
    var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
    return pattern.test(emailAddress);
};
</code>```

答: Firstly for integrating from in wordpress you don't need to create config file and include. Just create template in theme which you are using and create page in wordpress admin and call this template.</p>

Body:
I am creating custom form in php and using database. I want to integrate that form in wordpress; for this i create one template(customform.php) and adding in page. My php code is smoothly running on xampp but not in wordpress.

Please help me to integrate code in wordpress.

/*CustomForm php*/
<?php /* Template Name: CustomForm */ ?>
<?php  require_once("conn.php");?>

<?php get_header(); ?>

    <?php while ( have_posts() ) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    <form name="course_information" id="course_information" method="post" action="course_information_action.php" >

Product Details

Product Type

    <?php
        $sql = "select id,course from course_master";
        $result = mysqli_query($con,$sql);
        $selectbox = '';

        $selectbox .= '<select id="course_master" name="course_master" class="select_style"><option value="0"> -- select --</option>';
        while($data = mysqli_fetch_assoc($result))
        {
            $selectbox .= "<option value=".$data['id'].">".$data['course']."</option>";
        }
        $selectbox .= '</select>';
        echo $selectbox;
    ?>

Product

<select class="select_style" id="course_details" name="course_details" >
        <option value="0"> -- select --</option>
    </select>

    <input type="checkbox" name="check" id="check" value="" /> I need a product demonstration, installation assistance and for other queries at no additional cost

<textarea rows="5" cols="50" name="requirements" id="requirements" placeholder="Please provide your requirement here"></textarea>

Address

<textarea rows="5" cols="50" name="address" id="address" placeholder="Please provide your address for visit purpose"></textarea>

Please enter existing serial for extend subscription:

<input type="text" name="key" id="key" value="" />

No. of licenses* :

<input type="text" name="licenses" id="licenses" value="" required />

Sub Total :

<input type="hidden" name="price" id="hidden_subtotal" value="" />

<input class="form_btn" type="submit" id="continue_first" value="continue" />

    h1 class="heading">Contact Details

Email Address*:

<input type="text" id="email" name="email" value="" required />

Mobile *:

<input type="text" id="mobile" name="mobile" value="" maxlength="10" required />

<input class="form_btn" type="submit" id="continue" value="continue" />

    h1 class="heading">Billing Details

Your Name/Organisation Name*:

<input type="text" id="name" name="name" value="" required />

Your Area PIN code *:

<input type="text" id="pincode" name="pincode" value="" maxlength="10" required />

<input class="form_btn" type="submit" id="submit" value="submit" />

 </form>

    <?php endwhile; ?>

<?php get_footer();

/*contact form.js*/

// JavaScript Document
$(document).ready(function(){
        $("#key_val").hide();
        $("div#ex_data").hide();
        $("div#after_check").hide();
        $no = $("#licenses").val();

        $("#licenses").keypress(function (e) {
             //if the letter is not digit then display error and don't type anything
             if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                       return false;
            }
           });

        $("#course_master").change(function(){
            var cid = $(this).val();
            if(cid == 2)
            {
                $("#key_val").show();
                $('#licenses').attr('disabled', 'disabled');
                $("div#ex_data").css("display","none");
            }
            else{
                $("#key_val").hide();
                $("div#ex_data").show(1000);
                $("#licenses").removeAttr("disabled");
            }
            $.ajax({
                type:"POST",
                url:"get_course_details.php",
                data:"cid="+cid,
                success:function(msg)
                {
                    $("#course_details").html(msg);
                }
            });

        });

        $("#course_details").change(function(){
            var id = $(this).val();
            $.ajax({
                type:"POST",
                url:"get_course_info.php",
                data:"id="+id,
                success:function(msg)
                {
                    $("#hidden_subtotal").val(msg);
                    if($no == '')
                    {
                        var total = msg * 1;
                        $("#sub_total").text(total);
                    }
                    else
                    {
                        var total = msg * $no;
                        $("#sub_total").text(total);
                    }
                }
            });
        });

        $("#check").click(function(){
            if($(this).is(":checked")){
                $("div#after_check").show(1000);
                $("div#after_check #address").attr("required","true");
                $("div#after_check h3").append("*");
            }
            else
            {
                $("div#after_check").hide(1000);
                $("div#after_check #address").attr("required","false");
            }
        });

        $("#key").blur(function(){
            var key = $("#key").val();
            $.ajax({
                type:"POST",
                url:"validate_key.php",
                data:"key="+key,
                success:function(msg)
                {
                    if(msg ==1)
                    {
                        $("#licenses").removeAttr("disabled");
                    }
                    else
                    {
                        $('#licenses').attr('disabled', 'disabled');
                    }
                }
            });

        });

        $("#licenses").blur(function(){
            var subtotal = $("#hidden_subtotal").val();
            if(!isNaN(subtotal) && subtotal != '' && subtotal != 0)
            {
                subtotal = subtotal * $("#licenses").val();
                $("#sub_total").text(subtotal);
            }

        });

        $("#continue_first").click(function(){
            $("div#contact_details").css("display","block");

        });
        $("#continue").click(function(){
            $("div#billing_details").css("display","block");

        });

        $("#submit").click(function(){
            var email = $("#email").val();
            var mobile = $("#mobile").val();
            var pincode = $("#pincode").val();
            if( !isValidEmailAddress( email ) ) {
                alert("invalid email address!"); return false;
            }
            else if(isNaN(mobile) || (mobile.length < 10) )
            {
                alert("invalid mobile no!"); return false;
            }
            else if(isNaN(pincode))
            {
                alert("Invalid Pincode!");return false;
            }
            else{
                alert("success");
                $( "#course_information" ).submit();
                return true;
            }

        });

    });

    //if( !isValidEmailAddress( emailaddress ) ) { /* do stuff here */ }

    function isValidEmailAddress(emailAddress) {
    var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
    return pattern.test(emailAddress);
};


来源: stackexchange

问:
Apply CSS conditionally to last list item without JavaScript
Say you have a list of items:

```<code><li>abc</li>
<li>efg</li>
<li>hij</li>
</code>```

You want the last item to be red, but only if there is more than one
, is that possible without JavaScript?

答:
How about a selector for the last but not the first child?

li:last-child:not(:first-child) {
  color: red
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>

<ul>
  <li>alone</li>
</ul></code>```

ContentLicense: CC BY-SA 3.0

Body:
Say you have a list of items:

abc

efg

hij

You want the last item to be red, but only if there is more than one
, is that possible without JavaScript?

Body:
How about a selector for the last but not the first child?

li:last-child:not(:first-child) {
  color: red
}

<ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>

<ul>
  <li>alone</li>
</ul>


问:
.htaccess throws 403 Forbidden / Zend Framework quickstart project creation (Mac OS X 10.6.5)
I am trying to get Zend Framework's quickstart tutorial up and running, but i ran into .htaccess issue.  It seems if i remove the .htaccess file, the project runs fine, but if i leave it in there it throws a 403 Forbidden.  The .htaccess is the default file generated by Zend Framework console command.  Here is the .htaccess:

```<code>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</code>```

This is under Mac OS X 10.6.5

mod_rewrite is on
AllowOveride All

Here is my virtual host info

```<code><VirtualHost *:80>
     ServerName zf_cms.local
     DocumentRoot /Users/kjye/Sites/zf_cms/public
     SetEnv APPLICATION_ENV "development"
     <Directory /Users/kjye/Sites/zf_cms/public>
          Options +Indexes +FollowSymLinks +ExecCGI
          DirectoryIndex index.php
          AllowOverride All
          Order allow,deny
          Allow from all
     </Directory>
</VirtualHost>
</code>```

I fixed it by adding "Options +Indexes +FollowSymLinks +ExecCGI"  Thanks for viewing.

答:
```<code><VirtualHost *:80>
 ServerName zf_cms.local
 DocumentRoot /Users/kjye/Sites/zf_cms/public
 SetEnv APPLICATION_ENV "development"
 <Directory /Users/kjye/Sites/zf_cms/public>
      Options +Indexes +FollowSymLinks +ExecCGI
      DirectoryIndex index.php
      AllowOverride All
      Order allow,deny
      Allow from all
 </Directory>
</code>```

This turns out to work under mac os.  thanks for all the help and comment.

ContentLicense: CC BY-SA 2.5

Body:
I am trying to get Zend Framework's quickstart tutorial up and running, but i ran into .htaccess issue.  It seems if i remove the .htaccess file, the project runs fine, but if i leave it in there it throws a 403 Forbidden.  The .htaccess is the default file generated by Zend Framework console command.  Here is the .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

This is under Mac OS X 10.6.5

mod_rewrite is on
AllowOveride All

Here is my virtual host info

<VirtualHost *:80>
     ServerName zf_cms.local
     DocumentRoot /Users/kjye/Sites/zf_cms/public
     SetEnv APPLICATION_ENV "development"
     <Directory /Users/kjye/Sites/zf_cms/public>
          Options +Indexes +FollowSymLinks +ExecCGI
          DirectoryIndex index.php
          AllowOverride All
          Order allow,deny
          Allow from all
     </Directory>
</VirtualHost>

I fixed it by adding "Options +Indexes +FollowSymLinks +ExecCGI"  Thanks for viewing.

Body:
<VirtualHost *:80>
 ServerName zf_cms.local
 DocumentRoot /Users/kjye/Sites/zf_cms/public
 SetEnv APPLICATION_ENV "development"
 <Directory /Users/kjye/Sites/zf_cms/public>
      Options +Indexes +FollowSymLinks +ExecCGI
      DirectoryIndex index.php
      AllowOverride All
      Order allow,deny
      Allow from all
 </Directory>

This turns out to work under mac os.  thanks for all the help and comment.


问:
Angular 2 Printing POS receipts
My Angular 2 project requires printing POS related receipts on paper.
Can anyone suggest, what is the standard way for printing receipts for web app.

Currently, I am using Angular 2 as client side technology calling web services for manipulating data.

Should it be done client side(using browser) or server Side ?

Any help will be appreciated. Thanks.

答:
it can be done in the client side itself using the print() method

```<code><button (click)="printMe()" > Print </button>
</code>```

The method as

```<code>printMe(){
   window.print();
}
</code>```

Note : This method will print what ever visible on the screen.

Title: Angular 2 Printing POS receipts

Body:
it can be done in the client side itself using the print() method

<button (click)="printMe()" > Print </button>

The method as

printMe(){
   window.print();
}

Note : This method will print what ever visible on the screen.


问:
Regular expression to find large numbers in word form
I'm trying to extract numbers in word form from a string. For example, an input string might be something like:

```<code>"What is 3 million 6 hundred 5 divided by 5 hundred?"
</code>```

From this input, I'd like to figure out how to get the two numbers as groups.

```<code>["3 million 6 hundred 5", "5 hundred"]
</code>```

Note: It is possible that there could be more numbers found in other input strings.

I believe regex is the correct route to solve this problem. Ideally I could pass in a list of the scales such as:

```<code>["hundred", "thousand", "million", "billion", ...]
</code>```

So far this is what I have:

```<code>scales= ["hundred", "thousand", "million", "billion"]
scale_pattern = '|'.join(scales)
regex = re.compile('\b(d+' + scale_pattern + 'd+)+\b')
</code>```

I know my pattern isn't quite right, the psudeocode for what I'm going for is:

```<code>for any number of the following occurrences:
    find the pattern [int word_from_list optional_int]
</code>```

答:
Ideally I could pass in a list of the scales

You can pass them in non-capturing or capturing group like this.

Regex: (?:\d+\s(?:million|hundred|thousand|billion)*\s*)+

Above is a simple regex checking for a number \d+ followed by a whitespace \s and scale which is optional (by using * quantifier) for last number followed by optional whitespace. And the whole pattern repeated one or many times (by using + quantifier).

Regex101 Demo

Body:
I'm trying to extract numbers in word form from a string. For example, an input string might be something like:

"What is 3 million 6 hundred 5 divided by 5 hundred?"

From this input, I'd like to figure out how to get the two numbers as groups.

["3 million 6 hundred 5", "5 hundred"]

Note: It is possible that there could be more numbers found in other input strings.

I believe regex is the correct route to solve this problem. Ideally I could pass in a list of the scales such as:

["hundred", "thousand", "million", "billion", ...]

So far this is what I have:

scales= ["hundred", "thousand", "million", "billion"]
scale_pattern = '|'.join(scales)
regex = re.compile('\b(d+' + scale_pattern + 'd+)+\b')

I know my pattern isn't quite right, the psudeocode for what I'm going for is:

for any number of the following occurrences:
    find the pattern [int word_from_list optional_int]


问:
Why does php 016 divided by 2 answering 7?
I am trying to divide 016 by 2 an php answer 7.
Why does php 016 divided by 2 answering 7?
for example,

```<code><?php
$i=016;
echo $i/2;
?>
</code>```

output is 7
why?

答:
PHP interprets an integer with a leading 0 as an octal (base 8) number. 016 base 8 is 14 base 10.

From the manual:

Integers can be specified in decimal (base 10), hexadecimal (base 16), octal (base 8) or binary (base 2) notation, optionally preceded by a sign (- or +).

Binary integer literals are available since PHP 5.4.0.

To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. To use binary notation precede the number with 0b.

If you actually need to print the 0, you are better off doing one of two things:

Use regular integers, padding with zero only at display time. I recommend this option.

Pass around strings, instead of integers. This will work well only if you don't need to do math with the strings.

Body:
I am trying to divide 016 by 2 an php answer 7.
Why does php 016 divided by 2 answering 7?
for example,

<?php
$i=016;
echo $i/2;
?>

output is 7
why?


问:
How database records are stored on disk?
If I have a databases with multiple tables, how are they stored on the disk?

Who decides the most efficient way of storing them?

any relevant/text/article?

答:
They are completely and 100% database vendor dependent. Each DB decides what's the best option to store data on disk.

There are a lot of 80's paper that talk about it. Search them in scholar.google.com.


问:
Instasharp in a Console Application
I have a .net console application that I want to use to pull Instagram posts via the Instasharp wrapper using a hashtag search.

I use C# .net web forms extensively and am not very familiar with MVC nor how to use the await keyword. The code sample below seems to run, but never provides any output.

This line:

```<code>var tagInfo = await tagApi.Get("soccer");
</code>```

Returns me to the calling method with no indication of retrieved data.

Can anyone provide insights as to what I am doing wrong here?

```<code>public static async void GetInstagram(String tag, InstagramConfig config)
{
    var instagramPosts = await LoadInstagramPosts(tag, config);
    dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.ToString());

        foreach (var data in dyn.data)
        {
            Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
        }
    }

    public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config)
    {
        var tagApi = new InstaSharp.Endpoints.Tags(config);
        var tagInfo = await tagApi.Get("soccer");
 }
</code>```

EDITED code after first comment which solved my initial problem.

I feel like I'm close but something is still missing.
See specific questions below...

I've based the code on the documentation from InstaSharp GitHub (https://github.com/InstaSharp/InstaSharp). GitHubs example is based on an MVC application, mine is not an MVC project, but a console application.

I feel like I am very close and maybe others will benefit from helping me solve this.

My specific questions...
1) Not sure where the 'code' parameter in the OAuth method originate??
2) How to perform the needed call backs with Instagram??

```<code>var config = new InstaSharp.InstagramConfig(location.InstagramClientId, location.InstagramClientSecret, "http://localhost");
    string instagramLoginLink = InstagramLogin(config);
    GetInstagram("soccer", config, instagramLoginLink);
    public static async void GetInstagram(String tag, InstagramConfig config, string code)
    {
        OAuthResponse oAuthResponse = await OAuth(code, config);
        var instagramPosts = await LoadInstagramPosts(tag, config, oAuthResponse);
        if(instagramPosts.Data != null)
        {
            dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.Data.ToString());

            foreach (var data in dyn.data)
            {
                Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
            }
        }
    }

    public static string InstagramLogin(InstagramConfig config)
    {
        var scopes = new List<OAuth.Scope>();
        scopes.Add(InstaSharp.OAuth.Scope.Likes);
        scopes.Add(InstaSharp.OAuth.Scope.Comments);

        string link = InstaSharp.OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, InstaSharp.OAuth.ResponseType.Code);

        return link;
    }

    public static async Task<OAuthResponse> OAuth(string code, InstagramConfig config)
    {
        // add this code to the auth object
        var auth = new OAuth(config);

        // now we have to call back to instagram and include the code they gave us
        // along with our client secret
        return await auth.RequestToken(code);
    }

    public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config, OAuthResponse OAuth)
    {
        var tagApi = new InstaSharp.Endpoints.Tags(config, OAuth);
        return await tagApi.Get("soccer");
    }
</code>```

答:
I'm a bit late to the show, yet probably my answer will help someone who find this question when googling, someone like me.

The main problem with your approach is that Instagram is using OAuth authentication. I suggest you to google on OAuth to understand the principles, but I will try to explain the practical points of it below.

OAuth approach means that the result of the InstagramLogin method in the snippet above is not the code. It's the link where you need to send you user (yes, using a browser or a web-view) so that they can sign into their Instagram account and then authorize your application to access their data (so-called user consent screen).

In the end, after user consent, Instagram will redirect browser to the URL of your choice (it should be previously added in the list of allowed redirect urls in Instagram API -> Manage Clients (top-right corner) -> Create/Select client to Manage -> Security tab)

You can try set a breakpoint and copy the value of instagramLoginLink into your browser's address box. You will be able to see the whole flow of authentication and consent - and finally the redirect url that will most probably produce 404 in your browser.

This final link will contain the code in a get parameter. It's the so-called grant code that allows you to get an access token. This code is to be extracted from url and then used in your call to OAuth.RequestToken).

PS: Yes, everything I say above means that you need either a web app running that will redirect user to Instagram or a client-side app that will show the user a web view and somehow handle the moment when Instagram sends the user back to your redirect url - to grab the code and proceed.

Title: Instasharp in a Console Application

Body:
I have a .net console application that I want to use to pull Instagram posts via the Instasharp wrapper using a hashtag search.

I use C# .net web forms extensively and am not very familiar with MVC nor how to use the await keyword. The code sample below seems to run, but never provides any output.

This line:

var tagInfo = await tagApi.Get("soccer");

Returns me to the calling method with no indication of retrieved data.

Can anyone provide insights as to what I am doing wrong here?

public static async void GetInstagram(String tag, InstagramConfig config)
{
    var instagramPosts = await LoadInstagramPosts(tag, config);
    dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.ToString());

        foreach (var data in dyn.data)
        {
            Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
        }
    }

    public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config)
    {
        var tagApi = new InstaSharp.Endpoints.Tags(config);
        var tagInfo = await tagApi.Get("soccer");
 }

EDITED code after first comment which solved my initial problem.

I feel like I'm close but something is still missing.
See specific questions below...

I've based the code on the documentation from InstaSharp GitHub (https://github.com/InstaSharp/InstaSharp). GitHubs example is based on an MVC application, mine is not an MVC project, but a console application.

I feel like I am very close and maybe others will benefit from helping me solve this.

My specific questions...
1) Not sure where the 'code' parameter in the OAuth method originate??
2) How to perform the needed call backs with Instagram??

var config = new InstaSharp.InstagramConfig(location.InstagramClientId, location.InstagramClientSecret, "http://localhost");
    string instagramLoginLink = InstagramLogin(config);
    GetInstagram("soccer", config, instagramLoginLink);
    public static async void GetInstagram(String tag, InstagramConfig config, string code)
    {
        OAuthResponse oAuthResponse = await OAuth(code, config);
        var instagramPosts = await LoadInstagramPosts(tag, config, oAuthResponse);
        if(instagramPosts.Data != null)
        {
            dynamic dyn = JsonConvert.DeserializeObject(instagramPosts.Data.ToString());

            foreach (var data in dyn.data)
            {
                Console.WriteLine("{0} - {1}", data.filter, data.images.standard_resolution.url);
            }
        }
    }

    public static string InstagramLogin(InstagramConfig config)
    {
        var scopes = new List<OAuth.Scope>();
        scopes.Add(InstaSharp.OAuth.Scope.Likes);
        scopes.Add(InstaSharp.OAuth.Scope.Comments);

        string link = InstaSharp.OAuth.AuthLink(config.OAuthUri + "authorize", config.ClientId, config.RedirectUri, scopes, InstaSharp.OAuth.ResponseType.Code);

        return link;
    }

    public static async Task<OAuthResponse> OAuth(string code, InstagramConfig config)
    {
        // add this code to the auth object
        var auth = new OAuth(config);

        // now we have to call back to instagram and include the code they gave us
        // along with our client secret
        return await auth.RequestToken(code);
    }

    public static async Task<TagResponse> LoadInstagramPosts(String hashTagTerm, InstagramConfig config, OAuthResponse OAuth)
    {
        var tagApi = new InstaSharp.Endpoints.Tags(config, OAuth);
        return await tagApi.Get("soccer");
    }


问:
How to prevent vagrant from asking ssh key passphrase
Everything works fine, but it keeps prompting for ssh passphrase during provisioning, which is very annoying, when you have 6 vm's it will prompt you like 12 times (and the whole automation piece kinda loses its point).

I've tried searching the web, but couldn't find an answer to a pretty obvious question.

答:
There are various ways how to prevent this.

First of all and most obvious (but least preferable) is to remove the passphrase from the key:

```<code>ssh-keygen -p -P old_passphrase -N "" -f /path/to/key_file
</code>```

The other possibility is to use ssh-agent, which will store the encrypted version of your key and will do the required operation on it when asked. You can find many guides and questions about it, but for completeness

```<code>eval $(ssh-agent)
ssh-add /path/to/key_file
do-your-vagrant-stuff
</code>```

You can use sshpass, which will provide the passphrase to the ssh commands. It can read the passphrase as an argument, from environment variable or from file (can be insecure)

```<code>sshpass -p password your-vagrant-stuff
</code>```

there are probably other ways, but you should most probably use ssh-agent.

Body:
There are various ways how to prevent this.

First of all and most obvious (but least preferable) is to remove the passphrase from the key:

ssh-keygen -p -P old_passphrase -N "" -f /path/to/key_file

The other possibility is to use ssh-agent, which will store the encrypted version of your key and will do the required operation on it when asked. You can find many guides and questions about it, but for completeness

eval $(ssh-agent)
ssh-add /path/to/key_file
do-your-vagrant-stuff

You can use sshpass, which will provide the passphrase to the ssh commands. It can read the passphrase as an argument, from environment variable or from file (can be insecure)

sshpass -p password your-vagrant-stuff

there are probably other ways, but you should most probably use ssh-agent.


问:
Extract multiple numbers from a string without commas
I'm recently trying to use my RFID card's UID but I'd like the UID to be like 11217924711571 instead of [112, 179, 247, 115, 71]. I've tried int(re.search(r'\d+', uid_str).group()) but it only returns 112. Can somebody please help me?

答:
You could try this:</p>

```<code>old = [112, 179, 247, 115, 71]
new = ''.join(map(str, old)) # will be a str
new_int = int(new) # if you need it to be an integer, convert it
</code>```

Body:
You could try this:

old = [112, 179, 247, 115, 71]
new = ''.join(map(str, old)) # will be a str
new_int = int(new) # if you need it to be an integer, convert it


问:
I am trying to create a table in sql, but im missing a keyword, cant find out how to fix it
I'm trying to create a table in SQL, but I'm missing a keyword, and I can't figure out how to fix it:</p>

```<code>CREATE TABLE Attendance_of_employee
(
  supervisior VARCHAR(30) DEFAULT 'NONE',
  arrival double NOT NULL,
  shift_end double NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  ID_record VARCHAR(30) NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);

Error report -
SQL Error: ORA-00905: chýbajúce kľúčové slovo
00905. 00000 -  "missing keyword"
*Cause:
*Action:
</code>```

答:
In Oracle, you usually use number for numeric values and varchar2() for character strings.  I would always have the primary key be the first column in the table.  So:

```<code>CREATE TABLE Attendance_of_employee (
  ID_record VARCHAR2(30) NOT NULL,
  supervisior VARCHAR2(30) DEFAULT 'NONE',
  arrival number NOT NULL,
  shift_end number NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);
</code>```

Here is a link in Rextester (without the foreign key relationship, because EmployeeTAB is not defined).

Body:
I'm trying to create a table in SQL, but I'm missing a keyword, and I can't figure out how to fix it:

CREATE TABLE Attendance_of_employee
(
  supervisior VARCHAR(30) DEFAULT 'NONE',
  arrival double NOT NULL,
  shift_end double NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  ID_record VARCHAR(30) NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);

Error report -
SQL Error: ORA-00905: chýbajúce kľúčové slovo
00905. 00000 -  "missing keyword"
*Cause:
*Action:

Body:
In Oracle, you usually use number for numeric values and varchar2() for character strings.  I would always have the primary key be the first column in the table.  So:

CREATE TABLE Attendance_of_employee (
  ID_record VARCHAR2(30) NOT NULL,
  supervisior VARCHAR2(30) DEFAULT 'NONE',
  arrival number NOT NULL,
  shift_end number NOT NULL,
  date_time DATE NOT NULL,
  worked_hours INT NOT NULL,
  employeeID INT NOT NULL,
  PRIMARY KEY (ID_record),
  FOREIGN KEY (employeeID) REFERENCES EmployeeTAB(employeeID)
);

Here is a link in Rextester (without the foreign key relationship, because EmployeeTAB is not defined).


问:
How to match and point to a particular data in array in Blogger
As I asked in a previous question and I got a good and working answer :

 How to store the URL's and Titles of a list of posts under same label into a String array in Blogger

Now I want to know how to make a variable point or get the index number of the particular url.

Suppose I use var cURL="<data:post.url>" to store the URL of the post I am currently browsing on the blog into cURL variable.

Supposedly the blog post I have currently opened happens to be:

SITEURL

And the variable cURL stores this URL. I want a code to search and match this URL in a array which I have stored a number of URL's

Now if the value of cURL is as already above

If the array is var URLArray and its data with index happens to be:

As highlighted in bold above, the URL in URLArray[2] matches the URL stored in cURL.
Now I want this Index number 2 stored in a variable.

Since blogger doesn't allow normal java for loops, I don't know how to do it.

答:
To get index number through loop use index attribute as in the following example :

```<code><b:loop index='i' values='data:posts' var='post'>

    <data:i/> : <data:post.url/>

</b:loop>
</code>```

Notes :

i can be any name you choose.

Loop index starts from zero.

Javascript version :

```<code><script type="text/javascript">
    var URLArray = [];
    <b:loop index='i' values='data:posts' var='post'>
        URLArray[<data:i/>] = <data:post.url/>;
    </b:loop>
</script>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
To get index number through loop use index attribute as in the following example :

<b:loop index='i' values='data:posts' var='post'>

    <data:i/> : <data:post.url/>

</b:loop>

Notes :

i can be any name you choose.

Loop index starts from zero.

Javascript version :

<script type="text/javascript">
    var URLArray = [];
    <b:loop index='i' values='data:posts' var='post'>
        URLArray[<data:i/>] = <data:post.url/>;
    </b:loop>
</script>


Title: Numpy shape not including subarrays

Body:
I'm using a library (keras) that's dependent on having a specific shape of a numpy array. I've never had the following issue: numpy isn't putting forward the correct shape?

Here's what I output when I output my ndarray

array([ array([[-0.038548  ,  0.54251999, -0.21843   , ..., -0.38580999,
        -0.029534  ,  0.14425001],
       [-0.084961  ,  0.50199997,  0.0023823 , ..., -0.037066  ,
         0.10436   ,  0.17904   ],
       [ 0.27204001, -0.06203   , -0.1884    , ..., -0.088243  ,
         0.30318001,  0.087747  ],
       ...,
       [ 0.089187  ,  0.25792   ,  0.26282001, ..., -0.23406   ,
        -0.086024  , -0.50603998],
       [-0.89548999,  0.38773   ,  0.64984   , ..., -0.24102999,
        -0.29991001,  0.2174    ],
       [-0.086864  ,  0.19160999,  0.10915   , ..., -0.47512001,
         0.047597  , -0.12785   ]], dtype=float32),
       array([[-0.038548  ,  0.54251999, -0.21843   , ..., -0.38580999,
        -0.029534  ,  0.14425001],
       [-0.084961  ,  0.50199997,  0.0023823 , ..., -0.037066  ,
         0.10436   ,  0.17904   ],
       [ 0.27204001, -0.06203   , -0.1884    , ..., -0.088243  ,
         0.30318001,  0.087747  ],
       ...,
       [-0.27142   ,  0.047374  , -0.17278001, ...,  0.25861999,
         0.06769   ,  0.10761   ],
       [-0.33340001,  0.45183   ,  0.40684   , ...,  0.025225  ,
        -0.10559   , -0.058053  ],
       [-0.086864  ,  0.19160999,  0.10915   , ..., -0.47512001,
         0.047597  , -0.12785   ]], dtype=float32),
       array([[-0.23205   ,  0.47468001, -0.38264   , ..., -0.072927  ,
        -0.32218999, -0.065715  ],
       [-0.23857   ,  0.35457   , -0.30219001, ..., -0.023289  ,
        -0.29661   , -0.11824   ],
       [ 0.18732999,  0.40595001, -0.51174003, ...,  0.197     ,
        -0.48326999,  0.089523  ],
       ...,
       [ 0.043798  ,  0.024779  , -0.20937   , ...,  0.010196  ,
         0.37641999, -0.01946   ],
       [ 0.37004   ,  0.089479  ,  0.53771001, ..., -0.17144001,
        -0.41093001,  0.97061002],
       [-0.086864  ,  0.19160999,  0.10915   , ..., -0.47512001,
         0.047597  , -0.12785   ]], dtype=float32),
       ...,
       array([[ -3.85480002e-02,   5.42519987e-01,  -2.18429998e-01,
         -1.88549995e-01,   7.29999989e-02,   1.31799996e-01,
         -1.04020000e-01,   1.72309995e-01,  -5.15870005e-02,
          2.86459994e+00,  -2.51309991e-01,  -1.91459998e-01,
          7.99869969e-02,   7.28920028e-02,  -1.32090002e-01,
         -2.29709998e-01,  -1.72680005e-01,   8.35070014e-01,
         -3.84869993e-01,  -3.24919999e-01,   4.66800004e-01,
         -1.56780005e-01,   1.07069999e-01,  -1.24789998e-01,
         -1.60300002e-01,  -5.21539990e-03,   1.51660005e-02,
          1.65079996e-01,   9.80250016e-02,  -9.18980017e-02,
          2.45520001e-04,   4.42539990e-01,   1.60459995e-01,
          1.22149996e-01,   1.25939995e-01,   3.19990009e-01,
          2.20449999e-01,   1.68699995e-01,  -3.89270008e-01,
         -1.73470005e-01,  -1.31579995e-01,   7.98169971e-02,
         -5.80530018e-02,  -7.22350031e-02,   2.80330002e-01,
          6.10799994e-03,  -3.92890006e-01,   6.17439975e-04,
         -3.33629996e-02,   7.58850016e-03,  -9.36639979e-02,
          1.89319998e-01,  -2.25419998e-01,  -1.80910006e-02,
          2.95459986e-01,  -1.51629999e-01,  -1.55939996e-01,
         -2.19390005e-01,   8.83169994e-02,  -6.54719993e-02,
         -6.29500002e-02,  -1.99890003e-01,  -4.94540017e-03,
          2.95740008e-01,   2.73330003e-01,  -3.62129986e-01,
         -4.05099988e-02,   2.20449999e-01,   8.47209990e-02,
          6.27639983e-03,   1.69139996e-01,  -2.00430006e-01,
          5.16470015e-01,  -1.19050004e-01,   7.86669999e-02,
          2.68339992e-01,   6.69509992e-02,  -2.51179993e-01,
         -2.41449997e-01,   4.81339991e-01,   1.54479995e-01,
          1.15379997e-01,  -9.82709974e-02,  -6.84430003e-02,
          1.66710004e-01,  -4.16940004e-01,  -2.25419998e-01,
         -8.74610007e-01,   3.08230013e-01,   8.99629965e-02,
         -3.68919998e-01,  -1.73769996e-01,  -4.17360008e-01,
          2.62569994e-01,   3.59600008e-01,   1.33239999e-01,
          1.28410002e-02,  -3.85809988e-01,  -2.95340009e-02,
          1.44250005e-01],
       [ -8.49609971e-02,   5.01999974e-01,   2.38230010e-03,
         -1.67549998e-01,   3.07209998e-01,  -2.37619996e-01,
          1.60689995e-01,  -3.67859989e-01,  -5.83470017e-02,
          2.49900007e+00,  -2.36469996e-03,   1.07319998e-02,
         -3.04219991e-01,   8.45789984e-02,  -4.02989984e-02,
         -4.15619999e-01,  -2.44939998e-02,   1.46910000e+00,
         -5.29320017e-02,  -7.44130015e-02,  -3.92439991e-01,
         -3.25349987e-01,  -2.23330006e-01,   5.68229984e-03,
          3.56750011e-01,   1.94450006e-01,   5.67619987e-02,
         -4.55019996e-02,  -2.81049997e-01,  -5.88960014e-02,
         -9.86260027e-02,   9.21770036e-02,   3.31719995e-01,
         -3.99670005e-02,  -1.17660001e-01,   4.83729988e-02,
         -6.22409992e-02,  -1.04130000e-01,   9.92630026e-04,
         -4.89250004e-01,   3.47860008e-01,   3.27239990e-01,
          1.38820007e-01,  -1.99169993e-01,   1.29950002e-01,
          6.05489984e-02,  -2.37140000e-01,  -5.12950003e-01,
         -3.73959988e-01,   1.29020005e-01,   5.57969995e-02,
          3.34439993e-01,  -1.80250004e-01,  -3.47400010e-02,
          2.83230007e-01,  -9.53010023e-02,   2.11429998e-01,
         -7.61490017e-02,   1.50690004e-01,  -1.74410000e-01,
         -7.47680012e-03,  -7.82869980e-02,  -1.27509996e-01,
          2.25449994e-01,   3.51010002e-02,  -6.10149980e-01,
         -2.68119991e-01,   6.16319999e-02,  -3.05029988e-01,
         -1.34049997e-01,  -4.42710012e-01,  -1.77200004e-01,
          1.76630005e-01,  -3.12099993e-01,  -2.57220000e-01,
         -2.48579998e-02,   7.25039989e-02,  -7.97590017e-02,
         -1.92139998e-01,   5.96019983e-01,   1.28800005e-01,
         -7.46290013e-02,  -1.58120006e-01,   3.63940001e-01,
          2.30550006e-01,  -4.21750009e-01,  -9.06509981e-02,
         -3.00850004e-01,   1.79399997e-01,  -2.97859997e-01,
         -1.06420003e-01,   4.72389996e-01,  -1.38370007e-01,
         -1.01609997e-01,   8.01339969e-02,   4.07150015e-02,
         -3.69760007e-01,  -3.70660014e-02,   1.04359999e-01,
          1.79040000e-01],
       [  5.40710017e-02,   1.11100003e-01,  -1.45569995e-01,
         -2.42940001e-02,   3.81099999e-01,  -1.43889993e-01,
         -1.79979995e-01,  -3.10790002e-01,  -7.96900038e-03,
          2.65380001e+00,  -1.27719998e-01,   2.38850005e-02,
          7.12840036e-02,  -1.42639995e-01,   1.09389998e-01,
         -1.06670000e-01,  -3.81780006e-02,   1.18529999e+00,
          5.25589995e-02,  -1.71810001e-01,  -1.86289996e-01,
         -1.65330004e-02,  -8.40080008e-02,   1.45420000e-01,
          1.60589993e-01,  -6.91630021e-02,  -7.68119991e-02,
         -2.06579998e-01,   1.60249993e-01,   2.14049995e-01,
          5.92090003e-02,   4.78909999e-01,   8.33740011e-02,
          1.99939996e-01,   9.62250009e-02,  -1.00330003e-01,
          4.25769985e-02,  -9.35870036e-02,  -1.33890003e-01,
         -3.27039987e-01,   2.36499999e-02,   3.40640008e-01,
         -7.59759992e-02,  -1.01499997e-01,   1.24310002e-01,
         -5.59540018e-02,  -2.52840012e-01,  -1.85199995e-02,
          4.69119996e-02,  -8.47740024e-02,  -1.58840001e-01,
          2.37509996e-01,   7.61089996e-02,   7.17530027e-02,
          3.14049982e-02,   3.26559991e-02,   1.12709999e-01,
          2.78389990e-01,   3.52329999e-01,  -1.08439997e-01,
          7.01830015e-02,  -4.68910001e-02,  -1.88250005e-01,
          4.05180007e-01,   2.11799994e-01,  -1.43759996e-01,
         -4.80750017e-03,   1.38769999e-01,  -9.15210024e-02,
          2.51940012e-01,   1.79979995e-01,  -1.58999994e-01,
          1.47530004e-01,   1.18660003e-01,  -1.54469997e-01,
          1.09690003e-01,   5.79660013e-02,  -2.58619994e-01,
         -2.37639993e-02,   1.90640002e-01,  -3.43649983e-02,
          9.08799991e-02,  -2.90160000e-01,  -1.30030006e-01,
          2.86660008e-02,  -2.06230000e-01,  -2.85860002e-01,
         -2.29340002e-01,   1.53819993e-01,  -2.03730002e-01,
         -2.53500015e-01,   2.07029998e-01,  -8.60000029e-02,
         -8.44089985e-02,  -1.29040003e-01,   5.94369993e-02,
          8.51750001e-02,  -4.17740010e-02,   8.60700011e-02,
          7.82589987e-02],
       [ -2.91300006e-02,  -1.52989998e-01,   7.37699986e-01,
          1.23810001e-01,   7.53529966e-02,  -5.48210025e-01,
         -2.86799997e-01,  -4.00489986e-01,  -2.24610008e-02,
          1.09679997e+00,  -5.50310016e-01,  -4.02750000e-02,
          7.86580026e-01,  -3.43159996e-02,   2.01429993e-01,
         -3.19319993e-01,  -7.49930024e-01,   1.06040001e+00,
          3.85280013e-01,  -1.10100001e-01,   1.25440001e-01,
          3.97709996e-01,  -4.50349987e-01,  -1.37869999e-01,
          3.46359998e-01,  -2.17920005e-01,  -2.21599996e-01,
         -2.67529994e-01,  -7.48199999e-01,  -6.40890002e-02,
          1.69840008e-02,  -5.38230002e-01,   9.31750014e-02,
          4.50679988e-01,  -1.69719994e-01,  -1.70690000e-01,
          4.03360009e-01,  -4.86820012e-01,   2.00289994e-01,
          9.72639993e-02,  -2.96240002e-01,   8.76160026e-01,
          1.53449997e-02,  -6.04390025e-01,   5.52349985e-01,
         -1.20439999e-01,   2.56650001e-01,  -1.10550001e-01,
         -3.71060014e-01,   9.64860022e-02,   1.56389996e-01,
          6.02020025e-01,   4.12550010e-02,  -6.96389973e-02,
          1.25190005e-01,   9.21360031e-02,   1.84919998e-01,
         -7.63119981e-02,   7.02779964e-02,   4.12399992e-02,
          1.41660003e-02,  -2.79309992e-02,  -7.89560005e-02,
         -1.38319999e-01,  -3.62630010e-01,  -1.73889995e-02,
          1.62430003e-01,   3.83130014e-01,   2.36460000e-01,
          3.69349986e-01,  -6.75029993e-01,   3.32300007e-01,
         -4.22430009e-01,  -3.35220009e-01,   1.50879994e-01,
          2.00020000e-01,   5.75739980e-01,  -4.21869993e-01,
          1.37989998e-01,   3.77519995e-01,   8.12970027e-02,
          4.30990010e-01,   4.08219993e-01,   8.87599960e-03,
          2.73759991e-01,  -7.77720008e-03,   6.57100022e-01,
          6.44659996e-01,  -3.80160004e-01,  -2.27239996e-01,
          2.48699993e-01,  -2.06330001e-01,   1.25920000e-02,
         -1.82589993e-01,   3.50809991e-01,  -4.61959988e-01,
          5.15730008e-02,  -1.64570004e-01,  -3.00960004e-01,
          1.01379998e-01],
       [ -8.68640020e-02,   1.91609994e-01,   1.09150000e-01,
         -3.43210012e-01,   2.03679994e-01,  -2.47769997e-01,
          4.60460007e-01,  -3.65700006e-01,  -1.98039994e-01,
          1.73790002e+00,  -4.35070008e-01,   9.61349979e-02,
          1.56010002e-01,   2.39030004e-01,  -4.19310004e-01,
         -9.51310024e-02,   4.43420000e-02,   1.23920000e+00,
          1.11570004e-02,  -2.25219995e-01,   3.84110004e-01,
         -1.16060004e-01,  -3.90359983e-02,   3.61060016e-02,
         -5.26760006e-04,  -1.21540003e-01,  -5.68839982e-02,
          4.14249986e-01,   3.82479995e-01,   2.35900000e-01,
         -8.55500028e-02,   8.51199999e-02,  -3.79760005e-02,
         -1.61090001e-01,   4.62740004e-01,   4.56809998e-01,
          1.50989994e-01,   1.15510002e-01,  -5.93560003e-03,
         -1.49599999e-01,   1.15900002e-01,  -1.14139996e-01,
         -1.92619994e-01,  -2.57660002e-02,   1.68489993e-01,
          4.73800004e-02,  -4.74830002e-01,  -1.60710007e-01,
         -9.62430015e-02,   1.81920007e-01,   1.49540007e-01,
          1.21299997e-01,   9.35969991e-04,  -5.73629975e-01,
         -1.78800002e-01,  -1.44850001e-01,   1.11579999e-01,
         -1.83860004e-01,   3.40299994e-01,   2.17950001e-01,
         -2.64899999e-01,  -1.16650000e-01,   6.43589973e-01,
          9.53160040e-03,   5.43700010e-02,  -2.70080000e-01,
         -4.25550014e-01,   1.87640004e-02,  -3.04060012e-01,
         -3.53909992e-02,   1.68899998e-01,  -9.61219966e-02,
          4.85760003e-01,   2.26359993e-01,   8.67540017e-02,
          3.25210005e-01,   1.01999998e-01,  -2.13860005e-01,
          1.63530007e-01,   5.70400000e-01,  -4.88339990e-01,
         -2.96689998e-02,  -1.25320002e-01,   1.57839999e-01,
         -1.63489997e-01,   1.07620001e-01,   6.45250022e-01,
         -8.36459994e-01,   1.35000005e-01,   2.16319993e-01,
         -3.08219999e-01,  -1.56729996e-01,   2.70789992e-02,
         -4.64430004e-02,  -4.03910019e-02,  -3.12559992e-01,
         -4.49640006e-01,  -4.75120008e-01,   4.75969985e-02,
         -1.27849996e-01]], dtype=float32),
       array([[-0.038548  ,  0.54251999, -0.21843   , ..., -0.38580999,
        -0.029534  ,  0.14425001],
       [-0.084961  ,  0.50199997,  0.0023823 , ..., -0.037066  ,
         0.10436   ,  0.17904   ],
       [ 0.27204001, -0.06203   , -0.1884    , ..., -0.088243  ,
         0.30318001,  0.087747  ],
       ...,
       [-0.43731001, -0.14038999,  0.42151001, ..., -0.005359  ,
        -0.25985   ,  0.46535999],
       [-0.31110999, -0.044779  ,  0.0067328 , ...,  0.30699   ,
        -0.036171  ,  0.072974  ],
       [-0.086864  ,  0.19160999,  0.10915   , ..., -0.47512001,
         0.047597  , -0.12785   ]], dtype=float32),
       array([[ -3.85480002e-02,   5.42519987e-01,  -2.18429998e-01,
         -1.88549995e-01,   7.29999989e-02,   1.31799996e-01,
         -1.04020000e-01,   1.72309995e-01,  -5.15870005e-02,
          2.86459994e+00,  -2.51309991e-01,  -1.91459998e-01,
          7.99869969e-02,   7.28920028e-02,  -1.32090002e-01,
         -2.29709998e-01,  -1.72680005e-01,   8.35070014e-01,
         -3.84869993e-01,  -3.24919999e-01,   4.66800004e-01,
         -1.56780005e-01,   1.07069999e-01,  -1.24789998e-01,
         -1.60300002e-01,  -5.21539990e-03,   1.51660005e-02,
          1.65079996e-01,   9.80250016e-02,  -9.18980017e-02,
          2.45520001e-04,   4.42539990e-01,   1.60459995e-01,
          1.22149996e-01,   1.25939995e-01,   3.19990009e-01,
          2.20449999e-01,   1.68699995e-01,  -3.89270008e-01,
         -1.73470005e-01,  -1.31579995e-01,   7.98169971e-02,
         -5.80530018e-02,  -7.22350031e-02,   2.80330002e-01,
          6.10799994e-03,  -3.92890006e-01,   6.17439975e-04,
         -3.33629996e-02,   7.58850016e-03,  -9.36639979e-02,
          1.89319998e-01,  -2.25419998e-01,  -1.80910006e-02,
          2.95459986e-01,  -1.51629999e-01,  -1.55939996e-01,
         -2.19390005e-01,   8.83169994e-02,  -6.54719993e-02,
         -6.29500002e-02,  -1.99890003e-01,  -4.94540017e-03,
          2.95740008e-01,   2.73330003e-01,  -3.62129986e-01,
         -4.05099988e-02,   2.20449999e-01,   8.47209990e-02,
          6.27639983e-03,   1.69139996e-01,  -2.00430006e-01,
          5.16470015e-01,  -1.19050004e-01,   7.86669999e-02,
          2.68339992e-01,   6.69509992e-02,  -2.51179993e-01,
         -2.41449997e-01,   4.81339991e-01,   1.54479995e-01,
          1.15379997e-01,  -9.82709974e-02,  -6.84430003e-02,
          1.66710004e-01,  -4.16940004e-01,  -2.25419998e-01,
         -8.74610007e-01,   3.08230013e-01,   8.99629965e-02,
         -3.68919998e-01,  -1.73769996e-01,  -4.17360008e-01,
          2.62569994e-01,   3.59600008e-01,   1.33239999e-01,
          1.28410002e-02,  -3.85809988e-01,  -2.95340009e-02,
          1.44250005e-01],
       [ -8.49609971e-02,   5.01999974e-01,   2.38230010e-03,
         -1.67549998e-01,   3.07209998e-01,  -2.37619996e-01,
          1.60689995e-01,  -3.67859989e-01,  -5.83470017e-02,
          2.49900007e+00,  -2.36469996e-03,   1.07319998e-02,
         -3.04219991e-01,   8.45789984e-02,  -4.02989984e-02,
         -4.15619999e-01,  -2.44939998e-02,   1.46910000e+00,
         -5.29320017e-02,  -7.44130015e-02,  -3.92439991e-01,
         -3.25349987e-01,  -2.23330006e-01,   5.68229984e-03,
          3.56750011e-01,   1.94450006e-01,   5.67619987e-02,
         -4.55019996e-02,  -2.81049997e-01,  -5.88960014e-02,
         -9.86260027e-02,   9.21770036e-02,   3.31719995e-01,
         -3.99670005e-02,  -1.17660001e-01,   4.83729988e-02,
         -6.22409992e-02,  -1.04130000e-01,   9.92630026e-04,
         -4.89250004e-01,   3.47860008e-01,   3.27239990e-01,
          1.38820007e-01,  -1.99169993e-01,   1.29950002e-01,
          6.05489984e-02,  -2.37140000e-01,  -5.12950003e-01,
         -3.73959988e-01,   1.29020005e-01,   5.57969995e-02,
          3.34439993e-01,  -1.80250004e-01,  -3.47400010e-02,
          2.83230007e-01,  -9.53010023e-02,   2.11429998e-01,
         -7.61490017e-02,   1.50690004e-01,  -1.74410000e-01,
         -7.47680012e-03,  -7.82869980e-02,  -1.27509996e-01,
          2.25449994e-01,   3.51010002e-02,  -6.10149980e-01,
         -2.68119991e-01,   6.16319999e-02,  -3.05029988e-01,
         -1.34049997e-01,  -4.42710012e-01,  -1.77200004e-01,
          1.76630005e-01,  -3.12099993e-01,  -2.57220000e-01,
         -2.48579998e-02,   7.25039989e-02,  -7.97590017e-02,
         -1.92139998e-01,   5.96019983e-01,   1.28800005e-01,
         -7.46290013e-02,  -1.58120006e-01,   3.63940001e-01,
          2.30550006e-01,  -4.21750009e-01,  -9.06509981e-02,
         -3.00850004e-01,   1.79399997e-01,  -2.97859997e-01,
         -1.06420003e-01,   4.72389996e-01,  -1.38370007e-01,
         -1.01609997e-01,   8.01339969e-02,   4.07150015e-02,
         -3.69760007e-01,  -3.70660014e-02,   1.04359999e-01,
          1.79040000e-01],
       [ -1.84169993e-01,   5.51149994e-02,  -3.69529992e-01,
         -2.08949998e-01,   2.56720006e-01,   3.01420003e-01,
          1.62990004e-01,  -1.64370000e-01,  -7.02679977e-02,
          2.16380000e+00,  -2.65960008e-01,  -5.39130010e-02,
          4.81840014e-01,  -4.23640013e-02,  -3.80939990e-01,
          5.30319996e-02,   6.45349994e-02,   7.16679990e-01,
         -4.60260004e-01,  -5.72770014e-02,   7.41859972e-02,
          1.25790000e-01,  -1.88989997e-01,   1.86289998e-03,
         -2.29739994e-01,  -7.91509971e-02,  -6.16800003e-02,
         -2.95690000e-01,   3.95119995e-01,  -2.78979987e-01,
          1.79690003e-01,   3.21170002e-01,  -1.27489999e-01,
          4.81799990e-02,   2.32800007e-01,  -2.68130004e-01,
         -7.70540014e-02,   1.46990001e-01,  -2.71149993e-01,
          9.77350026e-02,  -1.76330000e-01,   2.92490005e-01,
         -2.01900005e-01,  -5.04230009e-03,   8.96809995e-02,
          2.62979995e-02,  -4.05790001e-01,  -2.38460004e-01,
         -8.90780017e-02,   6.78009987e-02,  -3.48470002e-01,
          1.95350006e-01,  -1.40560001e-01,   3.56579982e-02,
          5.83989993e-02,   8.71259999e-03,  -2.65359998e-01,
         -3.17880005e-01,  -7.53000006e-03,  -4.76210006e-02,
         -4.53200005e-02,  -5.04060015e-02,  -1.52730003e-01,
          1.53449997e-01,   1.06519997e-01,  -3.12390000e-01,
         -7.27680027e-02,   1.78140000e-01,   6.71949983e-03,
          1.67579994e-01,   1.00979999e-01,  -1.71670001e-02,
          3.08860004e-01,   1.38119996e-01,  -1.64940000e-01,
          1.90549999e-01,   4.05309983e-02,  -7.69170001e-02,
          7.96949957e-03,   7.93910027e-02,   5.87599985e-02,
         -2.83049997e-02,  -4.39249985e-02,  -3.18120003e-01,
          1.58710003e-01,  -3.04500014e-01,   1.12360001e-01,
         -1.07989997e-01,   1.23530000e-01,   1.59029998e-02,
         -2.62550004e-02,   9.91180018e-02,   3.85789983e-02,
          2.64290005e-01,   3.73979986e-01,  -5.87330014e-02,
          2.76419997e-01,  -1.05070002e-01,  -3.59629989e-02,
         -2.80809999e-01],
       [  3.19240004e-01,   6.31600022e-02,  -2.78580010e-01,
          2.61200011e-01,   7.92480037e-02,  -2.14619994e-01,
         -1.04950003e-01,   1.54949993e-01,  -3.35300006e-02,
          2.48340011e+00,  -5.09039998e-01,   8.74899998e-02,
          2.14259997e-01,   2.21509993e-01,  -2.52339989e-01,
         -9.75439996e-02,  -1.92699999e-01,   1.36059999e+00,
         -1.15920000e-01,  -1.03830002e-01,   2.19290003e-01,
          1.19970001e-01,  -1.10629998e-01,   1.42120004e-01,
         -1.66429996e-01,   2.18150005e-01,   4.20860015e-03,
         -7.00120032e-02,  -2.35320002e-01,  -2.65179992e-01,
          3.12479995e-02,   1.66690007e-01,  -8.97770002e-02,
          2.00590000e-01,   3.16139996e-01,  -5.58300018e-01,
          7.57350028e-02,   2.76349992e-01,   1.27409995e-01,
         -1.81850001e-01,  -1.27220005e-01,   2.46859994e-02,
         -7.72330016e-02,  -4.89980012e-01,   2.03549992e-02,
          3.91640002e-03,   1.21500000e-01,   8.97229984e-02,
         -7.89749995e-02,   8.14429969e-02,  -9.90869999e-02,
         -5.56209981e-02,   1.07369997e-01,  -4.40419978e-03,
          4.84959990e-01,   1.17169999e-01,  -1.73289999e-02,
          1.08999997e-01,  -3.55580002e-01,   5.10840006e-02,
          1.57140002e-01,   1.79609999e-01,  -2.97109991e-01,
          3.36450003e-02,  -2.57920008e-02,  -1.39309997e-02,
         -2.30000004e-01,  -4.03059982e-02,   2.22819999e-01,
         -1.35439998e-02,   1.15540000e-02,   3.91099989e-01,
          2.65329987e-01,  -3.10119987e-01,   4.05389994e-01,
         -4.29750010e-02,   2.08110008e-02,  -3.30330014e-01,
          1.95730001e-01,  -3.79579999e-02,   1.02739997e-01,
         -1.35809998e-03,  -4.45050001e-01,   7.78860003e-02,
          8.51100013e-02,  -2.02849999e-01,  -1.94810003e-01,
          5.69330007e-02,   5.31050026e-01,   3.41540016e-02,
         -5.69959998e-01,  -1.84689999e-01,   9.34029967e-02,
          2.80440003e-01,  -2.33490005e-01,   1.09379999e-01,
         -1.42879998e-02,  -2.73999989e-01,   3.41960005e-02,
         -9.84790027e-02],
       [  3.56700011e-02,   1.85599998e-01,  -3.05519998e-01,
         -2.51199991e-01,  -2.24189993e-04,  -7.31739998e-02,
          1.32200003e-01,   1.63519997e-02,  -3.41459997e-02,
          2.77419996e+00,  -6.77910000e-02,  -6.82319999e-02,
          4.20379996e-01,  -1.62430003e-01,  -3.19739997e-01,
         -3.38930003e-02,  -3.80869992e-02,   9.30549979e-01,
         -5.36260009e-01,   9.52339992e-02,  -5.37200011e-02,
         -2.39480004e-01,   1.52759999e-01,  -1.71739999e-02,
         -1.57989994e-01,   4.44849990e-02,  -3.49970013e-01,
         -2.36240000e-01,   2.76169986e-01,   3.48140001e-02,
         -4.43699993e-02,   2.15990007e-01,  -4.60020006e-02,
          1.22599997e-01,  -1.30390003e-02,   6.79529980e-02,
          4.99430001e-02,  -9.86519977e-02,  -2.87310004e-01,
         -1.95649996e-01,  -2.56339997e-01,   7.76060000e-02,
          1.04130000e-01,   1.21679999e-01,  -5.15320003e-02,
          7.22220019e-02,  -3.85670006e-01,  -1.68909997e-01,
          2.52389997e-01,   1.22180000e-01,  -4.29439992e-01,
         -1.22089997e-01,   6.01550005e-02,  -5.72599992e-02,
          4.16130006e-01,  -5.42609990e-02,  -2.48830006e-01,
         -1.29290000e-01,   1.78519997e-03,   4.42010015e-02,
         -7.49820024e-02,  -1.15110002e-01,  -1.44140005e-01,
          6.01159990e-01,   9.13949981e-02,   2.77630001e-01,
          2.75260001e-01,   6.13510013e-02,   2.76419997e-01,
          1.41230002e-01,   3.17680001e-01,   4.43419993e-01,
          4.27650005e-01,   1.03189997e-01,   3.38169992e-01,
          7.12070009e-03,   1.35120004e-01,  -2.19019994e-01,
         -1.14979997e-01,   3.67590010e-01,  -1.15110002e-01,
          1.01620004e-01,  -4.61019993e-01,  -2.34840006e-01,
          8.17179978e-02,  -3.45560014e-01,  -2.66669989e-01,
         -2.97380000e-01,   5.34730017e-01,  -1.03560001e-01,
          2.99919993e-02,  -1.99819997e-01,  -1.88350007e-02,
          3.15519989e-01,   3.74920011e-01,   2.29069993e-01,
          3.27549994e-01,   1.89150006e-01,  -1.23930000e-01,
          2.20180005e-02],
       .....
       [ -8.68640020e-02,   1.91609994e-01,   1.09150000e-01,
         -3.43210012e-01,   2.03679994e-01,  -2.47769997e-01,
          4.60460007e-01,  -3.65700006e-01,  -1.98039994e-01,
          1.73790002e+00,  -4.35070008e-01,   9.61349979e-02,
          1.56010002e-01,   2.39030004e-01,  -4.19310004e-01,
         -9.51310024e-02,   4.43420000e-02,   1.23920000e+00,
          1.11570004e-02,  -2.25219995e-01,   3.84110004e-01,
         -1.16060004e-01,  -3.90359983e-02,   3.61060016e-02,
         -5.26760006e-04,  -1.21540003e-01,  -5.68839982e-02,
          4.14249986e-01,   3.82479995e-01,   2.35900000e-01,
         -8.55500028e-02,   8.51199999e-02,  -3.79760005e-02,
         -1.61090001e-01,   4.62740004e-01,   4.56809998e-01,
          1.50989994e-01,   1.15510002e-01,  -5.93560003e-03,
         -1.49599999e-01,   1.15900002e-01,  -1.14139996e-01,
         -1.92619994e-01,  -2.57660002e-02,   1.68489993e-01,
          4.73800004e-02,  -4.74830002e-01,  -1.60710007e-01,
         -9.62430015e-02,   1.81920007e-01,   1.49540007e-01,
          1.21299997e-01,   9.35969991e-04,  -5.73629975e-01,
         -1.78800002e-01,  -1.44850001e-01,   1.11579999e-01,
         -1.83860004e-01,   3.40299994e-01,   2.17950001e-01,
         -2.64899999e-01,  -1.16650000e-01,   6.43589973e-01,
          9.53160040e-03,   5.43700010e-02,  -2.70080000e-01,
         -4.25550014e-01,   1.87640004e-02,  -3.04060012e-01,
         -3.53909992e-02,   1.68899998e-01,  -9.61219966e-02,
          4.85760003e-01,   2.26359993e-01,   8.67540017e-02,
          3.25210005e-01,   1.01999998e-01,  -2.13860005e-01,
          1.63530007e-01,   5.70400000e-01,  -4.88339990e-01,
         -2.96689998e-02,  -1.25320002e-01,   1.57839999e-01,
         -1.63489997e-01,   1.07620001e-01,   6.45250022e-01,
         -8.36459994e-01,   1.35000005e-01,   2.16319993e-01,
         -3.08219999e-01,  -1.56729996e-01,   2.70789992e-02,
         -4.64430004e-02,  -4.03910019e-02,  -3.12559992e-01,
         -4.49640006e-01,  -4.75120008e-01,   4.75969985e-02,
         -1.27849996e-01]], dtype=float32)], dtype=object)

Basically, it's an array (the rows of a pandas series passed to a matrix) of a list of arrays. The shape outputs as:

(404290,)

Why isn't numpy detecting that I want a three dimensional array?

Edit: Changed something because I was an idiot, but having the same issue here.

Edit2: Here's how i'm creating the array

train['question1_vector'] = train['question1_nlp'].apply(lambda x: np.array([k.vector[:100] for k in x]))

Basically, I'm pulling out all word vectors (up to 100 windows) from a sentence for every row.

Then I'm calling

train['question1_vector'].values

To try to get the values.

The shape should be like

(404290, len_of_sentence, 100)

Body:
Let's say you have data like these:

a = pd.Series(np.arange(1,3))
b = a.apply(lambda n: n * np.arange(3*4).reshape(4,-1))

b.values is now:

[ array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
 array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16],
       [18, 20, 22]])]

You want to "stack" these two, 2D arrays to make a single 3D array.  For example, 11 should be on top of 22, and adjacent to those, 10 should be on top of 20.

Use np.stack(b, 0):

[ array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
 array([[ 0,  2,  4],
       [ 6,  8, 10],
       [12, 14, 16],
       [18, 20, 22]])]


问:
JavaFX animation slow moving image
I'm trying to make a scrolling background; the hope is to connect it end to tail, so that it rotates the same "ribbon" around, and I place this at the back of my game.

I've been seeking the right way to achieve animating this. I can use an AnimationTimer as per my example, or a TimeLine. However, I want to move the animation speed much slower, and delaying updates to the timer causes jerking. I did add an int variable, which returns if less than "x" millis has passed, but it didn't look good.

What is a better way to accomplish this task?

```<code>import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

class ImageContainer extends VBox {
    int w, h;
    int sectionScrollWidth = 1;
    int sections;
    int sectionCounter = 0;
    Image image;
    Canvas canvas;

public ImageContainer() {
    setVisible(true);
    load();
    w = (int) image.getWidth();
    h = (int) image.getHeight();
    canvas = new Canvas(w, h);
    getChildren().add(canvas);
    sections = w / sectionScrollWidth;
    GraphicsContext gc = canvas.getGraphicsContext2D();
    canvas.setVisible(true);
    gc.drawImage(image, 0, 0, w, h);
    setPrefSize(w, h);

    final long startNanoTime = System.nanoTime();

    new AnimationTimer() {
        public void handle(long currentNanoTime) {
            sectionCounter = sectionCounter - sectionScrollWidth;
            canvas.setTranslateX(sectionCounter);
        }
    }.start();

//        KeyValue kv1 = new KeyValue(canvas.translateXProperty(), 0);
//        KeyValue kv2 = new KeyValue(canvas.translateXProperty(), 2000);
//        KeyFrame kf1 = new KeyFrame(Duration.millis(3000), kv1, kv2);
//        Timeline translate = new Timeline();
//        translate.getKeyFrames().add(kf1);
//        translate.play();

}

public void load() {
    Path imagePath = Paths.get("./src/main/resources/ribbonImages/clouds.png");
    File f = imagePath.toFile();
    assert f.exists();
    image = new Image(f.toURI().toString());
}
}
</code>```

答:
```<code> if (((System.nanoTime()-startNanoTime)/1000000000.0)<0.05) {
                return;
            }
            else {
                startNanoTime = System.nanoTime();
            }
</code>```

Added to the handle() method will force it to return if less than 0.05 secs have passed. Fairly obvious answer, but I didn't want to just delete my own question, in case this helps someone else.

Title: JavaFX animation slow moving image

Body:
I'm trying to make a scrolling background; the hope is to connect it end to tail, so that it rotates the same "ribbon" around, and I place this at the back of my game.

I've been seeking the right way to achieve animating this. I can use an AnimationTimer as per my example, or a TimeLine. However, I want to move the animation speed much slower, and delaying updates to the timer causes jerking. I did add an int variable, which returns if less than "x" millis has passed, but it didn't look good.

What is a better way to accomplish this task?

import javafx.animation.AnimationTimer;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

class ImageContainer extends VBox {
    int w, h;
    int sectionScrollWidth = 1;
    int sections;
    int sectionCounter = 0;
    Image image;
    Canvas canvas;

public ImageContainer() {
    setVisible(true);
    load();
    w = (int) image.getWidth();
    h = (int) image.getHeight();
    canvas = new Canvas(w, h);
    getChildren().add(canvas);
    sections = w / sectionScrollWidth;
    GraphicsContext gc = canvas.getGraphicsContext2D();
    canvas.setVisible(true);
    gc.drawImage(image, 0, 0, w, h);
    setPrefSize(w, h);

    final long startNanoTime = System.nanoTime();

    new AnimationTimer() {
        public void handle(long currentNanoTime) {
            sectionCounter = sectionCounter - sectionScrollWidth;
            canvas.setTranslateX(sectionCounter);
        }
    }.start();

//        KeyValue kv1 = new KeyValue(canvas.translateXProperty(), 0);
//        KeyValue kv2 = new KeyValue(canvas.translateXProperty(), 2000);
//        KeyFrame kf1 = new KeyFrame(Duration.millis(3000), kv1, kv2);
//        Timeline translate = new Timeline();
//        translate.getKeyFrames().add(kf1);
//        translate.play();

}

public void load() {
    Path imagePath = Paths.get("./src/main/resources/ribbonImages/clouds.png");
    File f = imagePath.toFile();
    assert f.exists();
    image = new Image(f.toURI().toString());
}
}

Body:
 if (((System.nanoTime()-startNanoTime)/1000000000.0)<0.05) {
                return;
            }
            else {
                startNanoTime = System.nanoTime();
            }

Added to the handle() method will force it to return if less than 0.05 secs have passed. Fairly obvious answer, but I didn't want to just delete my own question, in case this helps someone else.


问:
Maven Assembly Plugin NoClassDefFoundError
I know that there are several posts about this particular issue but I somehow didn't find a proper solution, so sorry for asking a question that has already been asked several times before:

When I use the Maven assembly plugin and try to execute the output jar, I get the NoClassDefFoundError exception.

My pom.xml:

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pm.maven-test</groupId>
<artifactId>packaging</artifactId>
<version>1.0.0</version>
<name>packaging-test</name>

<properties>
    <maven.compiler.source>1.8.0</maven.compiler.source>
    <maven.compiler.target>1.8.0</maven.compiler.target>
</properties>

<build>
    <plugins>
        <plugin>
            <!-- package as described in assembly.xml next to POM -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- package as Jar -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>
</code>```

My assembly.xml:

```<code><assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<!-- id -->
<id>dist</id>
<baseDirectory>011_packaging</baseDirectory>

<formats>
    <format>tar.gz</format>
</formats>

<fileSets>
    <fileSet>
        <!-- executable scripts -->
        <outputDirectory>bin</outputDirectory>
        <directory>${project.basedir}/standalone/bin</directory>
        <fileMode>0744</fileMode>
        <directoryMode>0755</directoryMode>
    </fileSet>
    <fileSet>
        <!-- instructions -->
        <outputDirectory>/</outputDirectory>
        <directory>${project.basedir}/standalone</directory>
        <includes>
            <include>readme.txt</include>
        </includes>
    </fileSet>
</fileSets>

<dependencySets>
    <dependencySet>
        <!-- jars -->
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>
</code>```

And my project setup:

I tried several variations but none of them worked ....
Thanks already in advance ;-)

答:
The following changes solved my problem:

Pom.xml:

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>pm.maven-test</groupId>
<artifactId>packaging</artifactId>
<version>1.0.0</version>

<build>
    <plugins>
        <plugin>
            <!-- package as described in assembly.xml next to POM -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- package as Jar -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <!-- Compiler Plugin to set JDK Compiler Configuration -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<!-- actual dependencies -->
<dependencies>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>
</code>```

Assembly.xml:

```<code><assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<!-- id -->
<id>dist</id>
<baseDirectory>011_packaging</baseDirectory>

<!-- packaging assembly containers -->
<formats>
    <format>tar.gz</format>
</formats>

<!-- export directories and files -->
<fileSets>
    <fileSet>
        <!-- executable scripts -->
        <outputDirectory>bin</outputDirectory>
        <directory>${project.basedir}/standalone/bin</directory>
        <fileMode>0744</fileMode>
        <directoryMode>0755</directoryMode>
    </fileSet>
    <fileSet>
        <!-- instructions -->
        <outputDirectory>/</outputDirectory>
        <directory>${project.basedir}/standalone</directory>
        <includes>
            <include>readme.txt</include>
        </includes>
    </fileSet>
</fileSets>

<!-- packaging -->
<dependencySets>
    <dependencySet>
        <!-- jars -->
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>
</code>```

Body:
I know that there are several posts about this particular issue but I somehow didn't find a proper solution, so sorry for asking a question that has already been asked several times before:

When I use the Maven assembly plugin and try to execute the output jar, I get the NoClassDefFoundError exception.

My pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pm.maven-test</groupId>
<artifactId>packaging</artifactId>
<version>1.0.0</version>
<name>packaging-test</name>

<properties>
    <maven.compiler.source>1.8.0</maven.compiler.source>
    <maven.compiler.target>1.8.0</maven.compiler.target>
</properties>

<build>
    <plugins>
        <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

My assembly.xml:

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>dist</id>
<baseDirectory>011_packaging</baseDirectory>

<formats>
    <format>tar.gz</format>
</formats>

<fileSets>
    <fileSet>

        <outputDirectory>bin</outputDirectory>
        <directory>${project.basedir}/standalone/bin</directory>
        <fileMode>0744</fileMode>
        <directoryMode>0755</directoryMode>
    </fileSet>
    <fileSet>

        <outputDirectory>/</outputDirectory>
        <directory>${project.basedir}/standalone</directory>
        <includes>
            <include>readme.txt</include>
        </includes>
    </fileSet>
</fileSets>

<dependencySets>
    <dependencySet>

        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>

And my project setup:

I tried several variations but none of them worked ....
Thanks already in advance ;-)

Body:
The following changes solved my problem:

Pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>pm.maven-test</groupId>
<artifactId>packaging</artifactId>
<version>1.0.0</version>

<build>
    <plugins>
        <plugin>
            <!-- package as described in assembly.xml next to POM -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- package as Jar -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.pm.cli.Application</mainClass>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <!-- Compiler Plugin to set JDK Compiler Configuration -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<!-- actual dependencies -->
<dependencies>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

Assembly.xml:

<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<!-- id -->
<id>dist</id>
<baseDirectory>011_packaging</baseDirectory>

<!-- packaging assembly containers -->
<formats>
    <format>tar.gz</format>
</formats>

<!-- export directories and files -->
<fileSets>
    <fileSet>
        <!-- executable scripts -->
        <outputDirectory>bin</outputDirectory>
        <directory>${project.basedir}/standalone/bin</directory>
        <fileMode>0744</fileMode>
        <directoryMode>0755</directoryMode>
    </fileSet>
    <fileSet>
        <!-- instructions -->
        <outputDirectory>/</outputDirectory>
        <directory>${project.basedir}/standalone</directory>
        <includes>
            <include>readme.txt</include>
        </includes>
    </fileSet>
</fileSets>

<!-- packaging -->
<dependencySets>
    <dependencySet>
        <!-- jars -->
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>


问:
Progress bar according to countdown
I want to display a progress bar based on a countdown of 7 minutes that is displayed in a div:
 0:06:24

I need if the page is reloaded don´t reset the progress bar. Would it be possible with CSS and a script that the bar represents what the timer displays?

I use this css progress bar:

```<code> #quiz-time-left {
width: 0;
    height: 100%;
    -webkit-animation: progreso 420s linear;
            animation: progreso 420s linear;
color: #eb7260;
background: #eb7260;
 }
#page-mod-quiz-summary #quiz-timer {
    text-align: center;
    display: none;
position: absolute;
    left: -50px;
    top: -50px;
}
#quiz-timer {
border: 2px solid #eb7260;
text-indent: -9999px;
display:block;
    font-size: 0px;
    height: 35px;
}
@-webkit-keyframes progreso {
    0% {
        width: 100%;;
    }
    100% {
        width: 0;
    }
}

@keyframes progreso {
    0% {
        width: 100%;
    }
    100% {
        width: 0;
    }
}
</code>```

html

```<code><div id="quiz-timer" role="timer" aria-atomic="true" aria-relevant="text" style="display: block;">Time left: <div id="quiz-time-left">0:06:41</div></div>
</code>```

Thank you. Best regards.

答:
You could implement something like this:

Make sure you save time left in localStorage

```<code>window.onbeforeunload = function(timeLeft) {
       localStorage.setItem('countDown', timeLeft);
    }
</code>```

When loading the page check if there is an item called countDown and resume countDown with the value:

```<code>if(localStorage['countDown'] {
    resumeCountdown(localStorage.getItem('countDown');
}
</code>```

Title: Progress bar according to countdown

Body:
I want to display a progress bar based on a countdown of 7 minutes that is displayed in a div:
 0:06:24

I need if the page is reloaded don´t reset the progress bar. Would it be possible with CSS and a script that the bar represents what the timer displays?

I use this css progress bar:

 #quiz-time-left {
width: 0;
    height: 100%;
    -webkit-animation: progreso 420s linear;
            animation: progreso 420s linear;
color: #eb7260;
background: #eb7260;
 }
#page-mod-quiz-summary #quiz-timer {
    text-align: center;
    display: none;
position: absolute;
    left: -50px;
    top: -50px;
}
#quiz-timer {
border: 2px solid #eb7260;
text-indent: -9999px;
display:block;
    font-size: 0px;
    height: 35px;
}
@-webkit-keyframes progreso {
    0% {
        width: 100%;;
    }
    100% {
        width: 0;
    }
}

@keyframes progreso {
    0% {
        width: 100%;
    }
    100% {
        width: 0;
    }
}

html

Time left:
0:06:41

Thank you. Best regards.

Body:
You could implement something like this:

Make sure you save time left in localStorage

window.onbeforeunload = function(timeLeft) {
       localStorage.setItem('countDown', timeLeft);
    }

When loading the page check if there is an item called countDown and resume countDown with the value:

if(localStorage['countDown'] {
    resumeCountdown(localStorage.getItem('countDown');
}


问:
Find how many times team has won and loss the matches?
Find how many times team has won and loss the matches ?

 Find how many times team has won and loss the matches ?
My Table Structure

TeamA | TeamB | Won
A     | D     | D
B     | A     | A
A     | D     | A

Result should be like below

TeamName | Won | Lost
A        | 2   | 1
B        | 0   | 1
D        | 1   | 1```

答:
You will get correct result by using this query:

SELECT team.t AS TeamName,(SELECT  COUNT(*) FROM TeamTable WHERE won = team.t) AS won,(SELECT  WHERE won != team.t  AND (TeamA = team.t || TeamB = team.t)) AS Lost FROM (SELECT = TeamA AS t FROM TeamTable  UNION SELECT TeamB AS t FROM TeamTable) team