问:
How best to instantiate a 2nd Vue instance for Non parent-child communication
I'm working through a tutorial to learn Vue 2.0 and just finished a lesson on communication using an event bus to allow for communication with components other than the immediate parent.

The code presented in the tutorial gave me an error however and I was able to solve it on my own as I'll explain below. I'd like to understand "why" the original code didn't work though just for my own learning and understanding.

The code given in the tutorial is as follows:

```<code>Window.Event = new Vue();

Vue.component('coupon', {

    template: '<input placeholder="Coupon Code" @blur="onCouponApplied">',

    methods: {
        onCouponApplied() {
            Event.$emit('applied');
        }
    }
});

var app = new Vue({
    el: '#root',

    created() {
        Event.$on('applied', () => alert('Handling it!'));
    }
});
</code>```

When I tried to run, I received an error: "TypeError: Event.$on is not a function". After researching online, I simply changed the instantiation of the first Vue instance to:

```<code>var bus = new Vue();
</code>```

and then referred to the emit / on as follows:

```<code>bus.$emit('applied');
</code>```

and

```<code>bus.$on('applied', () => alert('Handling it!'));
</code>```

For my own understanding, I'd appreciate some help with the following:

Why would the original Window.Event format not have worked for me
when it appears to have worked for others?

There were some comments in the comments section of this tutorial
along the lines of using Window.Event as not being a best practice,
but they didn't explain why.

Is there anything wrong with the way that I've done it, and is there
any functionality I'd be losing by not using the original
Window.Event?

Thanks!

答:
If the tutorial is literally recommending this exact line,

```<code>window.Event = new Vue()
</code>```

then they are recommending a bad idea. Event is a native browser object, if even if you could override it, you definitely should not. You would be replacing an object that many other libraries, including likely Vue itself, rely on.

If, on the other hand, you actually wrote this code

```<code>Window.Event = new Vue()
</code>```

then you added your Vue object to whatever Window is in your browser. Note the capital W. Window is not the same as window. Lowercase window refers to the global object in all browsers. In chrome, Window refers to something else (not sure exactly what).

So, when you try to call Event.$on(), you are referencing the native Event object I linked above, and not the bus you attempted to create, which results in your error.

Body:
I'm working through a tutorial to learn Vue 2.0 and just finished a lesson on communication using an event bus to allow for communication with components other than the immediate parent.

The code presented in the tutorial gave me an error however and I was able to solve it on my own as I'll explain below. I'd like to understand "why" the original code didn't work though just for my own learning and understanding.

The code given in the tutorial is as follows:

Window.Event = new Vue();

Vue.component('coupon', {

    template: '<input placeholder="Coupon Code" @blur="onCouponApplied">',

    methods: {
        onCouponApplied() {
            Event.$emit('applied');
        }
    }
});

var app = new Vue({
    el: '#root',

    created() {
        Event.$on('applied', () => alert('Handling it!'));
    }
});

When I tried to run, I received an error: "TypeError: Event.$on is not a function". After researching online, I simply changed the instantiation of the first Vue instance to:

var bus = new Vue();

and then referred to the emit / on as follows:

bus.$emit('applied');

and

bus.$on('applied', () => alert('Handling it!'));

For my own understanding, I'd appreciate some help with the following:

Why would the original Window.Event format not have worked for me
when it appears to have worked for others?

There were some comments in the comments section of this tutorial
along the lines of using Window.Event as not being a best practice,
but they didn't explain why.

Is there anything wrong with the way that I've done it, and is there
any functionality I'd be losing by not using the original
Window.Event?

Thanks!

Body:
If the tutorial is literally recommending this exact line,

window.Event = new Vue()

then they are recommending a bad idea. Event is a native browser object, if even if you could override it, you definitely should not. You would be replacing an object that many other libraries, including likely Vue itself, rely on.

If, on the other hand, you actually wrote this code

Window.Event = new Vue()

then you added your Vue object to whatever Window is in your browser. Note the capital W. Window is not the same as window. Lowercase window refers to the global object in all browsers. In chrome, Window refers to something else (not sure exactly what).

So, when you try to call Event.$on(), you are referencing the native Event object I linked above, and not the bus you attempted to create, which results in your error.


来源: stackexchange

问:
ruby uniq on the first two columns of two dimensional array
I have a two dimensional array with three fields in the second dimension.

Is it possible to use uniq on the first two fields of the second dimension?

I have seen array.uniq! {|c| c.first}. When I am correct, this apply uniq on the first field of the array.

Is it possible to use something like array.uniq! {|c| c.first c.second}?

@array = Array.new()

@array << Array.new([journal.from_account_number, journal.from_account,
                                journal.buchungsart])
There are several entries in @array.

The question was how to get unique values from array not considering journal.buchungsart.

The answer was: @array = @array.uniq! {|c| [c.first, c.second]}

答:
You could also make use of the fact that hash keys are unique.

```<code>arr = [[1, 2, 3],
       [2, 1, 4],
       [1, 2, 5]]

a = arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) }.values
  #=> [[1, 2, 5], [2, 1, 4]]
</code>```

See Hash#update (aka merge!).

Before extracting the hash values with Hash#value, we have computed the following hash.

```<code>arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) }
  #=> {[1, 2]=>[1, 2, 5], [2, 1]=>[2, 1, 4]}
</code>```

Notice that, for given values of the first two elements in a row, it is the last row of arr with those values that is to be "kept". The first such row in arr is to be kept, use the following.

```<code>arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) { |_,o,_| o } }.values
  #=> [[1, 2, 3], [2, 1, 4]]
</code>```

This does not mutate arr. If arr is to be modified, write

```<code>arr.replace(a)
</code>```

where a is defined above.

ContentLicense: CC BY-SA 3.0

Body:
You could also make use of the fact that hash keys are unique.

arr = [[1, 2, 3],
       [2, 1, 4],
       [1, 2, 5]]

a = arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) }.values
  #=> [[1, 2, 5], [2, 1, 4]]

See Hash#update (aka merge!).

Before extracting the hash values with Hash#value, we have computed the following hash.

arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) }
  #=> {[1, 2]=>[1, 2, 5], [2, 1]=>[2, 1, 4]}

Notice that, for given values of the first two elements in a row, it is the last row of arr with those values that is to be "kept". The first such row in arr is to be kept, use the following.

arr.each_with_object({}) { |row, h| h.update(row.first(2)=>row) { |_,o,_| o } }.values
  #=> [[1, 2, 3], [2, 1, 4]]

This does not mutate arr. If arr is to be modified, write

arr.replace(a)

where a is defined above.


问:
Get the device placement of a Tensorflow op programmatically
I want to write an assertion that ensures that certain ops in my graph will be run on a specific device. How can I determine programmatically the device placement of an op so that I can write such an assertion?</p>

答:
You can ensure that an operation is run on a specific device by using

```<code>with tf.device('/gpu:0'):
</code>```

before the definition of the operation (see here for more information).

edit:

Every available gpu has its own index: '/gpu:0', '/gpu:1', '/gpu:2' etc. This way you can bind specific operations to specific gpus. When you import tensorflow, it prints out which gpus are available and what index they are assigned.

(For example it prints: Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: ...))

