问:
'this' property has value undefined on nodeJS
I'm still learning JavaScript and when I tried to get an understanding of this behavior, I've got a little confused. One thing that I understand that this keyword is actually refer to where is the call-site of the function when it called. I was trying run the example code below:

```<code>function foo() {
    console.log ( this.a );
}
var a = 2;
foo();
</code>```

The expected result is 2. It did show 2 on Chrome's console but when I tried to run it from NodeJS, result result would be undefined. my Node version is 6.10.1

Is the call-site will be different when the code run in Node compare to Browser's Console or is there anything that need my concern when I'm running code on nodeJS especially when using this keyword?

答:
This is because default value for this in non-strict mode is window

Also when you define any variable outside a function, it becomes part of window.

Sample

function foo() {
  console.log(this.a);
  console.log(window.a);
}
var a = 2;
foo();```
</div>
</div>
</p>

<p>But if you try the same in strict mode(<em>Like in node console</em>), default value of <code>this</code> is undefined. So it will throw error when you try and access <code>this.a</code></p>

<p><strong>Sample</strong></p>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>"use strict";
function foo() {
  console.log(this.a);
}
var a = 2;
foo();</code>```

Body:
I'm still learning JavaScript and when I tried to get an understanding of this behavior, I've got a little confused. One thing that I understand that this keyword is actually refer to where is the call-site of the function when it called. I was trying run the example code below:

function foo() {
    console.log ( this.a );
}
var a = 2;
foo();

The expected result is 2. It did show 2 on Chrome's console but when I tried to run it from NodeJS, result result would be undefined. my Node version is 6.10.1

Is the call-site will be different when the code run in Node compare to Browser's Console or is there anything that need my concern when I'm running code on nodeJS especially when using this keyword?

Body:
This is because default value for this in non-strict mode is window

Also when you define any variable outside a function, it becomes part of window.

Sample

function foo() {
  console.log(this.a);
  console.log(window.a);
}
var a = 2;
foo();

But if you try the same in strict mode(Like in node console), default value of this is undefined. So it will throw error when you try and access this.a

Sample

"use strict";
function foo() {
  console.log(this.a);
}
var a = 2;
foo();


来源: stackexchange

问:
mysqli inner join: data not exist in other table
I have 3 tables and I am using inner join to get the data from table.

```<code> select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title, a.description, a.city, a.position,
        a.salary, a.looking_for,a.website,a.date
   from job_posting a
  inner join users b
  inner join job_applied c on a.uid = b.uid and b.uid = c.uid
  where c.job_id IS NULL and c.uid IS NULL and a.looking_for = 'student'
</code>```

Above query is not returning any data. It's empty.

Let me explain the table.

job_posting - Contain job information.

  users - contain user information who posted the job.

  job_applied - contain user has applied for the jobs.

So, I want to get the jobs those are not applied. In Job_paplied table I have job_id and uid.

答:
Instead of inner join try LEFT JOIN like:

```<code>select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title,a.description,a.city, a.position,
a.salary, a.looking_for,a.website,a.date from job_posting a
LEFT JOIN users b  on a.uid = b.uid
LEFT JOIN job_applied c  on b.uid = c.uid
where c.job_id IS NULL  and a.looking_for = 'student'
</code>```

and try again.

ContentLicense: CC BY-SA 3.0

Body:
I have 3 tables and I am using inner join to get the data from table.

 select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title, a.description, a.city, a.position,
        a.salary, a.looking_for,a.website,a.date
   from job_posting a
  inner join users b
  inner join job_applied c on a.uid = b.uid and b.uid = c.uid
  where c.job_id IS NULL and c.uid IS NULL and a.looking_for = 'student'

Above query is not returning any data. It's empty.

Let me explain the table.

job_posting - Contain job information.

  users - contain user information who posted the job.

  job_applied - contain user has applied for the jobs.

So, I want to get the jobs those are not applied. In Job_paplied table I have job_id and uid.

Body:
Instead of inner join try LEFT JOIN like:

select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title,a.description,a.city, a.position,
a.salary, a.looking_for,a.website,a.date from job_posting a
LEFT JOIN users b  on a.uid = b.uid
LEFT JOIN job_applied c  on b.uid = c.uid
where c.job_id IS NULL  and a.looking_for = 'student'

and try again.


问:
Get validators present in FormGroup/FormControl
I'm using Material 2 in my app, but in this question I want to solve a problem specifically with Input.

As you can see in API Reference there's a property bind called required, which shows as asterisk in the placeholder.

So, I'm wondering if there's a way to check if the form control has an specific validator in Angular, because I really don't want to set manually for each input [required]="true/false"

