问:
Subscript out of bound using the PerformanceAnalytics package
as part of my portfolio analysis work with R, I found the PerformanceAnalytics package which allows for Portfolio Optimization with Rebalancing Periods. For an equally weighted portfolio I want to compute the rebalanced portfolio weights and later the portfolio turnover.

Before I used my own return data, I worked with the edhec dataset that is given by the package "PerformanceAnalytics".

```<code>library(PerformanceAnalytics)
data(edhec)
results <- Return.portfolio(edhec,rebalance_on="months",verbose=T)
bop <- results$BOP.Weight #beginning of period weights
eop <- results$EOP.Weight #end of period weights
</code>```

For this data everything works fine, but when I use my own dataset return_wd_xts I receive the following error for the following command.

```<code>Result <- Return.portfolio(return_wd_xts,rebalance_on="months",verbose=T)
</code>```

Error in [<-(*tmp*, k, , value = c(1.18880324085028, 1.18880324085028,  :
        subscript out of bounds

As I am only changing the input parameter for the returns, I further checked the requirements, but did not notice any mistake. The package needs for "R" which specifies this parameter :   "An xts, vector, matrix, data frame, timeSeries or zoo object of asset returns"

Both are xts-objects, of course with different dimensions

```<code>> dim(edhec)
[1] 152  13
> dim(return_wd_xts)
[1] 339   5
</code>```

Here is a small part of these datasets which look the same way with respect to object

```<code>print(edhec[1:2, 1:4])
           Convertible Arbitrage CTA Global Distressed Securities Emerging Markets
1997-01-31                0.0119     0.0393                0.0178           0.0791
1997-02-28                0.0123     0.0298                0.0122           0.0525
print(return_wd_xts[1:2])
                DAX 30  FRANCE CAC FTSE All Share S&P 500 COMP        TOPIX
1989-02-01 -0.02505788  0.05263979    0.126172479   0.06947866  0.036789128
1989-03-01  0.00516151 -0.05138403    0.005407798  -0.02984021 -0.000433607
</code>```

I hope you understand my problem and may help me to make this command work with my dataset. Thank you for reading!

EDIT: Here is a subset of my data

```<code>dput((return_wd_xts [1:20]))
structure(c(-0.0250578781638776, 0.00516150959728493, 0.027984930778987,
0.0195568335946277, 0.0302476452426729, 0.0546235532472364, 0.0563960785993615,
0.0184616380328433, -0.0191649019029796, -0.0665670274978261,
0.0882841155121556, 0.104673742709786, 0.0371213941123424, -0.0385187293423887,
0.0771683841234946, -0.0630725360350319, 0.0238145415986074,
0.0309389114664863, -0.0117695066096512, -0.150003389036393,
0.052639785059758, -0.0513840293484853, 0.0505421849581241, 0.0155642004003558,
0.0363734024332616, 0.0134464149885949, 0.0611794007744512, 0.0306364141480501,
-0.00476426357615802, -0.0307021420106996, 0.0539317596724095,
0.0415031613822435, -0.053760533794565, -0.0338496575263754,
0.0610766549458317, 0.0503379829858021, 0.0218084330904627, -0.00795989511152998,
-0.0304398139576833, -0.175842319085768, 0.126172479401038, 0.00540779787360186,
0.0314517537542995, 0.01453934878465, 0.000434128493880409, 0.0255336793168354,
0.0578892368585609, 0.042087921981058, -0.0391320042167483, -0.0648506565720994,
0.0611233889072859, 0.0475085133961074, -0.0267936184684199,
-0.0455480674705554, -0.00356607515714309, -0.0449416111143059,
0.10956430081054, 0.00800782556241665, -0.0108157881757961, -0.0859772845435875,
0.069478662120746, -0.0298402081915591, 0.0342339735387596, 0.0438334768568805,
0.0456543343689892, -0.00609072901753578, 0.0758752300946291,
0.0324820659733045, -0.00584492636420969, -0.0259775996143165,
0.0311303923158632, 0.0103056824572813, -0.070224865042007, 0.0162103558059008,
0.0199957087624316, -0.0171621374023858, 0.0938262079394509,
-0.00793665021865761, -0.00918129795170854, -0.0930133488049235,
0.0367891282282156, -0.000433607003410761, 0.0121513316929921,
0.0143989004011288, 0.00599829397678363, -0.0203203973786165,
0.0630356139495902, -0.00954781314102344, 0.0397939154539181,
-0.00457220832276896, 0.0466803914188968, 0.0218468298980689,
-0.0451422736463294, -0.0824118566225031, -0.200446204450984,
0.0679573810667315, 0.0913633589712441, -0.0324209892423918,
-0.044392066114818, -0.143646040192435), class = c("xts", "zoo"
), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct",
"POSIXt"), .indexTZ = "", tzone = "", index = structure(c(602290800,
604710000, 607384800, 609976800, 612655200, 615247200, 617925600,
620604000, 623199600, 625878000, 628470000, 631148400, 633826800,
636246000, 638920800, 641512800, 644191200, 646783200, 649461600,
652140000), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(20L,
5L), .Dimnames = list(NULL, c("DAX 30", "FRANCE CAC", "FTSE All Share",
"S&P 500 COMP", "TOPIX")))
</code>```

答:
There's a bug in Return.portfolio when you pass it an xts object with a POSIXct index and specify the rebalance_on argument.  You can work-around it by converting the index of return_wd_xts to Date.

```<code>index(return_wd_xts) <- as.Date(index(return_wd_xts))
Result <- Return.portfolio(return_wd_xts, rebalance_on = "months", verbose = TRUE)
</code>```

Body:
as part of my portfolio analysis work with R, I found the PerformanceAnalytics package which allows for Portfolio Optimization with Rebalancing Periods. For an equally weighted portfolio I want to compute the rebalanced portfolio weights and later the portfolio turnover.

Before I used my own return data, I worked with the edhec dataset that is given by the package "PerformanceAnalytics".

library(PerformanceAnalytics)
data(edhec)
results <- Return.portfolio(edhec,rebalance_on="months",verbose=T)
bop <- results$BOP.Weight #beginning of period weights
eop <- results$EOP.Weight #end of period weights

For this data everything works fine, but when I use my own dataset return_wd_xts I receive the following error for the following command.

Result <- Return.portfolio(return_wd_xts,rebalance_on="months",verbose=T)

Error in [<-(*tmp*, k, , value = c(1.18880324085028, 1.18880324085028,  :
        subscript out of bounds

As I am only changing the input parameter for the returns, I further checked the requirements, but did not notice any mistake. The package needs for "R" which specifies this parameter :   "An xts, vector, matrix, data frame, timeSeries or zoo object of asset returns"

Both are xts-objects, of course with different dimensions

> dim(edhec)
[1] 152  13
> dim(return_wd_xts)
[1] 339   5

Here is a small part of these datasets which look the same way with respect to object

print(edhec[1:2, 1:4])
           Convertible Arbitrage CTA Global Distressed Securities Emerging Markets
1997-01-31                0.0119     0.0393                0.0178           0.0791
1997-02-28                0.0123     0.0298                0.0122           0.0525
print(return_wd_xts[1:2])
                DAX 30  FRANCE CAC FTSE All Share S&P 500 COMP        TOPIX
1989-02-01 -0.02505788  0.05263979    0.126172479   0.06947866  0.036789128
1989-03-01  0.00516151 -0.05138403    0.005407798  -0.02984021 -0.000433607

I hope you understand my problem and may help me to make this command work with my dataset. Thank you for reading!

EDIT: Here is a subset of my data

dput((return_wd_xts [1:20]))
structure(c(-0.0250578781638776, 0.00516150959728493, 0.027984930778987,
0.0195568335946277, 0.0302476452426729, 0.0546235532472364, 0.0563960785993615,
0.0184616380328433, -0.0191649019029796, -0.0665670274978261,
0.0882841155121556, 0.104673742709786, 0.0371213941123424, -0.0385187293423887,
0.0771683841234946, -0.0630725360350319, 0.0238145415986074,
0.0309389114664863, -0.0117695066096512, -0.150003389036393,
0.052639785059758, -0.0513840293484853, 0.0505421849581241, 0.0155642004003558,
0.0363734024332616, 0.0134464149885949, 0.0611794007744512, 0.0306364141480501,
-0.00476426357615802, -0.0307021420106996, 0.0539317596724095,
0.0415031613822435, -0.053760533794565, -0.0338496575263754,
0.0610766549458317, 0.0503379829858021, 0.0218084330904627, -0.00795989511152998,
-0.0304398139576833, -0.175842319085768, 0.126172479401038, 0.00540779787360186,
0.0314517537542995, 0.01453934878465, 0.000434128493880409, 0.0255336793168354,
0.0578892368585609, 0.042087921981058, -0.0391320042167483, -0.0648506565720994,
0.0611233889072859, 0.0475085133961074, -0.0267936184684199,
-0.0455480674705554, -0.00356607515714309, -0.0449416111143059,
0.10956430081054, 0.00800782556241665, -0.0108157881757961, -0.0859772845435875,
0.069478662120746, -0.0298402081915591, 0.0342339735387596, 0.0438334768568805,
0.0456543343689892, -0.00609072901753578, 0.0758752300946291,
0.0324820659733045, -0.00584492636420969, -0.0259775996143165,
0.0311303923158632, 0.0103056824572813, -0.070224865042007, 0.0162103558059008,
0.0199957087624316, -0.0171621374023858, 0.0938262079394509,
-0.00793665021865761, -0.00918129795170854, -0.0930133488049235,
0.0367891282282156, -0.000433607003410761, 0.0121513316929921,
0.0143989004011288, 0.00599829397678363, -0.0203203973786165,
0.0630356139495902, -0.00954781314102344, 0.0397939154539181,
-0.00457220832276896, 0.0466803914188968, 0.0218468298980689,
-0.0451422736463294, -0.0824118566225031, -0.200446204450984,
0.0679573810667315, 0.0913633589712441, -0.0324209892423918,
-0.044392066114818, -0.143646040192435), class = c("xts", "zoo"
), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct",
"POSIXt"), .indexTZ = "", tzone = "", index = structure(c(602290800,
604710000, 607384800, 609976800, 612655200, 615247200, 617925600,
620604000, 623199600, 625878000, 628470000, 631148400, 633826800,
636246000, 638920800, 641512800, 644191200, 646783200, 649461600,
652140000), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(20L,
5L), .Dimnames = list(NULL, c("DAX 30", "FRANCE CAC", "FTSE All Share",
"S&P 500 COMP", "TOPIX")))

Body:
There's a bug in Return.portfolio when you pass it an xts object with a POSIXct index and specify the rebalance_on argument.  You can work-around it by converting the index of return_wd_xts to Date.

index(return_wd_xts) <- as.Date(index(return_wd_xts))
Result <- Return.portfolio(return_wd_xts, rebalance_on = "months", verbose = TRUE)


来源: stackexchange

问:
PHP - Session doesnt work on mobile
For login im using a session_start(), for desktop its works fine, but on mobile, it doesnt work. When I make a session_id() with variable, for example, session_id('login') its works on mobile, but break other sessions on other computers. But when session_id() is generated automatically, it doesn't work on mobile. What should I do?

My session_start code on index.php

```<code>session_start();
if (isset($_SESSION['username'])){
    session_id();
}
</code>```

Whole code for login.php file

```<code><?php
require('config.php');
$usernameOK = false; $passwordOK = false;
if (isset($_POST['username']) and isset($_POST['password'])){

        $username = $_POST['username'];
        $password = $_POST['password'];

        $UserQuery = "SELECT username FROM `members` WHERE username='$username'";
        $userTestResult = mysqli_query($connection, $UserQuery);
        $usernameTEST = mysqli_num_rows($userTestResult);
        if($usernameTEST == 1){$usernameOK = true;}

        $PasswordQuery = "SELECT password FROM `members` WHERE username='$username'";
        $result = mysqli_query($connection,$PasswordQuery);
        $row = mysqli_fetch_row($result);

        if (password_verify($password, $row[0])){$passwordOK = true;}

        if($usernameOK == true && $passwordOK == true){
            $_SESSION['username'] = $username;
        }else{
            $error_message = "Incorrect login data";
        }
    }

    if (isset($_SESSION['username'])){
        header("Location: ../");
        exit;
    }else{?>
    <form class="login-form" method="POST">
        <?php if(isset($error_message)){ ?><div class="mini-mes error"> <?php echo $error_message; ?> </div><?php } ?>

        <span class="placeholder">username</span>
        <input type="text" name="username" placeholder="username" required>

        <span class="placeholder">password</span>
        <input type="password" name="password" id="inputPassword" placeholder="password" required>

        <button type="submit">Login</button>
        <a class="form-link" href="register.php">Register</a>
    </form>

<?php } ?>
</code>```

答:
Why you use session_id(). session I am always use this login system. I have no problem Desktop or Mobile session.

PHP code

```</p>

```<?php
session_start();
include 'connect.php';

if(isset($_POST['submit']))
{
  $username = htmlspecialchars($_POST["uname"], ENT_QUOTES, "ISO-8859-1");
  $username = stripslashes($username);
  $password = htmlspecialchars($_POST["pass"], ENT_QUOTES, "ISO-8859-1");
  $password = stripslashes($password);

  $sql="SELECT * FROM member WHERE username= '$username' AND password='$password' AND status='1' ";
  $result=mysql_db_query($dbname,$sql);
  $row=mysql_fetch_row($result);
  $num=mysql_num_rows($result);
  $msg= "
Incorrect login data
";

  if($num>0)
  {
    $_SESSION['id']       =$row[0];
    $_SESSION['fullName'] =$row[1];
    $_SESSION['username'] =$row[2];
    $_SESSION['password'] =$row[3];
    $_SESSION['email']    =$row[4];
    $_SESSION['userType'] =$row[5];
    $_SESSION['status']   =$row[6];
    header('location:index.php');
  }
}
?>
```

<p>```

My HTML Form

```

    <form method="post">
      <p><?php if (isset($_POST['submit'])) { echo $msg; } ?> </p>
      <div>
      <input type="text" name="uname" class="form-control" placeholder="Username..." required="" />
      </div>
      <div>
      <input type="password" name="pass" class="form-control" placeholder="Password..." required="" />
      <p align="right">Forgot it?</a></p>
      </div>
      <div>
      <button class="btn btn-success submit" type="submit" name="submit"> Login   <i class="fa fa-sign-in"></i></button>
      </div>
    </form>

```

ContentLicense: CC BY-SA 3.0

Title: PHP - Session doesnt work on mobile

Body:
For login im using a session_start(), for desktop its works fine, but on mobile, it doesnt work. When I make a session_id() with variable, for example, session_id('login') its works on mobile, but break other sessions on other computers. But when session_id() is generated automatically, it doesn't work on mobile. What should I do?

My session_start code on index.php

session_start();
if (isset($_SESSION['username'])){
    session_id();
}

Whole code for login.php file

<?php
require('config.php');
$usernameOK = false; $passwordOK = false;
if (isset($_POST['username']) and isset($_POST['password'])){

        $username = $_POST['username'];
        $password = $_POST['password'];

        $UserQuery = "SELECT username FROM `members` WHERE username='$username'";
        $userTestResult = mysqli_query($connection, $UserQuery);
        $usernameTEST = mysqli_num_rows($userTestResult);
        if($usernameTEST == 1){$usernameOK = true;}

        $PasswordQuery = "SELECT password FROM `members` WHERE username='$username'";
        $result = mysqli_query($connection,$PasswordQuery);
        $row = mysqli_fetch_row($result);

        if (password_verify($password, $row[0])){$passwordOK = true;}

        if($usernameOK == true && $passwordOK == true){
            $_SESSION['username'] = $username;
        }else{
            $error_message = "Incorrect login data";
        }
    }

    if (isset($_SESSION['username'])){
        header("Location: ../");
        exit;
    }else{?>
    <form class="login-form" method="POST">
        <?php if(isset($error_message)){ ?>
 <?php echo $error_message; ?>
<?php } ?>

        username
        <input type="text" name="username" placeholder="username" required>

        password
        <input type="password" name="password" id="inputPassword" placeholder="password" required>

        <button type="submit">Login</button>
        Register
    </form>

<?php } ?>

Body:
Why you use session_id(). session I am always use this login system. I have no problem Desktop or Mobile session.

PHP code

&lt;?php
session_start();
include 'connect.php';

if(isset($_POST['submit']))
{
  $username = htmlspecialchars($_POST["uname"], ENT_QUOTES, "ISO-8859-1");
  $username = stripslashes($username);
  $password = htmlspecialchars($_POST["pass"], ENT_QUOTES, "ISO-8859-1");
  $password = stripslashes($password);

  $sql="SELECT * FROM member WHERE username= '$username' AND password='$password' AND status='1' ";
  $result=mysql_db_query($dbname,$sql);
  $row=mysql_fetch_row($result);
  $num=mysql_num_rows($result);
  $msg= "<h3 style='padding:0px;margin:0px;font-size:16px;background:#fff;padding:8px;'><font color='red'><center>Incorrect login data</center></font></h3>";

  if($num>0)
  {
    $_SESSION['id']       =$row[0];
    $_SESSION['fullName'] =$row[1];
    $_SESSION['username'] =$row[2];
    $_SESSION['password'] =$row[3];
    $_SESSION['email']    =$row[4];
    $_SESSION['userType'] =$row[5];
    $_SESSION['status']   =$row[6];
    header('location:index.php');
  }
}
?>

My HTML Form

    <form method="post">
      <p><?php if (isset($_POST['submit'])) { echo $msg; } ?> </p>
      <div>
      <input type="text" name="uname" class="form-control" placeholder="Username..." required="" />
      </div>
      <div>
      <input type="password" name="pass" class="form-control" placeholder="Password..." required="" />
      <p align="right">Forgot it?</a></p>
      </div>
      <div>
      <button class="btn btn-success submit" type="submit" name="submit"> Login   <i class="fa fa-sign-in"></i></button>
      </div>
    </form>


问:
slideshow of images using jquery from the right center of the image
I am working on making slideshow of images and I was trying to use this tutorial: http://www.slidesjs.com/

I downloaded the zip file and started using it and it works fine. Only thing I was trying out but couldn't make it work was those four dots at the right bottom, I wanted them to be on the actual image but at right center just on the border line.

An example will be like this: https://s2.postimg.org/ochp3uevt/scroller.png

if you check above image out (not showing full image), in this all the dots are vertical instead of horizontal and at the right center on that image. I want to do something similar as well. Is this possible to do that?

I tried using margin-top but it didn't worked for me.

Update:-

There is a CSS from which that four dots image is coming up and I have modified that to include margin-top but it didn't worked:

```<code>.slidesjs-pagination li a {
  display: block;
  width: 13px;
  height: 0;
  padding-top: 13px;
  background-image: url("https://s16.postimg.org/pt4k43i9x/pagination.png");
  background-position: 0 0;
  float: left;
  <!-- added by me-->
  margin-top: -50px;
}
</code>```

Here is the full HTML code:

```<code><!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>SlidesJS Standard Code Example</title>
  <meta name="description" content="SlidesJS is a simple slideshow plugin for jQuery. Packed with a useful set of features to help novice and advanced developers alike create elegant and user-friendly slideshows.">
  <meta name="author" content="Nathan Searles">

  <!-- SlidesJS Required (if responsive): Sets the page width to the device width. -->
  <meta name="viewport" content="width=device-width">
  <!-- End SlidesJS Required -->

  <!-- CSS for slidesjs.com example -->
  <link rel="stylesheet" href="css/example.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <!-- End CSS for slidesjs.com example -->

  <!-- SlidesJS Optional: If you'd like to use this design -->
  <style>
    body {
      -webkit-font-smoothing: antialiased;
      font: normal 15px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: #232525;
      padding-top:70px;
    }

    #slides,
    #slides2,
    #slides3 {
      display: none;
      margin-bottom:50px;
    }

    .slidesjs-navigation {
      margin-top:3px;
    }

    .slidesjs-previous {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-next {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-pagination {
      margin: 6px 0 0;
      float: right;
      list-style: none;
    }

    .slidesjs-pagination li {
      float: left;
      margin: 0 1px;
    }

    .slidesjs-pagination li a {
      display: block;
      width: 13px;
      height: 0;
      padding-top: 13px;
      background-image: url("https://s16.postimg.org/pt4k43i9x/pagination.png");
      background-position: 0 0;
      float: left;
      overflow: hidden;
    }

    .slidesjs-pagination li a.active,
    .slidesjs-pagination li a:hover.active {
      background-position: 0 -13px
    }

    .slidesjs-pagination li a:hover {
      background-position: 0 -26px
    }

    a:link,
    a:visited {
      color: #333
    }

    a:hover,
    a:active {
      color: #9e2020
    }

    .navbar {
      overflow: hidden
    }
  </style>
  <!-- End SlidesJS Optional-->

  <!-- SlidesJS Required: These styles are required if you'd like a responsive slideshow -->
  <style>
    #slides {
      display: none
    }

    .container {
      margin: 0 auto
    }

    /* For tablets & smart phones */
    @media (max-width: 767px) {
      body {
        padding-left: 20px;
        padding-right: 20px;
      }
      .container {
        width: auto
      }
    }

    /* For smartphones */
    @media (max-width: 480px) {
      .container {
        width: auto
      }
    }

    /* For smaller displays like laptops */
    @media (min-width: 768px) and (max-width: 979px) {
      .container {
        width: 724px
      }
    }

    /* For larger displays */
    @media (min-width: 1200px) {
      .container {
        width: 1170px
      }
    }
  </style>
  <!-- SlidesJS Required: -->
</head>
<body>
  <!-- SlidesJS Required: Start Slides -->
  <!-- The container is used to define the width of the slideshow -->
  <div class="container">
    <div id="slides">
      <img src="https://s24.postimg.org/7cyxxftpd/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
      <img src="https://s24.postimg.org/5mfwvyc69/example-slide-2.jpg" alt="Photo by: Daniel Parks Link: http://www.flickr.com/photos/parksdh/5227623068/">
      <img src="https://s24.postimg.org/48oa0ncwx/example-slide-3.jpg" alt="Photo by: Mike Ranweiler Link: http://www.flickr.com/photos/27874907@N04/4833059991/">
      <img src="https://s24.postimg.org/rbjedk3s1/example-slide-4.jpg" alt="Photo by: Stuart SeegerLink: http://www.flickr.com/photos/stuseeger/97577796/">
      <a href="#" class="slidesjs-previous slidesjs-navigation"><i class="icon-chevron-left"></i></a>
      <a href="#" class="slidesjs-next slidesjs-navigation"><i class="icon-chevron-right"></i></a>
    </div>
  </div>
  <!-- End SlidesJS Required: Start Slides -->

  <!-- SlidesJS Required: Link to jQuery -->
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Link to jquery.slides.js -->
  <script src="js/jquery.slides.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Initialize SlidesJS with a jQuery doc ready -->
  <script>
    $(function() {
      $('#slides').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });

      /*
        To have multiple slideshows on the same page
        they just need to have separate IDs
      */
      $('#slides2').slidesjs({
        width: 940,
        height: 528,
        navigation: false,
        start: 3,
        play: {
          auto: true
        }
      });

      $('#slides3').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });
    });
  </script>
  <!-- End SlidesJS Required -->
</body>
</html>
</code>```

答:
You want to absolutely position the menu to the right side with a value for right that will create space between the menu and the right side, move it to the center, then un-float the li's.

#slides {
  position: relative;
}
#slides .slidesjs-pagination {
  position: absolute;
  top: 50%; right: 1em;
  transform: translateY(-50%);
  z-index: 9999;
}
#slides .slidesjs-pagination li {
  float: none;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slidesjs/3.0/jquery.slides.min.js"></script>
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>SlidesJS Standard Code Example</title>
  <meta name="description" content="SlidesJS is a simple slideshow plugin for jQuery. Packed with a useful set of features to help novice and advanced developers alike create elegant and user-friendly slideshows.">
  <meta name="author" content="Nathan Searles">

  <!-- SlidesJS Required (if responsive): Sets the page width to the device width. -->
  <meta name="viewport" content="width=device-width">
  <!-- End SlidesJS Required -->

  <!-- CSS for slidesjs.com example -->
  <link rel="stylesheet" href="css/example.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <!-- End CSS for slidesjs.com example -->

  <!-- SlidesJS Optional: If you'd like to use this design -->
  <style>
    body {
      -webkit-font-smoothing: antialiased;
      font: normal 15px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: #232525;
      padding-top:70px;
    }

    #slides,
    #slides2,
    #slides3 {
      display: none;
      margin-bottom:50px;
    }

    .slidesjs-navigation {
      margin-top:3px;
    }

    .slidesjs-previous {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-next {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-pagination {
      margin: 6px 0 0;
      float: right;
      list-style: none;
    }

    .slidesjs-pagination li {
      float: left;
      margin: 0 1px;
    }

    .slidesjs-pagination li a {
      display: block;
      width: 13px;
      height: 0;
      padding-top: 13px;
      background-image: url("https://s16.postimg.org/pt4k43i9x/pagination.png");
      background-position: 0 0;
      float: left;
      overflow: hidden;
    }

    .slidesjs-pagination li a.active,
    .slidesjs-pagination li a:hover.active {
      background-position: 0 -13px
    }

    .slidesjs-pagination li a:hover {
      background-position: 0 -26px
    }

    a:link,
    a:visited {
      color: #333
    }

    a:hover,
    a:active {
      color: #9e2020
    }

    .navbar {
      overflow: hidden
    }
  </style>
  <!-- End SlidesJS Optional-->

  <!-- SlidesJS Required: These styles are required if you'd like a responsive slideshow -->
  <style>
    #slides {
      display: none
    }

    .container {
      margin: 0 auto
    }

    /* For tablets & smart phones */
    @media (max-width: 767px) {
      body {
        padding-left: 20px;
        padding-right: 20px;
      }
      .container {
        width: auto
      }
    }

    /* For smartphones */
    @media (max-width: 480px) {
      .container {
        width: auto
      }
    }

    /* For smaller displays like laptops */
    @media (min-width: 768px) and (max-width: 979px) {
      .container {
        width: 724px
      }
    }

    /* For larger displays */
    @media (min-width: 1200px) {
      .container {
        width: 1170px
      }
    }
  </style>
  <!-- SlidesJS Required: -->
</head>
<body>
  <!-- SlidesJS Required: Start Slides -->
  <!-- The container is used to define the width of the slideshow -->
  <div class="container">
    <div id="slides">
      <img src="https://s24.postimg.org/7cyxxftpd/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
      <img src="https://s24.postimg.org/5mfwvyc69/example-slide-2.jpg" alt="Photo by: Daniel Parks Link: http://www.flickr.com/photos/parksdh/5227623068/">
      <img src="https://s24.postimg.org/48oa0ncwx/example-slide-3.jpg" alt="Photo by: Mike Ranweiler Link: http://www.flickr.com/photos/27874907@N04/4833059991/">
      <img src="https://s24.postimg.org/rbjedk3s1/example-slide-4.jpg" alt="Photo by: Stuart SeegerLink: http://www.flickr.com/photos/stuseeger/97577796/">
      <i class="icon-chevron-left"></i>
      <i class="icon-chevron-right"></i>
    </div>
  </div>
  <!-- End SlidesJS Required: Start Slides -->

  <!-- SlidesJS Required: Link to jQuery -->
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Link to jquery.slides.js -->
  <script src="js/jquery.slides.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Initialize SlidesJS with a jQuery doc ready -->
  <script>
    $(function() {
      $('#slides').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });

      /*
        To have multiple slideshows on the same page
        they just need to have separate IDs
      */
      $('#slides2').slidesjs({
        width: 940,
        height: 528,
        navigation: false,
        start: 3,
        play: {
          auto: true
        }
      });

      $('#slides3').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });
    });
  </script>
  <!-- End SlidesJS Required -->
