问:
SSRS URL Parameter won't set
I have the following c# code in a web form:

```<code>protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url;
            string startdate;
            string enddate;
            string costcenter;
            string account;

            //url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Details&rs:Command=Render&rc:Parameters=false";
            url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Totals&rs:Command=Render&rc:Parameters=false";
            costcenter = "&costcenter=990";

            startdate="&startdate=" + Convert.ToString(txtStartDate.Text);
            enddate = "&enddate=" + Convert.ToString(txtEndDate.Text);

            account="&account=" + Convert.ToString(GridView1.SelectedRow.Cells[1].Text);

            url =url + startdate + enddate + costcenter + account;

            //TextBox1.Text = Convert.ToString(GridView1.SelectedRow.Cells[1].Text);
                Response.Redirect(url, false);

        }
</code>```

I've tested a very similer version of this code against another report, the only different being the costcenter parameter.  The other report worked fine, but every time i run this code i get the error: "the 'costcenter' parameter is missing a value".  The only thing i can think of that's significantly different between the two reports is that in the Cost Center Totals report the costcenter parameter is used to populate the accounts parameter (both are multi-select).

Here's what the parameters page looks like:

答:
I've been under the impression that one difference between running a report on the web server and running it in code is that in code it does not bother with the "Available Values" queries for parameters. In code, you aren't selecting a human-readable label from a drop-down which then passes in the corresponding value. Instead, you just provide the value to the parameter.

So, have you tried not specifying the cost center parameter at all? If the account parameter is all the report's recordsets really are based on, then it may be superfluous to set it.

Update:

Since the time I wrote this answer originally I've learned that dependent parameters (at least in SSRS 2008) must be after the parameter(s) they're dependent on. Make sure your parameters are ordered in a sensible way.

It looks like that's what you've done, I just wanted to mention the possibility.

Title: SSRS URL Parameter won't set

Body:
I have the following c# code in a web form:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url;
            string startdate;
            string enddate;
            string costcenter;
            string account;

            //url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Details&rs:Command=Render&rc:Parameters=false";
            url = "http://server/reportserver?/Finance/Cost Spending/Cost Center Totals&rs:Command=Render&rc:Parameters=false";
            costcenter = "&costcenter=990";

            startdate="&startdate=" + Convert.ToString(txtStartDate.Text);
            enddate = "&enddate=" + Convert.ToString(txtEndDate.Text);

            account="&account=" + Convert.ToString(GridView1.SelectedRow.Cells[1].Text);

            url =url + startdate + enddate + costcenter + account;

            //TextBox1.Text = Convert.ToString(GridView1.SelectedRow.Cells[1].Text);
                Response.Redirect(url, false);

        }

I've tested a very similer version of this code against another report, the only different being the costcenter parameter.  The other report worked fine, but every time i run this code i get the error: "the 'costcenter' parameter is missing a value".  The only thing i can think of that's significantly different between the two reports is that in the Cost Center Totals report the costcenter parameter is used to populate the accounts parameter (both are multi-select).

Here's what the parameters page looks like:


来源: stackexchange

问:
Overriding the Defaults in a struct (c#)
Is it possible to set or override the default state for a structure?

As an example I have an

```<code>enum something{a,b,c,d,e};
</code>```

and a structure that links 2 values for that enum

```<code>struct SomethingData
{
    something type;
    int Value;
    double Multipler;

    SomethingData(something enumVal, int intVal, double DblVal) {...}
}
</code>```

But can I specify that the default state is

```<code>SomethingData(something.c,0,1);
</code>```

答:
My solution. It works as well.

```<code>public struct DisplayOptions
{
    public bool isUpon;
    public bool screenFade;

    public static DisplayOptions Build()
    {
        // Return default value
        return new DisplayOptions(true, true);
    }

    DisplayOptions(bool isUpon, bool screenFade)
    {
        this.isUpon = isUpon;
        this.screenFade = screenFade;
    }

    public DisplayOptions SetUpon(bool upon)
    {
        this.isUpon = upon;
        return this;
    }

    public DisplayOptions SetScreenFade(bool screenFade)
    {
        this.screenFade = screenFade;
        return this;
    }
}
</code>```

Use default value

```<code>        // Use default
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build());
        // Use custome
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build().SetScreenFade(false));
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build().SetUpon(false));
</code>```

ContentLicense: CC BY-SA 2.5

Body:
Is it possible to set or override the default state for a structure?

As an example I have an

enum something{a,b,c,d,e};

and a structure that links 2 values for that enum

struct SomethingData
{
    something type;
    int Value;
    double Multipler;

    SomethingData(something enumVal, int intVal, double DblVal) {...}
}

But can I specify that the default state is

SomethingData(something.c,0,1);

Body:
My solution. It works as well.

public struct DisplayOptions
{
    public bool isUpon;
    public bool screenFade;

    public static DisplayOptions Build()
    {
        // Return default value
        return new DisplayOptions(true, true);
    }

    DisplayOptions(bool isUpon, bool screenFade)
    {
        this.isUpon = isUpon;
        this.screenFade = screenFade;
    }

    public DisplayOptions SetUpon(bool upon)
    {
        this.isUpon = upon;
        return this;
    }

    public DisplayOptions SetScreenFade(bool screenFade)
    {
        this.screenFade = screenFade;
        return this;
    }
}

Use default value

        // Use default
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build());
        // Use custome
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build().SetScreenFade(false));
        UIMaster.Instance.StartScreen("Screen 2", DisplayOptions.Build().SetUpon(false));