I read the AbstractControl docs and I didn't find anything about it. I've encountered the hasError method (which ironically isn't documented in nowhere ... neither in FormGroup nor in FormControl nor in AbstractControl), however this is not what I'm looking for. It just checks if the form control has the error, but as you may have read, I want to check if the control has some specific validators...

Some code:

```<code><md-input-container>
  <input placeholder="Placeholder"
         mdInput [formControl]="anyCtrl"
         [required]="anyCtrl.hasValidator('required')"> <!-- something like this -->
</md-input-container>
</code>```

I hope the question is clear enough. Thanks in advance.

答:
This answer is a continuation of @joh04667's.  They wrote:

```<code>public hasValidator(control: string, validator: string): boolean {
  return !!this.myForm.controls[control].validators(control).hasOwnProperty(validator);
 // returns true if control has the validator
}
</code>```

However there is no AbstractControls.validators() method.  I'm assuming AbstractControls.validator() was meant.

The hasValidator() method only works for validators that 'fail' (eg. a required validator on a control with the value '' (empty)).  Since if they pass they return null.  A way around this would be to set the value so that it always fails and restore that afterwards.

```<code>public hasValidator(control: string, validator: string): boolean {
    let control: AbstractControl = this.myForm.controls[control];
    let lastValue: any = control.value;
    switch(validator) {
        case 'required':
            control.setValue('');  // as is appropriate for the control
        case 'pattern':
            control.setValue('3'); // given you have knowledge of what the pattern is - say its '\d\d\d'
        ....
    }
    let hasValidator: boolean = !!control.validator(control).hasOwnProperty(validator);

    control.setValue(lastValue);
    return hasValidator;
}
</code>```

And this is pretty horrible.  It begs the question - Why is there no AbstractControl.getValidators(): ValidatorFn[]|null?

What is the motivation in hiding this?  Perhaps they are worried someone might put in their code:

```<code>...
secretPassword: ['', [Validators.pattern('fjdfjafj734738&UERUEIOJDFDJj')]
...
</code>```

Body:
I'm using Material 2 in my app, but in this question I want to solve a problem specifically with Input.

As you can see in API Reference there's a property bind called required, which shows as asterisk in the placeholder.

So, I'm wondering if there's a way to check if the form control has an specific validator in Angular, because I really don't want to set manually for each input [required]="true/false"

I read the AbstractControl docs and I didn't find anything about it. I've encountered the hasError method (which ironically isn't documented in nowhere ... neither in FormGroup nor in FormControl nor in AbstractControl), however this is not what I'm looking for. It just checks if the form control has the error, but as you may have read, I want to check if the control has some specific validators...

Some code:

<md-input-container>
  <input placeholder="Placeholder"
         mdInput [formControl]="anyCtrl"
         [required]="anyCtrl.hasValidator('required')">
</md-input-container>

I hope the question is clear enough. Thanks in advance.

Body:
This answer is a continuation of @joh04667's.  They wrote:

public hasValidator(control: string, validator: string): boolean {
  return !!this.myForm.controls[control].validators(control).hasOwnProperty(validator);
 // returns true if control has the validator
}

However there is no AbstractControls.validators() method.  I'm assuming AbstractControls.validator() was meant.

The hasValidator() method only works for validators that 'fail' (eg. a required validator on a control with the value '' (empty)).  Since if they pass they return null.  A way around this would be to set the value so that it always fails and restore that afterwards.

public hasValidator(control: string, validator: string): boolean {
    let control: AbstractControl = this.myForm.controls[control];
    let lastValue: any = control.value;
    switch(validator) {
        case 'required':
            control.setValue('');  // as is appropriate for the control
        case 'pattern':
            control.setValue('3'); // given you have knowledge of what the pattern is - say its '\d\d\d'
        ....
    }
    let hasValidator: boolean = !!control.validator(control).hasOwnProperty(validator);

    control.setValue(lastValue);
    return hasValidator;
}

And this is pretty horrible.  It begs the question - Why is there no AbstractControl.getValidators(): ValidatorFn[]|null?

What is the motivation in hiding this?  Perhaps they are worried someone might put in their code:

...
secretPassword: ['', [Validators.pattern('fjdfjafj734738&UERUEIOJDFDJj')]
...

ContentLicense: CC BY-SA 4.0


问:
Wordpress and PHP
I have this code in my header.php for Wordpress to display a mini feed at the top of the page or not.

```<code><?php if ( !$noHeader ) { include('feed.php'); } ?>
</code>```

At the top of each page I set the $noHeader variable

```<code>$noHeader = true;
get_header();
</code>```

For some reason, this doesn't work. What am I doing wrong?

答:
I've had this problem.  The wordpress function get_header(); does not evaluate local variables from the parent file in your included header file.  Change it to

```<code>// get_header(); //commented out for clarity of explanation
include 'header.php';
</code>```

Honestly, there's no real reason that I've found to use get_header(); over an include, anyway.

You might as well do this too:

```<code>// get_sidebar();
include 'sidebar.php';

// get_footer();
include 'footer.php';
</code>```

ContentLicense: CC BY-SA 2.5

Title: Wordpress and PHP

Body:
I have this code in my header.php for Wordpress to display a mini feed at the top of the page or not.

<?php if ( !$noHeader ) { include('feed.php'); } ?>

At the top of each page I set the $noHeader variable

$noHeader = true;
get_header();

For some reason, this doesn't work. What am I doing wrong?

Body:
I've had this problem.  The wordpress function get_header(); does not evaluate local variables from the parent file in your included header file.  Change it to

// get_header(); //commented out for clarity of explanation
include 'header.php';

Honestly, there's no real reason that I've found to use get_header(); over an include, anyway.

You might as well do this too:

// get_sidebar();
include 'sidebar.php';

// get_footer();
include 'footer.php';


问:
Not sure why I am getting this error, I have an idea but am not sure how to fix it
This is for a project that I am working on. I am trying to model an intrusive dike of magma cooling in some host or country rock within the earths crust. I am fairly new to coding. I did my best to convert this code form another coding language to python. I have a basic idea of what is going on. I know that I am trying to index something out of range, but am not sure where and or how to fix it. Any help I could get would be greatly appreciated! Thanks in advance.

```<code>import numpy as np
import matplotlib.pyplot as plt

#Physical parameters
L = 100 #Length of modeled domain [m]
Tmagma = 1200 #Temp. magma [°C]
Trock = 300 #Temp. of country rock [°C]
kappa = 1e-6 #Thermal diffusivity of rock [m^2/s]
W = 5 #Width of dike [m]
day = 3600*24 #seconds per day
dt = 1*day #Timestep
print(kappa)
print(day)
print(dt)

#Numerical parameters
nx = 201 #Number of gridpoints in x-direction
nt = 500 #Number of timesteps to compute
dx = L/(nx-1) #Spacing of grid
x = np.linspace(-50,50,100) #Grid
print(dx)
print(x)

#Setup initial temp. profile
T = np.ones(np.shape(x))*Trock
T[x>=-W/2] = 1200
T[x>=W/2] = 300
print(T)

time = 0
for n in range(0,nt): #Timestep loop
    #compute new temp.
    Tnew = np.zeros((1,nx))
    print(Tnew)
    for i in range(2,nx-1):
        Tnew[i] = T[i]+kappa*dt*((T[i+1]-2*T[i]+T[i-1])/(dt**2))             # Set BC's
    Tnew[1] = T[1]
    Tnew[nx] = T[nx]

    #update temp. and time
    T = Tnew
    time = time+dt

    #Plot solution
    plt.figure()
    plt.plot(x,Tnew)
    plt.xlabel('x [m]')
    plt.ylabel('Temerpature [°C]')
    plt.legend()
    surf = ax.plot_surface(X, Y, cmap=cm.coolwarm, linewidth=0, antialiased=False)
    fig.colorbar(surf, shrink=0.5, aspect=5)
    plt.show()
</code>```

```<code>IndexError                                Traceback (most recent call last)
<ipython-input-51-e80d6234a5b4> in <module>()
     37     print(Tnew)
     38     for i in range(2,nx-1):
---> 39         Tnew[i] = T[i]+kappa*dt*((T[i+1]-2*T[i]+T[i-1])/(dt**2))
     40
     41     # Set BC's

IndexError: index 2 is out of bounds for axis 0 with size
</code>```

答:
```<code>Tnew = np.zeros((1,nx))
</code>```

This will gives you one array of nx element inside array (Two dimensional array)  and you need to access it like Tnew[0][i]

just change it to

```<code>Tnew = np.zeros((nx))
</code>```

check numpy.zeros DOC

NOTE: After resolving this error you are going to face is Index error at "T[i+1]" which is because when your 'i' reaches at last element you are not going to get 'i+1' element in 'T'.

Body:
This is for a project that I am working on. I am trying to model an intrusive dike of magma cooling in some host or country rock within the earths crust. I am fairly new to coding. I did my best to convert this code form another coding language to python. I have a basic idea of what is going on. I know that I am trying to index something out of range, but am not sure where and or how to fix it. Any help I could get would be greatly appreciated! Thanks in advance.

import numpy as np
import matplotlib.pyplot as plt

#Physical parameters
L = 100 #Length of modeled domain [m]
Tmagma = 1200 #Temp. magma [°C]
Trock = 300 #Temp. of country rock [°C]
kappa = 1e-6 #Thermal diffusivity of rock [m^2/s]
W = 5 #Width of dike [m]
day = 3600*24 #seconds per day
dt = 1*day #Timestep
print(kappa)
print(day)
print(dt)

#Numerical parameters
nx = 201 #Number of gridpoints in x-direction
nt = 500 #Number of timesteps to compute
dx = L/(nx-1) #Spacing of grid
x = np.linspace(-50,50,100) #Grid
print(dx)
print(x)

#Setup initial temp. profile
T = np.ones(np.shape(x))*Trock
T[x>=-W/2] = 1200
T[x>=W/2] = 300
print(T)

time = 0
for n in range(0,nt): #Timestep loop
    #compute new temp.
    Tnew = np.zeros((1,nx))
    print(Tnew)
    for i in range(2,nx-1):
        Tnew[i] = T[i]+kappa*dt*((T[i+1]-2*T[i]+T[i-1])/(dt**2))             # Set BC's
    Tnew[1] = T[1]
    Tnew[nx] = T[nx]

    #update temp. and time
    T = Tnew
    time = time+dt

    #Plot solution
    plt.figure()
    plt.plot(x,Tnew)
    plt.xlabel('x [m]')
    plt.ylabel('Temerpature [°C]')
    plt.legend()
    surf = ax.plot_surface(X, Y, cmap=cm.coolwarm, linewidth=0, antialiased=False)
    fig.colorbar(surf, shrink=0.5, aspect=5)
    plt.show()

IndexError                                Traceback (most recent call last)
<ipython-input-51-e80d6234a5b4> in <module>()
     37     print(Tnew)
     38     for i in range(2,nx-1):
---> 39         Tnew[i] = T[i]+kappa*dt*((T[i+1]-2*T[i]+T[i-1])/(dt**2))
     40
     41     # Set BC's

IndexError: index 2 is out of bounds for axis 0 with size

Body:
Tnew = np.zeros((1,nx))

This will gives you one array of nx element inside array (Two dimensional array)  and you need to access it like Tnew[0][i]

just change it to

Tnew = np.zeros((nx))

check numpy.zeros DOC

NOTE: After resolving this error you are going to face is Index error at "T[i+1]" which is because when your 'i' reaches at last element you are not going to get 'i+1' element in 'T'.


问:
Fail to install visual studio 2017 for mac
I have downloaded the visualstudioinstaller.dmg (which proves my network works), but while installing, the visual studio check the network connections and say 'no network'. And then i send the error report by network after that(what embarrassment.)
my question is:

how to solve this issue? my network absolute works, is the website on Microsoft down?

or else where can i have the offline install package of vs2017 for mac?

Thank you.

答:
Finally i find this notice  An offline installer feature is planned for future versions of Visual Studio for Mac.  :

https://learn.microsoft.com/en-us/visualstudio/mac/create-offline-installer


问:
my highchart is currently is not working with pie spline chart in updating after rendering chart
Here is my code for updating after rendering. In this code, first three buttons (plain, inverted and polar) are working perfectly fine, but last 2 buttons (pie, spline) are not working.

```<code>var chart = Highcharts.chart('container', {

    title: {
             text: 'Chart.update'
    },

    subtitle: {
             text: 'Plain'
    },

    xAxis: {
             categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
            type: 'column',
            colorByPoint: true,
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
            showInLegend: false
    }]

    });

    $('#plain').click(function () {
        chart.update({
                    chart: {
                    inverted: false,
                    polar: false,
                    pie:false,
                    spline:false
                    },
        subtitle: {
                    text: 'Plain'
        }
        });
    });

    $('#inverted').click(function () {
    chart.update({
        chart: {
                inverted: true,
                polar: false,
                pie:false,
                spline:false
        },
        subtitle: {
                text: 'Inverted'
        }
        });
    });

    $('#polar').click(function () {
    chart.update({
        chart: {
                inverted: false,
                polar: true,
                pie:false,
                spline:false
        },
        subtitle: {
                text: 'Polar'
        }
        });
    });

    $('#pie').click(function () {
    chart.update({
        chart: {
                pie:true,
                inverted: false,
                polar: false,
                spline:false,
                plain:false
        },
        subtitle: {
                    text: 'Pie'
        }
        });
    });
    $('#spline').click(function () {
    chart.update({
        chart: {
                type:'spline',
                inverted: false,
                polar: false,
                pie:false,
                plain:false
        },
        subtitle: {
                text: 'spline'
        }
        });
    });
</code>```

I am studying this topic from highcahrts.com and i want to add additional chart with that.

答:
chart Pie and spline are of different generic chart , but column chart can be represented in two different form plain means default column chart, inverted means column chart with axis inverted and polar has XY coordinate with X axis is wrapped around the perimeter while the Y axis extends from the center to the top. They cannot be mixed to change form(plain,inverted,polar) with (pie,spline)

So to update charts to plain(column), inverted(column),polar,pie,spline I use chart type.Hope this will make sense.

var chart = Highcharts.chart('container', {
  chart: {
    type: 'column',
  },
  title: {
    text: 'Chart.update'
  },

  subtitle: {
    text: 'Plain'
  },

  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  series: [{

    colorByPoint: true,
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
    showInLegend: false
  }]

});

$('#plain').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'Plain'
    }
  }, true);
});

$('#inverted').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: true,
      polar: false
    },
    subtitle: {
      text: 'Inverted'
    }
  }, true);
});

