问:
Reducing package size
I want to include mPDF into my WordPress plugin to enable some export to PDF features. However the mPDF files are pretty large at ~98mb.

Are there only specific files I can include to retain exporting to HTML and keeping the formatting? For example, I assume I can remove the fonts I will not be needed. Even then the overall package size is still pretty large. Can any other files/folders be omitted?

答:
Mike,

You can delete all fonts from 'ttfonts' directory and retain only the ones you require. If you are not using any fonts, you can just retain DejaVu fonts and delete others, which will reduce the size of fonts directory from 86.8MB to 8MB & overall library size to 20MB(approx) from 98MB.

Title: Reducing package size


来源: stackexchange

问:
org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd))
I have a Json string in the database but while converting in Java object, it gives following error:

Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

Json is : {"crt":"wrd","name":"7|6A TTTM"}

In java code I have configured it and have made it private (not static final)

```<code>objectMapper= new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
</code>```

Note: It some time converts that Json string in Object but some time gives above error. Why this unexpected result comes?

答:
this worked for me.</p>

```<code>String formattedString = yourString.trim().replaceAll("\uFFFD", "");
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have a Json string in the database but while converting in Java object, it gives following error:

Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('�' (code 65533 / 0xfffd)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

Json is : {"crt":"wrd","name":"7|6A TTTM"}

In java code I have configured it and have made it private (not static final)

objectMapper= new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);

Note: It some time converts that Json string in Object but some time gives above error. Why this unexpected result comes?

Body:
this worked for me.

String formattedString = yourString.trim().replaceAll("\uFFFD", "");


问:
How Can I Access private method of other object (but it's same instanceof) in Javascript

```<code>var a1 = new A("test")
var a2 = new A("test2")
console.log(a2.getOtherValue(a1)) // -> expected "test"
a2.setOtherValue(a1, "test3") // set another object value
console.log(a1.getValue()) // -> expected "test3"
</code>```

How Can I implement this??

答:
You can use getter and setter methods to create a property and on add, you can mutate own value. Mutating other object using current object is a bad idea.

Following is a sample:

function MyNumber(value) {
  var _value = value;

  Object.defineProperty(this, 'value', {
    get: function() {
      return _value;
    },
    set: function(v) {
      if(!isNaN(v))
        _value = v;
    }
  });
}

MyNumber.prototype = (function() {
  var proto = {};
  proto.add = function(o2) {
    if (o2 instanceof MyNumber) {
      this.value = this.value + o2.value;
    } else {
      throw new Error('Mismatched type. Expected an object of type MyNumber but got ' + o2.constructor.name);
    }
  }
  return proto;
})();

var o1 = new MyNumber(10);
var o2 = new MyNumber(20);

o1.add(o2);
console.log(o1.value);

var o3 = {
  value: 40
}

try {
  o1.add(o3);
} catch (ex) {
  console.log(ex.message)
}```

Body:
var a1 = new A("test")
var a2 = new A("test2")
console.log(a2.getOtherValue(a1)) // -> expected "test"
a2.setOtherValue(a1, "test3") // set another object value
console.log(a1.getValue()) // -> expected "test3"

How Can I implement this??


问:
Sql ranking query
I have a ranking query found from MySQL update statement to list ranking positions , but i have another requirement, after finding the rank i need to list ranking of my given player_id and few player above and below of the given player_id.

Is it possible to do it in a single query?

SAMPLE DATA:

```<code>rank player_id score
"1" "801"   "4995599"
"2" "800"   "4995599"
"3" "789"   "4995439"
"4" "1528"  "4993900"
"5" "1150"  "4993700"
"6" "2269"  "4993611"
"7" "465"   "4993523"
</code>```

DESIRED OUTPUT:
player_id = 1528

```<code>rank player_id score
"2" "800"   "4995599"
"3" "789"   "4995439"
"4" "1528"  "4993900"
"5" "1150"  "4993700"
"6" "2269"  "4993611"
</code>```

EDIT 1:
SAMPLE CODE:

```<code>SET @rank = 1, @seq = 1, @last = null;

select * from (
select *, @myRank := rank from (
SELECT *, @rank := if(@last = score, @rank, @seq) AS rank, @seq := @seq + 1,
@last := score FROM score ORDER BY score DESC) as d where player_id = 789)
as f where rank between @myRank -2 and @myRank + 2 ;
</code>```

regards,
KUMAR KS.

答:
do you mean this

```<code>SET @r=0;
select * from (select @rownum:=@rownum+1 ‘rank’, p.*
from player p,(SELECT @rownum:=0) r order by score desc) where rank>=@r-2 and rank<=@+2;
</code>```

or this,I'm sure its performance can't be lower

```<code>    SET @play_id = 0;
    set @above=2;
    set @below=2
    SELECT
        *
    FROM
        (
            SELECT
                @rownum :=@rownum + 1 rank,
                p.*
            FROM
                player p,
                (SELECT @rownum := 0) r
            ORDER BY
                score DESC
    ) t
WHERE
    rank >=(select rank from (
        SELECT
            @rownum :=@rownum + 1 ‘rank’,
            p.*
        FROM
            player p,
            (SELECT @rownum := 0) r
        ORDER BY
            score DESC
    ) a where play_id=@play_id) - @above
AND rank <=(select rank from (
        SELECT
            @rownum :=@rownum + 1 ‘rank’,
            p.*
        FROM
            player p,
            (SELECT @rownum := 0) r
        ORDER BY
            score DESC
    ) a where play_id=@play_id) + @above;
</code>```

Title: Sql ranking query

Body:
I have a ranking query found from MySQL update statement to list ranking positions , but i have another requirement, after finding the rank i need to list ranking of my given player_id and few player above and below of the given player_id.

Is it possible to do it in a single query?

SAMPLE DATA:

rank player_id score
"1" "801"   "4995599"
"2" "800"   "4995599"
"3" "789"   "4995439"
"4" "1528"  "4993900"
"5" "1150"  "4993700"
"6" "2269"  "4993611"
"7" "465"   "4993523"

DESIRED OUTPUT:
player_id = 1528

rank player_id score
"2" "800"   "4995599"
"3" "789"   "4995439"
"4" "1528"  "4993900"
"5" "1150"  "4993700"
"6" "2269"  "4993611"

EDIT 1:
SAMPLE CODE:

SET @rank = 1, @seq = 1, @last = null;

select * from (
select *, @myRank := rank from (
SELECT *, @rank := if(@last = score, @rank, @seq) AS rank, @seq := @seq + 1,
@last := score FROM score ORDER BY score DESC) as d where player_id = 789)
as f where rank between @myRank -2 and @myRank + 2 ;

regards,
KUMAR KS.

Body:
do you mean this

SET @r=0;
select * from (select @rownum:=@rownum+1 ‘rank’, p.*
from player p,(SELECT @rownum:=0) r order by score desc) where rank>=@r-2 and rank<=@+2;

or this,I'm sure its performance can't be lower

    SET @play_id = 0;
    set @above=2;
    set @below=2
    SELECT
        *
    FROM
        (
            SELECT
                @rownum :=@rownum + 1 rank,
                p.*
            FROM
                player p,
                (SELECT @rownum := 0) r
            ORDER BY
                score DESC
    ) t
WHERE
    rank >=(select rank from (
        SELECT
            @rownum :=@rownum + 1 ‘rank’,
            p.*
        FROM
            player p,
            (SELECT @rownum := 0) r
        ORDER BY
            score DESC
    ) a where play_id=@play_id) - @above
AND rank <=(select rank from (
        SELECT
            @rownum :=@rownum + 1 ‘rank’,
            p.*
        FROM
            player p,
            (SELECT @rownum := 0) r
        ORDER BY
            score DESC
    ) a where play_id=@play_id) + @above;


问:
Draw a circle at a new position
I am building a Monopoly game myself. So far I set up a interface containing the game board and several button. I want to draw two player's positions on a space once they roll their dice. I have drawn players' positions at the start area. I want to move their position(represented as filled circle) to a new position. But I don't know hot to do it. Specifically, how to let PaintEventHandler know that a new Paint event needs to be happened. Below is my code. </p>

