问:
How to efficiently get paged query results for a date range
Just starting out with NoSql in general and DynamodB in particular, and I've been asked the following question:

There is an existing table with a large number of rows with fields something like:

```<code>RecordId (Guid = partition key)
RecordType (Guid = sort key)
UserId (Guid)
CreationDateTime
... and some other attributes ...
</code>```

There is also a GSI (say GSI1) with:

```<code>UserId = partition key
RecordType = sort key
</code>```

Some users generate a large number of rows with the same RecordType (maybe hundreds or thousands per day), so this index typically has a large number of rows with the same UserId+RecordType.

I want to be able to efficiently execute a paged query for results that match a specific UserId+RecordType, and have a CreationDateTime within a range of dates.

What's the best way to achieve this?

It's been suggested to me that I can create a second GSI (say GSI2) with partitionKey = Userid and Sort key = CreationDateTime.  The idea being that this would be an efficient way to find the first row for UserId+RecordType that is in the required date range, and that then this would be used as a starting point (PaginationToken) for searching in GSI1.  Which would only work if the rows in GSI1 with a duplicate key are stored in order of creation.

Does this make sense?  And if not, what would be a better approach?

答:
if your query is: "specific UserId+RecordType, and  CreationDateTime range"
so you answered to yourself:

create GSI:

hash = UserId_RecordType (1234_type1)

range = CreationDateTime

in this way you can get all docs for user with RecordType, sorted by CreationDateTime

be careful with hot keys.

Body:
Just starting out with NoSql in general and DynamodB in particular, and I've been asked the following question:

There is an existing table with a large number of rows with fields something like:

RecordId (Guid = partition key)
RecordType (Guid = sort key)
UserId (Guid)
CreationDateTime
... and some other attributes ...

There is also a GSI (say GSI1) with:

UserId = partition key
RecordType = sort key

Some users generate a large number of rows with the same RecordType (maybe hundreds or thousands per day), so this index typically has a large number of rows with the same UserId+RecordType.

I want to be able to efficiently execute a paged query for results that match a specific UserId+RecordType, and have a CreationDateTime within a range of dates.

What's the best way to achieve this?

It's been suggested to me that I can create a second GSI (say GSI2) with partitionKey = Userid and Sort key = CreationDateTime.  The idea being that this would be an efficient way to find the first row for UserId+RecordType that is in the required date range, and that then this would be used as a starting point (PaginationToken) for searching in GSI1.  Which would only work if the rows in GSI1 with a duplicate key are stored in order of creation.

Does this make sense?  And if not, what would be a better approach?


来源: stackexchange

问:
Putting two async subscriptions in one Angular *ngIf statement
I have the following in my component template:

...

Within the above div I would like to use the async pipe to subscribe to another observable only once, and use it just like user above throughout the template. So for instance, would something like this be possible:

<ng-template *ngIf="language$ | async as language>

All template code that would use both {{user}} and {{language}} would go in between

</ng-template>```

Or can this even be combined in one statement?

答:
The problem with using "object as variable" is that it doesn't have the same behavior as the code in the question (plus it's a mild abuse of *ngIf to have it always evaluate to true). To get the desired behavior you need:</p>

```<code><div *ngIf="{ language: language$ | async, user: user$ | async } as userLanguage">
   <ng-container *ngIf="userLanguage.language && userLanguage.user">
      <b>{{userLanguage.language}}</b> and <b>{{userLanguage.user}}</b>
   </ng-container>
</div>
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have the following in my component template:

...

Within the above div I would like to use the async pipe to subscribe to another observable only once, and use it just like user above throughout the template. So for instance, would something like this be possible:

<ng-template *ngIf="language$ | async as language>

All template code that would use both {{user}} and {{language}} would go in between

</ng-template>

Or can this even be combined in one statement?

Body:
The problem with using "object as variable" is that it doesn't have the same behavior as the code in the question (plus it's a mild abuse of *ngIf to have it always evaluate to true). To get the desired behavior you need:

<div *ngIf="{ language: language$ | async, user: user$ | async } as userLanguage">
   <ng-container *ngIf="userLanguage.language && userLanguage.user">
      <b>{{userLanguage.language}}</b> and <b>{{userLanguage.user}}</b>
   </ng-container>
</div>


问:
Images not filling wrapper
 elements

The Problem:

So I have this webpage: http://a.yfrog.com/img610/3543/p4.png

I have several images that are layered together to create the background gradient, but for whatever reason, the two side gradients aren't filling the entire page. All the gradients are in  elements that wrap the entire page. If I set the overflow of one of the divs to overflow:auto; I can scroll that div to the length of the page (which I set to 5000px for testing) but its only in the box where you see that little cutoff, and as far as I can tell, it does this in all browsers. What's the issue? And for further clarification, I'm talking about how the gradients on the sides suddenly stop.

CSS:

```<code>#super_wrapper { height:100%; }
#page_bg_top {
  background:url(../images/body/top_shadow.png) repeat-x top;
  height:400px;
}
#page_bg_topleft {
  background:url(../images/body/top_left.png) no-repeat top left;
  height:300px;
}
#page_bg_topright {
  background:url(../images/body/top_right.png) no-repeat top right;
  height:300px;
}
#page_bg_left {
  background:url(../images/body/left_shadow.png) repeat-y left;
  height:100%;
}
#page_bg_right {
  background:url(../images/body/right_shadow.png) repeat-y right;
  height:100%;
}
</code>```

HTML:

```<code><div id="super_wrapper"><div id="page_bg_top"><div id="page_bg_topleft"><div id="page_bg_topright"><div id="page_bg_left"><div id="page_bg_right">
... Page Body
</div></div></div></div></div></div>
</code>```

答:
First of all, it's recommended to use less divs in your markup and there are more efficient ways to achieve the look you want, but you will learn that with time and practice.

First of all, if you want those gradient shadows on left and right to span the height of the document you need the divs that have those background images to be on the outside of everything except the wrapper.

So here is the correct markup:

```<code><div id="super_wrapper">
    <div id="page_bg_left">
        <div id="page_bg_right">
            <div id="page_bg_top">
                <div id="page_bg_topleft">
                    <div id="page_bg_topright">

                    ... Page Body
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</code>```

Next you need to give those two divs "overflow: hidden" in order to cause the backgrounds to repeat to the full height of the contained child divs.

Like this:

```<code>#page_bg_left {
  background:url(../images/body/left_shadow.png) repeat-y left;
  height:100%;
  overflow: hidden;
}
#page_bg_right {
  background:url(../images/body/right_shadow.png) repeat-y right;
  height:100%;
  overflow: hidden;
}
</code>```

ContentLicense: CC BY-SA 2.5

Title: Images not filling wrapper <div> elements

Body:
The Problem:

So I have this webpage: http://a.yfrog.com/img610/3543/p4.png

I have several images that are layered together to create the background gradient, but for whatever reason, the two side gradients aren't filling the entire page. All the gradients are in  elements that wrap the entire page. If I set the overflow of one of the divs to overflow:auto; I can scroll that div to the length of the page (which I set to 5000px for testing) but its only in the box where you see that little cutoff, and as far as I can tell, it does this in all browsers. What's the issue? And for further clarification, I'm talking about how the gradients on the sides suddenly stop.

CSS:

#super_wrapper { height:100%; }
#page_bg_top {
  background:url(../images/body/top_shadow.png) repeat-x top;
  height:400px;
}
#page_bg_topleft {
  background:url(../images/body/top_left.png) no-repeat top left;
  height:300px;
}
#page_bg_topright {
  background:url(../images/body/top_right.png) no-repeat top right;
  height:300px;
}
#page_bg_left {
  background:url(../images/body/left_shadow.png) repeat-y left;
  height:100%;
}
#page_bg_right {
  background:url(../images/body/right_shadow.png) repeat-y right;
  height:100%;
}

HTML:

... Page Body

Body:
First of all, it's recommended to use less divs in your markup and there are more efficient ways to achieve the look you want, but you will learn that with time and practice.

First of all, if you want those gradient shadows on left and right to span the height of the document you need the divs that have those background images to be on the outside of everything except the wrapper.

So here is the correct markup:

<div id="super_wrapper">
    <div id="page_bg_left">
        <div id="page_bg_right">
            <div id="page_bg_top">
                <div id="page_bg_topleft">
                    <div id="page_bg_topright">

                    ... Page Body
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Next you need to give those two divs "overflow: hidden" in order to cause the backgrounds to repeat to the full height of the contained child divs.

Like this:

#page_bg_left {
  background:url(../images/body/left_shadow.png) repeat-y left;
  height:100%;
  overflow: hidden;
}
#page_bg_right {
  background:url(../images/body/right_shadow.png) repeat-y right;
  height:100%;
  overflow: hidden;
}


问:
Get mailchimp form on one line with CSS
I am trying to get my mailchimp embed form all on one line, the call to signup, the input field and the submit button. I have tried following this answer here: https://codepen.io/pageaffairs/pen/JDrhG Tweaked a few things but still all in the middle and stacked on top of each other. http://theinvicto.com/

Tried changing the "clear: left" to "clear:none" and centered the form with text-align but still not on the same line. Would I use table for this?