</body>
</html></code>```

Body:
I am working on making slideshow of images and I was trying to use this tutorial: http://www.slidesjs.com/

I downloaded the zip file and started using it and it works fine. Only thing I was trying out but couldn't make it work was those four dots at the right bottom, I wanted them to be on the actual image but at right center just on the border line.

An example will be like this: https://s2.postimg.org/ochp3uevt/scroller.png

if you check above image out (not showing full image), in this all the dots are vertical instead of horizontal and at the right center on that image. I want to do something similar as well. Is this possible to do that?

I tried using margin-top but it didn't worked for me.

Update:-

There is a CSS from which that four dots image is coming up and I have modified that to include margin-top but it didn't worked:

.slidesjs-pagination li a {
  display: block;
  width: 13px;
  height: 0;
  padding-top: 13px;
  background-image: url("https://s16.postimg.org/pt4k43i9x/pagination.png");
  background-position: 0 0;
  float: left;

  margin-top: -50px;
}

Here is the full HTML code:

<!doctype html>

  <meta charset="utf-8">
  <title>SlidesJS Standard Code Example</title>
  <meta name="description" content="SlidesJS is a simple slideshow plugin for jQuery. Packed with a useful set of features to help novice and advanced developers alike create elegant and user-friendly slideshows.">
  <meta name="author" content="Nathan Searles">

  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="css/example.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">

Body:
You want to absolutely position the menu to the right side with a value for right that will create space between the menu and the right side, move it to the center, then un-float the li's.

#slides {
  position: relative;
}
#slides .slidesjs-pagination {
  position: absolute;
  top: 50%; right: 1em;
  transform: translateY(-50%);
  z-index: 9999;
}
#slides .slidesjs-pagination li {
  float: none;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slidesjs/3.0/jquery.slides.min.js"></script>
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>SlidesJS Standard Code Example</title>
  <meta name="description" content="SlidesJS is a simple slideshow plugin for jQuery. Packed with a useful set of features to help novice and advanced developers alike create elegant and user-friendly slideshows.">
  <meta name="author" content="Nathan Searles">

  <!-- SlidesJS Required (if responsive): Sets the page width to the device width. -->
  <meta name="viewport" content="width=device-width">
  <!-- End SlidesJS Required -->

  <!-- CSS for slidesjs.com example -->
  <link rel="stylesheet" href="css/example.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <!-- End CSS for slidesjs.com example -->

  <!-- SlidesJS Optional: If you'd like to use this design -->
  <style>
    body {
      -webkit-font-smoothing: antialiased;
      font: normal 15px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: #232525;
      padding-top:70px;
    }

    #slides,
    #slides2,
    #slides3 {
      display: none;
      margin-bottom:50px;
    }

    .slidesjs-navigation {
      margin-top:3px;
    }

    .slidesjs-previous {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-next {
      margin-right: 5px;
      float: left;
    }

    .slidesjs-pagination {
      margin: 6px 0 0;
      float: right;
      list-style: none;
    }

    .slidesjs-pagination li {
      float: left;
      margin: 0 1px;
    }

    .slidesjs-pagination li a {
      display: block;
      width: 13px;
      height: 0;
      padding-top: 13px;
      background-image: url("https://s16.postimg.org/pt4k43i9x/pagination.png");
      background-position: 0 0;
      float: left;
      overflow: hidden;
    }

    .slidesjs-pagination li a.active,
    .slidesjs-pagination li a:hover.active {
      background-position: 0 -13px
    }

    .slidesjs-pagination li a:hover {
      background-position: 0 -26px
    }

    a:link,
    a:visited {
      color: #333
    }

    a:hover,
    a:active {
      color: #9e2020
    }

    .navbar {
      overflow: hidden
    }
  </style>
  <!-- End SlidesJS Optional-->

  <!-- SlidesJS Required: These styles are required if you'd like a responsive slideshow -->
  <style>
    #slides {
      display: none
    }

    .container {
      margin: 0 auto
    }

    /* For tablets & smart phones */
    @media (max-width: 767px) {
      body {
        padding-left: 20px;
        padding-right: 20px;
      }
      .container {
        width: auto
      }
    }

    /* For smartphones */
    @media (max-width: 480px) {
      .container {
        width: auto
      }
    }

    /* For smaller displays like laptops */
    @media (min-width: 768px) and (max-width: 979px) {
      .container {
        width: 724px
      }
    }

    /* For larger displays */
    @media (min-width: 1200px) {
      .container {
        width: 1170px
      }
    }
  </style>
  <!-- SlidesJS Required: -->
</head>
<body>
  <!-- SlidesJS Required: Start Slides -->
  <!-- The container is used to define the width of the slideshow -->
  <div class="container">
    <div id="slides">
      <img src="https://s24.postimg.org/7cyxxftpd/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
      <img src="https://s24.postimg.org/5mfwvyc69/example-slide-2.jpg" alt="Photo by: Daniel Parks Link: http://www.flickr.com/photos/parksdh/5227623068/">
      <img src="https://s24.postimg.org/48oa0ncwx/example-slide-3.jpg" alt="Photo by: Mike Ranweiler Link: http://www.flickr.com/photos/27874907@N04/4833059991/">
      <img src="https://s24.postimg.org/rbjedk3s1/example-slide-4.jpg" alt="Photo by: Stuart SeegerLink: http://www.flickr.com/photos/stuseeger/97577796/">
      <a href="#" class="slidesjs-previous slidesjs-navigation"><i class="icon-chevron-left"></i></a>
      <a href="#" class="slidesjs-next slidesjs-navigation"><i class="icon-chevron-right"></i></a>
    </div>
  </div>
  <!-- End SlidesJS Required: Start Slides -->

  <!-- SlidesJS Required: Link to jQuery -->
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Link to jquery.slides.js -->
  <script src="js/jquery.slides.min.js"></script>
  <!-- End SlidesJS Required -->

  <!-- SlidesJS Required: Initialize SlidesJS with a jQuery doc ready -->
  <script>
    $(function() {
      $('#slides').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });

      /*
        To have multiple slideshows on the same page
        they just need to have separate IDs
      */
      $('#slides2').slidesjs({
        width: 940,
        height: 528,
        navigation: false,
        start: 3,
        play: {
          auto: true
        }
      });

      $('#slides3').slidesjs({
        width: 940,
        height: 528,
        navigation: false
      });
    });
  </script>
  <!-- End SlidesJS Required -->
</body>
</html>


问:
View row values in openpyxl
In the csv module in python, there is a function called csv.reader which allows you to iterate over a row, returns a reader object and can be held in a container like a list.

So when the list assigned to a variable and is printed, ie:

```<code>csv_rows = list(csv.reader(csvfile, delimiter=',', quotechar='|'))
print (csv_rows)
>
>
>
[['First Name', 'Last Name', 'Zodicac', 'Date of birth', 'Sex'] # I gave an example of the function outputting a header row
</code>```

So far, I don't see a similar function like this in the openpyxl. I could be mistaken so I'm wondering if any of you can help me out.

Update

@alecxe, your solution works perfectly (except its casting my date of birth as a datetime format instead of a regular string).

```<code>def iter_rows(ws):
for row in ws.iter_rows():
    yield [cell.value for cell in row]
>
>
>>> pprint(list(iter_rows(ws)))
[['First Nam', 'Last Name', 'Zodicac', 'Date of birth', 'Sex'], ['John', 'Smith', 'Snake', datetime.datetime(1989, 9, 4, 0, 0), 'M']]
</code>```

Since I'm a beginner I wanted to know how this would work if I used a for loop instead of a list comprehension.

So I used this:

```<code>def iter_rows(ws):
result=[]
for row in ws.iter_rows()
    for cell in row:
        result.append(cell.value)
yield result
</code>```

It almost gives me the exact same output, instead it gives me this:
As you can tell, it essentially gives me one gigantic list instead of nested list in the result you gave me.

```<code>>>>print(list(iter_rows(ws)))

[['First Nam', 'Last Name', 'Zodicac', 'Date of birth', 'Sex', 'David', 'Yao', 'Snake', datetime.datetime(1989, 9, 4, 0, 0), 'M']]
</code>```

答:
I got it to work using this method:

```<code>all_rows = []

for row in worksheet:
    current_row = []
    for cell in row:
        current_row.append(cell.value)
    all_rows.append(current_row)
</code>```

Essentially, I created a list for all of the data.
Then, I iterated through each row in the worksheet.
Each cell.value within a row was added to a short-term list (current row).
Once all of the cell.values within the row are added to the short-term list, the short-term list is added to the long-term list.

Title: View row values in openpyxl

Body:
In the csv module in python, there is a function called csv.reader which allows you to iterate over a row, returns a reader object and can be held in a container like a list.

So when the list assigned to a variable and is printed, ie:

csv_rows = list(csv.reader(csvfile, delimiter=',', quotechar='|'))
print (csv_rows)
>
>
>
[['First Name', 'Last Name', 'Zodicac', 'Date of birth', 'Sex'] # I gave an example of the function outputting a header row

So far, I don't see a similar function like this in the openpyxl. I could be mistaken so I'm wondering if any of you can help me out.

Update

@alecxe, your solution works perfectly (except its casting my date of birth as a datetime format instead of a regular string).

def iter_rows(ws):
for row in ws.iter_rows():
    yield [cell.value for cell in row]
>
>
>>> pprint(list(iter_rows(ws)))
[['First Nam', 'Last Name', 'Zodicac', 'Date of birth', 'Sex'], ['John', 'Smith', 'Snake', datetime.datetime(1989, 9, 4, 0, 0), 'M']]

Since I'm a beginner I wanted to know how this would work if I used a for loop instead of a list comprehension.

So I used this:

def iter_rows(ws):
result=[]
for row in ws.iter_rows()
    for cell in row:
        result.append(cell.value)
yield result

It almost gives me the exact same output, instead it gives me this:
As you can tell, it essentially gives me one gigantic list instead of nested list in the result you gave me.

>>>print(list(iter_rows(ws)))

[['First Nam', 'Last Name', 'Zodicac', 'Date of birth', 'Sex', 'David', 'Yao', 'Snake', datetime.datetime(1989, 9, 4, 0, 0), 'M']]

Body:
I got it to work using this method:

all_rows = []

for row in worksheet:
    current_row = []
    for cell in row:
        current_row.append(cell.value)
    all_rows.append(current_row)

Essentially, I created a list for all of the data.
Then, I iterated through each row in the worksheet.
Each cell.value within a row was added to a short-term list (current row).
Once all of the cell.values within the row are added to the short-term list, the short-term list is added to the long-term list.


问:
Exercice with type String in Pascal
(Translated from German to Englisch)
I need help in this exercise :

Thread: String processing The user can make simple changes to an input sentence.

conditions

The program displays a menu for the user to select the following action. This is also displayed again after the action has been completed until the user terminates the program (a loop is therefore required).

The menu contains the following items, which should be executed when the specified letter is entered:

A. Enter the sentence

B. Determine the number of words

C. Determine the number of characters that are less than their sequence character

D. Replace all the words in the sentence with their uppercase initials

X. end

If the user enters a different letter, nothing happens or the menu is output again.

If the menu item A is selected, a prompt is issued to enter a set which is read into a string variable. This variable can not be changed by the actions of menu items B, C and D! Possibly. A copy of the set has to be prepared beforehand in another string variable.

In menu point B the number of all words in the block is to be counted. For simplicity, you can assume that there is always one space between two words. At the beginning and end of the sentence there are no spaces. The number of words is output after the calculation (e.g., "The set is 4 words").

If the user executes menu item C, the set is traversed character-by-character, and for each character it is checked whether it is smaller than its trailing character. Here is a simple character comparison (you can also write directly something like '1' <'d'). The number of characters so found is then output (e.g., "13 characters found in the sentence less than the trailing character").

In menu item D, the sentence is traversed and every word contained in it is replaced by its upper-case initial character. The capitalization is of course only made if the first character is a letter, otherwise the character remains unchanged. You can assume that the sentence never starts or ends with a space. Between two words there is always exactly one space and so it should be between the initial letters. For example, from "123 good mood" becomes "1 G L".

It is not permissible here to build up a completely new string piece by piece! Instead, you should work in a loop on a copy of the original sentence with pos, copy, length, delete and insert! It is also forbidden to "gather" the initial characters all at the beginning or end of the string; These should be inserted directly into the string at the position of the corresponding word!

Furthermore, a string can not be accessed at menu point D, because the work with string routines is to be practised explicitly here. Menu items B, C and D may only be selectable if a record has already been entered. Otherwise nothing happens or a fault message is entered when entering B, C or D in the menu and the menu is output again.

Each call to the menu items B, C or D will always work on the original set entered by the user and not on a set that has already been altered by previously executed menu items!

By entering the menu item A again, the entered block can be overwritten by a new one.

With an 'X' the user can terminate the program.

Use wherever it is the predefined string functions and do not write it yourself with difficulty loops, etc.! However, the use of the strreplace or reverseString functions is forbidden!

Here's my work till now, I only have problems with part D:

```<code>     program Project2;
        {$APPTYPE CONSOLE}
        {$R *.res}

        uses
        System.SysUtils;

        const
          lz = ' ';

        var
  Satz: string;
  Buchstabe: char;
  i, p, j, zaehler2, index, count: integer;

 writeln('A) Write Sentence');
readln(Satz);

      'D':
        begin
          index := 2;
         insert(lz, Satz, length(Satz)+1);
          count := (pos(lz,Satz));
          repeat
            delete(Satz, index,(count - index));
            index := index + 2;
           count := pos(lz,copy(Satz,index,(length(Satz)-index)))+index-1;
          until  ;
         writeln(uppercase(Satz));
        end
</code>```

答:
I'm glad you've found your own solution, well done!

While you've been doing that, I've been writing the answer below and, as I
have finished it, I thought I'd post it here to show you another way
to go about the problem of extracting words from a string.  There are
dozens of ways of doing that task, but I hope the one I've used is fairly
easy to follow.

Maybe the reason you were having a problem with this is that your string-indexing
expressions are a bit too complicated.  I bet if you come back to your code in 6 months
it will take you a while to figure out what it is supposed to be doing and longer
to tell whether it is actually doing it.  The key to avoiding problems like that
is to break your code up into chucks which are easier to follow and easier
to test.  So instead of just telling you what your repeat condition should be,
I'll show you a way which is easier to follow.

The first thing to do is to extract a singe word from the input.  So, first thing
I've written is a function, ExtractFirstWord which returns the first word in
the input string, whether or not the input includes spaces, and also returns
a Remainder string which is what is left or the input string after the first
word (and any spaces immediately following it have been removed).  This is done
using some simple while loops which are coded to skip over the leading spaces
and then build a string from the non-space characters which follow.

Code

```<code>const
    lz = ' ';

  var
    Satz: string;
    FirstWord : String;
    Remainder : String;

function ExtractFirstWord(const InputStr : String; var Remainder : String) : String;
var
  P : Integer;
  WordStart : Integer;
begin
  Result := '';
  P := 1;
  //  The following skips over any spaces at the start of InputStr
  while (P <= Length(InputStr)) and (InputStr[P] = lz) do
    Inc(P);

  //  Now we know where the first word starts
  WordStart := P;

  //  Now we can get the first word, if there is one
  while (P <= Length(InputStr)) and (InputStr[P] <> lz) do
    Inc(P);
  Result := Copy(InputStr, WordStart, P - WordStart);

  Remainder := Copy(InputStr, P, Length(InputStr));
  //  the following is one way to remove spaces at the start of Remainder
  while (Length(Remainder) > 0) and (Remainder[1] = lz) do
    Delete(Remainder, 1, Length(lz));
  //  instead you could do something simlar to the first `while` loop above
end;

begin
  Satz := ' cat dog ';
  repeat
    FirstWord := ExtractFirstWord(Satz, Remainder);
    FirstWord := UpperCase(FirstWord);
    Satz := Remainder;
    writeln('First word: ', FirstWord, ' remainder: ', Remainder);
  until Remainder = '';
  readln;
end.
</code>```

This particular way of doing it is not an ideal fit with the other requirements
specified in your task but should be easily adaptable to them.  E.g, the upper-casing of words could be done "in place" on the input string by upper-casing the current character of it in the second While loop.

Btw, if you are using Delphi or Free Pascal/Lazarus, there is a much simpler
way of extracting the words from a string.  It uses a TStringList.  Try
looking it up in the online help and have a thing about how you might use it
to do the task.

Title: Exercice with type String in Pascal

Body:
(Translated from German to Englisch)
I need help in this exercise :

Thread: String processing The user can make simple changes to an input sentence.

conditions

The program displays a menu for the user to select the following action. This is also displayed again after the action has been completed until the user terminates the program (a loop is therefore required).

The menu contains the following items, which should be executed when the specified letter is entered:

A. Enter the sentence

B. Determine the number of words

C. Determine the number of characters that are less than their sequence character

D. Replace all the words in the sentence with their uppercase initials

X. end

If the user enters a different letter, nothing happens or the menu is output again.

If the menu item A is selected, a prompt is issued to enter a set which is read into a string variable. This variable can not be changed by the actions of menu items B, C and D! Possibly. A copy of the set has to be prepared beforehand in another string variable.

In menu point B the number of all words in the block is to be counted. For simplicity, you can assume that there is always one space between two words. At the beginning and end of the sentence there are no spaces. The number of words is output after the calculation (e.g., "The set is 4 words").

If the user executes menu item C, the set is traversed character-by-character, and for each character it is checked whether it is smaller than its trailing character. Here is a simple character comparison (you can also write directly something like '1' <'d'). The number of characters so found is then output (e.g., "13 characters found in the sentence less than the trailing character").

In menu item D, the sentence is traversed and every word contained in it is replaced by its upper-case initial character. The capitalization is of course only made if the first character is a letter, otherwise the character remains unchanged. You can assume that the sentence never starts or ends with a space. Between two words there is always exactly one space and so it should be between the initial letters. For example, from "123 good mood" becomes "1 G L".

It is not permissible here to build up a completely new string piece by piece! Instead, you should work in a loop on a copy of the original sentence with pos, copy, length, delete and insert! It is also forbidden to "gather" the initial characters all at the beginning or end of the string; These should be inserted directly into the string at the position of the corresponding word!

Furthermore, a string can not be accessed at menu point D, because the work with string routines is to be practised explicitly here. Menu items B, C and D may only be selectable if a record has already been entered. Otherwise nothing happens or a fault message is entered when entering B, C or D in the menu and the menu is output again.

Each call to the menu items B, C or D will always work on the original set entered by the user and not on a set that has already been altered by previously executed menu items!

By entering the menu item A again, the entered block can be overwritten by a new one.

With an 'X' the user can terminate the program.

Use wherever it is the predefined string functions and do not write it yourself with difficulty loops, etc.! However, the use of the strreplace or reverseString functions is forbidden!

Here's my work till now, I only have problems with part D:

     program Project2;
        {$APPTYPE CONSOLE}
        {$R *.res}

        uses
        System.SysUtils;

        const
          lz = ' ';

        var
  Satz: string;
  Buchstabe: char;
  i, p, j, zaehler2, index, count: integer;

 writeln('A) Write Sentence');
readln(Satz);

      'D':
        begin
          index := 2;
         insert(lz, Satz, length(Satz)+1);
          count := (pos(lz,Satz));
          repeat
            delete(Satz, index,(count - index));
            index := index + 2;
           count := pos(lz,copy(Satz,index,(length(Satz)-index)))+index-1;
          until  ;
         writeln(uppercase(Satz));
        end

Body:
I'm glad you've found your own solution, well done!

While you've been doing that, I've been writing the answer below and, as I
have finished it, I thought I'd post it here to show you another way
to go about the problem of extracting words from a string.  There are
dozens of ways of doing that task, but I hope the one I've used is fairly
easy to follow.

Maybe the reason you were having a problem with this is that your string-indexing
expressions are a bit too complicated.  I bet if you come back to your code in 6 months
it will take you a while to figure out what it is supposed to be doing and longer
to tell whether it is actually doing it.  The key to avoiding problems like that
is to break your code up into chucks which are easier to follow and easier
to test.  So instead of just telling you what your repeat condition should be,
I'll show you a way which is easier to follow.

The first thing to do is to extract a singe word from the input.  So, first thing
I've written is a function, ExtractFirstWord which returns the first word in
the input string, whether or not the input includes spaces, and also returns
a Remainder string which is what is left or the input string after the first
word (and any spaces immediately following it have been removed).  This is done
using some simple while loops which are coded to skip over the leading spaces
and then build a string from the non-space characters which follow.

Code

const
    lz = ' ';

  var
    Satz: string;
    FirstWord : String;
    Remainder : String;

function ExtractFirstWord(const InputStr : String; var Remainder : String) : String;
var
  P : Integer;
  WordStart : Integer;
begin
  Result := '';
  P := 1;
  //  The following skips over any spaces at the start of InputStr
  while (P <= Length(InputStr)) and (InputStr[P] = lz) do
    Inc(P);

  //  Now we know where the first word starts
  WordStart := P;

  //  Now we can get the first word, if there is one
  while (P <= Length(InputStr)) and (InputStr[P] <> lz) do
    Inc(P);
  Result := Copy(InputStr, WordStart, P - WordStart);

  Remainder := Copy(InputStr, P, Length(InputStr));
  //  the following is one way to remove spaces at the start of Remainder
  while (Length(Remainder) > 0) and (Remainder[1] = lz) do
    Delete(Remainder, 1, Length(lz));
  //  instead you could do something simlar to the first `while` loop above
end;

begin
  Satz := ' cat dog ';
  repeat
    FirstWord := ExtractFirstWord(Satz, Remainder);
    FirstWord := UpperCase(FirstWord);
    Satz := Remainder;
    writeln('First word: ', FirstWord, ' remainder: ', Remainder);
  until Remainder = '';
  readln;
end.

This particular way of doing it is not an ideal fit with the other requirements
specified in your task but should be easily adaptable to them.  E.g, the upper-casing of words could be done "in place" on the input string by upper-casing the current character of it in the second While loop.

Btw, if you are using Delphi or Free Pascal/Lazarus, there is a much simpler
way of extracting the words from a string.  It uses a TStringList.  Try
looking it up in the online help and have a thing about how you might use it
to do the task.


问:
Make a list of 10 random reals between 30 and 35
Please help if possible. I am hoping to complete this code to write a program that generates 10 random reals between 30 and 35 with square brackets around the whole group - i can only get them to change into single lists to appear, but they need to all be in the same list.
this is my current solution:

```<code>import random

def problem2_4():
    random.seed(70)
    ct = 0
    while ct <= 9:
        a = random.random()*5
        a = a+30
        a = [a]
        print(a,end=" ")
        ct = ct+1
</code>```

but when you execute it it is meant to look like this:

problem2_4()

[34.54884618961936, 31.470395203793395, 32.297169396656095, 30.681793552717807,
 34.97530360173135, 30.773219981037737, 33.36969776732032, 32.990127772708405,
 33.57311858494461, 32.052629620057274]

答:
Try this</p>

```<code>a = [random.uniform(30,35) for x in range(10)]
print(a)
</code>```

Body:
Please help if possible. I am hoping to complete this code to write a program that generates 10 random reals between 30 and 35 with square brackets around the whole group - i can only get them to change into single lists to appear, but they need to all be in the same list.
this is my current solution:

import random

def problem2_4():
    random.seed(70)
    ct = 0
    while ct <= 9:
        a = random.random()*5
        a = a+30
        a = [a]
        print(a,end=" ")
        ct = ct+1

but when you execute it it is meant to look like this:

problem2_4()

[34.54884618961936, 31.470395203793395, 32.297169396656095, 30.681793552717807,
 34.97530360173135, 30.773219981037737, 33.36969776732032, 32.990127772708405,
 33.57311858494461, 32.052629620057274]

Body:
Try this

a = [random.uniform(30,35) for x in range(10)]
print(a)


问:
Splitting string with character sequence as a delimiter
The requirement is to split strings in Java so that the following

"this#{s}is#{s}a#{s}string"

would result in the following array

["this","is","a","string"]

As you can see here the delimiter is the character sequence "#{s}".

What is the fastest and efficient way of doing this using existing tools?

Am I right to assume that using regex (String.split()) is a bit of wasting because we are splitting using static string?

I got the assumption from here http://www.javamex.com/tutorials/regular_expressions/splitting_tokenisation_performance.shtml .
But I cannot use StringTokenizer since the delimiter is a sequence of char.

Note: currently I'm using String.split() and have no problem with that. This is pure curiosity.

答:
Faster than using String.split is Pattern.split: i.e., precompile the pattern and store that for subsequent use. If you use the same pattern all the time, and do a lot of splitting using that pattern, it may be worth putting that pattern into a static field or something.

Also, if your pattern contains no regex metacharacters, you can pass in Pattern.LITERAL when creating the pattern. This is something you can't do with String.split. :-P

ContentLicense: CC BY-SA 2.5


答:
First of all: Don't change your environment (Windows, 32-bit, Console, MASM, Irvine32)! You will meet a lot of people who suggest you to change it (Do it with BIOS, MS-DOS, Linux. Do it with GDI, OpenGL, DirectX. And so on.). You might solve a problem better with another environment, but you'll get new problems, which can be solved with changing the environment. At the end you'll quit the whole project - unfinished.

"$"is the termination character of a MS-DOS string. In Windows/Irvine32 you handle with a null-termination.

Even the Console mode of Windows is quite quick. So you need Irvine's Delay function to see an animation:

```<code>INCLUDE Irvine32.inc

.DATA

FIG0    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG1    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG2    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG3    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG4    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG5    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG6    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG7    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG8    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'   \O/   |',0DH,0AH,'    |    |',0DH,0AH,'    |    |',0DH,0AH,'   / \   |',0DH,0AH,' ========+',0DH,0AH, 0

.CODE

main PROC

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG0
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG1
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG2
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG3
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG4
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr
    lea edx, FIG5
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG6
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG7
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG8
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    exit                                ; Irvine32: ExitProcess

main ENDP

END main
</code>```

ClrScr is not ideal for your purpose since it clears the whole screen including the inputs. Use Irvine's GotoXY. Delete the old picture by writing spaces.

Title: Print figure of hangman in assembly

Body:
Is there a better way to print a hangman figure?

FIG0    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG1    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG2    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG3    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG4    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG5    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG6    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG7    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG8    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'   \O/   |',0DH,0AH,'    |    |',0DH,0AH,'    |    |',0DH,0AH,'   / \   |',0DH,0AH,' ========+',0DH,0AH,'$'

Here is some nice figure. https://youtu.be/e2S_POws3DQ?t=42s

Its look really cool when he jump if you win game. I try to use call Clrscr and make him jump, but no luck.

Body:
First of all: Don't change your environment (Windows, 32-bit, Console, MASM, Irvine32)! You will meet a lot of people who suggest you to change it (Do it with BIOS, MS-DOS, Linux. Do it with GDI, OpenGL, DirectX. And so on.). You might solve a problem better with another environment, but you'll get new problems, which can be solved with changing the environment. At the end you'll quit the whole project - unfinished.

"$"is the termination character of a MS-DOS string. In Windows/Irvine32 you handle with a null-termination.

Even the Console mode of Windows is quite quick. So you need Irvine's Delay function to see an animation:

INCLUDE Irvine32.inc

.DATA

FIG0    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG1    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG2    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG3    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG4    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG5    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG6    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG7    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG8    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'   \O/   |',0DH,0AH,'    |    |',0DH,0AH,'    |    |',0DH,0AH,'   / \   |',0DH,0AH,' ========+',0DH,0AH, 0

.CODE

main PROC

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG0
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG1
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG2
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG3
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG4
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr
    lea edx, FIG5
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG6
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG7
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG8
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    exit                                ; Irvine32: ExitProcess

main ENDP

END main

ClrScr is not ideal for your purpose since it clears the whole screen including the inputs. Use Irvine's GotoXY. Delete the old picture by writing spaces.


问:
Undefined symbols for architecture when add adMob
I'm adding admob to my project, but I get this error:

Undefined symbols for architecture i386:

```<code> "_OBJC_CLASS_$_EKEvent", referenced from:
      objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
  "_OBJC_CLASS_$_EKEventEditViewController", referenced from:
      objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
</code>```

I have added:

```<code>StoreKit
AudioToolbox
MessageUI
SystemConfiguration
CoreGraphics
AdSupport
</code>```

And also use -ObjC link flags..

What is the problem?

Thanks!

答:
June 5, 2017

For Google Mobile Ads SDK version 7.20.0 the following frameworks are required.

GLKit

CoreTelephony

CoreMedia

CoreVideo

MessageUI

CFNetwork

MobileCoreServices

Body:
I'm adding admob to my project, but I get this error:

Undefined symbols for architecture i386:

 "_OBJC_CLASS_$_EKEvent", referenced from:
      objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
  "_OBJC_CLASS_$_EKEventEditViewController", referenced from:
      objc-class-ref in libGoogleAdMobAds.a(GADOpener.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have added:

StoreKit
AudioToolbox
MessageUI
SystemConfiguration
CoreGraphics
AdSupport

And also use -ObjC link flags..

What is the problem?

Thanks!


问:
Ansible sysctl setting bridge-nf-call-iptables failed: sysctl: cannot stat /proc/sys/bridge-nf-call-iptables: No such file or directory
I am using ansible in CentOS 7 and trying to set the kernel setting but it's giving an error.

Ansible version 2.3.0.0.

Here is the value I am trying to change:

```<code> - name: update kernel settings
       sysctl:
         name: bridge-nf-call-iptables
         value: 1
         sysctl_set: yes
         state: present
         reload: yes
</code>```

the file is in this path /proc/sys/net/bridge/bridge-nf-call-iptables, but Ansible is looking at in /proc/sys/bridge-nf-call-iptables.

How can I fix this error?

setting bridge-nf-call-iptables failed: sysctl: cannot stat

  /proc/sys/bridge-nf-call-iptables: No such file or directory

答:
Per sysctl module manual:

name - The dot-separated path (aka key) specifying the sysctl variable.

So you need to specify:

```<code>- name: update kernel settings
  become: yes
  sysctl:
    name: net.bridge.bridge-nf-call-iptables
    value: 1
    sysctl_set: yes
    state: present
    reload: yes
</code>```

I added become explicitly to avoid confusion.

The code in your question is also incorrectly indented.

Body:
I am using ansible in CentOS 7 and trying to set the kernel setting but it's giving an error.

Ansible version 2.3.0.0.

Here is the value I am trying to change:

 - name: update kernel settings
       sysctl:
         name: bridge-nf-call-iptables
         value: 1
         sysctl_set: yes
         state: present
         reload: yes

the file is in this path /proc/sys/net/bridge/bridge-nf-call-iptables, but Ansible is looking at in /proc/sys/bridge-nf-call-iptables.

How can I fix this error?

setting bridge-nf-call-iptables failed: sysctl: cannot stat

  /proc/sys/bridge-nf-call-iptables: No such file or directory

Body:
Per sysctl module manual:

name - The dot-separated path (aka key) specifying the sysctl variable.

So you need to specify:

- name: update kernel settings
  become: yes
  sysctl:
    name: net.bridge.bridge-nf-call-iptables
    value: 1
    sysctl_set: yes
    state: present
    reload: yes

I added become explicitly to avoid confusion.

The code in your question is also incorrectly indented.


问:
I have a list of integers. I am performing some action on the items of list and then print the result in a file

There is a list t with some temperatures in it. If the temperature is
  greater than -273, then convert it to Fahrenheit and write the result
  in a separate text file named tmp.txt

Below is my code.

```<code>t=[10,-20,-289,100]
def writer(input):
    with open("tmp.txt","w+") as f:
        for i in t:
            if i>-273.15:
                f=i*9/5+32
                f.write(f)
        f.close()
print(writer(t))
</code>```

Traceback:

```<code>Traceback (most recent call last):

  File "lst_input.py", line 9, in <module>
    print(writer(t))
  File "lst_input.py", line 7, in writer
    f.write(f)
AttributeError: 'float' object has no attribute 'write'
</code>```

How to write the result to tmp.txt file?

答:
You are reusing the same variable f (file object) to store the float result. Also you don't need to close the file (f.close()) as you are using a context manager.
One more thing the variable input is not used inside the function. Instead you are using the variable t. For that for i in t should be for i in input

If you want to write each value in a separate line you need also to append \n to the written string f.write(str(x) + '\n')

```<code>t=[10, -20, -289, 100]
def writer(input):
    with open("tmp.txt","w+") as f:
        for i in input:
            if i > -273.15:
                x = i * 9 / 5 + 32
                f.write(str(x) + '\n')
print(writer(t))
</code>```

Body:
There is a list t with some temperatures in it. If the temperature is
  greater than -273, then convert it to Fahrenheit and write the result
  in a separate text file named tmp.txt

Below is my code.

t=[10,-20,-289,100]
def writer(input):
    with open("tmp.txt","w+") as f:
        for i in t:
            if i>-273.15:
                f=i*9/5+32
                f.write(f)
        f.close()
print(writer(t))

Traceback:

Traceback (most recent call last):

  File "lst_input.py", line 9, in <module>
    print(writer(t))
  File "lst_input.py", line 7, in writer
    f.write(f)
AttributeError: 'float' object has no attribute 'write'

How to write the result to tmp.txt file?

Body:
You are reusing the same variable f (file object) to store the float result. Also you don't need to close the file (f.close()) as you are using a context manager.
One more thing the variable input is not used inside the function. Instead you are using the variable t. For that for i in t should be for i in input

If you want to write each value in a separate line you need also to append \n to the written string f.write(str(x) + '\n')

t=[10, -20, -289, 100]
def writer(input):
    with open("tmp.txt","w+") as f:
        for i in input:
            if i > -273.15:
                x = i * 9 / 5 + 32
                f.write(str(x) + '\n')
print(writer(t))


问:
Display simple markup in a Label in Delphi
I am currently displaying some text in a TLabel. I would now like to emphasise certain words within the text by displaying them in bold or perhaps italic. What is the recommended way to do this in Delphi? Is there a TLabel-like component that can display simple HTML or markup?
I am imagining some code like this:

```<code>label.text:='This information is <b>important</b>';
</code>```

I am using Delphi 2010

答: Check the THtmlViewer components are free and compatible with delphi 2010.

Body:
I am currently displaying some text in a TLabel. I would now like to emphasise certain words within the text by displaying them in bold or perhaps italic. What is the recommended way to do this in Delphi? Is there a TLabel-like component that can display simple HTML or markup?
I am imagining some code like this:

label.text:='This information is important';

I am using Delphi 2010


问:
How to set a view's outlets' values from within another class
In xcode, If we have a view controller that has some subviews' (eg: label) outlets, and we want to change its text from the AppDelegate.swift class whenever an app is becoming active after suspended, How can this be done? I have tried making an instance of this view controller class from the AppDelegate class, but that didn't work because it made another view instance instead of the view itself, and we can't set the outlet as static. I have also thought of making a static ViewController property observer, but since it is static I still can't set the outlet from inside it. So, how can we do such a thing?</p>

答: The best way to achieve what you want - is notifications. In your view controller add observer which will change your label's text or whatever. From AppDelegate method post notification. If you need an example, I can help you.</p>


问:
UiCollectionView must be initialized with a non-nil layout parameter Swift 3
I have searched StackOverflow for answers to this and have tried different ways of implementing this. I have a collectionView that has a button that, when pressed, attempts to initialize another collectionView. Here's the stack trace:

```<code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010adb3d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00000001079b321e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ae1d2b5 +[NSException raise:format:] + 197
    3   UIKit                               0x0000000108eca775 -[UICollectionView initWithFrame:collectionViewLayout:] + 76
    4   UIKit                               0x0000000108f13abb -[UICollectionViewController _newCollectionViewWithFrame:collectionViewLayout:] + 108
    5   UIKit                               0x0000000108f12c94 -[UICollectionViewController loadView] + 678
    6   UIKit                               0x000000010873761c -[UIViewController loadViewIfRequired] + 201
    7   UIKit                               0x0000000108737e70 -[UIViewController view] + 27
    8   UIKit                               0x0000000108ff86a4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
    9   UIKit                               0x0000000108712702 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
    10  UIKit                               0x000000010874ae97 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
    11  UIKit                               0x000000010874e26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
    12  UIKit                               0x000000010874dd51 -[UIViewController presentViewController:animated:completion:] + 179
    13  TheAppProject                   0x0000000107385842 _TFC17TheAppProject15DailyController12publishedTapfT6senderCSo8UIButton_T_ + 754
    14  TheAppProject                   0x00000001073859fa _TToFC17TheAppProject15DailyController12publishedTapfT6senderCSo8UIButton_T_ + 58
    15  UIKit                               0x00000001085978bc -[UIApplication sendAction:to:from:forEvent:] + 83
    16  UIKit                               0x000000010871dc38 -[UIControl sendAction:to:forEvent:] + 67
    17  UIKit                               0x000000010871df51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    18  UIKit                               0x000000010871ce4d -[UIControl touchesEnded:withEvent:] + 668
    19  UIKit                               0x0000000108605545 -[UIWindow _sendTouchesForEvent:] + 2747
    20  UIKit                               0x0000000108606c33 -[UIWindow sendEvent:] + 4011
    21  UIKit                               0x00000001085b39ab -[UIApplication sendEvent:] + 371
    22  UIKit                               0x0000000108da072d __dispatchPreprocessedEventFromEventQueue + 3248
    23  UIKit                               0x0000000108d99463 __handleEventQueue + 4879
    24  CoreFoundation                      0x000000010ad58761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    25  CoreFoundation                      0x000000010ad3d98c __CFRunLoopDoSources0 + 556
    26  CoreFoundation                      0x000000010ad3ce76 __CFRunLoopRun + 918
    27  CoreFoundation                      0x000000010ad3c884 CFRunLoopRunSpecific + 420
    28  GraphicsServices                    0x000000010dc1ba6f GSEventRunModal + 161
    29  UIKit                               0x0000000108595c68 UIApplicationMain + 159
    30  TheAppProject                   0x0000000107366d8f main + 111
    31  libdyld.dylib                       0x000000010bd6368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
</code>```

Here's my code:

```<code>private let reuseIdentifier = "cell"

class MyCollectionViewController: UICollectionViewController,  UICollectionViewDelegateFlowLayout {

let myCell = MyCell()

override func viewDidLoad() {
    super.viewDidLoad()

    let layout = UICollectionViewFlowLayout()
    let collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)

    collectionView.backgroundColor = UIColor.black
    collectionView.alwaysBounceVertical = true
    collectionView.delegate = self
    collectionView.dataSource = self

    self.collectionView!.register(MyCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}

// MARK: - Layout

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    return CGSize(width: 325, height: 630)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {

    return 60.0
  }
}
</code>```

答:
Your MyCollectionViewController class is a subclass of UICollectionViewController which has a property of collectionView which is the actual UICollectionView itself.  So the separate UICollectionView you create in this line:

```<code>let collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
</code>```

is not the same as self.collectionView which is the one provided by the UICollectionViewController itself.

So this is not the source of the error you are getting.

In fact the error you are seeing is relayed to how you are creating and presenting the MyCollectionViewController itself.  You don't show the code for how that is created but you are not passing any kind of layout to it.  For example to create it in code you would do this:

```<code>let layout = UICollectionViewFlowLayout()
let myCollectionVC = MyCollectionViewController(collectionViewLayout: layout)
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have searched StackOverflow for answers to this and have tried different ways of implementing this. I have a collectionView that has a button that, when pressed, attempts to initialize another collectionView. Here's the stack trace:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010adb3d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00000001079b321e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ae1d2b5 +[NSException raise:format:] + 197
    3   UIKit                               0x0000000108eca775 -[UICollectionView initWithFrame:collectionViewLayout:] + 76
    4   UIKit                               0x0000000108f13abb -[UICollectionViewController _newCollectionViewWithFrame:collectionViewLayout:] + 108
    5   UIKit                               0x0000000108f12c94 -[UICollectionViewController loadView] + 678
    6   UIKit                               0x000000010873761c -[UIViewController loadViewIfRequired] + 201
    7   UIKit                               0x0000000108737e70 -[UIViewController view] + 27
    8   UIKit                               0x0000000108ff86a4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
    9   UIKit                               0x0000000108712702 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141
    10  UIKit                               0x000000010874ae97 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956
    11  UIKit                               0x000000010874e26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
    12  UIKit                               0x000000010874dd51 -[UIViewController presentViewController:animated:completion:] + 179
    13  TheAppProject                   0x0000000107385842 _TFC17TheAppProject15DailyController12publishedTapfT6senderCSo8UIButton_T_ + 754
    14  TheAppProject                   0x00000001073859fa _TToFC17TheAppProject15DailyController12publishedTapfT6senderCSo8UIButton_T_ + 58
    15  UIKit                               0x00000001085978bc -[UIApplication sendAction:to:from:forEvent:] + 83
    16  UIKit                               0x000000010871dc38 -[UIControl sendAction:to:forEvent:] + 67
    17  UIKit                               0x000000010871df51 -[UIControl _sendActionsForEvents:withEvent:] + 444
    18  UIKit                               0x000000010871ce4d -[UIControl touchesEnded:withEvent:] + 668
    19  UIKit                               0x0000000108605545 -[UIWindow _sendTouchesForEvent:] + 2747
    20  UIKit                               0x0000000108606c33 -[UIWindow sendEvent:] + 4011
    21  UIKit                               0x00000001085b39ab -[UIApplication sendEvent:] + 371
    22  UIKit                               0x0000000108da072d __dispatchPreprocessedEventFromEventQueue + 3248
    23  UIKit                               0x0000000108d99463 __handleEventQueue + 4879
    24  CoreFoundation                      0x000000010ad58761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    25  CoreFoundation                      0x000000010ad3d98c __CFRunLoopDoSources0 + 556
    26  CoreFoundation                      0x000000010ad3ce76 __CFRunLoopRun + 918
    27  CoreFoundation                      0x000000010ad3c884 CFRunLoopRunSpecific + 420
    28  GraphicsServices                    0x000000010dc1ba6f GSEventRunModal + 161
    29  UIKit                               0x0000000108595c68 UIApplicationMain + 159
    30  TheAppProject                   0x0000000107366d8f main + 111
    31  libdyld.dylib                       0x000000010bd6368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Here's my code:

private let reuseIdentifier = "cell"

class MyCollectionViewController: UICollectionViewController,  UICollectionViewDelegateFlowLayout {

let myCell = MyCell()

override func viewDidLoad() {
    super.viewDidLoad()

    let layout = UICollectionViewFlowLayout()
    let collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)

    collectionView.backgroundColor = UIColor.black
    collectionView.alwaysBounceVertical = true
    collectionView.delegate = self
    collectionView.dataSource = self

    self.collectionView!.register(MyCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}

// MARK: - Layout

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    return CGSize(width: 325, height: 630)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {

    return 60.0
  }
}

Body:
Your MyCollectionViewController class is a subclass of UICollectionViewController which has a property of collectionView which is the actual UICollectionView itself.  So the separate UICollectionView you create in this line:

let collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)