Body:
You can ensure that an operation is run on a specific device by using

with tf.device('/gpu:0'):

before the definition of the operation (see here for more information).

edit:

Every available gpu has its own index: '/gpu:0', '/gpu:1', '/gpu:2' etc. This way you can bind specific operations to specific gpus. When you import tensorflow, it prints out which gpus are available and what index they are assigned.

(For example it prints: Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: ...))


问:
PHP jQuery ajax request is not responding
This jQuery ajax request is not working. The form submit just reloads the page, there are no alerts, nothing. Where am I going wrong?</p>

```<code>$("#newfolder").submit(function() {

    alert("1")

    $.ajax({
        type    : "POST",
        url     : "<?php echo $cfg->wwwroot ?>/pages/media/async/newfolder.php",
        data    : $(this).serializeArray(),
        success: function(data) {
            alert(data)
            //$.fancybox(data);
        }
    });

    return false;
});
</code>```

答:
This can have several causes.

Ensure that you've included jQuery as one of first
```</li>
<li><p>Ensure that you're calling this function when the document is ready loading.</p>

```<script>
    $(document).ready(function() {
        // Here.
    });
</script>
```</li>
<li><p>Ensure that the element with <code>id="newFolder"</code> is present in HTML DOM tree and supports the <code>submit</code> event.</p>

```<form id="newFolder">
```

ContentLicense: CC BY-SA 2.5

Body:
This jQuery ajax request is not working. The form submit just reloads the page, there are no alerts, nothing. Where am I going wrong?

$("#newfolder").submit(function() {

    alert("1")

    $.ajax({
        type    : "POST",
        url     : "<?php echo $cfg->wwwroot ?>/pages/media/async/newfolder.php",
        data    : $(this).serializeArray(),
        success: function(data) {
            alert(data)
            //$.fancybox(data);
        }
    });

    return false;
});

Body:
This can have several causes.

Ensure that you've included jQuery as one of first <script>s in HTML <head>.

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

Ensure that you're calling this function when the document is ready loading.

<script>
    $(document).ready(function() {
        // Here.
    });
</script>

Ensure that the element with id="newFolder" is present in HTML DOM tree and supports the submit event.

<form id="newFolder">


问:
Python 3 - create combination of list within dictionary and aggregate
I think I'm going about this all in a backwards way in pandas.  Here's an example dataframe:

```<code>Group rstart rend  qty
1     10000  11000 1000
1     10000  11000 8000
1     10000  11000 13000
1     10000  11000 1000
2     6000   8000  4000
2     6000   8000  9000
2     6000   8000  3000
</code>```

In the end I'm trying to identify the quantity or combination of quantities within the group that fall between the range and put a flag in a new column (and if possible save the combination in a new column too).

Here's what I have done so far and where I'm running into an issue - been trying out all different ways since I'm new to this language.

```<code>import pandas as pd
import numpy as np
import itertools

df = pd.read_csv('test.csv')
d = df[['group','qty']]
s = d.groupby('group')['qty'].apply(list).to_dict()
comb = list(map(dict,itertools.combinations(s.items(),2)))
</code>```

The comb stmt and multiple variations I tried are just printing the dictionary. Put 2 for two variations to test it out but not working - this would have to be adjusted based on the # of values in the list.

I brought in the dataset and then was thinking it would be best to create a dictionary with a list for each grouping and qty in order to create all the combinations in a separate table.  Once I have the combinations and sum of each of the values - link back to the main dataframe to compare against total and flag.

I'm running into issues with creating each combination of the quantities associated with the group and summing. I can perform it if stored in a list across all dictionaries but I need to grouped by the group. For instance, group 1 should have   1000,8000 and 1000,13000 and  1000,1000 and 1000,8000,13000 and so on. The amount of combinations can vary by group.

Can anyone assist with guiding me in the right direction? Maybe my thinking is off on how to go about this.

Thank you

答:
Here is one self explanatory solution which also uses itertools.combination in conjunction with list comprehensions:

```<code>def aggregate(sub_df):
    # get boundaries and actual values
    bound_low = sub_df["rstart"].iloc[0]
    bound_high = sub_df["rend"].iloc[0]
    values = sub_df["qty"].values

    # get possible combinations, iterate all lengths of combinations
    combis = [itertools.combinations(values, x+1)
              for x in range(len(values))]

    # flatten all combis and apply filter condition
    result = [combi for sub_combi in combis
              for combi in sub_combi
              if bound_low <= sum(combi) <= bound_high]

    return result

print(df.groupby("Group").apply(aggregate))

Group
1    [(1000, 8000, 1000)]
2          [(4000, 3000)]
dtype: object
</code>```

However, I don't understand your group 1 should have 1000,8000 and 1000,13000 and 1000,1000 and 1000,8000,13000 here.

Body:
I think I'm going about this all in a backwards way in pandas.  Here's an example dataframe:

Group rstart rend  qty
1     10000  11000 1000
1     10000  11000 8000
1     10000  11000 13000
1     10000  11000 1000
2     6000   8000  4000
2     6000   8000  9000
2     6000   8000  3000

In the end I'm trying to identify the quantity or combination of quantities within the group that fall between the range and put a flag in a new column (and if possible save the combination in a new column too).

Here's what I have done so far and where I'm running into an issue - been trying out all different ways since I'm new to this language.

import pandas as pd
import numpy as np
import itertools

df = pd.read_csv('test.csv')
d = df[['group','qty']]
s = d.groupby('group')['qty'].apply(list).to_dict()
comb = list(map(dict,itertools.combinations(s.items(),2)))

The comb stmt and multiple variations I tried are just printing the dictionary. Put 2 for two variations to test it out but not working - this would have to be adjusted based on the # of values in the list.

I brought in the dataset and then was thinking it would be best to create a dictionary with a list for each grouping and qty in order to create all the combinations in a separate table.  Once I have the combinations and sum of each of the values - link back to the main dataframe to compare against total and flag.

I'm running into issues with creating each combination of the quantities associated with the group and summing. I can perform it if stored in a list across all dictionaries but I need to grouped by the group. For instance, group 1 should have   1000,8000 and 1000,13000 and  1000,1000 and 1000,8000,13000 and so on. The amount of combinations can vary by group.

Can anyone assist with guiding me in the right direction? Maybe my thinking is off on how to go about this.

Thank you

Body:
Here is one self explanatory solution which also uses itertools.combination in conjunction with list comprehensions:

def aggregate(sub_df):
    # get boundaries and actual values
    bound_low = sub_df["rstart"].iloc[0]
    bound_high = sub_df["rend"].iloc[0]
    values = sub_df["qty"].values

    # get possible combinations, iterate all lengths of combinations
    combis = [itertools.combinations(values, x+1)
              for x in range(len(values))]

    # flatten all combis and apply filter condition
    result = [combi for sub_combi in combis
              for combi in sub_combi
              if bound_low <= sum(combi) <= bound_high]

    return result

print(df.groupby("Group").apply(aggregate))

Group
1    [(1000, 8000, 1000)]
2          [(4000, 3000)]
dtype: object

However, I don't understand your group 1 should have 1000,8000 and 1000,13000 and 1000,1000 and 1000,8000,13000 here.


问:
What is wrong with my JavaScript? Function not working
I am trying to get it so that when I click on a box, it'l turn black.

function colorize() {
  document.getElementsByClassName('boardpic').innerHTML.src = "images/black.png";
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{
  font-family: 'Raleway', sans-serif;
  margin: 0;
  background: #87e0fd;
  background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 74%,#05abe0 100%);
  background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 74%,#05abe0 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 );
}

#title{
  text-align: center;
  font-size: 96px;
  margin-bottom: 12px;
}

.boardpic{
  margin: 0;
  padding: 0;
  width: 32px;
  height: 32px;
}

#container{
  display: flex;
}

#board{
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  background-color: white;
  padding: 3px;
  width: 512px;
  height: 512px;
  font-size: 0;
  margin: auto;
  margin-bottom: 12px;
}

#colorpicker{
  font-size: 0;
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  width: 256px;
  margin: auto;
}</code>```

    <title>
      Drawify | 0.0.1
    </title>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <link href="https://fonts.googleapis.com/css?family=Raleway:700" rel="stylesheet">

      Drawify