ContentLicense: CC BY-SA 3.0


问:
Command "react-native" can not run after installed react-native-drawer
I inited React native project by:

react-native init MyShop
In MyShop folder, I install "react-native-drawer":

npm install --save react-native-drawer
After install, I run project by:

react-native run-android
And get error "Command run-android unrecognized. Make sure that you have run npm install and that you are inside a react-native project."
I checked react-native by command line

react-native -v
And get info:

react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory
It seems react-native lib has been removed after installed react-native-drawer.
My npm version:

E:\2.Projects\My\MyShop>npm -v
5.0.4
My node version:

E:\2.Projects\My\MyShop>node -v
v8.1.2
Please help me re-procedure and fix it. Thank you!

答:
I found out solution for this issue!
I update npm to latest version: 5.1.0.
Uninstall react-native-cli:

npm uninstall -g react-native-cli

Next, reinstall react-native-cli:

npm install -g react-native-cli

My issue has been fixed.


问:
How does one test item membership in an unordered sequence (C++)?
I've used python for a long time, and I'm just beginning to use C++

In python, if one has a set or a dictionary it is relatively easy to get a boolean value indicating whether or not a particular item is in that sequence using the in keyword.
i.e.

```<code>a = set(2,4,3)
if 4 in a
print "yes, 4 is in a, thank you for asking!"
</code>```

it's much more efficient than doing this:

```<code>a = [2,3,4]
for number in a
>if number == 4
>>return "yes, 4 is in a, thank you for asking!"
</code>```

is there a way to do make a membership test simple and efficient in cpp or do you always have to iterate through some ordered sequence?

答: Take a look at the containers offered by STL and their performance characteristics.</p>

Body:
I've used python for a long time, and I'm just beginning to use C++

In python, if one has a set or a dictionary it is relatively easy to get a boolean value indicating whether or not a particular item is in that sequence using the in keyword.
i.e.

a = set(2,4,3)
if 4 in a
print "yes, 4 is in a, thank you for asking!"

it's much more efficient than doing this:

a = [2,3,4]
for number in a
>if number == 4
>>return "yes, 4 is in a, thank you for asking!"

is there a way to do make a membership test simple and efficient in cpp or do you always have to iterate through some ordered sequence?


问:
How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+
ng-bind-html-unsafe was removed in Angular 1.2

I'm trying to implement something where I need to use ng-bind-html-unsafe. In the docs and on the github commit they say:

ng-bind-html provides ng-html-bind-unsafe like behavior (innerHTML's the result without
  sanitization) when bound to the result of $sce.trustAsHtml(string).

How do you do this?

答:
Simply creating a filter will do the trick. (Answered for Angular 1.6)

```<code>.filter('trustHtml', [
        '$sce',
        function($sce) {
            return function(value) {
                return $sce.trustAs('html', value);
            }
        }
    ]);
</code>```

And use this as follow in the html.

```<code><h2 ng-bind-html="someScopeValue | trustHtml"></h2>
</code>```

Body:
Simply creating a filter will do the trick. (Answered for Angular 1.6)

.filter('trustHtml', [
        '$sce',
        function($sce) {
            return function(value) {
                return $sce.trustAs('html', value);
            }
        }
    ]);

And use this as follow in the html.

<h2 ng-bind-html="someScopeValue | trustHtml"></h2>


问:
d3 line chart runs off the chart when threshold values are applied
I am new to d3 and working with line chart, where i want to view the chart between the threshold values Fiddler. The chart works fine with y.domain([min,max]), since i want to view the chart with my own threshold values the line runs off the chart, i've no idea why this is happening. Any help is much appreciated.

答:
If you want to avoid the lines bleeding over the graph area, what you might want is using a clip-path. I tweaked your code a little bit and added the clip path to it.

```<code>svg.append("clipPath")
   .attr("id", "clip-path")
   .append("rect")
   .attr("width", width)
   .attr("height", height);

svg.append("path") // Add the valueline path.
   .attr("d", valueline(data))
   .attr("clip-path", "url(#clip-path)");
</code>```

Here is the JSFiddle link for the same: http://jsfiddle.net/vxo1qsf9/2/