is not the same as self.collectionView which is the one provided by the UICollectionViewController itself.

So this is not the source of the error you are getting.

In fact the error you are seeing is relayed to how you are creating and presenting the MyCollectionViewController itself.  You don't show the code for how that is created but you are not passing any kind of layout to it.  For example to create it in code you would do this:

let layout = UICollectionViewFlowLayout()
let myCollectionVC = MyCollectionViewController(collectionViewLayout: layout)


问:
C++: How to return abstract class in a method of this abstract class
I have an abstract class and it has two derived classes. I'm trying to overload operator+ in the base class so I could do derivedClass=derivedClass+differentDerivedClass like this:

```<code>class iMatrix{
iMatrix operator+(const iMatrix& obj)
}

class UsualMatrix : public iMatrix

class SparseMatrix : public iMatrix
</code>```

Inside of main, I want to do

```<code>SparseMatrix a, b;
UsualMatrix c=a+b;
</code>```

I have copy constructors and everything that may be helpful. Now if I create the function like

```<code>iMatrix operator+(const iMatrix& obj)
</code>```

Compiler (LLVM in Xcode) says "Return type 'iMatrix' is an abstract class", but theoretically everything else should work properly. I've read manuals and other StackOverflow threads, so I've tried this:

```<code>iMatrix& operator+(const iMatrix& obj)
</code>```