HTML:

   #mc_embed_signup{background:#50B1C5; clear:none; }

    #mc-embedded-subscribe-form.validate {
        background: #50B1C5;
    }

    #mc_embed_signup #mce-EMAIL {
        border: 3px solid #F3A733;
    }

    input#mc-embedded-subscribe.button {
    background-color: #F3A733;
    font-family: ‘Abel’;
    }

    *, *:before, *:after {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
     #mc_embed_signup{ clear:none; font:18px Abel,Arial,sans-serif; vertical-align: middle; width: 100%; margin: 0 auto;}
     #mc_embed_signup form {display:block; position:relative; text-align:center;}
     #mc_embed_signup input {border:3px solid #F3A733; -webkit-appearance:none;}
     #mc_embed_signup input:focus {border-color:#333;}
     #mc_embed_signup .button {background-color: #F3A733; border: 0 none; border-radius:4px; color: #FFFFFF; cursor: pointer; display: inline-block; font-size:15px; height: 32px; line-height: 32px; margin: 0 5px 10px 0; padding:0; text-align: center; text-decoration: none; vertical-align: top; white-space: nowrap; width: auto;}
     #mc_embed_signup .button:hover {background-color:#EB7162;}
     #mc_embed_signup .small-meta {font-size: 11px;}
     #mc_embed_signup .nowrap {white-space:nowrap;}
     #mc_embed_signup .clear {clear:none; display: inline-block; width: 31%; vertical-align: top;}

     #mc_embed_signup label {display:inline-block; font-size:16px; padding-bottom:10px; font-weight:bold; width: 70%;vertical-align: top;}
     #mc_embed_signup input.email {display:inline-block; padding:8px 0; margin:0 10px 10px 0; text-indent:5px; width:34%;vertical-align: top;}
     #mc_embed_signup input.button {display:block; width:100%; margin:0 0 10px 0;}

     @media screen and (max-width: 780px) {
      #mc_embed_signup {width: 100%;}
      #mc_embed_signup label, #mc_embed_signup input.email, #mc_embed_signup .clear {display: block; width: 100%;}
     }```
<pre class="snippet-code-html lang-html prettyprint-override"><code> <!-- Begin MailChimp Signup Form -->
    <div id="mc_embed_signup">
    <form action="https://theinvicto.us17.list-manage.com/subscribe/post?u=197c4c27bd3b031b5957c0035&id=0d6f057689" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <div id="mc_embed_signup_scroll">
     <label for="mce-EMAIL"><span style="font-size: 35px;">be the first to know:</span></label>
     <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
        <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
        <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_197c4c27bd3b031b5957c0035_0d6f057689" tabindex="-1" value=""></div>
        <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
        </div>
    </form>
</div>

    <!--End mc_embed_signup-->

 </code>```

Let me know if anyone has had luck with something else. I'm learning and trying to troubleshoot but have finally decided to ask where I've gone wrong. Thinking maybe it's a display: table thing but I could be so wrong, hah.

答:
No need to use a table for this. To put the button on the same line, you can simply use this:

```<code>.clear {
    display: inline-block;
}
</code>```

The
 with the class "clear" displays as block by default, and since it contains the subscribe button, it will display on a new line. So changing it to inline-block will allow it to move to the same line.

However, looking at the source for your website, you've also got
 and
 tags between form elements, so those would have to be removed for this to work. Alternatively, you can just hide them using the following style:

```<code>#mc_embed_signup_scroll p,
#mc_embed_signup_scroll br {
    display: none;
}
</code>```

Hope this helps!

Title: Get mailchimp form on one line with CSS

Body:
I am trying to get my mailchimp embed form all on one line, the call to signup, the input field and the submit button. I have tried following this answer here: https://codepen.io/pageaffairs/pen/JDrhG Tweaked a few things but still all in the middle and stacked on top of each other. http://theinvicto.com/

Tried changing the "clear: left" to "clear:none" and centered the form with text-align but still not on the same line. Would I use table for this?

HTML:

   #mc_embed_signup{background:#50B1C5; clear:none; }

    #mc-embedded-subscribe-form.validate {
        background: #50B1C5;
    }

    #mc_embed_signup #mce-EMAIL {
        border: 3px solid #F3A733;
    }

    input#mc-embedded-subscribe.button {
    background-color: #F3A733;
    font-family: ‘Abel’;
    }

    *, *:before, *:after {-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
     #mc_embed_signup{ clear:none; font:18px Abel,Arial,sans-serif; vertical-align: middle; width: 100%; margin: 0 auto;}
     #mc_embed_signup form {display:block; position:relative; text-align:center;}
     #mc_embed_signup input {border:3px solid #F3A733; -webkit-appearance:none;}
     #mc_embed_signup input:focus {border-color:#333;}
     #mc_embed_signup .button {background-color: #F3A733; border: 0 none; border-radius:4px; color: #FFFFFF; cursor: pointer; display: inline-block; font-size:15px; height: 32px; line-height: 32px; margin: 0 5px 10px 0; padding:0; text-align: center; text-decoration: none; vertical-align: top; white-space: nowrap; width: auto;}
     #mc_embed_signup .button:hover {background-color:#EB7162;}
     #mc_embed_signup .small-meta {font-size: 11px;}
     #mc_embed_signup .nowrap {white-space:nowrap;}
     #mc_embed_signup .clear {clear:none; display: inline-block; width: 31%; vertical-align: top;}

     #mc_embed_signup label {display:inline-block; font-size:16px; padding-bottom:10px; font-weight:bold; width: 70%;vertical-align: top;}
     #mc_embed_signup input.email {display:inline-block; padding:8px 0; margin:0 10px 10px 0; text-indent:5px; width:34%;vertical-align: top;}
     #mc_embed_signup input.button {display:block; width:100%; margin:0 0 10px 0;}

     @media screen and (max-width: 780px) {
      #mc_embed_signup {width: 100%;}
      #mc_embed_signup label, #mc_embed_signup input.email, #mc_embed_signup .clear {display: block; width: 100%;}
     }

    <form action="https://theinvicto.us17.list-manage.com/subscribe/post?u=197c4c27bd3b031b5957c0035&id=0d6f057689" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>

     be the first to know:
     <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>

<input type="text" name="b_197c4c27bd3b031b5957c0035_0d6f057689" tabindex="-1" value="">

<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">

    </form>

Let me know if anyone has had luck with something else. I'm learning and trying to troubleshoot but have finally decided to ask where I've gone wrong. Thinking maybe it's a display: table thing but I could be so wrong, hah.

Body:
No need to use a table for this. To put the button on the same line, you can simply use this:

.clear {
    display: inline-block;
}

The <div> with the class "clear" displays as block by default, and since it contains the subscribe button, it will display on a new line. So changing it to inline-block will allow it to move to the same line.

However, looking at the source for your website, you've also got <br> and <p> tags between form elements, so those would have to be removed for this to work. Alternatively, you can just hide them using the following style:

#mc_embed_signup_scroll p,
#mc_embed_signup_scroll br {
    display: none;
}

Hope this helps!


问:
Pyspark inverted index
I am creating an inverted index of documents, where the output should contain a word (from the text file) followed by all the files it appeared in. Something like

[word1: file1.txt file2.txt] [word2: file2.txt file3.txt]

I have written the code but it throws me this error.

for k, v in iterator:
  TypeError: () takes exactly 2 arguments (1 given)

Code:

```<code>from pyspark import SparkContext
sc = SparkContext("local", "app")

path = '/ebooks'
rdd = sc.wholeTextFiles(path)

output = rdd.flatMap(lambda (file,contents):contents.lower().split())\
            .map(lambda file,word: (word,file))\
            .reduceByKey(lambda a,b: a+b)
print output.take(10)
</code>```

I cannot figure out a way to emit both key and value (word and the filename) in the map. How can i go about it?

In mapreduce, the (word, key) pair can be emitted (key is the filename) but how can this be done in spark?

答:
cannot figure out a way to emit both key and value

Use flatMapValues:

```<code>rdd = sc.wholeTextFiles("README.md")

rdd.flatMapValues(lambda content: content.lower().split()).take(3)

# [('file:/spark/README.md', '#'),
#  ('file:/spark/README.md', 'apache'),
#  ('file:/spark/README.md', 'spark')]
</code>```

with flatMap you can:

```<code>rdd.flatMap(
    lambda fc: ((fc[0], s) for s in fc[1].lower().split()))

# [('file:/spark/README.md', '#'),
#  ('file:/spark/README.md', 'apache'),
#  ('file:/spark/README.md', 'spark')]
</code>```

Title: Pyspark inverted index

Body:
I am creating an inverted index of documents, where the output should contain a word (from the text file) followed by all the files it appeared in. Something like

[word1: file1.txt file2.txt] [word2: file2.txt file3.txt]

I have written the code but it throws me this error.

for k, v in iterator:
  TypeError: () takes exactly 2 arguments (1 given)

Code:

from pyspark import SparkContext
sc = SparkContext("local", "app")

path = '/ebooks'
rdd = sc.wholeTextFiles(path)

output = rdd.flatMap(lambda (file,contents):contents.lower().split())\
            .map(lambda file,word: (word,file))\
            .reduceByKey(lambda a,b: a+b)
print output.take(10)

I cannot figure out a way to emit both key and value (word and the filename) in the map. How can i go about it?

In mapreduce, the (word, key) pair can be emitted (key is the filename) but how can this be done in spark?

Body:
cannot figure out a way to emit both key and value

Use flatMapValues:

rdd = sc.wholeTextFiles("README.md")

rdd.flatMapValues(lambda content: content.lower().split()).take(3)

# [('file:/spark/README.md', '#'),
#  ('file:/spark/README.md', 'apache'),
#  ('file:/spark/README.md', 'spark')]

with flatMap you can:

rdd.flatMap(
    lambda fc: ((fc[0], s) for s in fc[1].lower().split()))

# [('file:/spark/README.md', '#'),
#  ('file:/spark/README.md', 'apache'),
#  ('file:/spark/README.md', 'spark')]


问:
App store submission error Invalid Bundle Structure
I am receiving the following error from XCode 8.1 when trying to submit a previously successful submitted app version upgrade:

ERROR ITMS-90171: "Invalid Bundle Structure - The binary file 'Particle.app/Particle_armv7' is not permitted. Your app can’t contain standalone executables or libraries, other than the CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at https://developer.apple.com/go/?id=bundle-structure for information on the iOS app bundle structure."

  ERROR ITMS-90171: "Invalid Bundle Structure - The binary file 'Particle.app/Particle_armv7' is not permitted. Your app can’t contain standalone executables or libraries, other than the CFBundleExecutable of supported bundles. Refer to the Bundle Programming Guide at https://developer.apple.com/go/?id=bundle-structure for information on the iOS app bundle structure."

I did not modify anything in regards to architectures this build.
Any idea where I should look to solve this problem?

答:
This error occurs when a static library file is mistakenly copied into the app bundle.

You should link the libYourLibrary.a static library via a Link Binary with Libraries build phase.

It should NOT be added to the target's Copy Bundle Resources build phase.


问:
React: render concatenated component based on imported list of components
I'm not sure if what I'm trying to do is even possible, or if there's a better way to accomplish my goal. Any insight would be massively helpful.

Context:

I have a directory full of components that render inline SVGs

These components are gathered in an IconsIndex.js file and are exported as such:

export { default as Rocket } from "./Rocket";

I am importing the index to have access to my icon library from any given component:

import * as Icon from "./icons/IconsIndex";

This allows me to essentially do: <Icon.Rocket /> which renders the SVG component perfectly.

What I'd like to do is be able to have the <Icon /> component be able to be more dynamic from parent components.

For example:

```<code>class ResourceBlock extends React.Component {
  render() {
    return (
      <BlockContainer>
        <BlockIcon>
          <Icon.Rocket />
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}
</code>```

This outputs the Rocket icon everywhere the ResourceBlock component is called. What I'd like to be able to do is something like this:

```<code><ResourceBlock icon={Icon.Rocket} caption="Lorem..." buttonText="..." />
</code>```

Is this possible? How can I achieve this level of flexibility with our icons?

The key is to keep the SVGs as decoupled as possible, so wrapping them all in an additional <Icon /> component isn't appealing.

答:
It's a little odd, but in JSX if the node name is lowercase it will be translated as an html tag, not a component reference. So just assign your icon property to an uppercase local const and render it that way:

```<code>class ResourceBlock extends React.Component {
  render() {
    const Icon = this.props.icon;
    return (
      <BlockContainer>
        <BlockIcon>
          <Icon />
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}
</code>```

Used just like you had it:

```<code><ResourceBlock icon={Icon.Rocket} caption="Lorem..." buttonText="..." />
</code>```

Body:
I'm not sure if what I'm trying to do is even possible, or if there's a better way to accomplish my goal. Any insight would be massively helpful.

Context:

I have a directory full of components that render inline SVGs

These components are gathered in an IconsIndex.js file and are exported as such:

export { default as Rocket } from "./Rocket";

I am importing the index to have access to my icon library from any given component:

import * as Icon from "./icons/IconsIndex";

This allows me to essentially do: <Icon.Rocket /> which renders the SVG component perfectly.

What I'd like to do is be able to have the <Icon /> component be able to be more dynamic from parent components.

For example:

class ResourceBlock extends React.Component {
  render() {
    return (
      <BlockContainer>
        <BlockIcon>
          <Icon.Rocket />
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}

This outputs the Rocket icon everywhere the ResourceBlock component is called. What I'd like to be able to do is something like this:

<ResourceBlock icon={Icon.Rocket} caption="Lorem..." buttonText="..." />

Is this possible? How can I achieve this level of flexibility with our icons?

The key is to keep the SVGs as decoupled as possible, so wrapping them all in an additional <Icon /> component isn't appealing.

Body:
It's a little odd, but in JSX if the node name is lowercase it will be translated as an html tag, not a component reference. So just assign your icon property to an uppercase local const and render it that way:

class ResourceBlock extends React.Component {
  render() {
    const Icon = this.props.icon;
    return (
      <BlockContainer>
        <BlockIcon>
          <Icon />
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}

Used just like you had it:

<ResourceBlock icon={Icon.Rocket} caption="Lorem..." buttonText="..." />


问:
Will MSSQL 2012 database work on MSSQL 2008 server?
I have MsSQL database which is created in MSSQL 2012 SQL server.

On my local machine I have installed MSSQL 2008 SQL server.

Will the 2012 database work in MSSQL 2008?

Also,I have installed MSSQL 2012 SQL server on my local system.Do I need to install MSSQL management studio for 2012 SQL server?

Is it required for user interface?

答:
Whether a 2012 database will work on a 2008R2 server depends.
If you are deploying to your 2008R2 server by running T-SQL scripts then it will only work if

The database objects used in your 2012 database were available in 2008R2

You are not using SQL2012 T-SQL enhancements in your scripts

Your scripts do not depend on system objects or views that were introduced in SQL2012

The local edition of SQL2008R2 is compatible with the SQL2012 edition.  For example SQL2008R2 Express will not like SQL2012 Enterprise Edition features.

Ideally you will be using the Developer Edition for your local instance as this is simply a throttled version of Enterprise Edition.

If you are trying to restore to 2008R2 from a 2012 backup then no, it won't work.

Given that SQL Management Studio is a free download why would you stick with the SQL2008R2 version?  If you have licenced SQL2012 then you are licenced for the SQL2012 version of SSMS.  Why not go the whole hog and install SSMS for SQL2017?

If you do not like SMSS then a paid for alternative might be Aquafold Data Studio.  This has the advantage of supporting many database platforms from a single IDE.


答:
Sure:</p>

```<code><ResourceBlock icon={<Icon.Rocket />} caption="Lorem..." buttonText="..." />

class ResourceBlock extends React.Component {
  render() {
    return (
      <BlockContainer>
        <BlockIcon>
          {this.props.icon}
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}
</code>```

Title: React: render concatenated component based on imported list of components

Body:
Sure:

<ResourceBlock icon={<Icon.Rocket />} caption="Lorem..." buttonText="..." />

class ResourceBlock extends React.Component {
  render() {
    return (
      <BlockContainer>
        <BlockIcon>
          {this.props.icon}
        </BlockIcon>
        <BlockTitle>{this.props.caption}</BlockTitle>
        <Button>{this.props.buttonText}</Button>
      </BlockContainer>
    );
  }
}


问:
jacaco unit test coverage reports path and file name(as jacaco.exec)
I am running following maven command on jenkins

clean org.jacoco:jacoco-maven-plugin:prepare-agent install

The jacaco exec file created as shown below.
target/coverage-reports/jacoco-int-test.exec

I would like to generate this file under following path, since all other Project use same conventions.
target/jacoco.exec

I could not figureout why it is generated in this way and how to modify it as "target/jacoco.exec"

I will use this report in sonarqube analysis.

I would appriciate your helps, thanks in advance.

答: As per documentation of prepare-agent - destFile parameter controls location of output file, whose default is ${project.build.directory}/jacoco.exec which is exactly target/jacoco.exe. So check your POMs to find where it is modified to be target/coverage-reports/jacoco-int-test.exec.


问:
Problem with PHP sessions
Update Solved problem!

After examining the code, the freaking problem was I was missing the }else{} after

```<code>header ('location:referraldone.php?say=blankfields');
}
</code>```

.

I'm really lost at the moment with this session code. I don't understand why the session isn't working. Where did I go wrong? I'm trying to take the data entered in the fields to the next page when someone makes an error not filling an required field. Codes are below:

```<code><?php

if (!$_POST['cname'] | !$_POST['cphone'] | !$_POST['caddress'] | !$_POST['ccity'] | !$_POST['cstate'] | !$_POST['czip'] | !$_POST['cbirthday']) {

$rname = $_REQUEST['rname'];
$rdate = $_REQUEST['rdate'];
$ragency = $_REQUEST['ragency'];
$rphone = $_REQUEST['rphone'];
$cname = $_REQUEST['cname'];
$cphone = $_REQUEST['cphone'];
$caddress = $_REQUEST['caddress'];
$ccity = $_REQUEST['ccity'];
$cstate = $_REQUEST['cstate'];
$czip = $_REQUEST['czip'];
$cbirthday = $_REQUEST['cbirthday'];
$medmemid = $_REQUEST['medmemid'];
$medclaim = $_REQUEST['medclaim'];
$marital = $_REQUEST['marital'];
$income = $_REQUEST['income'];
$gender = $_REQUEST['gender'];
$race = $_REQUEST['race'];
$caregiver = $_REQUEST['caregiver'];
$relationship = $_REQUEST['relationship'];
$memphone = $_REQUEST['memphone'];
$physician = $_REQUEST['physician'];
$phyphone = $_REQUEST['phyphone'];

session_start();
$_SESSION['rname'] = $rname;
$_SESSION['rdate'] = $rdate;
$_SESSION['ragency'] = $ragency;
$_SESSION['rphone'] = $rphone;
$_SESSION['cname'] = $cname;
$_SESSION['cphone'] = $cphone;
$_SESSION['caddress'] = $caddress;
$_SESSION['ccity'] = $ccity;
$_SESSION['cstate'] = $cstate;
$_SESSION['czip'] = $czip;
$_SESSION['cbirthday'] = $cbirthday;
$_SESSION['medmemid'] = $medmemid;
$_SESSION['medclaim'] = $medclaim;
$_SESSION['marital'] = $marital;
$_SESSION['income'] = $income;
$_SESSION['gender'] = $gender;
$_SESSION['race'] = $race;
$_SESSION['caregiver'] = $caregiver;
$_SESSION['relationship'] = $relationship;
$_SESSION['memphone'] = $memphone;
$_SESSION['physician'] = $physician;
$_SESSION['phyphone'] = $phyphone;

header ('location:referraldone.php?say=blankfields');
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table style="text-align:left; width: 500px; left:45px; position:relative; padding:2px; border:1px solid #1A1A1A">
    <tr>
        <td colspan="2" style="vertical-align:top; text-align:center; border:1px solid #1A1A1A; background-color:#A52A2A; color:#FFFFFF;">REFERRAL FORM</td>
    </tr>
    <tr>
    <td colspan="2"><center>Choose us as your Home Care Agency!<br />We provide services 24 hours per day, 7 days a week.<br /><br />Please submit form below and your respond time<br />will be 48 hours.<br /><br /><strong>*Bold Fields Required</strong><br /><br /></td>
    </tr>
    <tr>
        <td valign="top">Reffered By:<br /><input name="rname" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Reffered Date:<br /><input name="rdate" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Reffered Agency:<br /><input name="ragency" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="rphone" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Client Name:</strong><br /><input name="cname" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Phone:</strong><br /><input name="cphone" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Address:</strong><br /><input name="caddress" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* City:</strong><br /><input name="ccity" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* State:</strong><br /><input name="cstate" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Zip Code:</strong><br /><input name="czip" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Birthday:</strong><br /><input name="cbirthday" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Medicaid Member ID:<br /><input name="medmemid" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Medicare Claim:<br /><input name="medclaim" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Marital Status:<br /><input name="marital" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Monthly Income:<br /><input name="income" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Gender:<br /><input name="gender" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Race:<br /><input name="race" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Caregiver Name:<br /><input name="caregiver" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Relationship:<br /><input name="relationship" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="memphone" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Physician:<br /><input name="physician" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="phyphone" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top" style="color:#C00000"><br />Please make sure all the <strong>BOLD</strong> fields are completed before submitting form.<br /><br /></td>
    </tr>
    <tr>
        <td align="right"><input type="reset" value="Clear Fields"> <input type="submit" name="send" value="Send" /></td>
    </tr>
    </table>
</form>
</code>```

Here's the error page that should take the session data and fill the fields with it, but it doesn't:

```<code><?php
$sb = "5";

$say = $_REQUEST['say'];

$rname = $_SESSION['rname'];
$rdate = $_SESSION['rdate'];
$ragency = $_SESSION['ragency'];
$rphone = $_SESSION['rphone'];
$cname = $_SESSION['cname'];
$cphone = $_SESSION['cphone'];
$caddress = $_SESSION['caddress'];
$ccity = $_SESSION['ccity'];
$cstate = $_SESSION['cstate'];
$czip = $_SESSION['czip'];
$cbirthday = $_SESSION['cbirthday'];
$medmemid = $_SESSION['medmemid'];
$medclaim = $_SESSION['medclaim'];
$marital = $_SESSION['marital'];
$income = $_SESSION['income'];
$gender = $_SESSION['gender'];
$race = $_SESSION['race'];
$caregiver = $_SESSION['caregiver'];
$relationship = $_SESSION['relationship'];
$memphone = $_SESSION['memphone'];
$physician = $_SESSION['physician'];
$phyphone = $_SESSION['phyphone'];

if(isset($say)){
    switch ($say){
        case "formsent":
        $return = "Referral Form Sent. Your respond time will be 48 hours.";
        break;
        case "blankfields":
        $return = "All <strong>Bold</strong> Fields Required";
        break;
        default:
        break;
    }
}

if (isset($_POST['send'])) {

    if (!$_POST['cname'] | !$_POST['cphone'] | !$_POST['caddress'] | !$_POST['ccity'] | !$_POST['cstate'] | !$_POST['czip'] | !$_POST['cbirthday']) {

$rname = $_REQUEST['rname'];
$rdate = $_REQUEST['rdate'];
$ragency = $_REQUEST['ragency'];
$rphone = $_REQUEST['rphone'];
$cname = $_REQUEST['cname'];
$cphone = $_REQUEST['cphone'];
$caddress = $_REQUEST['caddress'];
$ccity = $_REQUEST['ccity'];
$cstate = $_REQUEST['cstate'];
$czip = $_REQUEST['czip'];
$cbirthday = $_REQUEST['cbirthday'];
$medmemid = $_REQUEST['medmemid'];
$medclaim = $_REQUEST['medclaim'];
$marital = $_REQUEST['marital'];
$income = $_REQUEST['income'];
$gender = $_REQUEST['gender'];
$race = $_REQUEST['race'];
$caregiver = $_REQUEST['caregiver'];
$relationship = $_REQUEST['relationship'];
$memphone = $_REQUEST['memphone'];
$physician = $_REQUEST['physician'];
$phyphone = $_REQUEST['phyphone'];

session_start();
$_SESSION['rname'] = $rname;
$_SESSION['rdate'] = $rdate;
$_SESSION['ragency'] = $ragency;
$_SESSION['rphone'] = $rphone;
$_SESSION['cname'] = $cname;
$_SESSION['cphone'] = $cphone;
$_SESSION['caddress'] = $caddress;
$_SESSION['ccity'] = $ccity;
$_SESSION['cstate'] = $cstate;
$_SESSION['czip'] = $czip;
$_SESSION['cbirthday'] = $cbirthday;
$_SESSION['medmemid'] = $medmemid;
$_SESSION['medclaim'] = $medclaim;
$_SESSION['marital'] = $marital;
$_SESSION['income'] = $income;
$_SESSION['gender'] = $gender;
$_SESSION['race'] = $race;
$_SESSION['caregiver'] = $caregiver;
$_SESSION['relationship'] = $relationship;
$_SESSION['memphone'] = $memphone;
$_SESSION['physician'] = $physician;
$_SESSION['phyphone'] = $phyphone;

header ('location:referraldone.php?say=blankfields');
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table style="text-align:left; width: 500px; left:45px; position:relative; padding:2px; border:1px solid #1A1A1A">
    <tr>
        <td colspan="2" style="vertical-align:top; text-align:center; border:1px solid #1A1A1A; background-color:#A52A2A; color:#FFFFFF;">REFERRAL FORM</td>
    </tr>
    <tr>
    <td colspan="2"><center>Choose us as your Home Care Agency!<br />We provide services 24 hours per day, 7 days a week.<br /><br />Please submit form below and your respond time<br />will be 48 hours.<br /><br /><strong>*Bold Fields Required</strong><br /><br /></td>
    </tr>
    <tr>
        <td valign="top">Reffered By:<br /><input name="rname" type="text" value="<?php echo $rname; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Reffered Date:<br /><input name="rdate" type="text" value="<?php echo $rdate; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Reffered Agency:<br /><input name="ragency" type="text" value="<?php echo $ragency; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="rphone" type="text" style=value="rphone" "width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Client Name:</strong><br /><input name="cname" type="text" value="<?php echo $cname; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Phone:</strong><br /><input name="cphone" type="text" value="<?php echo $cphone; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Address:</strong><br /><input name="caddress" type="text" value="<?php echo $caddress; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* City:</strong><br /><input name="ccity" type="text" value="<?php echo $ccity; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* State:</strong><br /><input name="cstate" type="text" value="<?php echo $cstate; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Zip Code:</strong><br /><input name="czip" type="text" value="<?php echo $czip; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br /><strong>* Birthday:</strong><br /><input name="cbirthday" type="text" value="<?php echo $cbirthday; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Medicaid Member ID:<br /><input name="medmemid" type="text" value="<?php echo $medmemid; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Medicare Claim:<br /><input name="medclaim" type="text" value="<?php echo $medclaim; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Marital Status:<br /><input name="marital" type="text" value="<?php echo $marital; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Monthly Income:<br /><input name="income" type="text" value="<?php echo $income; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Gender:<br /><input name="gender" type="text" value="<?php echo $gender; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Race:<br /><input name="race" type="text" value="<?php echo $race; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Caregiver Name:<br /><input name="caregiver" type="text" value="<?php echo $caregiver; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Relationship:<br /><input name="relationship" type="text" value="<?php echo $relationship; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="memphone" type="text" value="<?php echo $phone; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Physician:<br /><input name="physician" type="text" value="<?php echo $physician; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top"><br />Phone:<br /><input name="phyphone" type="text" value="<?php echo $phyphone; ?>" style="width:98%" /></td>
    </tr>
    <tr>
        <td valign="top" style="color:#C00000"><br />Please make sure all the <strong>BOLD</strong> fields are completed before submitting form.<br /><br /></td>
    </tr>
    <tr>
        <td align="right"><input type="reset" value="Clear Fields"> <input type="submit" name="send" value="Send" /></td>
    </tr>
    </table>
</form>
</code>```

答:
Okay, some rewriting help.

I would ultimately start by making a descriptive array of the field names and titles. This way you have a secure list of acceptable input fields and simplify the output later on.

```<code>$allowed_fields = array("
      "cname" => "* Client name",  // titles may include <b>HTML</b>
      "phone" => "PHone number",
      "caddress" => "Address",
      ...
");
</code>```

But to simplify the first script, you can replace the 50 lines of $_REQUEST input and $_SESSION filling with just:

```<code>session_start();
foreach ($_REQUEST as $field=>$value) {
    $_SESSION[$field] = $_REQUEST[$field];
}
</code>```

And all the form field output can be simplified this way:

```<code>foreach ($allowed_fields as $field=>$title) {
    ?><tr>
    <td valign="top"><?=$title?>:<br /><input name="<?=$field?>" type="text" value="<?=htmlspecialchars($_SESSION[$field])?>" style="width:98%" /></td>
    </tr><?php
}
</code>```

Title: Problem with PHP sessions

Body:
Update Solved problem!

After examining the code, the freaking problem was I was missing the }else{} after

header ('location:referraldone.php?say=blankfields');
}

.

I'm really lost at the moment with this session code. I don't understand why the session isn't working. Where did I go wrong? I'm trying to take the data entered in the fields to the next page when someone makes an error not filling an required field. Codes are below:

<?php

if (!$_POST['cname'] | !$_POST['cphone'] | !$_POST['caddress'] | !$_POST['ccity'] | !$_POST['cstate'] | !$_POST['czip'] | !$_POST['cbirthday']) {

$rname = $_REQUEST['rname'];
$rdate = $_REQUEST['rdate'];
$ragency = $_REQUEST['ragency'];
$rphone = $_REQUEST['rphone'];
$cname = $_REQUEST['cname'];
$cphone = $_REQUEST['cphone'];
$caddress = $_REQUEST['caddress'];
$ccity = $_REQUEST['ccity'];
$cstate = $_REQUEST['cstate'];
$czip = $_REQUEST['czip'];
$cbirthday = $_REQUEST['cbirthday'];
$medmemid = $_REQUEST['medmemid'];
$medclaim = $_REQUEST['medclaim'];
$marital = $_REQUEST['marital'];
$income = $_REQUEST['income'];
$gender = $_REQUEST['gender'];
$race = $_REQUEST['race'];
$caregiver = $_REQUEST['caregiver'];
$relationship = $_REQUEST['relationship'];
$memphone = $_REQUEST['memphone'];
$physician = $_REQUEST['physician'];
$phyphone = $_REQUEST['phyphone'];

session_start();
$_SESSION['rname'] = $rname;
$_SESSION['rdate'] = $rdate;
$_SESSION['ragency'] = $ragency;
$_SESSION['rphone'] = $rphone;
$_SESSION['cname'] = $cname;
$_SESSION['cphone'] = $cphone;
$_SESSION['caddress'] = $caddress;
$_SESSION['ccity'] = $ccity;
$_SESSION['cstate'] = $cstate;
$_SESSION['czip'] = $czip;
$_SESSION['cbirthday'] = $cbirthday;
$_SESSION['medmemid'] = $medmemid;
$_SESSION['medclaim'] = $medclaim;
$_SESSION['marital'] = $marital;
$_SESSION['income'] = $income;
$_SESSION['gender'] = $gender;
$_SESSION['race'] = $race;
$_SESSION['caregiver'] = $caregiver;
$_SESSION['relationship'] = $relationship;
$_SESSION['memphone'] = $memphone;
$_SESSION['physician'] = $physician;
$_SESSION['phyphone'] = $phyphone;

header ('location:referraldone.php?say=blankfields');
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

        REFERRAL FORM

    Choose us as your Home Care Agency!
We provide services 24 hours per day, 7 days a week.

Please submit form below and your respond time
will be 48 hours.

*Bold Fields Required

        Reffered By:
<input name="rname" type="text" style="width:98%" />

Reffered Date:
<input name="rdate" type="text" style="width:98%" />

Reffered Agency:
<input name="ragency" type="text" style="width:98%" />

Phone:
<input name="rphone" type="text" style="width:98%" />

* Client Name:
<input name="cname" type="text" style="width:98%" />

* Phone:
<input name="cphone" type="text" style="width:98%" />

* Address:
<input name="caddress" type="text" style="width:98%" />

* City:
<input name="ccity" type="text" style="width:98%" />

* State:
<input name="cstate" type="text" style="width:98%" />

* Zip Code:
<input name="czip" type="text" style="width:98%" />

* Birthday:
<input name="cbirthday" type="text" style="width:98%" />

Medicaid Member ID:
<input name="medmemid" type="text" style="width:98%" />

Medicare Claim:
<input name="medclaim" type="text" style="width:98%" />

Marital Status:
<input name="marital" type="text" style="width:98%" />

Monthly Income:
<input name="income" type="text" style="width:98%" />

Gender:
<input name="gender" type="text" style="width:98%" />

Race:
<input name="race" type="text" style="width:98%" />

Caregiver Name:
<input name="caregiver" type="text" style="width:98%" />

Relationship:
<input name="relationship" type="text" style="width:98%" />

Phone:
<input name="memphone" type="text" style="width:98%" />

Physician:
<input name="physician" type="text" style="width:98%" />

Phone:
<input name="phyphone" type="text" style="width:98%" />

Please make sure all the BOLD fields are completed before submitting form.

        <input type="reset" value="Clear Fields"> <input type="submit" name="send" value="Send" />

</form>

Here's the error page that should take the session data and fill the fields with it, but it doesn't:

<?php
$sb = "5";

$say = $_REQUEST['say'];

$rname = $_SESSION['rname'];
$rdate = $_SESSION['rdate'];
$ragency = $_SESSION['ragency'];
$rphone = $_SESSION['rphone'];
$cname = $_SESSION['cname'];
$cphone = $_SESSION['cphone'];
$caddress = $_SESSION['caddress'];
$ccity = $_SESSION['ccity'];
$cstate = $_SESSION['cstate'];
$czip = $_SESSION['czip'];
$cbirthday = $_SESSION['cbirthday'];
$medmemid = $_SESSION['medmemid'];
$medclaim = $_SESSION['medclaim'];
$marital = $_SESSION['marital'];
$income = $_SESSION['income'];
$gender = $_SESSION['gender'];
$race = $_SESSION['race'];
$caregiver = $_SESSION['caregiver'];
$relationship = $_SESSION['relationship'];
$memphone = $_SESSION['memphone'];
$physician = $_SESSION['physician'];
$phyphone = $_SESSION['phyphone'];

if(isset($say)){
    switch ($say){
        case "formsent":
        $return = "Referral Form Sent. Your respond time will be 48 hours.";
        break;
        case "blankfields":
        $return = "All Bold Fields Required";
        break;
        default:
        break;
    }
}

if (isset($_POST['send'])) {

    if (!$_POST['cname'] | !$_POST['cphone'] | !$_POST['caddress'] | !$_POST['ccity'] | !$_POST['cstate'] | !$_POST['czip'] | !$_POST['cbirthday']) {

$rname = $_REQUEST['rname'];
$rdate = $_REQUEST['rdate'];
$ragency = $_REQUEST['ragency'];
$rphone = $_REQUEST['rphone'];
$cname = $_REQUEST['cname'];
$cphone = $_REQUEST['cphone'];
$caddress = $_REQUEST['caddress'];
$ccity = $_REQUEST['ccity'];
$cstate = $_REQUEST['cstate'];
$czip = $_REQUEST['czip'];
$cbirthday = $_REQUEST['cbirthday'];
$medmemid = $_REQUEST['medmemid'];
$medclaim = $_REQUEST['medclaim'];
$marital = $_REQUEST['marital'];
$income = $_REQUEST['income'];
$gender = $_REQUEST['gender'];
$race = $_REQUEST['race'];
$caregiver = $_REQUEST['caregiver'];
$relationship = $_REQUEST['relationship'];
$memphone = $_REQUEST['memphone'];
$physician = $_REQUEST['physician'];
$phyphone = $_REQUEST['phyphone'];

session_start();
$_SESSION['rname'] = $rname;
$_SESSION['rdate'] = $rdate;
$_SESSION['ragency'] = $ragency;
$_SESSION['rphone'] = $rphone;
$_SESSION['cname'] = $cname;
$_SESSION['cphone'] = $cphone;
$_SESSION['caddress'] = $caddress;
$_SESSION['ccity'] = $ccity;
$_SESSION['cstate'] = $cstate;
$_SESSION['czip'] = $czip;
$_SESSION['cbirthday'] = $cbirthday;
$_SESSION['medmemid'] = $medmemid;
$_SESSION['medclaim'] = $medclaim;
$_SESSION['marital'] = $marital;
$_SESSION['income'] = $income;
$_SESSION['gender'] = $gender;
$_SESSION['race'] = $race;
$_SESSION['caregiver'] = $caregiver;
$_SESSION['relationship'] = $relationship;
$_SESSION['memphone'] = $memphone;
$_SESSION['physician'] = $physician;
$_SESSION['phyphone'] = $phyphone;

header ('location:referraldone.php?say=blankfields');
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

        REFERRAL FORM

    Choose us as your Home Care Agency!
We provide services 24 hours per day, 7 days a week.

Please submit form below and your respond time
will be 48 hours.

*Bold Fields Required

        Reffered By:
<input name="rname" type="text" value="<?php echo $rname; ?>" style="width:98%" />

Reffered Date:
<input name="rdate" type="text" value="<?php echo $rdate; ?>" style="width:98%" />

Reffered Agency:
<input name="ragency" type="text" value="<?php echo $ragency; ?>" style="width:98%" />

Phone:
<input name="rphone" type="text" style=value="rphone" "width:98%" />

* Client Name:
<input name="cname" type="text" value="<?php echo $cname; ?>" style="width:98%" />

* Phone:
<input name="cphone" type="text" value="<?php echo $cphone; ?>" style="width:98%" />

* Address:
<input name="caddress" type="text" value="<?php echo $caddress; ?>" style="width:98%" />

* City:
<input name="ccity" type="text" value="<?php echo $ccity; ?>" style="width:98%" />

* State:
<input name="cstate" type="text" value="<?php echo $cstate; ?>" style="width:98%" />

* Zip Code:
<input name="czip" type="text" value="<?php echo $czip; ?>" style="width:98%" />

* Birthday:
<input name="cbirthday" type="text" value="<?php echo $cbirthday; ?>" style="width:98%" />

Medicaid Member ID:
<input name="medmemid" type="text" value="<?php echo $medmemid; ?>" style="width:98%" />

Medicare Claim:
<input name="medclaim" type="text" value="<?php echo $medclaim; ?>" style="width:98%" />

Marital Status:
<input name="marital" type="text" value="<?php echo $marital; ?>" style="width:98%" />

Monthly Income:
<input name="income" type="text" value="<?php echo $income; ?>" style="width:98%" />

Gender:
<input name="gender" type="text" value="<?php echo $gender; ?>" style="width:98%" />

Race:
<input name="race" type="text" value="<?php echo $race; ?>" style="width:98%" />

Caregiver Name:
<input name="caregiver" type="text" value="<?php echo $caregiver; ?>" style="width:98%" />

Relationship:
<input name="relationship" type="text" value="<?php echo $relationship; ?>" style="width:98%" />

Phone:
<input name="memphone" type="text" value="<?php echo $phone; ?>" style="width:98%" />

Physician:
<input name="physician" type="text" value="<?php echo $physician; ?>" style="width:98%" />

Phone:
<input name="phyphone" type="text" value="<?php echo $phyphone; ?>" style="width:98%" />

Please make sure all the BOLD fields are completed before submitting form.

        <input type="reset" value="Clear Fields"> <input type="submit" name="send" value="Send" />

</form>

Body:
Okay, some rewriting help.

I would ultimately start by making a descriptive array of the field names and titles. This way you have a secure list of acceptable input fields and simplify the output later on.

$allowed_fields = array("
      "cname" => "* Client name",  // titles may include <b>HTML</b>
      "phone" => "PHone number",
      "caddress" => "Address",
      ...
");

But to simplify the first script, you can replace the 50 lines of $_REQUEST input and $_SESSION filling with just:

session_start();
foreach ($_REQUEST as $field=>$value) {
    $_SESSION[$field] = $_REQUEST[$field];
}

And all the form field output can be simplified this way:

foreach ($allowed_fields as $field=>$title) {
    ?><tr>
    <td valign="top"><?=$title?>:<br /><input name="<?=$field?>" type="text" value="<?=htmlspecialchars($_SESSION[$field])?>" style="width:98%" /></td>
    </tr><?php
}


问:
Why does AlertDialog.Builder limit the buttons / how does it work?
I am trying to make a simple two-button alert dialog without having to resort to making a separate class. AlertDialog.Builder class, which I am using to build the dialog, has three methods when it comes to adding buttons to the dialog.

```<code>setPositiveButton(...)
setNegativeButton(...)
setNeutralButton(...)
</code>```

Why does the Dialog hardcode this 3-button limit? Also, why do buttons need to be set as positive, negative, or neutral? What effect does a negative button press have compared to a positive or neutral button press?

I'm clearly missing something important, but it seems like this is a bad way to handle adding buttons? Because what if I want two (or more buttons) which shouldn't really be considered as positive or negative? The dialog doesn't allow adding more than one neutral button.

答:
Positive, neutral or negative are the options for a standard alert dialog.
If you follow the button's name to handle a positive or a negative action, the builder will set the layout following the design guidelines, and if they change with new Android versions, you will have your options always following the suggested order.

Of course you can set your OnClickListener in whatever order you prefer.

And if you need more than 3 buttons you can inflate your custom view by something like this:

```<code>LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_dialog_custom_layout, null);
dialogBuilder.setView(dialogView);
</code>```

Body:
I am trying to make a simple two-button alert dialog without having to resort to making a separate class. AlertDialog.Builder class, which I am using to build the dialog, has three methods when it comes to adding buttons to the dialog.

setPositiveButton(...)
setNegativeButton(...)
setNeutralButton(...)

Why does the Dialog hardcode this 3-button limit? Also, why do buttons need to be set as positive, negative, or neutral? What effect does a negative button press have compared to a positive or neutral button press?

I'm clearly missing something important, but it seems like this is a bad way to handle adding buttons? Because what if I want two (or more buttons) which shouldn't really be considered as positive or negative? The dialog doesn't allow adding more than one neutral button.

Body:
Positive, neutral or negative are the options for a standard alert dialog.
If you follow the button's name to handle a positive or a negative action, the builder will set the layout following the design guidelines, and if they change with new Android versions, you will have your options always following the suggested order.

Of course you can set your OnClickListener in whatever order you prefer.

And if you need more than 3 buttons you can inflate your custom view by something like this:

LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.alert_dialog_custom_layout, null);
dialogBuilder.setView(dialogView);


问:
Express/Mongoose use object function as callback doesn't work
I want to call function from my object in express route. This function should call mongoose query, then run next, next etc. - all needed operations.

Here is my example route:

```<code>var MailSender = require('../../libs/mailer');

router.get('/mailer/test', function (req, res, next) {
    MailSender.getPending();
});
</code>```

And mailer file:

```<code>(here include all required)

module.exports = {

    currentMails : {},

    getPending : function() {

        MailObj.find()
            .limit(10)
            .exec(this.blockPending);
    },

    blockPending : function(err, mail) {
        currentMails = {};

        mail.forEach(function(data) {
            let mailId = mongoose.Types.ObjectId(data._id);
            currentMails[mailId] = data;
        });

        MailObj.update({ _id: { $in: Object.keys(currentMails)  } }, { block: 1 }, {multi: true}, function() {
            // Doesn't work
            this.myNextFunc();
        });
    },

    myNextFunc : function() {
      console.log("Yep!");
    }
}
</code>```

getPending - it works great and call blackPending with query results.

blockPending - works greats, I can prepare ids and update records

But... myNextFunc() doesn't work and I can't call any object function from this scope (console says that they are undefined). I know, that I make something wrong but... what?

I'ld like to encapsule related functions in such objects and run inside as callbacks. What am I doing wrong?

答:
As far as you are using Mongoose, why don't you take profit of it, and you update each mail in the loop?? It is less efficient, but maybe as a first approach it deserves:</p>

```<code>var numUpdates = 0;
mail.forEach(function(data) {
    data.block = 1;
    data.save(function(err, mailSaved) {
        //check error
        if(numUpdates ++ >= mail.length) {
            this.myNextFunc();
        }
    })
});
</code>```

Body:
I want to call function from my object in express route. This function should call mongoose query, then run next, next etc. - all needed operations.

Here is my example route:

var MailSender = require('../../libs/mailer');

router.get('/mailer/test', function (req, res, next) {
    MailSender.getPending();
});

And mailer file:

(here include all required)

module.exports = {

    currentMails : {},

    getPending : function() {

        MailObj.find()
            .limit(10)
            .exec(this.blockPending);
    },

    blockPending : function(err, mail) {
        currentMails = {};

        mail.forEach(function(data) {
            let mailId = mongoose.Types.ObjectId(data._id);
            currentMails[mailId] = data;
        });

        MailObj.update({ _id: { $in: Object.keys(currentMails)  } }, { block: 1 }, {multi: true}, function() {
            // Doesn't work
            this.myNextFunc();
        });
    },

    myNextFunc : function() {
      console.log("Yep!");
    }
}

getPending - it works great and call blackPending with query results.

blockPending - works greats, I can prepare ids and update records

But... myNextFunc() doesn't work and I can't call any object function from this scope (console says that they are undefined). I know, that I make something wrong but... what?

I'ld like to encapsule related functions in such objects and run inside as callbacks. What am I doing wrong?

Body:
As far as you are using Mongoose, why don't you take profit of it, and you update each mail in the loop?? It is less efficient, but maybe as a first approach it deserves:

var numUpdates = 0;
mail.forEach(function(data) {
    data.block = 1;
    data.save(function(err, mailSaved) {
        //check error
        if(numUpdates ++ >= mail.length) {
            this.myNextFunc();
        }
    })
});


问:
Angular 4 - Passing string between components
I am working on a movie database, I am using the MovieDb api. I currently have 20 random generated movies without an user input, so I know the api is working.

I have my HTML with an input to take in the movie name and a button to activate the method:

```<code><button id="searchBarButton" (click)="sendRequest(MovieTitle)">Search</button>
<input id="MovieTitle" class= "searchBar" type="text" #MovieTitle>
</code>```

The in my .ts for the search component.I am setting up the subscription to my service which will allow me to use the API and search through it:

```<code>sendRequest(value)
{
// Need to route the shit outta this
this._iMDBService.searchMDBMovie(this.MovieTitle).subscribe( shows => {
  this.searchedShows=shows.results;
  this.router.navigateByUrl("/details");
},
  error=>this.errorMessage=<any>error);
}
</code>```

As you can see I am trying to send the movie title taken in from the user on the HTML and send it to the service below with the .ts file

```<code>@Injectable()
    export class iMDBService {
    private _iMDBURL: string = 'https://api.themoviedb.org/3/';

    constructor(private _http: HttpClient) { }

    searchMDBMovie(MovieTitle) : Observable<any>{
        return this._http.get<any>(this._iMDBURL + 'search/movie?api_key=MyWorkingApiKey&language=en-US&query=' + MovieTitle + '&page=1&include_adult=false')
        .do(data => console.log('All: ' + JSON.stringify(data)))
        .catch(this.handleError);
    }

    private handleError(err: HttpErrorResponse) {
        console.log(err.message);
        return Observable.throw(err.message);
    }
}
</code>```

My question: The api is working however I need the movie title in between the api request, the HTML and .ts is not sending to the service.ts, how do I bring the titlename to the service.ts file?

答:
the template variable

```<code>#MovieTitle
</code>```

refers to the input element itself, not the value of it.  To get the value you need to:

```<code><button id= "searchBarButton" (click)= "sendRequest(MovieTitle.value)">Search</button>
</code>```

and also use that value in your component method rather than trying to redundantly access the tempalte variable again.

simple console logging / debugging will clear these issues up much quicker.

Body:
I am working on a movie database, I am using the MovieDb api. I currently have 20 random generated movies without an user input, so I know the api is working.

I have my HTML with an input to take in the movie name and a button to activate the method:

<button id="searchBarButton" (click)="sendRequest(MovieTitle)">Search</button>
<input id="MovieTitle" class= "searchBar" type="text" #MovieTitle>

The in my .ts for the search component.I am setting up the subscription to my service which will allow me to use the API and search through it:

sendRequest(value)
{
// Need to route the shit outta this
this._iMDBService.searchMDBMovie(this.MovieTitle).subscribe( shows => {
  this.searchedShows=shows.results;
  this.router.navigateByUrl("/details");
},
  error=>this.errorMessage=<any>error);
}

As you can see I am trying to send the movie title taken in from the user on the HTML and send it to the service below with the .ts file

@Injectable()
    export class iMDBService {
    private _iMDBURL: string = 'https://api.themoviedb.org/3/';

    constructor(private _http: HttpClient) { }

    searchMDBMovie(MovieTitle) : Observable<any>{
        return this._http.get<any>(this._iMDBURL + 'search/movie?api_key=MyWorkingApiKey&language=en-US&query=' + MovieTitle + '&page=1&include_adult=false')
        .do(data => console.log('All: ' + JSON.stringify(data)))
        .catch(this.handleError);
    }

    private handleError(err: HttpErrorResponse) {
        console.log(err.message);
        return Observable.throw(err.message);
    }
}

My question: The api is working however I need the movie title in between the api request, the HTML and .ts is not sending to the service.ts, how do I bring the titlename to the service.ts file?

Body:
the template variable

#MovieTitle

refers to the input element itself, not the value of it.  To get the value you need to:

<button id= "searchBarButton" (click)= "sendRequest(MovieTitle.value)">Search</button>

and also use that value in your component method rather than trying to redundantly access the tempalte variable again.

simple console logging / debugging will clear these issues up much quicker.


问:
Does tf.one_hot() supports SparseTensor as indices parameter?
I would like to ask whether tf.one_hot() function supports SparseTensor as the "indices" parameter. I want to do a multi-label classification (each example has multiple labels) which requires to calculate a cross_entropy loss.

I try to directly put the SparseTensor in the "indices" parameter but it raises the following error:

TypeError: Failed to convert object of type  to Tensor. Contents: SparseTensor(indices=Tensor("read_batch_features/fifo_queue_Dequeue:106", shape=(?, 2), dtype=int64, device=/job:worker), values=Tensor("string_to_index_Lookup:0", shape=(?,), dtype=int64, device=/job:worker), dense_shape=Tensor("read_batch_features/fifo_queue_Dequeue:108", shape=(2,), dtype=int64, device=/job:worker)). Consider casting elements to a supported type.

Any suggestion on the possible cause?

Thanks.

答:
You could build up another SparseTensor of shape (batch_size, num_classes) from the initial SparseTensor. For example if you keep your classes in a single string feature column (separated by spaces), you could use the following:

import tensorflow as tf

all_classes = ["class1", "class2", "class3"]
classes_column = ["class1 class3", "class1 class2", "class2", "class3"]

table = tf.contrib.lookup.index_table_from_tensor(
    mapping=tf.constant(all_classes)
)
classes = tf.constant(classes_column)
classes = tf.string_split(classes)
idx = table.lookup(classes) # SparseTensor of shape (4, 2), because each of the 4 rows has at most 2 classes
num_items = tf.cast(tf.shape(idx)[0], tf.int64) # num items in batch
num_entries = tf.shape(idx.indices)[0] # num nonzero entries

y = tf.SparseTensor(
    indices=tf.stack([idx.indices[:, 0], idx.values], axis=1),
    values=tf.ones(shape=(num_entries,), dtype=tf.int32),
    dense_shape=(num_items, len(all_classes)),
)
y = tf.sparse_tensor_to_dense(y, validate_indices=False)

with tf.Session() as sess:
    tf.tables_initializer().run()
    print(sess.run(y))

    # Outputs:
    # [[1 0 1]
    #  [1 1 0]
    #  [0 1 0]
    #  [0 0 1]]
```

Here the idx is a SparseTensor. The first column of its indices idx.indices[:, 0] contains the row numbers of the batch, and its values idx.values contains the index of the relevant class id. We combine these two to create the new y.indices.

For a full implementation of multi-label classification, see "Option 2" of  https://stackoverflow.com/a/47671503/507062

Body:
You could build up another SparseTensor of shape (batch_size, num_classes) from the initial SparseTensor. For example if you keep your classes in a single string feature column (separated by spaces), you could use the following:

import tensorflow as tf

all_classes = ["class1", "class2", "class3"]
classes_column = ["class1 class3", "class1 class2", "class2", "class3"]

table = tf.contrib.lookup.index_table_from_tensor(
    mapping=tf.constant(all_classes)
)
classes = tf.constant(classes_column)
classes = tf.string_split(classes)
idx = table.lookup(classes) # SparseTensor of shape (4, 2), because each of the 4 rows has at most 2 classes
num_items = tf.cast(tf.shape(idx)[0], tf.int64) # num items in batch
num_entries = tf.shape(idx.indices)[0] # num nonzero entries

y = tf.SparseTensor(
    indices=tf.stack([idx.indices[:, 0], idx.values], axis=1),
    values=tf.ones(shape=(num_entries,), dtype=tf.int32),
    dense_shape=(num_items, len(all_classes)),
)
y = tf.sparse_tensor_to_dense(y, validate_indices=False)

with tf.Session() as sess:
    tf.tables_initializer().run()
    print(sess.run(y))

    # Outputs:
    # [[1 0 1]
    #  [1 1 0]
    #  [0 1 0]
    #  [0 0 1]]

Here the idx is a SparseTensor. The first column of its indices idx.indices[:, 0] contains the row numbers of the batch, and its values idx.values contains the index of the relevant class id. We combine these two to create the new y.indices.

For a full implementation of multi-label classification, see "Option 2" of  https://stackoverflow.com/a/47671503/507062


问:
Fast changing Images / Frames (visible for 20ms)
I'm trying to create a program that shows for 1000 ms a transparent screen following by an image that is displaying for 20 ms. That should continue in a loop (1000m s -> 20 ms -> 1000 ms -> 20 ms -> ....).

The time for displaying the image is too long, so that you can see the image on the screen if it appears.

Is there a way to get a better performance?

Here is the code:

```<code>import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.util.TimerTask;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class SubPrimingJava extends JFrame {
    public SubPrimingJava() {
        super("GradientTranslucentWindow");

        setBackground(new Color(0,0,0,0));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width+20, screenSize.height+200);
        //setLocationRelativeTo(null);
        setLocation(-10, -100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                if (g instanceof Graphics2D) {
                    final int R = 240;
                    final int G = 240;
                    final int B = 240;

                    Paint p =
                        new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
                            0.0f, getHeight(), new Color(R, G, B, 0), true);
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.setPaint(p);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
                }
            }
        };
        setContentPane(panel);
        setLayout(new GridBagLayout());

    }

    public static void main(String[] args) {
        // Determine what the GraphicsDevice can support.
        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        boolean isPerPixelTranslucencySupported =
            gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);

        //If translucent windows aren't supported, exit.
        if (!isPerPixelTranslucencySupported) {
            System.out.println(
                "Per-pixel translucency is not supported");
                System.exit(0);
        }

        JFrame.setDefaultLookAndFeelDecorated(true);

        // Create the GUI on the event-dispatching thread
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SubPrimingJava gtw = new
                    SubPrimingJava();

                // Display the window.
                gtw.setVisible(true);
                ImageIcon icon = new ImageIcon("test.png");
                JLabel label = new JLabel( icon );
                gtw.add(label);
                gtw.setOpacity(0);

                Timer timer = new Timer(1000, new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        gtw.setOpacity(1);
                        Timer t2 = new Timer(1, new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                gtw.setOpacity(0);
                            }
                        });
                        t2.start();
                        t2.setRepeats(false);
                    }
                });
                timer.setRepeats(true);
                timer.start();
            }
        });
    }
}
</code>```

答:
Don't know if this blinks any faster, but its all I could come up with:</p>

```<code>Timer timer = new Timer(1000, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {

        gtw.setOpacity(1);
        label.paintImmediately(label.getBounds());

        gtw.setOpacity(0);
        label.paintImmediately(label.getBounds());
    }
});
timer.setRepeats(true);
timer.start();
</code>```

Body:
I'm trying to create a program that shows for 1000 ms a transparent screen following by an image that is displaying for 20 ms. That should continue in a loop (1000m s -> 20 ms -> 1000 ms -> 20 ms -> ....).

The time for displaying the image is too long, so that you can see the image on the screen if it appears.

Is there a way to get a better performance?

Here is the code:

import java.awt.*;
import javax.swing.*;
import static java.awt.GraphicsDevice.WindowTranslucency.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.util.TimerTask;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class SubPrimingJava extends JFrame {
    public SubPrimingJava() {
        super("GradientTranslucentWindow");

        setBackground(new Color(0,0,0,0));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width+20, screenSize.height+200);
        //setLocationRelativeTo(null);
        setLocation(-10, -100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                if (g instanceof Graphics2D) {
                    final int R = 240;
                    final int G = 240;
                    final int B = 240;

                    Paint p =
                        new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
                            0.0f, getHeight(), new Color(R, G, B, 0), true);
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.setPaint(p);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
                }
            }
        };
        setContentPane(panel);
        setLayout(new GridBagLayout());

    }

    public static void main(String[] args) {
        // Determine what the GraphicsDevice can support.
        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        boolean isPerPixelTranslucencySupported =
            gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);

        //If translucent windows aren't supported, exit.
        if (!isPerPixelTranslucencySupported) {
            System.out.println(
                "Per-pixel translucency is not supported");
                System.exit(0);
        }

        JFrame.setDefaultLookAndFeelDecorated(true);

        // Create the GUI on the event-dispatching thread
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                SubPrimingJava gtw = new
                    SubPrimingJava();

                // Display the window.
                gtw.setVisible(true);
                ImageIcon icon = new ImageIcon("test.png");
                JLabel label = new JLabel( icon );
                gtw.add(label);
                gtw.setOpacity(0);

                Timer timer = new Timer(1000, new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        gtw.setOpacity(1);
                        Timer t2 = new Timer(1, new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                gtw.setOpacity(0);
                            }
                        });
                        t2.start();
                        t2.setRepeats(false);
                    }
                });
                timer.setRepeats(true);
                timer.start();
            }
        });
    }
}

Body:
Don't know if this blinks any faster, but its all I could come up with:

Timer timer = new Timer(1000, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {

        gtw.setOpacity(1);
        label.paintImmediately(label.getBounds());

        gtw.setOpacity(0);
        label.paintImmediately(label.getBounds());
    }
});
timer.setRepeats(true);
timer.start();


答:
Well, I guest this little corrections would make it work:

```<code><button
  id= "searchBarButton"
  (click)="sendRequest(MovieTitle.value)">
  Search