```<code>namespace Monopoly
{
    public partial class GameInterface : Form
    {
        // If the remainder of whichTurn is 0, player1's turn to play game
        // Otherwise, player2's turn to play game
        private int whichTurn = 0;

        // Record the result of the dice rolled by players
        private int result;

        // 0 for beginning, 1 for playing
        private int state = 0;

        Game game = new Game();
        Player player1 = new Player("Player1");
        Player player2 = new Player("Player2");

        public GameInterface()
        {
            InitializeComponent();
        }

        private void panelBoard_Paint(object sender, PaintEventArgs e)
        {
            if(state == 0)
            {
                DrawPlayerAtStart(e);
            } else if(state == 1)
            {
                DrawMovement(e);
            }
        }

        // Draw two circles at the beginning area
        private void DrawPlayerAtStart(PaintEventArgs e)
        {
            // Draw first player's position
            SolidBrush firca_dis = new SolidBrush(Color.FromArgb(192, 0, 192));
            Rectangle recPlayer1 = new Rectangle(600, 500, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(firca_dis, recPlayer1); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(firca_dis), recPlayer1);

            // Draw second player's position
            SolidBrush secca_dis = new SolidBrush(Color.FromArgb(17, 0,255));
            Rectangle recPlayer2 = new Rectangle(600, 540, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(secca_dis, recPlayer2); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(secca_dis), recPlayer2);

        }

        // Draw two circles after player rolled the dice
        private void DrawMovement(PaintEventArgs e)
        {
            SolidBrush firca_dis = new SolidBrush(Color.FromArgb(192, 0, 192));
            Rectangle recPlayer1 = new Rectangle(547, 520, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(firca_dis, recPlayer1); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(firca_dis), recPlayer1);

            // Draw second player's position
            SolidBrush secca_dis = new SolidBrush(Color.FromArgb(17, 0, 255));
            Rectangle recPlayer2 = new Rectangle(547, 550, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(secca_dis, recPlayer2); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(secca_dis), recPlayer2);
        }

        // Let player roll dice roll dice
        private void rollDiceButton_Click(object sender, EventArgs e)
        {
            state = 1;
            if(whichTurn % 2 == 0)
            {
                result = player1.GetRollDiceResult();
                textBox1.AppendText("Player 1 rolled "+result + "\n");
            } else if(whichTurn % 2 == 1)
            {
                result = player2.GetRollDiceResult();
                textBox1.AppendText("Player 2 rolled " + result + "\n");
            }

        }
    }
}
</code>```

答: Move "recPlayer1" and "recPlayer2" out to Class level, just like you've done with "Player1" and "Player2".  Now simply change the location of the rectangle(s) and then call panelBoard.Invalidate(); to make the panel repaint and the circles move to their new position.

ContentLicense: CC BY-SA 4.0

Title: Draw a circle at a new position

Body:
I am building a Monopoly game myself. So far I set up a interface containing the game board and several button. I want to draw two player's positions on a space once they roll their dice. I have drawn players' positions at the start area. I want to move their position(represented as filled circle) to a new position. But I don't know hot to do it. Specifically, how to let PaintEventHandler know that a new Paint event needs to be happened. Below is my code.

namespace Monopoly
{
    public partial class GameInterface : Form
    {
        // If the remainder of whichTurn is 0, player1's turn to play game
        // Otherwise, player2's turn to play game
        private int whichTurn = 0;

        // Record the result of the dice rolled by players
        private int result;

        // 0 for beginning, 1 for playing
        private int state = 0;

        Game game = new Game();
        Player player1 = new Player("Player1");
        Player player2 = new Player("Player2");

        public GameInterface()
        {
            InitializeComponent();
        }

        private void panelBoard_Paint(object sender, PaintEventArgs e)
        {
            if(state == 0)
            {
                DrawPlayerAtStart(e);
            } else if(state == 1)
            {
                DrawMovement(e);
            }
        }

        // Draw two circles at the beginning area
        private void DrawPlayerAtStart(PaintEventArgs e)
        {
            // Draw first player's position
            SolidBrush firca_dis = new SolidBrush(Color.FromArgb(192, 0, 192));
            Rectangle recPlayer1 = new Rectangle(600, 500, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(firca_dis, recPlayer1); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(firca_dis), recPlayer1);

            // Draw second player's position
            SolidBrush secca_dis = new SolidBrush(Color.FromArgb(17, 0,255));
            Rectangle recPlayer2 = new Rectangle(600, 540, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(secca_dis, recPlayer2); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(secca_dis), recPlayer2);

        }

        // Draw two circles after player rolled the dice
        private void DrawMovement(PaintEventArgs e)
        {
            SolidBrush firca_dis = new SolidBrush(Color.FromArgb(192, 0, 192));
            Rectangle recPlayer1 = new Rectangle(547, 520, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(firca_dis, recPlayer1); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(firca_dis), recPlayer1);

            // Draw second player's position
            SolidBrush secca_dis = new SolidBrush(Color.FromArgb(17, 0, 255));
            Rectangle recPlayer2 = new Rectangle(547, 550, 20, 20); //Size and location of the Circle

            e.Graphics.FillEllipse(secca_dis, recPlayer2); //Draw a Circle and fill it
            e.Graphics.DrawEllipse(new Pen(secca_dis), recPlayer2);
        }

        // Let player roll dice roll dice
        private void rollDiceButton_Click(object sender, EventArgs e)
        {
            state = 1;
            if(whichTurn % 2 == 0)
            {
                result = player1.GetRollDiceResult();
                textBox1.AppendText("Player 1 rolled "+result + "\n");
            } else if(whichTurn % 2 == 1)
            {
                result = player2.GetRollDiceResult();
                textBox1.AppendText("Player 2 rolled " + result + "\n");
            }

        }
    }
}


问:
CSS for my SVG (Having trouble with Transform Origin)
So I have two classes(firstCircle & spin) on the First circle on the left and I'm trying to get it to rotate in place.(removed them from css so you can see the circle) I'm getting confused on transform-origin: What is wrong with my code.It's rotating way out of place instead of spinning. I added a width and height and tried transform-origin and it just makes it disappear.

```<code>.spin {
position: absolute;
top: 50%;
left: 50%;
width: 120px;
height: 1120px;
margin:-60px 0 0 -60px;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
transform-origin: center center;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg);
transform:rotate(360deg); } }
</code>```

.container { padding:auto;

width: auto;
height: auto;
text-align:center; }

.line1 {
 stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: dash 10s linear forwards;
   animation-delay: 2.13s;
}
.line2 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 2.5s;
}
.line3 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3s;
}
.line4 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3.4s;
}
.line5 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3.9s;
}
@keyframes dash {
  from {
    stroke-dashoffset: 1000;
  }
  to {
   stroke-dashoffset: 0;
  }
}

.insidefirstCircle {
  stroke-dasharray: 1000;
  stroke-dashoffset: 100;
 animation: insideCircle  10s linear forwards;
 animation-delay: 1.2s;

}
@keyframes insideCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 1;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}

.secondCircle {
 animation: secondCircle  2s linear forwards;
 animation-delay: 2.2s;
}

@keyframes secondCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 0;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}

.insidesecondCircle {
 animation: insidesecondCircle  2s linear forwards;
 animation-delay: 2.2s;
}

@keyframes insidesecondCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 0;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="css/css.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="container">
<svg>

    <path class="firstCircle spin"
       transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)"
       d="m -28.957516,-109.01346 a 20.505369,19.487934 0 0 1 25.9801488,5.74848 20.505369,19.487934 0 0 1 -1.9792854,25.281519 20.505369,19.487934 0 0 1 -26.5892124,2.031123 20.505369,19.487934 0 0 1 -6.202719,-24.656512"
       id="path7158"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <path class="insidefirstCircle"
       transform="matrix(-0.22033261,-0.9754248,-0.97735568,0.21160309,0,0)"
       d="m -102.55362,-32.142649 a 7.185163,7.442451 0 0 1 5.829705,7.489633 7.185163,7.442451 0 0 1 -6.173275,7.188196 7.185163,7.442451 0 0 1 -7.86062,-5.124812"
       id="path7160"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35700712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <ellipse class="secondCircle"
       ry="5.8064542"
       rx="5.806459"
       transform="rotate(-9.0228844)"
       cy="102.10918"
       cx="31.181959"
       id="path7162"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.38561434;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />

       <circle class="insidesecondCircle"
       r="2.081239"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:2.138;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7192"
       cx="46.80978"
       cy="95.955421" />
    <circle class="line1"
       r="8.1839027"
       cy="124.84148"
       cx="88.252518"
       id="path7166"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.63219434;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <circle
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:3.454;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7168"
       cx="88.252518"
       cy="124.84148"
       r="4.5812778" />
    <circle
       r="6.7396846"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.52063066;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7174"
       cx="128.74611"
       cy="90.168755" />
    <path
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="path7186"
       d="m -180.38976,-169.87182 a 20.505369,19.487934 0 0 1 27.64196,8.28339 20.505369,19.487934 0 0 1 -8.68637,26.27924 20.505369,19.487934 0 0 1 -27.66048,-8.22736 20.505369,19.487934 0 0 1 8.62739,-26.29677"
       transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)" />
    <ellipse
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="ellipse7190"
       cx="152.20651"
       cy="155.0309"
       transform="matrix(0.98886074,-0.14884364,0.16522023,0.9862567,0,0)"
       rx="5.5144606"
       ry="5.2409396" />

    <circle
       cy="90.168755"
       cx="128.74611"
       id="circle7196"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:2.13800001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       r="2.081239" />
    <path class="line1"
       id="path875"
       d="m 19.085467,74.174836 c 22.366283,17.178223 22.335724,17.75844 22.335724,17.75844"
       style="fill:none;stroke:#4fae7d;stroke-width:0.28233331px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
       <path class="line2"
       style="fill:none;stroke:#4fae7d;stroke-width:0.36648375px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
       d="m 51.183439,99.59881 c 29.032633,22.29825 28.992966,23.0514 28.992966,23.0514"
       id="path885" />
    <path class="line3"
       id="path879"
       d="M 95.534634,121.46865 C 123.9702,95.423153 123.73736,94.872744 123.73736,94.872744"
       style="fill:none;stroke:#4fae7d;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
    <path class="line4"
       id="path881"
       d="m 134.621,93.468564 c 37.14699,33.672096 37.14699,33.672096 37.14699,33.672096"
       style="fill:none;stroke:#4fae7d;stroke-width:0.26971px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
    <path class="line5"
       id="path883"
       d="m 181.40295,129.52127 c 31.40453,-10.83262 31.9066,-11.93052 31.9066,-11.93052"
       style="fill:none;stroke:#4fae7d;stroke-width:0.37912115px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />

  </g>