Whereas function on its own does "add obj to this" and returns *this. The problem is when I do c=a+b, a becomes equal to c, but it should not be changed.

```<code>a=
1 1
1 1
b=
1 1
1 1
a+b=c;
c=
2 2
2 2
b=
1 1
1 1
a=
2 2
2 2
</code>```

What should I do? Addition and multiplying must be implemented inside of base class, and I have no idea how to fix this error.
Any advice would be appreciated, thanks.

答:
One solution could be a non-member function like this:

```<code>template <
  typename T,
  typename = typename std::enable_if<std::is_base_of<iMatrix, T>::value>::type
>
T operator+(T const & a, T const & b) {
   T res;
   // calculate res
   return res;
}
</code>```

Because iMatrix is an abstract class, you can not return an instance of it. In the example above we are overloading operator+ for all derived classes T of iMatrix and we can return T instances.

Body:
I have an abstract class and it has two derived classes. I'm trying to overload operator+ in the base class so I could do derivedClass=derivedClass+differentDerivedClass like this:

class iMatrix{
iMatrix operator+(const iMatrix& obj)
}

class UsualMatrix : public iMatrix

class SparseMatrix : public iMatrix

Inside of main, I want to do

SparseMatrix a, b;
UsualMatrix c=a+b;

I have copy constructors and everything that may be helpful. Now if I create the function like