```

Whenever I click, the box doesn't change

I was pretty sure I was setting it up all right, but I guess not. So yeah, I am quite new to coding, so please explain with simple terms. :)

答:
Write your function like this:

```<code>function colorize(element) {
  element.src = "images/black.png";
}
</code>```

and then as onclick event add this:

```<code><img class="boardpic" src="images/white.png" onclick="colorize(this)" />
</code>```

to each img element you want to change on click.

Body:
I am trying to get it so that when I click on a box, it'l turn black.

function colorize() {
  document.getElementsByClassName('boardpic').innerHTML.src = "images/black.png";
}

body{
  font-family: 'Raleway', sans-serif;
  margin: 0;
  background: #87e0fd;
  background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 74%,#05abe0 100%);
  background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 74%,#05abe0 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 );
}

#title{
  text-align: center;
  font-size: 96px;
  margin-bottom: 12px;
}

.boardpic{
  margin: 0;
  padding: 0;
  width: 32px;
  height: 32px;
}

#container{
  display: flex;
}

#board{
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  background-color: white;
  padding: 3px;
  width: 512px;
  height: 512px;
  font-size: 0;
  margin: auto;
  margin-bottom: 12px;
}

#colorpicker{
  font-size: 0;
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  width: 256px;
  margin: auto;
}

    <title>
      Drawify | 0.0.1
    </title>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <link href="https://fonts.googleapis.com/css?family=Raleway:700" rel="stylesheet">

      Drawify

Whenever I click, the box doesn't change

I was pretty sure I was setting it up all right, but I guess not. So yeah, I am quite new to coding, so please explain with simple terms. :)

Body:
Write your function like this:

function colorize(element) {
  element.src = "images/black.png";
}

and then as onclick event add this:

<img class="boardpic" src="images/white.png" onclick="colorize(this)" />

to each img element you want to change on click.


问:
almost same code. but the other one does not produce an output in returning a child function
I am studying closures in Javascript and I saw this code example for closure  with an output of integer "2"

```<code>function foo() {
    var a = 2;

    function bar() {
        console.log( a );
    }
    return bar;
}

var baz = foo();
baz();
</code>```

And I try to modify it to see if i can see a same result by removing the var baz which function foo(); is passed, to reduce the code cause i think it has the same logic. But after changing it, it does not give me any output. Here is the code

```<code>function foo() {
    var a = 2;

    function bar() {
        console.log( a );
    }
    return bar;
}