Please let me know if this is what you are looking for. :)

Body:
If you want to avoid the lines bleeding over the graph area, what you might want is using a clip-path. I tweaked your code a little bit and added the clip path to it.

svg.append("clipPath")
   .attr("id", "clip-path")
   .append("rect")
   .attr("width", width)
   .attr("height", height);

svg.append("path") // Add the valueline path.
   .attr("d", valueline(data))
   .attr("clip-path", "url(#clip-path)");

Here is the JSFiddle link for the same: http://jsfiddle.net/vxo1qsf9/2/

Please let me know if this is what you are looking for. :)


问:
TYPO3 individual query filter by another table
I have TYPO3 version 7.6.18, and  want get data with filtering by field on another relation table.

```<code>class PhotoRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
    public function getFiltered($offset = 0, $limit = 5){
        $query = $this->createQuery();
        $query->matching($query->in('cruserId.gender', 3));
        return $query->execute();
    }
}
</code>```

Model:

```<code>class Photo extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

    /**
     * CruserId
     *
     * @var \Fhk\Feusersplus\Domain\Model\User>
     */
    protected $cruserId;

    /**
     * Returns the cruserId
     *
     * @return \Fhk\Feusersplus\Domain\Model\User> $cruserId
     */
    public function getCruserId()
    {
        return $this->cruserId;
    }

    /**
     * Sets the cruserId
     *
     * @return void
     */
    public function setCruserId($cruserId)
    {
        $this->cruserId = $cruserId;
    }
}
</code>```

And my TCA:

```<code>'cruser_id' => [
    'exclude' => 1,
    'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:tx_fefiles_domain_model_photo.cruser_id',
    'config' => [
        'type' => 'group',
        'internal_type' => 'db',
        'allowed' => 'fe_users',
        'size' => 1,
        'minitems' => 0,
        'maxitems' => 1,
    ]
],
</code>```

That not works. I get error. I don't know what is this error because it not put in error log. I think may be I should write relation in ext_typoscript_setup.txt or somewhere? I think I should make reference somewhere, but I don't know

答:
There should be a clear error message.

In any case the > in \Fhk\Feusersplus\Domain\Model\User> is wrong and must be removed. Please try that first.

Body:
I have TYPO3 version 7.6.18, and  want get data with filtering by field on another relation table.

class PhotoRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
    public function getFiltered($offset = 0, $limit = 5){
        $query = $this->createQuery();
        $query->matching($query->in('cruserId.gender', 3));
        return $query->execute();
    }
}

Model:

class Photo extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{

    /**
     * CruserId
     *
     * @var \Fhk\Feusersplus\Domain\Model\User>
     */
    protected $cruserId;

    /**
     * Returns the cruserId
     *
     * @return \Fhk\Feusersplus\Domain\Model\User> $cruserId
     */
    public function getCruserId()
    {
        return $this->cruserId;
    }

    /**
     * Sets the cruserId
     *
     * @return void
     */
    public function setCruserId($cruserId)
    {
        $this->cruserId = $cruserId;
    }
}

And my TCA:

'cruser_id' => [
    'exclude' => 1,
    'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:tx_fefiles_domain_model_photo.cruser_id',
    'config' => [
        'type' => 'group',
        'internal_type' => 'db',
        'allowed' => 'fe_users',
        'size' => 1,
        'minitems' => 0,
        'maxitems' => 1,
    ]
],

That not works. I get error. I don't know what is this error because it not put in error log. I think may be I should write relation in ext_typoscript_setup.txt or somewhere? I think I should make reference somewhere, but I don't know


问:
Grouping switch statement cases together?
I may be over looking something but is there a simple way in C++ to group cases together instead of writing them out individually? I remember in basic I could just do:

```<code>SELECT CASE Answer
CASE 1, 2, 3, 4
</code>```

Example in C++ (For those that need it):

```<code>#include <iostream.h>
#include <stdio.h>
int main()
{
   int Answer;
   cout << "How many cars do you have?";
   cin >> Answer;
   switch (Answer)
      {
      case 1:
      case 2:
      case 3:
      case 4:
         cout << "You need more cars. ";
         break;
      case 5:
      case 6:
      case 7:
      case 8:
         cout << "Now you need a house. ";
         break;
      default:
         cout << "What are you? A peace-loving hippie freak? ";
      }
      cout << "\nPress ENTER to continue... " << endl;
      getchar();
      return 0;
}
</code>```

答: Your example is as concise as it gets with the switch construct.

Body:
I may be over looking something but is there a simple way in C++ to group cases together instead of writing them out individually? I remember in basic I could just do:

SELECT CASE Answer
CASE 1, 2, 3, 4

Example in C++ (For those that need it):