iMatrix operator+(const iMatrix& obj)

Compiler (LLVM in Xcode) says "Return type 'iMatrix' is an abstract class", but theoretically everything else should work properly. I've read manuals and other StackOverflow threads, so I've tried this:

iMatrix& operator+(const iMatrix& obj)

Whereas function on its own does "add obj to this" and returns *this. The problem is when I do c=a+b, a becomes equal to c, but it should not be changed.

a=
1 1
1 1
b=
1 1
1 1
a+b=c;
c=
2 2
2 2
b=
1 1
1 1
a=
2 2
2 2

What should I do? Addition and multiplying must be implemented inside of base class, and I have no idea how to fix this error.
Any advice would be appreciated, thanks.

Body:
One solution could be a non-member function like this:

template <
  typename T,
  typename = typename std::enable_if<std::is_base_of<iMatrix, T>::value>::type
>
T operator+(T const & a, T const & b) {
   T res;
   // calculate res
   return res;
}

Because iMatrix is an abstract class, you can not return an instance of it. In the example above we are overloading operator+ for all derived classes T of iMatrix and we can return T instances.


问:
Does Google Cloud Speech API support regional endpoints
Is it possible to co-locate the cloud speech service in a region where the calling application resides or is there just a single endpoint?

I am wanting to reduce latency by getting my client application as close to the google service as possible, my client application is running in Azure.