$('#polar').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: false,
      polar: true
    },
    subtitle: {
      text: 'Polar'
    }
  }, true);
});
$('#pie').click(function() {
  chart.update({
    chart: {
      type: 'pie',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'Pie'
    }
  }, true);
});
$('#spline').click(function() {
  chart.update({
    chart: {
      type: 'spline',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'spline'
    }
  }, true);
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#container {
  min-width: 320px;
  max-width: 600px;
  margin: 0 auto;
}</code>```

<button id="plain" class="autocompare">Plain</button>
<button id="inverted" class="autocompare">Inverted</button>
<button id="polar" class="autocompare">Polar</button>
<button id="pie" class="autocompare">Pie</button>
<button id="spline" class="autocompare">Spline</button>```

Body:
Here is my code for updating after rendering. In this code, first three buttons (plain, inverted and polar) are working perfectly fine, but last 2 buttons (pie, spline) are not working.

var chart = Highcharts.chart('container', {

    title: {
             text: 'Chart.update'
    },

    subtitle: {
             text: 'Plain'
    },

    xAxis: {
             categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
            type: 'column',
            colorByPoint: true,
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
            showInLegend: false
    }]

    });

    $('#plain').click(function () {
        chart.update({
                    chart: {
                    inverted: false,
                    polar: false,
                    pie:false,
                    spline:false
                    },
        subtitle: {
                    text: 'Plain'
        }
        });
    });

    $('#inverted').click(function () {
    chart.update({
        chart: {
                inverted: true,
                polar: false,
                pie:false,
                spline:false
        },
        subtitle: {
                text: 'Inverted'
        }
        });
    });

    $('#polar').click(function () {
    chart.update({
        chart: {
                inverted: false,
                polar: true,
                pie:false,
                spline:false
        },
        subtitle: {
                text: 'Polar'
        }
        });
    });

    $('#pie').click(function () {
    chart.update({
        chart: {
                pie:true,
                inverted: false,
                polar: false,
                spline:false,
                plain:false
        },
        subtitle: {
                    text: 'Pie'
        }
        });
    });
    $('#spline').click(function () {
    chart.update({
        chart: {
                type:'spline',
                inverted: false,
                polar: false,
                pie:false,
                plain:false
        },
        subtitle: {
                text: 'spline'
        }
        });
    });

I am studying this topic from highcahrts.com and i want to add additional chart with that.

Body:
chart Pie and spline are of different generic chart , but column chart can be represented in two different form plain means default column chart, inverted means column chart with axis inverted and polar has XY coordinate with X axis is wrapped around the perimeter while the Y axis extends from the center to the top. They cannot be mixed to change form(plain,inverted,polar) with (pie,spline)

So to update charts to plain(column), inverted(column),polar,pie,spline I use chart type.Hope this will make sense.

var chart = Highcharts.chart('container', {
  chart: {
    type: 'column',
  },
  title: {
    text: 'Chart.update'
  },

  subtitle: {
    text: 'Plain'
  },

  xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  },

  series: [{

    colorByPoint: true,
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
    showInLegend: false
  }]

});

$('#plain').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'Plain'
    }
  }, true);
});

$('#inverted').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: true,
      polar: false
    },
    subtitle: {
      text: 'Inverted'
    }
  }, true);
});

$('#polar').click(function() {
  chart.update({
    chart: {
      type: 'column',
      inverted: false,
      polar: true
    },
    subtitle: {
      text: 'Polar'
    }
  }, true);
});
$('#pie').click(function() {
  chart.update({
    chart: {
      type: 'pie',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'Pie'
    }
  }, true);
});
$('#spline').click(function() {
  chart.update({
    chart: {
      type: 'spline',
      inverted: false,
      polar: false
    },
    subtitle: {
      text: 'spline'
    }
  }, true);
});

#container {
  min-width: 320px;
  max-width: 600px;
  margin: 0 auto;
}

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container"></div>
<button id="plain" class="autocompare">Plain</button>
<button id="inverted" class="autocompare">Inverted</button>
<button id="polar" class="autocompare">Polar</button>
<button id="pie" class="autocompare">Pie</button>
<button id="spline" class="autocompare">Spline</button>


问:
How to change the color of a
 tag in a div class under another
 tag?
I have some text in my HTML banner "Find out what Google can do for you". I want the color to be #ffffff (white), but for some reason it's picking up the color from the above "p" tag so it shows the color rgb (102, 102, 102). How can I make it so the .box-row p really shows #ffffff.

See my jsfiddle: http://jsfiddle.net/huskydawgs/tKn9f/39/

```<code>        <div id="wrapper-landing">
    <p>
        Google has released an update to its Text-to-Speech app (TTS) that adds new, high-quality voices—that now take up a couple hundred MB worth of space instead of the old 5-6MB—as well as several new language packs including UK English, Portuguese, and US Spanish.</p>
        <div class="box-row">
        <div class="box-form-body">
                <p>
                    Find out what Google can do for you!</p>
        </div>
        <div class="box-form-button">
            <img alt="Learn More" height="100" src="http://www.robindelillo.fr/img/home/seeMoreButton.png" width="100" />
        </div>
    </div>
    </div>

        #wrapper-landing {
        width: 916px;
        margin: 0 auto 50px auto;
        padding: 0;
    }

        #wrapper-landing p {
            color: rgb(102, 102, 102);
            font-family: 'SegoeRegular',Helvetica,Arial,sans-serif;
            font-size: 1.1em;
            line-height: 1.6em;
    }

    .box-row {
        width:915px;
        padding:10px;
        border:1px solid #e2e3e4;
        margin-top:50px;
        overflow: hidden;
        background-color:#f66511;
    }
    .box-row p {
        color: #ffffff;
        font-family: 'SegoeRegular',Helvetica,Arial,sans-serif;
        font-size: 1.1em;
        line-height: 1.6em;
}

.box-form-body {
    display: inline-block;
    vertical-align: middle;
    width: 75%;
    padding: 0 0 0 2em;
}
    .box-form-button {
        display: inline-block;
        vertical-align: middle;
        width: 15%;
        padding: 0 0 0 2em;
    }
    .box-form-button img {
        vertical-align: bottom;
    }
</code>```

答:
JQuery

```<code>$(document).ready(function() {
    $(".box-form-body").find('p').css({color: '#fff'});
});
</code>```

CSS

```<code>    .box-form-body p {
      color: #ffffff !important;
    }
</code>```

inline style

```<code><p style="color: #fff;"> Find out what Google can do for you!</p>
</code>```

Hope this is helpful!

Title: How to change the color of a <p> tag in a div class under another <p> tag?

Body:
I have some text in my HTML banner "Find out what Google can do for you". I want the color to be #ffffff (white), but for some reason it's picking up the color from the above "p" tag so it shows the color rgb (102, 102, 102). How can I make it so the .box-row p really shows #ffffff.

See my jsfiddle: http://jsfiddle.net/huskydawgs/tKn9f/39/

        Google has released an update to its Text-to-Speech app (TTS) that adds new, high-quality voices—that now take up a couple hundred MB worth of space instead of the old 5-6MB—as well as several new language packs including UK English, Portuguese, and US Spanish.

                    Find out what Google can do for you!

        #wrapper-landing {
        width: 916px;
        margin: 0 auto 50px auto;
        padding: 0;
    }

        #wrapper-landing p {
            color: rgb(102, 102, 102);
            font-family: 'SegoeRegular',Helvetica,Arial,sans-serif;
            font-size: 1.1em;
            line-height: 1.6em;
    }

    .box-row {
        width:915px;
        padding:10px;
        border:1px solid #e2e3e4;
        margin-top:50px;
        overflow: hidden;
        background-color:#f66511;
    }
    .box-row p {
        color: #ffffff;
        font-family: 'SegoeRegular',Helvetica,Arial,sans-serif;
        font-size: 1.1em;
        line-height: 1.6em;
}

.box-form-body {
    display: inline-block;
    vertical-align: middle;
    width: 75%;
    padding: 0 0 0 2em;
}
    .box-form-button {
        display: inline-block;
        vertical-align: middle;
        width: 15%;
        padding: 0 0 0 2em;
    }
    .box-form-button img {
        vertical-align: bottom;
    }

Body:
JQuery

$(document).ready(function() {
    $(".box-form-body").find('p').css({color: '#fff'});
});

CSS

    .box-form-body p {
      color: #ffffff !important;
    }

inline style

<p style="color: #fff;"> Find out what Google can do for you!</p>

Hope this is helpful!


问:
Multiple Classes Read From Single Class
I am working on a project which requires to start a Timer on load of the Form1 that  increments the TimerCount Property of Class TimeCounter in the tick event.

The Project has also Form2 which when open I want to read the increment updates from TimeCounter class which is being incremented by the Form1 because Form1 is parent and will not close I tried to read from TimeCounter but got default set value which is 0.

Here is code:

Timer Class

```<code>public class TimeCounter
{
    public int timer=0;
    public int TimerCount { get; set; }

    public int  GetTime()
    {
        return timer;
    }
}
</code>```

Form1 Increment TimerCount After 1 Second

```<code>private void Form1_Load(object sender, EventArgs e)
{
    System.Timers.Timer timer = new System.Timers.Timer();
    timer.Interval = 1000;
    timer.Elapsed += timer_Elapsed;
    timer.Start();
}

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    sk++;
    Timer t = new Timer();
    t.TimerCount = sk;

}
</code>```

Form2 Which Receive Counter Continuously(But Not Working)

```<code>  private void Form1_Load(object sender, EventArgs e)
  {
      System.Timers.Timer timer = new System.Timers.Timer();
      timer.Interval = 1000;
      timer.Elapsed += timer_Elapsed;
      timer.Enabled = true;
      timer.Start();
  }

  void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
      Timer t1 = new Timer();
      B01CountDown.Text = t1.GetTime().ToString();
  }
</code>```

答:
I have modified the code you have posted as follows. If you do not understand, then you need to start learning C#.

TimeCounter:

```<code>public class TimeCounter
{
    public static int timer = 0;
    public static int TimerCount
    {
        get
        {
            return timer;
        }
        set
        {
            timer = value;
        }
    }
}
</code>```

Form1:

```<code>public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        new Form2().Show();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        timer.Interval = 1000;
        timer.Elapsed += timer_Elapsed;
        timer.Start();
    }

    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        TimeCounter.TimerCount++;
    }
}
</code>```

Form 2:

```<code>public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        timer.Interval = 1000;
        timer.Elapsed += timer_Elapsed;
        timer.Enabled = true;
        timer.Start();
    }

    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (B01CountDown.InvokeRequired)
        {
            B01CountDown.Invoke((MethodInvoker)(() =>
            {
                B01CountDown.Text = TimeCounter.TimerCount.ToString();
            }));
        }
    }
}
</code>```

Title: Multiple Classes Read From Single Class

Body:
I am working on a project which requires to start a Timer on load of the Form1 that  increments the TimerCount Property of Class TimeCounter in the tick event.

The Project has also Form2 which when open I want to read the increment updates from TimeCounter class which is being incremented by the Form1 because Form1 is parent and will not close I tried to read from TimeCounter but got default set value which is 0.