#include <iostream.h>
#include <stdio.h>
int main()
{
   int Answer;
   cout << "How many cars do you have?";
   cin >> Answer;
   switch (Answer)
      {
      case 1:
      case 2:
      case 3:
      case 4:
         cout << "You need more cars. ";
         break;
      case 5:
      case 6:
      case 7:
      case 8:
         cout << "Now you need a house. ";
         break;
      default:
         cout << "What are you? A peace-loving hippie freak? ";
      }
      cout << "\nPress ENTER to continue... " << endl;
      getchar();
      return 0;
}


问:
Match a pattern within any element of the data using data table rather than plyr
I have a very big data set and have not used data.table before. I am finding the syntax a bit difficult to follow. My main question is how can i reproduce the 'apply' function for a data table?

My data is as follows

```<code>dat1 <- structure(list(id = c(1L, 1L, 2L, 3L), diag1 = structure(1:4, .Label = c("I20.1","I21.3", "I48", "I60.8"), class = "factor"), diag2 = structure(c(3L,2L, 1L, 1L), .Label = c("", "I50", "I60.9"), class = "factor"), diag3 = structure(c(1L, 2L, 1L, 1L), .Label = c("", "I38.1"), class = "factor")), .Names = c("id", "diag1", "diag2", "diag3"), row.names = c(NA, -4L), class = "data.frame")
</code>```

I want to add a variable for all records that have a diagnostic code either within the columns diag1, diag2 or diag 3 of I20, I21 or I60. Using apply and regex i have done the following.

```<code>code.list <- c("I20","I21","I60")
dat1$index <- apply(dat1[2:4],1, function(i) any(grep(paste(code.list,
collapse="|"), i)))
</code>```

I get the final dataset that i want is illustrated as below

```<code>structure(list(id = c(1L, 1L, 2L, 3L), diag1 = structure(1:4, .Label = c("I20.1","I21.3", "I48", "I60.8"), class = "factor"), diag2 = structure(c(3L,2L, 1L, 1L), .Label = c("", "I50", "I60.9"), class = "factor"),diag3 = structure(c(1L, 2L, 1L, 1L), .Label = c("", "I38.1"), class = "factor"), index = c(TRUE, TRUE, FALSE, TRUE)), .Names = c("id","diag1", "diag2", "diag3", "index"), row.names = c(NA, -4L), class = "data.frame")
</code>```

However this is going to take far too long using plyr. I was hoping to get the syntax for a data table. Would anybody be able to help?

Thanks in advance

A

答:
We can do this with data.table

```<code>library(data.table)
setDT(dat1)[, index := Reduce(`|`, lapply(.SD, grepl,
         pattern = paste(code.list, collapse="|"))), .SDcols = 2:4]
dat1
#    id diag1 diag2 diag3 index
#1:  1 I20.1 I60.9        TRUE
#2:  1 I21.3   I50 I38.1  TRUE
#3:  2   I48             FALSE
#4:  3 I60.8              TRUE
</code>```

Body:
I have a very big data set and have not used data.table before. I am finding the syntax a bit difficult to follow. My main question is how can i reproduce the 'apply' function for a data table?

My data is as follows

dat1 <- structure(list(id = c(1L, 1L, 2L, 3L), diag1 = structure(1:4, .Label = c("I20.1","I21.3", "I48", "I60.8"), class = "factor"), diag2 = structure(c(3L,2L, 1L, 1L), .Label = c("", "I50", "I60.9"), class = "factor"), diag3 = structure(c(1L, 2L, 1L, 1L), .Label = c("", "I38.1"), class = "factor")), .Names = c("id", "diag1", "diag2", "diag3"), row.names = c(NA, -4L), class = "data.frame")

I want to add a variable for all records that have a diagnostic code either within the columns diag1, diag2 or diag 3 of I20, I21 or I60. Using apply and regex i have done the following.

code.list <- c("I20","I21","I60")
dat1$index <- apply(dat1[2:4],1, function(i) any(grep(paste(code.list,
collapse="|"), i)))

I get the final dataset that i want is illustrated as below

structure(list(id = c(1L, 1L, 2L, 3L), diag1 = structure(1:4, .Label = c("I20.1","I21.3", "I48", "I60.8"), class = "factor"), diag2 = structure(c(3L,2L, 1L, 1L), .Label = c("", "I50", "I60.9"), class = "factor"),diag3 = structure(c(1L, 2L, 1L, 1L), .Label = c("", "I38.1"), class = "factor"), index = c(TRUE, TRUE, FALSE, TRUE)), .Names = c("id","diag1", "diag2", "diag3", "index"), row.names = c(NA, -4L), class = "data.frame")

However this is going to take far too long using plyr. I was hoping to get the syntax for a data table. Would anybody be able to help?

Thanks in advance

A

Body:
We can do this with data.table