</svg>
</div>
</body>
</html></code>```

答:
Firstly, most of the CSS properties you have in your .spin and firstCircle  definitions are invalid.  position, top, 'left, and margin are all HTML-only properties. And width and height are not valid for <path> elements.

It is important to remember that SVG is a totally different standard from HTML and works differently.

Secondly, your path already has a transform. CSS transforms don't add, so any transform in your animation, will overwrite the one on your <path>.

The simplest way to resolve that problem is to either (a) get your SVG editor to multiply through the transform to the path coordinates; or (b) work around it by using a nested group <g> element around the path. One of the transforms is applied to that, and the other is applied to the path.

```<code><g transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)">
  <path class="firstCircle spin"
        d="..." />
</g>
</code>```

transform-origin

Now that those issues are resolved, we can deal with the matter of the centre-of-rotation.

There are issues with browser compatibility with transform-origin. Chrome has an implementation that is out-of-date with respect to the specification. That is in the process of getting fixed, but for now, the workaround is to always use absolute coordinates instead of percentage values.

The centre of your circle is at (-19.5, -91.7), so the correct transform-origin to use is:

```<code>transform-origin: -19.5px -91.7px;
</code>```

So if we plug this into a working example:

.spin {
  transform-origin: -19.5px -91.7px;
  animation:spin 4s linear infinite;
}
@keyframes spin {
  100% { transform:rotate(360deg); }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><svg>

  <g transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)">
    <path class="firstCircle spin"
          d="m -28.957516,-109.01346 a 20.505369,19.487934 0 0 1 25.9801488,5.74848 20.505369,19.487934 0 0 1 -1.9792854,25.281519 20.505369,19.487934 0 0 1 -26.5892124,2.031123 20.505369,19.487934 0 0 1 -6.202719,-24.656512"
          style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
  </g>

</svg></code>```

Body:
So I have two classes(firstCircle & spin) on the First circle on the left and I'm trying to get it to rotate in place.(removed them from css so you can see the circle) I'm getting confused on transform-origin: What is wrong with my code.It's rotating way out of place instead of spinning. I added a width and height and tried transform-origin and it just makes it disappear.

.spin {
position: absolute;
top: 50%;
left: 50%;
width: 120px;
height: 1120px;
margin:-60px 0 0 -60px;
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
transform-origin: center center;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg);
transform:rotate(360deg); } }

.container { padding:auto;

width: auto;
height: auto;
text-align:center; }

.line1 {
 stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: dash 10s linear forwards;
   animation-delay: 2.13s;
}
.line2 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 2.5s;
}
.line3 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3s;
}
.line4 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3.4s;
}
.line5 {
 stroke-dasharray: 1000;
 stroke-dashoffset: 1000;
 animation: dash 10s linear forwards;
 animation-delay: 3.9s;
}
@keyframes dash {
  from {
    stroke-dashoffset: 1000;
  }
  to {
   stroke-dashoffset: 0;
  }
}

.insidefirstCircle {
  stroke-dasharray: 1000;
  stroke-dashoffset: 100;
 animation: insideCircle  10s linear forwards;
 animation-delay: 1.2s;

}
@keyframes insideCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 1;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}

.secondCircle {
 animation: secondCircle  2s linear forwards;
 animation-delay: 2.2s;
}

@keyframes secondCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 0;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}

.insidesecondCircle {
 animation: insidesecondCircle  2s linear forwards;
 animation-delay: 2.2s;
}

@keyframes insidesecondCircle {
  from {
    stroke-dashoffset: 1000;
    opacity: 0;

  }
  to {
   stroke-dashoffset: 0;
   opacity: 1;
  }
}

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="css/css.css">

<svg>

    <path class="firstCircle spin"
       transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)"
       d="m -28.957516,-109.01346 a 20.505369,19.487934 0 0 1 25.9801488,5.74848 20.505369,19.487934 0 0 1 -1.9792854,25.281519 20.505369,19.487934 0 0 1 -26.5892124,2.031123 20.505369,19.487934 0 0 1 -6.202719,-24.656512"
       id="path7158"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <path class="insidefirstCircle"
       transform="matrix(-0.22033261,-0.9754248,-0.97735568,0.21160309,0,0)"
       d="m -102.55362,-32.142649 a 7.185163,7.442451 0 0 1 5.829705,7.489633 7.185163,7.442451 0 0 1 -6.173275,7.188196 7.185163,7.442451 0 0 1 -7.86062,-5.124812"
       id="path7160"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35700712;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <ellipse class="secondCircle"
       ry="5.8064542"
       rx="5.806459"
       transform="rotate(-9.0228844)"
       cy="102.10918"
       cx="31.181959"
       id="path7162"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.38561434;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />

       <circle class="insidesecondCircle"
       r="2.081239"
       style="opacity:0;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:2.138;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7192"
       cx="46.80978"
       cy="95.955421" />
    <circle class="line1"
       r="8.1839027"
       cy="124.84148"
       cx="88.252518"
       id="path7166"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.63219434;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
    <circle
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:3.454;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7168"
       cx="88.252518"
       cy="124.84148"
       r="4.5812778" />
    <circle
       r="6.7396846"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.52063066;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="circle7174"
       cx="128.74611"
       cy="90.168755" />
    <path
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="path7186"
       d="m -180.38976,-169.87182 a 20.505369,19.487934 0 0 1 27.64196,8.28339 20.505369,19.487934 0 0 1 -8.68637,26.27924 20.505369,19.487934 0 0 1 -27.66048,-8.22736 20.505369,19.487934 0 0 1 8.62739,-26.29677"
       transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)" />
    <ellipse
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       id="ellipse7190"
       cx="152.20651"
       cy="155.0309"
       transform="matrix(0.98886074,-0.14884364,0.16522023,0.9862567,0,0)"
       rx="5.5144606"
       ry="5.2409396" />

    <circle
       cy="90.168755"
       cx="128.74611"
       id="circle7196"
       style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:2.13800001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
       r="2.081239" />
    <path class="line1"
       id="path875"
       d="m 19.085467,74.174836 c 22.366283,17.178223 22.335724,17.75844 22.335724,17.75844"
       style="fill:none;stroke:#4fae7d;stroke-width:0.28233331px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
       <path class="line2"
       style="fill:none;stroke:#4fae7d;stroke-width:0.36648375px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
       d="m 51.183439,99.59881 c 29.032633,22.29825 28.992966,23.0514 28.992966,23.0514"
       id="path885" />
    <path class="line3"
       id="path879"
       d="M 95.534634,121.46865 C 123.9702,95.423153 123.73736,94.872744 123.73736,94.872744"
       style="fill:none;stroke:#4fae7d;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
    <path class="line4"
       id="path881"
       d="m 134.621,93.468564 c 37.14699,33.672096 37.14699,33.672096 37.14699,33.672096"
       style="fill:none;stroke:#4fae7d;stroke-width:0.26971px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
    <path class="line5"
       id="path883"
       d="m 181.40295,129.52127 c 31.40453,-10.83262 31.9066,-11.93052 31.9066,-11.93052"
       style="fill:none;stroke:#4fae7d;stroke-width:0.37912115px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />

  </g>
</svg>

Body:
Firstly, most of the CSS properties you have in your .spin and firstCircle  definitions are invalid.  position, top, 'left, and margin are all HTML-only properties. And width and height are not valid for <path> elements.

It is important to remember that SVG is a totally different standard from HTML and works differently.

Secondly, your path already has a transform. CSS transforms don't add, so any transform in your animation, will overwrite the one on your <path>.

The simplest way to resolve that problem is to either (a) get your SVG editor to multiply through the transform to the path coordinates; or (b) work around it by using a nested group <g> element around the path. One of the transforms is applied to that, and the other is applied to the path.

<g transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)">
  <path class="firstCircle spin"
        d="..." />
</g>

transform-origin

Now that those issues are resolved, we can deal with the matter of the centre-of-rotation.

There are issues with browser compatibility with transform-origin. Chrome has an implementation that is out-of-date with respect to the specification. That is in the process of getting fixed, but for now, the workaround is to always use absolute coordinates instead of percentage values.

The centre of your circle is at (-19.5, -91.7), so the correct transform-origin to use is:

transform-origin: -19.5px -91.7px;

So if we plug this into a working example:

.spin {
  transform-origin: -19.5px -91.7px;
  animation:spin 4s linear infinite;
}
@keyframes spin {
  100% { transform:rotate(360deg); }
}

<svg>

  <g transform="matrix(-0.98886073,0.14884376,-0.16522036,-0.98625668,0,0)">
    <path class="firstCircle spin"
          d="m -28.957516,-109.01346 a 20.505369,19.487934 0 0 1 25.9801488,5.74848 20.505369,19.487934 0 0 1 -1.9792854,25.281519 20.505369,19.487934 0 0 1 -26.5892124,2.031123 20.505369,19.487934 0 0 1 -6.202719,-24.656512"
          style="opacity:1;fill:none;fill-opacity:0.94117647;stroke:#4fae7d;stroke-width:0.35702455;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" />
  </g>

</svg>


问:
Keeping session information between a primary domain and a subdomain
I was wondering if it is possible to retain session information between a primary domain and a subdomain. For example, I login on http://www.mydomain.com/ but I want to use the same session on http://something.mydomain.com/. </p>

答:
Use session_set_cookie_params()

```<code>session_set_cookie_params ( $lifetime , '/', '.yourdomain.com');
</code>```

Note, that the domain starts with a dot. This means, the session cookie is valid for every subdomain!

http://php.net/manual/en/function.session-set-cookie-params.php

ContentLicense: CC BY-SA 2.5

Body:
Use session_set_cookie_params()

session_set_cookie_params ( $lifetime , '/', '.yourdomain.com');

Note, that the domain starts with a dot. This means, the session cookie is valid for every subdomain!

http://php.net/manual/en/function.session-set-cookie-params.php


问:
Reading mp4 files with PHP
I'm trying to read mp4 file with PHP and what I'm doing now is this:

```<code><?php
header("Content-Length: filesize");
readfile('file.mp4');
?>
</code>```

but this way I can't skip or even go back until the video is not loaded 100%. Of course when I  read directly from the file (video.mp4) everything goes well.

Thanks.

答:
I found a much cheaper PHP-only way by experimenting with the accepted solution. Although I haven't tested this against X-Sendfile, I suspect the performance is even better overall for your site, since it means a shorter Apache file.

You only need the following code to be put out seekable .mp4 videos from PHP (haven't tested with .webm or other types):

```<code>$file='path/file.mp4';

header('Content-Type: video/mp4'); #Optional if you'll only load it from other pages
header('Accept-Ranges: bytes');
header('Content-Length:'.filesize($file));

readfile($file);
</code>```

Much cleaner and faster; the accepted answer's code resulted in the video taking a very long time to load for some reason, loading the video with this code was instantaneous (both tests were on a local server with a 7.25 MB video file).

Tested with Chrome, Firefox, and Edge's default video players.

Edit: tested without header('Content-Type: video/mp4');, it still works if the file's loaded from another page! If you directly access the URL, there will be no video player; the code will just be printed out.

Title: Reading mp4 files with PHP

Body:
I'm trying to read mp4 file with PHP and what I'm doing now is this:

<?php
header("Content-Length: filesize");
readfile('file.mp4');
?>

but this way I can't skip or even go back until the video is not loaded 100%. Of course when I  read directly from the file (video.mp4) everything goes well.

Thanks.

Body:
I found a much cheaper PHP-only way by experimenting with the accepted solution. Although I haven't tested this against X-Sendfile, I suspect the performance is even better overall for your site, since it means a shorter Apache file.

You only need the following code to be put out seekable .mp4 videos from PHP (haven't tested with .webm or other types):

$file='path/file.mp4';

header('Content-Type: video/mp4'); #Optional if you'll only load it from other pages
header('Accept-Ranges: bytes');
header('Content-Length:'.filesize($file));

readfile($file);

Much cleaner and faster; the accepted answer's code resulted in the video taking a very long time to load for some reason, loading the video with this code was instantaneous (both tests were on a local server with a 7.25 MB video file).

Tested with Chrome, Firefox, and Edge's default video players.

Edit: tested without header('Content-Type: video/mp4');, it still works if the file's loaded from another page! If you directly access the URL, there will be no video player; the code will just be printed out.


问:
Complex If statements; || not working as I hoped
I feel like this is a really dumb question but my brain is fried. Right now I'm working on a very complex set of if and else statements and I'm wondering if there is an easier way? I originally tried or statements but that didn't give me the desired result.

```<code>if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && fields[3].value === '' ) {
    clusterGroup.addLayer(layer);
} else if(fields[0].value === '' && fields[1].value === city && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && (fields[2].value <= sq && sq != null) && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)) {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);
}
</code>```

Thank you in advanced.

答:
Try restructuring it into something like this</p>

```<code>if (sq != null) {
if (fields[3].value >= sq &&
    fields[2].value <= sq &&
    fields[0].value === state &&
    field[1].value === city) {

    clusterGroup.addLayer(layer);

} else if (fields[3].value >= sq) {
    if ((fields[0].value === state) ||
        (fields[0].value === state && field[1].value === city) ||
        (fields[0].value === '' &&
            field[1].value === '')) {

        clusterGroup.addLayer(layer);
    }
} else if (fields[2].value <= sq) {
    if ((fields[1].value === city) ||
        (fields[0].value === state && field[1].value === city) ||
        (fields[0].value === '' && field[1].value === '')) {

        clusterGroup.addLayer(layer);
    }
}
} else if ((fields[1].value === '' && fields[0].value === state) ||
(fields[0].value === '' && fields[1].value === city) ||
(fields[0].value === state && fields[1].value === city)) {

clusterGroup.addLayer(layer);
}
</code>```

Body:
I feel like this is a really dumb question but my brain is fried. Right now I'm working on a very complex set of if and else statements and I'm wondering if there is an easier way? I originally tried or statements but that didn't give me the desired result.

if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && fields[3].value === '' ) {
    clusterGroup.addLayer(layer);
} else if(fields[0].value === '' && fields[1].value === city && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && (fields[2].value <= sq && sq != null) && fields[3].value === '') {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)) {
    clusterGroup.addLayer(layer);

} else if(fields[0].value === '' && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === '' && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && fields[3].value === ''){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && fields[2].value === '' && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);

} else if(fields[0].value === state && fields[1].value === city && (fields[2].value <= sq && sq != null) && (fields[3].value >= sq  && sq != null)){
    clusterGroup.addLayer(layer);
}

Thank you in advanced.

Body:
Try restructuring it into something like this

if (sq != null) {
if (fields[3].value >= sq &&
    fields[2].value <= sq &&
    fields[0].value === state &&
    field[1].value === city) {

    clusterGroup.addLayer(layer);

} else if (fields[3].value >= sq) {
    if ((fields[0].value === state) ||
        (fields[0].value === state && field[1].value === city) ||
        (fields[0].value === '' &&
            field[1].value === '')) {

        clusterGroup.addLayer(layer);
    }
} else if (fields[2].value <= sq) {
    if ((fields[1].value === city) ||
        (fields[0].value === state && field[1].value === city) ||
        (fields[0].value === '' && field[1].value === '')) {

        clusterGroup.addLayer(layer);
    }
}
} else if ((fields[1].value === '' && fields[0].value === state) ||
(fields[0].value === '' && fields[1].value === city) ||
(fields[0].value === state && fields[1].value === city)) {

clusterGroup.addLayer(layer);
}


问:
Python search and character extarction
I am wanting to search and extract unique numbers from a txt files.

Every line contains a unique 10 digit number beginning with 33- (33XXXXXXXX). How do I print just the number so that i end up with a list of 33XXXXXXXX numbers that are in the file? (Python)

I want to have all the number in a list separated by an "OR" statement?
**They are located at [155-156]

答:
```<code>>>> for line in open("list_phones.txt"):
...     print(line.strip('\n'))
...
33- (33534545)
45- (73727479)
67- (53512368)

>>> import re
>>> AllWords = []
>>> for line in open("list_phones.txt"):
...     AllWords.append(re.search(r"\(([0-9]+)\)", line).group(1))
...
>>> for word in AllWords:
...     print(word)
...
33534545
73727479
53512368
</code>```

Use join() to join all elements in list & separate by a string/char.

```<code>>>> ' OR '.join(AllWords)
'33534545 OR 73727479 OR 53512368'
</code>```

Title: Python search and character extarction

Body:
>>> for line in open("list_phones.txt"):
...     print(line.strip('\n'))
...
33- (33534545)
45- (73727479)
67- (53512368)

>>> import re
>>> AllWords = []
>>> for line in open("list_phones.txt"):
...     AllWords.append(re.search(r"\(([0-9]+)\)", line).group(1))
...
>>> for word in AllWords:
...     print(word)
...
33534545
73727479
53512368

Use join() to join all elements in list & separate by a string/char.

>>> ' OR '.join(AllWords)
'33534545 OR 73727479 OR 53512368'


问:
How to hide UINavigationBar 1px bottom line
I have an app that sometimes needs its navigation bar to blend in with the content.

Does anyone know how to get rid of or to change color of this annoying little bar?