答:
First it's important to clarify that google speech api has 2 ways of uploading files:
 1. from your local drive directly to the API
 2. from your google cloud storage (gcs) to the speech api

With this in mind, google cloud storage can be defined as multi-regional or regional to reduce the latency of any request against the storaget itself or the speech api from the storage.

I hope this helps


问:
Hook a section into WooCommerce Emails with customer ID
I am keen to hook a section into the WooCommerce emails with the customer number (which is the Wordpress user ID).

If I insert the following code directly into the email template file

```<code>echo $order->user_id;
</code>```

It works just fine, but if I try and hook it in, nothing is returned - except the word 'Hooked' which shows my hook is correct.

```<code>add_action( 'woocommerce_email_after_order_table', 'lnz_hook_content', 1);

function lnz_hook_content() {

echo 'hooked'; // Test Purposes only
echo $order->user_id;
</code>```

Any thoughts? Replies much appreciated.

答:
Sorted it. Needed to add the parameter into my new function:</p>

```<code>add_action( 'woocommerce_email_after_order_table', 'lnz_hook_content', 1);

function lnz_hook_content( $order) {

echo 'hooked'; // Test Purposes only
echo $order->user_id;
</code>```

Body:
I am keen to hook a section into the WooCommerce emails with the customer number (which is the Wordpress user ID).

If I insert the following code directly into the email template file

echo $order->user_id;

It works just fine, but if I try and hook it in, nothing is returned - except the word 'Hooked' which shows my hook is correct.

add_action( 'woocommerce_email_after_order_table', 'lnz_hook_content', 1);

function lnz_hook_content() {

echo 'hooked'; // Test Purposes only
echo $order->user_id;

Any thoughts? Replies much appreciated.

Body:
Sorted it. Needed to add the parameter into my new function:

add_action( 'woocommerce_email_after_order_table', 'lnz_hook_content', 1);

function lnz_hook_content( $order) {

echo 'hooked'; // Test Purposes only
echo $order->user_id;