foo();
</code>```

I was expecting to see the same result. since var baz is referencing the foo() function then why not remove the var baz and just execute the foo(); function. but i didnt give any output at all. can someone enlighten me what happens here?

答:
What you are experiencing is the difference between calling and not calling a function. Indeed doing

```<code>var baz = foo();
</code>```

stores the callable named bar in the variable baz. Then doing

```<code>baz()
</code>```

calls/invokes it.

Actually, as outlined by squint, you can directly call the callable bar returned by the function foo via doing

```<code>foo()()
</code>```

more details

Consider the function foo you defined. As such, foo can also be considered/used as a callable. If I do

```<code>var fou = foo;
</code>```

Then I can call the function foo contained in the variable fou by doing

```<code>var baz = fou();
</code>```

Henceforth, the callable bar is contained in the variable baz.

Body:
I am studying closures in Javascript and I saw this code example for closure  with an output of integer "2"

function foo() {
    var a = 2;

    function bar() {
        console.log( a );
    }
    return bar;
}

var baz = foo();
baz();

And I try to modify it to see if i can see a same result by removing the var baz which function foo(); is passed, to reduce the code cause i think it has the same logic. But after changing it, it does not give me any output. Here is the code

function foo() {
    var a = 2;

    function bar() {
        console.log( a );
    }
    return bar;
}

foo();

I was expecting to see the same result. since var baz is referencing the foo() function then why not remove the var baz and just execute the foo(); function. but i didnt give any output at all. can someone enlighten me what happens here?

Body:
What you are experiencing is the difference between calling and not calling a function. Indeed doing

var baz = foo();

stores the callable named bar in the variable baz. Then doing

baz()

calls/invokes it.

Actually, as outlined by squint, you can directly call the callable bar returned by the function foo via doing

foo()()

more details

Consider the function foo you defined. As such, foo can also be considered/used as a callable. If I do

var fou = foo;

Then I can call the function foo contained in the variable fou by doing

var baz = fou();

Henceforth, the callable bar is contained in the variable baz.


问:
PetSc installation Failed with MacPort can anyone help?
I'm trying to install PetSc with MacPorts. My final goal is to install libMesh on my Mac. When I'm trying to install PetSc its failing during configuration. I need to get PetSc installed before any attempt to install libMesh.

Here is the error part of the log.

```<code>:info:configure TESTING: checkFortranLibraries from config.compilers(/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4/config/BuildSystem/config/compilers.py:624)
:info:configure *******************************************************************************
:info:configure                     UNABLE to EXECUTE BINARIES for config/configure.py
:info:configure -------------------------------------------------------------------------------
:info:configure Cannot run executables created with C. If this machine uses a batch system
:info:configure to submit jobs you will need to configure using/configure.py with the additional option  --with-batch.
:info:configure  Otherwise there is problem with the compilers. Can you compile and run code with your C/C++ (and maybe Fortran) compilers?
:info:configure *******************************************************************************
:info:configure
:info:configure shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4" && /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4/config/configure.py --prefix=/opt/local --with-python --with-c-support=1 --with-c++-support=1 --with-pic=fPIC --with-shared=1 --prefix=/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/destroot/opt/local/lib/petsc --with-cc=/opt/local/bin/openmpicc --with-cxx=/opt/local/bin/openmpicxx --with-mpiexec=/opt/local/bin/openmpiexec --with-hdf5=1 --with-hdf5-dir=/opt/local --LIBS=-lsz --with-triangle=1 --with-triangle-dir=/opt/local --with-debugging=1 " returned error 1
:error:configure Target org.macports.configure returned: configure failure: shell command failed (see log for details)
:debug:configure Backtrace: configure failure: shell command failed (see log for details)
while executing
"$procedure $targetname"
:info:configure Warning: the following items did not execute (for petsc): org.macports.activate org.macports.configure org.macports.build org.macports.destroot org.macports.install
:notice:configure Log for petsc is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/main.log
</code>```

I'm running Mac OS 10.6.5 with Xcode 3.2.4. My MacPorts version is 1.9.2 the latest one.

Please help.

答:
You might be running up against bug #237223; adding -lstdc++ to LDFLAGS might help, in that case. Also, make sure you have a working gfortran in your path. Consider filing a bug against the port over at MacPorts, as well.

The log file mentioned in the last line would help in diagnosing this, as would some of the context from the Python file that's running the test. Output from an attempted installation with the -d and -v flags passed to port might also help.

Body:
I'm trying to install PetSc with MacPorts. My final goal is to install libMesh on my Mac. When I'm trying to install PetSc its failing during configuration. I need to get PetSc installed before any attempt to install libMesh.

Here is the error part of the log.

:info:configure TESTING: checkFortranLibraries from config.compilers(/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4/config/BuildSystem/config/compilers.py:624)
:info:configure *******************************************************************************
:info:configure                     UNABLE to EXECUTE BINARIES for config/configure.py
:info:configure -------------------------------------------------------------------------------
:info:configure Cannot run executables created with C. If this machine uses a batch system
:info:configure to submit jobs you will need to configure using/configure.py with the additional option  --with-batch.
:info:configure  Otherwise there is problem with the compilers. Can you compile and run code with your C/C++ (and maybe Fortran) compilers?
:info:configure *******************************************************************************
:info:configure
:info:configure shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4" && /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/petsc-3.1-p4/config/configure.py --prefix=/opt/local --with-python --with-c-support=1 --with-c++-support=1 --with-pic=fPIC --with-shared=1 --prefix=/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/work/destroot/opt/local/lib/petsc --with-cc=/opt/local/bin/openmpicc --with-cxx=/opt/local/bin/openmpicxx --with-mpiexec=/opt/local/bin/openmpiexec --with-hdf5=1 --with-hdf5-dir=/opt/local --LIBS=-lsz --with-triangle=1 --with-triangle-dir=/opt/local --with-debugging=1 " returned error 1
:error:configure Target org.macports.configure returned: configure failure: shell command failed (see log for details)
:debug:configure Backtrace: configure failure: shell command failed (see log for details)
while executing
"$procedure $targetname"
:info:configure Warning: the following items did not execute (for petsc): org.macports.activate org.macports.configure org.macports.build org.macports.destroot org.macports.install
:notice:configure Log for petsc is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_petsc/main.log

I'm running Mac OS 10.6.5 with Xcode 3.2.4. My MacPorts version is 1.9.2 the latest one.

Please help.


答:
Pass this as argument or use event.target to get clicked element!

getElementsByClassName returns array like collection hence you can not apply DOM methods directly on it, iteration of collection will be needed.

innerHTML.src is invalid syntax too, innerHTML returns String!

function colorize(e) {
  e = e || window.event;
  e.target.src = "images/black.png";
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  font-family: 'Raleway', sans-serif;
  margin: 0;
  background: #87e0fd;
  background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: -webkit-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: linear-gradient(to bottom, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0', GradientType=0);
}

#title {
  text-align: center;
  font-size: 96px;
  margin-bottom: 12px;
}

.boardpic {
  margin: 0;
  padding: 0;
  width: 32px;
  height: 32px;
}

#container {
  display: flex;
}

#board {
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  background-color: white;
  padding: 3px;
  width: 512px;
  height: 512px;
  font-size: 0;
  margin: auto;
  margin-bottom: 12px;
}

#colorpicker {
  font-size: 0;
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  width: 256px;
  margin: auto;
}</code>```

  <title>
    Drawify | 0.0.1
  </title>
  <link rel="stylesheet" type="text/css" href="styles.css">
  <link href="https://fonts.googleapis.com/css?family=Raleway:700" rel="stylesheet">

    Drawify