library(data.table)
setDT(dat1)[, index := Reduce(`|`, lapply(.SD, grepl,
         pattern = paste(code.list, collapse="|"))), .SDcols = 2:4]
dat1
#    id diag1 diag2 diag3 index
#1:  1 I20.1 I60.9        TRUE
#2:  1 I21.3   I50 I38.1  TRUE
#3:  2   I48             FALSE
#4:  3 I60.8              TRUE


问:
How to enable php run python script on GPU?
In my php website, I call a python script using theano and running on GPU.

However, when calling this python script from php, it seems apache doesn't have any permissions on GPU so the program falls back on CPU, which is far less efficient compared to GPU.

How can I grant apache rights to run programs on GPU?

答:
I would split that up, save the requirement as event in some storage (redis for example or even rabbitmq) and listen to that with some daemonized script (cron would be a bad joice since its hard to make it run more often than every minute). The script will update the storage entry with the results and you can access it again in your http stack. You can implement the functionallity via ajax or utilize a usleep command in php to wait for the results. If using a while loop, dont forget to break it after 1 second or something, so the request is not running too long.

Your problem might be the configured user, that executes the php binary - it maybe not permitted to access those binaries on your system. Typically its the www-data user. By adding the www-data user to the necessary group, you might be able to solve it without splitting all up. Have a look at the binary's ownerships and permissions to figure that out.


问:
Does assigning objects to null in Java impact garbage collection?
Does assigning an unused object reference to null in Java improve the garbage collection process in any measurable way?