Here is code:

Timer Class

public class TimeCounter
{
    public int timer=0;
    public int TimerCount { get; set; }

    public int  GetTime()
    {
        return timer;
    }
}

Form1 Increment TimerCount After 1 Second

private void Form1_Load(object sender, EventArgs e)
{
    System.Timers.Timer timer = new System.Timers.Timer();
    timer.Interval = 1000;
    timer.Elapsed += timer_Elapsed;
    timer.Start();
}

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    sk++;
    Timer t = new Timer();
    t.TimerCount = sk;

}

Form2 Which Receive Counter Continuously(But Not Working)

  private void Form1_Load(object sender, EventArgs e)
  {
      System.Timers.Timer timer = new System.Timers.Timer();
      timer.Interval = 1000;
      timer.Elapsed += timer_Elapsed;
      timer.Enabled = true;
      timer.Start();
  }

  void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
      Timer t1 = new Timer();
      B01CountDown.Text = t1.GetTime().ToString();
  }

Body:
I have modified the code you have posted as follows. If you do not understand, then you need to start learning C#.

TimeCounter:

public class TimeCounter
{
    public static int timer = 0;
    public static int TimerCount
    {
        get
        {
            return timer;
        }
        set
        {
            timer = value;
        }
    }
}

Form1:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        new Form2().Show();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        timer.Interval = 1000;
        timer.Elapsed += timer_Elapsed;
        timer.Start();
    }

    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        TimeCounter.TimerCount++;
    }
}

Form 2:

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        System.Timers.Timer timer = new System.Timers.Timer();
        timer.Interval = 1000;
        timer.Elapsed += timer_Elapsed;
        timer.Enabled = true;
        timer.Start();
    }

    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (B01CountDown.InvokeRequired)
        {
            B01CountDown.Invoke((MethodInvoker)(() =>
            {
                B01CountDown.Text = TimeCounter.TimerCount.ToString();
            }));
        }
    }
}


问:
Interdisciplinary Algorithm Construction with Non-developers
Yeah, I know the title is a mouthful...

What I mean is to say is how do you communicate with a subject matter expert who needs a theory coded and tested?

For example, weather simulation is a collaboration between meteorologists, computer scientists, and software engineers.  The computer scientists and software engineers generally speak the same language, but he meteorologist is in a completely different world.

How do you increase the level of communication and understanding between disciplines?  And not necessarily just for weather, other sciences too.

答:
I think what most of the commenters are missing is actually pretty crucial to your question - the idea that you're working with domain experts to build an implementation of their model to test their theories.

Most software engineering stuff out there is not about this regime - and like you say, this is just qualitiatively different than implementing some buisness process or building a server that has to implement RFCxxxx.

There are people working on this from both ends -- trying to teach scientists about the very basics of responsible software engineering (eg, Greg Wilson's Software Carpentry) and teaching software engineering people about large-scale computational science (eg, Steve Easterbrook's very interesting blog, from which this is particularly relevent).   Why things are as primitive as they are on this front, I have no idea.  Both have links to relevent colleagues on their blogrolls.

There are a number of important differences in this regime from stuff you may have been taught.  For one, the overall structure of scientific software is generally quite simple, but the subtlety is quite high - each line of numerics may be the result of 10 years of scientific literature in a number of fields.   Secondly, the whole idea of specifications kind of gets flipped on its head -- the specification is "accurately models reality" and what the scientist has is a model that they hope does that.  In a way, scientific code development is both implementing a draft specification and groping around for the real specification.

@vfilby sort of has the right idea - continuous customer involvement - but it's a little more than that.  For this to work, you are going to get put into the science loop - instead of the cycle being scientist → theory → test → interpretation → update theory, it's going to be scientist → theory → you code → you and scientist both interpret your own parts → update theory and/or implementation.   The domain scientists aren't going to know as well as you how to best implement what they want, or how to disentangle the results of their model from the results of your implementation of the model; on the other hand, they're going to understand the implications of the model much much better than you and how to update the theory.

This is a hard balancing act to get right. For it to work, both sides have to (a) respect the others domain of expertise, (b) learn a little bit of that other field, and (c) be invested in the project as a whole working.    These sorts of cross-disciplinary projects break down more often then they succeed, but they are vitally important.   I really wish I  had some easy, guaranteed-to-work tips for you.

OwnerDisplayName: dacracot

LastEditorDisplayName: mquander


答:
You are not passing the Timer object correctly to Form2. You need to pass the instance of Timer being used by form 1 to form 2.

Timer:

```<code>public class Timer
{
    public int timer = 0;
    public int TimerCount { get; set; }

    public int GetTime()
    {

        return timer;

    }
}
</code>```

Form1:

```<code>public partial class Form1 : Form
{
    private Timer _timer;

    public Form1()
    {
        InitializeComponent();
        _timer = new Timer();
        timer1.Start();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        timer1.Tick += timer1_Tick;
    }

    void timer1_Tick(object sender, EventArgs e)
    {
        _timer.TimerCount++;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2(_timer);
        frm2.ShowDialog();
    }
}
</code>```

Form2:

```<code>public partial class Form2 : Form
{
    public Timer _timer;

    public Form2(Timer timer)
    {
        InitializeComponent();
        _timer = timer;
        timer1.Start();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        timer1.Tick += timer1_Tick;
    }

    void timer1_Tick(object sender, EventArgs e)
    {
        label1.Text = _timer.TimerCount.ToString();
    }
}
</code>```

Output:

Title: Multiple Classes Read From Single Class

Body:
You are not passing the Timer object correctly to Form2. You need to pass the instance of Timer being used by form 1 to form 2.

Timer:

public class Timer
{
    public int timer = 0;
    public int TimerCount { get; set; }

    public int GetTime()
    {

        return timer;

    }
}

Form1:

public partial class Form1 : Form
{
    private Timer _timer;

    public Form1()
    {
        InitializeComponent();
        _timer = new Timer();
        timer1.Start();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        timer1.Tick += timer1_Tick;
    }

    void timer1_Tick(object sender, EventArgs e)
    {
        _timer.TimerCount++;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2(_timer);
        frm2.ShowDialog();
    }
}

Form2:

public partial class Form2 : Form
{
    public Timer _timer;

    public Form2(Timer timer)
    {
        InitializeComponent();
        _timer = timer;
        timer1.Start();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        timer1.Tick += timer1_Tick;
    }

    void timer1_Tick(object sender, EventArgs e)
    {
        label1.Text = _timer.TimerCount.ToString();
    }
}

Output:


问:
How to unwrap multidimensional array results in PyCharm console?
I have python code which adds elements from 1 to 78 to list and then converts it to 3x26 matrix. I use PyCharm IDE and it wraps results after 24th element in each row. This is the code:

```<code>import numpy as np
mylist=[]
for i in range(1,79):
    mylist.append(i)

data=np.matrix([mylist])
x=(data.reshape(3,26))
print(x)
</code>```

And this is the result:

```<code>[[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  25 26]
 [27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  51 52]
 [53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  77 78]]

Process finished with exit code 0
</code>```

What I want to do is to display each row in exactly one line (such as 25,26 and other two are not wrapped to a new line). How can I do that ? Is this problem pythonic or PyCharm related ? Thanks in advance for your help !

答:
This is not PyCharm related. You will get exactly the same results in IDLE or the Python command-line interpreter.

Nor is it really Python related.

When your code calls print(x) you are asking for the string representation of x, which is a numpy matrix.

numpy does the conversion for you, and it is breaking the lines of output to fit nicely on a generic output console. It doesn't know you are using PyCharm.

A quick fix for this particular problem is to change numpy's default output line length (which is 75).

```<code>numpy.set_printoptions(linewidth=90)
</code>```

But to get full control over the output you will have to format the matrix yourself, rather than relying on the default string conversion that numpy provides.

Body:
I have python code which adds elements from 1 to 78 to list and then converts it to 3x26 matrix. I use PyCharm IDE and it wraps results after 24th element in each row. This is the code:

import numpy as np
mylist=[]
for i in range(1,79):
    mylist.append(i)

data=np.matrix([mylist])
x=(data.reshape(3,26))
print(x)

And this is the result:

[[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  25 26]
 [27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  51 52]
 [53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  77 78]]

Process finished with exit code 0

What I want to do is to display each row in exactly one line (such as 25,26 and other two are not wrapped to a new line). How can I do that ? Is this problem pythonic or PyCharm related ? Thanks in advance for your help !

Body:
This is not PyCharm related. You will get exactly the same results in IDLE or the Python command-line interpreter.

Nor is it really Python related.

When your code calls print(x) you are asking for the string representation of x, which is a numpy matrix.

numpy does the conversion for you, and it is breaking the lines of output to fit nicely on a generic output console. It doesn't know you are using PyCharm.

A quick fix for this particular problem is to change numpy's default output line length (which is 75).

numpy.set_printoptions(linewidth=90)

But to get full control over the output you will have to format the matrix yourself, rather than relying on the default string conversion that numpy provides.


问:
Change viewController BG color based off another view controller
So I need some help for a project. I have a simple tab bar SVC where the first view is a timer and the second is a settings page. On the settings page I've setup a struct with an array of colors, then when a user clicks a button a random color in the array is called and applied to the back ground. This part works just as I Intended. What I'd like to do is then apply that color to the background of the second view.

Here is the settings code

```<code>import UIKit
import GameKit

public var randomColor = UIColor()

class SettingsViewController: UIViewController {

@IBOutlet weak var pushMe: UIButton!
let colorProvider = BackgroundColorProvider()

@IBAction func pushMeChange(_ sender: Any) {
randomColor = colorProvider.randomColorBG()
print (randomColor.superclass as Any)
view.backgroundColor = randomColor
}

struct BackgroundColorProvider {
let colors = [
    UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), // teal color
    UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), // yellow color
    UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), // red color
    UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), // orange color
    UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), // dark color
    UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), // purple color
    UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), // green color
]

func randomColorBG() -> UIColor {
let randomNumber = GKRandomSource.sharedRandom().nextInt(upperBound: colors.count)
return colors[randomNumber]
    }
}
</code>```

}