```

Title: What is wrong with my JavaScript? Function not working

Body:
Pass this as argument or use event.target to get clicked element!

getElementsByClassName returns array like collection hence you can not apply DOM methods directly on it, iteration of collection will be needed.

innerHTML.src is invalid syntax too, innerHTML returns String!

function colorize(e) {
  e = e || window.event;
  e.target.src = "images/black.png";
}

body {
  font-family: 'Raleway', sans-serif;
  margin: 0;
  background: #87e0fd;
  background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: -webkit-linear-gradient(top, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  background: linear-gradient(to bottom, #87e0fd 0%, #53cbf1 74%, #05abe0 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0', GradientType=0);
}

#title {
  text-align: center;
  font-size: 96px;
  margin-bottom: 12px;
}

.boardpic {
  margin: 0;
  padding: 0;
  width: 32px;
  height: 32px;
}

#container {
  display: flex;
}

#board {
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  background-color: white;
  padding: 3px;
  width: 512px;
  height: 512px;
  font-size: 0;
  margin: auto;
  margin-bottom: 12px;
}

#colorpicker {
  font-size: 0;
  border-color: black;
  border-width: 3px;
  border-radius: 3px;
  border-style: solid;
  width: 256px;
  margin: auto;
}

<html>

<head>
  <title>
    Drawify | 0.0.1
  </title>
  <link rel="stylesheet" type="text/css" href="styles.css">
  <link href="https://fonts.googleapis.com/css?family=Raleway:700" rel="stylesheet">
</head>

<body>
  <h1 id="title">
    Drawify
  </h1>
  <div id="container">
    <div id="board">
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
      <div class="line">
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
        <img class="boardpic" src="images/white.png" onclick="colorize()" />
      </div>
    </div>
  </div>
  <div id="colorpicker">
    <div class="colorpickerline">
      <img src="images/red.png" />
      <img src="images/orange.png" />
      <img src="images/yellow.png" />
      <img src="images/green.png" />
      <img src="images/blue.png" />
      <img src="images/purple.png" />
      <img src="images/white.png" />
      <img src="images/black.png" />
    </div>
  </div>
  <script src="code.js">
  </script>
</body>

</html>


问:
zuul API Gateway Filter
I am facing problem when i trying to access another REST API(registered in ZUUL route) from zuul pre-filter, the call is becoming recursive i.e its running my pre-filter code again and again. My Usecase is as follows-

In Zuul PreFilter run() method, I am validating the token passed in the header.

After validating the token, I am calling one rest service(User Location Service) to fetch the user details. My User Location Service is itself registered in ZUUL as below:

```<code>user-location-service:
  path: /userLocationService/**
  url: http://localhost:9002
</code>```

The problem is that the JWT token validation code is running again and again, Can you please suggest some solution where I can apply the call Userlocation service so that the PreFilter code would not run again and again?

答:
you need to allow sensitiveHeaders. </p>

```<code>     zuul:
        routes:
            resource:
                path: /resource/**
                url: http://localhost:8002/
                sensitiveHeaders: Cookie,Set-Cookie
</code>```

Title: zuul API Gateway Filter

Body:
I am facing problem when i trying to access another REST API(registered in ZUUL route) from zuul pre-filter, the call is becoming recursive i.e its running my pre-filter code again and again. My Usecase is as follows-

In Zuul PreFilter run() method, I am validating the token passed in the header.

After validating the token, I am calling one rest service(User Location Service) to fetch the user details. My User Location Service is itself registered in ZUUL as below:

user-location-service:
  path: /userLocationService/**
  url: http://localhost:9002

The problem is that the JWT token validation code is running again and again, Can you please suggest some solution where I can apply the call Userlocation service so that the PreFilter code would not run again and again?

Body:
you need to allow sensitiveHeaders.

     zuul:
        routes:
            resource:
                path: /resource/**
                url: http://localhost:8002/
                sensitiveHeaders: Cookie,Set-Cookie


问:
How to include plain text file in emacs org-mode
I am using emacs org-mode with taskjuggler export. I like to include multiple org files into one main org-file and export all content into one taskjuggler file, so I can seperate e.g. sources from projects.

I thought about using the #+INCLUDE: macro, but this one includes additional header information like the source filename. I was able to remove author and timestamp by customizing the export, but I can not get rid of the filename.

Question: what would be a good solution to include org-files so I can use them with taskjuggler export?

答:
This doesn't directly answer your question, but fits under the title for anyone that ends up here.

I modified @cm2 's answer to use pygmentize vs cat, then used display-ansi-colors to remove the ANSI color codes. eg:

```<code>#+BEGIN_SRC shell :results raw
pygmentize Test.java
#+END_SRC

#+RESULTS:
public class Test {
  public static void main(String[] args)
  {
String result = "hello";
    System.out.print(result);
  }
}
</code>```

Body:
This doesn't directly answer your question, but fits under the title for anyone that ends up here.

I modified @cm2 's answer to use pygmentize vs cat, then used display-ansi-colors to remove the ANSI color codes. eg:

#+BEGIN_SRC shell :results raw
pygmentize Test.java
#+END_SRC

#+RESULTS:
public class Test {
  public static void main(String[] args)
  {
String result = "hello";
    System.out.print(result);
  }
}


问:
Infinite loop in haskell program
The following code gives me a stack overflow error in some cases (ex hosum (\x->x `mod` 3) 1000 ) and I don't understand why. Could anyone explain this to me? (I am new to Haskell and I'd appreciate any help :) )

```<code> hosum :: (Int -> Int) ->  (Int -> Int)
    hosum f  = (\x -> hs f x (- x))
            where hs :: (Int -> Int) -> Int -> Int -> Int
                  hs f 0 0 = f 0
                  hs f n m
                          | m <= n
                          = f m + hs f n (m+1)
                          | n <= m
                          = f n + hs f (n+1) m
                          | otherwise
                          = 0
</code>```

答:
The stack overflow is likely caused by the infinite recursion. Your guards are m <= n and n <= m; for every n and m, one of those is always true. Your otherwise is never reached, the recursion never terminates. You probably meant your guards to be m < n and n < m.

Your hs should therefore be

```<code>hs f 0 0 = f 0
hs f n m | m < n     = f m + hs f n (m + 1)
         | m > n     = f n + hs f (n + 1) m
         | otherwise = 0
</code>```

Because of that last guard, you could even remove the pattern hs f 0 0; the otherwise catches that one.

Title: Infinite loop in haskell program

Body:
The following code gives me a stack overflow error in some cases (ex hosum (\x->x `mod` 3) 1000 ) and I don't understand why. Could anyone explain this to me? (I am new to Haskell and I'd appreciate any help :) )

 hosum :: (Int -> Int) ->  (Int -> Int)
    hosum f  = (\x -> hs f x (- x))
            where hs :: (Int -> Int) -> Int -> Int -> Int
                  hs f 0 0 = f 0
                  hs f n m
                          | m <= n
                          = f m + hs f n (m+1)
                          | n <= m
                          = f n + hs f (n+1) m
                          | otherwise
                          = 0

Body:
The stack overflow is likely caused by the infinite recursion. Your guards are m <= n and n <= m; for every n and m, one of those is always true. Your otherwise is never reached, the recursion never terminates. You probably meant your guards to be m < n and n < m.

Your hs should therefore be

hs f 0 0 = f 0
hs f n m | m < n     = f m + hs f n (m + 1)
         | m > n     = f n + hs f (n + 1) m
         | otherwise = 0

Because of that last guard, you could even remove the pattern hs f 0 0; the otherwise catches that one.


问:
traverse list in scala and group all the first elements and second elements
This might be pretty simple questions. I have a list named "List1" that contain list of integer pairs as below.

List1 = List((1,2), (3,4), (9,8), (9,10))

Output should be:

r1 = (1,3,9,9)      //List((1,2), (3,4), (9,8), (9,10))

    r2 = (2,4,8,10)     //List((1,2), (3,4), (9,8), (9,10))

```<code>array r1(Array[int]) should contains set of all first integers of each pair in the list.
array r2(Array[int]) should contains set of all second integers of each pair
</code>```

答:
Use foldLeft

```<code>val (alist, blist) = list1.foldLeft((List.empty[Int], List.empty[Int])) { (r, c) => (r._1 ++ List(c._1), r._2 ++ List(c._2))}
</code>```

Scala REPL

```<code>scala> val list1 = List((1, 2), (3, 4), (5, 6))
list1: List[(Int, Int)] = List((1,2), (3,4), (5,6))

scala> val (alist, blist) = list1.foldLeft((List.empty[Int], List.empty[Int])) { (r, c) => (r._1 ++ List(c._1), r._2 ++ List(c._2))}
alist: List[Int] = List(1, 3, 5)
blist: List[Int] = List(2, 4, 6)
</code>```

Body:
This might be pretty simple questions. I have a list named "List1" that contain list of integer pairs as below.

List1 = List((1,2), (3,4), (9,8), (9,10))

Output should be:

r1 = (1,3,9,9)      //List((1,2), (3,4), (9,8), (9,10))

    r2 = (2,4,8,10)     //List((1,2), (3,4), (9,8), (9,10))

array r1(Array[int]) should contains set of all first integers of each pair in the list.
array r2(Array[int]) should contains set of all second integers of each pair

Body:
Use foldLeft

val (alist, blist) = list1.foldLeft((List.empty[Int], List.empty[Int])) { (r, c) => (r._1 ++ List(c._1), r._2 ++ List(c._2))}

Scala REPL

scala> val list1 = List((1, 2), (3, 4), (5, 6))
list1: List[(Int, Int)] = List((1,2), (3,4), (5,6))

scala> val (alist, blist) = list1.foldLeft((List.empty[Int], List.empty[Int])) { (r, c) => (r._1 ++ List(c._1), r._2 ++ List(c._2))}
alist: List[Int] = List(1, 3, 5)
blist: List[Int] = List(2, 4, 6)


问:
arp command - what does it all mean? *and* getting a wireless router MAC address from IP
When I type in arp -a in my bash shell, I get output that looks like the following:

```<code>? (10.0.0.1) at 0:f0:7f:43:e8:68 on en1 ifscope [ethernet]
box1.google.com (10.0.0.3) at 0:1f:fe:fe:ca:d4 on en1 ifscope [ethernet]
box2.google.com (10.0.0.2) at 0:2:a3:45:90:bf on en1 ifscope [ethernet]
box3.google.com (10.0.0.50) at 78:e7:df:7c:34:c on en1 ifscope [ethernet]
box4.google.com (10.0.0.230) at 0:80:74:c9:50:d5 on en1 ifscope [ethernet]
box5.google.com (10.0.0.256) at 0:23:df:91:4f:9e on en1 ifscope [ethernet]
box6.google.com (10.0.0.458) at 0:15:9:89:36:68 on en1 ifscope [ethernet]
? (10.0.0.179) at 0:2a:32:f0:f4:d0 on en1 ifscope [ethernet]
box7.google.com (10.0.0.283) at 0:27:16:66:2d:ef on en1 ifscope [ethernet]
box8.google.com (10.0.0.386) at 0:13:eb:91:d8:b5 on en1 ifscope [ethernet]
box9.google.com (10.0.0.287) at 0:1c:25:10:d8:89 on en1 ifscope [ethernet]
? (10.0.0.255) at (incomplete) on en1 ifscope [ethernet]
? (172.17.122.255) at (incomplete) on vmnet8 ifscope [ethernet]
? (172.17.254.1) at 0:50:56:c0:0:1 on vmnet1 ifscope permanent [ethernet]
? (172.17.254.255) at (incomplete) on vmnet1 ifscope [ethernet]
</code>```

What does all of this mean?  I loosely understand that I'm seeing domain names, IP addresses (internal IP addresses?), and MAC addresses.  How do I find the MAC address for the wireless router that I'm connected to?  Why are there so many entries here?  I figured that there would only be one for my computer, one for the wireless router, one for the cable modem, and then possibly some other things upstream... but I'm seeing other computers that are not mine.  Furthermore, I am not seeing my computer.  Also, could I somehow use information like this to find the MAC addresses for wireless routers in public?  What if I can not connect to said public routers?

答:
At a guess 10.0.0.1 looks like the gateway.
Why do you want to find the MAC address for the router you are on?
Also, if you cannot connect to a wireless router then you won't be able to find it with this command, there are some other commands you can use to scan for wireless signals.
You don't see your computer on there because this is your local arp table, why would you need to know where you are? You're already there.</p>

Body:
When I type in arp -a in my bash shell, I get output that looks like the following:

? (10.0.0.1) at 0:f0:7f:43:e8:68 on en1 ifscope [ethernet]
box1.google.com (10.0.0.3) at 0:1f:fe:fe:ca:d4 on en1 ifscope [ethernet]
box2.google.com (10.0.0.2) at 0:2:a3:45:90:bf on en1 ifscope [ethernet]
box3.google.com (10.0.0.50) at 78:e7:df:7c:34:c on en1 ifscope [ethernet]
box4.google.com (10.0.0.230) at 0:80:74:c9:50:d5 on en1 ifscope [ethernet]
box5.google.com (10.0.0.256) at 0:23:df:91:4f:9e on en1 ifscope [ethernet]
box6.google.com (10.0.0.458) at 0:15:9:89:36:68 on en1 ifscope [ethernet]
? (10.0.0.179) at 0:2a:32:f0:f4:d0 on en1 ifscope [ethernet]
box7.google.com (10.0.0.283) at 0:27:16:66:2d:ef on en1 ifscope [ethernet]
box8.google.com (10.0.0.386) at 0:13:eb:91:d8:b5 on en1 ifscope [ethernet]
box9.google.com (10.0.0.287) at 0:1c:25:10:d8:89 on en1 ifscope [ethernet]
? (10.0.0.255) at (incomplete) on en1 ifscope [ethernet]
? (172.17.122.255) at (incomplete) on vmnet8 ifscope [ethernet]
? (172.17.254.1) at 0:50:56:c0:0:1 on vmnet1 ifscope permanent [ethernet]
? (172.17.254.255) at (incomplete) on vmnet1 ifscope [ethernet]

What does all of this mean?  I loosely understand that I'm seeing domain names, IP addresses (internal IP addresses?), and MAC addresses.  How do I find the MAC address for the wireless router that I'm connected to?  Why are there so many entries here?  I figured that there would only be one for my computer, one for the wireless router, one for the cable modem, and then possibly some other things upstream... but I'm seeing other computers that are not mine.  Furthermore, I am not seeing my computer.  Also, could I somehow use information like this to find the MAC addresses for wireless routers in public?  What if I can not connect to said public routers?


问:
python (bottle) - asynchronous respose - handling client-side (javascript)
I found this example on the Bottle docs re asynchronous responses.

Here is the code slightly modified:

```<code>from gevent import monkey; monkey.patch_all()

from time import sleep
from bottle import hook, response, route, run

@route('/stream')
def stream():
    yield 'START'
    sleep(3)
    yield '\nPROGRESS 1'
    sleep(3)
    yield '\nPROGRESS 2'
    sleep(3)
    yield '\nPROGRESS 3'
    sleep(3)
    yield '\nEND'

run(host='0.0.0.0', port=8080, server='gevent')
</code>```

calling this view from the browser works as explained in the docs:

If you run this script and point your browser to
  http://localhost:8080/stream, you should see START, MIDDLE, and END
  show up one by one (rather than waiting 8 seconds to see them all at
  once).

I was wondering how to handle this via Javascript in an AJAX request, specifically with JQuery, in order to display the messages in sequence.

ANy help about that?

答:
jQuery doesn't support that, but you can do that with plain XHR:

```<code>var xhr = new XMLHttpRequest()
xhr.open("GET", "/test/chunked", true)
xhr.onprogress = function () {
  console.log("PROGRESS:", xhr.responseText)
}
xhr.send()
</code>```

This works in all modern browsers, including IE 10. W3C specification here.

The downside here is that xhr.responseText contains an accumulated
response. You can use substring on it, but a better idea is to use the
responseType attribute and use slice on an ArrayBuffer.

SOURCE: How to write javascript in client side to receive and parse `chunked` response in time?

Body:
I found this example on the Bottle docs re asynchronous responses.

Here is the code slightly modified:

from gevent import monkey; monkey.patch_all()

from time import sleep
from bottle import hook, response, route, run

@route('/stream')
def stream():
    yield 'START'
    sleep(3)
    yield '\nPROGRESS 1'
    sleep(3)
    yield '\nPROGRESS 2'
    sleep(3)
    yield '\nPROGRESS 3'
    sleep(3)
    yield '\nEND'

run(host='0.0.0.0', port=8080, server='gevent')

calling this view from the browser works as explained in the docs:

If you run this script and point your browser to
  http://localhost:8080/stream, you should see START, MIDDLE, and END
  show up one by one (rather than waiting 8 seconds to see them all at
  once).

I was wondering how to handle this via Javascript in an AJAX request, specifically with JQuery, in order to display the messages in sequence.

ANy help about that?

Body:
jQuery doesn't support that, but you can do that with plain XHR:

var xhr = new XMLHttpRequest()
xhr.open("GET", "/test/chunked", true)
xhr.onprogress = function () {
  console.log("PROGRESS:", xhr.responseText)
}
xhr.send()

This works in all modern browsers, including IE 10. W3C specification here.

The downside here is that xhr.responseText contains an accumulated
response. You can use substring on it, but a better idea is to use the
responseType attribute and use slice on an ArrayBuffer.

SOURCE: How to write javascript in client side to receive and parse `chunked` response in time?


问:
How to internationalize string in coffeescript with i18n value?
My problem is fairly simple: I have a string in one of my coffeescripts that I need to internationalize with an i18n value in my Rails application. Here's my code:

```<code> $ ->
      $("#order_accepted_terms").on 'invalid', ->
        this.setCustomValidity('Die AGB müssen akzeptiert werden.')
</code>```

Anyone got any ideas?

答:
In my opinion, a better way (and one that doesn't require yet another gem, remember - performance) is to include an object with internationalized messages as a global scoped javascript variable. So you'd go about it this way (for Ruby on Rails):

 1. in your application.html.erb add  tags right after title (before any other javascript files are referenced)

 2. add a global scope variable object within those inline script tags in head

```<code>generalMessages = {
    someMessage: '<%= t 'path.to.some_message_in_yml' %>',
    anotherMessage: '<%= t 'path.another_message' %>'
}
</code>```

3. reference the variable (in javascript/coffeescript/typescript) as:

```<code>foo = generalMessages.someMessage
</code>```

Voila.

A similar approach (just different syntax how to reference and print out the internationalized messages, obviously) will also work for any other language that supports internationalization and has no way to add those internationalized strings directly in javascript.

Body:
My problem is fairly simple: I have a string in one of my coffeescripts that I need to internationalize with an i18n value in my Rails application. Here's my code:

 $ ->
      $("#order_accepted_terms").on 'invalid', ->
        this.setCustomValidity('Die AGB müssen akzeptiert werden.')

Anyone got any ideas?

Body:
In my opinion, a better way (and one that doesn't require yet another gem, remember - performance) is to include an object with internationalized messages as a global scoped javascript variable. So you'd go about it this way (for Ruby on Rails):

 1. in your application.html.erb add  tags right after title (before any other javascript files are referenced)

 2. add a global scope variable object within those inline script tags in head

generalMessages = {
    someMessage: '<%= t 'path.to.some_message_in_yml' %>',
    anotherMessage: '<%= t 'path.another_message' %>'
}

3. reference the variable (in javascript/coffeescript/typescript) as:

foo = generalMessages.someMessage

Voila.

A similar approach (just different syntax how to reference and print out the internationalized messages, obviously) will also work for any other language that supports internationalization and has no way to add those internationalized strings directly in javascript.


问:
android:textColor no longer works in Marshmallow
I have written an app which relies on colors defined in resources. Some are set directly in the layout XML file, others are set in code. Examples:

Color definition in res/values/styles.xml:

```<code><color name="orvGyro">#33B5E5</color>
</code>```

Layout:

```<code><TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dotSpace"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="@color/orvGyro" />
</code>```

Color in code:

```<code>accStatus.setTextColor(getResources().getColor(R.color.somecolor));
</code>```

The app targets API 17. Up to Lollipop, this has worked flawlessly, displaying the right colors. After migrating to Marshmallow (Cyanogenmod 13), all these colors display as orange. Other colors, which are defined in Java code and not in resources, seem to display correctly.

I've tried changing the target API to 23 and adding styles for API 21+, to no avail.

What's wrong here? Is that a bug in CyanogenMod13, or am I doing something wrong?

EDIT: It seems it's not about getting the color from the resource. Hard-coding the colors as shown below also gives me orange text:

```<code><TextView
    android:id="@+id/textView9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dotSpace"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#669900" />
</code>```

EDIT 2: Just came across Android M Developer Preview - TextView android:textColor being ignored. Could this explain the behavior I'm experiencing?

EDIT 3: When I generate content dynamically instead of using layouts, colors display correctly. Example:

```<code>    TextView newType = new TextView(rilLteCells.getContext());
    newType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newType.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium);
    newType.setTextColor(rilLteCells.getContext().getResources().getColor(getColorFromGeneration(cell.getGeneration())));
    newType.setText(rilLteCells.getContext().getResources().getString(R.string.smallDot));
    row.addView(newType);
</code>```

答:
Faced the same problem on my Sony Xperia (Android 6.0 Marshmallow). The reason was that the Settings/Accessibility/High contrast text (experimental) was enabled.

When I disabled it, it worked fine again as expected.

Body:
I have written an app which relies on colors defined in resources. Some are set directly in the layout XML file, others are set in code. Examples:

Color definition in res/values/styles.xml:

<color name="orvGyro">#33B5E5</color>

Layout:

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dotSpace"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="@color/orvGyro" />

Color in code:

accStatus.setTextColor(getResources().getColor(R.color.somecolor));

The app targets API 17. Up to Lollipop, this has worked flawlessly, displaying the right colors. After migrating to Marshmallow (Cyanogenmod 13), all these colors display as orange. Other colors, which are defined in Java code and not in resources, seem to display correctly.

I've tried changing the target API to 23 and adding styles for API 21+, to no avail.

What's wrong here? Is that a bug in CyanogenMod13, or am I doing something wrong?

EDIT: It seems it's not about getting the color from the resource. Hard-coding the colors as shown below also gives me orange text:

<TextView
    android:id="@+id/textView9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/dotSpace"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#669900" />

EDIT 2: Just came across Android M Developer Preview - TextView android:textColor being ignored. Could this explain the behavior I'm experiencing?

EDIT 3: When I generate content dynamically instead of using layouts, colors display correctly. Example:

    TextView newType = new TextView(rilLteCells.getContext());
    newType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
    newType.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium);
    newType.setTextColor(rilLteCells.getContext().getResources().getColor(getColorFromGeneration(cell.getGeneration())));
    newType.setText(rilLteCells.getContext().getResources().getString(R.string.smallDot));
    row.addView(newType);


问:
How to parse Int from String.charAt()
I need to parse Integer from first String position.
Something like this:

```<code>String s = "1abc";
int x = s.charAt(0);
</code>```

This doesn't work (obviously) but hopefully you got the idea.
I also can't use anything like this:

```<code>int x = s.substring(0, 1);
</code>```

Since that would return second character ('a') in this case.

答:
For java you could do

```<code>int x = Integer.parseInt(s.substring(0,1));
</code>```

Check if it works

Title: How to parse Int from String.charAt()

Body:
I need to parse Integer from first String position.
Something like this:

String s = "1abc";
int x = s.charAt(0);

This doesn't work (obviously) but hopefully you got the idea.
I also can't use anything like this:

int x = s.substring(0, 1);

Since that would return second character ('a') in this case.

Body:
For java you could do

int x = Integer.parseInt(s.substring(0,1));

Check if it works


问:
Using bagof/3 only for the side effect
Solving a very simple exercise in Prolog: print all numbers from 1 to 100, but instead of the number, print 'Fuzz' if number is a multiple of 3, 'Buzz' if multiple of 5, and 'FizzBuzz' if both.

I ended up doing the following:

```<code>fizzbuzz :- forall( between(1, 100, X), fizzbuzz(X) ).
fizzbuzz(X) :- ( write_fb(X) ; write_n(X) ), nl.

write_fb(X) :- bagof(_, fb(X), _).
fb(X) :- X rem 3 =:= 0, write('Fizz').
fb(X) :- X rem 5 =:= 0, write('Buzz').

write_n(X) :- write(X).
</code>```

but isn't there any predicate or a control structure that would avoid using bagof/3 only for its side effect? (I am always a bit unsure with using predicates only for the side effects).

答:
/*

problem statement

solve for all each number   :

generate each number from 1 to 100  ,
    but transform each number into an each message  ,
        into each message 'Fuzz' if the each number is a multiple of 3  ,
        into each message 'Buzz' if the each number is a multiple of 5  ,
        into each message 'FizzBuzz' if the each number is both ,
    then print each message .

*/