On the image below situation i have - i'm talking about this 1px height line below "Root View Controller"

答:
Swift 4
//for hiding navigation bar shadow line

```<code>navigationController?.navigationBar.shadowImage = UIImage()
</code>```

Body:
Swift 4
//for hiding navigation bar shadow line

navigationController?.navigationBar.shadowImage = UIImage()


问:
Why does the while loop not go through the loop, it stops after the first 3 inputs?
I'm trying to get this program to calculate how much these movies will cost the customer, but the while loop only asks the first three questions it never prints the total, the tax or anything else. Please help me solve this problem!

```<code>def checkout():
    The_Bourne_Identity = 1
    Harry_Potter = 2
    Holy_Cross = 3
    Arrival = 4
    Hidden = 5

    price_of_movie = 0
    price_of_movie2 = 0
    price_of_movie3 = 0
    price_of_movie4 = 0
    price_of_movie5 = 0

    ans = 0
    response = 'y'

    while response == 'y':
        ans = int(input('What movie do you have?'))
        q1 = int(input('How many of these do you have'))
        response =input('Do you have a different movie?: type y for yes: ')
        if ans == The_Bourne_Identity:
            price_of_movie = 9.99 * q1
            return price_of_movie
        elif ans == Harry_Potter:
            price_of_movie2 = 15.99 * q1
            return price_of_movie2

        elif ans == Holy_Cross:
            price_of_movie3 = 4.75 * q1
            return price_of_movie3
        elif ans == Arrival:
            price_of_movie4 = 24.99 * q1
            return price_of_movie4

        elif ans == Hidden:
            price_of_movie4 = 29.98 * q1
            return price_of_movie5

    movie_total_price =  price_of_movie + price_of_movie2 + price_of_movie3 + price_of_movie4 + price_of_movie5

    movie_tax = movie_total_price * .07
    total_cost = movie_tax + movie_total_price

    print("Your movies cost,", movie_total_price)
    print("Your tax will be,", movie_tax)
    print("Your total cost,", total_cost)

def main():
    checkout()
main()
</code>```

when I run it just does the first 3 questions and stops

答: You return from the checkout function if any of the conditions is True. If there isn't a reason to do so, comment out the return statements and you should see the remaining logs.</p>

Body:
I'm trying to get this program to calculate how much these movies will cost the customer, but the while loop only asks the first three questions it never prints the total, the tax or anything else. Please help me solve this problem!

def checkout():
    The_Bourne_Identity = 1
    Harry_Potter = 2
    Holy_Cross = 3
    Arrival = 4
    Hidden = 5

    price_of_movie = 0
    price_of_movie2 = 0
    price_of_movie3 = 0
    price_of_movie4 = 0
    price_of_movie5 = 0

    ans = 0
    response = 'y'

    while response == 'y':
        ans = int(input('What movie do you have?'))
        q1 = int(input('How many of these do you have'))
        response =input('Do you have a different movie?: type y for yes: ')
        if ans == The_Bourne_Identity:
            price_of_movie = 9.99 * q1
            return price_of_movie
        elif ans == Harry_Potter:
            price_of_movie2 = 15.99 * q1
            return price_of_movie2

        elif ans == Holy_Cross:
            price_of_movie3 = 4.75 * q1
            return price_of_movie3
        elif ans == Arrival:
            price_of_movie4 = 24.99 * q1
            return price_of_movie4

        elif ans == Hidden:
            price_of_movie4 = 29.98 * q1
            return price_of_movie5

    movie_total_price =  price_of_movie + price_of_movie2 + price_of_movie3 + price_of_movie4 + price_of_movie5

    movie_tax = movie_total_price * .07
    total_cost = movie_tax + movie_total_price

    print("Your movies cost,", movie_total_price)
    print("Your tax will be,", movie_tax)
    print("Your total cost,", total_cost)

def main():
    checkout()
main()

when I run it just does the first 3 questions and stops


问:
how to sort nested list without using optional argument `key`
im sort of stuck on a homework question.
Suppose I have a list as such:

[('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3), ('Phil Dam', 1)]

I have to write a function such that the list will be ordered by the second element , which is the integer value. Also, if two people have the same integer, then i have to sort alphabetically. Also, i am allowed to use sort but i cannot use the optional argument, key. So i should have something like this:

[('Mitchell Piker', 3), ('Luke Skywalker', 2), ('Paul George', 1), ('Phil Dam', 1)]

```<code>>>> def sort(lst: List[Tuple[str, int]]):
    """Return the list of tuples from largest integer score to lowest
    integer score. If two people have the same score, then sort them by
    alphabetical order.
    """
    lst2 = []
    lst2.append(lst[0])
    for i in range(len(lst)):
        for j in range(len(lst2)):
            if lst[i][-1] > lst2[j][-1] and lst[i][-1] not in lst2:
                lst2.insert(0, lst2[i])
            if lst[i][-1] < lst2[j][-1] and lst[i][-1] not in lst2:
                lst2.append(lst2[i][-1])
    return lst2
</code>```

however i get an error. Can anyone help? Thank you very much

答:
You can try something like this :

just for test_case, I have edited the name for more accuracy:

```<code>your_data=[('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3), ('Ahil Dam', 1)]

new={}
for item in your_data:
    if item[1] not in new:
        new[item[1]]=[item[0]]
    else:
        new[item[1]].append(item[0])

    for key,value in new.items():
        if len(value)>1:

            new[key]=sorted(value)

final_list=[]
for key,value in new.items():
    if len(value) > 1:
        for sub_item in value:
            final_list.append((sub_item,key))
    else:
        final_list.append(("".join(value),key))

print(final_list)
</code>```

output:

```<code>[('Ahil Dam', 1), ('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3)]
</code>```

or if you want result like that then just reverse the final result:

```<code>print(final_list[::-1])
</code>```

Body:
im sort of stuck on a homework question.
Suppose I have a list as such:

[('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3), ('Phil Dam', 1)]

I have to write a function such that the list will be ordered by the second element , which is the integer value. Also, if two people have the same integer, then i have to sort alphabetically. Also, i am allowed to use sort but i cannot use the optional argument, key. So i should have something like this:

[('Mitchell Piker', 3), ('Luke Skywalker', 2), ('Paul George', 1), ('Phil Dam', 1)]

>>> def sort(lst: List[Tuple[str, int]]):
    """Return the list of tuples from largest integer score to lowest
    integer score. If two people have the same score, then sort them by
    alphabetical order.
    """
    lst2 = []
    lst2.append(lst[0])
    for i in range(len(lst)):
        for j in range(len(lst2)):
            if lst[i][-1] > lst2[j][-1] and lst[i][-1] not in lst2:
                lst2.insert(0, lst2[i])
            if lst[i][-1] < lst2[j][-1] and lst[i][-1] not in lst2:
                lst2.append(lst2[i][-1])
    return lst2

however i get an error. Can anyone help? Thank you very much

Body:
You can try something like this :

just for test_case, I have edited the name for more accuracy:

your_data=[('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3), ('Ahil Dam', 1)]

new={}
for item in your_data:
    if item[1] not in new:
        new[item[1]]=[item[0]]
    else:
        new[item[1]].append(item[0])

    for key,value in new.items():
        if len(value)>1:

            new[key]=sorted(value)

final_list=[]
for key,value in new.items():
    if len(value) > 1:
        for sub_item in value:
            final_list.append((sub_item,key))
    else:
        final_list.append(("".join(value),key))

print(final_list)

output:

[('Ahil Dam', 1), ('Paul George', 1), ('Luke Skywalker', 2), ('Mitchell Piker', 3)]

or if you want result like that then just reverse the final result:

print(final_list[::-1])


问:
Triangles meets in the middle
I'm trying to figure out how to cover the bottom part of div with triangles so they meet and still get that point in the middle. Check image

Or maybe cut out that part

Title: Triangles meets in the middle

Body:
SOLUTION

-webkit-clip-path: polygon(100% 0, 100% 86%, 50% 100%, 0 85%, 0 0);
clip-path: polygon(100% 0, 100% 86%, 50% 100%, 0 85%, 0 0);

My result.


问:
how to repeat arrayllist data in java netbeans
I want to repeat data from arraylist in java netbenas one by one by pressing jbutton. so i want to know how repeat data from single array list following my code

```<code>public class NewJFrame extends javax.swing.JFrame {

private List<String>numbers;
private ListIterator <String>ltr;

public NewJFrame() {
        initComponents();
numbers=newArraylist<>();
numbers.add("A");
numbers.add("b");
numbers.add("c");

ltr= numbers.Listinterator();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ltr.hasnext()
{
system.out.println(ltr.next());}}
</code>```

out put need to come like

AbcAbc

答:
Since you want iterator to start over from the beginning when it reaches the end, you need to create a new Iterator, e.g.

```<code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    if (! ltr.hasNext())
        ltr = numbers.listInterator();
    System.out.println(ltr.next()); // Prints next or first element
}
</code>```

As an alternative, since its an ArrayList, you can use indexes to access elements, and wrap the index around using the % modulus operator, e.g.

```<code>private int listIdx;
</code>```

```<code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println(numbers.get(listIdx++ % numbers.size()));
}
</code>```

Or use an if statement:

```<code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println(numbers.get(listIdx));
    if (++listIdx == numbers.size())
        listIdx = 0;
}
</code>```

Body:
I want to repeat data from arraylist in java netbenas one by one by pressing jbutton. so i want to know how repeat data from single array list following my code

public class NewJFrame extends javax.swing.JFrame {

private List<String>numbers;
private ListIterator <String>ltr;

public NewJFrame() {
        initComponents();
numbers=newArraylist<>();
numbers.add("A");
numbers.add("b");
numbers.add("c");

ltr= numbers.Listinterator();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ltr.hasnext()
{
system.out.println(ltr.next());}}

out put need to come like

AbcAbc

Body:
Since you want iterator to start over from the beginning when it reaches the end, you need to create a new Iterator, e.g.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    if (! ltr.hasNext())
        ltr = numbers.listInterator();
    System.out.println(ltr.next()); // Prints next or first element
}

As an alternative, since its an ArrayList, you can use indexes to access elements, and wrap the index around using the % modulus operator, e.g.

private int listIdx;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println(numbers.get(listIdx++ % numbers.size()));
}

Or use an if statement:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println(numbers.get(listIdx));
    if (++listIdx == numbers.size())
        listIdx = 0;
}


问:
Using explicit cursor to calculate the total credits and the overall grade point for each student
I am trying to  calculate the total credits and the overall grade point for each student using PL/SQL cursor and also use the ROUND function to calculate GPA. I have no idea what I am doing wrong here.

I am getting a lot of errors.

Output should look like:

Student Name: Pete

BK 101 Intro to geography     3   B

BK 102 Intro to photographs       3   C

BK 140 Intro to maththematics 3   C

Total Credits: 9

Overall GPA: 2.33

```<code>DECLARE
CURSOR studentCursor IS SELECT StudentName, CourseID, CourseDescription,
CourseCredits, Grade
FROM SampleStudent;
s_StudentName VarChar2 (30)
s_CourseID Varchar2 (20)
s_CourseDescription VarChar2 (30)
s_CourseCredits VarChar2 (2)
s_Grade VarChar (2)
s_GradePoint
BEGIN
OPEN studentcursor;
    LOOP
      FETCH studentcursor INTO s_StudentName, s_CourseID,
s_CourseDescription, s_CourseCredits, s_Grade;
      EXIT WHEN studentcursor%NOTFOUND;
IF s_Grade = 'A' THEN s_GradePoint := 4
IF s_Grade = 'B' THEN s_GradePoint := 3
IF s_Grade = 'C' THEN s_GradePoint := 2
END IF;
END IF;
END IF;
DBMS_OUTPUT.PUT_LINE('Student Name: ' || s_StudentName);
DBMS_OUTPUT.PUT_LINE(s_CourseDescription || s_CourseCredits || s_Grade);
DBMS_OUTPUT.PUT_LINE('Total Credits:' || SUM(s_CourseCredits);
DBMS_OUTPUT.PUT_LINE('Overall GPA:' || ROUND()
END LOOP;
CLOSE studentCursor;
DBMS_OUTPUT.PUT_LINE('GRAND TOTAL VALUE OF ALL ITEMS:');
END;
/
</code>```

答:
This is another block with cursor:</p>

```<code>DECLARE
  V_TOTAL_CREDITS      NUMBER := 0;
  V_STUDENT_NAME       VARCHAR2(100);
  V_COURSE_ID          VARCHAR2(50);
  V_COURSE_DESCRIPTION VARCHAR2(200);
  V_GRADE              VARCHAR2(10);
  V_GRADE_POINT        PLS_INTEGER;
  V_COURSE_CREDITS     NUMBER;
  V_SUM_COURSE_CREDITS NUMBER;
  V_GPA                NUMBER;

  CURSOR STUDENT_CURSOR IS
    SELECT StudentName,
           CourseID,
           CourseDescription,
           Grade,
           DECODE(GRADE, 'A', 4, 'B', 3, 'C', 2) GRADE_POINT,
           CourseCredits,
           SUM(CourseCredits) OVER(PARTITION BY StudentName ORDER BY CourseID)  SUM_COURSE_CREDITS,
           AVG(CourseCredits) OVER(PARTITION BY StudentName ORDER BY CourseID)  GPA
    FROM SampleStudent;

BEGIN
  OPEN STUDENT_CURSOR;

  LOOP
    FETCH STUDENT_CURSOR INTO V_STUDENT_NAME,
                              V_COURSE_ID,
                              V_COURSE_DESCRIPTION,
                              V_GRADE,
                              V_GRADE_POINT,
                              V_COURSE_CREDITS,
                              V_SUM_COURSE_CREDITS,
                              V_GPA;

    EXIT WHEN STUDENT_CURSOR%NOTFOUND;

    V_TOTAL_CREDITS := V_TOTAL_CREDITS + V_COURSE_CREDITS;

    DBMS_OUTPUT.PUT_LINE('Student Name: ' || V_STUDENT_NAME);
    DBMS_OUTPUT.PUT_LINE(V_COURSE_ID || ' '  ||
                         V_COURSE_CREDITS || ' INTRO TO ' ||
                         V_COURSE_DESCRIPTION || ' ' ||
                         V_GRADE_POINT || ' ' ||
                         V_GRADE);
    DBMS_OUTPUT.PUT_LINE('Total Credits:' || V_SUM_COURSE_CREDITS);
    DBMS_OUTPUT.PUT_LINE('Overall GPA:' || V_GPA);

  END LOOP;
  CLOSE STUDENT_CURSOR;

  DBMS_OUTPUT.PUT_LINE('GRAND TOTAL VALUE OF ALL ITEMS:' || V_TOTAL_CREDITS);

END;
</code>```

Body:
I am trying to  calculate the total credits and the overall grade point for each student using PL/SQL cursor and also use the ROUND function to calculate GPA. I have no idea what I am doing wrong here.

I am getting a lot of errors.

Output should look like:

Student Name: Pete

BK 101 Intro to geography     3   B

BK 102 Intro to photographs       3   C

BK 140 Intro to maththematics 3   C

Total Credits: 9

Overall GPA: 2.33

DECLARE
CURSOR studentCursor IS SELECT StudentName, CourseID, CourseDescription,
CourseCredits, Grade
FROM SampleStudent;
s_StudentName VarChar2 (30)
s_CourseID Varchar2 (20)
s_CourseDescription VarChar2 (30)
s_CourseCredits VarChar2 (2)
s_Grade VarChar (2)
s_GradePoint
BEGIN
OPEN studentcursor;
    LOOP
      FETCH studentcursor INTO s_StudentName, s_CourseID,
s_CourseDescription, s_CourseCredits, s_Grade;
      EXIT WHEN studentcursor%NOTFOUND;
IF s_Grade = 'A' THEN s_GradePoint := 4
IF s_Grade = 'B' THEN s_GradePoint := 3
IF s_Grade = 'C' THEN s_GradePoint := 2
END IF;
END IF;
END IF;
DBMS_OUTPUT.PUT_LINE('Student Name: ' || s_StudentName);
DBMS_OUTPUT.PUT_LINE(s_CourseDescription || s_CourseCredits || s_Grade);
DBMS_OUTPUT.PUT_LINE('Total Credits:' || SUM(s_CourseCredits);
DBMS_OUTPUT.PUT_LINE('Overall GPA:' || ROUND()
END LOOP;
CLOSE studentCursor;
DBMS_OUTPUT.PUT_LINE('GRAND TOTAL VALUE OF ALL ITEMS:');
END;
/

Body:
This is another block with cursor:

DECLARE
  V_TOTAL_CREDITS      NUMBER := 0;
  V_STUDENT_NAME       VARCHAR2(100);
  V_COURSE_ID          VARCHAR2(50);
  V_COURSE_DESCRIPTION VARCHAR2(200);
  V_GRADE              VARCHAR2(10);
  V_GRADE_POINT        PLS_INTEGER;
  V_COURSE_CREDITS     NUMBER;
  V_SUM_COURSE_CREDITS NUMBER;
  V_GPA                NUMBER;

  CURSOR STUDENT_CURSOR IS
    SELECT StudentName,
           CourseID,
           CourseDescription,
           Grade,
           DECODE(GRADE, 'A', 4, 'B', 3, 'C', 2) GRADE_POINT,
           CourseCredits,
           SUM(CourseCredits) OVER(PARTITION BY StudentName ORDER BY CourseID)  SUM_COURSE_CREDITS,
           AVG(CourseCredits) OVER(PARTITION BY StudentName ORDER BY CourseID)  GPA
    FROM SampleStudent;

BEGIN
  OPEN STUDENT_CURSOR;

  LOOP
    FETCH STUDENT_CURSOR INTO V_STUDENT_NAME,
                              V_COURSE_ID,
                              V_COURSE_DESCRIPTION,
                              V_GRADE,
                              V_GRADE_POINT,
                              V_COURSE_CREDITS,
                              V_SUM_COURSE_CREDITS,
                              V_GPA;

    EXIT WHEN STUDENT_CURSOR%NOTFOUND;

    V_TOTAL_CREDITS := V_TOTAL_CREDITS + V_COURSE_CREDITS;

    DBMS_OUTPUT.PUT_LINE('Student Name: ' || V_STUDENT_NAME);
    DBMS_OUTPUT.PUT_LINE(V_COURSE_ID || ' '  ||
                         V_COURSE_CREDITS || ' INTRO TO ' ||
                         V_COURSE_DESCRIPTION || ' ' ||
                         V_GRADE_POINT || ' ' ||
                         V_GRADE);
    DBMS_OUTPUT.PUT_LINE('Total Credits:' || V_SUM_COURSE_CREDITS);
    DBMS_OUTPUT.PUT_LINE('Overall GPA:' || V_GPA);

  END LOOP;
  CLOSE STUDENT_CURSOR;

  DBMS_OUTPUT.PUT_LINE('GRAND TOTAL VALUE OF ALL ITEMS:' || V_TOTAL_CREDITS);

END;


问:
What is the best way to count page views in PHP/MySQL?
And by best I mean most efficient, right now placing this on my post.php file is the only thing I can think of:

```<code>$query = mysql_query(" UPDATE posts SET views + 1 WHERE id = '$id' ");
</code>```

is there a better way, a method that would consume less server resources. I ask because if this was a small app I would have no problem with the above, but I am trying to build something that will be used by a lot of people and I want to be as query conscious as possible.

答:
If memcache is an option in your server environment, here's another cool way to sample, but also keep up with the precise number (unlike my other answer):

```<code>function recordPostPageView($page_id) {
    $memcache = new Memcached(); // you could also pull this instance from somewhere else, if you want a bit more efficiency*

    $key = "Counter for Post {$page_id}";

    if(!$memcache->get($key)) {
        $memcache->set($key, 0);
    }

    $new_count = $memcache->increment($key);

    // you could uncomment the following if you still want to notify mysql of the value occasionally
    /*
    $notify_mysql_interval = 100;
    if($new_count % $notify_mysql_interval == 0) {
        $query = mysql_query("UPDATE posts SET views = {$new_count} WHERE id = '{$page_id}' ");
        // execute query, etc
    }
    */

    return $new_count;
}
</code>```

And don't mind purists crying foul about Singletons.  Or you could pass it into this function, if you're more purist than pragmatist :)

Body:
And by best I mean most efficient, right now placing this on my post.php file is the only thing I can think of:

$query = mysql_query(" UPDATE posts SET views + 1 WHERE id = '$id' ");

is there a better way, a method that would consume less server resources. I ask because if this was a small app I would have no problem with the above, but I am trying to build something that will be used by a lot of people and I want to be as query conscious as possible.

Body:
If memcache is an option in your server environment, here's another cool way to sample, but also keep up with the precise number (unlike my other answer):

function recordPostPageView($page_id) {
    $memcache = new Memcached(); // you could also pull this instance from somewhere else, if you want a bit more efficiency*

    $key = "Counter for Post {$page_id}";

    if(!$memcache->get($key)) {
        $memcache->set($key, 0);
    }

    $new_count = $memcache->increment($key);

    // you could uncomment the following if you still want to notify mysql of the value occasionally
    /*
    $notify_mysql_interval = 100;
    if($new_count % $notify_mysql_interval == 0) {
        $query = mysql_query("UPDATE posts SET views = {$new_count} WHERE id = '{$page_id}' ");
        // execute query, etc
    }
    */

    return $new_count;
}

And don't mind purists crying foul about Singletons.  Or you could pass it into this function, if you're more purist than pragmatist :)


问:
POST call in Mulesoft
I am trying to make a HTTPS POST call in mulesoft to an external API. I had read in the mulesoft documentation and also in other posts that in order to send the request body, a map has to be prepared.
Hence, i am using the "Set-Payload" to prepare a map.
Eg: #[{'key':'value'}]
When I am using the logger to display it, it prints a map (as expected).
But when the POST call is being made, i am receiving the following error:

Response code 503 mapped as failure. Message payload is of type: BufferInputStream

Payload : org.glassfish.grizzly.utils.BufferInputStream@3f8f77a

Could anyone let me know where am i going wrong?

Thanks in Advance.

答:
Status code 503 implies that the server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay.
Please try resending the message or hit the API with Postman.</p>

Title: POST call in Mulesoft


问:
AbsoluteUri need to return correct path
Using method bellow in my MVC view I am getting URL like "localhost:54871/Home/Index" but I don't want "Index" on last. It should be only "localhost:54871/Home". How should I implement this?

```<code>@(Request.Url.AbsoluteUri)
</code>```

Thank you for your help!

答:
You can try the below one.

For Example if the url with parameters are like below

```<code>http://localhost:61221/Websitetest/Default1.aspx?QueryString1=1&QueryString2=2
</code>```

Then by using the below code you can get the results

```<code>HttpContext.Current.Request.Url.Host
HttpContext.Current.Request.Url.Authority
HttpContext.Current.Request.Url.Port
HttpContext.Current.Request.Url.AbsolutePath
HttpContext.Current.Request.ApplicationPath
HttpContext.Current.Request.Url.AbsoluteUri
HttpContext.Current.Request.Url.PathAndQuery
</code>```

will provide the output like below

OUTPUT

```<code>localhost
localhost:61221
61221
/Websitetest/Default1.aspx
/Websitetest
http://localhost:61221/Websitetest/Default1.aspx?QueryString1=1&QueryString1=2
/Websitetest/Default1.aspx?QueryString1=1&QueryString2=2
</code>```

Title: AbsoluteUri need to return correct path

Body:
Using method bellow in my MVC view I am getting URL like "localhost:54871/Home/Index" but I don't want "Index" on last. It should be only "localhost:54871/Home". How should I implement this?

@(Request.Url.AbsoluteUri)

Thank you for your help!

Body:
You can try the below one.

For Example if the url with parameters are like below

http://localhost:61221/Websitetest/Default1.aspx?QueryString1=1&QueryString2=2

Then by using the below code you can get the results

HttpContext.Current.Request.Url.Host
HttpContext.Current.Request.Url.Authority
HttpContext.Current.Request.Url.Port
HttpContext.Current.Request.Url.AbsolutePath
HttpContext.Current.Request.ApplicationPath
HttpContext.Current.Request.Url.AbsoluteUri
HttpContext.Current.Request.Url.PathAndQuery

will provide the output like below

OUTPUT

localhost
localhost:61221
61221
/Websitetest/Default1.aspx
/Websitetest
http://localhost:61221/Websitetest/Default1.aspx?QueryString1=1&QueryString1=2
/Websitetest/Default1.aspx?QueryString1=1&QueryString2=2


问:
Edit button not found on gerrit
My gerrit version is 2.10, java is 1.8. When I open my commit, the files are shown but there is no "Edit" button. Then click the committed files, there still none 'Edit' button. Should I make some special configuration?</p>

答: Inline Editing was added as a new feature in Gerrit 2.11, see its Release Notes. The version 2.10 that you're running is very outdated.</p>

Title: Edit button not found on gerrit


问:
Defining an Entity Framework 1:1 association
I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model.
When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of the two tables but then I am forced to choose a column from that table (or view) for each end of the relationship. I would expect to be able to choose a column from one table for one end of the association and a column from the other table for the other end of the association, but there's no way to do this.

Here I've chosen to map to the "DW_ WF_ClaimInfo" view and it is forcing me to choose two columns from that view - one for each end of the relationship.

I've also tried defining the mapping manually in the XML as follows:

```<code><AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
     StoreEntitySet="Entity1">
  <EndProperty Name="Entity2">
    <ScalarProperty Name="DOCUMENT" ColumnName="DOCUMENT" />
  </EndProperty>
  <EndProperty Name="Entity1">
    <ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
  </EndProperty>
</AssociationSetMapping>
</code>```

But this gives:
Error 2010: The Column 'DOCUMENT' specified as part of this MSL does not exist in MetadataWorkspace.
Seems like it still expects both columns to come from the same table, which doesn't make sense to me.

Furthermore, if I select the same key for each end, e.g.:

```<code><AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
     StoreEntitySet="Entity1">
  <EndProperty Name="Entity2">
    <ScalarProperty Name="DOCUMENT" ColumnName="PK_DocumentId" />
  </EndProperty>
  <EndProperty Name="Entity1">
    <ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
  </EndProperty>
</AssociationSetMapping>
</code>```

I then get:

```<code>Error 3021: Problem in Mapping Fragment starting at line 675: Each of the following
columns in table AssignedClaims is mapped to multiple conceptual side properties:
  AssignedClaims.PK_DocumentId is mapped to
    <AssignedClaimDW_WF_ClaimInfo.DW_WF_ClaimInfo.DOCUMENT,
    AssignedClaimDW_WF_ClaimInfo.AssignedClaim.PK_DocumentId>
</code>```

What am I not getting?

答:
You have to select the table, that cotains the foreign key. The next step is to remove that foreign key from the entity, as it is already expressed using the relation you just created.

Example:

```<code>table A
-------
A_ID int
B_ID int

table B
-------
B_ID int
</code>```

In this case, you would select the table A in the designer, as it contains the foreign key. Also you'll need to remove B_ID from the A entity afterwards.

OwnerDisplayName: Craig Fisher

Body:
I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model.
When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of the two tables but then I am forced to choose a column from that table (or view) for each end of the relationship. I would expect to be able to choose a column from one table for one end of the association and a column from the other table for the other end of the association, but there's no way to do this.

Here I've chosen to map to the "DW_ WF_ClaimInfo" view and it is forcing me to choose two columns from that view - one for each end of the relationship.

I've also tried defining the mapping manually in the XML as follows:

<AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
     StoreEntitySet="Entity1">
  <EndProperty Name="Entity2">
    <ScalarProperty Name="DOCUMENT" ColumnName="DOCUMENT" />
  </EndProperty>
  <EndProperty Name="Entity1">
    <ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
  </EndProperty>
</AssociationSetMapping>

But this gives:
Error 2010: The Column 'DOCUMENT' specified as part of this MSL does not exist in MetadataWorkspace.
Seems like it still expects both columns to come from the same table, which doesn't make sense to me.

Furthermore, if I select the same key for each end, e.g.:

<AssociationSetMapping Name="Entity1Entity2" TypeName="ClaimsModel.Entity1Entity2"
     StoreEntitySet="Entity1">
  <EndProperty Name="Entity2">
    <ScalarProperty Name="DOCUMENT" ColumnName="PK_DocumentId" />
  </EndProperty>
  <EndProperty Name="Entity1">
    <ScalarProperty Name="PK_DocumentId" ColumnName="PK_DocumentId" />
  </EndProperty>
</AssociationSetMapping>

I then get:

Error 3021: Problem in Mapping Fragment starting at line 675: Each of the following
columns in table AssignedClaims is mapped to multiple conceptual side properties:
  AssignedClaims.PK_DocumentId is mapped to
    <AssignedClaimDW_WF_ClaimInfo.DW_WF_ClaimInfo.DOCUMENT,
    AssignedClaimDW_WF_ClaimInfo.AssignedClaim.PK_DocumentId>

What am I not getting?

LastEditorDisplayName: Craig Fisher

Body:
You have to select the table, that cotains the foreign key. The next step is to remove that foreign key from the entity, as it is already expressed using the relation you just created.

Example:

table A
-------
A_ID int
B_ID int

table B
-------
B_ID int

In this case, you would select the table A in the designer, as it contains the foreign key. Also you'll need to remove B_ID from the A entity afterwards.

OwnerDisplayName: driAn


问:
spring web, security + web.xml + mvc dispatcher + Bean is created twice
I have the Web.xml as below:

```<code> <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/api/secure/*</url-pattern>
</filter-mapping>
</code>```

[Edit]

After I added the spring security, then I get the error!

java.lang.IllegalStateException: No WebApplicationContext found:  no
  ContextLoaderListener registered?

then I added

```<code> <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/mvc-dispatcher-servlet.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</code>```

then it seems working fine, but then
1) The problem is the bean are created twice!

if I only remove that:

```<code><context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/mvc-dispatcher-servlet.xml
    </param-value>
</context-param>
</code>```

but leave the <listener> then the web application doesn't run at all

[Extra]

The full Web.xml is below:

```<code><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/api/secure/*</url-pattern>
    </filter-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/mvc-dispatcher-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>
</code>```

here is my mvc-dispatcher-servlet.xml

```<code><beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <mvc:annotation-driven/>
    <context:annotation-config/>
    <context:component-scan base-package="com.ge.wtracker"/>
    <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!--Java Persistence API config-->
    <jpa:repositories base-package="com.ge.wtracker.repository"/>

    <!--JPA and Database Config-->
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="defaultPersistenceUnit"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <property name="testWhileIdle" value="true"/>
        <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
        <property name="numTestsPerEvictionRun" value="3"/>
        <property name="minEvictableIdleTimeMillis" value="1800000"/>
        <property name="validationQuery" value="SELECT 1"/>
    </bean>

    <!--Spring Security-->
    <security:http create-session="stateless" entry-point-ref="restAuthenticationEntryPoint" authentication-manager-ref="authenticationManager">
        <security:intercept-url pattern="/api/secure/**" access="ROLE_USER" />
        <security:custom-filter ref="customRestFilter" position="BASIC_AUTH_FILTER" />
    </security:http>
    <!-- Configures the authentication entry point that returns HTTP status code 401 -->
    <bean id="restAuthenticationEntryPoint" class="com.ge.wtracker.web.security.RestAuthenticationEntryPoint">
        <property name="realmName" value="Not Authorized" />
    </bean>
    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider ref="restAuthenticationProvider" />
    </security:authentication-manager>

    <!--The customRestFilter responsibles for retrieving and manipulating any request data to pass to the authentication
        provider to authenticate.-->
    <bean id="customRestFilter" class="com.ge.wtracker.web.security.RestSecurityFilter">
        <constructor-arg name="authenticationManager" ref="authenticationManager" />
        <constructor-arg name="authenticationEntryPoint" ref="restAuthenticationEntryPoint" />
    </bean>
    <bean id="restAuthenticationProvider" class="com.ge.wtracker.web.security.RestAuthenticationProvider" />

</beans>
</code>```

答:
Spring MVC then create a new any-name.xml and place context specific beans like
Spring-security.xml and  for your security  bean to load.

New xml will be like this

```<code><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">

 <mvc:annotation-driven/>
  <context:component-scan base-package="com"/>
<task:annotation-driven/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.
config.PropertyPlaceholderConfigurer">
 <property name="location" value=""/>
    <property name="locations">
           <list>
               <value>/WEB-INF/jdbc.properties</value>
           </list>
        </property>
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.databaseurl}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
</bean>
</beans>
</code>```

and now include this in web.xml

```<code>  <context-param>
   <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/login-security.xml,
      /WEB-INF/application-context.xml
   </param-value>
 </context-param>
</code>```

hope this will help you.

Body:
I have the Web.xml as below:

 <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/api/secure/*</url-pattern>
</filter-mapping>

[Edit]

After I added the spring security, then I get the error!

java.lang.IllegalStateException: No WebApplicationContext found:  no
  ContextLoaderListener registered?

then I added

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/mvc-dispatcher-servlet.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

then it seems working fine, but then
1) The problem is the bean are created twice!

if I only remove that:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/mvc-dispatcher-servlet.xml
    </param-value>
</context-param>

but leave the <listener> then the web application doesn't run at all

[Extra]

The full Web.xml is below:

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/api/secure/*</url-pattern>
    </filter-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/mvc-dispatcher-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

</web-app>

here is my mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
                            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <mvc:annotation-driven/>
    <context:annotation-config/>
    <context:component-scan base-package="com.ge.wtracker"/>
    <context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <jpa:repositories base-package="com.ge.wtracker.repository"/>

    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="defaultPersistenceUnit"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
        <property name="testOnBorrow" value="true"/>
        <property name="testOnReturn" value="true"/>
        <property name="testWhileIdle" value="true"/>
        <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
        <property name="numTestsPerEvictionRun" value="3"/>
        <property name="minEvictableIdleTimeMillis" value="1800000"/>
        <property name="validationQuery" value="SELECT 1"/>
    </bean>

    <security:http create-session="stateless" entry-point-ref="restAuthenticationEntryPoint" authentication-manager-ref="authenticationManager">
        <security:intercept-url pattern="/api/secure/**" access="ROLE_USER" />
        <security:custom-filter ref="customRestFilter" position="BASIC_AUTH_FILTER" />
    </security:http>

    <bean id="restAuthenticationEntryPoint" class="com.ge.wtracker.web.security.RestAuthenticationEntryPoint">
        <property name="realmName" value="Not Authorized" />
    </bean>
    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider ref="restAuthenticationProvider" />
    </security:authentication-manager>

    <bean id="customRestFilter" class="com.ge.wtracker.web.security.RestSecurityFilter">
        <constructor-arg name="authenticationManager" ref="authenticationManager" />
        <constructor-arg name="authenticationEntryPoint" ref="restAuthenticationEntryPoint" />
    </bean>
    <bean id="restAuthenticationProvider" class="com.ge.wtracker.web.security.RestAuthenticationProvider" />

</beans>

Body:
Spring MVC then create a new any-name.xml and place context specific beans like
Spring-security.xml and  for your security  bean to load.

New xml will be like this

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">

 <mvc:annotation-driven/>
  <context:component-scan base-package="com"/>
<task:annotation-driven/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.
config.PropertyPlaceholderConfigurer">
 <property name="location" value=""/>
    <property name="locations">
           <list>
               <value>/WEB-INF/jdbc.properties</value>
           </list>
        </property>
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.databaseurl}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
</bean>
</beans>

and now include this in web.xml

  <context-param>
   <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/login-security.xml,
      /WEB-INF/application-context.xml
   </param-value>
 </context-param>

hope this will help you.