My experience with Java (and C#) has taught me that is often counter intuitive to try and outsmart the virtual machine or JIT compiler, but I've seen co-workers use this method and I am curious if this is a good practice to pick up or one of those voodoo programming superstitions?

答:
At least in java, it's not voodoo programming at all.  When you create an object in java using something like

```<code>Foo bar = new Foo();
</code>```

you do two things: first, you create a reference to an object, and second, you create the Foo object itself.   So long as that reference or another exists, the specific object can't be gc'd.  however, when you assign null to that reference...

```<code>bar = null ;
</code>```

and assuming nothing else has a reference to the object, it's freed and available for gc the next time the garbage collector passes by.

OwnerDisplayName: nemo

LastEditorDisplayName: nemo

Body:
At least in java, it's not voodoo programming at all.  When you create an object in java using something like

Foo bar = new Foo();

you do two things: first, you create a reference to an object, and second, you create the Foo object itself.   So long as that reference or another exists, the specific object can't be gc'd.  however, when you assign null to that reference...

bar = null ;

and assuming nothing else has a reference to the object, it's freed and available for gc the next time the garbage collector passes by.

OwnerDisplayName: Charlie Martin


问:
XML Schema key/keyref - how to use them?
Long story short : i would like to know how to use the key/keyref from XSD to let elements have references to each other. it has to have a form of an example, using a simple xsd and an XML.

Long story : I am familiar with usage of ID/IDREF. I use those to connect elements for JAXB. I have been told repeatedly that the key/keyref construct in XSD offers enhanced flexibility for inter-element referencing. I have consulted the OReilly XML Schema book, that seems to teach everything about correct definition of key/keyref and how it is similar to the ID/IDREF (but better) and doesn't give a simple example of its use. It doesn't seem to be similar, because you define the ID as an attribute in one element and the IDREF in another element and voila. But key/keyref have to be defined in a common ancestor of the referencing and the referenced element (AFAIK)...

I use the XSD files to generate JAXB-bound Java classes with XJC

I have searched for how-tos, tutorials and examples, but google gives me scraps. same for searches on SO (also with google and inclusive search with '+' ).

In order to make everyone's lives easier i have prepared an XSD with already defined key/keyref pair as i have understood it.

```<code><xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="referenced">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:string" />
                </xs:complexType>
            </xs:element>
            <xs:element name="owner">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:string" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:key name="aKey">
        <xs:selector xpath="owner" />
        <xs:field xpath="@id" />
    </xs:key>
    <xs:keyref name="aKeyRef" refer="aKey">
        <xs:selector xpath="referenced" />
        <xs:field xpath="@id" />
    </xs:keyref>
</xs:element>
</code>```

How would a piece of XML look like, with an 'owner'-element referencing a 'referenced'-element?

EDIT :  applied the change proposed by Tom W, changing the xpath attribute of the key element to "owner". JAXB (XJC) still doesnt care though.

Thank you

答:
The JAXB spec does not explicitly cover key/keyref.  However JAXB implemenations such as EclipseLink MOXy (I'm the tech lead) have extensions for this.  Our upcoming 2.2 release provides a means to specify this kind of relationship via annotations (I'll put together an example).  Below is a link to how it can be done using the current release.

For more information see:

JAXB - Example of following a keyref when unmarshalling

UPDATE

I was hoping to get an example included with the answer, but I am running out of time before I leave on vacation.  Below is an example from our design documents that demonstrates the concept:

http://wiki.eclipse.org/EclipseLink/DesignDocs/317962/Phase3#Relationship_Mapping_Support

Body:
Long story short : i would like to know how to use the key/keyref from XSD to let elements have references to each other. it has to have a form of an example, using a simple xsd and an XML.

Long story : I am familiar with usage of ID/IDREF. I use those to connect elements for JAXB. I have been told repeatedly that the key/keyref construct in XSD offers enhanced flexibility for inter-element referencing. I have consulted the OReilly XML Schema book, that seems to teach everything about correct definition of key/keyref and how it is similar to the ID/IDREF (but better) and doesn't give a simple example of its use. It doesn't seem to be similar, because you define the ID as an attribute in one element and the IDREF in another element and voila. But key/keyref have to be defined in a common ancestor of the referencing and the referenced element (AFAIK)...

I use the XSD files to generate JAXB-bound Java classes with XJC

I have searched for how-tos, tutorials and examples, but google gives me scraps. same for searches on SO (also with google and inclusive search with '+' ).

In order to make everyone's lives easier i have prepared an XSD with already defined key/keyref pair as i have understood it.

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="referenced">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:string" />
                </xs:complexType>
            </xs:element>
            <xs:element name="owner">
                <xs:complexType>
                    <xs:attribute name="id" type="xs:string" />
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:key name="aKey">
        <xs:selector xpath="owner" />
        <xs:field xpath="@id" />
    </xs:key>
    <xs:keyref name="aKeyRef" refer="aKey">
        <xs:selector xpath="referenced" />
        <xs:field xpath="@id" />
    </xs:keyref>
</xs:element>

How would a piece of XML look like, with an 'owner'-element referencing a 'referenced'-element?

EDIT :  applied the change proposed by Tom W, changing the xpath attribute of the key element to "owner". JAXB (XJC) still doesnt care though.

Thank you


问:
Include TeX header in R package for RMarkdown documents
I want to create an R package containing a latex header file which would then be available from an RMarkdown document to create a PDF with slides via TeX. When I include a reference to the latex file in the header of the RMarkdown document, I can create my slides. But I do not know how to package it. So my two related questions are:

How can I put a LaTeX-file in an R package so that it can be accessed later?

How can I include the LaTeX file in a new RMarkdown document to create slides after loading the package (like a template)?

答:
Yes, you can. Do something like

```<code>---
output:
  beamer_presentation:
    includes:
      in_header: my_header.tex
---
</code>```

and the my_header.tex may be any (la)tex code, including package load and variable settings.  You can also have before_body: and more.

If you just want packages loaded there is also a simpler way via yaml but I don't have that handy as I use the above mechanism more often.

Body:
Yes, you can. Do something like

---
output:
  beamer_presentation:
    includes:
      in_header: my_header.tex
---

and the my_header.tex may be any (la)tex code, including package load and variable settings.  You can also have before_body: and more.

If you just want packages loaded there is also a simpler way via yaml but I don't have that handy as I use the above mechanism more often.

ContentLicense: CC BY-SA 4.0


问:
php - foreach loop, custom slide
It should be a slider, which shows all posts, but only 15 posts on each slide. I get all Posts.

(I use Wordpress functions.)

In the -div class = "slide"- there are 15 posts, after that a new -div class = "slide"- with 15 posts should be created.

Here is the code for all posts:

```<code>$myposts = get_posts($args);

$result = '<div id="fullpage">';
    $result .= '<div class="section" id="section1">';

        $result .= '<div class="slide">';
            foreach ($myposts as $post) {
                $result .= '<a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>';
                 //        the_post_thumbnail('full');
            }

        $result .= '</div>';
    $result .= ' </div>';

$result .= '</div>';

return $result;
</code>```

After 15 posts, I would like a new slide. I do not know how to adjust the foreach loop. Should I do this with an if statement, or can I do this with a foreach loop?

答:
Use a counter, and reset it after 15. (Not tested, I have no PHP at the moment)</p>

```<code>$counter = 1;
foreach ($myposts as $post) {
    if ($counter == 1) {
        $result .= '<div class="slide">';
    }
    $result .= '<a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>';
    $counter++;
    if ($counter == 16) {
        $counter = 1;
        $result .= '</div>';
    }
}
</code>```

Title: php - foreach loop, custom slide

Body:
It should be a slider, which shows all posts, but only 15 posts on each slide. I get all Posts.

(I use Wordpress functions.)

In the -div class = "slide"- there are 15 posts, after that a new -div class = "slide"- with 15 posts should be created.

Here is the code for all posts:

$myposts = get_posts($args);

$result = '
';
    $result .= '
';

        $result .= '
';
            foreach ($myposts as $post) {
                $result .= 'ID) . '">' . $post->post_title . '';
                 //        the_post_thumbnail('full');
            }

        $result .= '
';
    $result .= '
';

$result .= '
';

return $result;

After 15 posts, I would like a new slide. I do not know how to adjust the foreach loop. Should I do this with an if statement, or can I do this with a foreach loop?

Body:
Use a counter, and reset it after 15. (Not tested, I have no PHP at the moment)

$counter = 1;
foreach ($myposts as $post) {
    if ($counter == 1) {
        $result .= '<div class="slide">';
    }
    $result .= '<a href="' . get_permalink($post->ID) . '">' . $post->post_title . '</a>';
    $counter++;
    if ($counter == 16) {
        $counter = 1;
        $result .= '</div>';
    }
}


问:
error: src refspec master does not match any
I have tried to follow the solutions suggested in this post but it didnt work and I am still getting: src refspec master does not match any.

Here is what I did:
Followed this solution

```<code>// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.
</code>```

When doing:

```<code>$ git push origin HEAD:master
b40ffdf..a0d1423  HEAD -> master // looks promising

// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master does not match any.
</code>```

More information:

```<code>$ git branch
* origin

$ git show-ref
refs/heads/origin
refs/remotes/devstage/master
refs/remotes/origin/HEAD
refs/remotes/origin/devstage
refs/remotes/origin/master
refs/remotes/origin/origin
</code>```

So I am definitely missing refs/heads/master but dont know how to create it.

Thanks

答:
Run the command git show-ref, the result refs/heads/YOURBRANCHNAME
If your branch is not there, then you need to switch the branch by

```<code>git checkout -b "YOURBRANCHNAME"
</code>```

git show-ref, will now show your branch reference.

Now you can do the operations on your branch.

Body:
I have tried to follow the solutions suggested in this post but it didnt work and I am still getting: src refspec master does not match any.

Here is what I did:
Followed this solution

// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.

When doing:

$ git push origin HEAD:master
b40ffdf..a0d1423  HEAD -> master // looks promising

// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master does not match any.

More information:

$ git branch
* origin

$ git show-ref
refs/heads/origin
refs/remotes/devstage/master
refs/remotes/origin/HEAD
refs/remotes/origin/devstage
refs/remotes/origin/master
refs/remotes/origin/origin

So I am definitely missing refs/heads/master but dont know how to create it.

Thanks

Body:
Run the command git show-ref, the result refs/heads/YOURBRANCHNAME
If your branch is not there, then you need to switch the branch by

git checkout -b "YOURBRANCHNAME"

git show-ref, will now show your branch reference.

Now you can do the operations on your branch.


问:
How does this JS code look like in if...else format?
How would the following be written in an if/else format?

```<code>hours == 0 ? 12 : (hours > 12) ? hours - 12 : hours
</code>```

答:
You can also use brackets... look at the following sample </p>

```<code>console.log(((hours==0)*12)+((hours>12)*-12)+hours));
</code>```

Body:
How would the following be written in an if/else format?

hours == 0 ? 12 : (hours > 12) ? hours - 12 : hours

Body:
You can also use brackets... look at the following sample

console.log(((hours==0)*12)+((hours>12)*-12)+hours));