/*

program

*/

```<code>    :- use_module(library(clpfd)) .

    :- op(10'1,'yfx','forall') .
    :- op(10'1,'fy','once') .

    (
        program
    )
    :-
    (
        (
            between(1,100,NUMBER)
        )
        forall
        (
            once
            (
                (
                    MESSAGE='FizzBuzz'
                    ,
                    NUMBER rem 10'3 #= 10'0
                    ,
                    NUMBER rem 10'5 #= 10'0
                )
                |
                (
                    MESSAGE='Buzz'
                    ,
                    NUMBER rem 10'5 #= 10'0
                )
                |
                (
                    MESSAGE='Fuzz'
                    ,
                    NUMBER rem 10'3 #= 10'0
                )
                |
                (
                    MESSAGE=_
                )
            )
            ,
            once
            (
                (
                    nonvar(MESSAGE)
                    ,
                    writeq(NUMBER)
                    ,
                    nl
                    ,
                    writeq(MESSAGE)
                    ,
                    nl
                )
                |
                (
                    true
                )
            )
        )
    )
    .
</code>```

/*

testing

Tested in swi prolog .
*/

```<code>    ?- program .

    3
    'Fuzz'
    5
    'Buzz'
    6
    'Fuzz'
    9
    'Fuzz'
    10
    'Buzz'
    12
    'Fuzz'
    15
    'FizzBuzz'

    { .e.t.c. | ... as expected ... |  .e.t.c. }

    99
    'Fuzz'
    100
    'Buzz'
    true.

    ?-
</code>```