Then I have this in the main viewController I pulled from here:
Changing background color of all views in project from one view controller?

The function does error below doesn't error out however I'm a noob at best, I'm not sure how the bell should work and i doubt its even being called. Any help is appreciated.

```<code>// bringing in background color from SettingsViewController

 func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
        let viewController:SettingsViewController = segue!.destination as!  SettingsViewController
        viewController.view.backgroundColor = self.view.backgroundColor
    }
}
</code>```

答:
Swift has this neat feature called a singleton that can be used to manage "settings" across a list of view controllers. In the viewDidLoad() method of the timer view you can set the view's background color to singleton.backgroundColor. In the settings view, when the user selects a new color, it should set singleton.backgroundColor = newColorThatUserChose. This way, when the user switches back to the Timer View, the color will automatically switch.

As shown in the link above, a singleton can be created like this:

```<code>class Settings {
    static let sharedInstance = Settings()
    var backgroundColor = UIColor.White // set to white by default.
}
</code>```

Then in the viewDidLoad method for the Timer View:

```<code>self.view.backgroundColor = Settings.sharedInstance.backgroundColor
</code>```

Finally in the SettingsViewController when the user chooses a new color:

```<code>var color = [UIColor.White, UIColor.Black, UIColor.Blue, UIColor.Green........]
Settings.sharedInstance.backgroundColor = color[x] // where x is the index that was chosen.
</code>```

This will allow the views to change automatically based on the apps settings. To ensure that this works in all of the views that you would like to change the color for,

```<code>self.view.backgroundColor = Settings.sharedInstance.backgroundColor
</code>```

should be placed in every UIViewController.

To further abstract this, you can create a custom class called GeneralUIViewController which is a class of type UIViewController and has the above code in its viewDidLoad method. After doing this every UIViewController should have its class set to GeneralUIViewController. This will make it so you only need to set the background color in one file and every view controller in your project will automatically inherit setting its background color to what the User has chosen in the settings page of this application.

These preferences should probably be saved when the application is reopened so CoreData can be used for this. I'd check out this link for more information.

Body:
So I need some help for a project. I have a simple tab bar SVC where the first view is a timer and the second is a settings page. On the settings page I've setup a struct with an array of colors, then when a user clicks a button a random color in the array is called and applied to the back ground. This part works just as I Intended. What I'd like to do is then apply that color to the background of the second view.

Here is the settings code

import UIKit
import GameKit

public var randomColor = UIColor()

class SettingsViewController: UIViewController {

@IBOutlet weak var pushMe: UIButton!
let colorProvider = BackgroundColorProvider()

@IBAction func pushMeChange(_ sender: Any) {
randomColor = colorProvider.randomColorBG()
print (randomColor.superclass as Any)
view.backgroundColor = randomColor
}

struct BackgroundColorProvider {
let colors = [
    UIColor(red: 90/255.0, green: 187/255.0, blue: 181/255.0, alpha: 1.0), // teal color
    UIColor(red: 222/255.0, green: 171/255.0, blue: 66/255.0, alpha: 1.0), // yellow color
    UIColor(red: 223/255.0, green: 86/255.0, blue: 94/255.0, alpha: 1.0), // red color
    UIColor(red: 239/255.0, green: 130/255.0, blue: 100/255.0, alpha: 1.0), // orange color
    UIColor(red: 77/255.0, green: 75/255.0, blue: 82/255.0, alpha: 1.0), // dark color
    UIColor(red: 105/255.0, green: 94/255.0, blue: 133/255.0, alpha: 1.0), // purple color
    UIColor(red: 85/255.0, green: 176/255.0, blue: 112/255.0, alpha: 1.0), // green color
]

func randomColorBG() -> UIColor {
let randomNumber = GKRandomSource.sharedRandom().nextInt(upperBound: colors.count)
return colors[randomNumber]
    }
}

}

Then I have this in the main viewController I pulled from here:
Changing background color of all views in project from one view controller?

The function does error below doesn't error out however I'm a noob at best, I'm not sure how the bell should work and i doubt its even being called. Any help is appreciated.

// bringing in background color from SettingsViewController

 func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if (segue.identifier == "Load View") {
        // pass data to next view
        let viewController:SettingsViewController = segue!.destination as!  SettingsViewController
        viewController.view.backgroundColor = self.view.backgroundColor
    }
}

Body:
Swift has this neat feature called a singleton that can be used to manage "settings" across a list of view controllers. In the viewDidLoad() method of the timer view you can set the view's background color to singleton.backgroundColor. In the settings view, when the user selects a new color, it should set singleton.backgroundColor = newColorThatUserChose. This way, when the user switches back to the Timer View, the color will automatically switch.

As shown in the link above, a singleton can be created like this:

class Settings {
    static let sharedInstance = Settings()
    var backgroundColor = UIColor.White // set to white by default.
}

Then in the viewDidLoad method for the Timer View:

self.view.backgroundColor = Settings.sharedInstance.backgroundColor

Finally in the SettingsViewController when the user chooses a new color:

var color = [UIColor.White, UIColor.Black, UIColor.Blue, UIColor.Green........]
Settings.sharedInstance.backgroundColor = color[x] // where x is the index that was chosen.

This will allow the views to change automatically based on the apps settings. To ensure that this works in all of the views that you would like to change the color for,

self.view.backgroundColor = Settings.sharedInstance.backgroundColor

should be placed in every UIViewController.

To further abstract this, you can create a custom class called GeneralUIViewController which is a class of type UIViewController and has the above code in its viewDidLoad method. After doing this every UIViewController should have its class set to GeneralUIViewController. This will make it so you only need to set the background color in one file and every view controller in your project will automatically inherit setting its background color to what the User has chosen in the settings page of this application.

These preferences should probably be saved when the application is reopened so CoreData can be used for this. I'd check out this link for more information.


问:
"Can't find symbol" error in the java.math.BigInteger class
I'm trying to write code for a function that inputs String and returns its remainder when divided by 7 as an 'int'.
For some reason I'm getting the following error,

```<code>    Main.java:16: error: cannot find symbol
        n=java.math.BigInteger.bg.intValue();
                          ^
    symbol:   variable bg
    location: class BigInteger
    1 error
</code>```

My code is as follows,

```<code>    /* package whatever; // don't place package name! */

    import java.util.*;
    import java.lang.*;
    import java.io.*;

    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        int remainderWith7(String num)
        {
            // Your code here
            java.math.BigInteger bg=new java.math.BigInteger(num);
            Integer n=java.math.bg.intValue();
            //int n=java.util.Integer.parseInt(num);
            //hello
            return (int)n%7;
        }
        public static void main (String[] args) throws java.lang.Exception
        {
            // your code goes here
            Ideone id=new Ideone();
            id.remainderWith7("10");
        }
    }
</code>```

Please help.
Thank You.

答:
```<code>import java.math.BigInteger;
import java.util.Scanner;

public class BigIntergerSumExample {

    public static void main(String args[]) {

        BigInteger number1;
        BigInteger number2;
        BigInteger sum;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the value of number 1");
        number1 = sc.nextBigInteger();
        System.out.println("Enter the value of number 2");
        number2 = sc.nextBigInteger();

        BigInteger a = new BigInteger(""+number1);
        BigInteger b = new BigInteger(""+number2);
        BigInteger result = a.add(b);

        System.out.println("Sum is Two numbers : -> " + result);
    }

}

Answer is

Enter the value of number 1
1111111111111111111111111111111111111111111111111
Enter the value of number 2
2222222222222222222222222222222222222222222222222
Sum is Two numbers : ->
3333333333333333333333333333333333333333333333333
</code>```

Body:
I'm trying to write code for a function that inputs String and returns its remainder when divided by 7 as an 'int'.
For some reason I'm getting the following error,

    Main.java:16: error: cannot find symbol
        n=java.math.BigInteger.bg.intValue();
                          ^
    symbol:   variable bg
    location: class BigInteger
    1 error

My code is as follows,

    /* package whatever; // don't place package name! */

    import java.util.*;
    import java.lang.*;
    import java.io.*;

    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        int remainderWith7(String num)
        {
            // Your code here
            java.math.BigInteger bg=new java.math.BigInteger(num);
            Integer n=java.math.bg.intValue();
            //int n=java.util.Integer.parseInt(num);
            //hello
            return (int)n%7;
        }
        public static void main (String[] args) throws java.lang.Exception
        {
            // your code goes here
            Ideone id=new Ideone();
            id.remainderWith7("10");
        }
    }

Please help.
Thank You.


问:
what are pros and cons to define constant local variables as static ( c++)?
```<code>void Animation::playAnimation() const
{
    static const int index = 0;
    const std::string& animationFileName = m_animationContainer.getAnimationName(index);
    static const int zOrder = -1;
    static bool isLooping = false;

    AnimationBank::play(animationFileName,
                        zOrder,
                        isLooping);
}
</code>```

what are pros and cons to define constant local variables as static?
what is an overhead of defining index, zOrder, isLooping as static. Is there any benefit to do this?

答:
Let's start with the easy one.

const:

const doesn't give you any ovehead and the only advantage it give you is the variable can't be changed during its life time. It is interesting because:

Correctness.

If want a that show clearly show what the variable, use const make clear that variable won't/can't be changed.

You may think, why I don't use a #define for example. Well, define will make the compiler replace it to fix values and in some cases it is not and advantage like strings or objects.

Protection.

If someone else qill use your function you make clear this variable can be changed and you protect its value.

Static:

Static give you a overhead because after create the variable for the first time it will exist during the lifetime of your program and the advantage is exactly that. When the variable is create you give it an value. Because it stay alive after that, no matter what happens, it can't get again a value as it the is the  first time.

Lets see an example with class.

Suppose you want a class to manager an addition to one int and this int need to accumulate this additions including a new object of this class is created and or destroyed:

```<code>#include <iostream>
using namespace std;
class ClassAcInt {
      public:
             void Print_iVar();
             void Add_iVar();
      private:
             static int iVar;
};

int ClassAcInt::iVar = 10;           //iVar = 10

void ClassAcInt::Print_iVar() {      //Show iVar
     cout << iVar << '\n';
}

void ClassAcInt::Add_iVar() {        //Add 1 to iVar
     iVar++;
}

int main () {
    ClassAcInt* oC1 = new ClassAcInt();     //iVar = 10
    oC1->Print_iVar();                      //print iVar
    oC1->Add_iVar();                        //iVar = iVar + 1
    oC1->Print_iVar();                      //Print iVar
    delete oC1;                             //Bye what we did... Are you sure?

    ClassAcInt* oC2 = new ClassAcInt();     //iVar = 10? Are you sure?
    oC2->Print_iVar();                      //Print iVar.... What a hack!!!!
    oC2->Add_iVar();                        //iVar = iVAr + 1
    oC2->Print_iVar();                      //omgosh...
    delete oC2;
}
</code>```

You can think the result will be:
10
11
10
11

but 'surprisingly' the result is:
10
11
11
12

The key is the lines static int iVar; and int ClassAcInt::iVar = 10;. Try to suppress the static word and see what happens :)

Body:
void Animation::playAnimation() const
{
    static const int index = 0;
    const std::string& animationFileName = m_animationContainer.getAnimationName(index);
    static const int zOrder = -1;
    static bool isLooping = false;

    AnimationBank::play(animationFileName,
                        zOrder,
                        isLooping);
}

what are pros and cons to define constant local variables as static?
what is an overhead of defining index, zOrder, isLooping as static. Is there any benefit to do this?

Body:
Let's start with the easy one.

const:

const doesn't give you any ovehead and the only advantage it give you is the variable can't be changed during its life time. It is interesting because:

Correctness.

If want a that show clearly show what the variable, use const make clear that variable won't/can't be changed.

You may think, why I don't use a #define for example. Well, define will make the compiler replace it to fix values and in some cases it is not and advantage like strings or objects.

Protection.

If someone else qill use your function you make clear this variable can be changed and you protect its value.

Static:

Static give you a overhead because after create the variable for the first time it will exist during the lifetime of your program and the advantage is exactly that. When the variable is create you give it an value. Because it stay alive after that, no matter what happens, it can't get again a value as it the is the  first time.

Lets see an example with class.

Suppose you want a class to manager an addition to one int and this int need to accumulate this additions including a new object of this class is created and or destroyed:

#include <iostream>
using namespace std;
class ClassAcInt {
      public:
             void Print_iVar();
             void Add_iVar();
      private:
             static int iVar;
};

int ClassAcInt::iVar = 10;           //iVar = 10

void ClassAcInt::Print_iVar() {      //Show iVar
     cout << iVar << '\n';
}

void ClassAcInt::Add_iVar() {        //Add 1 to iVar
     iVar++;
}

int main () {
    ClassAcInt* oC1 = new ClassAcInt();     //iVar = 10
    oC1->Print_iVar();                      //print iVar
    oC1->Add_iVar();                        //iVar = iVar + 1
    oC1->Print_iVar();                      //Print iVar
    delete oC1;                             //Bye what we did... Are you sure?

    ClassAcInt* oC2 = new ClassAcInt();     //iVar = 10? Are you sure?
    oC2->Print_iVar();                      //Print iVar.... What a hack!!!!
    oC2->Add_iVar();                        //iVar = iVAr + 1
    oC2->Print_iVar();                      //omgosh...
    delete oC2;
}

You can think the result will be:
10
11
10
11

but 'surprisingly' the result is:
10
11
11
12

The key is the lines static int iVar; and int ClassAcInt::iVar = 10;. Try to suppress the static word and see what happens :)


问:
Custom hardware causing Linux boot to hang after initrd on PC
We've created some custom hardware that uses PCIe 2.0. This hardware works with an HP DL360 G7 server with CentOS Linux 5.4. So on the HP server Linux is able to cold-boot just fine, recognize the card, and interface with our driver. However, when we try plugging the card into a regular Dell T3500 PC Linux is unable to boot. It hangs after initrd with no crash, debug, or error messages. So my question is, what tools or settings are available to help debug this problem? We want to know why the boot process can't get past initrd.</p>

答: Its not clear from your description if the boot is hanging while mounting initrd or if its hanging while executing the contents in the initrd (init scripts, etc). If the latter,I've diagnosed similar problems by cracking open the initrd and altering the init scripts inside it to just immediately drop to a bash prompt. Then re-archive the initrd, and you should boot right to a prompt. From there you can manually execute each command in the initrd init scripts until you find the culprit.</p>


问:
Remove margin for the div for which width is given in percentage
In styled components of React JS, I have given the width for div in percentage to make it responsive....
But the div is getting margin at right which is making the alignment disturbed.
How to get rid of this margin.

```<code>export const BannerHeaderText = styled.h1`
    width: 46.5%;
    height: 64px;
    font-size: 28px;
    font-weight: 600;
    line-height: 1.14;
    `
export const BannerParagraph = styled.p`
    width: 51.4%;
    height: 40px;
    margin-top: 8px;
    font-size: 16px;
    line-height: 1.5;
    color: #000000;
    opacity: 0.38;
    `
</code>```

I am getting the width as I needed.

```<code><BannerParagraphBlock>

                <BannerHeaderText>
                    Solveing the most common problems in marketing
                </BannerHeaderText>

                <BannerParagraph>
                    Exquisite codially mr happiness of neglected distrusts.
                    Boisterous impossible unaffected he me everything.
                </BannerParagraph>

                <SeeAllProductsButton>{message.SayEffectHomePageSeeAllProductsButton.value}</SeeAllProductsButton>

            </BannerParagraphBlock>
</code>```

Missed Data

BannerHeaderText is h1 and BannerParagrap is p
BannerParagraphBlock is section

答:
Use flex to get the same

below i posted an example

more update of flex FLEX

.wrapper {
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-flow: column nowrap;
}

.wrapper h1 {
  font-size: 19px;
  margin: 10px 0px;
  color: #fff;
  max-width: 352px;
  text-align: center;
}

.wrapper p {
  font-size: 14px;
  color: #f7f7f7;
  max-width: 352px;
  text-align: center;
}

.wrapper button {
  background: #7C6ECC;
  color: #fff;
  text-align: center;
  margin-top: 10px;
  border: none;
  font-size: 14px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <h1>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  </h1>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, rem, neque rerum nemo nam dolor ea nihil
  </p>
  <button>
    See all products
  </button>
</div></code>```

Body:
In styled components of React JS, I have given the width for div in percentage to make it responsive....
But the div is getting margin at right which is making the alignment disturbed.
How to get rid of this margin.

export const BannerHeaderText = styled.h1`
    width: 46.5%;
    height: 64px;
    font-size: 28px;
    font-weight: 600;
    line-height: 1.14;
    `
export const BannerParagraph = styled.p`
    width: 51.4%;
    height: 40px;
    margin-top: 8px;
    font-size: 16px;
    line-height: 1.5;
    color: #000000;
    opacity: 0.38;
    `

I am getting the width as I needed.

<BannerParagraphBlock>

                <BannerHeaderText>
                    Solveing the most common problems in marketing
                </BannerHeaderText>

                <BannerParagraph>
                    Exquisite codially mr happiness of neglected distrusts.
                    Boisterous impossible unaffected he me everything.
                </BannerParagraph>

                <SeeAllProductsButton>{message.SayEffectHomePageSeeAllProductsButton.value}</SeeAllProductsButton>

            </BannerParagraphBlock>

Missed Data

BannerHeaderText is h1 and BannerParagrap is p
BannerParagraphBlock is section

Body:
Use flex to get the same

below i posted an example

more update of flex FLEX

.wrapper {
  width: 100%;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-flow: column nowrap;
}

.wrapper h1 {
  font-size: 19px;
  margin: 10px 0px;
  color: #fff;
  max-width: 352px;
  text-align: center;
}

.wrapper p {
  font-size: 14px;
  color: #f7f7f7;
  max-width: 352px;
  text-align: center;
}

.wrapper button {
  background: #7C6ECC;
  color: #fff;
  text-align: center;
  margin-top: 10px;
  border: none;
  font-size: 14px;
}

<div class="wrapper">
  <h1>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit.
  </h1>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, rem, neque rerum nemo nam dolor ea nihil
  </p>
  <button>
    See all products
  </button>
</div>


问:
Why am I not able to add click event to dynamically inserted element of a list?
I have code shown below for a project where I insert list elements using javascript and for click on each element I have to call a function. However, it does not seem to work.

var c = document.getElementById("content");

c.innerHTML += "
";

for(var j = 0; j<5; j++){

    c.innerHTML += "
some stuff"+j+"
";

    document.getElementById(j).addEventListener("click", function(){ alert('this is test'); }, false);

}
c.innerHTML += "
";```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id = "content"> </div></code>```

Why is the click event not being triggered? How can I make this work?

答:
Create a function and use it onclick. You can also pass this(the element) as argument to the function where you can get the object attributes in that function.

var c = document.getElementById("content");

c.innerHTML += "
";

for(var j = 0; j<5; j++){

    c.innerHTML += "
some stuff"+j+"
";

}
c.innerHTML += "
";

function alertMe(obj){
alert('this is test from '+obj.id);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id = "content"> </div></code>```

addEventListener Method:-

document.getElementById can only be called once you have append it into your DOM. before appending to the DOM you cant access it

If you still want to use addEventListener you can achieve by adding listener after appending the element like below

var c = document.getElementById("content");

c.innerHTML += "
";

for(var j = 0; j<5; j++){

    c.innerHTML += "
some stuff"+j+"
";

    document.getElementById(j).addEventListener("click", function(){ alert('this is test'); }, false);

}
c.innerHTML += "
";```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id = "content"> </div></code>```

var c = document.getElementById("content");
c.innerHTML += "
";
for (var j = 0; j < 5; j++) {
  c.innerHTML += "
some stuff" + j + "
";
}
c.innerHTML += "
";
for (var j = 0; j < 5; j++) {
  document.getElementById(j).addEventListener("click", function() {
    alert('this is test');
  }, false);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="content"> </div></code>```

Body:
I have code shown below for a project where I insert list elements using javascript and for click on each element I have to call a function. However, it does not seem to work.

var c = document.getElementById("content");

c.innerHTML += "
";

for(var j = 0; j<5; j++){

    c.innerHTML += "
some stuff"+j+"
";

    document.getElementById(j).addEventListener("click", function(){ alert('this is test'); }, false);

}
c.innerHTML += "
";

Why is the click event not being triggered? How can I make this work?

Body:
Create a function and use it onclick. You can also pass this(the element) as argument to the function where you can get the object attributes in that function.

var c = document.getElementById("content");

c.innerHTML += "<ul>";

for(var j = 0; j<5; j++){

    c.innerHTML += "<li id = '" + j +  "' onclick='alertMe(this)'>some stuff"+j+"</li>";

}
c.innerHTML += "</ul>";

function alertMe(obj){
alert('this is test from '+obj.id);
}

<div id = "content"> </div>

addEventListener Method:-

document.getElementById can only be called once you have append it into your DOM. before appending to the DOM you cant access it

If you still want to use addEventListener you can achieve by adding listener after appending the element like below

var c = document.getElementById("content");

c.innerHTML += "<ul>";

for(var j = 0; j<5; j++){

    c.innerHTML += "<li id = '" + j +  "'>some stuff"+j+"</li>";

    document.getElementById(j).addEventListener("click", function(){ alert('this is test'); }, false);

}
c.innerHTML += "</ul>";

<div id = "content"> </div>

var c = document.getElementById("content");
c.innerHTML += "<ul>";
for (var j = 0; j < 5; j++) {
  c.innerHTML += "<li id = '" + j + "'>some stuff" + j + "</li>";
}
c.innerHTML += "</ul>";
for (var j = 0; j < 5; j++) {
  document.getElementById(j).addEventListener("click", function() {
    alert('this is test');
  }, false);
}

<div id="content"> </div>


问:
Finding new line character in a String in "Swift 3"
In my app I am receiving some incoming data from a web service. In that data some wrong values can also be received like new line characters. I want to find in response string that if it contains a new line character or not.

Before Swift 3 I was able to do it like this

```<code>string.rangeOfString("\n")) == nil)
</code>```

But in Swift 3 this methods is no longer available. However substring method is available which does with the help of Range.

I want to detect if my string contains "\n" how this would be accomplished using this method in Swift 3.

答:
.characters.contains() should do the trick:

```<code>let s1 = "Hi I'm a string\n with a new line"
s1.characters.contains("\n")  // => true