问:
Icons appear too small on Bootstrap navbar
How can I make the icons bigger and centered on the navbar?

There are no CSS rules that are associated to the navbar so why don't the icons show up the same as the other elements? I've tried several things but nothing seem to work.

in the following picture notice the icons on the right, they're not aligned with the other elements

Code:

```<code><header>
  <nav class = "navbar navbar-default navbar-fixed-top">
    <div class = "container">
      <div class = "navbar-header">
        <a class = "navbar-brand" href = "#">
          BRAND
        </a>
      </div>
      <ul class = "nav navbar-nav navbar-right">
        <li class = "text"><a href="#">ABCD</a></li>
        <li class = "text"><a href="#">EFGH</a></li>
        <li class = "text"><a href="#">IJKL</a></li>
        <li class = "text"><a href="#">MNOP</a></li>
        <li><i class = "fa fa-facebook"></i><li/>
        <li><i class = "fa fa-twitter"> </i><li/>
        <li><i class = "fa fa-instagram"> </i><li/>
      </ul>
    </div>
  </nav>
</header>
</code>```

答:
```<code>  <ul class = "nav navbar-nav navbar-right">
    <li class = "text"><a href="#">ABCD</a></li>
    <li class = "text"><a href="#">EFGH</a></li>
    <li class = "text"><a href="#">IJKL</a></li>
    <li class = "text"><a href="#">MNOP</a></li>
    <li><a href="#"><i class = "fa fa-facebook"></i></a><li/>
    <li><a href="#"><i class = "fa fa-twitter"> </i></a><li/>
    <li><a href="#"><i class = "fa fa-instagram"></i></a><li/>
  </ul>
</code>```

If you want to increase the size use