</button>
<input
  id="MovieTitle"
  class="searchBar"
  type="text"
  #MovieTitle />

sendRequest(value) {
  this._iMDBService.searchMDBMovie(value).subscribe( shows => {
  ...
</code>```

An suggestion to make it better for user interaction:

```<code><button
  id= "searchBarButton"
  (click)="sendRequest(MovieTitle.value)">
  Search
</button>
<input
  id="MovieTitle"
  class="searchBar"
  type="text"
  #MovieTitle
  (keyup.enter)="sendRequest(MovieTitle.value)" />
</code>```

The (keyup.enter) will call the sendRequest method when the user hits the Enter key when the input is focused.

Title: Angular 4 - Passing string between components

Body:
Well, I guest this little corrections would make it work:

<button
  id= "searchBarButton"
  (click)="sendRequest(MovieTitle.value)">
  Search
</button>
<input
  id="MovieTitle"
  class="searchBar"
  type="text"
  #MovieTitle />

sendRequest(value) {
  this._iMDBService.searchMDBMovie(value).subscribe( shows => {
  ...

An suggestion to make it better for user interaction:

<button
  id= "searchBarButton"
  (click)="sendRequest(MovieTitle.value)">
  Search
</button>
<input
  id="MovieTitle"
  class="searchBar"
  type="text"
  #MovieTitle
  (keyup.enter)="sendRequest(MovieTitle.value)" />

The (keyup.enter) will call the sendRequest method when the user hits the Enter key when the input is focused.


问:
CSS Transparent Gold Background
I've been struggling for days on how to achieve this transparent gold at the right side of the image below.

That is what exactly look like in the PSD but when saving it as .PNG it seems to look like a very different color as it kinda turns to yellow. Maybe because it doesn't use the web standard colors. So I'm trying some CSS solution on this code sample below, but I don't know how to do it right or what should be the color combination should I use.

.bg-gold { position: relative; }
.bg-gold-1, .bg-gold-2 {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
}
.bg-gold-1 {
  background: #b38600;
  opacity: .5;
}
.bg-gold-2 {
  background: #b36b00;
  opacity: .2;
}

img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="bg-gold">
  <img src="http://wilsin.com.sg/wp-content/uploads/2017/08/index-banner-1-black-and-white.jpg" alt="">
  <div class="bg-gold bg-gold-1"></div>
  <div class="bg-gold bg-gold-2"></div>
</div></code>```

答:
You can achieve using css property transform.Hope this code helps.

.infoContainer {
  margin: 30px 20px;
  display: inline-block;
  width: 100px;
  height: 100px;
  overflow: hidden;
  border-radius: 20px;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg); /* IE 9 */
  -webkit-transform: rotate(45deg); /* Safari and Chrome */
  position:relative;

  /* non-essential styling */
  -webkit-box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  background-color:rgba(218,165,32,0.5);
}

.infoContainerB {
  margin: 10px 10px;
  display: inline-block;
  width: 100px;
  height: 100px;
  overflow: hidden;
  border-radius: 20px;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg); /* IE 9 */
  -webkit-transform: rotate(45deg); /* Safari and Chrome */
  position:relative;

  /* non-essential styling */
  -webkit-box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  background-color:rgba(218,165,32,0.8);
}

.infoContainer p,
.infoContainerB p {
  transform: rotate(-45deg);
  -ms-transform: rotate(-45deg); /* IE 9 */
  -webkit-transform: rotate(-45deg); /* Safari and Chrome */
  position:absolute;
  top:30px;
}

.wrapper {
  font-family: 'Oswald', Arial, Sans;
  font-size: 16px;
  position: absolute;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <figure>
    <div class="infoContainer">
      <p>Howdy!!</p>
    </div>
    <div class="infoContainerB">
      <p>Howdy B!!</p>
    </div>
  </figure>
</div></code>```

Title: CSS Transparent Gold Background

Body:
You can achieve using css property transform.Hope this code helps.

.infoContainer {
  margin: 30px 20px;
  display: inline-block;
  width: 100px;
  height: 100px;
  overflow: hidden;
  border-radius: 20px;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg); /* IE 9 */
  -webkit-transform: rotate(45deg); /* Safari and Chrome */
  position:relative;

  /* non-essential styling */
  -webkit-box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  background-color:rgba(218,165,32,0.5);
}

.infoContainerB {
  margin: 10px 10px;
  display: inline-block;
  width: 100px;
  height: 100px;
  overflow: hidden;
  border-radius: 20px;
  transform: rotate(45deg);
  -ms-transform: rotate(45deg); /* IE 9 */
  -webkit-transform: rotate(45deg); /* Safari and Chrome */
  position:relative;

  /* non-essential styling */
  -webkit-box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  box-shadow: 0px 0px 3px 3px rgba(0, 0, 0, .05);
  background-color:rgba(218,165,32,0.8);
}

.infoContainer p,
.infoContainerB p {
  transform: rotate(-45deg);
  -ms-transform: rotate(-45deg); /* IE 9 */
  -webkit-transform: rotate(-45deg); /* Safari and Chrome */
  position:absolute;
  top:30px;
}

.wrapper {
  font-family: 'Oswald', Arial, Sans;
  font-size: 16px;
  position: absolute;
}

<div class="wrapper">
  <figure>
    <div class="infoContainer">
      <p>Howdy!!</p>
    </div>
    <div class="infoContainerB">
      <p>Howdy B!!</p>
    </div>
  </figure>
</div>


问:
How to dynamically create a search field as a header in angular

Hey there,

I've been struggling with this problem for a few days, I'm trying to create an angular directive template form that takes in a data source and will create a searchable table with that data. As of now, I'm able to individually add searchable columns for the table (for example search.BookId) and it will sort on multiple columns, however I don't know what the column names will be ahead of time so I'm trying to keep it as fluid as possible.

The problem is when I use search.{{key}} it will not show the correct data and instead when inspecting the element just show literally "search.{{key}}". I have tried using search['{{key}}'] which will get the keys correctly and put them into the right spots but then I can't do the filtering the way I want on the table.

Here's what my template looks like:

```<code>            '<table class="table table-striped table-bordered">' +
            '<thead>' +
            '<tr>' +
            //'<th><input type="text" ng-model="search.BookID"></input></th>' +

            '<th>' +
            '' +
            '</th>' +

                '<th ng-repeat="(key, value) in tableArray[0]">' +
                    '<input type="text" placeholder="{{key}}" ng-model="search.{{key}}"></input>' +
            '</th>' +

            '</tr>' +
            '</thead>' +
            '<tbody>' +
            '<tr ng-repeat="tr in tableArray | filter:search:strict">' +
            '<td ng-repeat="item in tr">{{item}}</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>',
</code>```

and my table array:

```<code>$scope.tableArray = [
                    {
                        "BookID": "1",
                        "BookName": "Computer Architecture",
                        "Category": "Computers",
                        "Price": "125.60"
                    },
                    {
                        "BookID": "2",
                        "BookName": "Asp.Net 4 Blue Book",
                        "Category": "Programming",
                        "Price": "56.00"
                    },
                    {
                        "BookID": "3",
                        "BookName": "Popular Science",
                        "Category": "Science",
                        "Price": "210.40"
                    },
                    {
                        "BookID": "4",
                        "BookName": "Indian Studies",
                        "Category": "History",
                        "Price": "132.68"
                    },
                    {
                        "BookID": "5",
                        "BookName": "Derivatives and You",
                        "Category": "Math",
                        "Price": "206.73"
                    },
                    {
                        "BookID": "6",
                        "BookName": "The art of the Greeks",
                        "Category": "Social Studies",
                        "Price": "10.30"
                    },
                    {
                        "BookID": "7",
                        "BookName": "Chemistry 101",
                        "Category": "Chemistry",
                        "Price": "140.40"
                    }
                ];
</code>```

I'd like the end result be similar to the Angular documentations filtering version (plnkr: https://plnkr.co/edit/?p=preview ). But they use static data whereas i'm using dynamic data.

Some things I have also tried is doing:

```<code>'<table>' +
                '    <thead>' +
                '       <th ng-repeat="(key, value) in obj[0]"><input type="text" ng-model="search[\'{{key}}\']"></input></th>' +
                '    </thead>' +
                '</table>' +
</code>```

But that didn't seem to work either when doing the filter

```<code> '<tr ng-repeat="tr in tableArray | filter:search:strict">' +
</code>```

Any ideas of what I'm doing wrong?

答:
The value in ng-model is an AngularJS expression that gets evaluated against the current scope, so you don't need the double-curlies inside of it, you can just do ng-model="search[key]".

Here's a plunk showing it working.

Body:
Hey there,

I've been struggling with this problem for a few days, I'm trying to create an angular directive template form that takes in a data source and will create a searchable table with that data. As of now, I'm able to individually add searchable columns for the table (for example search.BookId) and it will sort on multiple columns, however I don't know what the column names will be ahead of time so I'm trying to keep it as fluid as possible.

The problem is when I use search.{{key}} it will not show the correct data and instead when inspecting the element just show literally "search.{{key}}". I have tried using search['{{key}}'] which will get the keys correctly and put them into the right spots but then I can't do the filtering the way I want on the table.

Here's what my template looks like:

            '
' +
            '
' +
            '
' +
            //'<input type="text" ng-model="search.BookID"></input>	' +

            '' +
            '' +
            '	' +

                '' +
                    '<input type="text" placeholder="{{key}}" ng-model="search.{{key}}"></input>' +
            '	' +

            '
' +
            '
' +
            '
' +
            '
' +
            '{{item}}	' +
            '
' +
            '
' +
            '
',

and my table array:

$scope.tableArray = [
                    {
                        "BookID": "1",
                        "BookName": "Computer Architecture",
                        "Category": "Computers",
                        "Price": "125.60"
                    },
                    {
                        "BookID": "2",
                        "BookName": "Asp.Net 4 Blue Book",
                        "Category": "Programming",
                        "Price": "56.00"
                    },
                    {
                        "BookID": "3",
                        "BookName": "Popular Science",
                        "Category": "Science",
                        "Price": "210.40"
                    },
                    {
                        "BookID": "4",
                        "BookName": "Indian Studies",
                        "Category": "History",
                        "Price": "132.68"
                    },
                    {
                        "BookID": "5",
                        "BookName": "Derivatives and You",
                        "Category": "Math",
                        "Price": "206.73"
                    },
                    {
                        "BookID": "6",
                        "BookName": "The art of the Greeks",
                        "Category": "Social Studies",
                        "Price": "10.30"
                    },
                    {
                        "BookID": "7",
                        "BookName": "Chemistry 101",
                        "Category": "Chemistry",
                        "Price": "140.40"
                    }
                ];

I'd like the end result be similar to the Angular documentations filtering version (plnkr: https://plnkr.co/edit/?p=preview ). But they use static data whereas i'm using dynamic data.

Some things I have also tried is doing:

'
' +
                '
' +
                '       <input type="text" ng-model="search[\'{{key}}\']"></input>	' +
                '
' +
                '
' +

But that didn't seem to work either when doing the filter

 '
' +

Any ideas of what I'm doing wrong?


问:
Size Limit of camel header variable and property
I have to store the request xml in to database. I was using header variable to do that.

```<code>exchange.getIn().setHeader("inputRequestXml", body);
</code>```

it was working for some files And I was getting below exception for some files, it seems like because of the file size.

```<code> 413 Request entity too large
</code>```

So I have changed the implementation by using camel property, like below

```<code>exchange.setProperty("inputRequestXml", body);
</code>```

Now I am not getting the exception. But I am afraid that will it handle the bigger files in actual PROD environment. So i want to know, What would be the size
limit of header variable and property?

答:
Apache Camel has no limit on Headers and Properties. It is limited by Java heap size, as every other object.

Error you have posted is HTTP error, you are probably sending it over HTTP and remote server returned this error.
Apache Camel translates Message#headers as HTTP headers and you have exceeded size limit configured on server.

See: Maximum on http header values?

Switching to Properties worked, because Properties are not tranferred over HTTP. You might be interested in endpoint options copyHeaders=false and headerFilterStrategy

Body:
I have to store the request xml in to database. I was using header variable to do that.

exchange.getIn().setHeader("inputRequestXml", body);

it was working for some files And I was getting below exception for some files, it seems like because of the file size.

 413 Request entity too large

So I have changed the implementation by using camel property, like below

exchange.setProperty("inputRequestXml", body);

Now I am not getting the exception. But I am afraid that will it handle the bigger files in actual PROD environment. So i want to know, What would be the size
limit of header variable and property?


问:
Rewrite shell script without whitespace
Is it possible to write a shell script like that without using spaces, tabs or newlines:

```<code>/path/to/foo; test $? -ne 6
</code>```

The script runs another program and fails iff its return code is 6.

Background

I use this together within pam_exec.so and another program that controls access to a system. It does not relate to security, and I want to ensure access to the system if something about that other script fails (other than rc 6). The other program is a bit brittle, may break for various reasons, or simply be unavailable due to a messed up installation. I currently use a wrapper script, but that again needs to be deployed and i need to ensure that deployment of that script is consistent with the pam configuration. I would prefer a self-contained portable solution within the pam configuration.

Unfortunately 1) pam_exec.so doesn't care for the return code of the program it calls, and 2) the pam.d config parser does not care for quotes, it just splits arguments by " \n\t", so I cannot use

```<code>... pam_exec.so /bin/bash -c "/bath/to/foo; test$? -ne 6"
</code>```

I am curious if there is a way to reformulate that such that it does not need spaces and can be used here.

答:
Use an arithmetic statement, which requires less whitespace during parsing.</p>

```<code>bash -c '/path/to/foo;(($?!=6))'
</code>```

Title: Rewrite shell script without whitespace

Body:
Is it possible to write a shell script like that without using spaces, tabs or newlines:

/path/to/foo; test $? -ne 6

The script runs another program and fails iff its return code is 6.

Background

I use this together within pam_exec.so and another program that controls access to a system. It does not relate to security, and I want to ensure access to the system if something about that other script fails (other than rc 6). The other program is a bit brittle, may break for various reasons, or simply be unavailable due to a messed up installation. I currently use a wrapper script, but that again needs to be deployed and i need to ensure that deployment of that script is consistent with the pam configuration. I would prefer a self-contained portable solution within the pam configuration.

Unfortunately 1) pam_exec.so doesn't care for the return code of the program it calls, and 2) the pam.d config parser does not care for quotes, it just splits arguments by " \n\t", so I cannot use

... pam_exec.so /bin/bash -c "/bath/to/foo; test$? -ne 6"

I am curious if there is a way to reformulate that such that it does not need spaces and can be used here.

Body:
Use an arithmetic statement, which requires less whitespace during parsing.

bash -c '/path/to/foo;(($?!=6))'


问:
Update file after FlatFileItemReader in Spring Batch
I currently have the following processing in a Spring Batch job:

FlatFileItemReader reads a CSV file

Processor does some work

FlatFileItemWriter creates a mirror of the read file, but updates the file to reflect processing

I don't want to write to a new file, but I want to update the same file that is being read during processing.

My question is, is there a typical method in Spring to use the FlatFileItemReader and then update that same file per row in the processor at runtime?

Thanks for any help.

答:
You can always write a custom writer in spring batch,  just like an example below. Where you read data form the file into memory, and then update the same file with the data that you are intended to.

https://github.com/pkainulainen/spring-batch-examples/tree/master/spring/src/main/java/net/petrikainulainen/springbatch/custom/in

more than that FlatFileItemReader is not thread safe. Of course there are hacks to achieve thread safety but not a good practice to use such hacks, its always good to create custom writer.


问:
Sum integer list when next integer is the same value
So I need to have a code that checks one integer, and checks if the integer after it is the same value. If so, it will add the value to x.

```<code>input1 = [int(i) for i in str(1234441122)]
x= 0
</code>```

So my code currently gives the result [1, 2, 3, 4, 4, 4, 1, 1 ,2 ,2]. I want it to give the result of x = 0+4+4+1+2.
I do not know any way to do that.

答:
No need for that list. You can remove the "non-repeated" digits from the string already:

```<code>>>> n = 1234441122
>>> import re
>>> sum(map(int, re.sub(r'(.)(?!\1)', '', str(n))))
11
</code>```

Body:
So I need to have a code that checks one integer, and checks if the integer after it is the same value. If so, it will add the value to x.

input1 = [int(i) for i in str(1234441122)]
x= 0

So my code currently gives the result [1, 2, 3, 4, 4, 4, 1, 1 ,2 ,2]. I want it to give the result of x = 0+4+4+1+2.
I do not know any way to do that.

Body:
No need for that list. You can remove the "non-repeated" digits from the string already:

>>> n = 1234441122
>>> import re
>>> sum(map(int, re.sub(r'(.)(?!\1)', '', str(n))))
11