let s2 = "I'm not"
s2.characters.contains("\n")  // => false
</code>```

Body:
In my app I am receiving some incoming data from a web service. In that data some wrong values can also be received like new line characters. I want to find in response string that if it contains a new line character or not.

Before Swift 3 I was able to do it like this

string.rangeOfString("\n")) == nil)

But in Swift 3 this methods is no longer available. However substring method is available which does with the help of Range.

I want to detect if my string contains "\n" how this would be accomplished using this method in Swift 3.

Body:
.characters.contains() should do the trick:

let s1 = "Hi I'm a string\n with a new line"
s1.characters.contains("\n")  // => true

let s2 = "I'm not"
s2.characters.contains("\n")  // => false


问:
Using an interface as a type
I've been looking through some production code, and I'm a little confused on the concept of using an interface as a type (object)

I saw this explanation http://download.oracle.com/javase/tutorial/java/IandI/interfaceAsType.html

Here's the code below:

```<code>public Object findLargest(Object object1, Object object2) {
   Relatable obj1 = (Relatable)object1;
   Relatable obj2 = (Relatable)object2;
   if ( (obj1).isLargerThan(obj2) > 0)
      return object1;
   else
      return object2;
}
</code>```

Where Relatable is an interface, I don't understand where it gets the logic for the isLargerThan(obj2) function call.

Can somebody make this clear for me?

答: While the compile time type of obj1 is Relatable, the runtime type is some concrete class that implements Relatable. The code that actually gets called is defined by that runtime type. This is known as dynamic dispatch.

Title: Using an interface as a type

Body:
I've been looking through some production code, and I'm a little confused on the concept of using an interface as a type (object)

I saw this explanation http://download.oracle.com/javase/tutorial/java/IandI/interfaceAsType.html

Here's the code below:

public Object findLargest(Object object1, Object object2) {
   Relatable obj1 = (Relatable)object1;
   Relatable obj2 = (Relatable)object2;
   if ( (obj1).isLargerThan(obj2) > 0)
      return object1;
   else
      return object2;
}

Where Relatable is an interface, I don't understand where it gets the logic for the isLargerThan(obj2) function call.

Can somebody make this clear for me?


问:
jquery.ui tooltip: Show tooltip only after hover for a duration of time
I would like to show the tooltip over an element only if I have kept the mouse there for 1 second. If I hover for less than 1 second, the tooltip should not show. How do I accomplish this?</p>

答:
You can use show:{duration:value} option while initializing the tooltip as below:

```<code>$( "#elementid" ).tooltip({
    show: { duration: 2000 }
});
</code>```

DEMO FIDDLE

Body:
You can use show:{duration:value} option while initializing the tooltip as below:

$( "#elementid" ).tooltip({
    show: { duration: 2000 }
});

DEMO FIDDLE


问:
Loading fonts with webpack
I'm trying to use custom fonts in a Project website with angular4.

This is my Project structure

This is my webpack.config.js

```<code>const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
                // Font Definitions
                { test: /\.svg$/, loader: 'url?limit=65000&mimetype=image/svg+xml&name=font/[name].[ext]' },
                { test: /\.woff$/, loader: 'url?limit=65000&mimetype=application/font-woff&name=font/[name].[ext]' },
                { test: /\.woff2$/, loader: 'url?limit=65000&mimetype=application/font-woff2&name=font/[name].[ext]' },
                { test: /\.[ot]tf$/, loader: 'url?limit=65000&mimetype=application/octet-stream&name=font/[name].[ext]' },
                { test: /\.eot$/, loader: 'url?limit=65000&mimetype=application/vnd.ms-fontobject&name=font/[name].[ext]' }
            ]
        },
        plugins: [new CheckerPlugin()]
    };