```<code>fa fa-instagram fa-2x
</code>```

or

```<code><i class = "fa fa-instagram" style="font-size:20px;"</i>
</code>```

Body:
How can I make the icons bigger and centered on the navbar?

There are no CSS rules that are associated to the navbar so why don't the icons show up the same as the other elements? I've tried several things but nothing seem to work.

in the following picture notice the icons on the right, they're not aligned with the other elements

Code:

          BRAND

ABCD

EFGH

IJKL

MNOP

Body:
  <ul class = "nav navbar-nav navbar-right">
    <li class = "text"><a href="#">ABCD</a></li>
    <li class = "text"><a href="#">EFGH</a></li>
    <li class = "text"><a href="#">IJKL</a></li>
    <li class = "text"><a href="#">MNOP</a></li>
    <li><a href="#"><i class = "fa fa-facebook"></i></a><li/>
    <li><a href="#"><i class = "fa fa-twitter"> </i></a><li/>
    <li><a href="#"><i class = "fa fa-instagram"></i></a><li/>
  </ul>

If you want to increase the size use

fa fa-instagram fa-2x

or

<i class = "fa fa-instagram" style="font-size:20px;"</i>


问:
CQRS - Read Model DTO Confusion
I have been reading up on CQRS and find many of the principles to be valuable. However, I have one major point of contention. Many people talk about having the read model queries map directly to view model dtos. So far, so good. However, where does the "one table or one select per view" come from that I constantly hear? Sure, some screens map 1-1 very easily. But I routinely work with some complex screens that would involve multiple selects for things like reference data in drop down lists, widgets, etc...

I could easily see my views needing multiple selects, maybe some with join or two.

How can you possibly avoid this, aside from working with perfect world scenarios where your views are simple and flat?

答:
But I routinely work with some complex
  screens that would involve multiple
  selects for things like reference data
  in drop down lists, widgets, etc...

Select lists, widgets, etc.  You can view these each as a view themselves nested in another view (possibly obvious if they are already their own partial).  When viewed that way, they can each have their own query.

Title: CQRS - Read Model DTO Confusion


问:
How can I make substitutions only within the scope of certain LaTeX command arguments?
The below Latex is written in one line, but it could have been over several.

The problem is # in caption commands have to be escaped, so the question is how to do this only within captions?

Or does there exist a Perl/Ruby module that can find the closing } in such a complicated case?

\caption{\small{Et elliptisk område i planen er afgrænset af en ellipse som er niveaukurven $\mathcal{K }_{0}(f)$ for andengradspolynomiet $f(x,y) = 2\cdot x^{2} + 2\cdot y^{2} + 2\cdot x\cdot y -8\cdot x -10 \cdot y + 13$. Se opgave \ref{exercEllipseLevel}  og  eksempel \href{./20-Keglesnit.pdf#evncount.20.1}{ 20.1} i eNote \ref{tn20}.}} \label{figEllipseLevel}

答:
Here is a brute force solution in Ruby, now that you have added the Ruby tag. It is not efficient, but safe and simple.

```<code>x.split('\caption').each_with_index.map { |str, i|
  next str if i == 0
  indent = 0
  end_caption = str.length
  str.split('').each_with_index do |c, ci|
    if c == '{'
      indent = indent + 1
    elsif c == '}'
      indent = indent - 1
      if (indent == 0)
        end_caption = ci
        break
      end
    end
  end
  str[0..(end_caption)].gsub(/([^\\])#/,'\1\\#')+ str[(end_caption+1)..-1]
}.join(‘\caption')
</code>```

or if you are looking for a one-liner, then

```<code>x.gsub(/\\caption\{((?:[^{}]+|\{\g<1>\})+)\}/m)  { |xx| Regexp.last_match[0].gsub(/([^\\])#/,’\1\\#’) }
</code>```

All of these of course requires that your Latex file can compile.

For Perl you could consider Text::Balanced

Body:
Here is a brute force solution in Ruby, now that you have added the Ruby tag. It is not efficient, but safe and simple.

x.split('\caption').each_with_index.map { |str, i|
  next str if i == 0
  indent = 0
  end_caption = str.length
  str.split('').each_with_index do |c, ci|
    if c == '{'
      indent = indent + 1
    elsif c == '}'
      indent = indent - 1
      if (indent == 0)
        end_caption = ci
        break
      end
    end
  end
  str[0..(end_caption)].gsub(/([^\\])#/,'\1\\#')+ str[(end_caption+1)..-1]
}.join(‘\caption')

or if you are looking for a one-liner, then

x.gsub(/\\caption\{((?:[^{}]+|\{\g<1>\})+)\}/m)  { |xx| Regexp.last_match[0].gsub(/([^\\])#/,’\1\\#’) }

All of these of course requires that your Latex file can compile.

For Perl you could consider Text::Balanced