*/

Title: Using bagof/3 only for the side effect

Body:
Solving a very simple exercise in Prolog: print all numbers from 1 to 100, but instead of the number, print 'Fuzz' if number is a multiple of 3, 'Buzz' if multiple of 5, and 'FizzBuzz' if both.

I ended up doing the following:

fizzbuzz :- forall( between(1, 100, X), fizzbuzz(X) ).
fizzbuzz(X) :- ( write_fb(X) ; write_n(X) ), nl.

write_fb(X) :- bagof(_, fb(X), _).
fb(X) :- X rem 3 =:= 0, write('Fizz').
fb(X) :- X rem 5 =:= 0, write('Buzz').

write_n(X) :- write(X).

but isn't there any predicate or a control structure that would avoid using bagof/3 only for its side effect? (I am always a bit unsure with using predicates only for the side effects).

Body:
/*

problem statement

solve for all each number   :

generate each number from 1 to 100  ,
    but transform each number into an each message  ,
        into each message 'Fuzz' if the each number is a multiple of 3  ,
        into each message 'Buzz' if the each number is a multiple of 5  ,
        into each message 'FizzBuzz' if the each number is both ,
    then print each message .

*/

/*

program

*/

    :- use_module(library(clpfd)) .

    :- op(10'1,'yfx','forall') .
    :- op(10'1,'fy','once') .

    (
        program
    )
    :-
    (
        (
            between(1,100,NUMBER)
        )
        forall
        (
            once
            (
                (
                    MESSAGE='FizzBuzz'
                    ,
                    NUMBER rem 10'3 #= 10'0
                    ,
                    NUMBER rem 10'5 #= 10'0
                )
                |
                (
                    MESSAGE='Buzz'
                    ,
                    NUMBER rem 10'5 #= 10'0
                )
                |
                (
                    MESSAGE='Fuzz'
                    ,
                    NUMBER rem 10'3 #= 10'0
                )
                |
                (
                    MESSAGE=_
                )
            )
            ,
            once
            (
                (
                    nonvar(MESSAGE)
                    ,
                    writeq(NUMBER)
                    ,
                    nl
                    ,
                    writeq(MESSAGE)
                    ,
                    nl
                )
                |
                (
                    true
                )
            )
        )
    )
    .

/*

testing

Tested in swi prolog .
*/

    ?- program .

    3
    'Fuzz'
    5
    'Buzz'
    6
    'Fuzz'
    9
    'Fuzz'
    10
    'Buzz'
    12
    'Fuzz'
    15
    'FizzBuzz'

    { .e.t.c. | ... as expected ... |  .e.t.c. }

    99
    'Fuzz'
    100
    'Buzz'
    true.

    ?-

*/


问:
sqlite create ordered partitions based on a column value si.e. dense_rank()
If have the following table@

```<code>ID     VAR1
--     ----
A      YES
B      YES
C      YES
D      NO
E      YES
F      NO
G      YES
H      YES
</code>```

I would like to create a new partition where VAR1 changes between YES and NO like so:

```<code>ID     VAR1    VAR2
--     ----
A      YES     1
B      YES     1
C      YES     1
D      NO      2
E      YES     3
F      NO      4
G      YES     5
H      YES     5
</code>```

Obviously I might use a dense_rank() in sql server, but I see no equivalent of this in sqlite.

Any workarounds anyone is aware of?

答:
This is tricky in SQLite, but at least it supports CTEs.  Here is the idea . . pull in the previous value (using a correlated subquery).  Then do a cumulative sum based on logic on that value.

```<code>with tt as (
      select t.*,
             (select t2.var1
              from t t2
              where t2.id < t.id
              order by t2.id desc
              limit 1
             ) as prev_var1
      from t
     )
select tt.*,
       (select sum(case when prev_var1 is null or prev_var1 <> var1 then 1 else 0 end)
        from tt tt2
        where tt2.id <= tt.id
       ) as var2
from tt;
</code>```

This assumes -- as in the question -- that the ordering is specified by the id column.

Body:
If have the following table@

ID     VAR1
--     ----
A      YES
B      YES
C      YES
D      NO
E      YES
F      NO
G      YES
H      YES

I would like to create a new partition where VAR1 changes between YES and NO like so:

ID     VAR1    VAR2
--     ----
A      YES     1
B      YES     1
C      YES     1
D      NO      2
E      YES     3
F      NO      4
G      YES     5
H      YES     5

Obviously I might use a dense_rank() in sql server, but I see no equivalent of this in sqlite.

Any workarounds anyone is aware of?

Body:
This is tricky in SQLite, but at least it supports CTEs.  Here is the idea . . pull in the previous value (using a correlated subquery).  Then do a cumulative sum based on logic on that value.

with tt as (
      select t.*,
             (select t2.var1
              from t t2
              where t2.id < t.id
              order by t2.id desc
              limit 1
             ) as prev_var1
      from t
     )
select tt.*,
       (select sum(case when prev_var1 is null or prev_var1 <> var1 then 1 else 0 end)
        from tt tt2
        where tt2.id <= tt.id
       ) as var2
from tt;

This assumes -- as in the question -- that the ordering is specified by the id column.