</code>```

This is my css with @font-face

```<code>@font-face {
    font-family: "FuturaMaxiLight";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Light.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Light.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Light.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "FuturaMaxiDemi";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Demi.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Demi.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Demi.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "FuturaMaxiBold";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Bold.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Bold.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Bold.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
</code>```

This is the error when I try like that

If I change the css and try to include a dot before the import.
1 dot gives errors.
2 dots breaks the app.

```<code>@font-face {
    font-family: "FuturaMaxiBold";
    src: url('./fonts/FuturaMaxi/Futura-Maxi-Bold.eot') format('embedded-opentype'), /*for IE */
    url('./fonts/FuturaMaxi/Futura-Maxi-Bold.ttf') format('truetype'), /* for CSS3 browsers */
    url('./fonts/FuturaMaxi/Futura-Maxi-Bold.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
</code>```

答:
You need resolve-url-loader to resolve the correct path in your build.

See https://github.com/bholloway/resolve-url-loader

Install resolve-url-loader

```<code>npm install --save-dev resolve-url-loader
</code>```

Modify your Webpack CSS rule:

```<code>{
  test: /\.css$/,
  use: [
    'to-string-loader',
    isDevBuild ? 'css-loader' : 'css-loader?minimize',
    'resolve-url-loader'      // Add this
  ]
}
</code>```

Use relative paths in your CSS files

```<code>@font-face {
    font-family: "FuturaMaxiLight";
    src: url('../fonts/FuturaMaxi/Futura-Maxi-Light.eot') format('embedded-opentype'), /*for IE */
    url('../fonts/FuturaMaxi/Futura-Maxi-Light.ttf') format('truetype'), /* for CSS3 browsers */
    url('../fonts/FuturaMaxi/Futura-Maxi-Light.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}
</code>```

Title: Loading fonts with webpack

Body:
I'm trying to use custom fonts in a Project website with angular4.

This is my Project structure

This is my webpack.config.js

const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
                // Font Definitions
                { test: /\.svg$/, loader: 'url?limit=65000&mimetype=image/svg+xml&name=font/[name].[ext]' },
                { test: /\.woff$/, loader: 'url?limit=65000&mimetype=application/font-woff&name=font/[name].[ext]' },
                { test: /\.woff2$/, loader: 'url?limit=65000&mimetype=application/font-woff2&name=font/[name].[ext]' },
                { test: /\.[ot]tf$/, loader: 'url?limit=65000&mimetype=application/octet-stream&name=font/[name].[ext]' },
                { test: /\.eot$/, loader: 'url?limit=65000&mimetype=application/vnd.ms-fontobject&name=font/[name].[ext]' }
            ]
        },
        plugins: [new CheckerPlugin()]
    };

This is my css with @font-face

@font-face {
    font-family: "FuturaMaxiLight";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Light.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Light.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Light.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "FuturaMaxiDemi";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Demi.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Demi.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Demi.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "FuturaMaxiBold";
    src: url('/fonts/FuturaMaxi/Futura-Maxi-Bold.eot') format('embedded-opentype'), /*for IE */
    url('/fonts/FuturaMaxi/Futura-Maxi-Bold.ttf') format('truetype'), /* for CSS3 browsers */
    url('/fonts/FuturaMaxi/Futura-Maxi-Bold.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

This is the error when I try like that

If I change the css and try to include a dot before the import.
1 dot gives errors.
2 dots breaks the app.

@font-face {
    font-family: "FuturaMaxiBold";
    src: url('./fonts/FuturaMaxi/Futura-Maxi-Bold.eot') format('embedded-opentype'), /*for IE */
    url('./fonts/FuturaMaxi/Futura-Maxi-Bold.ttf') format('truetype'), /* for CSS3 browsers */
    url('./fonts/FuturaMaxi/Futura-Maxi-Bold.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

Body:
You need resolve-url-loader to resolve the correct path in your build.

See https://github.com/bholloway/resolve-url-loader

Install resolve-url-loader

npm install --save-dev resolve-url-loader

Modify your Webpack CSS rule:

{
  test: /\.css$/,
  use: [
    'to-string-loader',
    isDevBuild ? 'css-loader' : 'css-loader?minimize',
    'resolve-url-loader'      // Add this
  ]
}

Use relative paths in your CSS files

@font-face {
    font-family: "FuturaMaxiLight";
    src: url('../fonts/FuturaMaxi/Futura-Maxi-Light.eot') format('embedded-opentype'), /*for IE */
    url('../fonts/FuturaMaxi/Futura-Maxi-Light.ttf') format('truetype'), /* for CSS3 browsers */
    url('../fonts/FuturaMaxi/Futura-Maxi-Light.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}


问:
jQuery DataTables with Bootstrap Styling and responsive extension does't work
In my html page i replaced the example of this link. In the head tag i have this:

```<code><link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="http:////cdn.datatables.net/plug-ins/a5734b29083/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
    <link href="http://cdn.datatables.net/responsive/1.0.1/css/dataTables.responsive.css" rel="stylesheet">
</code>```

for the css and this:

```<code><script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http:////cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
    <script src="http:////cdn.datatables.net/responsive/1.0.1/js/dataTables.responsive.min.js"></script>
    <script src="http://cdn.datatables.net/plug-ins/a5734b29083/integration/bootstrap/3/dataTables.bootstrap.js"></script>
</code>```

for the javascript.

The table is this:

```<code><table id="example" class="table table-striped table-hover dt-responsive" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                    <th>Extn.</th>
                    <th>E-mail</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Quinn</td>
                    <td>Flynn</td>
                    <td>Support Lead</td>
                    <td>Edinburgh</td>
                    <td>22</td>
                    <td>2013/03/03</td>
                    <td>$342,000</td>
                    <td>9497</td>
                    <td>q.flynn@datatables.net</td>
                </tr>
                <tr>
                    <td>Quinn</td>
                    <td>Flynn</td>
                    <td>Support Lead</td>
                    <td>Edinburgh</td>
                    <td>22</td>
                    <td>2013/03/03</td>
                    <td>$342,000</td>
                    <td>9497</td>
                    <td>q.flynn@datatables.net</td>
                </tr>
                <tr>
                    <td>Quinn</td>
                    <td>Flynn</td>
                    <td>Support Lead</td>
                    <td>Edinburgh</td>
                    <td>22</td>
                    <td>2013/03/03</td>
                    <td>$342,000</td>
                    <td>9497</td>
                    <td>q.flynn@datatables.net</td>
                </tr>
            </tbody>
        </table>
</code>```

I call datatable at the end of body with:

```<code><script>
        $(document).ready(function() {
            $('#example').dataTable({
                responsive: true
            });
        });
    </script>
</code>```

My code seems the same of the example on the DataTable site. It works and my doesn't work. Why?

答:
Premise: I'm writing this reply because I'm facing the same problem and since I don't find a good example/tutorial, I explain how I'll deal with this.

I suggest to look at the source code in the DataTables Bootstrap Styling page

DataTables Bootstrap Styling

That page shows DataTables and the Responsive extension being used with the Bootstrap framework providing the styling

Said first that below the demo table being shown in the DataTables Bootstrap Styling, there are the correct CSS, JS and HTML to be used for the case, and if am I not wrong, they are also placed in the correct order,

you have another option to go for:

just watch at the source code of that page, e.g. in Firefox I press Ctrl-u and in the address bar it is opened

view-source:https://datatables.net/extensions/responsive/examples/styling/bootstrap.html

this allows to see the source code of the rendered html.

Find the same command for your browser and you'll see how at DataTables website they setup the CSS(es) and JS(es) scripts to make it working.

What looks sharp is that they just use this script to initialize the table

```<code>$(document).ready(function() {
    $('#example').DataTable();
} );
</code>```

so no responsive keyword is used,

which makes it bright that the magic looks done by the singles CSS and JS (if correctly loaded).

In the end, to start from a safe point, place the js scripts loading in the HEAD section of your html test page and begin with making this to succesfully work,

only after a positive test, if needed, move them where you want.

Body:
In my html page i replaced the example of this link. In the head tag i have this:

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="http:////cdn.datatables.net/plug-ins/a5734b29083/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
    <link href="http://cdn.datatables.net/responsive/1.0.1/css/dataTables.responsive.css" rel="stylesheet">

for the css and this:

for the javascript.

The table is this:

                    First name
                    Last name
                    Position
                    Office
                    Age
                    Start date
                    Salary
                    Extn.
                    E-mail

                    Quinn
                    Flynn
                    Support Lead
                    Edinburgh
                    22
                    2013/03/03
                    $342,000
                    9497
                    q.flynn@datatables.net

                    Quinn
                    Flynn
                    Support Lead
                    Edinburgh
                    22
                    2013/03/03
                    $342,000
                    9497
                    q.flynn@datatables.net

                    Quinn
                    Flynn
                    Support Lead
                    Edinburgh
                    22
                    2013/03/03
                    $342,000
                    9497
                    q.flynn@datatables.net

I call datatable at the end of body with:

My code seems the same of the example on the DataTable site. It works and my doesn't work. Why?

Body:
Premise: I'm writing this reply because I'm facing the same problem and since I don't find a good example/tutorial, I explain how I'll deal with this.

I suggest to look at the source code in the DataTables Bootstrap Styling page

DataTables Bootstrap Styling

That page shows DataTables and the Responsive extension being used with the Bootstrap framework providing the styling

Said first that below the demo table being shown in the DataTables Bootstrap Styling, there are the correct CSS, JS and HTML to be used for the case, and if am I not wrong, they are also placed in the correct order,

you have another option to go for:

just watch at the source code of that page, e.g. in Firefox I press Ctrl-u and in the address bar it is opened

view-source:https://datatables.net/extensions/responsive/examples/styling/bootstrap.html

this allows to see the source code of the rendered html.

Find the same command for your browser and you'll see how at DataTables website they setup the CSS(es) and JS(es) scripts to make it working.

What looks sharp is that they just use this script to initialize the table

$(document).ready(function() {
    $('#example').DataTable();
} );

so no responsive keyword is used,

which makes it bright that the magic looks done by the singles CSS and JS (if correctly loaded).

In the end, to start from a safe point, place the js scripts loading in the HEAD section of your html test page and begin with making this to succesfully work,

only after a positive test, if needed, move them where you want.


问:
OpenLayers 3/Javascript: Why is there a "delay" when my array is filled?
I am a javascript-noob trying to access data via geoserver and openlayers3. Here is my code:

```<code>function loadData(featureName)
{
var features = [];

var featureRequest = new ol.format.WFS().writeGetFeature({
    srsName: 'EPSG:4326',
    featurePrefix: 'progeo16',
    featureTypes: [featureName],
    outputFormat: 'application/json'
});

fetch('http://...:8080/geoserver/wfs', {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest)
}).then(function(response) {
    return response.json();
}).then(function(json) {
    features = new ol.format.GeoJSON().readFeatures(json);
});

return features;
}
</code>```

My problem is now, that the features-array won't be filled "fast" enough. If I set a breakpoint (using firebug) at "return features;" the array will be empty. If I wait 2 seconds and hover over the variable "features", the array is filled with the expected elements.
So my question is:
I think that may be a problem due to a asynchronous request.
How can I be able to return the filled array in a proper way?

Thanks in advance

答:
There might be delay in asynchronous call.One way to deal with it is call the next consecutive step only after the completion of the asynchronous call.I added callback_function() in your code. For example

```<code>function loadData(featureName,callback_function)
{
var features = [];

var featureRequest = new ol.format.WFS().writeGetFeature({
    srsName: 'EPSG:4326',
    featurePrefix: 'progeo16',
    featureTypes: [featureName],
    outputFormat: 'application/json'
});
fetch('http://...:8080/geoserver/wfs', {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest)
}).then(function(response) {
    return response.json();
}).then(function(json) {
    features = new ol.format.GeoJSON().readFeatures(json);
    callback_function(features);
});
}
</code>```

Then make your function loadData() to return nothing. But when your asynchronous call fetches data, it will execute callback_function() which is the next steps of your logic.

Body:
I am a javascript-noob trying to access data via geoserver and openlayers3. Here is my code:

function loadData(featureName)
{
var features = [];

var featureRequest = new ol.format.WFS().writeGetFeature({
    srsName: 'EPSG:4326',
    featurePrefix: 'progeo16',
    featureTypes: [featureName],
    outputFormat: 'application/json'
});

fetch('http://...:8080/geoserver/wfs', {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest)
}).then(function(response) {
    return response.json();
}).then(function(json) {
    features = new ol.format.GeoJSON().readFeatures(json);
});

return features;
}

My problem is now, that the features-array won't be filled "fast" enough. If I set a breakpoint (using firebug) at "return features;" the array will be empty. If I wait 2 seconds and hover over the variable "features", the array is filled with the expected elements.
So my question is:
I think that may be a problem due to a asynchronous request.
How can I be able to return the filled array in a proper way?

Thanks in advance

Body:
There might be delay in asynchronous call.One way to deal with it is call the next consecutive step only after the completion of the asynchronous call.I added callback_function() in your code. For example

function loadData(featureName,callback_function)
{
var features = [];

var featureRequest = new ol.format.WFS().writeGetFeature({
    srsName: 'EPSG:4326',
    featurePrefix: 'progeo16',
    featureTypes: [featureName],
    outputFormat: 'application/json'
});
fetch('http://...:8080/geoserver/wfs', {
    method: 'POST',
    body: new XMLSerializer().serializeToString(featureRequest)
}).then(function(response) {
    return response.json();
}).then(function(json) {
    features = new ol.format.GeoJSON().readFeatures(json);
    callback_function(features);
});
}

Then make your function loadData() to return nothing. But when your asynchronous call fetches data, it will execute callback_function() which is the next steps of your logic.


答:
```<code>let string:String = "This is a string"
if string.range(of: "\n") == nil {
    print  ("contains nil")
}
else {
    print("contains new line")
}
</code>```

perferctly working in swift 3.

Title: Finding new line character in a String in "Swift 3"

Body:
let string:String = "This is a string"
if string.range(of: "\n") == nil {
    print  ("contains nil")
}
else {
    print("contains new line")
}

perferctly working in swift 3.